dinocollab-core 1.0.0 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/_virtual/_rollupPluginBabelHelpers.js +67 -10
- package/dist/_virtual/_rollupPluginBabelHelpers.js.map +1 -1
- package/dist/{src/api-context → api-context}/alert-global.js +49 -34
- package/dist/api-context/alert-global.js.map +1 -0
- package/dist/{src/api-context → api-context}/drawer-global.js +40 -33
- package/dist/api-context/drawer-global.js.map +1 -0
- package/dist/{src/api-context → api-context}/global-modal.js +40 -32
- package/dist/api-context/global-modal.js.map +1 -0
- package/dist/{src/api-context → api-context}/popover-global.js +44 -36
- package/dist/api-context/popover-global.js.map +1 -0
- package/dist/api-context/popover.js +94 -0
- package/dist/api-context/popover.js.map +1 -0
- package/dist/{src/api-context → api-context}/ui.units.js +12 -10
- package/dist/api-context/ui.units.js.map +1 -0
- package/dist/components/breadcrumbs.js +65 -0
- package/dist/components/breadcrumbs.js.map +1 -0
- package/dist/{src/components → components}/copy-to-clipboard.js +39 -32
- package/dist/components/copy-to-clipboard.js.map +1 -0
- package/dist/components/help-tooltip.js +104 -0
- package/dist/components/help-tooltip.js.map +1 -0
- package/dist/components/image-with-fallback.js +51 -0
- package/dist/components/image-with-fallback.js.map +1 -0
- package/dist/{src/components → components}/text-editor.js +24 -23
- package/dist/components/text-editor.js.map +1 -0
- package/dist/components/text-editor.preview.js +27 -0
- package/dist/components/text-editor.preview.js.map +1 -0
- package/dist/form/create.autocomplete.chips.js +228 -0
- package/dist/form/create.autocomplete.chips.js.map +1 -0
- package/dist/{src/form → form}/create.date-expired.js +71 -61
- package/dist/form/create.date-expired.js.map +1 -0
- package/dist/{src/form → form}/create.date-picker.js +40 -37
- package/dist/form/create.date-picker.js.map +1 -0
- package/dist/{src/form → form}/create.form-base.js +47 -41
- package/dist/form/create.form-base.js.map +1 -0
- package/dist/form/create.form-comfirm.js +131 -0
- package/dist/form/create.form-comfirm.js.map +1 -0
- package/dist/form/create.form-grid-layout.js +188 -0
- package/dist/form/create.form-grid-layout.js.map +1 -0
- package/dist/{src/form → form}/create.form-grid-layout.units.js +17 -14
- package/dist/form/create.form-grid-layout.units.js.map +1 -0
- package/dist/form/create.input.file.js +79 -0
- package/dist/form/create.input.file.js.map +1 -0
- package/dist/form/create.input.js +276 -0
- package/dist/form/create.input.js.map +1 -0
- package/dist/form/create.select-simple.js +114 -0
- package/dist/form/create.select-simple.js.map +1 -0
- package/dist/form/create.select-with-api.js +277 -0
- package/dist/form/create.select-with-api.js.map +1 -0
- package/dist/form/create.text-editor.js +181 -0
- package/dist/form/create.text-editor.js.map +1 -0
- package/dist/{src/form → form}/dino-form.js +17 -18
- package/dist/form/dino-form.js.map +1 -0
- package/dist/{src/form → form}/helper.js +14 -14
- package/dist/form/helper.js.map +1 -0
- package/dist/{src/form → form}/modal-wrapper.js +32 -25
- package/dist/form/modal-wrapper.js.map +1 -0
- package/dist/{src/form → form}/validator.js +47 -43
- package/dist/form/validator.js.map +1 -0
- package/dist/{src/hooks → hooks}/index.js +1 -1
- package/dist/hooks/index.js.map +1 -0
- package/dist/index.d.ts +928 -0
- package/dist/{src/index.js → index.js} +10 -3
- package/dist/{src/index.js.map → index.js.map} +1 -1
- package/dist/redux/create.hoc-lazy.js +71 -0
- package/dist/redux/create.hoc-lazy.js.map +1 -0
- package/dist/{src/redux → redux}/dino.js +2 -2
- package/dist/redux/dino.js.map +1 -0
- package/dist/redux/types.js.map +1 -0
- package/dist/redux/ui.error-page.js +89 -0
- package/dist/redux/ui.error-page.js.map +1 -0
- package/dist/redux/vector-404.webp.js.map +1 -0
- package/dist/{src/table → table}/context.js +5 -2
- package/dist/table/context.js.map +1 -0
- package/dist/table/create.action-row.js +144 -0
- package/dist/table/create.action-row.js.map +1 -0
- package/dist/table/create.table.js +246 -0
- package/dist/table/create.table.js.map +1 -0
- package/dist/{src/table → table}/custom.filter-operators.js +2 -2
- package/dist/table/custom.filter-operators.js.map +1 -0
- package/dist/table/dino.js +136 -0
- package/dist/table/dino.js.map +1 -0
- package/dist/{src/table → table}/helpers.js +31 -32
- package/dist/table/helpers.js.map +1 -0
- package/dist/table/model-filter.js.map +1 -0
- package/dist/table/toolbar-pannel.js +143 -0
- package/dist/table/toolbar-pannel.js.map +1 -0
- package/dist/table/ui.buttons.js +67 -0
- package/dist/table/ui.buttons.js.map +1 -0
- package/dist/table/ui.units.js +248 -0
- package/dist/table/ui.units.js.map +1 -0
- package/dist/types/api-context/alert-global.d.ts +29 -0
- package/dist/types/api-context/drawer-global.d.ts +32 -0
- package/dist/types/api-context/global-modal.d.ts +37 -0
- package/dist/types/api-context/index.d.ts +9 -0
- package/dist/types/api-context/popover-global.d.ts +37 -0
- package/dist/types/api-context/popover.d.ts +32 -0
- package/dist/types/api-context/ui.units.d.ts +2 -0
- package/dist/types/components/breadcrumbs.d.ts +13 -0
- package/dist/types/components/copy-to-clipboard.d.ts +26 -0
- package/dist/types/components/help-tooltip.d.ts +15 -0
- package/dist/types/components/image-with-fallback.d.ts +13 -0
- package/dist/types/components/index.d.ts +11 -0
- package/dist/types/components/input-debounce-timer.d.ts +9 -0
- package/dist/types/components/loading-buttons.d.ts +6 -0
- package/dist/types/components/text-editor.d.ts +26 -0
- package/dist/types/components/text-editor.preview.d.ts +5 -0
- package/dist/types/form/create.autocomplete.chips.d.ts +16 -0
- package/dist/types/form/create.date-expired.d.ts +19 -0
- package/dist/types/form/create.date-picker.d.ts +19 -0
- package/dist/types/form/create.form-base.d.ts +30 -0
- package/dist/types/form/create.form-comfirm.d.ts +20 -0
- package/dist/types/form/create.form-grid-layout.d.ts +44 -0
- package/dist/types/form/create.form-grid-layout.units.d.ts +8 -0
- package/dist/types/form/create.input.d.ts +29 -0
- package/dist/types/form/create.input.file.d.ts +16 -0
- package/dist/types/form/create.select-simple.d.ts +24 -0
- package/dist/types/form/create.select-with-api.d.ts +29 -0
- package/dist/types/form/create.text-editor.d.ts +42 -0
- package/dist/types/form/dino-form.d.ts +26 -0
- package/dist/types/form/helper.d.ts +14 -0
- package/dist/types/form/index.d.ts +7 -0
- package/dist/types/form/modal-wrapper.d.ts +14 -0
- package/dist/types/form/types.d.ts +15 -0
- package/dist/types/form/validator.d.ts +64 -0
- package/dist/types/hooks/index.d.ts +4 -0
- package/dist/types/index.d.ts +7 -0
- package/dist/types/lab/create.autocomplete.simple.d.ts +19 -0
- package/dist/types/lab/create.dino-store.d.ts +1 -0
- package/dist/types/lab/create.multi-select-dropdown.d.ts +23 -0
- package/dist/types/lab/create.select-mul-with-api/index.d.ts +26 -0
- package/dist/types/lab/create.select-mul-with-api/table-custom.d.ts +43 -0
- package/dist/types/lab/create.select-mul-with-api/types.d.ts +21 -0
- package/dist/types/lab/create.select-mul-with-api/ui.units.d.ts +29 -0
- package/dist/types/lab/filter-bar/base.d.ts +34 -0
- package/dist/types/lab/filter-bar/create.filter-bar.d.ts +92 -0
- package/dist/types/lab/filter-bar/create.filter-menu.d.ts +66 -0
- package/dist/types/lab/filter-bar/create.filter-panel.d.ts +117 -0
- package/dist/types/lab/filter-bar/create.filtered.d.ts +59 -0
- package/dist/types/lab/filter-bar/create.sort-menu.d.ts +7 -0
- package/dist/types/lab/filter-bar/demo.d.ts +3 -0
- package/dist/types/lab/filter-bar/index.d.ts +4 -0
- package/dist/types/lab/filter-bar/types.d.ts +81 -0
- package/dist/types/lab/filter-bar/ui.units.d.ts +13 -0
- package/dist/types/lab/grafana-dashboard/configs.d.ts +4 -0
- package/dist/types/lab/grafana-dashboard/date-time-range/absolute-time-rage.d.ts +14 -0
- package/dist/types/lab/grafana-dashboard/date-time-range/helpers.d.ts +36 -0
- package/dist/types/lab/grafana-dashboard/date-time-range/index.d.ts +24 -0
- package/dist/types/lab/grafana-dashboard/date-time-range/menu-wrap.d.ts +19 -0
- package/dist/types/lab/grafana-dashboard/date-time-range/quick-ranges.d.ts +20 -0
- package/dist/types/lab/grafana-dashboard/date-time-range/types.d.ts +8 -0
- package/dist/types/lab/grafana-dashboard/date-time-range/units.d.ts +2 -0
- package/dist/types/lab/grafana-dashboard/helper.d.ts +7 -0
- package/dist/types/lab/grafana-dashboard/hooks.d.ts +10 -0
- package/dist/types/lab/grafana-dashboard/icons.d.ts +5 -0
- package/dist/types/lab/grafana-dashboard/index.d.ts +12 -0
- package/dist/types/lab/grafana-dashboard/top-bar.d.ts +19 -0
- package/dist/types/lab/grafana-dashboard/top-bar.types.d.ts +4 -0
- package/dist/types/lab/grafana-dashboard/types.d.ts +8 -0
- package/dist/types/lab/media-player.core1.d.ts +14 -0
- package/dist/types/lab/media-player.muted.d.ts +10 -0
- package/dist/types/lab/media-player.units.d.ts +36 -0
- package/dist/types/lab/table-grid/create.table-grid.d.ts +4 -0
- package/dist/types/lab/table-grid/demo.d.ts +3 -0
- package/dist/types/lab/table-grid/dino.d.ts +6 -0
- package/dist/types/lab/table-grid/helpers.d.ts +11 -0
- package/dist/types/lab/table-grid/index.d.ts +2 -0
- package/dist/types/lab/table-grid/item-actions.d.ts +93 -0
- package/dist/types/lab/table-grid/toolbar-pannel.d.ts +27 -0
- package/dist/types/lab/table-grid/types.d.ts +56 -0
- package/dist/types/redux/create.hoc-lazy.d.ts +19 -0
- package/dist/types/redux/dino.d.ts +6 -0
- package/dist/types/redux/index.d.ts +4 -0
- package/dist/types/redux/types.d.ts +22 -0
- package/dist/types/redux/ui.error-page.d.ts +3 -0
- package/dist/types/redux/ui.units.d.ts +9 -0
- package/dist/types/table/context.d.ts +8 -0
- package/dist/types/table/create.action-row.d.ts +16 -0
- package/dist/types/table/create.table.d.ts +33 -0
- package/dist/types/table/custom.filter-operators.d.ts +2 -0
- package/dist/types/table/dino.d.ts +41 -0
- package/dist/types/table/helpers.d.ts +23 -0
- package/dist/types/table/index.d.ts +7 -0
- package/dist/types/table/model-filter.d.ts +38 -0
- package/dist/types/table/toolbar-pannel.d.ts +18 -0
- package/dist/types/table/types.d.ts +40 -0
- package/dist/types/table/ui.buttons.d.ts +16 -0
- package/dist/types/table/ui.units.d.ts +62 -0
- package/dist/types/utils/dayjs-config.d.ts +2 -0
- package/dist/types/utils/helpers.d.ts +35 -0
- package/dist/types/utils/index.d.ts +4 -0
- package/dist/types/utils/json-object.d.ts +9 -0
- package/dist/types/utils/mfe-events.d.ts +12 -0
- package/dist/types/utils/query-param.d.ts +25 -0
- package/dist/utils/dayjs-config.js.map +1 -0
- package/dist/{src/utils → utils}/helpers.js +11 -9
- package/dist/utils/helpers.js.map +1 -0
- package/dist/{src/utils → utils}/json-object.js +13 -13
- package/dist/utils/json-object.js.map +1 -0
- package/dist/{src/utils → utils}/query-param.js +17 -17
- package/dist/utils/query-param.js.map +1 -0
- package/package.json +18 -4
- package/dist/node_modules/.pnpm/@rollup_plugin-typescript@1_d0d2002d9033600b6738d939bd598bc6/node_modules/tslib/tslib.es6.js +0 -46
- package/dist/node_modules/.pnpm/@rollup_plugin-typescript@1_d0d2002d9033600b6738d939bd598bc6/node_modules/tslib/tslib.es6.js.map +0 -1
- package/dist/src/api-context/alert-global.js.map +0 -1
- package/dist/src/api-context/drawer-global.js.map +0 -1
- package/dist/src/api-context/global-modal.js.map +0 -1
- package/dist/src/api-context/popover-global.js.map +0 -1
- package/dist/src/api-context/popover.js +0 -86
- package/dist/src/api-context/popover.js.map +0 -1
- package/dist/src/api-context/ui.units.js.map +0 -1
- package/dist/src/components/copy-to-clipboard.js.map +0 -1
- package/dist/src/components/custom.breadcrumbs.js +0 -61
- package/dist/src/components/custom.breadcrumbs.js.map +0 -1
- package/dist/src/components/help-tooltip.js +0 -91
- package/dist/src/components/help-tooltip.js.map +0 -1
- package/dist/src/components/image-with-fallback.js +0 -48
- package/dist/src/components/image-with-fallback.js.map +0 -1
- package/dist/src/components/text-editor.js.map +0 -1
- package/dist/src/form/create.autocomplete.chips.js +0 -218
- package/dist/src/form/create.autocomplete.chips.js.map +0 -1
- package/dist/src/form/create.date-expired.js.map +0 -1
- package/dist/src/form/create.date-picker.js.map +0 -1
- package/dist/src/form/create.form-base.js.map +0 -1
- package/dist/src/form/create.form-comfirm.js +0 -119
- package/dist/src/form/create.form-comfirm.js.map +0 -1
- package/dist/src/form/create.form-grid-layout.js +0 -177
- package/dist/src/form/create.form-grid-layout.js.map +0 -1
- package/dist/src/form/create.form-grid-layout.units.js.map +0 -1
- package/dist/src/form/create.input-base.js +0 -260
- package/dist/src/form/create.input-base.js.map +0 -1
- package/dist/src/form/create.input.file.js +0 -74
- package/dist/src/form/create.input.file.js.map +0 -1
- package/dist/src/form/create.select-simple.js +0 -104
- package/dist/src/form/create.select-simple.js.map +0 -1
- package/dist/src/form/create.select-with-api.js +0 -271
- package/dist/src/form/create.select-with-api.js.map +0 -1
- package/dist/src/form/create.text-editor.js +0 -156
- package/dist/src/form/create.text-editor.js.map +0 -1
- package/dist/src/form/dino-form.js.map +0 -1
- package/dist/src/form/helper.js.map +0 -1
- package/dist/src/form/modal-wrapper.js.map +0 -1
- package/dist/src/form/validator.js.map +0 -1
- package/dist/src/hooks/index.js.map +0 -1
- package/dist/src/redux/create.hoc-lazy.js +0 -67
- package/dist/src/redux/create.hoc-lazy.js.map +0 -1
- package/dist/src/redux/dino.js.map +0 -1
- package/dist/src/redux/types.js.map +0 -1
- package/dist/src/redux/ui.error-page.js +0 -80
- package/dist/src/redux/ui.error-page.js.map +0 -1
- package/dist/src/redux/vector-404.webp.js.map +0 -1
- package/dist/src/table/context.js.map +0 -1
- package/dist/src/table/create.action-row.js +0 -135
- package/dist/src/table/create.action-row.js.map +0 -1
- package/dist/src/table/create.status-cell.js +0 -49
- package/dist/src/table/create.status-cell.js.map +0 -1
- package/dist/src/table/create.table.js +0 -233
- package/dist/src/table/create.table.js.map +0 -1
- package/dist/src/table/custom.filter-operators.js.map +0 -1
- package/dist/src/table/dino.js +0 -129
- package/dist/src/table/dino.js.map +0 -1
- package/dist/src/table/helpers.js.map +0 -1
- package/dist/src/table/model-filter.js.map +0 -1
- package/dist/src/table/toolbar-pannel.js +0 -134
- package/dist/src/table/toolbar-pannel.js.map +0 -1
- package/dist/src/table/ui.buttons.js +0 -60
- package/dist/src/table/ui.buttons.js.map +0 -1
- package/dist/src/table/ui.units.js +0 -201
- package/dist/src/table/ui.units.js.map +0 -1
- package/dist/src/utils/dayjs-config.js.map +0 -1
- package/dist/src/utils/helpers.js.map +0 -1
- package/dist/src/utils/json-object.js.map +0 -1
- package/dist/src/utils/query-param.js.map +0 -1
- package/rollup.config.js +0 -39
- package/src/@types/global.d.ts +0 -5
- package/src/api-context/alert-global.tsx +0 -174
- package/src/api-context/drawer-global.tsx +0 -116
- package/src/api-context/global-modal.tsx +0 -109
- package/src/api-context/index.ts +0 -13
- package/src/api-context/popover-global.tsx +0 -107
- package/src/api-context/popover.tsx +0 -89
- package/src/api-context/ui.units.tsx +0 -10
- package/src/components/copy-to-clipboard.tsx +0 -86
- package/src/components/custom.breadcrumbs.tsx +0 -67
- package/src/components/help-tooltip.tsx +0 -75
- package/src/components/image-with-fallback.tsx +0 -51
- package/src/components/index.tsx +0 -1
- package/src/components/input-debounce-timer.tsx +0 -138
- package/src/components/loading-buttons.tsx +0 -35
- package/src/components/text-editor.preview.tsx +0 -30
- package/src/components/text-editor.tsx +0 -125
- package/src/form/README.md +0 -55
- package/src/form/create.autocomplete.chips.tsx +0 -199
- package/src/form/create.date-expired.tsx +0 -195
- package/src/form/create.date-picker.tsx +0 -122
- package/src/form/create.form-base.tsx +0 -102
- package/src/form/create.form-comfirm.tsx +0 -83
- package/src/form/create.form-grid-layout.tsx +0 -170
- package/src/form/create.form-grid-layout.units.tsx +0 -37
- package/src/form/create.input-base.tsx +0 -222
- package/src/form/create.input.file.tsx +0 -76
- package/src/form/create.select-simple.tsx +0 -101
- package/src/form/create.select-with-api.tsx +0 -213
- package/src/form/create.text-editor.tsx +0 -161
- package/src/form/dino-form.tsx +0 -40
- package/src/form/helper.ts +0 -132
- package/src/form/index.ts +0 -12
- package/src/form/modal-wrapper.tsx +0 -75
- package/src/form/types.ts +0 -16
- package/src/form/validator.ts +0 -202
- package/src/hooks/index.ts +0 -44
- package/src/index.ts +0 -7
- package/src/lab/create.autocomplete.simple.tsx +0 -57
- package/src/lab/create.dino-store.ts +0 -59
- package/src/lab/create.multi-select-dropdown.tsx +0 -189
- package/src/lab/create.select-mul-with-api/index.tsx +0 -271
- package/src/lab/create.select-mul-with-api/table-custom.tsx +0 -194
- package/src/lab/create.select-mul-with-api/types.ts +0 -26
- package/src/lab/create.select-mul-with-api/ui.units.tsx +0 -163
- package/src/lab/filter-bar/base.tsx +0 -162
- package/src/lab/filter-bar/create.filter-bar.tsx +0 -190
- package/src/lab/filter-bar/create.filter-menu.tsx +0 -156
- package/src/lab/filter-bar/create.filter-panel.tsx +0 -95
- package/src/lab/filter-bar/create.filtered.tsx +0 -41
- package/src/lab/filter-bar/create.sort-menu.tsx +0 -43
- package/src/lab/filter-bar/demo.tsx +0 -50
- package/src/lab/filter-bar/index.ts +0 -6
- package/src/lab/filter-bar/types.ts +0 -105
- package/src/lab/filter-bar/ui.units.tsx +0 -70
- package/src/lab/grafana-dashboard/configs.ts +0 -43
- package/src/lab/grafana-dashboard/date-time-range/absolute-time-rage.tsx +0 -137
- package/src/lab/grafana-dashboard/date-time-range/helpers.ts +0 -126
- package/src/lab/grafana-dashboard/date-time-range/index.tsx +0 -62
- package/src/lab/grafana-dashboard/date-time-range/menu-wrap.tsx +0 -101
- package/src/lab/grafana-dashboard/date-time-range/quick-ranges.tsx +0 -161
- package/src/lab/grafana-dashboard/date-time-range/types.ts +0 -9
- package/src/lab/grafana-dashboard/date-time-range/units.tsx +0 -18
- package/src/lab/grafana-dashboard/helper.ts +0 -25
- package/src/lab/grafana-dashboard/hooks.tsx +0 -79
- package/src/lab/grafana-dashboard/icons.tsx +0 -67
- package/src/lab/grafana-dashboard/index.tsx +0 -120
- package/src/lab/grafana-dashboard/top-bar.tsx +0 -62
- package/src/lab/grafana-dashboard/top-bar.types.ts +0 -5
- package/src/lab/grafana-dashboard/types.ts +0 -8
- package/src/lab/media-player.core1.tsx +0 -273
- package/src/lab/media-player.muted.tsx +0 -62
- package/src/lab/media-player.units.ts +0 -80
- package/src/lab/table-grid/create.table-grid.tsx +0 -183
- package/src/lab/table-grid/demo.tsx +0 -53
- package/src/lab/table-grid/dino.tsx +0 -8
- package/src/lab/table-grid/helpers.tsx +0 -11
- package/src/lab/table-grid/index.ts +0 -3
- package/src/lab/table-grid/item-actions.tsx +0 -138
- package/src/lab/table-grid/toolbar-pannel.tsx +0 -98
- package/src/lab/table-grid/types.ts +0 -68
- package/src/redux/create.hoc-lazy.tsx +0 -80
- package/src/redux/dino.ts +0 -9
- package/src/redux/index.ts +0 -6
- package/src/redux/types.ts +0 -27
- package/src/redux/ui.error-page.tsx +0 -62
- package/src/redux/ui.units.tsx +0 -41
- package/src/redux/vector-404.webp +0 -0
- package/src/table/context.tsx +0 -16
- package/src/table/create.action-row.tsx +0 -91
- package/src/table/create.status-cell.tsx +0 -51
- package/src/table/create.table.tsx +0 -239
- package/src/table/custom.filter-operators.ts +0 -94
- package/src/table/dino.tsx +0 -120
- package/src/table/helpers.ts +0 -94
- package/src/table/index.ts +0 -13
- package/src/table/model-filter.ts +0 -43
- package/src/table/toolbar-pannel.tsx +0 -106
- package/src/table/types.ts +0 -50
- package/src/table/ui.buttons.tsx +0 -54
- package/src/table/ui.units.tsx +0 -189
- package/src/utils/dayjs-config.ts +0 -13
- package/src/utils/helpers.ts +0 -171
- package/src/utils/index.ts +0 -7
- package/src/utils/json-object.ts +0 -29
- package/src/utils/mfe-events.tsx +0 -34
- package/src/utils/query-param.ts +0 -129
- package/tsconfig.json +0 -20
- /package/dist/{src/redux → redux}/types.js +0 -0
- /package/dist/{src/redux → redux}/vector-404.webp.js +0 -0
- /package/dist/{src/table → table}/model-filter.js +0 -0
- /package/dist/{src/utils → utils}/dayjs-config.js +0 -0
|
@@ -1,199 +0,0 @@
|
|
|
1
|
-
import React, { Component } from 'react'
|
|
2
|
-
import { Autocomplete, Chip, IconButton, styled, TextField, TextFieldProps, Tooltip, Typography } from '@mui/material'
|
|
3
|
-
import RemoveIcon from '@mui/icons-material/Remove'
|
|
4
|
-
import { IFormInputBase } from './types'
|
|
5
|
-
import { getErrorMessage } from './helper'
|
|
6
|
-
|
|
7
|
-
interface IOptions {
|
|
8
|
-
optionItems?: string[]
|
|
9
|
-
limitTags?: number
|
|
10
|
-
separator?: string
|
|
11
|
-
saveLocalStorageByKey?: string
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
interface IProps<T> extends IFormInputBase<T, IOptions> {}
|
|
15
|
-
|
|
16
|
-
interface IState {
|
|
17
|
-
value: string[]
|
|
18
|
-
options: string[]
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export default function CreateAutocompleteChip<T>(options?: IOptions) {
|
|
22
|
-
const separator = options?.separator || '|'
|
|
23
|
-
const limitTags = options?.limitTags || 2
|
|
24
|
-
const storeItems = options?.saveLocalStorageByKey ? AutocompleteChipStore.initial(options.saveLocalStorageByKey) : undefined
|
|
25
|
-
|
|
26
|
-
return class AutocompleteChip extends Component<IProps<T>, IState> {
|
|
27
|
-
constructor(props: IProps<T>) {
|
|
28
|
-
super(props)
|
|
29
|
-
this.state = {
|
|
30
|
-
value: this.getDefaultValue(),
|
|
31
|
-
options: this.getSelectOptions()
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
refInput: HTMLInputElement | null = null
|
|
36
|
-
render() {
|
|
37
|
-
const { name } = this.props
|
|
38
|
-
return (
|
|
39
|
-
<>
|
|
40
|
-
<Autocomplete
|
|
41
|
-
multiple
|
|
42
|
-
freeSolo
|
|
43
|
-
limitTags={limitTags}
|
|
44
|
-
value={this.state.value}
|
|
45
|
-
onChange={this.handleAddOption}
|
|
46
|
-
options={this.state.options}
|
|
47
|
-
renderOption={(props, option) => (
|
|
48
|
-
<ItemOption {...props} key={option}>
|
|
49
|
-
<Typography variant='subtitle1' sx={{ flex: 1 }}>
|
|
50
|
-
{option}
|
|
51
|
-
</Typography>
|
|
52
|
-
{this.isBtnRemoveOption(option) && (
|
|
53
|
-
<Tooltip title='Remove option' arrow placement='left'>
|
|
54
|
-
<IconButton size='small' onClick={(e) => this.handleRemoveItem(e, option)}>
|
|
55
|
-
<RemoveIcon fontSize='small' />
|
|
56
|
-
</IconButton>
|
|
57
|
-
</Tooltip>
|
|
58
|
-
)}
|
|
59
|
-
</ItemOption>
|
|
60
|
-
)}
|
|
61
|
-
renderTags={(tagValue, getTagProps) => {
|
|
62
|
-
return tagValue.map((option, index) => <Chip label={option} {...getTagProps({ index })} key={option.toString()} />)
|
|
63
|
-
}}
|
|
64
|
-
renderInput={(params) => <TextField {...params} variant='outlined' {...this.getTextFieldProps()} />}
|
|
65
|
-
/>
|
|
66
|
-
<input
|
|
67
|
-
ref={(ref) => {
|
|
68
|
-
this.refInput = ref
|
|
69
|
-
}}
|
|
70
|
-
hidden
|
|
71
|
-
type='text'
|
|
72
|
-
name={name?.toString()}
|
|
73
|
-
defaultValue={this.state.value.join(separator)}
|
|
74
|
-
/>
|
|
75
|
-
</>
|
|
76
|
-
)
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
handleRemoveItem = (e: React.MouseEvent<HTMLButtonElement, MouseEvent>, value: string) => {
|
|
80
|
-
e.preventDefault()
|
|
81
|
-
e.stopPropagation()
|
|
82
|
-
console.log(value)
|
|
83
|
-
const list = storeItems?.delete(value) ?? []
|
|
84
|
-
this.setState({ options: list })
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
handleAddOption = (_: React.SyntheticEvent, newValue: string[]) => {
|
|
88
|
-
if (options?.saveLocalStorageByKey) {
|
|
89
|
-
const options = storeItems?.setItems(this.state.options, newValue) ?? this.state.options
|
|
90
|
-
this.setState({ value: newValue, options })
|
|
91
|
-
} else {
|
|
92
|
-
this.setState({ value: newValue })
|
|
93
|
-
}
|
|
94
|
-
if (this.refInput) {
|
|
95
|
-
this.refInput.value = newValue.join(separator)
|
|
96
|
-
}
|
|
97
|
-
this.props.name && this.props.onBlur && this.props.onBlur(this.props.name)
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
isBtnRemoveOption = (value: string) => {
|
|
101
|
-
const isSelectedOption = this.state.value.findIndex((x) => x === value) < 0
|
|
102
|
-
const selectOptions = options?.optionItems ?? this.props.slots?.optionItems ?? []
|
|
103
|
-
const isDefault = selectOptions.findIndex((x) => x === value) < 0
|
|
104
|
-
return isDefault && isSelectedOption
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
getSelectOptions = () => {
|
|
108
|
-
let items = options?.optionItems ?? []
|
|
109
|
-
if (options?.saveLocalStorageByKey) {
|
|
110
|
-
items = storeItems?.getItemsAndMerge(items) ?? []
|
|
111
|
-
}
|
|
112
|
-
return items
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
getTextFieldProps = (): TextFieldProps => {
|
|
116
|
-
const { name, label, placeholder, onBlur, messageErrors } = this.props
|
|
117
|
-
const eMessage = getErrorMessage(messageErrors, name)
|
|
118
|
-
return {
|
|
119
|
-
label,
|
|
120
|
-
placeholder: placeholder || 'Add new',
|
|
121
|
-
onBlur: () => {
|
|
122
|
-
if (!name) return
|
|
123
|
-
onBlur && onBlur(name)
|
|
124
|
-
},
|
|
125
|
-
error: eMessage.error,
|
|
126
|
-
helperText: eMessage.message
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
getDefaultValue = (): string[] => {
|
|
131
|
-
const { name, data } = this.props
|
|
132
|
-
const value = name ? data?.[name]?.toString() : ''
|
|
133
|
-
return value?.split(separator).filter((x) => !!x) ?? []
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
const ItemOption = styled('li')({
|
|
139
|
-
display: 'flex',
|
|
140
|
-
alignItems: 'center'
|
|
141
|
-
})
|
|
142
|
-
|
|
143
|
-
type TChipStoreRoot = { [key: string]: string[] }
|
|
144
|
-
|
|
145
|
-
class AutocompleteChipStore {
|
|
146
|
-
private storeKeyRoot = 'autocomplete_chip_store'
|
|
147
|
-
private storeKey: string
|
|
148
|
-
constructor(key: string, defaultValue?: string[]) {
|
|
149
|
-
this.storeKey = key
|
|
150
|
-
if (defaultValue) {
|
|
151
|
-
this.setChild(defaultValue)
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
static initial = (key: string, defaultValue?: string[]) => new AutocompleteChipStore(key, defaultValue)
|
|
156
|
-
|
|
157
|
-
private getRoot = (): TChipStoreRoot => {
|
|
158
|
-
try {
|
|
159
|
-
const res = window.localStorage.getItem(this.storeKeyRoot)
|
|
160
|
-
return JSON.parse(res ?? '{}')
|
|
161
|
-
} catch (error) {
|
|
162
|
-
return {}
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
private getChild = (): string[] => {
|
|
167
|
-
return this.getRoot()[this.storeKey]
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
private setRoot = (value: TChipStoreRoot) => {
|
|
171
|
-
window.localStorage.setItem(this.storeKeyRoot, JSON.stringify(value))
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
private setChild = (value: string[]) => {
|
|
175
|
-
const obj = this.getRoot()
|
|
176
|
-
obj[this.storeKey] = value
|
|
177
|
-
this.setRoot(obj)
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
getItemsAndMerge = (value: string[]): string[] => {
|
|
181
|
-
try {
|
|
182
|
-
return Array.from(new Set([...this.getChild(), ...value])).sort()
|
|
183
|
-
} catch (error) {
|
|
184
|
-
return value
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
setItems = (options: string[], value: string[]): string[] => {
|
|
189
|
-
const list = Array.from(new Set([...options, ...value])).sort()
|
|
190
|
-
this.setChild(list)
|
|
191
|
-
return list
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
delete = (value: string) => {
|
|
195
|
-
const list = this.getChild().filter((x) => x !== value)
|
|
196
|
-
this.setChild(list)
|
|
197
|
-
return list
|
|
198
|
-
}
|
|
199
|
-
}
|
|
@@ -1,195 +0,0 @@
|
|
|
1
|
-
import React, { Component } from 'react'
|
|
2
|
-
import { LocalizationProvider } from '@mui/x-date-pickers'
|
|
3
|
-
import { AdapterDayjs } from '@mui/x-date-pickers/AdapterDayjs'
|
|
4
|
-
import { Switch, Typography, TextField, styled, Box, TextFieldProps } from '@mui/material'
|
|
5
|
-
import { dayjsCustom, mergeObjects, tryParseIntRequired } from '../utils'
|
|
6
|
-
import { IFormInputBase } from './types'
|
|
7
|
-
import { getErrorMessage } from './helper'
|
|
8
|
-
|
|
9
|
-
const defaultFormatString = 'MM-DD-YYYY'
|
|
10
|
-
|
|
11
|
-
const dateExpiredClasses = {
|
|
12
|
-
root: 'DateExpired-root',
|
|
13
|
-
control: 'DateExpired-control',
|
|
14
|
-
label: 'DateExpired-label',
|
|
15
|
-
labelSwitch: 'DateExpired-labelSwitch',
|
|
16
|
-
input: 'DateExpired-input',
|
|
17
|
-
switch: 'DateExpired-switch'
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
interface ISlots<T> {
|
|
21
|
-
/** @default string */
|
|
22
|
-
type?: 'number' | 'string'
|
|
23
|
-
textFieldProps?: Partial<TextFieldProps>
|
|
24
|
-
switchChecked?: boolean
|
|
25
|
-
switchCheckedGetter?: (value: any, model?: Partial<T>) => boolean
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
interface IProps<T> extends IFormInputBase<T> {
|
|
29
|
-
slots?: ISlots<T>
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
interface IState {
|
|
33
|
-
numberOfDays: number
|
|
34
|
-
switchChecked: boolean
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
function CreateDateExpired<T>(params?: ISlots<T>): React.ComponentType<IProps<T>> {
|
|
38
|
-
class DateExpired extends Component<IProps<T>, IState> {
|
|
39
|
-
defaultNumberOfDays: number = 30
|
|
40
|
-
private id
|
|
41
|
-
constructor(props: IProps<T>) {
|
|
42
|
-
super(props)
|
|
43
|
-
this.state = {
|
|
44
|
-
numberOfDays: this.getNumberOfDays(),
|
|
45
|
-
switchChecked: this.slots.switchChecked
|
|
46
|
-
}
|
|
47
|
-
this.id = new Date().getTime().toString()
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
get slots(): ISlots<T> & { switchChecked: boolean } {
|
|
51
|
-
const { switchChecked, switchCheckedGetter } = this.props.slots ?? {}
|
|
52
|
-
const obj = mergeObjects(params, this.props.slots)
|
|
53
|
-
let check = (this.defaulValue ? !!this.defaulValue : switchChecked) ?? true
|
|
54
|
-
if (switchCheckedGetter) check = switchCheckedGetter(this.defaulValue, this.props.data)
|
|
55
|
-
return { ...obj, switchChecked: check }
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
get defaulValue(): string {
|
|
59
|
-
const { data, name } = this.props
|
|
60
|
-
return this.props.defaultValue ?? (!!data && !!name ? data[name]?.toString() : undefined)
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
get defaultValueInput(): string | number {
|
|
64
|
-
if (this.slots.type === 'number') {
|
|
65
|
-
return this.state.numberOfDays
|
|
66
|
-
} else {
|
|
67
|
-
return this.getOffsetDate(this.state.numberOfDays, 'YYYY-MM-DDTHH:mm:ss.sssZ')
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
getNumberOfDays = (): number => {
|
|
72
|
-
if (this.slots.type === 'number') {
|
|
73
|
-
return tryParseIntRequired(this.defaulValue, this.defaultNumberOfDays)
|
|
74
|
-
} else {
|
|
75
|
-
return this.getDaysUntilDate(this.defaulValue, this.defaultNumberOfDays)
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
//#region Render
|
|
80
|
-
render() {
|
|
81
|
-
return (
|
|
82
|
-
<LocalizationProvider dateAdapter={AdapterDayjs}>
|
|
83
|
-
<Wrap className={dateExpiredClasses.root}>
|
|
84
|
-
<input key={this.defaultValueInput} type='text' hidden name={this.props.name?.toString()} defaultValue={this.defaultValueInput} />
|
|
85
|
-
<TextField {...this.mapTextFieldProps()} />
|
|
86
|
-
<div className={dateExpiredClasses.control}>
|
|
87
|
-
<Typography
|
|
88
|
-
variant='caption'
|
|
89
|
-
className={dateExpiredClasses.labelSwitch}
|
|
90
|
-
{...{ component: 'label', htmlFor: this.id }}
|
|
91
|
-
sx={{ color: this.state.switchChecked ? 'success.main' : '#767676' }}
|
|
92
|
-
>
|
|
93
|
-
{this.state.switchChecked ? 'Use Expiration Date' : 'No Expiration'}
|
|
94
|
-
</Typography>
|
|
95
|
-
<Switch
|
|
96
|
-
id={this.id}
|
|
97
|
-
size='small'
|
|
98
|
-
color='success'
|
|
99
|
-
checked={this.state.switchChecked}
|
|
100
|
-
onChange={(_, checked) => this.setState({ switchChecked: checked })}
|
|
101
|
-
/>
|
|
102
|
-
</div>
|
|
103
|
-
</Wrap>
|
|
104
|
-
</LocalizationProvider>
|
|
105
|
-
)
|
|
106
|
-
}
|
|
107
|
-
//#endregion
|
|
108
|
-
|
|
109
|
-
mapTextFieldProps = (): TextFieldProps => {
|
|
110
|
-
const { messageErrors, name, onBlur } = this.props
|
|
111
|
-
const disabled = this.props.disabled || !this.state.switchChecked
|
|
112
|
-
const obj: TextFieldProps = {
|
|
113
|
-
fullWidth: true,
|
|
114
|
-
className: dateExpiredClasses.input,
|
|
115
|
-
label: (
|
|
116
|
-
<span className={dateExpiredClasses.label}>
|
|
117
|
-
Expiry date
|
|
118
|
-
{this.state.switchChecked && <b>{this.getOffsetDate(this.state.numberOfDays)}</b>}
|
|
119
|
-
</span>
|
|
120
|
-
),
|
|
121
|
-
variant: 'outlined',
|
|
122
|
-
type: 'number',
|
|
123
|
-
disabled: disabled,
|
|
124
|
-
value: this.state.switchChecked ? this.state.numberOfDays : 0,
|
|
125
|
-
onChange: this.handleChange
|
|
126
|
-
}
|
|
127
|
-
if (!!name) {
|
|
128
|
-
obj.onBlur = () => onBlur && onBlur(name)
|
|
129
|
-
const temp = getErrorMessage(messageErrors, name)
|
|
130
|
-
if (temp.error) {
|
|
131
|
-
obj.error = Boolean(temp.error)
|
|
132
|
-
obj.helperText = temp.message ?? ''
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
return mergeObjects<TextFieldProps>({}, obj, this.slots.textFieldProps)
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
handleChange = (e: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) => {
|
|
139
|
-
const numberOfDays: number = e.target.value != '' ? parseInt(e.target.value) : 0
|
|
140
|
-
this.setState({ numberOfDays })
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
getOffsetDate = (num: number, formatString = defaultFormatString): string => {
|
|
144
|
-
return dayjsCustom().add(num, 'day').format(formatString)
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
getDaysUntilDate = (value?: string, defaultValue = 0): number => {
|
|
148
|
-
try {
|
|
149
|
-
if (!value) return defaultValue
|
|
150
|
-
const target = dayjsCustom(value)
|
|
151
|
-
const today = dayjsCustom()
|
|
152
|
-
const diff = target.diff(today, 'day', true)
|
|
153
|
-
return Math.round(diff)
|
|
154
|
-
} catch {
|
|
155
|
-
return defaultValue
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
return DateExpired
|
|
160
|
-
}
|
|
161
|
-
export default CreateDateExpired
|
|
162
|
-
|
|
163
|
-
const Wrap = styled(Box)({
|
|
164
|
-
display: 'flex',
|
|
165
|
-
alignItems: 'center',
|
|
166
|
-
gap: '10px',
|
|
167
|
-
position: 'relative',
|
|
168
|
-
[`.${dateExpiredClasses.switch}`]: {
|
|
169
|
-
margin: 0,
|
|
170
|
-
flex: '0 0 auto'
|
|
171
|
-
},
|
|
172
|
-
[`.${dateExpiredClasses.label}`]: {
|
|
173
|
-
b: {
|
|
174
|
-
color: '#1976d2',
|
|
175
|
-
marginLeft: '8px'
|
|
176
|
-
}
|
|
177
|
-
},
|
|
178
|
-
[`.${dateExpiredClasses.labelSwitch}`]: {
|
|
179
|
-
fontWeight: 600,
|
|
180
|
-
cursor: 'pointer'
|
|
181
|
-
},
|
|
182
|
-
[`.${dateExpiredClasses.control}`]: {
|
|
183
|
-
position: 'absolute',
|
|
184
|
-
top: 0,
|
|
185
|
-
right: 0,
|
|
186
|
-
height: '100%',
|
|
187
|
-
display: 'flex',
|
|
188
|
-
alignItems: 'center'
|
|
189
|
-
},
|
|
190
|
-
[`.${dateExpiredClasses.input}`]: {
|
|
191
|
-
'.MuiInputBase-input': {
|
|
192
|
-
paddingRight: '160px'
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
})
|
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
import React, { Component } from 'react'
|
|
2
|
-
import { styled } from '@mui/material'
|
|
3
|
-
import { AdapterDayjs } from '@mui/x-date-pickers/AdapterDayjs'
|
|
4
|
-
import { DatePicker as MUIDatePicker, LocalizationProvider, DatePickerProps } from '@mui/x-date-pickers'
|
|
5
|
-
import { dayjsCustom, mergeObjects } from '../utils'
|
|
6
|
-
import { IFormInputBase } from './types'
|
|
7
|
-
import { getErrorMessage } from './helper'
|
|
8
|
-
import { Dayjs } from 'dayjs'
|
|
9
|
-
|
|
10
|
-
const formatDefault = 'MM/DD/YYYY'
|
|
11
|
-
|
|
12
|
-
interface ISlots {
|
|
13
|
-
defaultValue?: string
|
|
14
|
-
minDate?: Dayjs
|
|
15
|
-
minDateOffset?: number
|
|
16
|
-
datePickerProps?: DatePickerProps<Dayjs>
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
interface IProps<T> extends IFormInputBase<T> {
|
|
20
|
-
format?: string
|
|
21
|
-
slots?: Omit<ISlots, 'defaultValue'>
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
interface IState {
|
|
25
|
-
value: Dayjs | null
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
const CreateDatePicker = function <T extends Object>(params?: ISlots): React.ComponentType<IProps<T>> {
|
|
29
|
-
class DatePicker extends Component<IProps<T>, IState> {
|
|
30
|
-
private _cachedSlots: ISlots = {}
|
|
31
|
-
constructor(props: IProps<T>) {
|
|
32
|
-
super(props)
|
|
33
|
-
this._cachedSlots = this.mergeSlots(props.slots) ?? {}
|
|
34
|
-
this.state = { value: this.getDefaultValue() }
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
get slots() {
|
|
38
|
-
return this._cachedSlots
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
componentDidUpdate(prevProps: IProps<T>) {
|
|
42
|
-
if (prevProps.slots !== this.props.slots) {
|
|
43
|
-
this._cachedSlots = this.mergeSlots(this.props.slots)
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
getDatePickerProps = (): DatePickerProps<Dayjs> => {
|
|
48
|
-
const delayInDays = params?.minDateOffset ?? 0
|
|
49
|
-
const minDate = delayInDays > 0 ? dayjsCustom().add(delayInDays, 'day').startOf('day') : params?.minDate
|
|
50
|
-
const label = this.props.label ?? this.props.name?.toString()
|
|
51
|
-
const format = this.props.format ?? formatDefault
|
|
52
|
-
const eMessage = getErrorMessage<T>(this.props.messageErrors, this.props.name)
|
|
53
|
-
const obj: DatePickerProps<Dayjs> = {
|
|
54
|
-
label,
|
|
55
|
-
format,
|
|
56
|
-
views: ['day', 'month', 'year'],
|
|
57
|
-
value: this.state.value,
|
|
58
|
-
onChange: this.handleChange,
|
|
59
|
-
disabled: this.props.disabled,
|
|
60
|
-
minDate,
|
|
61
|
-
slotProps: {
|
|
62
|
-
textField: { onBlur: this.handleBlur, fullWidth: true, error: eMessage.error, helperText: eMessage.message, variant: 'outlined' }
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
return mergeObjects(obj, params?.datePickerProps, this.slots?.datePickerProps)
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
refInput: HTMLInputElement | null = null
|
|
69
|
-
render() {
|
|
70
|
-
return (
|
|
71
|
-
<LocalizationProvider dateAdapter={AdapterDayjs}>
|
|
72
|
-
<CustomDatePicker {...this.getDatePickerProps()} />
|
|
73
|
-
<input
|
|
74
|
-
hidden
|
|
75
|
-
name={this.props.name?.toString()}
|
|
76
|
-
defaultValue={this.getDefaultValue()?.toDate().toISOString()}
|
|
77
|
-
ref={(ref) => (this.refInput = ref)}
|
|
78
|
-
/>
|
|
79
|
-
</LocalizationProvider>
|
|
80
|
-
)
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
private mergeSlots = (currentSlots?: ISlots): ISlots => {
|
|
84
|
-
return mergeObjects<ISlots>({}, params, currentSlots)
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
handleBlur = () => {
|
|
88
|
-
if (!this.props.name) return
|
|
89
|
-
this.props.onBlur && this.props.onBlur(this.props.name)
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
handleChange = (newValue: Dayjs | null) => {
|
|
93
|
-
this.setState({ value: newValue })
|
|
94
|
-
if (this.refInput) {
|
|
95
|
-
this.refInput.value = newValue && !isNaN(newValue.toDate().getTime()) ? newValue.toDate().toISOString() : ''
|
|
96
|
-
}
|
|
97
|
-
setTimeout(this.handleBlur, 50)
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
getDefaultValue = (): Dayjs => {
|
|
101
|
-
try {
|
|
102
|
-
if (!this.props.defaultValue && !this.slots.defaultValue && this.slots.minDateOffset) return dayjsCustom().add(1, 'day').startOf('day')
|
|
103
|
-
if (!this.props.defaultValue && this.slots.minDate) return this.slots.minDate
|
|
104
|
-
|
|
105
|
-
const { data, name } = this.props
|
|
106
|
-
const dValue = this.props.defaultValue ?? this.slots.defaultValue ?? (name ? data?.[name] : '')
|
|
107
|
-
return dValue ? dayjsCustom(dValue.toString()) : dayjsCustom()
|
|
108
|
-
} catch {
|
|
109
|
-
return dayjsCustom()
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
return DatePicker
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
export default CreateDatePicker
|
|
117
|
-
|
|
118
|
-
const CustomDatePicker = styled(MUIDatePicker<Dayjs>)({
|
|
119
|
-
'& .MuiInputBase-root::before, & .MuiInputBase-root::after': {
|
|
120
|
-
borderBottom: 'none !important'
|
|
121
|
-
}
|
|
122
|
-
})
|
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
import React, { Component } from 'react'
|
|
2
|
-
import { Box, SxProps, Theme } from '@mui/material'
|
|
3
|
-
import { IFormBase } from './types'
|
|
4
|
-
import { convertFormDataToJson, GetErrorFromResponse, SingleValidate, ValidateMerge } from './helper'
|
|
5
|
-
import FormValidator, { PartialError, SingleRuleValidate } from './validator'
|
|
6
|
-
|
|
7
|
-
interface IParam<TModel> {
|
|
8
|
-
validate?: FormValidator<Partial<TModel>>
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
interface IProps<TModel> {
|
|
12
|
-
sx?: SxProps<Theme>
|
|
13
|
-
validate?: FormValidator<Partial<TModel>>
|
|
14
|
-
onSubmit: (data: Partial<TModel>, e: React.FormEvent<HTMLFormElement>) => Promise<void>
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
interface IState<TModel> extends Pick<IFormBase<TModel>, 'messageErrors'> {
|
|
18
|
-
modelState?: Partial<TModel>
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export interface IFormContextBase<TModel> {
|
|
22
|
-
modelState?: Partial<TModel>
|
|
23
|
-
messageErrors: PartialError<TModel>
|
|
24
|
-
onBlur: (keyName: keyof TModel) => void
|
|
25
|
-
setError: (keyName: keyof TModel, message: string) => void
|
|
26
|
-
clearErrorAll: (keyName: keyof TModel) => void
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
const CreateFormBase = function <TModel>(param?: IParam<TModel>) {
|
|
30
|
-
const FormBaseContext = React.createContext<IFormContextBase<TModel>>({} as any)
|
|
31
|
-
class FormBase extends Component<React.PropsWithChildren<IProps<TModel>>, IState<TModel>> {
|
|
32
|
-
refForm: HTMLFormElement | null = null
|
|
33
|
-
constructor(props: IProps<TModel>) {
|
|
34
|
-
super(props)
|
|
35
|
-
this.validate = this.getValidate()
|
|
36
|
-
this.state = { messageErrors: {} }
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
setError = (keyName: keyof TModel, message: string) => {
|
|
40
|
-
const error = { [keyName]: [{ rule: SingleRuleValidate.Custom, message }] }
|
|
41
|
-
this.setState({
|
|
42
|
-
messageErrors: Object.assign({}, this.state.messageErrors, error)
|
|
43
|
-
})
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
clearErrorAll = () => {
|
|
47
|
-
this.setState({ messageErrors: {} })
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
render() {
|
|
51
|
-
const { onBlur, setError, clearErrorAll } = this
|
|
52
|
-
const { modelState, messageErrors } = this.state
|
|
53
|
-
return (
|
|
54
|
-
<Box component='form' sx={this.props.sx} ref={(ref: HTMLFormElement) => (this.refForm = ref)} onSubmit={this.onSubmit}>
|
|
55
|
-
<FormBaseContext.Provider value={{ setError, onBlur, clearErrorAll, modelState, messageErrors }}>
|
|
56
|
-
{this.props.children}
|
|
57
|
-
</FormBaseContext.Provider>
|
|
58
|
-
</Box>
|
|
59
|
-
)
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
private validate: FormValidator<Partial<TModel>>
|
|
63
|
-
onSubmit: React.FormEventHandler<HTMLFormElement> = async (e) => {
|
|
64
|
-
e.preventDefault()
|
|
65
|
-
const formData = new FormData(e.currentTarget as HTMLFormElement)
|
|
66
|
-
const model = convertFormDataToJson<TModel>(formData)
|
|
67
|
-
this.setState({ modelState: model })
|
|
68
|
-
const messageErrors = this.validate.run(model) as PartialError<TModel>
|
|
69
|
-
if (messageErrors) {
|
|
70
|
-
this.setState({ messageErrors: messageErrors })
|
|
71
|
-
if (Object.keys(messageErrors).length > 0) return
|
|
72
|
-
}
|
|
73
|
-
await this.props.onSubmit(model, e).catch((error) => {
|
|
74
|
-
const messageError = GetErrorFromResponse(error, model)
|
|
75
|
-
this.setState({ messageErrors: { ...this.state.messageErrors, ...(messageError || {}) } })
|
|
76
|
-
})
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
onBlur = (keyName: keyof TModel) => {
|
|
80
|
-
if (!this.refForm) return
|
|
81
|
-
const { messageErrors } = this.state
|
|
82
|
-
const formData = new FormData(this.refForm)
|
|
83
|
-
const model = convertFormDataToJson(formData)
|
|
84
|
-
this.setState({ modelState: model })
|
|
85
|
-
const error = SingleValidate<TModel, Partial<TModel>>(keyName, model, messageErrors, this.validate) || {}
|
|
86
|
-
this.setState({ messageErrors: error as PartialError<TModel> })
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
getValidate = (): FormValidator<Partial<TModel>> => {
|
|
90
|
-
const defaultValidate = new FormValidator<Partial<TModel>>({})
|
|
91
|
-
return ValidateMerge(defaultValidate, param?.validate, this.props.validate)
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
return {
|
|
96
|
-
Form: FormBase,
|
|
97
|
-
Validator: param?.validate,
|
|
98
|
-
Context: FormBaseContext,
|
|
99
|
-
contextMapping: (params: (context: IFormContextBase<TModel>) => JSX.Element) => <FormBaseContext.Consumer>{params}</FormBaseContext.Consumer>
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
export default CreateFormBase
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
import React, { Component } from 'react'
|
|
2
|
-
import { Box, Button, Card, DialogActions, DialogContent, DialogTitle, styled } from '@mui/material'
|
|
3
|
-
import { fetchDelay } from '../utils'
|
|
4
|
-
import { IGlobalModalContext, MapGlobalModalContext } from '../api-context'
|
|
5
|
-
|
|
6
|
-
interface IParam<TModel> {
|
|
7
|
-
title?: string
|
|
8
|
-
content: (value?: TModel) => JSX.Element
|
|
9
|
-
colors?: {
|
|
10
|
-
yes?: 'inherit' | 'error' | 'primary' | 'secondary' | 'success' | 'info' | 'warning'
|
|
11
|
-
no?: 'inherit' | 'error' | 'primary' | 'secondary' | 'success' | 'info' | 'warning'
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
const CreateFormComfirm = function <TModel = any>(param?: IParam<TModel>) {
|
|
15
|
-
interface IProps {
|
|
16
|
-
data?: TModel
|
|
17
|
-
title?: string
|
|
18
|
-
onSubmit: (value?: TModel) => Promise<void>
|
|
19
|
-
onCancel?: () => void
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
interface IState {
|
|
23
|
-
loading?: boolean
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
class FormConfirm extends Component<React.PropsWithChildren<IProps>, IState> {
|
|
27
|
-
constructor(props: IProps) {
|
|
28
|
-
super(props)
|
|
29
|
-
this.state = { loading: false }
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
render() {
|
|
33
|
-
const content = this.props.children || (param?.content ? param?.content(this.props.data) : undefined)
|
|
34
|
-
const title = this.props.title ?? param?.title ?? 'Are you sure?'
|
|
35
|
-
return (
|
|
36
|
-
<Box sx={{ flex: 1, display: 'flex', alignItems: 'center', justifyContent: 'center' }}>
|
|
37
|
-
{MapGlobalModalContext((context) => (
|
|
38
|
-
<Card>
|
|
39
|
-
<DialogTitle id='alert-dialog-title'>{title}</DialogTitle>
|
|
40
|
-
<DialogContent sx={{ minWidth: '300px' }}>{content}</DialogContent>
|
|
41
|
-
<DialogActions>
|
|
42
|
-
<CustomButton disabled={this.state.loading} color={param?.colors?.no || 'inherit'} onClick={() => this.handleClickNo(context)}>
|
|
43
|
-
No
|
|
44
|
-
</CustomButton>
|
|
45
|
-
<CustomButton color={param?.colors?.yes || 'error'} disabled={this.state.loading} onClick={() => this.handleClickYes(context)}>
|
|
46
|
-
Yes
|
|
47
|
-
</CustomButton>
|
|
48
|
-
</DialogActions>
|
|
49
|
-
</Card>
|
|
50
|
-
))}
|
|
51
|
-
</Box>
|
|
52
|
-
)
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
handleClickNo = (context: IGlobalModalContext) => {
|
|
56
|
-
context.close()
|
|
57
|
-
this.props.onCancel && this.props.onCancel()
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
handleClickYes = async (context: IGlobalModalContext) => {
|
|
61
|
-
if (!this.props.onSubmit) return
|
|
62
|
-
try {
|
|
63
|
-
this.setState({ loading: true })
|
|
64
|
-
await fetchDelay(() => this.props.onSubmit(this.props.data), 700)
|
|
65
|
-
context.close()
|
|
66
|
-
} catch (error) {
|
|
67
|
-
console.log(error)
|
|
68
|
-
} finally {
|
|
69
|
-
this.setState({ loading: false })
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
return FormConfirm
|
|
74
|
-
}
|
|
75
|
-
export default CreateFormComfirm
|
|
76
|
-
|
|
77
|
-
const CustomButton = styled(Button)({
|
|
78
|
-
textTransform: 'capitalize',
|
|
79
|
-
fontWeight: 600,
|
|
80
|
-
'&.MuiButton-colorInherit': {
|
|
81
|
-
color: '#606060!important'
|
|
82
|
-
}
|
|
83
|
-
})
|