@digitalfactory/react-native-components v1.1.27
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
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.
Name | Type | Default | Description |
---|---|---|---|
buttonType | string (one of: primarySquare , primaryRounded , primaryRoundLarge , primaryRoundSmall , secondarySquare , secondaryRounded , secondaryRoundLarge , secondaryRoundSmall , tertiarySquare , tertiaryRounded ) | "primarySquare" | Defines the button's default style. |
children | React.ReactNode | Child elements for the button. | |
accessibilityLabel | string | "button" | Overrides the text that's read by the screen reader when the user interacts with the element. |
accessibilityHint | string | "Button" | Helps users understand what will happen when they perform an action on the button. |
disabled | boolean | false | Whether or not the button is in a disabled state. |
icon | ({ weight, color, size, style, mirrored }: IconProps) => JSX.Element or JSX.Element or React.ReactElement | Icon to use for the button. Supports Phosphor Icons. | |
iconPosition | string (one of: left or right ) | "left" | Whether the icon should be left-aligned or right-aligned in relation to the button text. |
iconProps | IconProps (see the phosphor-react-native package for more info) | Phosphor icon props to customise the phosphor icon style. | |
text | string | The button text. | |
buttonStyle | ViewStyle | Custom styles to apply on the button. | |
pressedButtonStyle | ViewStyle | Custom styles to apply on the button when it is in a 'pressed' state. | |
textStyle | TextStyle | Custom 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.
Name | Type | Default | Description |
---|---|---|---|
id | string | Assigns a unique ID to the InputAccessoryView | |
previousDisabled | boolean | false | Whether or not to disable the previous arrow button |
nextDisabled | boolean | false | Whether or not to disable the next arrow button |
onPressPrevious | () => void | () => null | Function to execute when the previous button is pressed |
onPressNext | () => void | () => null | Function to execute when the next button is pressed |
onPressDone | () => void | () => Keyboard.dismiss() | Function to execute when the done button is pressed |
useInputAccessoryView | boolean | true | Whether 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.
Name | Type | Default | Description |
---|---|---|---|
assistiveTextTop | string | Gray assistive text to display above the input field | |
assistiveTextBottom | string | Gray assistive text to display below the input field | |
children | React.ReactNode | The child elements (i.e. input field) for the component | |
containerStyle | ViewStyle | Override the default container styles | |
labelText | string | The label for your input field | |
required | boolean | false | Displays a red asterisk on the label for mandatory fields |
showCharactersRemaining | { currentCount: number; maxCount: number; } | Displays the current field length count against the max | |
statusText | StatusText[] | 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
Name | Type | Default | Description |
---|---|---|---|
animating | boolean | true | Show (true) or hide (false) the loading spinner |
size | number | 60 | Defines the width and height of the spinner (pixels) |
color | string | grayCod (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.
Name | Type | Default | Description |
---|---|---|---|
children | React.ReactNode | Child elements / content to display within the modal | |
showOverlay | boolean | true | Whether or not to show the full-screen modal overlay |
wrapperStyle | ViewStyle | Override the default wrapper styles | |
modalStyle | ViewStyle | Override 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 useiconLeft
oriconRight
(see below table).InputAccessoryView
- instead useinputAccessoryViewProps
(see here for available options) to pass props to the InputAccessoryView.
The component also accepts the following props, all of which are optional:
Name | Type | Default | Description | ||
---|---|---|---|---|---|
containerStyle | ViewStyle | Allows you to override the default container style | |||
disabled | boolean | false | Whether or not the component is in a disabled state | ||
focusRingColor | string | "#0058DB" | Allows you to override the default focus ring colour | ||
hideInputAccessoryView | boolean | false | Whether or not to hide the InputAccessoryView | ||
iconLeft | React.ComponentType | Left icon to display on the component | |||
iconRight | React.ComponentType | (Phosphor icon's CaretDown) | Right icon to display on the component | ||
inputAccessoryViewProps | InputAccessoryViewProps | Props to pass to the InputAccessoryView. See here for available options | |||
onOpen | () => void | Function to call when the input opens / recieves focus | |||
onClose | () => void | Function 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:
Name | Type | Default | Description | ||
---|---|---|---|---|---|
containerStyle | ViewStyle | Allows you to override the default container style | |||
disabled | boolean | false | Whether or not the component is in a disabled state | ||
elementLeft | React.ComponentType | Element to display on the left side of the input | |||
elementRight | React.ComponentType | Element to display on the right side of the input | |||
focusRingColor | string | "#0058DB" | Allows you to override the default focus ring colour | ||
hideInputAccessoryView | boolean | false | Whether or not to hide the InputAccessoryView | ||
inputAccessoryViewProps | InputAccessoryViewProps | Props to pass to the InputAccessoryView. See here for available options | |||
inputStyle | TextStyle | Allows you to override the default input style | |||
multiline | boolean | false | Whether or no the component should be multiline (like textarea) | ||
numberOfLines | number | 1. Defaults to 4 if multiline is true | The number of lines for the component (determines height of the component) | ||
onBlur | Function | Function to call on blur of the input | |||
onFocus | Function | Function 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:
- The
type
option of theToast.show
method has the available values:success
,warning
,error
andinfo
- The
text2
option of theToast.show
method has no effect. This is because there are no requirement to support this currently. Put any text you want in thetext1
option.
Props
Some additional props can be passed into the Toast.show
options object under the props
property:
Name | Type | Default | Description |
---|---|---|---|
hideCloseBtn | boolean | false | Hides the 'X' close icon |
textEl | React.ComponentType (Text) | Pass in a custom Text component, e.g. if needing to style text | |
btn1Text | string | Text for the first Toast button, if needed | |
btn1AccessibilityLabel | string | Accessibility label for the first Toast button | |
btn1AccessibilityHint | string | Accessibility hint for the first Toast button | |
onPressBtn1 | Function | Function to call on press of the first Toast button | |
btn2Text | string | Text for the second Toast button, if needed | |
btn2AccessibilityLabel | string | Accessibility label for the second Toast button | |
btn2AccessibilityHint | string | Accessibility hint for the second Toast button | |
onPressBtn2 | Function | Function to call on press of the second Toast button |
2 months ago
2 months ago
2 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
9 months ago
10 months ago
9 months ago
10 months ago
9 months ago
9 months ago
9 months ago
9 months ago
8 months ago
9 months ago
10 months ago
8 months ago
8 months ago
7 months ago
7 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
7 months ago
7 months ago
7 months ago
5 months ago
6 months ago
6 months ago
6 months ago
5 months ago
12 months ago
11 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
3 years ago