0.0.66 • Published 1 year ago

@digitalinsurance/falcon-ui v0.0.66

Weekly downloads
-
License
ISC
Repository
-
Last release
1 year ago

Falcon | Falcon UI

Table of contents

  1. About The Project
  2. Getting Started
  3. Guidelines
  4. Adding a component
  5. Using the package in a project
  6. Rendering values from the context data
  7. Testing

About The Project

The Falcon UI project is the place where components that are shared between the Falcon projects can be developed.

Getting started

To run the Falcon UI project on your local machine, follow these simple steps.

Prerequisites

  1. Git
  2. Node
  3. NPM
  4. VS Code (preferred because of jsdocs usage. Read the developer guide in the frontend docs project for more)

Installation

  1. Clone the repo
    git clone git@gitlab.com:digitalinsuranceio/falcon/falcon-ui.git
  2. Navigate to the repository folder
    cd falcon-ui
  3. Install the required packages
    npm install

Linking

To use this project in another project locally follow the steps below: 1. In the Falcon UI project folder: build and watch the project

npm run build:watch
  1. In the Falcon UI project folder: link the project
    npm link
  2. In the target project folder: link the falcon-ui library:
    npm link @digitalinsurance/falcon-ui

Guidelines

  • Everything that is an input/form component should have a name that ends in 'Input'.
  • Everything that is an input/form component should allow for validation messages.
  • Everything that is an input/form component should have a label (this can be hidden by default).
  • Translations are not handled in this project, intl is not used. The components in this project expect already translated labels to be passed to the components.
  • A new component should be added to the components folder in its own folder. If you component is named MyComponent you should add a file named MyComponent.jsx in the src/components/MyComponent folder.
  • All components should be exported from the src/index.js file as a named export.
  • All components should have a snapshot test and unit tests for any functionality.
  • All utility functions should also be tested.

Adding a component

The components in this project are used as Chakra UI components. We use their API to build the components. Please read this page carefully: https://chakra-ui.com/docs/theming/component-style.

When adding a new component please use the following folder structure:

File/folder nameDescription
partsFolder where you put individual parts of your component in
Component.jsxThe main component file
theme.jsThe theme file

For an example of this please refer to the ShowData component. Any other files specific to this component can be added in the component folder itself, on the same level as the theme.js file. Make sure to add the theme for your component to the src/theme/index.js file and to export your component in the src/index.js file.

Extending a component

When extending a Chakra component, for example the Select component, prefix the Chakra component with Chakra when importing it:

import { Select as ChakraSelect } from '@chakra-ui/react';

This pattern can also be followed for other packages. Prefix the import with the package name and then extend it in the code:

import { Link as ReactRouterDomLink } from 'react-router-dom';

Using the package in a project

  1. Install the package as a dependency
    npm install @digitalinsurance/falcon-ui
  2. Import the Falcon UI theme
    import { falconUITheme } from '@digitalinsurance/falcon-ui';
  3. Merge the theme with your projects theme and pass it to the ChakraProvider
    // We use lodash/merge here to merge the different theme adjustments
    <ChakraProvider theme={extendTheme(merge(theme, falconUITheme /* other theme adjustments */))}>
      {children}
    </ChakraProvider>
  4. Now you can use the components from Falcon UI in your project.

Rendering values from the context data

Some components in Falcon UI are capable of rendering data coming from the context data. You can pass a string as children that contains the following template string: $< first_name > where first_name is the key of the value from the context data you want to render.

To enable this you have to wrap the component with the ContextDataProvider from Falcon UI and pass the data you want to expose to it. Follow the steps below to enable this:

  1. Import the ContextDataProvider
    import { ContextDataProvider } from '@digitalinsurance/falcon-ui';
  2. Render the ContextDataProvider around the Falcon UI component you want to use the data in
    /**
     * The data can be anything, for example the values from the form using the methods.getValues()
     * function from react-hook-form in a useEffect hook
     */
    <ContextDataProvider data={/* pass your data object here */}>
      {children}
    </ContextDataProvider>
  3. Now you can use the templating format in a component, for example the ShowData component
    <ShowData
      label="The first_name value from the contextData"
      value="Hello $< first_name >, welcome!"
    />

Testing

For detailed testing explanation please refer to the frontend docs project on GitLab.

0.0.64

1 year ago

0.0.65

1 year ago

0.0.66

1 year ago

0.0.63

1 year ago

0.0.62

2 years ago

0.0.61

2 years ago

0.0.60

2 years ago

0.0.59

2 years ago

0.0.52

2 years ago

0.0.53

2 years ago

0.0.54

2 years ago

0.0.55

2 years ago

0.0.56

2 years ago

0.0.57

2 years ago

0.0.58

2 years ago

0.0.46

2 years ago

0.0.47

2 years ago

0.0.51

2 years ago

0.0.50

2 years ago

0.0.48

2 years ago

0.0.49

2 years ago

0.0.40

2 years ago

0.0.41

2 years ago

0.0.42

2 years ago

0.0.43

2 years ago

0.0.44

2 years ago

0.0.45

2 years ago

0.0.37

2 years ago

0.0.38

2 years ago

0.0.39

2 years ago

0.0.20

2 years ago

0.0.21

2 years ago

0.0.22

2 years ago

0.0.23

2 years ago

0.0.24

2 years ago

0.0.25

2 years ago

0.0.15

2 years ago

0.0.16

2 years ago

0.0.17

2 years ago

0.0.18

2 years ago

0.0.19

2 years ago

0.0.30

2 years ago

0.0.31

2 years ago

0.0.32

2 years ago

0.0.10

2 years ago

0.0.33

2 years ago

0.0.11

2 years ago

0.0.34

2 years ago

0.0.12

2 years ago

0.0.35

2 years ago

0.0.13

2 years ago

0.0.36

2 years ago

0.0.14

2 years ago

0.0.26

2 years ago

0.0.27

2 years ago

0.0.28

2 years ago

0.0.29

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.9

2 years ago

0.0.8

2 years ago

0.0.5

2 years ago

0.0.4

2 years ago

0.0.7

2 years ago

0.0.6

2 years ago

0.0.1

2 years ago