1.1.27 • Published 2 months ago

@digitalfactory/react-native-components v1.1.27

Weekly downloads
-
License
-
Repository
-
Last release
2 months ago

DF Design System React Native

This project can be ran on your local machine using iOS simulator.

Installing the library into your React Native project

Requirements

  • react >=16.0
  • react-native >=0.63.0
  • react-native-device-info >=10.9.0 (npm install react-native-device-info)
  • react-native-svg >=12.1.0 (npm install react-native-svg)
  • phosphor-react-native >=1.1.1 (npm install phosphor-react-native)
  • @react-native-clipboard/clipboard >=1.7.0 (npm install @react-native-clipboard/clipboard)
  • @react-native-picker/picker >=2.4.0 (npm install @react-native-picker/picker)
  • react-native-picker-select >=8.0.4 (npm install react-native-picker-select)
  • react-native-gesture-handler >=2.8.0 (npm install react-native-gesture-handler)
  • @react-native-async-storage/async-storage >=1.13.3 (npm install @react-native-async-storage/async-storage)
  • @react-navigation/native 6.1.7 (npm install @react-navigation/native@6.1.7)
  • @react-navigation/stack 6.3.17 (npm install @react-navigation/stack@6.3.17)

Install the library:

npm install --save @digitalfactory/react-native-components

For iOS, use cocoapods to link the packages:

npx pod-install

or alternatively:

cd ios &&
pod install &&
cd ..

Running the Design System for local development

Environment

  • nodejs 14 or greater
  • watchman (brew install watchman on mac osx)
  • xcode 14.3
  • cocoapods (sudo gem install cocoapods on maxc osx)
  • ruby v2.7.4

Install dependencies

npm install

For iOS, use cocoapods to link the packages:

npx pod-install

or alternatively:

cd ios &&
pod install &&
cd ..

Running on Simulator

npm start to start Metro, the JavaScript bundler that ships with React Native. Metro takes in an entry file and various options, and returns a single JavaScript file that includes all your code and its dependencies

npm run ios to run app in ios simulator

Debugging

see React Native debugging

npm run debug to start (React Developer Tools)https://reactnative.dev/docs/debugging#react-developer-tools

open Developer Menu on simulator

Select Debug to launch http://localhost:8081/debugger-ui/ in browser, open devtools to see console logs and set break points

Usage

Available components:

useColors hook

The useColors hook provides you with a way to access the colours in our Figma Design System here. It uses React Native's useColorScheme hook to determine whether or not the user is in dark mode, and therefore which colour code to return for a selected colour. To see the list of colours and their associated hex codes, see here.

For example colors.greenApple would return the "#3F923C" hex color code. However if the user's mobile was in dark mode then "#54B450" would have been returned.

The colour names used by the hook were converted from hex using veli.ee/colorpedia.

Example usage

import { useColors } from "@digitalfactory/react-native-components";

const colors = useColors();
const primaryBlue = colors.blueScience;

Button

The Button component provides you with a way to use the buttons in our Figma Design System here. It is built on top of React Native's Pressable component and supports the icons in our Figma Design System which are based off of Phosphor Icons.

Example usage

import { Button } from "@digitalfactory/react-native-components";
import { PencilSimple } from "phosphor-react-native";

<Button
  buttonType="primaryRounded"
  text="Edit"
  icon={PencilSimple}
  onPress={() => console.log("clicked edit button!")}
/>

// You could provide child elements if you prefer:
<Button
  onPress={() => console.log("clicked button!")}
  buttonType="secondaryRounded">
  <View style={{ flexDirection: "row", alignItems: "center" }}>
    <PencilSimple color="#999999" size={20} weight="fill" />
    <Text
      accessible
      style={{
        fontSize: 16,
        fontWeight: "600",
        lineHeight: 20,
        color: "#999999",
        marginLeft: 12,
      }}>
      w/ child els
    </Text>
  </View>
</Button>

Props

Inherits all React Native Pressable props. All props in the table below are optional.

NameTypeDefaultDescription
buttonTypestring (one of: primarySquare, primaryRounded, primaryRoundLarge, primaryRoundSmall, secondarySquare, secondaryRounded, secondaryRoundLarge, secondaryRoundSmall, tertiarySquare, tertiaryRounded)"primarySquare"Defines the button's default style.
childrenReact.ReactNodeChild elements for the button.
accessibilityLabelstring"button"Overrides the text that's read by the screen reader when the user interacts with the element.
accessibilityHintstring"Button"Helps users understand what will happen when they perform an action on the button.
disabledbooleanfalseWhether or not the button is in a disabled state.
icon({ weight, color, size, style, mirrored }: IconProps) => JSX.Element or JSX.Element or React.ReactElementIcon to use for the button. Supports Phosphor Icons.
iconPositionstring (one of: left or right)"left"Whether the icon should be left-aligned or right-aligned in relation to the button text.
iconPropsIconProps (see the phosphor-react-native package for more info)Phosphor icon props to customise the phosphor icon style.
textstringThe button text.
buttonStyleViewStyleCustom styles to apply on the button.
pressedButtonStyleViewStyleCustom styles to apply on the button when it is in a 'pressed' state.
textStyleTextStyleCustom styles to apply on the button's text element.

Icon

The Icon component provides default styling for commonly used icons, and icons that are not available in the Phosphor Icons library.

Example usage

import { Icon } from "@digitalfactory/react-native-components";

<View
  style={{
    aspectRatio: 1,
    width: 34,
    height: 34,
    padding: 5,
  }}>
  <Icon.CheckCircle color="#0058DB" />
</View>

Props

The icons all accept a color prop. To change the size of the icon, the icon should be wrapped in a View component which has a style of aspectRatio: 1. Then change the width and height as required.

InputAccessoryView

The InputAccessoryView is a component that can be used to display a view above the keyboard (or input selector) whenever an input has focus. It has previous and next arrows and a done button.

Example usage

import { InputAccessoryView } from "@digitalfactory/react-native-components";

<InputAccessoryView
  id="unique-id"
  onPressPrevious={() => inputRefPrev.current?.focus()}
  onPressNext={() => inputRefNext.current?.focus()}
/>

Props

All props in the table below are optional.

NameTypeDefaultDescription
idstringAssigns a unique ID to the InputAccessoryView
previousDisabledbooleanfalseWhether or not to disable the previous arrow button
nextDisabledbooleanfalseWhether or not to disable the next arrow button
onPressPrevious() => void() => nullFunction to execute when the previous button is pressed
onPressNext() => void() => nullFunction to execute when the next button is pressed
onPressDone() => void() => Keyboard.dismiss()Function to execute when the done button is pressed
useInputAccessoryViewbooleantrueWhether or not to use React Native's InputAccessoryView

InputContainer

The InputContainer component provides a way of giving an input field a label, assistive text and status-related (e.g. error) text messages.

Example usage

import React, { useState } from "react";
import { KeyboardAwareScrollView } from "react-native-keyboard-aware-scroll-view";
import { InputContainer, TextInput } from "@digitalfactory/react-native-components";

const TextInputExample = (): React.ReactElement => {
  const [value1, setValue1] = useState("");

  return (
    <KeyboardAwareScrollView keyboardShouldPersistTaps="handled">
      <InputContainer
        labelText="Input Label"
        assistiveTextTop="Example assistive text for a required input"
        required
      >
        <TextInput
          onChangeText={setValue1}
          placeholder="Placeholder text"
          value={value1}
        />
      </InputContainer>
    </View>
  );
};

Props

All props in the table below are optional.

NameTypeDefaultDescription
assistiveTextTopstringGray assistive text to display above the input field
assistiveTextBottomstringGray assistive text to display below the input field
childrenReact.ReactNodeThe child elements (i.e. input field) for the component
containerStyleViewStyleOverride the default container styles
labelTextstringThe label for your input field
requiredbooleanfalseDisplays a red asterisk on the label for mandatory fields
showCharactersRemaining{ currentCount: number; maxCount: number; }Displays the current field length count against the max
statusTextStatusText[]Displays any status text below the input field

Loader

The Loader component provides loading/spinner components that can be used for when you need to display a loading state.

Example usage

import { Loader } from "@digitalfactory/react-native-components";

const { ActivityIndicator, FadeSpinner } = Loader;

<View>
  <FadeSpinner size={75} color="blue" />
</View>

<View>
  <ActivityIndicator size="large" color="red" />
</View>

Props

FadeSpinner
NameTypeDefaultDescription
animatingbooleantrueShow (true) or hide (false) the loading spinner
sizenumber60Defines the width and height of the spinner (pixels)
colorstringgrayCod (from the useColors hook - "#1D1D1D")Color of the spinner
ActivityIndicator

See: React Native ActivityIndicator.

Modal

