npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@uswitch/ustyle-react

v0.0.108

Published

uStyle React Components

Downloads

22

Readme

ustyle-react

A collection of React components implementing the uSwitch style guide, uStyle.

Installation

First, install the package:

npm i @uswitch/ustyle-react

Congratulations! You can now import ustyle-react components like so:

import {Button} from '@uswitch/ustyle-react';

// Do things with your button here...

Development

Note: you should use the npm 5 cli to add dependencies in order to keep package-lock.json up to date

First, clone the project and install the dependencies:

git clone https://github.com/uswitch/ustyle-react
cd ustyle-react && npm install

To start the development server (on port 9000) run:

npm start

Since the project is written in ES2015+, the src code will need to built when you commit. Luckily, we have a pre-commit hook that builds the code for you before every commit!

To run the build step manually:

npm run build

Components

Below are a list of components, with some guidance of how to use them.

Button

Example:

import {Button} from '@uswitch/ustyle-react';

<Button size='large' variant='primary' blocked />

Props:

  • variant [string] - options: primary, action, secondary, hero, reversed
  • size [string] - options: large, small
  • href [string] - if set, will return an anchor tag instead of a button
  • size [boolean]
  • blocked [boolean]
  • link [boolean]
  • stronger [boolean]
  • onClick [function] - called when the button is clicked

Breadcrumbs

Example:

import {Breadcrumbs} from '@uswitch/ustyle-react';

const items = [{
  href: '/',
  text: 'uSwitch.com'
}, {
  href: null, // NOTE: optional; not used
  text: 'Statutory credit reports'
}];

const onClick = (e) => e.preventDefault();

<Breadcrumbs items={items} onClick={onClick} />

Props:

  • items [array:objects]
    • href [string]
    • text [string/node]
  • onClick [function] - called when a breadcrumb is clicked

ProgressNavigation

Example:

import {ProgressNavigation} from '@uswitch/ustyle-react';

const items = [{
  href: '/journey/step-1',
  text: 'Step 1'
}, {
  href: '/journey/step-2', // NOTE: optional; not used
  text: 'Step 2',
  current: true
}, {
  href: '/journey/step-3', // NOTE: optional; not used
  text: 'Step 3'
}];

const onClick = (e, item) => e.preventDefault();

<ProgressNavigation items={items} onClick={onClick} />

Props:

  • items [array:objects]
    • href [string] - only required for completed steps
    • text [string/node]
    • current [boolean] - the step that the user is currently on
  • onClick [function] - called when a navigation link is clicked

USP

Example:

import {USP} from '@uswitch/ustyle-react';

<USP color='red' text='Example USP' annotation='More info goes here...' />

Props:

  • text [string:required] - the main USP text
  • annotation [string]
  • color [string] - options: blue, orange, purple, yellow, typecyan, green, navy, cyan, typegrey, red

Loader

Example:

import {Loader} from '@uswitch/ustyle-react';

let isLoading = true;

setTimeout(() => isLoading = false, 10000);

<div>{ isLoading ? <Loader text='Loading...' /> : null }</div>

LoaderContainer

Example:

import {LoaderContainer} from '@uswitch/ustyle-react';

let isLoading = true;

setTimeout(() => isLoading = false, 10000);

<LoaderContainer text='Loading...' isLoading={isLoading}>
  <ul className='us-list'>
    <li><a href='#'>List item 1</a></li>
    <li><a href='#'>List item 2</a></li>
    <li><a href='#'>List item 3</a></li>
    <li><a href='#'>List item 4</a></li>
  </ul>
</LoaderContainer>

Props:

  • text [string] - displayed under the loading spinner
  • isLoading [boolean]
  • children [nodes]

Icons

Example:

import {Icon} from '@uswitch/ustyle-react';

<Icon name='google' color='typecyan' size='large' />

Props:

  • name [string] - displayed under the loading spinner
  • color [string] - options: white, typegrey, inputgrey, typecyan, custom
  • size [string] options: small, medium, large
  • sizeTablet [string] - maps to .us-icon--{sizeTablet}--sm-tablet
  • sizeMobile [string] - maps to .us-icon--{sizeMobile}--mobile
  • noText [boolean]
  • iconPath [string] - default /icons.svg, the path where your icons are hosted

