@grampro/kit 0.0.0-stage → 2.4.0
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/.gbs/skills/gbs-components/SKILL.md +190 -0
- package/.gbs/skills/gbs-components/references/accessibility.md +102 -0
- package/.gbs/skills/gbs-components/references/data-display.md +185 -0
- package/.gbs/skills/gbs-components/references/data-grid.md +116 -0
- package/.gbs/skills/gbs-components/references/forms.md +202 -0
- package/.gbs/skills/gbs-components/references/install.md +211 -0
- package/.gbs/skills/gbs-components/references/overlays.md +206 -0
- package/.gbs/skills/gbs-components/references/pickers.md +83 -0
- package/.gbs/skills/gbs-components/references/styling.md +246 -0
- package/.gbs/skills/gbs-components/references/toaster.md +57 -0
- package/CHANGELOG.md +139 -0
- package/LICENSE +15 -0
- package/README.md +193 -2
- package/index.cjs +1370 -0
- package/package.json +74 -4
- package/schema/passport-v1.schema.json +204 -0
- package/source/components/accordion/README.md +45 -0
- package/source/components/accordion/core/index.ts +2 -0
- package/source/components/accordion/core/open.ts +56 -0
- package/source/components/accordion/core/types.ts +17 -0
- package/source/components/accordion/index.ts +8 -0
- package/source/components/accordion/passport.json +259 -0
- package/source/components/accordion/react/Accordion.tsx +133 -0
- package/source/components/accordion/react/AccordionItem.tsx +120 -0
- package/source/components/accordion/react/context.ts +20 -0
- package/source/components/accordion/react/props.ts +13 -0
- package/source/components/accordion/styles.css +207 -0
- package/source/components/alert/README.md +39 -0
- package/source/components/alert/core/index.ts +2 -0
- package/source/components/alert/core/live.ts +25 -0
- package/source/components/alert/core/types.ts +7 -0
- package/source/components/alert/index.ts +5 -0
- package/source/components/alert/passport.json +250 -0
- package/source/components/alert/react/Alert.tsx +113 -0
- package/source/components/alert/react/icons.tsx +21 -0
- package/source/components/alert/react/locale.ts +5 -0
- package/source/components/alert/react/props.ts +11 -0
- package/source/components/alert/styles.css +154 -0
- package/source/components/avatar/core/identity.ts +103 -0
- package/source/components/avatar/core/index.ts +2 -0
- package/source/components/avatar/core/types.ts +12 -0
- package/source/components/avatar/index.ts +7 -0
- package/source/components/avatar/passport.json +294 -0
- package/source/components/avatar/react/Avatar.tsx +118 -0
- package/source/components/avatar/react/AvatarGroup.tsx +74 -0
- package/source/components/avatar/react/locale.ts +11 -0
- package/source/components/avatar/react/props.ts +6 -0
- package/source/components/avatar/styles.css +225 -0
- package/source/components/badge/README.md +37 -0
- package/source/components/badge/core/count.ts +37 -0
- package/source/components/badge/core/index.ts +2 -0
- package/source/components/badge/core/types.ts +11 -0
- package/source/components/badge/index.ts +7 -0
- package/source/components/badge/passport.json +332 -0
- package/source/components/badge/react/Badge.tsx +89 -0
- package/source/components/badge/react/Tag.tsx +82 -0
- package/source/components/badge/react/locale.ts +5 -0
- package/source/components/badge/react/props.ts +6 -0
- package/source/components/badge/styles.css +203 -0
- package/source/components/breadcrumb/README.md +34 -0
- package/source/components/breadcrumb/core/index.ts +4 -0
- package/source/components/breadcrumb/core/trail.ts +42 -0
- package/source/components/breadcrumb/core/types.ts +20 -0
- package/source/components/breadcrumb/index.ts +5 -0
- package/source/components/breadcrumb/passport.json +243 -0
- package/source/components/breadcrumb/react/Breadcrumb.tsx +177 -0
- package/source/components/breadcrumb/react/locale.ts +6 -0
- package/source/components/breadcrumb/react/props.ts +14 -0
- package/source/components/breadcrumb/styles.css +138 -0
- package/source/components/button/README.md +32 -0
- package/source/components/button/core/index.ts +3 -0
- package/source/components/button/core/state.ts +16 -0
- package/source/components/button/core/types.ts +28 -0
- package/source/components/button/index.ts +5 -0
- package/source/components/button/passport.json +402 -0
- package/source/components/button/passport.manual.json +31 -0
- package/source/components/button/react/Button.tsx +173 -0
- package/source/components/button/react/locale.ts +5 -0
- package/source/components/button/react/props.ts +23 -0
- package/source/components/button/styles.css +232 -0
- package/source/components/card/README.md +60 -0
- package/source/components/card/core/index.ts +4 -0
- package/source/components/card/core/trend.ts +32 -0
- package/source/components/card/core/types.ts +5 -0
- package/source/components/card/index.ts +5 -0
- package/source/components/card/passport.json +337 -0
- package/source/components/card/react/Card.tsx +133 -0
- package/source/components/card/react/Stat.tsx +127 -0
- package/source/components/card/react/props.ts +4 -0
- package/source/components/card/styles.css +230 -0
- package/source/components/checkbox/README.md +36 -0
- package/source/components/checkbox/core/group.ts +30 -0
- package/source/components/checkbox/core/index.ts +3 -0
- package/source/components/checkbox/core/types.ts +17 -0
- package/source/components/checkbox/index.ts +9 -0
- package/source/components/checkbox/passport.json +456 -0
- package/source/components/checkbox/react/Checkbox.tsx +147 -0
- package/source/components/checkbox/react/CheckboxGroup.tsx +149 -0
- package/source/components/checkbox/react/context.ts +16 -0
- package/source/components/checkbox/react/locale.ts +5 -0
- package/source/components/checkbox/react/props.ts +6 -0
- package/source/components/checkbox/styles.css +211 -0
- package/source/components/combobox/README.md +170 -0
- package/source/components/combobox/core/filter.ts +155 -0
- package/source/components/combobox/core/index.ts +16 -0
- package/source/components/combobox/core/types.ts +48 -0
- package/source/components/combobox/core/virtual.ts +67 -0
- package/source/components/combobox/index.ts +13 -0
- package/source/components/combobox/passport.json +456 -0
- package/source/components/combobox/react/Listbox.tsx +310 -0
- package/source/components/combobox/react/MultiSelect.tsx +265 -0
- package/source/components/combobox/react/Popover.tsx +38 -0
- package/source/components/combobox/react/Select.tsx +200 -0
- package/source/components/combobox/react/icons.tsx +11 -0
- package/source/components/combobox/react/locale.ts +16 -0
- package/source/components/combobox/react/props.ts +88 -0
- package/source/components/combobox/react/useCombobox.ts +409 -0
- package/source/components/combobox/styles.css +419 -0
- package/source/components/data-grid/README.md +233 -0
- package/source/components/data-grid/agent/coerce.ts +368 -0
- package/source/components/data-grid/agent/contract.ts +410 -0
- package/source/components/data-grid/agent/dataset.ts +92 -0
- package/source/components/data-grid/agent/engine.ts +470 -0
- package/source/components/data-grid/agent/executors.ts +155 -0
- package/source/components/data-grid/agent/index.ts +79 -0
- package/source/components/data-grid/agent/intent.ts +324 -0
- package/source/components/data-grid/agent/operations.ts +335 -0
- package/source/components/data-grid/agent/validate.ts +630 -0
- package/source/components/data-grid/agent/webmcp.ts +107 -0
- package/source/components/data-grid/core/columnHelper.ts +21 -0
- package/source/components/data-grid/core/columns.ts +288 -0
- package/source/components/data-grid/core/filtering.ts +237 -0
- package/source/components/data-grid/core/grid.ts +638 -0
- package/source/components/data-grid/core/index.ts +14 -0
- package/source/components/data-grid/core/rows.ts +64 -0
- package/source/components/data-grid/core/sorting.ts +133 -0
- package/source/components/data-grid/core/state.ts +82 -0
- package/source/components/data-grid/core/store.ts +52 -0
- package/source/components/data-grid/core/types.ts +302 -0
- package/source/components/data-grid/core/values.ts +98 -0
- package/source/components/data-grid/core/virtual.ts +85 -0
- package/source/components/data-grid/export/csv.ts +32 -0
- package/source/components/data-grid/export/download.ts +12 -0
- package/source/components/data-grid/export/pdf-font.ts +139 -0
- package/source/components/data-grid/export/pdf-writer.ts +113 -0
- package/source/components/data-grid/export/pdf.ts +379 -0
- package/source/components/data-grid/export/table.ts +73 -0
- package/source/components/data-grid/export/xlsx.ts +145 -0
- package/source/components/data-grid/export/zip.ts +87 -0
- package/source/components/data-grid/index.ts +14 -0
- package/source/components/data-grid/passport.json +1051 -0
- package/source/components/data-grid/passport.manual.json +255 -0
- package/source/components/data-grid/react/AskGrid.tsx +164 -0
- package/source/components/data-grid/react/Cell.tsx +282 -0
- package/source/components/data-grid/react/ColumnMenu.tsx +135 -0
- package/source/components/data-grid/react/DataGrid.tsx +335 -0
- package/source/components/data-grid/react/FilterForm.tsx +142 -0
- package/source/components/data-grid/react/HeaderRow.tsx +332 -0
- package/source/components/data-grid/react/Pagination.tsx +107 -0
- package/source/components/data-grid/react/Popover.tsx +35 -0
- package/source/components/data-grid/react/Row.tsx +85 -0
- package/source/components/data-grid/react/Toolbar.tsx +267 -0
- package/source/components/data-grid/react/Viewport.tsx +167 -0
- package/source/components/data-grid/react/context.ts +57 -0
- package/source/components/data-grid/react/hooks.ts +83 -0
- package/source/components/data-grid/react/icons.tsx +45 -0
- package/source/components/data-grid/react/keyboard.ts +110 -0
- package/source/components/data-grid/react/locale.ts +130 -0
- package/source/components/data-grid/styles.css +874 -0
- package/source/components/date-picker/README.md +141 -0
- package/source/components/date-picker/core/calendar.ts +266 -0
- package/source/components/date-picker/core/format.ts +170 -0
- package/source/components/date-picker/core/index.ts +41 -0
- package/source/components/date-picker/core/today.ts +72 -0
- package/source/components/date-picker/core/types.ts +68 -0
- package/source/components/date-picker/index.ts +16 -0
- package/source/components/date-picker/passport.json +407 -0
- package/source/components/date-picker/react/Calendar.tsx +160 -0
- package/source/components/date-picker/react/CalendarPanel.tsx +170 -0
- package/source/components/date-picker/react/DatePicker.tsx +249 -0
- package/source/components/date-picker/react/DateRangePicker.tsx +291 -0
- package/source/components/date-picker/react/MonthYearPanels.tsx +123 -0
- package/source/components/date-picker/react/Popover.tsx +45 -0
- package/source/components/date-picker/react/icons.tsx +15 -0
- package/source/components/date-picker/react/locale.ts +23 -0
- package/source/components/date-picker/react/props.ts +76 -0
- package/source/components/date-picker/react/useDatePicker.ts +557 -0
- package/source/components/date-picker/styles.css +445 -0
- package/source/components/dialog/README.md +39 -0
- package/source/components/dialog/core/api.ts +34 -0
- package/source/components/dialog/core/dialog.ts +11 -0
- package/source/components/dialog/core/index.ts +7 -0
- package/source/components/dialog/core/store.ts +81 -0
- package/source/components/dialog/core/types.ts +59 -0
- package/source/components/dialog/index.ts +7 -0
- package/source/components/dialog/passport.json +344 -0
- package/source/components/dialog/react/Dialog.tsx +279 -0
- package/source/components/dialog/react/DialogHost.tsx +45 -0
- package/source/components/dialog/react/icons.tsx +20 -0
- package/source/components/dialog/react/locale.ts +8 -0
- package/source/components/dialog/react/props.ts +13 -0
- package/source/components/dialog/styles.css +280 -0
- package/source/components/file-uploader/README.md +99 -0
- package/source/components/file-uploader/core/format.ts +79 -0
- package/source/components/file-uploader/core/index.ts +26 -0
- package/source/components/file-uploader/core/store.ts +432 -0
- package/source/components/file-uploader/core/transport.ts +154 -0
- package/source/components/file-uploader/core/types.ts +126 -0
- package/source/components/file-uploader/core/validate.ts +83 -0
- package/source/components/file-uploader/index.ts +7 -0
- package/source/components/file-uploader/passport.json +518 -0
- package/source/components/file-uploader/react/FileRow.tsx +268 -0
- package/source/components/file-uploader/react/FileUploader.tsx +511 -0
- package/source/components/file-uploader/react/icons.tsx +60 -0
- package/source/components/file-uploader/react/locale.ts +33 -0
- package/source/components/file-uploader/react/props.ts +31 -0
- package/source/components/file-uploader/react/useFileUploader.ts +32 -0
- package/source/components/file-uploader/styles.css +394 -0
- package/source/components/input/README.md +44 -0
- package/source/components/input/core/count.ts +5 -0
- package/source/components/input/core/index.ts +11 -0
- package/source/components/input/core/otp.ts +64 -0
- package/source/components/input/core/types.ts +14 -0
- package/source/components/input/index.ts +8 -0
- package/source/components/input/passport.json +536 -0
- package/source/components/input/react/Input.tsx +219 -0
- package/source/components/input/react/OtpInput.tsx +256 -0
- package/source/components/input/react/dom.ts +10 -0
- package/source/components/input/react/icons.tsx +17 -0
- package/source/components/input/react/locale.ts +9 -0
- package/source/components/input/react/props.ts +6 -0
- package/source/components/input/styles.css +295 -0
- package/source/components/menu/README.md +68 -0
- package/source/components/menu/core/index.ts +11 -0
- package/source/components/menu/core/navigation.ts +84 -0
- package/source/components/menu/core/types.ts +32 -0
- package/source/components/menu/index.ts +19 -0
- package/source/components/menu/passport.json +322 -0
- package/source/components/menu/react/Menu.tsx +371 -0
- package/source/components/menu/react/context.ts +31 -0
- package/source/components/menu/react/items.tsx +268 -0
- package/source/components/menu/react/locale.ts +6 -0
- package/source/components/menu/react/props.ts +4 -0
- package/source/components/menu/react/useMenuKeys.ts +124 -0
- package/source/components/menu/styles.css +224 -0
- package/source/components/modal/README.md +51 -0
- package/source/components/modal/core/dismiss.ts +29 -0
- package/source/components/modal/core/index.ts +3 -0
- package/source/components/modal/core/types.ts +27 -0
- package/source/components/modal/index.ts +5 -0
- package/source/components/modal/passport.json +289 -0
- package/source/components/modal/react/Modal.tsx +242 -0
- package/source/components/modal/react/icons.tsx +1 -0
- package/source/components/modal/react/locale.ts +5 -0
- package/source/components/modal/react/props.ts +17 -0
- package/source/components/modal/styles.css +241 -0
- package/source/components/number-input/README.md +53 -0
- package/source/components/number-input/core/format.ts +37 -0
- package/source/components/number-input/core/index.ts +4 -0
- package/source/components/number-input/core/parse.ts +118 -0
- package/source/components/number-input/core/step.ts +73 -0
- package/source/components/number-input/core/types.ts +32 -0
- package/source/components/number-input/index.ts +5 -0
- package/source/components/number-input/passport.json +541 -0
- package/source/components/number-input/react/NumberInput.tsx +465 -0
- package/source/components/number-input/react/icons.tsx +17 -0
- package/source/components/number-input/react/locale.ts +7 -0
- package/source/components/number-input/react/props.ts +11 -0
- package/source/components/number-input/styles.css +230 -0
- package/source/components/popover/README.md +44 -0
- package/source/components/popover/core/index.ts +2 -0
- package/source/components/popover/core/types.ts +12 -0
- package/source/components/popover/index.ts +4 -0
- package/source/components/popover/passport.json +238 -0
- package/source/components/popover/react/Popover.tsx +202 -0
- package/source/components/popover/react/locale.ts +5 -0
- package/source/components/popover/react/props.ts +4 -0
- package/source/components/popover/styles.css +148 -0
- package/source/components/progress/README.md +38 -0
- package/source/components/progress/core/index.ts +2 -0
- package/source/components/progress/core/progress.ts +40 -0
- package/source/components/progress/core/types.ts +23 -0
- package/source/components/progress/index.ts +7 -0
- package/source/components/progress/passport.json +270 -0
- package/source/components/progress/react/CircularProgress.tsx +106 -0
- package/source/components/progress/react/Progress.tsx +113 -0
- package/source/components/progress/react/locale.ts +7 -0
- package/source/components/progress/react/props.ts +6 -0
- package/source/components/progress/styles.css +200 -0
- package/source/components/radio-group/README.md +58 -0
- package/source/components/radio-group/core/group.ts +36 -0
- package/source/components/radio-group/core/index.ts +2 -0
- package/source/components/radio-group/core/types.ts +20 -0
- package/source/components/radio-group/index.ts +9 -0
- package/source/components/radio-group/passport.json +477 -0
- package/source/components/radio-group/react/Radio.tsx +144 -0
- package/source/components/radio-group/react/RadioGroup.tsx +179 -0
- package/source/components/radio-group/react/context.ts +18 -0
- package/source/components/radio-group/react/locale.ts +5 -0
- package/source/components/radio-group/react/props.ts +12 -0
- package/source/components/radio-group/styles.css +269 -0
- package/source/components/shared/README.md +54 -0
- package/source/components/shared/core/agent/adapter.ts +65 -0
- package/source/components/shared/core/agent/history.ts +120 -0
- package/source/components/shared/core/agent/index.ts +46 -0
- package/source/components/shared/core/agent/numbers.ts +217 -0
- package/source/components/shared/core/agent/schema.ts +180 -0
- package/source/components/shared/core/agent/types.ts +169 -0
- package/source/components/shared/core/agent/webmcp.ts +328 -0
- package/source/components/shared/core/cx.ts +9 -0
- package/source/components/shared/core/field.ts +35 -0
- package/source/components/shared/core/position.ts +124 -0
- package/source/components/shared/core/text.ts +14 -0
- package/source/components/shared/index.ts +17 -0
- package/source/components/shared/react/GramproAIProvider.tsx +50 -0
- package/source/components/shared/react/Popover.tsx +189 -0
- package/source/components/shared/react/icons.tsx +74 -0
- package/source/components/shared/react/useAskAgent.ts +217 -0
- package/source/components/shared/react/useControllableState.ts +42 -0
- package/source/components/shared/styles.css +79 -0
- package/source/components/shared/version.json +4 -0
- package/source/components/shared/version.ts +6 -0
- package/source/components/skeleton/README.md +58 -0
- package/source/components/skeleton/core/index.ts +3 -0
- package/source/components/skeleton/core/lines.ts +25 -0
- package/source/components/skeleton/core/types.ts +5 -0
- package/source/components/skeleton/index.ts +5 -0
- package/source/components/skeleton/passport.json +251 -0
- package/source/components/skeleton/react/Empty.tsx +51 -0
- package/source/components/skeleton/react/Skeleton.tsx +92 -0
- package/source/components/skeleton/react/props.ts +4 -0
- package/source/components/skeleton/styles.css +185 -0
- package/source/components/spinner/README.md +29 -0
- package/source/components/spinner/core/index.ts +3 -0
- package/source/components/spinner/core/types.ts +28 -0
- package/source/components/spinner/core/visibility.ts +34 -0
- package/source/components/spinner/index.ts +6 -0
- package/source/components/spinner/passport.json +245 -0
- package/source/components/spinner/react/Spinner.tsx +96 -0
- package/source/components/spinner/react/locale.ts +5 -0
- package/source/components/spinner/react/props.ts +4 -0
- package/source/components/spinner/react/useDelayedLoading.ts +39 -0
- package/source/components/spinner/styles.css +173 -0
- package/source/components/switch/README.md +46 -0
- package/source/components/switch/core/index.ts +2 -0
- package/source/components/switch/core/toggle.ts +54 -0
- package/source/components/switch/core/types.ts +9 -0
- package/source/components/switch/index.ts +5 -0
- package/source/components/switch/passport.json +421 -0
- package/source/components/switch/react/Switch.tsx +219 -0
- package/source/components/switch/react/locale.ts +5 -0
- package/source/components/switch/react/props.ts +12 -0
- package/source/components/switch/styles.css +227 -0
- package/source/components/tabs/README.md +32 -0
- package/source/components/tabs/core/index.ts +3 -0
- package/source/components/tabs/core/navigation.ts +54 -0
- package/source/components/tabs/core/types.ts +16 -0
- package/source/components/tabs/index.ts +5 -0
- package/source/components/tabs/passport.json +315 -0
- package/source/components/tabs/react/Tabs.tsx +306 -0
- package/source/components/tabs/react/context.ts +21 -0
- package/source/components/tabs/styles.css +263 -0
- package/source/components/textarea/README.md +39 -0
- package/source/components/textarea/core/count.ts +5 -0
- package/source/components/textarea/core/index.ts +4 -0
- package/source/components/textarea/core/size.ts +23 -0
- package/source/components/textarea/core/types.ts +17 -0
- package/source/components/textarea/index.ts +5 -0
- package/source/components/textarea/passport.json +382 -0
- package/source/components/textarea/react/Textarea.tsx +208 -0
- package/source/components/textarea/react/locale.ts +5 -0
- package/source/components/textarea/react/props.ts +4 -0
- package/source/components/textarea/styles.css +158 -0
- package/source/components/toaster/README.md +128 -0
- package/source/components/toaster/core/api.ts +87 -0
- package/source/components/toaster/core/index.ts +14 -0
- package/source/components/toaster/core/store.ts +211 -0
- package/source/components/toaster/core/toast.ts +12 -0
- package/source/components/toaster/core/types.ts +78 -0
- package/source/components/toaster/index.ts +6 -0
- package/source/components/toaster/passport.json +221 -0
- package/source/components/toaster/react/ToastItem.tsx +164 -0
- package/source/components/toaster/react/Toaster.tsx +187 -0
- package/source/components/toaster/react/icons.tsx +23 -0
- package/source/components/toaster/react/locale.ts +6 -0
- package/source/components/toaster/react/props.ts +15 -0
- package/source/components/toaster/react/useToasts.ts +11 -0
- package/source/components/toaster/styles.css +282 -0
- package/source/components/tooltip/README.md +43 -0
- package/source/components/tooltip/core/index.ts +4 -0
- package/source/components/tooltip/core/types.ts +4 -0
- package/source/components/tooltip/core/visibility.ts +34 -0
- package/source/components/tooltip/index.ts +3 -0
- package/source/components/tooltip/passport.json +170 -0
- package/source/components/tooltip/react/Tooltip.tsx +196 -0
- package/source/components/tooltip/react/props.ts +4 -0
- package/source/components/tooltip/styles.css +71 -0
- package/source/fallback/index.tsx +11 -0
- package/source/globalStyle.ts +74 -0
- package/source/hooks/SelectionHooks/type.ts +4 -0
- package/source/hooks/SelectionHooks/useClickOutside.ts +22 -0
- package/source/hooks/SelectionHooks/useMultiSelectState.ts +64 -0
- package/source/hooks/SelectionHooks/useSelectData.ts +58 -0
- package/source/hooks/SelectionHooks/useSelectState.ts +36 -0
- package/source/icon/Icon.tsx +102 -0
- package/source/icon/iconPaths.ts +206 -0
- package/source/legacy-components/bargraph/index.tsx +95 -0
- package/source/legacy-components/bargraph/type.ts +12 -0
- package/source/legacy-components/breadcrumb/index.tsx +66 -0
- package/source/legacy-components/breadcrumb/types.ts +10 -0
- package/source/legacy-components/button/index.tsx +42 -0
- package/source/legacy-components/card/index.tsx +31 -0
- package/source/legacy-components/checkbox/index.tsx +25 -0
- package/source/legacy-components/contextmenu/ContextMenu.tsx +87 -0
- package/source/legacy-components/contextmenu/ContextMenuItem.tsx +30 -0
- package/source/legacy-components/contextmenu/index.ts +2 -0
- package/source/legacy-components/contextmenu/types.ts +19 -0
- package/source/legacy-components/darkmode/index.tsx +55 -0
- package/source/legacy-components/datagrid/context/GridContext.tsx +215 -0
- package/source/legacy-components/datagrid/createTemplate.tsx +82 -0
- package/source/legacy-components/datagrid/hooks/index.ts +6 -0
- package/source/legacy-components/datagrid/hooks/useColumns.ts +33 -0
- package/source/legacy-components/datagrid/hooks/useDataSource.ts +54 -0
- package/source/legacy-components/datagrid/hooks/useFiltering.ts +169 -0
- package/source/legacy-components/datagrid/hooks/usePagination.ts +112 -0
- package/source/legacy-components/datagrid/hooks/useRowSelection.ts +48 -0
- package/source/legacy-components/datagrid/hooks/useSearch.ts +90 -0
- package/source/legacy-components/datagrid/index.tsx +28 -0
- package/source/legacy-components/datagrid/layout/FilterPopup.tsx +92 -0
- package/source/legacy-components/datagrid/layout/GridBody.tsx +184 -0
- package/source/legacy-components/datagrid/layout/GridPagination.tsx +119 -0
- package/source/legacy-components/datagrid/layout/GridToolbar.tsx +109 -0
- package/source/legacy-components/datagrid/layout/index.tsx +68 -0
- package/source/legacy-components/datagrid/type.ts +198 -0
- package/source/legacy-components/datepicker/index.tsx +365 -0
- package/source/legacy-components/datepicker/types.ts +12 -0
- package/source/legacy-components/dialog/index.tsx +44 -0
- package/source/legacy-components/dialog/types.ts +12 -0
- package/source/legacy-components/formrenderer/componentHandles/CheckBoxHandles.tsx +80 -0
- package/source/legacy-components/formrenderer/componentHandles/DatePickerHandles.tsx +93 -0
- package/source/legacy-components/formrenderer/componentHandles/InputHandles.tsx +106 -0
- package/source/legacy-components/formrenderer/componentHandles/MultiHandles.tsx +93 -0
- package/source/legacy-components/formrenderer/componentHandles/SelectHandles.tsx +95 -0
- package/source/legacy-components/formrenderer/helperFunctions.ts +72 -0
- package/source/legacy-components/formrenderer/index.tsx +93 -0
- package/source/legacy-components/formrenderer/types.ts +127 -0
- package/source/legacy-components/input/index.tsx +142 -0
- package/source/legacy-components/input/types.ts +10 -0
- package/source/legacy-components/materialInput/index.tsx +138 -0
- package/source/legacy-components/materialInput/types.ts +16 -0
- package/source/legacy-components/modal/index.tsx +152 -0
- package/source/legacy-components/modal/types.ts +19 -0
- package/source/legacy-components/multiselect/PortalDropDown.tsx +44 -0
- package/source/legacy-components/multiselect/index.tsx +269 -0
- package/source/legacy-components/multiselect/types.ts +26 -0
- package/source/legacy-components/navbar/AuthSection.tsx +98 -0
- package/source/legacy-components/navbar/MobileToggle.tsx +31 -0
- package/source/legacy-components/navbar/NavItemComponent.tsx +119 -0
- package/source/legacy-components/navbar/SearchBar.tsx +55 -0
- package/source/legacy-components/navbar/helperFunctions.ts +27 -0
- package/source/legacy-components/navbar/index.tsx +156 -0
- package/source/legacy-components/navbar/types.ts +69 -0
- package/source/legacy-components/select/PortalDropDown.tsx +59 -0
- package/source/legacy-components/select/index.tsx +249 -0
- package/source/legacy-components/select/types.ts +29 -0
- package/source/legacy-components/sidebar/components/MenuItem.tsx +101 -0
- package/source/legacy-components/sidebar/components/MenuSection.tsx +34 -0
- package/source/legacy-components/sidebar/components/SidebarFooter.tsx +50 -0
- package/source/legacy-components/sidebar/components/SidebarLogo.tsx +24 -0
- package/source/legacy-components/sidebar/components/SidebarMenu.tsx +29 -0
- package/source/legacy-components/sidebar/components/UserProfile.tsx +31 -0
- package/source/legacy-components/sidebar/hooks/useSidebarState.ts +41 -0
- package/source/legacy-components/sidebar/index.tsx +77 -0
- package/source/legacy-components/sidebar/type.ts +42 -0
- package/source/legacy-components/spinner/Stroke.tsx +89 -0
- package/source/legacy-components/spinner/index.tsx +54 -0
- package/source/legacy-components/spinner/types.ts +9 -0
- package/source/legacy-components/tabs/index.tsx +71 -0
- package/source/legacy-components/tabs/types.ts +16 -0
- package/source/legacy-components/textarea/index.tsx +123 -0
- package/source/legacy-components/textarea/types.ts +15 -0
- package/source/legacy-components/toast/ToastComponent.tsx +101 -0
- package/source/legacy-components/toast/ToastIcon.tsx +61 -0
- package/source/legacy-components/toast/index.tsx +42 -0
- package/source/legacy-components/toast/toastStore.ts +42 -0
- package/source/legacy-components/toast/types.ts +18 -0
- package/source/legacy-components/toast/useToast.ts +12 -0
- package/source/legacy-components/uploader/ProgressAnimation.tsx +50 -0
- package/source/legacy-components/uploader/UploadedFilePreview.tsx +130 -0
- package/source/legacy-components/uploader/index.tsx +311 -0
- package/source/legacy-components/uploader/types.ts +30 -0
- package/source/legacy-components/uploader/uploaderIcon.tsx +72 -0
- package/source/legacy-components/uploader/uploaderService.ts +134 -0
- package/source/legacy-components/useUploader/useUploader.tsx +310 -0
- package/source/legacy-components/usepaginateddata/usePaginatedData.ts +174 -0
- package/source/theme.ts +40 -0
- package/source/utils.ts +10 -0
- package/tools/env.cjs +61 -0
- package/tools/passport/cli.cjs +79 -0
- package/tools/passport/extract.cjs +493 -0
- package/tools/passport/index.cjs +185 -0
- package/tools/passport/merge.cjs +131 -0
- package/tools/passport/policy.cjs +65 -0
- package/tools/passport/validate.cjs +277 -0
- package/tools/ts-require.cjs +79 -0
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# Modal
|
|
2
|
+
|
|
3
|
+
A modal and drawer for React 19 on the native `<dialog>` element, styled to match
|
|
4
|
+
the rest of the library. No runtime dependencies besides React.
|
|
5
|
+
|
|
6
|
+
The browser provides the top layer, the inert page behind, the focus trap and
|
|
7
|
+
focus return. The component adds controlled state, dismiss rules, an
|
|
8
|
+
`onBeforeClose` guard, sizes, drawers and enter/exit animation.
|
|
9
|
+
|
|
10
|
+
## Setup
|
|
11
|
+
|
|
12
|
+
```ts
|
|
13
|
+
import { Modal } from "@/components/modal";
|
|
14
|
+
import "@/components/modal/styles.css";
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Usage
|
|
18
|
+
|
|
19
|
+
```tsx
|
|
20
|
+
const [open, setOpen] = useState(false);
|
|
21
|
+
|
|
22
|
+
<button onClick={() => setOpen(true)}>Edit</button>
|
|
23
|
+
<Modal
|
|
24
|
+
open={open}
|
|
25
|
+
onOpenChange={setOpen}
|
|
26
|
+
title="Edit profile"
|
|
27
|
+
footer={({ close }) => <button onClick={close}>Done</button>}
|
|
28
|
+
>
|
|
29
|
+
…
|
|
30
|
+
</Modal>
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Props
|
|
34
|
+
|
|
35
|
+
| Prop | Type | Default | Description |
|
|
36
|
+
| --- | --- | --- | --- |
|
|
37
|
+
| `open` / `defaultOpen` / `onOpenChange` | `boolean` / `boolean` / `(open, reason?) => void` | — / `false` | Controlled or uncontrolled state. `reason`: `escape`, `backdrop`, `close-button`, `api`. |
|
|
38
|
+
| `title`, `description`, `aria-label` | `ReactNode` / `string` | — | Header text; `aria-label` names an untitled modal. |
|
|
39
|
+
| `children`, `footer` | `ReactNode \| ({ close }) => ReactNode` | — | Body and footer. |
|
|
40
|
+
| `size` | `sm` \| `md` \| `lg` \| `xl` \| `full` | `md` | 400 / 520 / 720 / 960 px or the whole screen. |
|
|
41
|
+
| `placement` | `center` \| `top` \| `left` \| `right` \| `bottom` | `center` | `left`, `right` and `bottom` are drawers. |
|
|
42
|
+
| `closeButton`, `closeOnEscape`, `closeOnBackdrop` | `boolean` | `true` | Dismiss options. |
|
|
43
|
+
| `onBeforeClose` | `(reason) => boolean \| Promise<boolean>` | — | Return `false` to stay open. |
|
|
44
|
+
| `initialFocus` | `RefObject<HTMLElement>` | — | Otherwise `[data-autofocus]`, then the first focusable element. |
|
|
45
|
+
| `keepMounted` | `boolean` | `false` | Keep the content's state while closed. |
|
|
46
|
+
| `className`, `classNames`, `style`, `localeText`, `id`, `ref` | — | — | Slots: `root`, `header`, `title`, `description`, `close`, `body`, `footer`. `ref`: `open()`, `close()`, `getElement()`. |
|
|
47
|
+
|
|
48
|
+
## Known limits
|
|
49
|
+
|
|
50
|
+
- Exit animations need `transition-behavior: allow-discrete` (Chrome 117+, Safari 18+); elsewhere the modal closes instantly.
|
|
51
|
+
- Page scrolling is locked with `:root:has(.md-root[open])`, which can shift content by the scrollbar's width.
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { CloseGuard, CloseReason, DismissOptions, Rect } from "./types";
|
|
2
|
+
|
|
3
|
+
/** Whether a close request is allowed before asking `onBeforeClose`. Code and the close button always are. */
|
|
4
|
+
export function canDismiss(reason: CloseReason, options: DismissOptions = {}): boolean {
|
|
5
|
+
if (reason === "escape") return options.closeOnEscape ?? true;
|
|
6
|
+
if (reason === "backdrop") return options.closeOnBackdrop ?? true;
|
|
7
|
+
return true;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* A native `<dialog>` reports clicks on its backdrop as clicks on itself, so a
|
|
12
|
+
* click counts as "on the backdrop" when it lands outside the dialog's box.
|
|
13
|
+
*/
|
|
14
|
+
export function isOutside(rect: Rect, x: number, y: number): boolean {
|
|
15
|
+
return x < rect.left || x > rect.right || y < rect.top || y > rect.bottom;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Runs `onBeforeClose`. Only an explicit `false` (or a promise of it) keeps the
|
|
20
|
+
* modal open; a guard that throws keeps it open too, so unsaved work isn't lost.
|
|
21
|
+
*/
|
|
22
|
+
export async function confirmClose(guard: CloseGuard | undefined, reason: CloseReason): Promise<boolean> {
|
|
23
|
+
if (!guard) return true;
|
|
24
|
+
try {
|
|
25
|
+
return (await guard(reason)) !== false;
|
|
26
|
+
} catch {
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export type ModalSize = "sm" | "md" | "lg" | "xl" | "full";
|
|
2
|
+
|
|
3
|
+
/** `center` and `top` are dialogs; `left`, `right` and `bottom` slide in as drawers. */
|
|
4
|
+
export type ModalPlacement = "center" | "top" | "left" | "right" | "bottom";
|
|
5
|
+
|
|
6
|
+
/** What asked the modal to close. */
|
|
7
|
+
export type CloseReason = "escape" | "backdrop" | "close-button" | "api";
|
|
8
|
+
|
|
9
|
+
export interface DismissOptions {
|
|
10
|
+
/** Default true. */
|
|
11
|
+
closeOnEscape?: boolean;
|
|
12
|
+
/** Default true. */
|
|
13
|
+
closeOnBackdrop?: boolean;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface Rect {
|
|
17
|
+
left: number;
|
|
18
|
+
top: number;
|
|
19
|
+
right: number;
|
|
20
|
+
bottom: number;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export type CloseGuard = (reason: CloseReason) => boolean | Promise<boolean>;
|
|
24
|
+
|
|
25
|
+
export interface ModalLocaleText {
|
|
26
|
+
close: string;
|
|
27
|
+
}
|
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
{
|
|
2
|
+
"passportVersion": "1.0.0",
|
|
3
|
+
"identity": {
|
|
4
|
+
"component": "Modal",
|
|
5
|
+
"folder": "modal",
|
|
6
|
+
"exports": [
|
|
7
|
+
"Modal"
|
|
8
|
+
]
|
|
9
|
+
},
|
|
10
|
+
"source": {
|
|
11
|
+
"libraryVersion": "2.4.0",
|
|
12
|
+
"files": [
|
|
13
|
+
"core/dismiss.ts",
|
|
14
|
+
"core/index.ts",
|
|
15
|
+
"core/types.ts",
|
|
16
|
+
"index.ts",
|
|
17
|
+
"react/Modal.tsx",
|
|
18
|
+
"react/icons.tsx",
|
|
19
|
+
"react/locale.ts",
|
|
20
|
+
"react/props.ts"
|
|
21
|
+
],
|
|
22
|
+
"sourceHash": "sha256:910a347e2afc5b243068783ae93ebef3fa8595aa9dd4df3531aca3c754c84248"
|
|
23
|
+
},
|
|
24
|
+
"props": [
|
|
25
|
+
{
|
|
26
|
+
"name": "aria-label",
|
|
27
|
+
"type": "string",
|
|
28
|
+
"typeText": "string | undefined",
|
|
29
|
+
"required": false,
|
|
30
|
+
"origin": "derived",
|
|
31
|
+
"description": "Accessible name when there is no `title`.",
|
|
32
|
+
"descriptionOrigin": "jsdoc"
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
"name": "children",
|
|
36
|
+
"type": "other",
|
|
37
|
+
"typeText": "Renderable",
|
|
38
|
+
"required": false,
|
|
39
|
+
"origin": "derived"
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
"name": "className",
|
|
43
|
+
"type": "string",
|
|
44
|
+
"typeText": "string | undefined",
|
|
45
|
+
"required": false,
|
|
46
|
+
"origin": "derived"
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
"name": "classNames",
|
|
50
|
+
"type": "other",
|
|
51
|
+
"typeText": "Partial<Record<ModalSlot, string>> | undefined",
|
|
52
|
+
"required": false,
|
|
53
|
+
"origin": "derived"
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
"name": "closeButton",
|
|
57
|
+
"type": "boolean",
|
|
58
|
+
"typeText": "boolean | undefined",
|
|
59
|
+
"required": false,
|
|
60
|
+
"default": true,
|
|
61
|
+
"origin": "derived",
|
|
62
|
+
"description": "Show the × button. Default true.",
|
|
63
|
+
"descriptionOrigin": "jsdoc"
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
"name": "closeOnBackdrop",
|
|
67
|
+
"type": "boolean",
|
|
68
|
+
"typeText": "boolean | undefined",
|
|
69
|
+
"required": false,
|
|
70
|
+
"default": true,
|
|
71
|
+
"origin": "derived",
|
|
72
|
+
"description": "Default true.",
|
|
73
|
+
"descriptionOrigin": "jsdoc"
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
"name": "closeOnEscape",
|
|
77
|
+
"type": "boolean",
|
|
78
|
+
"typeText": "boolean | undefined",
|
|
79
|
+
"required": false,
|
|
80
|
+
"default": true,
|
|
81
|
+
"origin": "derived",
|
|
82
|
+
"description": "Default true.",
|
|
83
|
+
"descriptionOrigin": "jsdoc"
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
"name": "defaultOpen",
|
|
87
|
+
"type": "boolean",
|
|
88
|
+
"typeText": "boolean | undefined",
|
|
89
|
+
"required": false,
|
|
90
|
+
"default": false,
|
|
91
|
+
"origin": "derived"
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
"name": "description",
|
|
95
|
+
"type": "other",
|
|
96
|
+
"typeText": "ReactNode",
|
|
97
|
+
"required": false,
|
|
98
|
+
"origin": "derived"
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
"name": "footer",
|
|
102
|
+
"type": "other",
|
|
103
|
+
"typeText": "Renderable",
|
|
104
|
+
"required": false,
|
|
105
|
+
"origin": "derived"
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
"name": "id",
|
|
109
|
+
"type": "string",
|
|
110
|
+
"typeText": "string | undefined",
|
|
111
|
+
"required": false,
|
|
112
|
+
"origin": "derived"
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
"name": "initialFocus",
|
|
116
|
+
"type": "other",
|
|
117
|
+
"typeText": "RefObject<HTMLElement | null> | undefined",
|
|
118
|
+
"required": false,
|
|
119
|
+
"origin": "derived",
|
|
120
|
+
"description": "Focused on open. Otherwise the first `[data-autofocus]` element, then the first focusable one.",
|
|
121
|
+
"descriptionOrigin": "jsdoc"
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
"name": "keepMounted",
|
|
125
|
+
"type": "boolean",
|
|
126
|
+
"typeText": "boolean | undefined",
|
|
127
|
+
"required": false,
|
|
128
|
+
"default": false,
|
|
129
|
+
"origin": "derived",
|
|
130
|
+
"description": "Keep the content mounted while closed, preserving its state. Default false.",
|
|
131
|
+
"descriptionOrigin": "jsdoc"
|
|
132
|
+
},
|
|
133
|
+
{
|
|
134
|
+
"name": "localeText",
|
|
135
|
+
"type": "other",
|
|
136
|
+
"typeText": "Partial<ModalLocaleText> | undefined",
|
|
137
|
+
"required": false,
|
|
138
|
+
"origin": "derived"
|
|
139
|
+
},
|
|
140
|
+
{
|
|
141
|
+
"name": "onBeforeClose",
|
|
142
|
+
"type": "function",
|
|
143
|
+
"signature": "((reason: CloseReason) => boolean | Promise<boolean>) | undefined",
|
|
144
|
+
"required": false,
|
|
145
|
+
"origin": "derived",
|
|
146
|
+
"description": "Return `false` (or a promise of it) to keep the modal open, e.g. for unsaved changes.",
|
|
147
|
+
"descriptionOrigin": "jsdoc"
|
|
148
|
+
},
|
|
149
|
+
{
|
|
150
|
+
"name": "onOpenChange",
|
|
151
|
+
"type": "function",
|
|
152
|
+
"signature": "((open: boolean, reason?: CloseReason) => void) | undefined",
|
|
153
|
+
"required": false,
|
|
154
|
+
"origin": "derived",
|
|
155
|
+
"description": "`reason` says what closed it; it is undefined when opening.",
|
|
156
|
+
"descriptionOrigin": "jsdoc"
|
|
157
|
+
},
|
|
158
|
+
{
|
|
159
|
+
"name": "open",
|
|
160
|
+
"type": "boolean",
|
|
161
|
+
"typeText": "boolean | undefined",
|
|
162
|
+
"required": false,
|
|
163
|
+
"origin": "derived",
|
|
164
|
+
"description": "Controlled open state.",
|
|
165
|
+
"descriptionOrigin": "jsdoc"
|
|
166
|
+
},
|
|
167
|
+
{
|
|
168
|
+
"name": "placement",
|
|
169
|
+
"type": "enum",
|
|
170
|
+
"values": [
|
|
171
|
+
"bottom",
|
|
172
|
+
"center",
|
|
173
|
+
"left",
|
|
174
|
+
"right",
|
|
175
|
+
"top"
|
|
176
|
+
],
|
|
177
|
+
"typeText": "ModalPlacement | undefined",
|
|
178
|
+
"required": false,
|
|
179
|
+
"default": "center",
|
|
180
|
+
"origin": "derived",
|
|
181
|
+
"description": "Default `center`.",
|
|
182
|
+
"descriptionOrigin": "jsdoc"
|
|
183
|
+
},
|
|
184
|
+
{
|
|
185
|
+
"name": "ref",
|
|
186
|
+
"type": "other",
|
|
187
|
+
"typeText": "Ref<ModalHandle> | undefined",
|
|
188
|
+
"required": false,
|
|
189
|
+
"origin": "derived"
|
|
190
|
+
},
|
|
191
|
+
{
|
|
192
|
+
"name": "size",
|
|
193
|
+
"type": "enum",
|
|
194
|
+
"values": [
|
|
195
|
+
"full",
|
|
196
|
+
"lg",
|
|
197
|
+
"md",
|
|
198
|
+
"sm",
|
|
199
|
+
"xl"
|
|
200
|
+
],
|
|
201
|
+
"typeText": "ModalSize | undefined",
|
|
202
|
+
"required": false,
|
|
203
|
+
"default": "md",
|
|
204
|
+
"origin": "derived",
|
|
205
|
+
"description": "Width for dialogs; for drawers, the width (left/right) or height (bottom). Default `md`.",
|
|
206
|
+
"descriptionOrigin": "jsdoc"
|
|
207
|
+
},
|
|
208
|
+
{
|
|
209
|
+
"name": "style",
|
|
210
|
+
"type": "other",
|
|
211
|
+
"typeText": "CSSProperties | undefined",
|
|
212
|
+
"required": false,
|
|
213
|
+
"origin": "derived"
|
|
214
|
+
},
|
|
215
|
+
{
|
|
216
|
+
"name": "title",
|
|
217
|
+
"type": "other",
|
|
218
|
+
"typeText": "ReactNode",
|
|
219
|
+
"required": false,
|
|
220
|
+
"origin": "derived"
|
|
221
|
+
}
|
|
222
|
+
],
|
|
223
|
+
"events": [
|
|
224
|
+
{
|
|
225
|
+
"name": "onBeforeClose",
|
|
226
|
+
"signature": "((reason: CloseReason) => boolean | Promise<boolean>) | undefined"
|
|
227
|
+
},
|
|
228
|
+
{
|
|
229
|
+
"name": "onOpenChange",
|
|
230
|
+
"signature": "((open: boolean, reason?: CloseReason) => void) | undefined"
|
|
231
|
+
}
|
|
232
|
+
],
|
|
233
|
+
"slots": [
|
|
234
|
+
"root",
|
|
235
|
+
"header",
|
|
236
|
+
"title",
|
|
237
|
+
"description",
|
|
238
|
+
"close",
|
|
239
|
+
"body",
|
|
240
|
+
"footer"
|
|
241
|
+
],
|
|
242
|
+
"states": [
|
|
243
|
+
{
|
|
244
|
+
"attr": "data-placement",
|
|
245
|
+
"values": [
|
|
246
|
+
"bottom",
|
|
247
|
+
"left",
|
|
248
|
+
"right",
|
|
249
|
+
"top"
|
|
250
|
+
]
|
|
251
|
+
},
|
|
252
|
+
{
|
|
253
|
+
"attr": "data-size",
|
|
254
|
+
"values": [
|
|
255
|
+
"full",
|
|
256
|
+
"lg",
|
|
257
|
+
"sm",
|
|
258
|
+
"xl"
|
|
259
|
+
]
|
|
260
|
+
},
|
|
261
|
+
{
|
|
262
|
+
"attr": "data-state"
|
|
263
|
+
},
|
|
264
|
+
{
|
|
265
|
+
"attr": "data-theme",
|
|
266
|
+
"values": [
|
|
267
|
+
"dark",
|
|
268
|
+
"light"
|
|
269
|
+
]
|
|
270
|
+
}
|
|
271
|
+
],
|
|
272
|
+
"accessibility": {
|
|
273
|
+
"supplied": [],
|
|
274
|
+
"required": []
|
|
275
|
+
},
|
|
276
|
+
"composition": {},
|
|
277
|
+
"operations": {},
|
|
278
|
+
"intentDomains": [],
|
|
279
|
+
"safeMutations": {},
|
|
280
|
+
"examples": [],
|
|
281
|
+
"coverage": {
|
|
282
|
+
"propsTotal": 22,
|
|
283
|
+
"propsDescribed": 11,
|
|
284
|
+
"describedPct": 50,
|
|
285
|
+
"authoredSections": [
|
|
286
|
+
"accessibility"
|
|
287
|
+
]
|
|
288
|
+
}
|
|
289
|
+
}
|
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
useCallback,
|
|
5
|
+
useEffect,
|
|
6
|
+
useId,
|
|
7
|
+
useImperativeHandle,
|
|
8
|
+
useMemo,
|
|
9
|
+
useRef,
|
|
10
|
+
useState,
|
|
11
|
+
type CSSProperties,
|
|
12
|
+
type MouseEvent,
|
|
13
|
+
type ReactNode,
|
|
14
|
+
type Ref,
|
|
15
|
+
type RefObject,
|
|
16
|
+
} from "react";
|
|
17
|
+
import { useControllableState } from "../../shared/react/useControllableState";
|
|
18
|
+
import { canDismiss, confirmClose, isOutside } from "../core/dismiss";
|
|
19
|
+
import type {
|
|
20
|
+
CloseReason,
|
|
21
|
+
ModalLocaleText,
|
|
22
|
+
ModalPlacement,
|
|
23
|
+
ModalSize,
|
|
24
|
+
} from "../core/types";
|
|
25
|
+
import { XIcon } from "./icons";
|
|
26
|
+
import { defaultModalText } from "./locale";
|
|
27
|
+
import { cx, type ModalHandle, type ModalRenderProps, type ModalSlot } from "./props";
|
|
28
|
+
|
|
29
|
+
/** Matches the CSS transition, so content stays mounted while the modal animates out. */
|
|
30
|
+
const EXIT_DURATION = 200;
|
|
31
|
+
|
|
32
|
+
type Renderable = ReactNode | ((props: ModalRenderProps) => ReactNode);
|
|
33
|
+
|
|
34
|
+
export interface ModalProps {
|
|
35
|
+
/** Controlled open state. */
|
|
36
|
+
open?: boolean;
|
|
37
|
+
defaultOpen?: boolean;
|
|
38
|
+
/** `reason` says what closed it; it is undefined when opening. */
|
|
39
|
+
onOpenChange?(open: boolean, reason?: CloseReason): void;
|
|
40
|
+
title?: ReactNode;
|
|
41
|
+
description?: ReactNode;
|
|
42
|
+
/** Accessible name when there is no `title`. */
|
|
43
|
+
"aria-label"?: string;
|
|
44
|
+
children?: Renderable;
|
|
45
|
+
footer?: Renderable;
|
|
46
|
+
/** Width for dialogs; for drawers, the width (left/right) or height (bottom). Default `md`. */
|
|
47
|
+
size?: ModalSize;
|
|
48
|
+
/** Default `center`. */
|
|
49
|
+
placement?: ModalPlacement;
|
|
50
|
+
/** Show the × button. Default true. */
|
|
51
|
+
closeButton?: boolean;
|
|
52
|
+
/** Default true. */
|
|
53
|
+
closeOnEscape?: boolean;
|
|
54
|
+
/** Default true. */
|
|
55
|
+
closeOnBackdrop?: boolean;
|
|
56
|
+
/** Return `false` (or a promise of it) to keep the modal open, e.g. for unsaved changes. */
|
|
57
|
+
onBeforeClose?(reason: CloseReason): boolean | Promise<boolean>;
|
|
58
|
+
/** Focused on open. Otherwise the first `[data-autofocus]` element, then the first focusable one. */
|
|
59
|
+
initialFocus?: RefObject<HTMLElement | null>;
|
|
60
|
+
/** Keep the content mounted while closed, preserving its state. Default false. */
|
|
61
|
+
keepMounted?: boolean;
|
|
62
|
+
id?: string;
|
|
63
|
+
className?: string;
|
|
64
|
+
classNames?: Partial<Record<ModalSlot, string>>;
|
|
65
|
+
style?: CSSProperties;
|
|
66
|
+
localeText?: Partial<ModalLocaleText>;
|
|
67
|
+
ref?: Ref<ModalHandle>;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const outside = (event: MouseEvent<HTMLDialogElement>) =>
|
|
71
|
+
event.target === event.currentTarget &&
|
|
72
|
+
isOutside(event.currentTarget.getBoundingClientRect(), event.clientX, event.clientY);
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* A modal built on the native `<dialog>` element. The browser provides the top
|
|
76
|
+
* layer, the inert background, the focus trap and focus return; the component
|
|
77
|
+
* adds controlled state, dismiss rules, drawers and animation.
|
|
78
|
+
*/
|
|
79
|
+
export function Modal(props: ModalProps) {
|
|
80
|
+
const {
|
|
81
|
+
ref,
|
|
82
|
+
open: openProp,
|
|
83
|
+
defaultOpen = false,
|
|
84
|
+
onOpenChange,
|
|
85
|
+
title,
|
|
86
|
+
description,
|
|
87
|
+
"aria-label": ariaLabel,
|
|
88
|
+
children,
|
|
89
|
+
footer,
|
|
90
|
+
size = "md",
|
|
91
|
+
placement = "center",
|
|
92
|
+
closeButton = true,
|
|
93
|
+
closeOnEscape = true,
|
|
94
|
+
closeOnBackdrop = true,
|
|
95
|
+
onBeforeClose,
|
|
96
|
+
initialFocus,
|
|
97
|
+
keepMounted = false,
|
|
98
|
+
id: idProp,
|
|
99
|
+
className,
|
|
100
|
+
classNames,
|
|
101
|
+
style,
|
|
102
|
+
localeText,
|
|
103
|
+
} = props;
|
|
104
|
+
|
|
105
|
+
const reactId = useId();
|
|
106
|
+
const id = idProp ?? reactId;
|
|
107
|
+
const text = useMemo(() => ({ ...defaultModalText, ...localeText }), [localeText]);
|
|
108
|
+
const dialogRef = useRef<HTMLDialogElement>(null);
|
|
109
|
+
const pressStartedOutside = useRef(false);
|
|
110
|
+
|
|
111
|
+
const [open, setOpenState] = useControllableState(openProp, defaultOpen);
|
|
112
|
+
|
|
113
|
+
// Keep the content mounted through the exit transition. Adjusting state while
|
|
114
|
+
// rendering avoids an extra render with the content already gone.
|
|
115
|
+
const [previousOpen, setPreviousOpen] = useState(open);
|
|
116
|
+
const [closing, setClosing] = useState(false);
|
|
117
|
+
if (previousOpen !== open) {
|
|
118
|
+
setPreviousOpen(open);
|
|
119
|
+
setClosing(!open);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
useEffect(() => {
|
|
123
|
+
if (!closing) return;
|
|
124
|
+
const timer = setTimeout(() => setClosing(false), EXIT_DURATION);
|
|
125
|
+
return () => clearTimeout(timer);
|
|
126
|
+
}, [closing]);
|
|
127
|
+
|
|
128
|
+
const setOpen = useCallback(
|
|
129
|
+
(next: boolean, reason?: CloseReason) => {
|
|
130
|
+
setOpenState(next);
|
|
131
|
+
onOpenChange?.(next, reason);
|
|
132
|
+
},
|
|
133
|
+
[setOpenState, onOpenChange],
|
|
134
|
+
);
|
|
135
|
+
|
|
136
|
+
const requestClose = useCallback(
|
|
137
|
+
(reason: CloseReason) => {
|
|
138
|
+
if (!canDismiss(reason, { closeOnEscape, closeOnBackdrop })) return;
|
|
139
|
+
void confirmClose(onBeforeClose, reason).then((allowed) => {
|
|
140
|
+
if (allowed) setOpen(false, reason);
|
|
141
|
+
});
|
|
142
|
+
},
|
|
143
|
+
[closeOnEscape, closeOnBackdrop, onBeforeClose, setOpen],
|
|
144
|
+
);
|
|
145
|
+
|
|
146
|
+
useEffect(() => {
|
|
147
|
+
const dialog = dialogRef.current;
|
|
148
|
+
if (!dialog) return;
|
|
149
|
+
if (open && !dialog.open) {
|
|
150
|
+
dialog.showModal();
|
|
151
|
+
const target =
|
|
152
|
+
initialFocus?.current ?? dialog.querySelector<HTMLElement>("[data-autofocus]");
|
|
153
|
+
target?.focus();
|
|
154
|
+
} else if (!open && dialog.open) {
|
|
155
|
+
dialog.close();
|
|
156
|
+
}
|
|
157
|
+
}, [open, initialFocus]);
|
|
158
|
+
|
|
159
|
+
useImperativeHandle(
|
|
160
|
+
ref,
|
|
161
|
+
() => ({
|
|
162
|
+
open: () => setOpen(true),
|
|
163
|
+
close: () => requestClose("api"),
|
|
164
|
+
getElement: () => dialogRef.current,
|
|
165
|
+
}),
|
|
166
|
+
[setOpen, requestClose],
|
|
167
|
+
);
|
|
168
|
+
|
|
169
|
+
const renderProps: ModalRenderProps = { close: () => requestClose("api") };
|
|
170
|
+
const render = (node: Renderable) => (typeof node === "function" ? node(renderProps) : node);
|
|
171
|
+
const mounted = open || closing || keepMounted;
|
|
172
|
+
|
|
173
|
+
return (
|
|
174
|
+
<dialog
|
|
175
|
+
ref={dialogRef}
|
|
176
|
+
id={id}
|
|
177
|
+
className={cx("md-root", classNames?.root, className)}
|
|
178
|
+
style={style}
|
|
179
|
+
data-size={size}
|
|
180
|
+
data-placement={placement}
|
|
181
|
+
data-state={open ? "open" : "closed"}
|
|
182
|
+
aria-labelledby={title ? `${id}-title` : undefined}
|
|
183
|
+
aria-describedby={description ? `${id}-description` : undefined}
|
|
184
|
+
aria-label={title ? undefined : ariaLabel}
|
|
185
|
+
// Escape: keep the browser from closing it, and decide ourselves.
|
|
186
|
+
onCancel={(event) => {
|
|
187
|
+
event.preventDefault();
|
|
188
|
+
requestClose("escape");
|
|
189
|
+
}}
|
|
190
|
+
// Closed some other way, e.g. by a `<form method="dialog">` inside.
|
|
191
|
+
onClose={() => {
|
|
192
|
+
if (open) setOpen(false, "api");
|
|
193
|
+
}}
|
|
194
|
+
// A drag that starts inside and ends on the backdrop must not close it.
|
|
195
|
+
onPointerDown={(event) => {
|
|
196
|
+
pressStartedOutside.current = outside(event);
|
|
197
|
+
}}
|
|
198
|
+
onClick={(event) => {
|
|
199
|
+
if (pressStartedOutside.current && outside(event)) requestClose("backdrop");
|
|
200
|
+
pressStartedOutside.current = false;
|
|
201
|
+
}}
|
|
202
|
+
>
|
|
203
|
+
{mounted && (
|
|
204
|
+
<>
|
|
205
|
+
{(title || description || closeButton) && (
|
|
206
|
+
<header className={cx("md-header", classNames?.header)}>
|
|
207
|
+
<div className="md-heading">
|
|
208
|
+
{title && (
|
|
209
|
+
<h2 id={`${id}-title`} className={cx("md-title", classNames?.title)}>
|
|
210
|
+
{title}
|
|
211
|
+
</h2>
|
|
212
|
+
)}
|
|
213
|
+
{description && (
|
|
214
|
+
<p id={`${id}-description`} className={cx("md-description", classNames?.description)}>
|
|
215
|
+
{description}
|
|
216
|
+
</p>
|
|
217
|
+
)}
|
|
218
|
+
</div>
|
|
219
|
+
{closeButton && (
|
|
220
|
+
<button
|
|
221
|
+
type="button"
|
|
222
|
+
className={cx("md-close", classNames?.close)}
|
|
223
|
+
aria-label={text.close}
|
|
224
|
+
title={text.close}
|
|
225
|
+
onClick={() => requestClose("close-button")}
|
|
226
|
+
>
|
|
227
|
+
<XIcon />
|
|
228
|
+
</button>
|
|
229
|
+
)}
|
|
230
|
+
</header>
|
|
231
|
+
)}
|
|
232
|
+
{/* Focusable: the body scrolls, and a scroll area the keyboard can't
|
|
233
|
+
reach leaves its content unreadable without a mouse. */}
|
|
234
|
+
<div className={cx("md-body", classNames?.body)} tabIndex={0}>
|
|
235
|
+
{render(children)}
|
|
236
|
+
</div>
|
|
237
|
+
{footer && <footer className={cx("md-footer", classNames?.footer)}>{render(footer)}</footer>}
|
|
238
|
+
</>
|
|
239
|
+
)}
|
|
240
|
+
</dialog>
|
|
241
|
+
);
|
|
242
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { XIcon } from "../../shared/react/icons";
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export type ModalSlot = "root" | "header" | "title" | "description" | "close" | "body" | "footer";
|
|
2
|
+
|
|
3
|
+
export interface ModalHandle {
|
|
4
|
+
open(): void;
|
|
5
|
+
/** Asks to close; `onBeforeClose` still gets a say. */
|
|
6
|
+
close(): void;
|
|
7
|
+
getElement(): HTMLDialogElement | null;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/** Passed to `children` and `footer` when they are functions. */
|
|
11
|
+
export interface ModalRenderProps {
|
|
12
|
+
/** Closes through `onBeforeClose`, like the close button. */
|
|
13
|
+
close(): void;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// Shared with every other component, so class handling cannot drift.
|
|
17
|
+
export { cx } from "../../shared/core/cx";
|