0.22.9 • Published 17 days ago

@ledgerhq/native-ui v0.22.9

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

@ledgerhq/native-ui

npm storybook

Design and interface resources for React Native

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

Reference

🔗 Storybook

Installation

Package

npm i @ledgerhq/native-ui

Peer dependencies

This library uses the following packages under the hood and relies on them being installed separately to avoid package duplication.

npm i styled-components react-native-reanimated react-native-svg

Additional setup

Follow the installation instructions for:

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/native-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/native-ui.

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

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

Fonts

Using Expo

expo install expo-font
import { useFonts } from "expo-font";

/*
  A higher-order component that will load and provide Ledger fonts to your app.
*/
function FontProvider({ children }) {
  const [fontsLoaded] = useFonts({
    "HMAlphaMono-Medium": require("@ledgerhq/native-ui/lib/assets/fonts/alpha/HMAlphaMono-Medium.otf"),
    "Inter-Medium": require("@ledgerhq/native-ui/lib/assets/fonts/inter/Inter-Medium.otf"),
    "Inter-SemiBold": require("@ledgerhq/native-ui/lib/assets/fonts/inter/Inter-SemiBold.otf"),
    "Inter-Bold": require("@ledgerhq/native-ui/lib/assets/fonts/inter/Inter-Bold.otf"),
  });

  if (!fontsLoaded) {
    return null;
  }

  return children;
}

React Native - Bare

Add the paths in the react-native.config.js file:

module.exports = {
  assets: [
    "node_modules/@ledgerhq/native-ui/lib/assets/fonts/alpha",
    "node_modules/@ledgerhq/native-ui/lib/assets/fonts/inter",
  ],
};

Then run the following command to add the required native code:

npx react-native link

Minimal Working Example

🌍 Hosted here.

Expo

import React from "react";
import { StyleProvider, Flex, Switch, Text, Logos } from "@ledgerhq/native-ui";
import { useTheme } from "styled-components/native";
import { useFonts } from "expo-font";

function Logo() {
  const theme = useTheme();
  return <Logos.LedgerLiveRegular color={theme.colors.neutral.c100} />;
}

function FontProvider({ children }) {
  const [fontsLoaded] = useFonts({
    "HMAlphaMono-Medium": require("@ledgerhq/native-ui/lib/assets/fonts/alpha/HMAlphaMono-Medium.otf"),
    "Inter-Medium": require("@ledgerhq/native-ui/lib/assets/fonts/inter/Inter-Medium.otf"),
    "Inter-SemiBold": require("@ledgerhq/native-ui/lib/assets/fonts/inter/Inter-SemiBold.otf"),
    "Inter-Bold": require("@ledgerhq/native-ui/lib/assets/fonts/inter/Inter-Bold.otf"),
  });

  if (!fontsLoaded) {
    return null;
  }

  return children;
}

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

  return (
    <FontProvider>
      <StyleProvider selectedPalette={palette}>
        <Flex
          flex={1}
          justifyContent="center"
          alignItems="center"
          flexDirection="column"
          backgroundColor="neutral.c00"
        >
          <Logo />
          <Text variant="h2" color="neutral.c100" my={10}>
            Hello, world!
          </Text>
          <Switch
            checked={isLight}
            onChange={() => setPalette(() => (isLight ? "dark" : "light"))}
          />
        </Flex>
      </StyleProvider>
    </FontProvider>
  );
}

React Native - Bare

import React from "react";
import { StyleProvider } from "@ledgerhq/native-ui";
import { Flex, Text, Logos, Switch } from "@ledgerhq/native-ui";
import { useTheme } from "styled-components/native";

function Logo() {
  const theme = useTheme();
  return <Logos.LedgerLiveRegular color={theme.colors.neutral.c100} />;
}

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

  return (
    <StyleProvider selectedPalette={palette}>
      <Flex
        flex={1}
        p={12}
        justifyContent="center"
        alignItems="center"
        flexDirection="column"
        backgroundColor="neutral.c00"
      >
        <Logo />
        <Text variant="h2" color="neutral.c100" my={10}>
          Hello, world!
        </Text>
        <Switch checked={isLight} onChange={() => setPalette(() => (isLight ? "dark" : "light"))} />
      </Flex>
    </StyleProvider>
  );
}
0.22.9

17 days ago

0.22.9-next.0

1 month ago

0.22.8

2 months ago

0.22.8-nightly.0

2 months ago

0.22.8-next.1

2 months ago

0.22.8-next.0

2 months ago

0.22.7

3 months ago

0.22.7-new-wc.0

3 months ago

0.22.7-nightly.2

3 months ago

0.22.7-nightly.1

3 months ago

0.22.7-wc-test.0

3 months ago

0.22.7-next.0

3 months ago

0.22.7-nightly.0

3 months ago

0.22.6

3 months ago

0.22.6-next.1

3 months ago

0.22.6-nightly.1

3 months ago

0.22.6-nightly.0

3 months ago

0.22.6-next.0

3 months ago

0.22.5

3 months ago

0.22.5-next.0

4 months ago

0.22.4-nightly.1

4 months ago

0.22.4

4 months ago

0.22.4-nightly.0

4 months ago

0.22.4-next.0

5 months ago

0.22.3-nightly.1

5 months ago

0.22.3

5 months ago

0.22.3-nightly.0

5 months ago

0.22.3-next.0

5 months ago

0.20.1

10 months ago

0.20.7-nightly.1

9 months ago

0.21.0-next.0

8 months ago

0.22.1-nightly.0

7 months ago

