@bywin/drawer-hoc

1.0.2 • Public • Published

DrawerHOC Usage Guide

A high-order component for Ant Design Drawer.

Encapsulate Drawer

  1. Create the component and wrap it with DrawerHOC.
import DrawerHOC from '@bywin/drawer-hoc'
import React from 'react'
const XxxDrawer = (props) => {
const [form] = Form.useForm()
const model = {
  [key]: value
}
return (
  props.bindForm(form, model)({
    schema: {
      properties: [
        [
          {
            key: 'form field key',
            title: 'form field label',
            value: 'string or form field component'
          }
        ]
      ]
    }
  })
  )
}
export default DrawerHOC(XxxDrawer, {
  title: 'drawer title',
  type: 'ADD' | 'UPDATE' | 'DETAIL',
  events: {
    onOk: (dispatch, data) => {
      // TODO: handle form submition here with dispatch.
    }
  }
})
  1. Dispatch UI change
const dispatch = useDispatch()
dispatch({
  type: 'DrawerHOC/updateUI',
  payload: {
    XxxDrawer: {
      visible: true
    }
  }
})
  1. Add the corresponding component state in src/models/DrawerHOC.js file.
state: {
  UIState: {
    DispositionCreateDrawer: {
      visible: false
    },
    DispositionFeatureCreateDrawer: {
      visible: false
    },
    FeatureListUpdateDrawer: {
      visible: false
    },
    XxxDrawer: {
      visible: false
    },
  }
}
  1. Import the component in your page.
<XxxDrawer />
  1. Naming style of DrawerHOC.
  • XxxDetailDrawer
  • XxxCreateDrawer
  • XxxUpdateDrawer

Encapsulate Form

FormBuilder.createForm({
  schema: {
    properties: [
      [
        {
          key: 'form field key',
          title: 'form field label',
          value: 'string or form field component'
        }
      ]
    ]
  }
})

Readme

Keywords

Package Sidebar

Install

npm i @bywin/drawer-hoc

Weekly Downloads

2

Version

1.0.2

License

ISC

Unpacked Size

14 kB

Total Files

5

Last publish

Collaborators

  • bytrix