1.0.42 • Published 6 years ago

@omahoito/oda-ui-common v1.0.42

Weekly downloads
8
License
MIT
Repository
github
Last release
6 years ago

ODA 2 common UI library

This repository contains common UI components for ODA-applications, created with React and styled-components. This repository also acts as a living style guide for the ODA project.

Key technologies

Here are the key libraries used in the project.

LibraryDescription
reactUI-component library
styled-componentsReact primitives
storybookA UI to preview the components

Usage

Installation from NPM

Install the latest version of oda-ui-common as a dependency to your project by running:

npm install @omahoito/oda-ui-common

Theming

oda-ui-common components require a wrapping ThemeProvider-component, to inject theming-related props to the UI-components. A ThemeProvider passes theme properties to their children UI-components (all children, not just direct children).

You can have as many ThemeProviders in your application as you want, but you should probably have one at the top-level of your app. By default, ThemeProvider uses the default theme bundled with the app, but you can also pass a custom theme, which is just an object.

If you want to create your own themes, you can use oda-ui-common/src/themes/defaultTheme.js as your basis.

Here is an example of using the themeProvider with the default theme:

import React from 'react'
import {render} from 'react-dom'
import {ThemeProvider, P} from '@omahoito/oda-ui-common'

render(
    <ThemeProvider>
        <P>Hello, world!</P>
    </ThemeProvider>,
    document.querySelector('#app')
)

And here with a custom theme:

import React from 'react'
import {render} from 'react-dom'
import {ThemeProvider, P, defaultTheme} from '@omahoito/oda-ui-common'

const customTheme = {
    ...defaultTheme:
    myCustomComponent: {
        text: 'pink'
    }
}

render(
    <ThemeProvider theme={customTheme}>
        <P>Hello, world!</P>
    </ThemeProvider>,
    document.querySelector('#app')
)

Recommended global styles

While the vast majority of styles in this repository are self contained, some styles are intentionally left out of repository, such as fonts and normalizations.

We recommend the following global styles to be used with the defaultTheme:

*, *::before, *::after {
  box-sizing: border-box;
}

body {
  font-family: 'Gill Sans', sans-serif;
  font-size: 16px;
  font-weight: normal;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

Using normalize.css or equivalent is also highly recommended.

Fonts

We recommend the font Gill Sans to be used with the default theme. This font is not included in the package, and it must be downloaded and licensed separately.

These are the font-weight mappings used in oda-web-front:

Font-weightFont
300Gill Sans Light
500 / normalGill Sans Book
700 / boldGill Sans Medium

Local installation

If you want to contribute to oda-ui-common, you should clone the repository and compile the components locally.

Node.js is needed to run the front-end build. You can download it from here. Version 8.0.0 or above is recommended.

All project dependencies are listed in package.json. To install them you need NPM (installed automatically with Node.js).

Once you have installed Node.js, run this command in the root folder (the one that contains file package.json) of the project to install project's dependencies:

npm install

Some dependencies are marked as peer dependencies. These need to be installed separately. You can either install each one or use a utility, like npm-install-peers:

npm install -g npm-install-peers
npm-install-peers

Building the project

To build the project run

npm run build

Storybook

To launch the style guide UI locally, run

npm run storybook

This will start a local server on port 6006.

Other scripts

All of these scripts can be run with "npm run script name"

ScriptDescription
lintRuns eslint linter (see .eslinrc.json for linting settings)
cleanRemoves dist/-folder
startRuns babel build in watch-mode
deploy-storybookPush master to gh-pages branch

Contributing to the project

Guidelines

  1. Follow atomic web design principles
  2. All inputs should be controlled components
  3. Avoid writing stateful components

Folder structure

FolderDescription
/Project root, build configuration files
/srcApplication source codes
/src/atomsPrimitive components
/src/atoms/typeAtomic components of similar type (e.g. "button")
/src/molecules/Components, combinations of atoms
/src/molecules/typeMolecular components of similar type (e.g. "form")
/src/themesDefault theme and themeProvider-component

Naming conventions

Here is an example of file naming conventions. For example, the contents of an imaginary /src/atoms/button -folder might look like this

FileDescription
buttonWithIcon.jsExports ButtonWithIcon-component as default
bigRoundButton.jsExports BigRoundButton-component as default
button.story.jsStory file for the components of this folder
index.jsExports ButtonWithIcon and BigRoundButton as named exports

Publishing to NPM

To publish the package to NPM, you must be a member of the Omahoito-organization in NPM.

If you already are a member of the organization, you can publish the package using these commands:

npm version patch
npm publish
git push

NPM version patch will increase the version and automatically create a Git-tag for the new version. The tag should be pushed to git after a succesful publish.

Versioning

Versioning follows SemVer guidelines.

1.0.42

6 years ago

1.0.41

6 years ago

1.0.40

6 years ago

1.0.39

6 years ago

1.0.38

6 years ago

1.0.37

6 years ago

1.0.36

6 years ago

1.0.34

6 years ago

1.0.33

6 years ago

1.0.32

6 years ago

1.0.31

6 years ago

1.0.30

6 years ago

1.0.29

6 years ago

1.0.28

6 years ago

1.0.27

6 years ago

1.0.26

6 years ago

1.0.25

6 years ago

1.0.24

6 years ago

1.0.23

6 years ago

1.0.22

6 years ago

1.0.20

6 years ago

1.0.19

6 years ago

1.0.18

6 years ago

1.0.16

6 years ago

1.0.15

6 years ago

1.0.14

6 years ago

1.0.13

6 years ago

1.0.12

6 years ago

1.0.11

6 years ago

1.0.10

6 years ago

1.0.9

6 years ago

1.0.8

6 years ago

1.0.7

6 years ago

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago