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

@statisticsnorway/ssb-component-library

v2.4.3

Published

Component library for SSB (Statistics Norway)

Downloads

522

Readme

SSB Component Library

npm version

The SSB component library is developed mainly for developers at SSB. Visit the documentation page to see all available components and how to use them.


Usage

Installing library

If you want to use the component library in your project, simply install it from npm.

$ npm install @statisticsnorway/ssb-component-library --save

Use components

Every component is developed to support being used as React components or as HTML by downloading the bundled CSS. Regardless of which way you use it, you need to import the stylesheet at the top of your project. You can do this either in the top javascript file, or in the top scss file. If using the library as a module, we recommend importing the main scss file, If you want to only apply the CSS, you can download the bundled CSS stylesheet and add it to your project.

If your project uses React, just use the module as you usually would use an external react component.

import { Button } from '@statisticsnorway/ssb-component-library'
;<Button onClick={callback} primary>
  Click me!
</Button>

If you only use HTML and CSS, look at the documentation for the specific component to make sure you get the class names right. Use them precisely to ensure you get all the appropriate styles.

<button class="ssb-button primary-btn">Click me</button>

You can find all available components here with the needed descriptions of how to use. You can also find this at the website (only in Norwegian for now).

Contributing

Run project locally

... clone repository ...
$ npm install
$ npm start

This will open storybook where you can develop components in an isolated environment.

How to start working on a feature

$ git checkout master
$ git pull
$ git checkout -b add-feature-x
... do changes ...
$ git commit -a -m "detailed commit message"
$ git status
... verify that correct files are included ...
$ git push -u origin add-feature-x
... create pull-request to master ...

Publish to NPM

Merge to master will automatically publish to NPM if version number in package.json is updated.

Development

Components

Components are written in React using the JSX syntax. Components should be written as functions, as opposed to classes, and if a local state or event handler is needed you should take use of the Hooks API.

As a way to ensure that our components are being used they way we intended, we use PropTypes to check properties being passed to components. All components with props available should have this.

One of the requirements for the components is that they should be able to render with the desired design using only HTML. Please develop components with that in mind. Some projects will only extract the stylesheet and apply the class names to receive styling, while handling interactions on their own. Always develop with this in mind.

Storybook

Storybook is an open source tool for developing UI components in an isolated environment. It is also a useful tool for demoing components by themselves or put together into a user scenario. To add a component to the storybook build, create a file named like componentName.story.jsx. Import some needed modules, the component you are creating the story for, and add it like this:

import React from 'react'
import { storiesOf } from '@storybook/react'
import centered from '@storybook/addon-centered/react'
import Button from './index'

storiesOf('Button', module)
  .addDecorator(centered)
  .add('Primary button', () => (
    <div>
      <Button text='Primary' primary />
      <Button text='Disabled' primary disabled />
    </div>
  ))

Every new instance of storiesOf creates a new menu item in the storybook. When using the add, it creates an item in a sub menu.

Testing

Testing is done with Jest and React testing library. Write unit tests for all components and aim for a 100% test coverage. Do no test component internals and state. Test on actual ouput on what user experiences. To run the tests, simply run npm test. To run tests without using any cache, run npm run clean-test. If you need to replace outdated screenshots, run npm run clear-tests.

Here is a cheat sheet for Jest.

Here is a cheat sheet for Testing library.

Styling

Styling is done with SCSS. You should familiarise yourself just a bit with the stylelint configuration, but it's pretty manageable. Just make sure you stick to the color variables specified in the variables document to make maintenance and potential changes easier.