1.0.81 • Published 2 years ago

ucworks-client-desktop-common v1.0.81

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

Project is maintained (v1.0.38)

this project contains components and custom hooks that is used by ucworks desktop team.

Table of contents

  • Installation
  • components
  • hooks

Installation

Using npm

npm install --save ucworks-client-desktop-common

Using yarn

yarn add ucworks-client-desktop-common

write these codes into your project.

// for providing palettes in whole project.
// index.tsx
/** @jsx jsx */
import { jsx } from '@emotion/react';
import { UcThemeProvider } from 'ucworks-client-desktop-common';
import { render } from 'react-dom';
import App from './routes/app.route';
import 'ucworks-client-desktop-common/lib/index.css';

render(
  <UcThemeProvider>
    <App />
  </UcThemeProvider>,
  document.getElementById('root')
);

// theme.d.ts
// for intellisense 
import { UcTheme } from "ucworks-client-desktop-common";

declare module "@emotion/react" {
  interface Theme extends UcTheme {}
}

components

<Button/>

PropTypes

PropertyTypeRequired?DefaultDescription
colorThemestringnonedetermine button's color
overrideInterpolationoverride default css

<Checkbox/>

PropTypes

PropertyTypeRequired?DefaultDescription
Partial<UseFormRegisterReturn>return value of register
labelstringdescription for checkbox
overrideInterpolationoverride default css

usages

import { Checkbox, Button } from "ucworks-client-desktop-common";

const App = () => {
  const {handleSubmit, register} = useForm();
  return (
    <form onSubmit={handleSubmit((data) => {console.log(data)})}>
      <Checkbox label="checkbox" {...register("checkbox")}/>
      <Button type="submit">submit</Button>
    </form>);
}

<Radio/>

PropTypes

PropertyTypeRequired?DefaultDescription
Partial<UseFormRegisterReturn>return value of register
labelstringdescription for checkbox
valueanyvalue of radio group
overrideInterpolationoverride default css

usages

import { Radio, Button } from "ucworks-client-desktop-common";

const App = () => {
  const {handleSubmit, register} = useForm();
  return (
    <form onSubmit={handleSubmit((data) => {console.log(data)})}>
      <Radio label="딸기" {...register('food')} value="strawberry" />
      <Radio label="바나나" {...register('food')} value="banana" />
      <Button type="submit">submit</Button>
    </form>);
}

<Input/>

PropTypes

PropertyTypeRequired?DefaultDescription
type"number" | "text" | "password"input types
Partial<UseFormRegisterReturn>return value of register
errorsFieldErrorskey of FormState
overrideInterpolationoverride default css

usages

import { Input, Button } from "ucworks-client-desktop-common";

const App = () => {
  const {handleSubmit, register, formState} = useForm({
    resolver: yupResolver(
      yup.object({
        input: yup.string().required("fill the input!"),
      })
    ),
  });
  return (
    <form onSubmit={handleSubmit((data) => {console.log(data)})}>
      <Input type="text" {...register("input")} errors={formState.errors}/>
      <Button type="submit">submit</Button>
    </form>);
}

<Table/>

PropTypes

PropertyTypeRequired?DefaultDescription
columnsColumn[]table columns
dataany[]table data
initialStateTableStatedetermine initial table state(ex. hiddenColumns)
renderCell(cell: Cell) => React.Reactdetermine a shape of each cell
selectablebooleanfalsedetermine if the table is selectable(should be used with onSelect())
onSelect(selectedRow: Row) => voidcalled after rows are selected
searchValuestringfilter rows by given value.
overrideInterpolationoverride default css

usages

import { Table } from "ucworks-client-desktop-common";

const App = () => {
  const columns = [
    {
      Header: "foo",
      accessor: "foo",
      minWidth: 100,
    },
    { Header: "bar", accessor: "bar", minWidth: 100 },
  ];

  const data = [
    { foo: "foo1", bar: "bar1" },
    { foo: "foo2", bar: "bar2" },
  ];

  return (
    <Table
      selectable
      columns={columns}
      data={data}
      onSelect={(row) => {
        console.log(row);
      }}
    />
  )
}

hooks

useSelect()

PropsTypes

PropertyTypeRequired?DefaultDescription
itemsUseSelectItem[]treeItem of select
initialKeystring | numberitems0.keytreeItem which is displayed at first
disabledbooleanfalsedetermine whether select button is disabled or not

useTab()

return TabComponent and current tab index

PropsTypes

PropertyTypeRequired?DefaultDescription
rowsstring[]tab title that is displayed
initialRownumber0tab index that is displayed at first

Usages

import { useTab } from "ucworks-client-desktop-common";

const App = () => {
  const [current, Tab] = useTab({
    rows: ["foo", "bar"],
    initialRow: 1,
  });
  return (
    <>
      <Tab />
      {current === 0 ? <span>foo</span> : <span>bar</span>}
    </>
  );
};

useModal()

return Portal, toggle functions and boolean that represents if the modal is visible or not.

PropsTypes

PropertyTypeRequired?DefaultDescription
overlaybooleantrueDetermine if overlay is visible
closeOnOutsideClickbooleantrueDetermine if the modal is closed when a user clicked outside of modal

Usages

import { useModal } from "ucworks-client-desktop-common";

const App = () => {
  const { openModal, closeModal, isOpen, Modal } = useModal();

  return (
    <>
      <button
        type="button"
        onClick={(e) => {
          openModal(e);
        }}
      >
        clickme!
      </button>
      {isOpen && (
        <Modal>
          <span>modal</span>
        </Modal>
      )}
    </>
  );
};
1.0.79

2 years ago

1.0.78

2 years ago

1.0.80

2 years ago

1.0.81

2 years ago

1.0.76

2 years ago

1.0.66

3 years ago

1.0.69

3 years ago

1.0.68

3 years ago

1.0.67

3 years ago

1.0.73

3 years ago

1.0.72

3 years ago

1.0.71

3 years ago

1.0.70

3 years ago

1.0.77

3 years ago

1.0.75

3 years ago

1.0.74

3 years ago

1.0.65

3 years ago

1.0.64

3 years ago

1.0.63

3 years ago

1.0.62

3 years ago

1.0.61

3 years ago

1.0.60

3 years ago

1.0.59

3 years ago

1.0.58

3 years ago

1.0.55

3 years ago

1.0.54

3 years ago

1.0.57

3 years ago

1.0.56

3 years ago

1.0.43

3 years ago

1.0.48

3 years ago

1.0.47

3 years ago

1.0.46

3 years ago

1.0.45

3 years ago

1.0.49

3 years ago

1.0.51

3 years ago

1.0.50

3 years ago

1.0.53

3 years ago

1.0.52

3 years ago

1.0.39

3 years ago

1.0.40

3 years ago

1.0.42

3 years ago

1.0.41

3 years ago

1.0.38

3 years ago

1.0.37

3 years ago

1.0.33

3 years ago

1.0.32

3 years ago

1.0.35

3 years ago

1.0.34

3 years ago

1.0.29

3 years ago

1.0.31

3 years ago

1.0.30

3 years ago

1.0.28

3 years ago

1.0.27

3 years ago

1.0.22

3 years ago

1.0.21

3 years ago

1.0.20

3 years ago

1.0.26

3 years ago

1.0.25

3 years ago

1.0.24

3 years ago

1.0.23

3 years ago

1.0.19

3 years ago

1.0.18

3 years ago

1.0.17

3 years ago

1.0.16

3 years ago

1.0.15

3 years ago

1.0.14

3 years ago

1.0.13

3 years ago

1.0.12

3 years ago

1.0.11

3 years ago

1.0.10

3 years ago

1.0.9

3 years ago

1.0.8

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago