0.0.40 • Published 10 months ago

e30studio v0.0.40

Weekly downloads
-
License
MIT
Repository
github
Last release
10 months ago

e30studio

This package is a collection of React hooks and components, its contains also useful services

Table of Contents


Installation

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>
}

Components

SplitView

The SplitView component allows you to create a two-column layout where the width of the left column is adjustable. This component is ideal for creating resizable sidebars or any other layout with an adjustable left pane.

Props:

NameOptionalTypeDefaultDescription
localStorageKeyyesstring'split-view'Key for localstorage to persist width across sessions
minWidthyesnumber200Minimal width of left column
maxWidthyesnumber800Maximal width of left column
Example
import React from 'react'
import { SplitView } from 'e30studio/components'

export const App: React.FC = () => {
    return <SplitView>
      <div>Left column</div>
      <div>Right column</div>
    </SplitView>
}

AutoSize

AutoSize component provide dimensions of container

Example
import { AutoSize } from 'e30studio/components'

export const TestExample = () => (
        <AutoSize>
          {({ width, height }) => (
                  <span>My container is {width}px x {height}px</span>
          )}
        </AutoSize>
)

CopyToClipboard

Wrapper component that provide copy to clipboard functionality

Example
import { ContentCopy } from '@mui/icons-material'
import { CopyToClipboard } from 'e30studio/components'

const WithIcon = ({ value }) => <CopyToClipboard value={value} icon={<ContentCopy />} />

const WithStyle = styled(WithIcon)`
display: flex;
gap: var(--theme-gap);

.value {
  font-weight: var(--theme-font-bold);
}

.icon {
  &:hover {
    transform: scale(1.1);
  }
}
`

Services

Service is a static class that can perform various things

LocalStorageService

interface ILocalStorageService {
  get<T>(key: string, defaultValue: T, parse?: boolean): T
  set(key: string, value: string | object): void
  clear(): void
}

example

import React from 'react'
import { LocalStorageService } from 'e30studio/services'

export const App: React.FC = () => {
    const value = LocalStorageService.get('my-value', 'default')
    const myObj = LocalStorageService.get('my-obj', { name: '', age: 0 }, true)
  
    return <div>
      <span>value: {value}</span>
      <span>value from object: {myObj.name}</span>
    </div>
}

SessionStorageService

works exactly the same as LocalStorageService but operates over SessionStorage

0.0.40

10 months ago

0.0.38

10 months ago

0.0.39

10 months ago

0.0.32

10 months ago

0.0.30

10 months ago

0.0.31

10 months ago

0.0.34

10 months ago

0.0.28

1 year ago

0.0.29

1 year ago

0.0.23

1 year ago

0.0.21

3 years ago

0.0.22

3 years ago

0.0.16

3 years ago

0.0.18

3 years ago

0.0.15

3 years ago

0.0.14

3 years ago

0.0.13

3 years ago

0.0.12

3 years ago

0.0.11

3 years ago

0.0.10

3 years ago

0.0.9

3 years ago

0.0.8

3 years ago

0.0.7

3 years ago

0.0.6

3 years ago

0.0.5

3 years ago

0.0.4

3 years ago

0.0.3

3 years ago

0.0.2

3 years ago