0.22.1-nightly.3

6 months ago

0.22.1-nightly.2

6 months ago

0.22.1-nightly.1

7 months ago

0.20.7-nightly.0

9 months ago

0.20.2-next.0

10 months ago

0.21.1

8 months ago

0.20.3-next.0

9 months ago

0.22.2-nightly.0

6 months ago

0.22.2-nightly.1

6 months ago

0.21.0

8 months ago

0.20.5-next.0

9 months ago

0.20.4-hotfix.0

9 months ago

0.20.3-nightly.0

10 months ago

0.20.3-nightly.1

9 months ago

0.20.3-nightly.2

9 months ago

0.22.2-next.0

6 months ago

0.22.1-next.0

6 months ago

0.22.0-next.0

8 months ago

0.22.2

5 months ago

0.22.1

6 months ago

0.22.1-tag-word.0

6 months ago

0.22.0

7 months ago

0.20.2-nightly.2

10 months ago

0.20.3-hotfix.0

10 months ago

0.20.2-nightly.0

10 months ago

0.20.2-nightly.1

10 months ago

0.21.0-nightly.2

9 months ago

0.22.0-nightly.0

8 months ago

0.20.4-next.0

9 months ago

0.21.0-nightly.4

8 months ago

0.21.0-nightly.3

8 months ago

0.20.5-nightly.1

9 months ago

0.20.5-nightly.2

9 months ago

0.20.5-nightly.0

9 months ago

0.20.6

9 months ago

0.20.5

9 months ago

0.20.4

9 months ago

0.20.3

10 months ago

0.20.2

10 months ago

0.20.6-hotfix.0

9 months ago

0.20.1-next.0

10 months ago

0.20.1-nightly.1

10 months ago

0.20.0

11 months ago

0.19.1-proto-test.0

12 months ago

0.20.1-nightly.0

11 months ago

0.19.1-next.0

12 months ago

0.19.0

12 months ago

0.19.1

12 months ago

0.19.0-next.0

1 year ago

0.20.1-notarizer.0

11 months ago

0.20.0-nightly.1

12 months ago

0.20.0-next.0

11 months ago

0.19.1-nightly.0

12 months ago

0.17.0

1 year ago

0.17.0-next.0

1 year ago

0.18.1

1 year ago

0.18.0

1 year ago

0.18.0-next.0

1 year ago

0.18.1-next.0

1 year ago

0.17.1-next.0

1 year ago

0.16.0-next.0

1 year ago

0.16.0

1 year ago

0.15.1

1 year ago

0.15.1-next.0

1 year ago

0.13.0

1 year ago

0.14.0

1 year ago

0.13.0-next.0

1 year ago

0.12.2-next.0

1 year ago

0.14.0-next.0

1 year ago

0.12.1-next.0

1 year ago

0.15.0

1 year ago

0.12.1

1 year ago

0.12.2

1 year ago

0.15.0-next.0

1 year ago

0.11.0

2 years ago

0.11.0-next.0

2 years ago

0.12.1-ts-llm.0

2 years ago

0.12.0-next.0

2 years ago

0.12.0

2 years ago

0.10.0

2 years ago

0.11.0-nightly.0

2 years ago

0.11.0-nightly.1

2 years ago

0.12.0-nightly.0

2 years ago

0.10.0-next.0

2 years ago

0.9.0

2 years ago

0.9.1-nightly.0

2 years ago

0.10.0-nightly.2

2 years ago

0.10.0-nightly.1

2 years ago

0.9.0-next.0

2 years ago

0.9.0-next.1

2 years ago

0.8.0-next.2

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.7.19-nightly.0

2 years ago

0.8.0-next.1

2 years ago

0.8.3-next.1

2 years ago

0.8.2-nightly.0

2 years ago

0.8.4-nightly.0

2 years ago

0.7.18

2 years ago

0.8.1-nightly.0

2 years ago

0.9.0-nightly.1

2 years ago

0.9.0-nightly.2

2 years ago

0.8.2-yolo.0

2 years ago

0.8.1

2 years ago

0.7.19-next.0

2 years ago

0.8.0

2 years ago

0.8.3

2 years ago

0.8.2

2 years ago

0.7.17

2 years ago

0.7.16

2 years ago

0.7.17-nightly.0

2 years ago

0.7.18-esbuild.0

2 years ago

0.7.18-nightly.0

2 years ago

0.7.18-next.0

2 years ago

0.7.18-updater.0

2 years ago

0.7.11

2 years ago

0.7.10

2 years ago

0.7.9

2 years ago

0.7.13

2 years ago

0.7.12

2 years ago

0.7.8

2 years ago

0.7.7

2 years ago

0.7.15

2 years ago

0.7.14

2 years ago

0.7.6

2 years ago

0.7.4-monorepo.3

2 years ago

0.7.5

2 years ago

0.7.4-monorepo.4

2 years ago

0.7.4-monorepo.0

2 years ago

0.7.4-monorepo.1

2 years ago

0.7.4

2 years ago

0.7.3

2 years ago

0.6.7

2 years ago

0.6.6

2 years ago

0.7.2

2 years ago

0.6.3

2 years ago

0.7.1

2 years ago

0.6.2

2 years ago

0.6.5

2 years ago

0.6.4

2 years ago

0.7.0

2 years ago

0.3.0

2 years ago

0.2.0

2 years ago

0.5.0

2 years ago

0.4.0

2 years ago

0.6.1

2 years ago

0.6.0

2 years ago

0.1.1

3 years ago

0.1.0

3 years ago