0.14.17 • Published 17 days ago

@ledgerhq/react-ui v0.14.17

Weekly downloads
-
License
MIT
Repository
github
Last release
17 days ago

@ledgerhq/react-ui

build npm storybook

Design and interface resources for React

This package contains React components and styles built on top of our design system and used internally at Ledger.

Reference

🔗 Storybook

Installation

Package

npm i @ledgerhq/react-ui

Peer dependencies

This library uses styled components heavily and relies on it being installed separately (to avoid package duplication).

npm i styled-components

And (obviously) if React packages are not already installed:

npm i react react-dom

Usage

Provider

Before using the library components, the style provider must be imported and rendered once to provide the components with the right context.

import { StyleProvider } from "@ledgerhq/react-ui";

function Root({ children }) {
  // Selected theme palette can be either "dark" or "light".
  return <StyleProvider selectedPalette="light">{children}</StyleProvider>;
}

Components

Import the components from @ledgerhq/react-ui.

import { Text, Flex, Logos } from "@ledgerhq/react-ui";

function Hello() {
  return (
    <Flex flexDirection="column" alignItems="center" rowGap={12} p={12}>
      <Text color="neutral.c100">
        <Logos.LedgerLiveRegular />
      </Text>
      <Text variant="h1">Hello, world!</Text>
    </Flex>
  );
}

Fonts (optional but recommended)

Ledger fonts can be either imported or added manually to your project.

After picking a method add the fontsPath property to the StyleProvider component to automatically generate @font-face blocks and register the Inter and Alpha font families.

// Create a global css font style that will import the required fonts based on the fontsPath prefix.
<StyleProvider fontsPath="assets/fonts">

Import

Using the import requires you to use a bundler to export and save the files to the target folder.

import "@ledgerhq/react-ui/assets/fonts";

With webpack 5 the rule below will process the font files and save them in the src/assets/fonts folder.

{
  test: /\.woff2/,
  type: "asset/resource",
  generator: {
    filename: "assets/fonts/[name].woff2",
  },
},

Scoped Imports

If you are using a loader that saves the fonts with custom names (for instance when using create-react-app), you can use the fontMappings prop to map the font names.

// These imports return the path to the public folder where the loader saves the fonts during the build.
import HMAlphaMono from "@ledgerhq/react-ui/assets/fonts/HMAlphaMono-Medium.woff2";
import InterBold from "@ledgerhq/react-ui/assets/fonts/Inter-Bold.woff2";
import InterExtraBold from "@ledgerhq/react-ui/assets/fonts/Inter-ExtraBold.woff2";
import InterExtraLight from "@ledgerhq/react-ui/assets/fonts/Inter-ExtraLight-BETA.woff2";
import InterLight from "@ledgerhq/react-ui/assets/fonts/Inter-Light-BETA.woff2";
import InterMedium from "@ledgerhq/react-ui/assets/fonts/Inter-Medium.woff2";
import InterRegular from "@ledgerhq/react-ui/assets/fonts/Inter-Regular.woff2";
import InterSemiBold from "@ledgerhq/react-ui/assets/fonts/Inter-SemiBold.woff2";

// Map the font names with the file path.
const fontMap = {
  "HMAlphaMono-Medium": HMAlphaMono,
  "Inter-Bold": InterBold,
  "Inter-ExtraBold": InterExtraBold,
  "Inter-ExtraLight-BETA": InterExtraLight,
  "Inter-Light-BETA": InterLight,
  "Inter-Medium": InterMedium,
  "Inter-Regular": InterRegular,
  "Inter-SemiBold": InterSemiBold,
};

// The substring call is used to make the path relative (removes the prepending /).
const fontMappings = (name) => fontMap[name].substring(1);

/* … */

<StyleProvider fontPath="path/to/fonts" fontMappings={fontMappings}>

Manually

The .woff2 font files are located in the src/assets/fonts folder. You can host them yourself, use a CDN (see below) or process them with a bundler by importing them.

The important thing is to register fonts by adding @font-face blocks for the Inter and Alpha font families.

For instance using the unpkg.com CDN:

@font-face {
  font-family: "Alpha";
  src: url("https://unpkg.com/@ledgerhq/react-ui/assets/fonts/HMAlphaMono-Medium.woff2") format("woff2");
  font-weight: 100;
  font-style: normal;
}

Minimal Working Example

🌍 Hosted here.

Assuming dependencies, webpack and babel (or equivalents) are installed and configured.

import React from "react";
import ReactDOM from "react-dom";
import "@ledgerhq/react-ui/assets/fonts"; // all fonts are consumed by the bundler and outputted to /assets
import { StyleProvider, Text, Logos, Flex, Switch } from "@ledgerhq/react-ui";

function Root() {
  const [palette, setPalette] = React.useState("light");
  const isLight = palette === "light";

  return (
    <StyleProvider fontsPath="assets" selectedPalette={palette}>
      <Flex flexDirection="column" alignItems="center" rowGap={12} p={12}>
        <Text color="neutral.c100">
          <Logos.LedgerLiveRegular />
        </Text>
        <Text variant="h1">Hello, world!</Text>
        <Switch
          name="select-theme"
          checked={isLight}
          onChange={() => setPalette(() => (isLight ? "dark" : "light"))}
        />
      </Flex>
    </StyleProvider>
  );
}

ReactDOM.render(<Root />, document.getElementById("react-root"));

Contributing

Check the contributing guide here.

0.14.18-next.0

17 days ago

0.14.17

23 days ago

0.14.17-next.0

1 month ago

0.14.16

2 months ago

0.14.16-nightly.0

2 months ago

0.14.16-next.0

2 months ago

0.14.15

3 months ago

0.14.15-new-wc.0

3 months ago

0.14.15-nightly.4

3 months ago

0.14.15-nightly.3

3 months ago

0.14.15-wc-test.0

3 months ago

0.14.15-next.0

3 months ago

0.14.15-nightly.2

3 months ago

0.14.15-nightly.1

3 months ago

0.14.15-nightly.0

4 months ago

0.14.14

4 months ago

0.14.14-next.0

4 months ago

0.14.13

4 months ago

0.14.13-nightly.0

4 months ago

0.14.13-next.0

5 months ago

0.14.12-nightly.1

5 months ago

0.14.12

5 months ago

0.14.12-nightly.0

5 months ago

0.14.12-next.0

5 months ago

0.14.11

6 months ago

0.14.10

6 months ago

0.14.6-next.0

9 months ago

0.14.3-nightly.1

10 months ago

0.14.3-nightly.0

10 months ago

0.14.5-hotfix.0

9 months ago

0.14.6-nightly.0

9 months ago

0.14.10-nightly.2

6 months ago

0.14.11-next.0

6 months ago

0.14.10-nightly.1

6 months ago

0.14.10-nightly.0

7 months ago

0.14.10-tag-word.0

7 months ago

0.14.7-hotfix.0

9 months ago

0.14.5

9 months ago

0.14.6

9 months ago

0.14.7

9 months ago

0.14.8

8 months ago

0.14.9

8 months ago

0.14.2

10 months ago

0.14.3

10 months ago

0.14.4

10 months ago

0.14.4-nightly.0

10 months ago

0.14.4-nightly.1

10 months ago

0.14.4-nightly.2

9 months ago

0.14.4-next.0

9 months ago

0.14.8-next.0

9 months ago

0.14.10-next.0

6 months ago

0.14.5-next.0

9 months ago

0.14.3-next.0

10 months ago

0.14.11-nightly.0

6 months ago

0.14.11-nightly.3

6 months ago

0.14.8-nightly.1

8 months ago

0.14.8-nightly.2

8 months ago

0.14.11-nightly.1

6 months ago

0.14.11-nightly.2

6 months ago

0.14.8-nightly.0

9 months ago

0.14.4-hotfix.0

10 months ago

0.14.2-next.0

11 months ago

0.14.2-nightly.0

11 months ago

0.14.0

1 year ago

0.14.1

12 months ago

0.14.0-next.0

1 year ago

0.14.2-notarizer.0

11 months ago

0.14.1-nightly.0

12 months ago

0.14.2-nightly.1

11 months ago

0.14.1-next.0

12 months ago

0.13.0

1 year ago

0.12.0-next.0

1 year ago

0.13.0-next.0

1 year ago

0.12.1-next.0

1 year ago

0.11.0

1 year ago

0.12.0

1 year ago

0.12.1

1 year ago

0.11.0-next.0

1 year ago

0.10.5

1 year ago

0.10.2-next.0

1 year ago

0.10.0-next.0

1 year ago

0.10.4-next.0

1 year ago

0.10.1

1 year ago

0.10.2

1 year ago

0.10.3

1 year ago

0.10.3-next.0

1 year ago

0.10.4

1 year ago

0.10.1-next.0

1 year ago

0.10.0

1 year ago

0.10.0-nightly.2

2 years ago

0.10.0-nightly.3

2 years ago

0.9.2-next.0

2 years ago

0.9.2

2 years ago

0.9.2-nightly.0

2 years ago

0.9.1

2 years ago

0.10.0-ts-llm.0

2 years ago

0.9.3-nightly.0

2 years ago

0.10.0-nightly.1

2 years ago

0.9.0

2 years ago

0.9.1-next.0

2 years ago

0.9.1-nightly.0

2 years ago

0.9.0-next.0

2 years ago

0.8.3-next.0

2 years ago

0.8.2-next.0

2 years ago

0.8.1-next.0

2 years ago

0.8.0-next.0

2 years ago

0.7.8-next.0

2 years ago

0.7.9-nightly.0

2 years ago

0.8.2-nightly.0

2 years ago

0.8.2-nightly.1

2 years ago

0.7.8

2 years ago

0.7.7

2 years ago

0.8.1-yolo.0

2 years ago

0.8.1-nightly.2

2 years ago

0.8.1-nightly.1

2 years ago

0.8.1-nightly.0

2 years ago

0.8.1

2 years ago

0.8.0

2 years ago

0.8.0-nightly.0

2 years ago

0.8.3

2 years ago

0.9.0-nightly.0

2 years ago

0.8.2

2 years ago

0.7.6

2 years ago

0.7.6-nightly.0

2 years ago

0.7.7-esbuild.0

2 years ago

0.7.7-next.0

2 years ago

0.7.7-updater.0

2 years ago

0.7.7-nightly.0

2 years ago

0.7.5

2 years ago

0.7.5-monorepo.4

2 years ago

0.7.5-monorepo.3

2 years ago

0.7.5-monorepo.0

2 years ago

0.7.5-monorepo.1

2 years ago

0.7.2

2 years ago

0.7.1

2 years ago

0.7.4

2 years ago

0.7.3

2 years ago

0.3.0

2 years ago

0.2.0

3 years ago

0.5.0

2 years ago

0.4.0

2 years ago

0.3.1

2 years ago

0.7.0

2 years ago

0.6.0

2 years ago

0.1.1

3 years ago

0.1.0

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago