0.0.22 • Published 1 year ago

e30studio v0.0.22

Weekly downloads
-
License
Unlicense
Repository
github
Last release
1 year ago

e30Studio

This package is collection of hooks and components

Getting started

yarn add e30studio

Hooks

useToggle

Hook is just sugar syntax over useState

useToggle(initialValue = false)

Response:

{ 
    value: boolean
    toggle: () => void
    on, 
    off,
    open, 
    close
}
NameTypeDescription
valuebooleanstate of toggle
toggle() => voidtoggle the state
on / open() => voidset state to true
off / close() => voidset state to false
Example
import React from 'react'
import { useToggle } from 'e30studio/hooks'

export const Foo: React.FC = () => {
    const { value, toggle } = useToggle();
    
    return <div>
        <span>{value.toString()}</span>
        <button onClick={toggle}>toggle</button>
    </div>
}

useFeatureFlag

If you want to have feature flag based on your ENV Variables

useFeatureFlag([FLAG_1, ... ,FLAG_N])

Response:

[boolean, ..., boolean]

Example

.env

REACT_APP_USE_NEW_MENU=true
import React from 'react'
import { useFeatureFlag } from 'e30studio/hooks'
import { MenuV1, MenuV2 } from './components'

export const Foo: React.FC = () => {
    const [isNewMenu] = useFeatureFlag(['USE_NEW_MENU']);
    
    return isNewMenu ? <MenuV2 /> : <MenuV1 /> 
}

useNotification

Hook for invoking notifications, use together with <Notification /> component

Response:

NameTypeDescription
success(message, timeout) => voidshow success toast
info(message, timeout) => voidshow info toast
warning(message, timeout) => voidshow warning toast
error(message, timeout) => voidshow error toast
clearAll() => voidClose all toasts

message can be either string or INotification

export interface INotification {
  title?: string
  message?: string
  timeout?: number
  onClick?: () => void
}

by default success, info, warning has timeout set to defaultTimeout from <Notification /> component

To disable timeout, set it to 0

Example

import React from 'react'
import { useNotification } from 'e30studio/components'

export const Home: React.FC = () => {
  const { success, warn } = useNotification()
  const retry = () => { 
    console.log('do something')
  }
  
  return <div>
    <button onClick={() => success('Button clicked')}>Show notification</button>
    <button onClick={() => warn('Ups...')}>Show warning</button>
    <button onClick={() => warn({
      title: 'Network issues',
      message: 'Fetching user went wrong',
      onClick: retry
    })}>Custom</button>
</div>
}

Components

Notifications

Notifications wrapper, use together with useNotification hook by default its placed top-left corner of screen (z-index: 1000)

Props:

NameTypeDefaultDescription
groupbooleanfalseGroup identical toasts together
showCountbooleantrueShow count when group = true
defaultTimeoutnumber5000default timeout for success, info, warning toast
Example
import React from 'react'
import { Notifications } from 'e30studio/components'

export const App: React.FC = () => {
    return <div>
        <Notifications />
        <div>
          <Home />
        </div>
    </div>
}
0.0.21

1 year ago

0.0.22

1 year ago

0.0.16

2 years ago

0.0.18

2 years ago

0.0.15

2 years ago

0.0.14

2 years ago

0.0.13

2 years ago

0.0.12

2 years ago

0.0.11

2 years ago

0.0.10

2 years ago

0.0.9

2 years ago

0.0.8

2 years ago

0.0.7

2 years ago

0.0.6

2 years ago

0.0.5

2 years ago

0.0.4

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago