1.0.81 • Published 4 years ago

ucworks-client-desktop-common v1.0.81

Weekly downloads
-
License
ISC
Repository
-
Last release
4 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

4 years ago

1.0.78

4 years ago

1.0.80

4 years ago

1.0.81

4 years ago

1.0.76

4 years ago

1.0.66

4 years ago

1.0.69

4 years ago

1.0.68

4 years ago

1.0.67

4 years ago

1.0.73

4 years ago

1.0.72

4 years ago

1.0.71

4 years ago

1.0.70

4 years ago

1.0.77

4 years ago

1.0.75

4 years ago

1.0.74

4 years ago

1.0.65

4 years ago

1.0.64

4 years ago

1.0.63

4 years ago

1.0.62

4 years ago

1.0.61

4 years ago

1.0.60

4 years ago

1.0.59

4 years ago

1.0.58

4 years ago

1.0.55

4 years ago

1.0.54

4 years ago

1.0.57

4 years ago

1.0.56

4 years ago

1.0.43

4 years ago

1.0.48

4 years ago

1.0.47

4 years ago

1.0.46

4 years ago

1.0.45

4 years ago

1.0.49

4 years ago

1.0.51

4 years ago

1.0.50

4 years ago

1.0.53

4 years ago

1.0.52

4 years ago

1.0.39

4 years ago

1.0.40

4 years ago

1.0.42

4 years ago

1.0.41

4 years ago

1.0.38

4 years ago

1.0.37

4 years ago

1.0.33

4 years ago

1.0.32

4 years ago

1.0.35

4 years ago

1.0.34

4 years ago

1.0.29

4 years ago

1.0.31

4 years ago

1.0.30

4 years ago

1.0.28

4 years ago

1.0.27

4 years ago

1.0.22

4 years ago

1.0.21

4 years ago

1.0.20

4 years ago

1.0.26

4 years ago

1.0.25

4 years ago

1.0.24

4 years ago

1.0.23

4 years ago

1.0.19

4 years ago

1.0.18

4 years ago

1.0.17

4 years ago

1.0.16

4 years ago

1.0.15

4 years ago

1.0.14

4 years ago

1.0.13

4 years ago

1.0.12

4 years ago

1.0.11

4 years ago

1.0.10

4 years ago

1.0.9

4 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago