0.4.5 • Published 5 months ago

@gyldendal/kobber-icons v0.4.5

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

SVG icons

Icons can be used as react components or as web components. TypeScript definitions are included.

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

Usage

Installation

Run one of the following commands to add @gyldendal/kobber-icons to your project:

npm install @gyldendal/kobber-icons
yarn add @gyldendal/kobber-icons

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

Using the svgs

Icons can be imported as react components, as web components, or as an SVG sprite.

As a react component

import { IconArrowRight } from "@gyldendal/kobber-icons/react";
const App = () => <ArrowRight />;

As a custom element

<script>
  import "@gyldendal/kobber-icons/web-components";
</script>
<kobber-arrow_right />

Custom element icon names are prefixed with kobber-, to ensure valid naming.

Use sprite directly

Include the sprite @gyldendal/kobber-icons/symbols/kobber-icons.svg in your html, and reference its symbols. The file @gyldendal/kobber-icons/symbols/kobber-icons-lists.ts contains a list of all icons and a type declaration, which can be useful.

Symbol ids are prefixed with kobber-, to avoid collisions with any other id in the html (including svg symbols in other sprites).

(Note that such ID references do not currenly work across the shadow dom barrier.)

<svg role="presentation" aria-hidden="true">
  <use href="#kobber-arrow_right" />
</svg>

Styling

Color

Icons have fill=currentcolor. This means the icon components' color will inherit from their parent element.

Size

Icons take the size prop for sizing (in react: iconSize).

Example in React:

import { User } from "@gyldendal/kobber-icons/dist/react-ssr-safe";
<User iconSize="large" />;

Other styling

Web components

Each icon web component :host is display: flex;, as this is useful for most usages. As this style is on the :host selector, consumers are free to override that style on the icon component container (when, for example, inline styling is required).

Likewise, other styles can be applied to the icon component container, like stroke or stroke width.

Styling react components

These are injected as SVG elements into HTML. This means you can style the SVG element the same way you style HTML elements.

🧱 Icons folder structure

/
└── chunks/
│   └── chunk-[hash].js
└── react/
│   ā”œā”€ā”€ index.js
│   └── index.d.ts
└── symbols/
│   ā”œā”€ā”€ kobber-icons.svg
│   └── kobber-icons-lists.ts
└── web-components/
    ā”œā”€ā”€ index.js
    └── index.d.ts

Development

⚔ Quick how to: Update icons

  1. Get all current icons from DAM:
    • Download from DAM, or
    • Recieve svgs from a colleague with access to DAM.
  2. Delete all content in folder kobber/packages/kobber-icons/src/assets/svgs.
  3. Extract svgs to folder kobber/packages/kobber-icons/src/assets/svgs.
  4. Run yarn build.
  5. Commit changes, and publish according to changeset.

Building icons

yarn build runs the svg script, and then the tsup script.

Script svg

svg uses the package svg-sprite to make the sprite ./symbols/kobber-icons.svg from all icons in src/assets/svgs folder.

svg-sprite uses ./svg-sprite-config.json to generate the sprite containing each icon as an svg symbol.

For each svg symbol, this config file:

  • prefixes its id with kobber- (to avoid collisions with any other id in the html, including svg symbols in other sprites)
  • ensures currentcolor is used as fill color

Script tsup

In ./tsup.config.ts, the sprite is used as input for making ./symbols/kobber-icons-lists.ts, the all icon components and their story files.

Generated files

All files in folders (chunks, react, symbols and web-components) are auto generated and should never be edited manually.

0.3.75

8 months ago

0.3.74

8 months ago

1.0.0

6 months ago

0.3.73

8 months ago

0.3.72

8 months ago

0.3.71

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.4

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.44

1 year ago

0.3.43

1 year ago

0.3.42

1 year ago

0.3.41

1 year ago

0.3.40

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.31

1 year ago

0.3.30

1 year ago

0.3.29

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.20

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