Notes:

  • To set a global icon path, you can set process.env.ICON_PATH = /images/icons.svg;

ValidationError

Example:

import {ValidationError} from '@uswitch/ustyle-react';

<ValidationError>Something went wrong!</ValidationError>

Props:

  • children [node] - error message to display

Notes:

  • Alias for <ValidationMessage variant='error' children={children}/>

ValidationMessage

Example:

import {ValidationMessage} from '@uswitch/ustyle-react';

let valid = true;
let message = 'You have been subscribe';

<ValidationMessage variant={ valid ? 'success' : 'error'} children={message} />

Props:

  • variant [string] - options: error, success
  • children [node] - error message to display

Toggle

Example:

import {Toggle} from '@uswitch/ustyle-react';

const items = [
  {
    text: 'Red',
    value: 'red'
  },
  {
    text: 'White',
    value: 'white'
  },
  {
    text: 'Rosé',
    value: 'rose'
  }
];

const onChange = (e, item) => console.log(item);

<Toggle items={items} onChange={onChange} name='toggle' />

Props:

  • items [array:objects]
    • text [string/node]
    • value [string]
    • disabled [boolean]
  • value [string] - the current value for the toggle component
  • name [string]
  • onChange [function]

ToggleYesNo

Example:

import {ToggleYesNo} from '@uswitch/ustyle-react';

const onChange = (e, item) => console.log(item);

<ToggleYesNo value={true} onChange={onChange} name='toggle-yes-no' />

Props:

  • value [string] - the current value for the toggle component
  • name [string]
  • onChange [function]

Select

Example:

import {Select} from '@uswitch/ustyle-react';

const items = [{
  text: 'Aye!',
  value: 'yes'
}, {
  text: 'Nay...',
  value: 'no'
}];

const onChange = (e, item) => console.log(item);

<Select items={items} onChange={onChange} name='select' />

Props:

  • items [array:objects]
    • text [string/node]
    • value [string]
    • disabled [boolean]
  • value [string] the current value of the select component
  • name [string]
  • variant [string]
  • disabled [boolean]
  • blocked [boolean]
  • onChange [function]

InputGroup

Example:

import {InputGroup} from '@uswitch/ustyle-react';

<InputGroup text="kwh" position="right">
  <input className="us-form-input" type="number" id="energy" placeholder="0" />
</InputGroup>

Props:

  • text [string/node]
  • icon [string] replaces text
  • position [string] options: left, right
  • disabled [boolean]
  • blocked [boolean]

Tabs

Example:

import {Tabs} from '@uswitch/ustyle-react';

const items = [{
  id: 'tab1', title: 'Tab 1', body: 'test'
}, {
  id: 'tab2', title: 'Tab 2', body: 'test', active: true
}, {
  id: 'tab3', title: 'Tab 3', body: 'test'
}];

const onClick = (e, item) => console.log({activeTab: item})

<Tabs items={items} onClick={onClick} />

Props:

  • items [array:objects]
    • id [string]
    • href [string]
    • title [string]
    • body [string/node]
    • active [boolean]
  • onClick [function] (optional)

Overlay

Example:

import {Overlay} from '@uswitch/ustyle-react';
// TODO: Write about overlay...

Props:

  • title [string]
  • children [string/node]
  • variant [string] - options: left, right, modal
  • isOpen [boolean]
  • onClose [function]

TextArea

Example:

import {TextArea} from '@uswitch/ustyle-react';
// TODO: Write about textarea...

Props:

  • name [string]
  • value [string]
  • disabled [boolean]
  • blocked [boolean]
  • onChange [function]

Tooltip

Example:

.tooltip-demo {
  position: relative;
}
import {Tooltip} from '@uswitch/ustyle-react';


<Tooltip
  className="tooltip-demo"
  trigger={ <div className="us-tooltip__icon"></div> }
  tooltipContent={ <div>Content</div> }>
  <div>
    Hello
  </div>
</Tooltip>