The Modal component provides a generic customisable dialog box/popup window that is based on React Native's Modal component. It sets some sensible style defaults on the modal which can be overriden as required.

Example usage

import React, { useState } from "react";
import { Button, Modal, useColors } from "@digitalfactory/react-native-components";

const SimpleModal = (): React.ReactElement => {
  const colors = useColors();
  const [showModal, setShowModal] = useState(false);

  return (
    <View>
      <Button
        buttonType="primaryRounded"
        onPress={() => setShowModal(!showModal)}
        text="Show simple modal"
      />
      <Modal visible={showModal}>
        <Text style={{ color: colors.grayCod, fontSize: 16, marginBottom: 16 }}>
          Simple modal example
        </Text>
        <Button buttonType="primaryRounded" text="Close" onPress={() => setShowModal(false)} />
      </Modal>
    </View>
  );
};

Props

Inherits all React Native Modal props in addition to the below. All props in the table below are optional.

NameTypeDefaultDescription
childrenReact.ReactNodeChild elements / content to display within the modal
showOverlaybooleantrueWhether or not to show the full-screen modal overlay
wrapperStyleViewStyleOverride the default wrapper styles
modalStyleViewStyleOverride the default modal styles

SelectInput

The SelectInput component is based off of react-native-picker-select and provides you with an input which allows you to select one of multiple options.

To use this component, make sure you have installed both the react-native-picker-select and @react-native-picker/picker packages.

Example usage

import React, { useState } from "react";
import { View } from "react-native";
import { SelectInput } from "@digitalfactory/react-native-components";

const SelectInputExample = (): React.ReactElement => {
  const [value1, setValue1] = useState("");

  const items = [
    { label: "Football", value: "football" },
    { label: "Baseball", value: "baseball" },
  ];

  return (
    <View>
      <SelectInput
        items={items}
        onValueChange={(val) => setValue1(val)}
        value={value1}
      />
    </View>
  );
};

Props

The component accepts all props as per: react-native-picker-select, except for the following:

  • Icon - instead use iconLeft or iconRight (see below table).
  • InputAccessoryView - instead use inputAccessoryViewProps (see here for available options) to pass props to the InputAccessoryView.

The component also accepts the following props, all of which are optional:

NameTypeDefaultDescription
containerStyleViewStyleAllows you to override the default container style
disabledbooleanfalseWhether or not the component is in a disabled state
focusRingColorstring"#0058DB"Allows you to override the default focus ring colour
hideInputAccessoryViewbooleanfalseWhether or not to hide the InputAccessoryView
iconLeftReact.ComponentTypeLeft icon to display on the component
iconRightReact.ComponentType(Phosphor icon's CaretDown)Right icon to display on the component
inputAccessoryViewPropsInputAccessoryViewPropsProps to pass to the InputAccessoryView. See here for available options
onOpen() => voidFunction to call when the input opens / recieves focus
onClose() => voidFunction to call when the input closes / loses focus
status"success""warning""error"Status for the input - will display a coloured ring around the input

TextInput

The TextInput component is based off of React Native's TextInput and provides a way for the user to input text via the keyboard.

Example usage

import React, { useState } from "react";
import { KeyboardAwareScrollView } from "react-native-keyboard-aware-scroll-view";
import { TextInput } from "@digitalfactory/react-native-components";

const TextInputExample = (): React.ReactElement => {
  const [value1, setValue1] = useState("");

  return (
    <KeyboardAwareScrollView keyboardShouldPersistTaps="handled">
      <TextInput
        onChangeText={setValue1}
        placeholder="Placeholder text"
        value={value1}
      />
    </View>
  );
};

Props

The component accepts all props as per: React Native's TextInput, as well as the following props which are all optional:

NameTypeDefaultDescription
containerStyleViewStyleAllows you to override the default container style
disabledbooleanfalseWhether or not the component is in a disabled state
elementLeftReact.ComponentTypeElement to display on the left side of the input
elementRightReact.ComponentTypeElement to display on the right side of the input
focusRingColorstring"#0058DB"Allows you to override the default focus ring colour
hideInputAccessoryViewbooleanfalseWhether or not to hide the InputAccessoryView
inputAccessoryViewPropsInputAccessoryViewPropsProps to pass to the InputAccessoryView. See here for available options
inputStyleTextStyleAllows you to override the default input style
multilinebooleanfalseWhether or no the component should be multiline (like textarea)
numberOfLinesnumber1. Defaults to 4 if multiline is trueThe number of lines for the component (determines height of the component)
onBlurFunctionFunction to call on blur of the input
onFocusFunctionFunction to call on focus of the input
status"success""warning""error"Status for the input - will display a coloured ring around the input

Toast

The Toast notification component is based off of react-native-toast-message and displays brief a message to the user at the top of the page.

Example usage

Render the Toast component in your app's entry file, as the LAST CHILD in the View hierarchy (along with any other components that might be rendered there):

// App.tsx
import { Toast } from "@digitalfactory/react-native-components";

export function App(props) {
  return (
    <>
      {/* ... */}
      <Toast />
    </>
  );
}

Then use it anywhere in your app by calling any Toast method directly:

// Foo.tsx
import { Button, Toast } from "@digitalfactory/react-native-components";

export function Foo(props) {
  const showToast = () => {
    Toast.show({
      type: "success",
      text1: "Positive Message",
    });
  }

  return (
    <Button
      onPress={showToast}
      text="Show success toast"
      buttonType="primarySquare"
    />
  )
}

API

The component methods and props are the same as described in the react-native-toast-message documentation here, with a couple of differences:

  1. The type option of the Toast.show method has the available values: success, warning, error and info
  2. The text2 option of the Toast.show method has no effect. This is because there are no requirement to support this currently. Put any text you want in the text1 option.

Props

Some additional props can be passed into the Toast.show options object under the props property:

NameTypeDefaultDescription
hideCloseBtnbooleanfalseHides the 'X' close icon
textElReact.ComponentType (Text)Pass in a custom Text component, e.g. if needing to style text
btn1TextstringText for the first Toast button, if needed
btn1AccessibilityLabelstringAccessibility label for the first Toast button
btn1AccessibilityHintstringAccessibility hint for the first Toast button
onPressBtn1FunctionFunction to call on press of the first Toast button
btn2TextstringText for the second Toast button, if needed
btn2AccessibilityLabelstringAccessibility label for the second Toast button
btn2AccessibilityHintstringAccessibility hint for the second Toast button
onPressBtn2FunctionFunction to call on press of the second Toast button
1.1.27

2 months ago

1.1.26

2 months ago

1.1.25

2 months ago

1.1.24

3 months ago

1.1.22

3 months ago

1.1.21

3 months ago

1.1.20

3 months ago

1.1.19

3 months ago

1.1.18

3 months ago

1.0.2

9 months ago

0.3.31

10 months ago

1.0.1

9 months ago

0.3.30

10 months ago

1.0.0

9 months ago

0.3.35

9 months ago

0.3.34

9 months ago

0.3.33

9 months ago

1.0.3

8 months ago

0.3.32

9 months ago

0.3.29

10 months ago

1.1.1

8 months ago

1.1.0

8 months ago

1.1.9

7 months ago

1.1.8

7 months ago

1.1.7

8 months ago

1.1.6

8 months ago

1.1.5

8 months ago

1.1.4

8 months ago

1.1.3

8 months ago

1.1.2

8 months ago

1.1.12

7 months ago

1.1.11

7 months ago

1.1.10

7 months ago

1.1.16

5 months ago

1.1.15

6 months ago

1.1.14

6 months ago

1.1.13

6 months ago

1.1.17

5 months ago

0.3.20

12 months ago

0.3.28

11 months ago

0.3.27

12 months ago

0.3.26

12 months ago

0.3.25

12 months ago

0.3.24

12 months ago

0.3.23

12 months ago

0.3.22

12 months ago

0.3.21

12 months ago

0.3.19

1 year ago

0.3.17

1 year ago

0.3.18

1 year ago

0.3.9

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

1 year ago

0.3.11

1 year ago

0.3.10

1 year ago

0.3.0

1 year ago

0.3.6

1 year ago

0.2.7

1 year ago

0.3.5

1 year ago

0.2.6

1 year ago

0.3.8

1 year ago

0.3.7

1 year ago

0.3.2

1 year ago

0.3.3

1 year ago

0.2.3

1 year ago

0.2.2

1 year ago

0.2.5

1 year ago

0.2.4

1 year ago

0.2.1

2 years ago

0.2.0

2 years ago

0.1.7

2 years ago

0.1.4

2 years ago

0.1.6

2 years ago

0.1.5

2 years ago

0.1.3

2 years ago

0.1.0

2 years ago

0.1.2

2 years ago

0.1.1

2 years ago

0.0.9-beta.0

3 years ago