0.5.17 • Published 2 years ago

@admixltd/admix-component-library v0.5.17

Weekly downloads
-
License
MIT
Repository
-
Last release
2 years ago

ACL 🔷 Admix Components Library

package version beta version package downloads package min size package min zip size

yarn add @admixltd/admix-component-library

Subpackages list

this packages not included to @admixltd/admix-component-library directly and should use specific import

'@admixltd/admix-component-library/Api'
'@admixltd/admix-component-library/AuthWrapper'
'@admixltd/admix-component-library/AutoComplete'
'@admixltd/admix-component-library/ChipArray'
'@admixltd/admix-component-library/Deprecated'
'@admixltd/admix-component-library/FormAtomGenerator'
'@admixltd/admix-component-library/NumericInput'
'@admixltd/admix-component-library/RecoilNexus'
'@admixltd/admix-component-library/Snackbar'
'@admixltd/admix-component-library/Table'

Usage in your project:

1. Install component-specific dependencies


Deprecated

If you want to use legacy packages from deprecated section, based on antd, you should install next packages:

They are in the deprecated section because they use direct or indirect dependence on antd, for example AdmixButton in AppDiscoveryItem.tsx

yarn add recharts antd
import { AdmixButton, AdmixBarChart, AdmixBarChartProps } from '@admixltd/admix-component-library/Deprecated'

Autocomplete , Select

To use Autocomplete or Select component please install:

yarn add react-window
 
import { AutoComplete, Select } from '@admixltd/admix-component-library/AutoComplete'

Table

To use Table component please install:

yarn add @mui/x-data-grid react-window 
 
import { Table } from '@admixltd/admix-component-library/Table'

NumericInput

To use NumericInput component please install:

yarn add react-number-format
 
import { NumericInput } from '@admixltd/admix-component-library/NumericInput'

AuthWrapper

To use AuthWrapper component please install:

yarn add react-cookie notistack
 
import { AuthWrapper } from '@admixltd/admix-component-library/AuthWrapper'

ChipArray

To use ChipArray component please install:

yarn add react-transition-group
 
import { ChipArray } from '@admixltd/admix-component-library/ChipArray'

FormAtomGenerator

To use FormAtomGenerator component please install:

More usage details

yarn add recoil
 
import { FormAtomGenerator } from '@admixltd/admix-component-library/FormAtomGenerator'

RecoilNexus

To use RecoilNexus component please install:

More usage details

yarn add recoil
 
import { RecoilNexus } from '@admixltd/admix-component-library/RecoilNexus'

Snackbar

If you want use Snackbar component please install:

More usage details

yarn add notistack
import { Snackbar } from '@admixltd/admix-component-library/Snackbar'

2. Add Inter font


To use this library, please add Inter font to your project

<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap" rel="stylesheet">

Or use local Inter font copy (Preferred for ssr)

Use: https://amio.github.io/embedded-google-fonts/ to store font in one file with base64

<!-- Your html file-->
<!--suppress CommaExpressionJS -->
<script>
    const fontFile = '/inter.css'
    const fontFamily = `Inter`
    /**
     * Save font into localstorage for fast refresh
     */
    ;(function() {
      function addFont() {
        const e = document.createElement('style');
        document.head.appendChild(e);
        e.textContent = localStorage.preloaded_font;
      }
      const fontExists = !!localStorage.preloaded_font && localStorage.preloaded_font.includes(fontFamily);
      if (fontExists){
        addFont();
        return;
      } 
      fetch(fontFile).then(t=>t.text()).then(t=>{
        localStorage.setItem('preloaded_font', t);
        addFont();
      });
    })()
</script>

3. Use theme


1. Merge AdmixLibraryTheme with your @emotion theme

//styles/theme.ts

import { AdmixLibraryTheme } from '@admixltd/admix-component-library'

/**
 * Your styles
 */
const projectTheme = {
  purple: `#DDA0DD`,
}

/**
 * Override theme styles
 */
AdmixLibraryTheme.colors.primary = '#000'
AdmixLibraryTheme.colors.secondary = projectTheme.purple

/**
 * Extend style-components with theme type
 */
export type ITheme = typeof AdmixLibraryTheme & typeof projectTheme
const theme = { ...AdmixLibraryTheme, ...projectTheme } as ITheme
export type PropsWithTheme<T = unknown> = T & {
  theme: ITheme
}
export default theme

2. Redeclare Theme

https://emotion.sh/docs/typescript#define-a-theme

//emotion.d.ts
import "@emotion/react";
import { ITheme } from "@styles/theme";


declare module "@emotion/react" {
  /**
   * Should be interface not a type
   */
  export interface Theme extends ITheme {
  }
}

3.Wrap your app with AdmixThemeProvider and ThemeProvider from @emotion

//App.jsx

import { AdmixThemeProvider } from '@admixltd/admix-component-library';
import theme from 'styles/theme';

<AdmixThemeProvider theme={theme}>
  <App />
</AdmixThemeProvider>

/**
 * Or same without AdmixThemeProvider
 */

import { ThemeProvider as EmotionThemeProvider } from '@emotion/react'
import { createTheme, ThemeProvider as MuiThemeProvider } from '@mui/material'
import theme from 'styles/theme';

const muiTheme = createTheme({});

<MuiThemeProvider theme={muiTheme}>
  <EmotionThemeProvider theme={theme}>
    <App />
  </EmotionThemeProvider>
</MuiThemeProvider>

1. Merge AdmixLibraryTheme with your styled-components theme

//styles/theme.ts

import { AdmixLibraryTheme } from '@admixltd/admix-component-library'

/**
 * Your styles
 */
const projectTheme = {
  purple: `#DDA0DD`,
}

/**
 * Override theme styles
 */
AdmixLibraryTheme.colors.primary = '#000'
AdmixLibraryTheme.colors.secondary = projectTheme.purple

/**
 * Extend style-components with theme type
 */

export type ITheme = typeof AdmixLibraryTheme & typeof projectTheme
const theme = { ...AdmixLibraryTheme, ...projectTheme } as ITheme
export default theme

2. Redeclare DefaultTheme

https://styled-components.com/docs/api#create-a-declarations-file

//styled.d.ts
import 'styled-components'
import { ITheme } from '@styles/theme'


declare module 'styled-components' {
  /**
   * Should be interface not a type
   */
  export interface DefaultTheme extends ITheme {}
}

3.Wrap your app with AdmixThemeProvider and ThemeProvider from styled-components

//App.jsx

import { AdmixThemeProvider } from '@admixltd/admix-component-library';
import { ThemeProvider } from 'styled-components';
import theme from 'styles/theme';

<AdmixThemeProvider>
  <ThemeProvider theme={theme}>
    <App />
  </ThemeProvider>
</AdmixThemeProvider>

/**
 * Or same without AdmixThemeProvider
 */

import { ThemeProvider as EmotionThemeProvider } from '@emotion/react'
import { createTheme, ThemeProvider as MuiThemeProvider } from '@mui/material'
import { ThemeProvider } from 'styled-components';
import theme from 'styles/theme';

const muiTheme = createTheme({});


<MuiThemeProvider theme={muiTheme}>
  <EmotionThemeProvider theme={theme}>
    <ThemeProvider theme={theme}>
      <App />
    </ThemeProvider>
  </EmotionThemeProvider>
</MuiThemeProvider>

4. Enjoy using it, you are wonderful! 🎂


Development

If you haven't used yarn before, please make sure that you install dependencies in an empty node_modules folder

Install yarn and rimraf

npm install --global yarn 
yarn global add rimraf

Remove node_modules recursively

rimraf node_modules

1. Install dependencies

yarn

2. Run storybook

yarn start

Build project

yarn clean && yarn build

Link projects to work locally

1. Start building in watch mode

   
yarn build-watch
   

2. Link dependencies and admix-component-library in your project package.json file

{
  "@admixltd/admix-component-library": "link:../admix-component-library/build",
  "react": "link:../admix-component-library/node_modules/react",
  "react-dom": "link:../admix-component-library/node_modules/react-dom",
  "@emotion/react": "link:../admix-component-library/node_modules/@emotion/react",
  "@emotion/styled": "link:../admix-component-library/node_modules/@emotion/styled",
  "@mui/material": "link:../admix-component-library/node_modules/@mui/material",
  "notistack": "link:../admix-component-library/node_modules/notistack",
  "recoil": "link:../admix-component-library/node_modules/recoil"
}

3. Use theming

Snackbar usage

1. Install notistack package

yarn add notistack

2. Wrap your app with SnackbarProvider

3. Add SnackbarUtilsConfigurator next to your app

import { SnackbarProvider } from 'notistack';
import { SnackbarUtilsConfigurator } from '@admixltd/admix-component-library/Snackbar';

<SnackbarProvider
  maxSnack={10}
  anchorOrigin={{
    vertical: 'bottom', horizontal: 'right',
  }}
>
  <YourApp />
  <SnackbarUtilsConfigurator />
</SnackbarProvider>

4. Use Snackbar anywhere

import { Snackbar } from '@admixltd/admix-component-library/Snackbar'

Snackbar.toast('Hello world!')
Snackbar.success(<>Hello <strong>world</strong>!</>)

FormAtomGenerator usage

import { useRecoilState } from 'recoil'
import { FormAtomGenerator } from "@admixltd/admix-component-library/FormAtomGenerator";

const initialValue: FormDataProps = {
  name: 'Jake',
  surname: 'Smith'
}

interface FormDataProps {
  name: string
  surname: string
}

const {
	AtomUpdater: SomeFormAtomUpdater,
	DataUpdater: SomeFormDataUpdater,
	DataMerger: SomeFormDataMerger,
} = FormAtomGenerator<FormDataProps>(
	'SomeFormKey',
	initialValue
)



const SomeComponent = () => {
  /**
   * Control value for specific field
   */
  const [value1, setValue1] = useRecoilState(SomeFormAtomUpdater('name'))
  const [value2, setValue2] = useRecoilState(SomeFormAtomUpdater('surname'))


  /**
   * Control array of fields ( useful for errors )
   */
  const [value3, setValue3] = useRecoilState(SomeFormAtomUpdater(['name', 'surname']))
  /**
   * value3 - returns first non undefinened value from list of fields 
   * value3 = values1['name'] ?? values1['surname'] ?? values1[...]
   * setValue3('SomeText') - updates current field form value3
   * if value3 = values1['name'] - updates 'name'
   */
  
  
  /**
   * Controll all values
   * setValues1 first call  {x: text}
   * setValues1 second call {y: text}
   * ===>
   * {y: text}
   */
  const [values1, setValues1] = useRecoilState(SomeFormDataUpdater)


  /**
   * Controll all values with merge
   * Merge values by parts like:
   * setValues2 first call  {x: text}
   * setValues2 second call {y: text}
   * ===>
   * {x: text, y: text}
   */
  const [values2, setValues2] = useRecoilState(SomeFormDataMerger)

  
  return <></>
}

RecoilNexus usage

1. Add RecoilNexus in your RecoilRoot

import React from "react";
import { RecoilRoot } from "recoil";
import { RecoilNexus } from "@admixltd/admix-component-library/RecoilNexus";

export default function App() {
  return (
    <RecoilRoot>
      <RecoilNexus />

      {/* ... */}
    </RecoilRoot>
  );
}

export default App;

2. Use the following methods to get/set values passing your atom as a parameter.

| Method | Returns | |:-------------------|:----------------------------------------------------------------------------| | getRecoil | getter function | | getRecoilPromise | getter function, returns a promise. To be used with asynchronous selectors. | | setRecoil | setter function, pass value to be set as second parameter | | resetRecoil | pass atom as parameter to reset to default value |

// Loading example
import { loadingState } from "../atoms/loadingState";
import { getRecoil, setRecoil } from "@admixltd/admix-component-library/RecoilNexus";

export default function toggleLoading() {
  const loading = getRecoil(loadingState);
  setRecoil(loadingState, !loading);
}
//Loader
import React from "react";
import { useRecoilValue } from "recoil";

export default function Loader() {
  loading = useRecoilValue(loadingState);
  return loading ? <h3>Loading...</h3> : null;
}
//Atom
import { atom } from "recoil";

export const loadingState = atom({
  key: "LOADING",
  default: false,
});

Helpers description

NameDescription
AdmixThemeProviderThemeContextProver with a theme included in it for Admix component library
AuthWrapperMakes child components available only after Admix authorization
PromiseAllAllows you to receive a response from Promise.all as an object
SnackbarPlease read snackbar usage section
RecoilNexusPlease read RecoilNexus usage section
FormAtomGeneratorPlease read FormAtomGenerator usage section. Generate atoms and selectors for recoil to use them in forms or in please where you need control state based on object

Hooks description

NameDescription
useMergeObject.assign for the state, used as an analogue of useState, but without overwriting the entire state, but only part of it
usePreviousSaves the state of the previous render
useFirstRenderDetect is first render or not
useWindowSizeAllows you to get the window size

Utils description

NameDescription
childrenToTextAccepts JSX and returns only the Text from it. Useful for logging
trimUrlSlashesRemoves unnecessary slashes from the URL
fontLoaderLoads the font file into the localStorage
childrenWithPropsPass props to children
ignoreRecoilErrorsAllows you to ignore recoil errors, which are usually incorrect
getURLSearchParametersAllows you to get the parameters object from the search part of the URL
numberFormatterShortens the number with formatting (K, M, G, ...)
transientOptionsYou need to add to emotion/styled so that attributes with $ are not passed to the component EX: const ButtonInput = styled(Button, transientOptions)<{$primaryColor?: ...}>
handleBlurTriggers a loss of focus for the user
uniqByFilters an array of objects by field (no lodash)

Chromatic manual deploying

npx chromatic --project-token=YOUR_TOKEN
0.5.17

2 years ago

0.5.16

2 years ago

0.5.15

2 years ago

0.5.14-1

2 years ago

0.5.14-2

2 years ago

0.5.14-3

2 years ago

0.5.14-4

2 years ago

0.5.14-5

2 years ago

0.5.14-6

2 years ago

0.5.14-7

2 years ago

0.5.10

2 years ago

0.5.11

2 years ago

0.5.11-1

2 years ago

0.5.14

2 years ago

0.5.12

2 years ago

0.5.13

2 years ago

0.5.13-1

2 years ago

0.5.8

2 years ago

0.5.7

2 years ago

0.5.9

2 years ago

0.5.1-2

2 years ago

0.5.1-1

2 years ago

0.5.1-4

2 years ago

0.5.1-3

2 years ago

0.5.1-6

2 years ago

0.5.1-5

2 years ago

0.5.2-1

2 years ago

0.5.6-1

2 years ago

0.5.4

2 years ago

0.5.3

2 years ago

0.5.6

2 years ago

0.5.5

2 years ago

0.5.2

2 years ago

0.5.7-1

2 years ago

0.4.2-9

2 years ago

0.4.2-8

2 years ago

0.5.0-1

2 years ago

0.5.0-2

2 years ago

0.5.0-16

2 years ago

0.5.0-15

2 years ago

0.5.0-17

2 years ago

0.5.0-10

2 years ago

0.5.0-12

2 years ago

0.5.0-11

2 years ago

0.5.0-14

2 years ago

0.5.0-13

2 years ago

0.5.0-9

2 years ago

0.5.0-8

2 years ago

0.5.0-5

2 years ago

0.5.0-4

2 years ago

0.5.0-7

2 years ago

0.5.0-6

2 years ago

0.4.4

2 years ago

0.4.3

2 years ago

0.4.4-1

2 years ago

0.5.0

2 years ago

0.5.1

2 years ago

0.4.2-6

2 years ago

0.4.2-5

2 years ago

0.4.2-4

2 years ago

0.4.2-3

2 years ago

0.4.2-7

2 years ago

0.4.2--

2 years ago

0.4.2-2

2 years ago

0.4.2-1

2 years ago

0.2.27

2 years ago

0.3.8-1

2 years ago

0.3.8-3

2 years ago

0.3.8-2

2 years ago

0.3.8-5

2 years ago

0.3.8-4

2 years ago

0.3.0

2 years ago

0.3.5

2 years ago

0.2.3-2.0

2 years ago

0.3.7

2 years ago

0.3.2

2 years ago

0.3.1

2 years ago

0.3.4

2 years ago

0.3.3

2 years ago

0.3.7-2

2 years ago

0.3.7-1

2 years ago

0.3.7-4

2 years ago

0.3.7-3

2 years ago

0.2.34

2 years ago

0.2.33

2 years ago

0.2.32

2 years ago

0.2.31

2 years ago

0.2.29

2 years ago

0.2.28

2 years ago

0.2.32-2.1

2 years ago

0.2.32-2.2

2 years ago

0.4.1

2 years ago

0.4.0

2 years ago

0.4.1-1

2 years ago

0.4.2

2 years ago

0.2.26

2 years ago

0.2.25

2 years ago

0.2.24

3 years ago

0.2.23

3 years ago

0.2.22

3 years ago

0.2.21

3 years ago

0.2.20

3 years ago

0.2.19

3 years ago

0.2.18

3 years ago

0.2.17

3 years ago

0.2.16

3 years ago

0.2.15

3 years ago

0.2.14

3 years ago

0.2.13

3 years ago

0.1.12

3 years ago

0.2.12

3 years ago

0.2.11

3 years ago

0.2.10

3 years ago

0.2.1

3 years ago

0.2.7

3 years ago

0.2.6

3 years ago

0.2.9

3 years ago

0.2.8

3 years ago

0.2.3

3 years ago

0.2.2

3 years ago

0.2.5

3 years ago

0.2.4

3 years ago

0.2.0

3 years ago

0.1.11

3 years ago

0.1.10

3 years ago

0.1.8

3 years ago

0.1.7

3 years ago

0.1.9

3 years ago

0.1.6

3 years ago

0.1.4

3 years ago

0.1.5

3 years ago

0.1.1

3 years ago

0.1.3

3 years ago

0.1.0

3 years ago