0.4.5 • Published 5 months ago

@gyldendal/kobber-components v0.4.5

Weekly downloads
-
License
MIT
Repository
github
Last release
5 months ago

Component library

Components can be used as React components or as web components. TypeScript definitions are included.

See also https://kobber.gyldendal.no/komponenter.

Installation

npm install @gyldendal/kobber-components

Depending on you usage, you might need to to install the optional peerDependencies.

Fonts

Components specifically sets font-family. You should download the fonts from DAM, add them to public folder and add the following CSS:

@font-face {
  font-family: "pp mori";
  src: url("./PPMori-Regular.woff2");
}

@font-face {
  font-family: "lyon display";
  src: url("./LyonDisplay-Regular-Web-2.woff2");
}

@font-face {
  font-family: "inter";
  src: url("./InterVariable.ttf");
}

:root {
  /* Kobber default font is PP Mori */
  font-family: "pp mori", Arial, sans-serif;
}

See also https://kobber.gyldendal.no/merkevare/typografi.

Usage

Components can be imported as React components or as web components.

As a React component:

import { ProgressBar } from "@gyldendal/kobber-components/react";
const App = () => <ProgressBar />;

As a custom element:

<script>
  import "@gyldendal/kobber-components/web-components";
</script>
<kobber-progress-bar />

As a web component:

import { ProgressBar } from "@gyldendal/kobber-components/web-components";
const progressBar = new ProgressBar();
document.body.appendChild(progressBar);

CSS

We recommend using normalize.css or something similar to normalize browser styles.

Development

When developing components it's usually best to run storybook from root, and see changes live:

cd ../..
yarn storybook

If you're building a React-component used in the docs app, you need to build the component every time you make a change:

yarn dev

Create components

For maintainability, components should be created to consume data as children rather than props. By using props for all data, the amount of component props over time will grow unmaintanable. Most likely, you will end up with a component that needs to accept children components as props (while having to maintain possibly deprecated data props).

Example of component consuming data as children:

<RadioGroup
  label="Format"
  onChange={(value) => setValue(value)}
  currentValue={value}
  direction="horizontal" // eller vertical
>
  <RadioInput group="format" value="hardcover">Innbundet</RadioInput>
  <RadioInput group="format" value="pocket">Pocket</RadioInput>
  <RadioInput group="format" value="ebook">Ebok</RadioInput>
  <RadioInput group="format" value="audiobook">Lydbok</RadioInput>
</RadioGroup>

Example of component consuming data as props:

<RadioGroup
  label="Format"
  group="format"
  onChange={(value) => setValue(value)}
  currentValue={value}
  direction="horizontal" // eller vertical
  options={[
    { label: "Innbundet", value: "hardcover" },
    { label: "Pocket", value: "pocket" },
    { label: "Ebok", value: "ebook" },
    { label: "Lydbok", value: "audiobook" }
  ]}
/>

Publish components

After creating a new component, do the following steps to expose it to the world:

  1. Export it from src/index.react.tsx and src/index.web-components.ts.
  2. Run yarn build.
  3. Commit changes, and publish according to changeset.

Prerequisites

  • Make your own npm user (like olabaloo). You should get a token (to use in next step), and set up using an authenticator app.
  • In an .npmrc file in your personal home folder: Add //registry.npmjs.org/:_authToken=<token>

Versioning

  • We always publish all packages (also unchanged ones). This enforces all packages to always have same verion number, which eases troubleshooting.
  • First, decide whether your change is breaking, major, minor, or a patch. When publishing: if yor are uncertain: choose patch. Progress by clicking enter (regardless of whether you have made a selection).

Regret published version

Revert the version in your package.json (to a number not previously published on NPM):

{
  "version": "0.3.88"
}

Run:

git add package.json
git commit -m "Revert version bump"
npm publish

Keep it stable

After a component is published, its storybook story may be embedded elsewhere (perhaps in docs). The story embed url is based on the story name and its folder name. Therefore: try not to change name of components and stories after publication.

0.3.75

8 months ago

0.3.74

8 months ago

1.0.0

6 months ago

0.3.72

8 months ago

0.3.70

8 months ago

0.3.79

7 months ago

0.3.78

8 months ago

0.3.77

8 months ago

0.3.76

8 months ago

0.3.64

10 months ago

0.3.63

10 months ago

0.3.62

10 months ago

0.3.61

10 months ago

0.3.60

10 months ago

0.3.69

8 months ago

0.3.68

9 months ago

0.3.67

9 months ago

0.3.66

9 months ago

0.3.65

9 months ago

0.3.53

11 months ago

0.3.52

11 months ago

0.3.51

11 months ago

0.3.50

11 months ago

0.3.59

11 months ago

0.3.58

11 months ago

0.3.57

11 months ago

0.3.56

11 months ago

0.3.55

11 months ago

0.3.54

11 months ago

0.3.86

6 months ago

0.3.85

7 months ago

0.3.84

7 months ago

0.3.83

7 months ago

0.3.82

7 months ago

0.3.81

7 months ago

0.3.80

7 months ago

0.3.49

11 months ago

0.3.48

11 months ago

0.3.47

11 months ago

0.3.87

6 months ago

0.4.5

5 months ago

0.4.1

6 months ago

0.4.0

6 months ago

0.4.3

5 months ago

0.4.2

5 months ago

0.3.46

12 months ago

0.3.45

1 year ago

0.3.31

1 year ago

0.3.30

1 year ago

0.3.39

1 year ago

0.3.38

1 year ago

0.3.37

1 year ago

0.3.36

1 year ago

0.3.35

1 year ago

0.3.34

1 year ago

0.3.33

1 year ago

0.3.32

1 year ago

0.3.29

1 year ago

0.3.20

1 year ago

0.3.28

1 year ago

0.3.27

1 year ago

0.3.26

1 year ago

0.3.25

1 year ago

0.3.24

1 year ago

0.3.23

1 year ago

0.3.22

1 year ago

0.3.21

1 year ago

0.3.19

1 year ago

0.3.18

1 year ago

0.3.17

1 year ago

0.3.16

1 year ago

0.3.15

1 year ago

0.3.14

1 year ago

0.3.13

1 year ago

0.3.42

1 year ago

0.3.41

1 year ago

0.3.40

1 year ago

0.3.44

1 year ago

0.3.43

1 year ago

0.3.12

1 year ago

0.3.11

1 year ago

0.3.10

1 year ago

0.3.9

1 year ago

0.3.8

1 year ago

0.3.7

1 year ago

0.3.6

2 years ago

0.3.5

2 years ago

0.3.3

2 years ago

0.3.0

2 years ago

0.3.2

2 years ago

0.3.1

2 years ago

0.2.0

2 years ago

0.1.0

2 years ago

0.0.1

2 years ago