0.23.2 • Published 2 months ago

@fuel-ui/react v0.23.2

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

CI status codecov NPM version NPM downloads

License Issues Open Github Forks Github Stars


🙋🏻  Getting Started

Inside this package you'll found styled, very opiniated, acessible with high-quality user experience React components we're using inside as part of our design system inside our applications.

📦  Install

$ yarn add @fuel-ui/react
$ pnpm install @fuel-ui/react

👨🏻‍💻  Usage

First wrap your entire application using our ThemeProvider component

import { ThemeProvider } from '@fuel-ui/react';

const Main = () => (
  <ThemeProvider>
    <App />
  </ThemeProvider>
);

Then inside your app you can use as you want our component

import { Button, Form, Icon, Input, Stack } from '@fuel-ui/react';

const App = () => {
  const [showing, setShowing] = useState(false);

  function toggle() {
    setShowing((s) => !s);
  }

  return (
    <Stack css={{ maxW: '400px' }}>
      <Form.Control isRequired>
        <Form.Label htmlFor="email">Email</Form.Label>
        <Input isFullWidth>
          <Input.ElementLeft element={<Icon icon="Lock" />} />
          <Input.Field
            type={showing ? 'text' : 'password'}
            name="password"
            placeholder="Your password..."
          />
          <Input.ElementRight>
            <Button variant="outlined" onPress={toggle} css={{ mr: '-8px' }}>
              Show
            </Button>
          </Input.ElementRight>
        </Input>
        <Form.HelperText>Try a strong password</Form.HelperText>
        <Form.ErrorMessage>Password validation error</Form.ErrorMessage>
      </Form.Control>
    </Stack>
  );
};

💅🏻  Styling Components

The best approach to style our component is by using @fuel-ui/css package. It's include all Stitches theme features and also our theme/tokens definitions.

You can simply create a className with it or use the css prop of our components:

import { css } from '@fuel-ui/css';
import { Box } from '@fuel-ui/react';

const App = () => {
  <Box className={customStyle()} css={{ display: 'flex' }}>
    Hello world
  </Box>;
};

const customStyle = css({
  alignItems: 'center',
  justifyContent: 'center',
  bg: '$brand',
  px: '$4',
  textSize: 'base',
});

💪🏻  Contributing

Besides our main Contribution Guide it's very important you know about our code conventions and design principles if you want to contribute. Because of that we encourage you to read about all of these concepts and conventions bellow before start to develop or help here.

📖  Principles

Simplicity: Strive to keep the component API fairly simple and show real world scenarios of using the component.Composition: Break down components into smaller parts with minimal props to keep complexity low, and compose them together. This will ensure that the styles and functionality are flexible and extensible.Accessibility: When creating a component, keep accessibility top of mind. This includes keyboard navigation, focus management, color contrast, voice over, and the correct aria-* attributes.Dark Mode: Make components dark mode compatible. Use our darkTheme to handle styling according to Stitches.Naming Props: We all know naming is the hardest thing in this industry. Generally, ensure a prop name is indicative of what it does. Boolean props should be named using auxiliary verbs such as does, has, is and should. For example, Button uses isDisabled, isLoading, etc.

🏭  Component Pattern

There are two base props we have in all components: as and css. The as is very help if you want to change the base element of some component and the css prop will help you in order to change styles.

To make this available in some component inside our design system, we created a _unstable_createComponent function. This function will work together with the React's createElement function and the Stitches styled to create all behavior we need.

Check this example of our Box component:

import { cx, styled } from '@fuel-ui/css';
import { createElement } from 'react';

import type { HTMLProps } from '../../utils';
import { _unstable_createComponent } from '../../utils';

export type BoxProps = HTMLProps['div'];

const Root = styled('div');
export const Box = _unstable_createComponent<BoxProps>(
  ({ className, children, ...props }) => {
    const classes = cx('fuel_Box', className);
    return _unstable_createEl(Root, { ...props, className: classes }, children);
  },
);

🕹  Generating Components

If you don't want to copy and paste or create some snippet, you can use simply our generator by running:

$ pnpm add:component --name NameOfYourComponent

  Testing Components

It's extremelly important that all components that has custom behaviors and settings are tested. So, we have @fuels/jest package that will help you to test using React Testing Library with some cool patches and modifications for accessibility tests as well (this package is a copy of ChakraUI test utils package).

A base test of some component always include a11y test as first case:

import { testA11y } from '@fuels/jest';
import { MyComponent } from './MyComponent';

describe('MyComponent', () => {
  it('a11y', async () => {
    await testA11y(<MyComponent>Hello world</MyComponent>);
  });
});

With test utils package you can run some triggers in order to test accessibility as well. Keyboard commands like Tab and ArrowDown is very easy by using press helper:

import { press, render, screen } from '@fuels/jest';
import { RadioGroup } from './RadioGroup';

describe('RadioGroup', () => {
  it('should focus correctly', async () => {
    render(content);

    await press.Tab();
    expect(screen.getByLabelText('Default')).toHaveFocus();
    await press.ArrowDown();
    expect(screen.getByLabelText('Comfortable')).toHaveFocus();
    await press.ArrowDown();
    expect(screen.getByLabelText('Compact')).toHaveFocus();
  });
});

⚙️  Dev Environment

This is the resources you'll need to know in order to run our dev environment.

⌨️  Local Commands

Use this commands in order to run locally and have our dev environment setup in your machine.

CommandDescription
pnpm add:componentCreate a component based on our default templates
pnpm build:storyBuild Storybook project
pnpm buildRun tsup for build using ESbuild
pnpm devRun Storybook in development mode
pnpm testRun Jest with json output file option for Storybook addon

🛠  Tools

There are several tools we're using inside our design system and all of them is important, mainly because we really care about our user experience and we wan't to achieve good accessibility inside our components

@fuel-ui/css

This is an internal package containing all styles, theme and tokens definitions that we need for entire monorepo and mainly here in our design system. Couple tools like Stitches and Radix Colors are used inside this package. We're encourage you to check it also.

StorybookJS

This project utilizes Storybook for component development with some really cool addons to help us to achieve accessibility, be able to cover user experience use cases in our and have a good documentation of each component.

RadixUI

We are using Radix as base components extensively here:

Radix Primitives is a low-level UI component library with a focus on accessibility, customization and developer experience. You can use their components either as the base layer of your design system, or adopt them incrementally. We're

TablerIcons

As icon set, we're using Tabler Icons here. Tabler Icons is a flexible icon family for interfaces, diagrams, presentations — whatever, really.

Radix Colors

We also use Radix Colors inside the @fuel-ui/css package. So, you we can check all colors inside the package folder.

XState

We also use XState as state management internally.

💪🏻  Contributing

Feel like contributing? That's awesome! We have a contributing guide to help guide you.

📜  License

The primary license for this repo is Apache 2.0, see LICENSE.

0.23.2-dev-b5e00d1

2 months ago

0.23.2

2 months ago

0.23.1

3 months ago

0.23.1-dev-72dd4fe

3 months ago

0.23.0-dev-d23a038

4 months ago

0.23.0

4 months ago

0.22.0

4 months ago

0.22.0-dev-3c26cb9

4 months ago

0.22.0-dev-3816ea5

4 months ago

0.20.1

8 months ago

0.20.0

8 months ago

0.19.1-dev-16fd177

8 months ago

0.21.1-dev-bd8bc55

7 months ago

0.17.0

9 months ago

0.18.0-dev-5d32abe

9 months ago

0.21.1

7 months ago

0.17.1-dev-d9fba4d

9 months ago

0.21.0-dev-dffa94e

8 months ago

0.21.0

8 months ago

0.20.0-dev-7b40886

8 months ago

0.18.1

9 months ago

0.18.2

9 months ago

0.18.3

9 months ago

0.18.4

8 months ago

0.18.0-dev-48d1f1a

9 months ago

0.18.0

9 months ago

0.17.0-dev-b79c7e4

9 months ago

0.18.0-dev-327b756

9 months ago

0.18.2-dev-9f44c66

9 months ago

0.16.2-dev-9e06773

10 months ago

0.18.0-dev-5189bed

9 months ago

0.18.1-dev-c91eb86

9 months ago

0.16.2-dev-2cfcac9

10 months ago

0.16.2

10 months ago

0.21.1-dev-4a11149

7 months ago

0.20.0-dev-3254fe0

8 months ago

0.18.4-dev-b24dd9c

8 months ago

0.20.0-dev-1dcecb3

8 months ago

0.18.3-dev-ddb3201

9 months ago

0.18.2-dev-da58c21

9 months ago

0.16.3-pr--3a46de0

9 months ago

0.20.1-dev-0dac513

8 months ago

0.19.0

8 months ago

0.19.1

8 months ago

0.19.0-dev-779aacd

8 months ago

0.18.2-dev-aec9c59

9 months ago

0.18.1-dev-88ab7fa

9 months ago

0.18.0-dev-7536770

9 months ago

0.18.0-dev-f9a56be

9 months ago

0.17.1-pr--2e552c8

9 months ago

0.18.2-dev-36a81f8

9 months ago

0.15.1-dev-80e1a79

11 months ago

0.16.1-dev-ed83589

11 months ago

0.16.0

11 months ago

0.16.1

11 months ago

0.16.0-dev-8d32e8d

11 months ago

0.15.1-dev-96bff44

11 months ago

0.15.1-dev-9d4ea31

11 months ago

0.15.1-pr--2ef2a88

11 months ago

0.15.1-pr--4c3fae7

12 months ago

0.15.1-pr--4118fe0

12 months ago

0.14.0

1 year ago

0.14.1

1 year ago

0.15.0-dev-c6f1a1b

12 months ago

0.14.2

1 year ago

0.15.1-pr--ff00aff

12 months ago

0.14.3-dev-f9369d1

12 months ago

0.15.1-pr--e15a9d2

12 months ago

0.15.0-pr--7a6b3e7

12 months ago

0.15.1-pr--55142cc

11 months ago

0.15.0-dev-349c0a6

12 months ago

0.15.0-dev-9c7ba65

12 months ago

0.15.1-dev-d71ff58

11 months ago

0.15.1-pr--88079fa

12 months ago

0.15.1-pr--51a4b2d

11 months ago

0.15.0

12 months ago

0.15.0-pr--55a36e3

12 months ago

0.15.1-pr--7dd0095

12 months ago

0.15.1-pr--ad2cb33

12 months ago

0.14.3-dev-f617ddc

12 months ago

0.15.1-pr--c2189e6

12 months ago

0.15.1-dev-69762a5

11 months ago

0.15.1-pr--050ea2f

11 months ago

0.15.1-pr--6608ab8

12 months ago

0.13.0

1 year ago

0.12.4

1 year ago

0.11.0

1 year ago

0.12.0

1 year ago

0.10.2

1 year ago

0.12.1

1 year ago

0.12.2

1 year ago

0.12.3

1 year ago

0.9.0

2 years ago

0.9.2

1 year ago

0.9.1

1 year ago

0.9.3

1 year ago

0.10.1

1 year ago

0.10.0

1 year ago

0.8.0

2 years ago

0.5.0

2 years ago

0.7.0

2 years ago

0.6.0

2 years ago

0.4.0

2 years ago

0.3.0

2 years ago

0.2.0

2 years ago

0.1.1

2 years ago

0.1.0

2 years ago

0.0.2

2 years ago