0.11.7 • Published 5 years ago

@qred/ui-components v0.11.7

Weekly downloads
-
License
ISC
Repository
github
Last release
5 years ago

@qred/ui-components

Boilerplate Based on this tutorial by codewithbernard

Commands

Development

To develop locally either run:

yarn storybook

or:

yarn dev

storybook launches a local version of storybook using the .stories.js files in the components, while dev runs the app in the srctest/ folder, develop locally using the method you prefer.


Deploy storybook

First:

yarn build-storybook

Then:

yarn deploy-storybook


Deployment to npm

To deploy you need to change the package.json version first: ideally upwards using: (major/minor/hotfix)

First:

yarn build

Then:

npm publish


Storybooks

https://qred.github.io/ui-components

npm

https://www.npmjs.com/package/@qred/ui-components

Documentation

Component name
Button
CircularProgressBar
DropDown
FileUploader
Header
Icon
LoadingButton
LoadingSpinner
MobileDrawer
Modal
MultipleChoice
MultipleChoiceItem
ProgressBar
TextArea
TextInput
ThemeProvider & theme

Deploy storybooks

Run the command:

yarn deploy-storybook

To start

yarn
yarn start

Edit src/index.js (your component)

Run local test client

yarn dev

Edit /srctest/app.js to change the parent environment, pass in props, etc.

Run locally as import into another project

Build this project:

yarn build

In this project's root directory, type:

yarn link

And then, in the project (root dir) you would like to use your component:

yarn link my-awesome-component

For this example I've used the package name my-awesome-component. This creates a symlink of your package in your project's node_modules/ dir. Now, you may import the component in your test project, as if it was a normally installed dependancy:

import MyAwesomeComponent from 'my-awesome-component'

If you're using a hot-reload system, you should be able to observe any changes you make to your component (as long as you build them)

To publish your component to npm

Update the package.json with correct information. Important things to set:

{
  "name": "cool-beans",
  "version": "4.2.0",
  "description": "My wizzbang gizmo",
  "author": "stevejobs",
  "license": "ISC"
}

If you have a git repo for the project, include the details:

"repository": {
    "type" : "git",
    "url" : "https://github.com/zxol/react-component-publish"
  },

Then, in the root directory, type:

npm publish

npm docs on publishing packages

A note on webpack configs and the dev server:

There are two webpack configs.

  • One for building the published component webpack.publish.js
  • One for viewing the component in the dev server. webpack.testServer.js

Note that they are separate, so any additions you make will have to be mirrored in both files, if you want to use the dev server. If anyone knows a better way to do this, please let me know.

Button

Props

Common props you may want to specify include:

  • disabled - gives a disabled style to the button
  • primary - use primary style for button
  • secondary use secondary style for button
  • tertiary - use tertiary style for button
  • size - button size either: 'small', 'medium'
  • style - passing css style to the button
  • to - href link
  • target - a tag html target=""
  • onClick - on click of button do this
  • icon - icon to display inside the button
  • fullwidth - display with 100% width

Usage

import { Button } from '@qred/ui-components';
...
<Button> </Button>

Header

Props

PropUsage
logoUrlUrl to be used for logo default: ''
childrenReact nodes to be rendered to the right of the logo default: null
backgroundColorBackground color for header section, defaults to transparent default: null

Usage

  <Header
    logoUrl="htps://static.qred.com/sv-se/bilder/logo-desktop-se.svg"
  >
    // Inner node can be any valid jsx
    <div className="Menu">
      <ul>
        <li>
          <a href="https://google.com">Home</a>
        </li>
        <li>
          <a href="https://googleplus.com">Trash</a>
        </li>
      </ul>
    </div>
  </Header>

MobileDrawer

Mobile drawer component to store mobile navigation. Won't show above screen size desktop: (992px).

Props

PropUsage
openBoolean value whether drawer is open or not default: false
onCloseFunction on close icon click in drawer default: () => {}

Usage

children node will appear in the drawer content.

  <MobileDrawer
    open={drawerOpen}
    onClose={this.handleToggleDrawer}
  >
    <ul>
      <li><a href="https://qred.com/se/">Home</a></li>
      <li><a href="https://qred.com/se/om-oss">About us</a></li>
    </ul>
  </MobileDrawer>

Modal

The modal component uses a styled react-modal

PropUsage
isOpenBoolean describing if the modal should be shown or not. default: false
onAfterOpenFunction that will be run after the modal has opened.
closeModalFunction that will be run when the modal is requested to be closed. (either by clicking on overlay or pressing ESC)
screenReaderLabelString indicating how the content container should be announced to screenreaders.
ariaHideAppBoolean indicating if the appElement should be hidden.
shouldCloseOnOverlayClickBoolean indicating if the overlay should close the modal.

import { Modal } from '@qred/ui-components';

...

  <Modal
    isOpen={isOpen}
    closeModal={() => setIsOpen(false)}
    screenReaderLabel=""
  >
    <>
      <input type="button" onClick={() => setIsOpen(false)} value="close modal" />
      <h1>This is a modal</h1>
      <p>This content also belongs to a modal</p>
    </>

  </Modal>

MultipleChoice

The multiple choice component

Props

PropUsage
iconUse the icon layout or not default: false
choicesAn array of objects, with keys: label, value, iconUrl (See examples) default: []
selectedAn object with keys: label, value, iconUrl (See examples) default: {}
onChange()When a multiple choice item is clicked onChange will be called with the choice as the argument in the form of an object with keys: label, value, iconUrl

Usage

import { MultipleChoice } from '@qred/ui-components';
...

<MultipleChoice
  choices={[
    {
      label: 'Choice 1',
      value: 1
    },
    {
      label: 'Choice 2',
      value: 2
    },
    {
      label: 'Choice 3',
      value: 3
    }
  ]}

  selected={this.state.selected}

  onChange={
    // onChange will have the object for the item clicked sent in choices
    (selected) => {
      this.setState({
        selected
      })
    }
  }

/>

Or in icon mode

import { MultipleChoice } from '@qred/ui-components';
...

<MultipleChoice
  icon
  choices={[
    {
      label: 'Choice 1',
      value: 1,
      iconUrl: 'https://static.qred.com/sv-se/bilder/icons8-trolley-500.svg'
    },
    {
      label: 'Choice 2',
      value: 2,
      iconUrl: 'https://static.qred.com/sv-se/bilder/icons8-trolley-500.svg'
    },
    {
      label: 'Choice 3',
      value: 3,
      iconUrl: 'https://static.qred.com/sv-se/bilder/icons8-trolley-500.svg'
    }
  ]}
  ...

Props

PropUsage
iconUse the icon layout or not default: false
choicesAn array of objects, with keys: label, value, iconUrl (See examples) default: []
selectedAn object with keys: label, value, iconUrl (See examples) default: {}
onChange()When a multiple choice item is clicked onChange will be called with the choice as the argument in the form of an object with keys: label, value, iconUrl

ProgressBar

Props

PropUsage
percentThe percent of the progress bar to be shown. Number between 0 & 100 default: null
labelThe label to go above the progress bar default: 'Profile strength: '
statusA status for the progress, changes to color of bar and percent value. Valid statuses 'success', 'warning', 'error' default: 'success'

Usage

import { ProgressBar } from '@qred/ui-components'

...

return (
  <ProgressBar
    percent={10}
    label={"The progress:"}
    status={"warning"}
  />
)
...

ThemeProvider & theme

Implements styled-components Themeprovider

Usage:

import { ThemeProvider } from 'styled-components'
import { Button, themes } from '@qred/ui-components';
...
render() {
  return (
    <ThemeProvider theme={themes.swagnes}>
      <Button>Press me! </Button>
    <ThemeProvider>
  )
}

Current theme: swagnes

Then in css files usage of theme variables:

import styled from 'styled-components';

export const Container = styled.div`
  background-color: ${props => props.theme.colors.primary};
`

Available theme options:

OptionUsage
props.theme.colors.primaryThe primary color of the theme
props.theme.colors.secondaryThe secondary color of the theme

swagnes theme

{
  colors: {
    primary: '#42D984',
    secondary: '#4C53FF',
    lightGreen: '#EAF9EE',
    grey: '#C4C4C4',
    greyText: '#989898',
    darkGrey: '#4E4E4E',
    white: '#fff',
    black: '#000',
    success: '#2EC185',
    warning: '#F5BB58',
    error: '#EB4C6A',
  },
  fontFamily: 'Poppins',
  maxContentWidth: '1080px',
}
0.11.6

5 years ago

0.11.7

5 years ago

0.11.5

5 years ago

0.11.4

5 years ago

0.11.3

5 years ago

0.11.2

5 years ago

0.11.1

5 years ago

0.11.0

5 years ago

0.10.0

5 years ago

0.9.0

5 years ago

0.8.5

5 years ago

0.8.4

5 years ago

0.8.3

5 years ago

0.8.2

5 years ago

0.8.1

5 years ago

0.8.0

5 years ago

0.7.1

5 years ago

0.7.0

5 years ago

0.6.10

5 years ago

0.6.9

5 years ago

0.6.8

5 years ago

0.6.7

5 years ago

0.6.6

5 years ago

0.6.5

5 years ago

0.6.4

5 years ago

0.6.3

5 years ago

0.6.2

5 years ago

0.5.2

5 years ago

0.5.1

5 years ago

0.5.0

5 years ago

0.4.0

5 years ago

0.3.3

5 years ago

0.3.2

5 years ago

0.3.1

5 years ago

0.3.0

5 years ago

0.2.8

5 years ago

0.2.7

5 years ago

0.2.6

5 years ago

0.2.5

5 years ago

0.2.4

5 years ago

0.2.3

5 years ago

0.2.2

5 years ago

0.2.1

5 years ago

0.2.0

5 years ago

0.1.9

5 years ago

0.1.8

5 years ago

0.1.7

5 years ago

0.1.6

5 years ago

0.1.5

5 years ago

0.1.4

5 years ago

0.1.3

5 years ago

0.1.2

5 years ago

0.1.1

5 years ago

0.0.9

5 years ago

0.0.8

5 years ago

0.0.7

5 years ago

0.0.6

5 years ago

0.1.0

5 years ago

0.0.5

5 years ago

0.0.4

5 years ago

0.0.3

5 years ago

0.0.2

5 years ago

0.0.1

5 years ago