@apexhub/apex-ui-react-source 0.0.0-stage → 1.2.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/LICENSE +21 -0
- package/README.md +97 -2
- package/bin/apex-ui-react-source.mjs +717 -0
- package/dist/files/AGENTS.md +89 -0
- package/dist/files/LICENSE +21 -0
- package/dist/files/_assets/adapt-to-page.raw.ts +3 -0
- package/dist/files/_assets/adapt-to-page.url.ts +3 -0
- package/dist/files/_assets/calendar.raw.ts +3 -0
- package/dist/files/_assets/doc-format.raw.ts +3 -0
- package/dist/files/_assets/docx-format.raw.ts +3 -0
- package/dist/files/_assets/full-screen.raw.ts +3 -0
- package/dist/files/_assets/full-screen.url.ts +3 -0
- package/dist/files/_assets/gif-format.raw.ts +3 -0
- package/dist/files/_assets/jpeg-format.raw.ts +3 -0
- package/dist/files/_assets/jpg-format.raw.ts +3 -0
- package/dist/files/_assets/ofd-format.raw.ts +3 -0
- package/dist/files/_assets/one-to-one.raw.ts +3 -0
- package/dist/files/_assets/one-to-one.url.ts +3 -0
- package/dist/files/_assets/pdf-format.raw.ts +3 -0
- package/dist/files/_assets/png-format.raw.ts +3 -0
- package/dist/files/_assets/rotate-left.raw.ts +3 -0
- package/dist/files/_assets/rotate-left.url.ts +3 -0
- package/dist/files/_assets/rotate-right.raw.ts +3 -0
- package/dist/files/_assets/rotate-right.url.ts +3 -0
- package/dist/files/_assets/table-empty.url.ts +3 -0
- package/dist/files/_assets/txt-format.raw.ts +3 -0
- package/dist/files/_assets/upload-file-doc-20.raw.ts +3 -0
- package/dist/files/_assets/upload-file-docx-20.raw.ts +3 -0
- package/dist/files/_assets/upload-file-gif-20.raw.ts +3 -0
- package/dist/files/_assets/upload-file-jpeg-20.raw.ts +3 -0
- package/dist/files/_assets/upload-file-jpg-20.raw.ts +3 -0
- package/dist/files/_assets/upload-file-ofd-20.raw.ts +3 -0
- package/dist/files/_assets/upload-file-pdf-20.raw.ts +3 -0
- package/dist/files/_assets/upload-file-png-20.raw.ts +3 -0
- package/dist/files/_assets/upload-file-txt-20.raw.ts +3 -0
- package/dist/files/_assets/upload-file-xlsx-20.raw.ts +3 -0
- package/dist/files/_assets/xlsx-format.raw.ts +3 -0
- package/dist/files/_assets/zoom-in.raw.ts +3 -0
- package/dist/files/_assets/zoom-in.url.ts +3 -0
- package/dist/files/_assets/zoom-out.raw.ts +3 -0
- package/dist/files/_assets/zoom-out.url.ts +3 -0
- package/dist/files/_headless/dismiss-intent.ts +1 -0
- package/dist/files/_headless/placement.ts +1 -0
- package/dist/files/_headless/use-embedded-scroll-lock-guard.ts +47 -0
- package/dist/files/_headless/use-floating-overlay.tsx +3 -0
- package/dist/files/_namespace/constants.ts +23 -0
- package/dist/files/_namespace/index.ts +1 -0
- package/dist/files/_overlay/auto-update-anchored-overlay.ts +11 -0
- package/dist/files/_overlay/collision-boundary.ts +78 -0
- package/dist/files/_overlay/dismiss-intent.ts +107 -0
- package/dist/files/_overlay/get-overlay-root.ts +157 -0
- package/dist/files/_overlay/index.ts +57 -0
- package/dist/files/_overlay/observe-anchor-lifecycle.ts +72 -0
- package/dist/files/_overlay/overlay-theme.ts +91 -0
- package/dist/files/_overlay/overlay-trigger.ts +100 -0
- package/dist/files/_overlay/overlay.css +29 -0
- package/dist/files/_overlay/placement.ts +18 -0
- package/dist/files/_overlay/resolve-portal-container.ts +13 -0
- package/dist/files/_overlay/use-anchored-overlay.tsx +493 -0
- package/dist/files/_overlay/zIndex.ts +17 -0
- package/dist/files/_tags/MaxTagList.tsx +336 -0
- package/dist/files/_tags/OverflowTagPopover.tsx +315 -0
- package/dist/files/_tags/get-max-tag-display.ts +26 -0
- package/dist/files/_tags/index.ts +15 -0
- package/dist/files/_tags/resolve-max-tag-popover.ts +28 -0
- package/dist/files/_tags/tags.css +126 -0
- package/dist/files/_tags/types.ts +46 -0
- package/dist/files/_tags/use-responsive-max-tag-count.ts +165 -0
- package/dist/files/alert/Alert.tsx +100 -0
- package/dist/files/alert/alert.css +85 -0
- package/dist/files/alert/index.ts +2 -0
- package/dist/files/alert/interface.ts +59 -0
- package/dist/files/alert/llm.txt +160 -0
- package/dist/files/alert/tokens.txt +44 -0
- package/dist/files/alert/variants.ts +17 -0
- package/dist/files/apex-env.d.ts +2 -0
- package/dist/files/apex-provider/ApexProvider.tsx +53 -0
- package/dist/files/apex-provider/apex-provider.css +0 -0
- package/dist/files/apex-provider/context.ts +17 -0
- package/dist/files/apex-provider/index.ts +18 -0
- package/dist/files/apex-provider/interface.ts +181 -0
- package/dist/files/apex-provider/llm.txt +367 -0
- package/dist/files/apex-provider/localeKind.ts +20 -0
- package/dist/files/auto-complete/AutoComplete.tsx +419 -0
- package/dist/files/auto-complete/auto-complete.css +108 -0
- package/dist/files/auto-complete/auto-complete.stories.css +17 -0
- package/dist/files/auto-complete/index.ts +8 -0
- package/dist/files/auto-complete/interface.ts +77 -0
- package/dist/files/auto-complete/llm.txt +374 -0
- package/dist/files/auto-complete/tokens.txt +77 -0
- package/dist/files/auto-complete/variants.ts +19 -0
- package/dist/files/avatar/Avatar.tsx +277 -0
- package/dist/files/avatar/avatar.css +159 -0
- package/dist/files/avatar/index.ts +2 -0
- package/dist/files/avatar/interface.ts +147 -0
- package/dist/files/avatar/llm.txt +195 -0
- package/dist/files/avatar/tokens.txt +38 -0
- package/dist/files/avatar/use-responsive-size.ts +66 -0
- package/dist/files/avatar/variants.ts +41 -0
- package/dist/files/breadcrumb/Breadcrumb.stories.css +5 -0
- package/dist/files/breadcrumb/Breadcrumb.tsx +238 -0
- package/dist/files/breadcrumb/BreadcrumbLink.tsx +63 -0
- package/dist/files/breadcrumb/BreadcrumbSeparatorIcon.tsx +30 -0
- package/dist/files/breadcrumb/breadcrumb.css +113 -0
- package/dist/files/breadcrumb/index.ts +12 -0
- package/dist/files/breadcrumb/interface.ts +81 -0
- package/dist/files/breadcrumb/llm.txt +249 -0
- package/dist/files/breadcrumb/tokens.txt +193 -0
- package/dist/files/breadcrumb/variants.ts +8 -0
- package/dist/files/button/Button.tsx +235 -0
- package/dist/files/button/button.css +261 -0
- package/dist/files/button/index.ts +2 -0
- package/dist/files/button/interface.ts +145 -0
- package/dist/files/button/llm.txt +254 -0
- package/dist/files/button/tokens.txt +470 -0
- package/dist/files/button/variants.ts +89 -0
- package/dist/files/card/Card.tsx +63 -0
- package/dist/files/card/card.css +66 -0
- package/dist/files/card/index.ts +2 -0
- package/dist/files/card/interface.ts +25 -0
- package/dist/files/card/llm.txt +93 -0
- package/dist/files/card/tokens.txt +27 -0
- package/dist/files/cascader/Cascader.tsx +955 -0
- package/dist/files/cascader/_adapter/locale.ts +4 -0
- package/dist/files/cascader/cascader-data.ts +354 -0
- package/dist/files/cascader/cascader.css +382 -0
- package/dist/files/cascader/index.ts +16 -0
- package/dist/files/cascader/interface.ts +358 -0
- package/dist/files/cascader/llm.txt +897 -0
- package/dist/files/cascader/tokens.txt +253 -0
- package/dist/files/cascader/variants.ts +35 -0
- package/dist/files/checkbox/Checkbox.tsx +477 -0
- package/dist/files/checkbox/checkbox.css +196 -0
- package/dist/files/checkbox/index.ts +9 -0
- package/dist/files/checkbox/interface.ts +162 -0
- package/dist/files/checkbox/llm.txt +326 -0
- package/dist/files/checkbox/tokens.txt +28 -0
- package/dist/files/checkbox/variants.ts +29 -0
- package/dist/files/clear/Clear.tsx +49 -0
- package/dist/files/clear/clear.css +60 -0
- package/dist/files/clear/index.ts +2 -0
- package/dist/files/clear/interface.ts +8 -0
- package/dist/files/collapse/Collapse.tsx +163 -0
- package/dist/files/collapse/collapse.css +174 -0
- package/dist/files/collapse/index.ts +2 -0
- package/dist/files/collapse/interface.ts +132 -0
- package/dist/files/collapse/llm.txt +328 -0
- package/dist/files/collapse/tokens.txt +84 -0
- package/dist/files/core/date-picker/index.ts +191 -0
- package/dist/files/core/form/index.ts +212 -0
- package/dist/files/core/index.ts +11 -0
- package/dist/files/core/input-number/index.ts +112 -0
- package/dist/files/core/namespace/index.ts +14 -0
- package/dist/files/core/overlay/index.ts +40 -0
- package/dist/files/core/pagination/index.ts +128 -0
- package/dist/files/core/table/access.ts +37 -0
- package/dist/files/core/table/columns.ts +4 -0
- package/dist/files/core/table/data-model.ts +58 -0
- package/dist/files/core/table/fixed-offset.ts +29 -0
- package/dist/files/core/table/grouped-header.ts +24 -0
- package/dist/files/core/table/index.ts +11 -0
- package/dist/files/core/table/merge.ts +132 -0
- package/dist/files/core/table/pagination.ts +51 -0
- package/dist/files/core/table/rowModel.ts +4 -0
- package/dist/files/core/table/types.ts +14 -0
- package/dist/files/core/typography/index.ts +125 -0
- package/dist/files/core/upload/file-type.ts +160 -0
- package/dist/files/core/upload/format-size.ts +17 -0
- package/dist/files/core/upload/index.ts +19 -0
- package/dist/files/core/upload/limits.ts +76 -0
- package/dist/files/core/utils/cn.ts +6 -0
- package/dist/files/core/utils/index.ts +2 -0
- package/dist/files/core/utils/svg.ts +101 -0
- package/dist/files/date-picker/DatePicker.tsx +601 -0
- package/dist/files/date-picker/RangePicker.tsx +1047 -0
- package/dist/files/date-picker/Trigger.tsx +115 -0
- package/dist/files/date-picker/_adapter/calendar.ts +136 -0
- package/dist/files/date-picker/_adapter/disable.ts +89 -0
- package/dist/files/date-picker/_adapter/format.ts +54 -0
- package/dist/files/date-picker/_adapter/keymap.ts +17 -0
- package/dist/files/date-picker/_adapter/locale.ts +4 -0
- package/dist/files/date-picker/_adapter/presets.ts +30 -0
- package/dist/files/date-picker/_adapter/range.ts +44 -0
- package/dist/files/date-picker/_adapter/types.ts +29 -0
- package/dist/files/date-picker/context.ts +60 -0
- package/dist/files/date-picker/date-picker.css +1093 -0
- package/dist/files/date-picker/index.ts +26 -0
- package/dist/files/date-picker/interface.ts +135 -0
- package/dist/files/date-picker/llm.txt +422 -0
- package/dist/files/date-picker/panels/DatePanel.tsx +110 -0
- package/dist/files/date-picker/panels/DecadePanel.tsx +49 -0
- package/dist/files/date-picker/panels/Footer.tsx +109 -0
- package/dist/files/date-picker/panels/Header.tsx +228 -0
- package/dist/files/date-picker/panels/MonthPanel.tsx +83 -0
- package/dist/files/date-picker/panels/Panel.tsx +339 -0
- package/dist/files/date-picker/panels/QuarterPanel.tsx +70 -0
- package/dist/files/date-picker/panels/TimePanel.tsx +171 -0
- package/dist/files/date-picker/panels/WeekPanel.tsx +145 -0
- package/dist/files/date-picker/panels/YearPanel.tsx +89 -0
- package/dist/files/date-picker/panels/time-panel-utils.ts +33 -0
- package/dist/files/date-picker/tokens.txt +171 -0
- package/dist/files/date-picker/variants.ts +20 -0
- package/dist/files/divider/Divider.tsx +80 -0
- package/dist/files/divider/divider.css +66 -0
- package/dist/files/divider/index.ts +7 -0
- package/dist/files/divider/interface.ts +58 -0
- package/dist/files/divider/llm.txt +158 -0
- package/dist/files/divider/tokens.txt +22 -0
- package/dist/files/drawer/Drawer.tsx +491 -0
- package/dist/files/drawer/drawer.css +201 -0
- package/dist/files/drawer/index.ts +13 -0
- package/dist/files/drawer/interface.ts +172 -0
- package/dist/files/drawer/llm.txt +374 -0
- package/dist/files/drawer/tokens.txt +71 -0
- package/dist/files/drawer/variants.ts +14 -0
- package/dist/files/dropdown/Dropdown.tsx +629 -0
- package/dist/files/dropdown/dropdown.css +243 -0
- package/dist/files/dropdown/index.ts +12 -0
- package/dist/files/dropdown/interface.ts +91 -0
- package/dist/files/dropdown/lib.ts +78 -0
- package/dist/files/dropdown/llm.txt +427 -0
- package/dist/files/dropdown/tokens.txt +59 -0
- package/dist/files/form/Form.tsx +229 -0
- package/dist/files/form/FormItem.tsx +526 -0
- package/dist/files/form/_adapter/bindField.ts +189 -0
- package/dist/files/form/_adapter/compileRules.ts +185 -0
- package/dist/files/form/_adapter/controlStatus.ts +23 -0
- package/dist/files/form/_adapter/deriveStatus.ts +42 -0
- package/dist/files/form/_adapter/instance.ts +281 -0
- package/dist/files/form/_adapter/messages.ts +15 -0
- package/dist/files/form/_adapter/types.ts +82 -0
- package/dist/files/form/_adapter/validationMeta.ts +29 -0
- package/dist/files/form/_adapter/validationTransaction.ts +69 -0
- package/dist/files/form/context.ts +38 -0
- package/dist/files/form/form.css +268 -0
- package/dist/files/form/index.ts +13 -0
- package/dist/files/form/interface.ts +99 -0
- package/dist/files/form/llm.txt +346 -0
- package/dist/files/form/tokens.txt +26 -0
- package/dist/files/form/useForm.ts +150 -0
- package/dist/files/form/utils.ts +28 -0
- package/dist/files/form/variants.ts +30 -0
- package/dist/files/global.css +8 -0
- package/dist/files/grid/Col.tsx +104 -0
- package/dist/files/grid/Grid.tsx +18 -0
- package/dist/files/grid/Row.tsx +129 -0
- package/dist/files/grid/grid.css +990 -0
- package/dist/files/grid/index.ts +12 -0
- package/dist/files/grid/interface.ts +109 -0
- package/dist/files/grid/llm.txt +419 -0
- package/dist/files/grid/useBreakpoint.ts +67 -0
- package/dist/files/icon/Icon.tsx +16 -0
- package/dist/files/icon/icon.css +26 -0
- package/dist/files/icon/icons-map.ts +1 -0
- package/dist/files/icon/index.ts +2 -0
- package/dist/files/icon/interface.ts +9 -0
- package/dist/files/icons/ActionIcons.tsx +105 -0
- package/dist/files/icons/AlertCloseIcon.tsx +21 -0
- package/dist/files/icons/CalendarIcon.tsx +6 -0
- package/dist/files/icons/CaretIcons.tsx +43 -0
- package/dist/files/icons/FileFormatIcons.tsx +27 -0
- package/dist/files/icons/Icons.tsx +10 -0
- package/dist/files/icons/MagnifyingGlassIcon.tsx +26 -0
- package/dist/files/icons/MessageIcons.tsx +111 -0
- package/dist/files/icons/NavigationIcons.tsx +126 -0
- package/dist/files/icons/PreviewIcons.tsx +18 -0
- package/dist/files/icons/StarIcons.tsx +71 -0
- package/dist/files/icons/UploadIcons.tsx +167 -0
- package/dist/files/icons/XCloseIcon.tsx +26 -0
- package/dist/files/icons/createAssetIcon.tsx +64 -0
- package/dist/files/icons/icons.css +4 -0
- package/dist/files/icons/index.ts +36 -0
- package/dist/files/icons/interface.ts +9 -0
- package/dist/files/icons/registry.ts +94 -0
- package/dist/files/image/Image.tsx +328 -0
- package/dist/files/image/ImageActionIcons.tsx +60 -0
- package/dist/files/image/ImagePreview.tsx +684 -0
- package/dist/files/image/_adapter/locale.ts +4 -0
- package/dist/files/image/image.css +451 -0
- package/dist/files/image/index.ts +7 -0
- package/dist/files/image/interface.ts +139 -0
- package/dist/files/image/llm.txt +429 -0
- package/dist/files/image/tokens.txt +28 -0
- package/dist/files/input/Input.tsx +261 -0
- package/dist/files/input/icons.tsx +3 -0
- package/dist/files/input/index.ts +12 -0
- package/dist/files/input/input-clear.stories.css +12 -0
- package/dist/files/input/input-size.ts +36 -0
- package/dist/files/input/input.css +366 -0
- package/dist/files/input/interface.ts +204 -0
- package/dist/files/input/lib.ts +51 -0
- package/dist/files/input/llm.txt +419 -0
- package/dist/files/input/tokens.txt +136 -0
- package/dist/files/input/variants.ts +17 -0
- package/dist/files/input-number/InputNumber.tsx +510 -0
- package/dist/files/input-number/icons.tsx +28 -0
- package/dist/files/input-number/index.ts +15 -0
- package/dist/files/input-number/input-number.css +440 -0
- package/dist/files/input-number/interface.ts +269 -0
- package/dist/files/input-number/lib.ts +128 -0
- package/dist/files/input-number/llm.txt +484 -0
- package/dist/files/input-number/tokens.txt +159 -0
- package/dist/files/input-number/variants.ts +27 -0
- package/dist/files/layout/Layout.tsx +360 -0
- package/dist/files/layout/index.ts +21 -0
- package/dist/files/layout/interface.ts +106 -0
- package/dist/files/layout/layout.css +278 -0
- package/dist/files/layout/llm.txt +296 -0
- package/dist/files/layout/tokens.txt +29 -0
- package/dist/files/llms-theme.txt +32 -0
- package/dist/files/llms.txt +895 -0
- package/dist/files/locale/en_US.ts +167 -0
- package/dist/files/locale/zh_CN.ts +166 -0
- package/dist/files/menu/Menu.stories.shared.tsx +85 -0
- package/dist/files/menu/Menu.tsx +713 -0
- package/dist/files/menu/demo/menu-sliding-panel.css +71 -0
- package/dist/files/menu/demo/use-sliding-panel.ts +35 -0
- package/dist/files/menu/icons.tsx +92 -0
- package/dist/files/menu/index.ts +17 -0
- package/dist/files/menu/interface.ts +229 -0
- package/dist/files/menu/lib.ts +160 -0
- package/dist/files/menu/llm.txt +686 -0
- package/dist/files/menu/menu.css +455 -0
- package/dist/files/menu/tokens.txt +87 -0
- package/dist/files/message/Message.tsx +217 -0
- package/dist/files/message/index.ts +2 -0
- package/dist/files/message/interface.ts +149 -0
- package/dist/files/message/lib/constants.ts +18 -0
- package/dist/files/message/lib/helpers.ts +26 -0
- package/dist/files/message/lib/motion.ts +117 -0
- package/dist/files/message/lib/store.ts +72 -0
- package/dist/files/message/llm.txt +301 -0
- package/dist/files/message/message.css +178 -0
- package/dist/files/message/tokens.txt +25 -0
- package/dist/files/modal/Modal.tsx +547 -0
- package/dist/files/modal/_adapter/locale.ts +4 -0
- package/dist/files/modal/index.ts +16 -0
- package/dist/files/modal/interface.ts +368 -0
- package/dist/files/modal/lib/ConfirmDialog.tsx +229 -0
- package/dist/files/modal/lib/confirm.tsx +112 -0
- package/dist/files/modal/lib/confirmIcons.tsx +21 -0
- package/dist/files/modal/lib/useModal.tsx +130 -0
- package/dist/files/modal/llm.txt +586 -0
- package/dist/files/modal/modal-padding.stories.css +22 -0
- package/dist/files/modal/modal.css +322 -0
- package/dist/files/modal/tokens.txt +96 -0
- package/dist/files/modal/variants.ts +41 -0
- package/dist/files/notification/Notification.tsx +354 -0
- package/dist/files/notification/index.ts +8 -0
- package/dist/files/notification/interface.ts +140 -0
- package/dist/files/notification/lib/constants.ts +40 -0
- package/dist/files/notification/lib/helpers.ts +31 -0
- package/dist/files/notification/lib/motion.ts +148 -0
- package/dist/files/notification/lib/store.ts +149 -0
- package/dist/files/notification/llm.txt +386 -0
- package/dist/files/notification/notification.css +416 -0
- package/dist/files/notification/tokens.txt +79 -0
- package/dist/files/pagination/PageButton.tsx +48 -0
- package/dist/files/pagination/PageSizeChanger.tsx +42 -0
- package/dist/files/pagination/Pagination.tsx +308 -0
- package/dist/files/pagination/QuickJumper.tsx +52 -0
- package/dist/files/pagination/TotalText.tsx +28 -0
- package/dist/files/pagination/_adapter/calculate.ts +33 -0
- package/dist/files/pagination/_adapter/locale.ts +4 -0
- package/dist/files/pagination/_adapter/responsive.ts +22 -0
- package/dist/files/pagination/_adapter/types.ts +27 -0
- package/dist/files/pagination/context.ts +15 -0
- package/dist/files/pagination/index.ts +3 -0
- package/dist/files/pagination/interface.ts +55 -0
- package/dist/files/pagination/llm.txt +204 -0
- package/dist/files/pagination/pagination.css +241 -0
- package/dist/files/pagination/tokens.txt +33 -0
- package/dist/files/pagination/useResizeObserver.ts +40 -0
- package/dist/files/pagination/variants.ts +3 -0
- package/dist/files/popover/Popover.tsx +353 -0
- package/dist/files/popover/index.ts +2 -0
- package/dist/files/popover/interface.ts +124 -0
- package/dist/files/popover/llm.txt +235 -0
- package/dist/files/popover/placement.ts +39 -0
- package/dist/files/popover/popover.css +65 -0
- package/dist/files/popover/popover.stories.css +42 -0
- package/dist/files/popover/tokens.txt +28 -0
- package/dist/files/progress/Progress.tsx +213 -0
- package/dist/files/progress/index.ts +4 -0
- package/dist/files/progress/interface.ts +89 -0
- package/dist/files/progress/llm.txt +277 -0
- package/dist/files/progress/progress.css +192 -0
- package/dist/files/progress/tokens.txt +83 -0
- package/dist/files/radio/Radio.tsx +315 -0
- package/dist/files/radio/context.tsx +16 -0
- package/dist/files/radio/helpers.ts +163 -0
- package/dist/files/radio/index.ts +13 -0
- package/dist/files/radio/interface.ts +207 -0
- package/dist/files/radio/llm.txt +344 -0
- package/dist/files/radio/radio.css +137 -0
- package/dist/files/radio/tokens.txt +21 -0
- package/dist/files/radio/variants.ts +20 -0
- package/dist/files/rate/Rate.tsx +199 -0
- package/dist/files/rate/RateItem.tsx +113 -0
- package/dist/files/rate/StarFilled.tsx +19 -0
- package/dist/files/rate/index.ts +11 -0
- package/dist/files/rate/interface.ts +116 -0
- package/dist/files/rate/lib.ts +72 -0
- package/dist/files/rate/llm.txt +237 -0
- package/dist/files/rate/rate.css +126 -0
- package/dist/files/rate/tokens.txt +20 -0
- package/dist/files/rate/variants.ts +19 -0
- package/dist/files/scrollbar.css +148 -0
- package/dist/files/select/Select.tsx +1366 -0
- package/dist/files/select/_adapter/locale.ts +4 -0
- package/dist/files/select/index.ts +17 -0
- package/dist/files/select/interface.ts +494 -0
- package/dist/files/select/llm.txt +828 -0
- package/dist/files/select/select-overflow.stories.css +3 -0
- package/dist/files/select/select.css +443 -0
- package/dist/files/select/tokens.txt +160 -0
- package/dist/files/select/variants.ts +63 -0
- package/dist/files/skeleton/Skeleton.tsx +345 -0
- package/dist/files/skeleton/index.ts +19 -0
- package/dist/files/skeleton/interface.ts +101 -0
- package/dist/files/skeleton/llm.txt +274 -0
- package/dist/files/skeleton/skeleton.css +171 -0
- package/dist/files/skeleton/tokens.txt +15 -0
- package/dist/files/skeleton/variants.ts +40 -0
- package/dist/files/spin/Spin.tsx +197 -0
- package/dist/files/spin/index.ts +2 -0
- package/dist/files/spin/interface.ts +69 -0
- package/dist/files/spin/llm.txt +294 -0
- package/dist/files/spin/spin.css +111 -0
- package/dist/files/spin/tokens.txt +21 -0
- package/dist/files/spin/variants.ts +19 -0
- package/dist/files/steps/Steps.tsx +211 -0
- package/dist/files/steps/index.ts +11 -0
- package/dist/files/steps/interface.ts +155 -0
- package/dist/files/steps/lib.ts +46 -0
- package/dist/files/steps/llm.txt +296 -0
- package/dist/files/steps/steps.css +268 -0
- package/dist/files/steps/tokens.txt +30 -0
- package/dist/files/steps/variants.ts +15 -0
- package/dist/files/switch/Switch.tsx +131 -0
- package/dist/files/switch/index.ts +2 -0
- package/dist/files/switch/interface.ts +92 -0
- package/dist/files/switch/llm.txt +212 -0
- package/dist/files/switch/switch.css +198 -0
- package/dist/files/switch/tokens.txt +38 -0
- package/dist/files/switch/variants.ts +15 -0
- package/dist/files/table/Table.stories.css +56 -0
- package/dist/files/table/Table.tsx +481 -0
- package/dist/files/table/_adapter/locale.ts +4 -0
- package/dist/files/table/constants.ts +7 -0
- package/dist/files/table/context.ts +46 -0
- package/dist/files/table/hooks/useColumnControl.ts +135 -0
- package/dist/files/table/hooks/useColumns.ts +87 -0
- package/dist/files/table/hooks/useExpandable.tsx +271 -0
- package/dist/files/table/hooks/useOverlayScrollbar.ts +304 -0
- package/dist/files/table/hooks/usePagination.ts +110 -0
- package/dist/files/table/hooks/useRowSelection.tsx +250 -0
- package/dist/files/table/hooks/useScrollShadow.ts +66 -0
- package/dist/files/table/hooks/useSkeletonRowCount.ts +78 -0
- package/dist/files/table/hooks/useTableLayoutScale.ts +38 -0
- package/dist/files/table/hooks/useTableModel.ts +91 -0
- package/dist/files/table/index.ts +24 -0
- package/dist/files/table/interface.ts +407 -0
- package/dist/files/table/llm.txt +1050 -0
- package/dist/files/table/parts/TableBody.tsx +396 -0
- package/dist/files/table/parts/TableCell.tsx +123 -0
- package/dist/files/table/parts/TableColgroup.tsx +35 -0
- package/dist/files/table/parts/TableEmpty.tsx +48 -0
- package/dist/files/table/parts/TableEmptyIllustration.tsx +27 -0
- package/dist/files/table/parts/TableHeader.tsx +102 -0
- package/dist/files/table/parts/TablePagination.tsx +46 -0
- package/dist/files/table/parts/TableRow.tsx +42 -0
- package/dist/files/table/parts/TableScrollbars.tsx +79 -0
- package/dist/files/table/parts/TableSkeleton.tsx +47 -0
- package/dist/files/table/parts/TableSummary.tsx +121 -0
- package/dist/files/table/table.css +850 -0
- package/dist/files/table/tokenScopes.ts +28 -0
- package/dist/files/table/tokens.txt +94 -0
- package/dist/files/table/utils/computeMergeGrid.ts +41 -0
- package/dist/files/table/utils/dataModel.ts +45 -0
- package/dist/files/table/utils/getCellValue.ts +7 -0
- package/dist/files/table/utils/getGroupedHeaderSpan.ts +73 -0
- package/dist/files/table/utils/getRowKey.ts +31 -0
- package/dist/files/table/utils/paginationState.ts +31 -0
- package/dist/files/table/utils/prefixSvgIds.ts +6 -0
- package/dist/files/table/utils/scaleFixedOffset.ts +19 -0
- package/dist/files/tabs/Tabs.tsx +140 -0
- package/dist/files/tabs/index.ts +2 -0
- package/dist/files/tabs/interface.ts +117 -0
- package/dist/files/tabs/llm.txt +305 -0
- package/dist/files/tabs/tabs.css +299 -0
- package/dist/files/tabs/tokens.txt +78 -0
- package/dist/files/tabs/variants.ts +51 -0
- package/dist/files/tag/Tag.tsx +180 -0
- package/dist/files/tag/index.ts +8 -0
- package/dist/files/tag/interface.ts +68 -0
- package/dist/files/tag/llm.txt +301 -0
- package/dist/files/tag/tag.css +96 -0
- package/dist/files/tag/tokens.txt +76 -0
- package/dist/files/tag/variants.ts +71 -0
- package/dist/files/theme/aliases.css +217 -0
- package/dist/files/theme/component-tokens.css +2211 -0
- package/dist/files/theme/index.css +4 -0
- package/dist/files/theme/primitives.css +182 -0
- package/dist/files/theme/static.css +13 -0
- package/dist/files/tooltip/Tooltip.tsx +362 -0
- package/dist/files/tooltip/index.ts +7 -0
- package/dist/files/tooltip/interface.ts +118 -0
- package/dist/files/tooltip/llm.txt +308 -0
- package/dist/files/tooltip/placement.ts +51 -0
- package/dist/files/tooltip/tokens.txt +22 -0
- package/dist/files/tooltip/tooltip.css +78 -0
- package/dist/files/tree/Tree.tsx +1069 -0
- package/dist/files/tree/constants.ts +2 -0
- package/dist/files/tree/index.ts +22 -0
- package/dist/files/tree/interface.ts +447 -0
- package/dist/files/tree/llm.txt +501 -0
- package/dist/files/tree/tokens.txt +36 -0
- package/dist/files/tree/tree-data.ts +260 -0
- package/dist/files/tree/tree.css +231 -0
- package/dist/files/tree/variants.ts +25 -0
- package/dist/files/tree-select/TreeSelect.tsx +864 -0
- package/dist/files/tree-select/_adapter/locale.ts +4 -0
- package/dist/files/tree-select/index.ts +23 -0
- package/dist/files/tree-select/interface.ts +415 -0
- package/dist/files/tree-select/llm.txt +754 -0
- package/dist/files/tree-select/tokens.txt +174 -0
- package/dist/files/tree-select/tree-select-data.ts +294 -0
- package/dist/files/tree-select/tree-select.css +303 -0
- package/dist/files/tree-select/variants.ts +42 -0
- package/dist/files/typography/Typography.tsx +739 -0
- package/dist/files/typography/_adapter/locale.ts +4 -0
- package/dist/files/typography/canvasTextMeasure.ts +148 -0
- package/dist/files/typography/index.ts +21 -0
- package/dist/files/typography/interface.ts +154 -0
- package/dist/files/typography/llm.txt +412 -0
- package/dist/files/typography/tokens.txt +60 -0
- package/dist/files/typography/typography.css +312 -0
- package/dist/files/typography/useEllipsisSuffix.ts +245 -0
- package/dist/files/typography/variants.ts +24 -0
- package/dist/files/upload/Upload.stories.css +54 -0
- package/dist/files/upload/Upload.stories.shared.ts +21 -0
- package/dist/files/upload/Upload.tsx +1108 -0
- package/dist/files/upload/UploadActionIcons.tsx +13 -0
- package/dist/files/upload/UploadFileIcon.tsx +52 -0
- package/dist/files/upload/_adapter/locale.ts +4 -0
- package/dist/files/upload/constants.ts +46 -0
- package/dist/files/upload/index.ts +38 -0
- package/dist/files/upload/interface.ts +302 -0
- package/dist/files/upload/lib/file-type.ts +60 -0
- package/dist/files/upload/lib/format-size.ts +6 -0
- package/dist/files/upload/lib/limits.ts +46 -0
- package/dist/files/upload/llm.txt +705 -0
- package/dist/files/upload/tokens.txt +201 -0
- package/dist/files/upload/upload.css +460 -0
- package/dist/files/utils/cn.ts +16 -0
- package/dist/files/utils/env.ts +16 -0
- package/dist/files/utils/normalizeRawSvg.ts +12 -0
- package/dist/manifest.json +580 -0
- package/package.json +41 -3
|
@@ -0,0 +1,1366 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import '../dropdown/dropdown.css'
|
|
4
|
+
import './select.css'
|
|
5
|
+
import { useVirtualizer } from '@tanstack/react-virtual'
|
|
6
|
+
import * as React from 'react'
|
|
7
|
+
import {
|
|
8
|
+
AnchoredOverlayContent,
|
|
9
|
+
useAnchoredOverlay,
|
|
10
|
+
warnDeprecatedGetPopupContainer,
|
|
11
|
+
} from '../_overlay'
|
|
12
|
+
import { MaxTagList } from '../_tags'
|
|
13
|
+
import { useConfig } from '../apex-provider'
|
|
14
|
+
import { Clear } from '../clear'
|
|
15
|
+
import { CaretDownIcon, CheckIcon } from '../icons'
|
|
16
|
+
import {
|
|
17
|
+
resolveInputSizeClass,
|
|
18
|
+
resolveInputTagSize,
|
|
19
|
+
resolveInputVariant,
|
|
20
|
+
resolveInputVariantClass,
|
|
21
|
+
} from '../input/input-size'
|
|
22
|
+
import { Typography } from '../typography'
|
|
23
|
+
import { cn } from '../utils/cn'
|
|
24
|
+
import { defaultLocale } from './_adapter/locale'
|
|
25
|
+
import type {
|
|
26
|
+
SelectAllowClear,
|
|
27
|
+
SelectBaseOptionType,
|
|
28
|
+
SelectFieldNames,
|
|
29
|
+
SelectFlattenOptionData,
|
|
30
|
+
SelectOptionType,
|
|
31
|
+
SelectProps,
|
|
32
|
+
SelectShowSearchOption,
|
|
33
|
+
SelectValue,
|
|
34
|
+
} from './interface'
|
|
35
|
+
import {
|
|
36
|
+
selectListVariants,
|
|
37
|
+
selectOptionVariants,
|
|
38
|
+
selectPopupVariants,
|
|
39
|
+
selectSelectorVariants,
|
|
40
|
+
} from './variants'
|
|
41
|
+
|
|
42
|
+
const prefixCls = 'apex-select'
|
|
43
|
+
|
|
44
|
+
/** 与 `select.css` 中 `.apex-select__list` 的 `--dropdown-size-container-gap` 一致 */
|
|
45
|
+
const SELECT_LIST_ITEM_GAP = 2
|
|
46
|
+
const SELECT_VIRTUAL_OVERSCAN = 6
|
|
47
|
+
const SELECT_DEFAULT_ITEM_HEIGHT = 32
|
|
48
|
+
|
|
49
|
+
const SelectCaretDownIcon = React.memo(() => <CaretDownIcon />)
|
|
50
|
+
SelectCaretDownIcon.displayName = 'SelectCaretDownIcon'
|
|
51
|
+
|
|
52
|
+
const SelectSelectedCheckIcon = React.memo(() => <CheckIcon />)
|
|
53
|
+
SelectSelectedCheckIcon.displayName = 'SelectSelectedCheckIcon'
|
|
54
|
+
|
|
55
|
+
// ── Helpers ──────────────────────────────────────────────────────────────────
|
|
56
|
+
|
|
57
|
+
type RawValue = string | number
|
|
58
|
+
|
|
59
|
+
interface NormalizedFieldNames {
|
|
60
|
+
label: string
|
|
61
|
+
value: string
|
|
62
|
+
options: string
|
|
63
|
+
groupLabel: string
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
interface SelectVirtualConfig {
|
|
67
|
+
enabled: boolean
|
|
68
|
+
estimateSize: number
|
|
69
|
+
overscan: number
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
interface SelectVirtualListProps {
|
|
73
|
+
options: SelectFlattenOptionData[]
|
|
74
|
+
scrollElement: HTMLDivElement | null
|
|
75
|
+
scrollToIndexRef: React.MutableRefObject<((index: number) => void) | null>
|
|
76
|
+
estimateSize: number
|
|
77
|
+
overscan: number
|
|
78
|
+
getItemKey: (index: number) => string | number
|
|
79
|
+
renderItem: (
|
|
80
|
+
option: SelectFlattenOptionData,
|
|
81
|
+
index: number,
|
|
82
|
+
measureRef: (element: Element | null) => void,
|
|
83
|
+
) => React.ReactElement
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function resolveSelectVirtualConfig(
|
|
87
|
+
virtual: boolean | undefined,
|
|
88
|
+
listHeight: number,
|
|
89
|
+
listItemHeight: number,
|
|
90
|
+
): SelectVirtualConfig {
|
|
91
|
+
const hasConstrainedHeight = Number.isFinite(listHeight) && listHeight > 0
|
|
92
|
+
const resolvedItemHeight =
|
|
93
|
+
Number.isFinite(listItemHeight) && listItemHeight > 0
|
|
94
|
+
? listItemHeight
|
|
95
|
+
: SELECT_DEFAULT_ITEM_HEIGHT
|
|
96
|
+
|
|
97
|
+
return {
|
|
98
|
+
enabled: virtual !== false && hasConstrainedHeight,
|
|
99
|
+
estimateSize: resolvedItemHeight + SELECT_LIST_ITEM_GAP,
|
|
100
|
+
overscan: SELECT_VIRTUAL_OVERSCAN,
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function SelectVirtualSpacer({ height }: { height: number }): React.ReactElement | null {
|
|
105
|
+
if (height <= 0) return null
|
|
106
|
+
return (
|
|
107
|
+
<div
|
|
108
|
+
data-slot="select-virtual-spacer"
|
|
109
|
+
className="apex-select__virtual-spacer"
|
|
110
|
+
style={{ height }}
|
|
111
|
+
aria-hidden
|
|
112
|
+
/>
|
|
113
|
+
)
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function SelectVirtualList({
|
|
117
|
+
options,
|
|
118
|
+
scrollElement,
|
|
119
|
+
scrollToIndexRef,
|
|
120
|
+
estimateSize,
|
|
121
|
+
overscan,
|
|
122
|
+
getItemKey,
|
|
123
|
+
renderItem,
|
|
124
|
+
}: SelectVirtualListProps): React.ReactElement {
|
|
125
|
+
const virtualizer = useVirtualizer({
|
|
126
|
+
count: options.length,
|
|
127
|
+
getScrollElement: () => scrollElement,
|
|
128
|
+
estimateSize: () => estimateSize,
|
|
129
|
+
overscan,
|
|
130
|
+
enabled: scrollElement !== null && options.length > 0,
|
|
131
|
+
getItemKey,
|
|
132
|
+
})
|
|
133
|
+
|
|
134
|
+
React.useEffect(() => {
|
|
135
|
+
scrollToIndexRef.current = (index) => virtualizer.scrollToIndex(index, { align: 'auto' })
|
|
136
|
+
return () => {
|
|
137
|
+
scrollToIndexRef.current = null
|
|
138
|
+
}
|
|
139
|
+
}, [scrollToIndexRef, virtualizer])
|
|
140
|
+
|
|
141
|
+
const virtualItems = virtualizer.getVirtualItems()
|
|
142
|
+
const totalSize = virtualizer.getTotalSize()
|
|
143
|
+
const paddingTop = virtualItems[0]?.start ?? 0
|
|
144
|
+
const paddingBottom = virtualItems.length
|
|
145
|
+
? totalSize - virtualItems[virtualItems.length - 1].end
|
|
146
|
+
: 0
|
|
147
|
+
|
|
148
|
+
return (
|
|
149
|
+
<div
|
|
150
|
+
data-slot="select-virtual-holder"
|
|
151
|
+
className="apex-select__virtual-holder"
|
|
152
|
+
role="presentation"
|
|
153
|
+
>
|
|
154
|
+
<SelectVirtualSpacer height={paddingTop} />
|
|
155
|
+
{virtualItems.map((virtualItem) =>
|
|
156
|
+
renderItem(options[virtualItem.index], virtualItem.index, virtualizer.measureElement),
|
|
157
|
+
)}
|
|
158
|
+
<SelectVirtualSpacer height={paddingBottom} />
|
|
159
|
+
</div>
|
|
160
|
+
)
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
function resolveFieldNames(fieldNames?: SelectFieldNames): NormalizedFieldNames {
|
|
164
|
+
return {
|
|
165
|
+
label: fieldNames?.label ?? 'label',
|
|
166
|
+
value: fieldNames?.value ?? 'value',
|
|
167
|
+
options: fieldNames?.options ?? 'options',
|
|
168
|
+
groupLabel: fieldNames?.groupLabel ?? 'label',
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* 把 SelectValue 标准化为 RawValue 数组。
|
|
174
|
+
* - 单选返回 1 个或 0 个元素的数组
|
|
175
|
+
* - LabeledValue 取其 .value
|
|
176
|
+
* - 单选 undefined 返回 []
|
|
177
|
+
*/
|
|
178
|
+
function normalizeValues(value: SelectValue | undefined, isMulti: boolean): RawValue[] {
|
|
179
|
+
if (value === undefined || value === null) return []
|
|
180
|
+
if (Array.isArray(value)) {
|
|
181
|
+
return value.map((v) =>
|
|
182
|
+
typeof v === 'object' && v !== null && 'value' in v
|
|
183
|
+
? (v as { value: RawValue }).value
|
|
184
|
+
: (v as RawValue),
|
|
185
|
+
)
|
|
186
|
+
}
|
|
187
|
+
if (typeof value === 'object' && 'value' in value) {
|
|
188
|
+
return [(value as { value: RawValue }).value]
|
|
189
|
+
}
|
|
190
|
+
if (isMulti) {
|
|
191
|
+
return [value as RawValue]
|
|
192
|
+
}
|
|
193
|
+
return [value as RawValue]
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* 把 options 拍平:保留 group label 行(isGroupOption=true)以便渲染。
|
|
198
|
+
* 嵌套 group 不递归(antd 也只支持一层 group)。
|
|
199
|
+
*/
|
|
200
|
+
function flattenOptions(
|
|
201
|
+
options: SelectBaseOptionType[] | undefined,
|
|
202
|
+
fields: NormalizedFieldNames,
|
|
203
|
+
): SelectFlattenOptionData[] {
|
|
204
|
+
if (!options || options.length === 0) return []
|
|
205
|
+
const out: SelectFlattenOptionData[] = []
|
|
206
|
+
for (const opt of options) {
|
|
207
|
+
const nested = (opt as Record<string, unknown>)[fields.options] as
|
|
208
|
+
| SelectBaseOptionType[]
|
|
209
|
+
| undefined
|
|
210
|
+
if (Array.isArray(nested)) {
|
|
211
|
+
out.push({
|
|
212
|
+
...opt,
|
|
213
|
+
// 分组标题字段名可由 fieldNames.groupLabel 指定,但展示时统一映射到 label 上
|
|
214
|
+
label: (opt as Record<string, unknown>)[fields.groupLabel] as React.ReactNode,
|
|
215
|
+
isGroupOption: true,
|
|
216
|
+
level: 0,
|
|
217
|
+
})
|
|
218
|
+
for (const child of nested) {
|
|
219
|
+
out.push({ ...child, level: 1 })
|
|
220
|
+
}
|
|
221
|
+
} else {
|
|
222
|
+
out.push({ ...opt, level: 0 })
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
return out
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* 默认过滤器:基于 optionFilterProp 字段做大小写不敏感的子串匹配,
|
|
230
|
+
* 数组字段时多字段 OR 匹配。
|
|
231
|
+
*/
|
|
232
|
+
function defaultMatch(
|
|
233
|
+
opt: SelectBaseOptionType,
|
|
234
|
+
input: string,
|
|
235
|
+
optionFilterProp: string | string[] | undefined,
|
|
236
|
+
fields: NormalizedFieldNames,
|
|
237
|
+
): boolean {
|
|
238
|
+
const fieldList = Array.isArray(optionFilterProp)
|
|
239
|
+
? optionFilterProp
|
|
240
|
+
: [optionFilterProp ?? fields.value]
|
|
241
|
+
const lower = input.toLowerCase()
|
|
242
|
+
for (const key of fieldList) {
|
|
243
|
+
const raw = (opt as Record<string, unknown>)[key]
|
|
244
|
+
if (raw == null) continue
|
|
245
|
+
if (String(raw).toLowerCase().includes(lower)) return true
|
|
246
|
+
}
|
|
247
|
+
return false
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
function filterFlatOptions(
|
|
251
|
+
list: SelectFlattenOptionData[],
|
|
252
|
+
search: string,
|
|
253
|
+
filterOption: SelectProps['filterOption'],
|
|
254
|
+
optionFilterProp: string | string[] | undefined,
|
|
255
|
+
fields: NormalizedFieldNames,
|
|
256
|
+
): SelectFlattenOptionData[] {
|
|
257
|
+
if (!search || filterOption === false) return list
|
|
258
|
+
const matcher =
|
|
259
|
+
typeof filterOption === 'function'
|
|
260
|
+
? (opt: SelectBaseOptionType) => filterOption(search, opt)
|
|
261
|
+
: (opt: SelectBaseOptionType) => defaultMatch(opt, search, optionFilterProp, fields)
|
|
262
|
+
|
|
263
|
+
const matched: SelectFlattenOptionData[] = []
|
|
264
|
+
// 分组:先按 group 收集子项;保留含有匹配项的分组标题
|
|
265
|
+
let pendingGroup: SelectFlattenOptionData | null = null
|
|
266
|
+
let groupHasMatch = false
|
|
267
|
+
for (const item of list) {
|
|
268
|
+
if (item.isGroupOption) {
|
|
269
|
+
pendingGroup = item
|
|
270
|
+
groupHasMatch = false
|
|
271
|
+
continue
|
|
272
|
+
}
|
|
273
|
+
if (matcher(item)) {
|
|
274
|
+
if (pendingGroup && !groupHasMatch) {
|
|
275
|
+
matched.push(pendingGroup)
|
|
276
|
+
groupHasMatch = true
|
|
277
|
+
}
|
|
278
|
+
matched.push(item)
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
return matched
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
function placementToPopper(placement: SelectProps['placement']): {
|
|
285
|
+
side: 'top' | 'bottom'
|
|
286
|
+
align: 'start' | 'end'
|
|
287
|
+
} {
|
|
288
|
+
switch (placement) {
|
|
289
|
+
case 'topLeft':
|
|
290
|
+
return { side: 'top', align: 'start' }
|
|
291
|
+
case 'topRight':
|
|
292
|
+
return { side: 'top', align: 'end' }
|
|
293
|
+
case 'bottomRight':
|
|
294
|
+
return { side: 'bottom', align: 'end' }
|
|
295
|
+
case 'bottomLeft':
|
|
296
|
+
default:
|
|
297
|
+
return { side: 'bottom', align: 'start' }
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
/**
|
|
302
|
+
* useControllableState — 受控/非受控状态。
|
|
303
|
+
* `isControlled` 优先:单选清除时 `value` 可为 `undefined`,不能用 `controlled !== undefined` 判别。
|
|
304
|
+
*/
|
|
305
|
+
function useControllableState<T>(
|
|
306
|
+
controlled: T | undefined,
|
|
307
|
+
defaultValue: T | undefined,
|
|
308
|
+
isControlled?: boolean,
|
|
309
|
+
): [T | undefined, (next: T | undefined) => void] {
|
|
310
|
+
const controlledMode = isControlled ?? controlled !== undefined
|
|
311
|
+
const [internal, setInternal] = React.useState<T | undefined>(defaultValue)
|
|
312
|
+
const value = controlledMode ? controlled : internal
|
|
313
|
+
const set = React.useCallback(
|
|
314
|
+
(next: T | undefined) => {
|
|
315
|
+
if (!controlledMode) setInternal(next)
|
|
316
|
+
},
|
|
317
|
+
[controlledMode],
|
|
318
|
+
)
|
|
319
|
+
return [value, set]
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
// ── Component ────────────────────────────────────────────────────────────────
|
|
323
|
+
|
|
324
|
+
/**
|
|
325
|
+
* Select — 选择器
|
|
326
|
+
*
|
|
327
|
+
* 实现要点:
|
|
328
|
+
* - 用 Radix `Popover` 作为浮层 / 定位原语,便于在触发器内放置真实 `<input>`(Radix `Select`
|
|
329
|
+
* 的 Trigger 是 `<button>`,不能嵌套表单控件)
|
|
330
|
+
* - 单选 / 多选 / 可搜索(同步 + 异步)/ allowClear / 分组 options / fieldNames / 自定义渲染
|
|
331
|
+
* - 全部样式 / token 沿用 `select.css`,根节点挂 `.apex-input.apex-default-input` 复用 Input 作用域
|
|
332
|
+
*
|
|
333
|
+
* 异步搜索:传 `filterOption={false}` 关闭客户端过滤,监听 `onSearch` 拉取 `options` 即可。
|
|
334
|
+
*/
|
|
335
|
+
export const Select: React.FC<SelectProps> = (props) => {
|
|
336
|
+
const {
|
|
337
|
+
// value / open
|
|
338
|
+
value: valueProp,
|
|
339
|
+
defaultValue,
|
|
340
|
+
open: openProp,
|
|
341
|
+
defaultOpen,
|
|
342
|
+
// options
|
|
343
|
+
options,
|
|
344
|
+
fieldNames,
|
|
345
|
+
getPopupContainer,
|
|
346
|
+
optionRender,
|
|
347
|
+
optionLabelProp = 'label',
|
|
348
|
+
// mode
|
|
349
|
+
mode,
|
|
350
|
+
maxCount,
|
|
351
|
+
maxTagCount,
|
|
352
|
+
maxTagPlaceholder,
|
|
353
|
+
maxTagPopover,
|
|
354
|
+
// search
|
|
355
|
+
showSearch,
|
|
356
|
+
searchValue: searchValueProp,
|
|
357
|
+
filterOption = true,
|
|
358
|
+
filterSort,
|
|
359
|
+
optionFilterProp,
|
|
360
|
+
autoClearSearchValue = true,
|
|
361
|
+
// display
|
|
362
|
+
placeholder,
|
|
363
|
+
prefix,
|
|
364
|
+
suffixIcon,
|
|
365
|
+
removeIcon,
|
|
366
|
+
searchIcon: _searchIcon,
|
|
367
|
+
notFoundContent,
|
|
368
|
+
allowClear = false,
|
|
369
|
+
// state
|
|
370
|
+
disabled = false,
|
|
371
|
+
readOnly = false,
|
|
372
|
+
status,
|
|
373
|
+
size = 'medium',
|
|
374
|
+
variant = 'default',
|
|
375
|
+
placement = 'bottomLeft',
|
|
376
|
+
closeOnScroll = false,
|
|
377
|
+
defaultActiveFirstOption = true,
|
|
378
|
+
// styles
|
|
379
|
+
className,
|
|
380
|
+
style,
|
|
381
|
+
classNames,
|
|
382
|
+
styles,
|
|
383
|
+
// events
|
|
384
|
+
onChange,
|
|
385
|
+
onSelect,
|
|
386
|
+
onDeselect,
|
|
387
|
+
onClear,
|
|
388
|
+
onOpenChange,
|
|
389
|
+
onSearch,
|
|
390
|
+
onFocus,
|
|
391
|
+
onBlur,
|
|
392
|
+
onInputKeyDown,
|
|
393
|
+
onPopupScroll,
|
|
394
|
+
onActive,
|
|
395
|
+
// virtual scroll
|
|
396
|
+
virtual = true,
|
|
397
|
+
listHeight = 256,
|
|
398
|
+
listItemHeight = 32,
|
|
399
|
+
// misc
|
|
400
|
+
ref,
|
|
401
|
+
tagRender,
|
|
402
|
+
labelRender,
|
|
403
|
+
...restProps
|
|
404
|
+
} = props
|
|
405
|
+
const config = useConfig()
|
|
406
|
+
const pickerLocale = config?.locale?.Select ?? defaultLocale
|
|
407
|
+
const resolvedPlaceholder = placeholder ?? pickerLocale.placeholder
|
|
408
|
+
const resolvedNotFoundContent = notFoundContent ?? pickerLocale.notFoundContent
|
|
409
|
+
|
|
410
|
+
const isMulti = mode === 'multiple' || mode === 'tags'
|
|
411
|
+
const effectiveShowSearch = showSearch === undefined ? isMulti : Boolean(showSearch)
|
|
412
|
+
const showSearchOpts: SelectShowSearchOption | undefined =
|
|
413
|
+
typeof showSearch === 'object' ? showSearch : undefined
|
|
414
|
+
|
|
415
|
+
const effectiveFilterOption = showSearchOpts?.filterOption ?? filterOption
|
|
416
|
+
const effectiveOptionFilterProp = showSearchOpts?.optionFilterProp ?? optionFilterProp
|
|
417
|
+
const effectiveAutoClear = showSearchOpts?.autoClearSearchValue ?? autoClearSearchValue
|
|
418
|
+
const effectiveOnSearch = showSearchOpts?.onSearch ?? onSearch
|
|
419
|
+
const effectiveFilterSort = showSearchOpts?.filterSort ?? filterSort
|
|
420
|
+
|
|
421
|
+
// ── State ──────────────────────────────────────────────────────────────────
|
|
422
|
+
const [innerValue, setInnerValue] = useControllableState<SelectValue>(
|
|
423
|
+
valueProp,
|
|
424
|
+
defaultValue,
|
|
425
|
+
'value' in props,
|
|
426
|
+
)
|
|
427
|
+
const [open, setOpen] = useControllableState<boolean>(openProp, defaultOpen)
|
|
428
|
+
const [searchValue, setSearchValue] = useControllableState<string>(
|
|
429
|
+
showSearchOpts?.searchValue ?? searchValueProp,
|
|
430
|
+
'',
|
|
431
|
+
)
|
|
432
|
+
|
|
433
|
+
const isOpen = (open ?? false) && !readOnly
|
|
434
|
+
const search = searchValue ?? ''
|
|
435
|
+
|
|
436
|
+
const [activeIndex, setActiveIndex] = React.useState<number>(-1)
|
|
437
|
+
const [isComposing, setIsComposing] = React.useState(false)
|
|
438
|
+
// 指针展开只展示列表;用户搜索或使用键盘后再自动激活候选项。
|
|
439
|
+
const suppressFirstActivationRef = React.useRef(false)
|
|
440
|
+
const composingRef = React.useRef(false)
|
|
441
|
+
|
|
442
|
+
const inputRef = React.useRef<HTMLInputElement>(null)
|
|
443
|
+
const triggerRef = React.useRef<HTMLDivElement>(null)
|
|
444
|
+
const scrollToIndexRef = React.useRef<((index: number) => void) | null>(null)
|
|
445
|
+
const [listElement, setListElement] = React.useState<HTMLDivElement | null>(null)
|
|
446
|
+
const [, setTriggerNode] = React.useState<HTMLDivElement | null>(null)
|
|
447
|
+
|
|
448
|
+
const setTriggerRef = React.useCallback((node: HTMLDivElement | null) => {
|
|
449
|
+
triggerRef.current = node
|
|
450
|
+
setTriggerNode(node)
|
|
451
|
+
}, [])
|
|
452
|
+
|
|
453
|
+
const setListRef = React.useCallback((node: HTMLDivElement | null) => {
|
|
454
|
+
setListElement((current) => (current === node ? current : node))
|
|
455
|
+
}, [])
|
|
456
|
+
|
|
457
|
+
// C15: React 19 ref-as-prop —— 用 useEffect 把焦点目标元素同步到外部 ref。
|
|
458
|
+
// 焦点目标:showSearch=true 时为 <input>;否则为 selector trigger <div>。
|
|
459
|
+
React.useEffect(() => {
|
|
460
|
+
if (!ref) return
|
|
461
|
+
const target = (effectiveShowSearch ? inputRef.current : triggerRef.current) as
|
|
462
|
+
| HTMLInputElement
|
|
463
|
+
| HTMLDivElement
|
|
464
|
+
| null
|
|
465
|
+
if (typeof ref === 'function') {
|
|
466
|
+
ref(target)
|
|
467
|
+
// 显式 void 包裹:RefCallback 在 React 19 可返回清理函数,不能直接作为 effect cleanup 透传
|
|
468
|
+
return () => {
|
|
469
|
+
ref(null)
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
;(ref as React.MutableRefObject<HTMLInputElement | HTMLDivElement | null>).current = target
|
|
473
|
+
return () => {
|
|
474
|
+
;(ref as React.MutableRefObject<HTMLInputElement | HTMLDivElement | null>).current = null
|
|
475
|
+
}
|
|
476
|
+
}, [ref, effectiveShowSearch])
|
|
477
|
+
|
|
478
|
+
// ── Options pipeline ───────────────────────────────────────────────────────
|
|
479
|
+
const fields = React.useMemo(() => resolveFieldNames(fieldNames), [fieldNames])
|
|
480
|
+
|
|
481
|
+
const flatOptions = React.useMemo(() => flattenOptions(options, fields), [options, fields])
|
|
482
|
+
const rowKeys = React.useMemo(() => {
|
|
483
|
+
const keys = new Map<SelectFlattenOptionData, string>()
|
|
484
|
+
const seen = new Map<string, number>()
|
|
485
|
+
const reported = new Set<string>()
|
|
486
|
+
flatOptions.forEach((option, index) => {
|
|
487
|
+
const raw = option.isGroupOption
|
|
488
|
+
? `group:${index}`
|
|
489
|
+
: (option.key ?? (option as Record<string, unknown>)[fields.value])
|
|
490
|
+
const identity: string = raw == null ? `position:${index}` : `${typeof raw}:${String(raw)}`
|
|
491
|
+
keys.set(option, identity)
|
|
492
|
+
if (raw == null && !reported.has('missing')) {
|
|
493
|
+
console.error(
|
|
494
|
+
'[ApexSelect] invalid option row identity at position %d; provide a legal, unique, stable option.key.',
|
|
495
|
+
index,
|
|
496
|
+
)
|
|
497
|
+
reported.add('missing')
|
|
498
|
+
}
|
|
499
|
+
const previous = seen.get(identity)
|
|
500
|
+
if (previous !== undefined && !reported.has(String(identity))) {
|
|
501
|
+
console.error(
|
|
502
|
+
'[ApexSelect] duplicate option row identity at positions %d and %d; provide a legal, unique, stable option.key.',
|
|
503
|
+
previous,
|
|
504
|
+
index,
|
|
505
|
+
)
|
|
506
|
+
reported.add(String(identity))
|
|
507
|
+
}
|
|
508
|
+
if (previous === undefined) seen.set(identity, index)
|
|
509
|
+
})
|
|
510
|
+
return keys
|
|
511
|
+
}, [flatOptions, fields.value])
|
|
512
|
+
|
|
513
|
+
const filteredOptions = React.useMemo(() => {
|
|
514
|
+
let list = filterFlatOptions(
|
|
515
|
+
flatOptions,
|
|
516
|
+
search,
|
|
517
|
+
effectiveFilterOption,
|
|
518
|
+
effectiveOptionFilterProp,
|
|
519
|
+
fields,
|
|
520
|
+
)
|
|
521
|
+
if (effectiveFilterSort && search) {
|
|
522
|
+
// 仅对非分组项排序
|
|
523
|
+
const groups = list.filter((o) => o.isGroupOption)
|
|
524
|
+
const leaves = list.filter((o) => !o.isGroupOption)
|
|
525
|
+
leaves.sort((a, b) => effectiveFilterSort(a, b, { searchValue: search }))
|
|
526
|
+
// 简化:丢弃分组顺序,仅排序后追加(分组在异步搜索场景通常不常见)
|
|
527
|
+
list = groups.length > 0 ? [...groups, ...leaves] : leaves
|
|
528
|
+
}
|
|
529
|
+
return list
|
|
530
|
+
}, [
|
|
531
|
+
flatOptions,
|
|
532
|
+
search,
|
|
533
|
+
effectiveFilterOption,
|
|
534
|
+
effectiveOptionFilterProp,
|
|
535
|
+
effectiveFilterSort,
|
|
536
|
+
fields,
|
|
537
|
+
])
|
|
538
|
+
|
|
539
|
+
/** 可被键盘 / 鼠标激活的项的 index 集合(剔除分组标题与 disabled) */
|
|
540
|
+
const selectableIndexes = React.useMemo(() => {
|
|
541
|
+
const out: number[] = []
|
|
542
|
+
for (let i = 0; i < filteredOptions.length; i++) {
|
|
543
|
+
const o = filteredOptions[i]
|
|
544
|
+
if (!o.isGroupOption && !o.disabled) out.push(i)
|
|
545
|
+
}
|
|
546
|
+
return out
|
|
547
|
+
}, [filteredOptions])
|
|
548
|
+
|
|
549
|
+
const virtualConfig = React.useMemo(
|
|
550
|
+
() => resolveSelectVirtualConfig(virtual, listHeight, listItemHeight),
|
|
551
|
+
[listHeight, listItemHeight, virtual],
|
|
552
|
+
)
|
|
553
|
+
const useVirtualList = virtualConfig.enabled
|
|
554
|
+
|
|
555
|
+
const getVirtualItemKey = React.useCallback(
|
|
556
|
+
(index: number): string | number => {
|
|
557
|
+
const option = filteredOptions[index]
|
|
558
|
+
if (!option) return index
|
|
559
|
+
return rowKeys.get(option) ?? `position:${index}`
|
|
560
|
+
},
|
|
561
|
+
[filteredOptions, rowKeys],
|
|
562
|
+
)
|
|
563
|
+
|
|
564
|
+
// Modal/Drawer 打开时 react-remove-scroll 会在 capture 阶段拦截 body 外 portaled 浮层的 wheel。
|
|
565
|
+
// 下拉列表需手动滚动并阻断冒泡,否则触控板无法滚动(只能拖滚动条)。
|
|
566
|
+
React.useEffect(() => {
|
|
567
|
+
if (!isOpen) return
|
|
568
|
+
const list = listElement
|
|
569
|
+
if (!list) return
|
|
570
|
+
|
|
571
|
+
const handleWheel = (event: WheelEvent) => {
|
|
572
|
+
if (list.scrollHeight <= list.clientHeight) return
|
|
573
|
+
|
|
574
|
+
const maxScrollTop = list.scrollHeight - list.clientHeight
|
|
575
|
+
const nextScrollTop = Math.min(maxScrollTop, Math.max(0, list.scrollTop + event.deltaY))
|
|
576
|
+
if (nextScrollTop === list.scrollTop) return
|
|
577
|
+
|
|
578
|
+
list.scrollTop = nextScrollTop
|
|
579
|
+
list.dispatchEvent(new Event('scroll', { bubbles: true }))
|
|
580
|
+
event.preventDefault()
|
|
581
|
+
event.stopPropagation()
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
list.addEventListener('wheel', handleWheel, { passive: false })
|
|
585
|
+
return () => list.removeEventListener('wheel', handleWheel)
|
|
586
|
+
}, [isOpen, listElement])
|
|
587
|
+
|
|
588
|
+
const currentValues = React.useMemo(
|
|
589
|
+
() => normalizeValues(innerValue, isMulti),
|
|
590
|
+
[innerValue, isMulti],
|
|
591
|
+
)
|
|
592
|
+
const selectedOptionsRef = React.useRef(new Map<RawValue, SelectBaseOptionType>())
|
|
593
|
+
|
|
594
|
+
/** 当前结果优先;远程搜索移除的已选项从上一次提交的缓存补齐。 */
|
|
595
|
+
const valueOptionMap = React.useMemo(() => {
|
|
596
|
+
const map = new Map<RawValue, SelectBaseOptionType>()
|
|
597
|
+
for (const v of currentValues) {
|
|
598
|
+
const cached = selectedOptionsRef.current.get(v)
|
|
599
|
+
if (cached) map.set(v, cached)
|
|
600
|
+
}
|
|
601
|
+
// 编辑回显可直接提供 { value, label },无需先把已选项放进搜索结果。
|
|
602
|
+
const values = Array.isArray(innerValue) ? innerValue : [innerValue]
|
|
603
|
+
for (const item of values) {
|
|
604
|
+
if (typeof item === 'object' && item !== null && item.label !== undefined) {
|
|
605
|
+
map.set(item.value, {
|
|
606
|
+
...map.get(item.value),
|
|
607
|
+
[fields.value]: item.value,
|
|
608
|
+
[fields.label]: item.label,
|
|
609
|
+
})
|
|
610
|
+
}
|
|
611
|
+
}
|
|
612
|
+
for (const o of flatOptions) {
|
|
613
|
+
if (!o.isGroupOption) {
|
|
614
|
+
const v = (o as Record<string, unknown>)[fields.value] as RawValue | undefined
|
|
615
|
+
if (v !== undefined) map.set(v, o)
|
|
616
|
+
}
|
|
617
|
+
}
|
|
618
|
+
return map
|
|
619
|
+
}, [flatOptions, fields.value, fields.label, currentValues, innerValue])
|
|
620
|
+
|
|
621
|
+
// 仅在提交后更新缓存,避免被放弃的并发渲染污染;取消选择时释放对应数据。
|
|
622
|
+
React.useLayoutEffect(() => {
|
|
623
|
+
const selected = new Map<RawValue, SelectBaseOptionType>()
|
|
624
|
+
for (const v of currentValues) {
|
|
625
|
+
const option = valueOptionMap.get(v)
|
|
626
|
+
if (option) selected.set(v, option)
|
|
627
|
+
}
|
|
628
|
+
selectedOptionsRef.current = selected
|
|
629
|
+
}, [currentValues, valueOptionMap])
|
|
630
|
+
const hasSelection = currentValues.length > 0
|
|
631
|
+
const hasNumericTagOverflow =
|
|
632
|
+
isMulti && typeof maxTagCount === 'number' && currentValues.length > maxTagCount
|
|
633
|
+
const shouldHideEmptyMultiSearch = hasNumericTagOverflow && search === '' && !isComposing
|
|
634
|
+
|
|
635
|
+
// ── Reset activeIndex when list/open changes ───────────────────────────────
|
|
636
|
+
React.useEffect(() => {
|
|
637
|
+
if (!isOpen) {
|
|
638
|
+
suppressFirstActivationRef.current = false
|
|
639
|
+
return
|
|
640
|
+
}
|
|
641
|
+
|
|
642
|
+
const selectedIndex = selectableIndexes.find((i) => {
|
|
643
|
+
const opt = filteredOptions[i]
|
|
644
|
+
if (!opt || opt.isGroupOption) return false
|
|
645
|
+
const v = (opt as Record<string, unknown>)[fields.value] as RawValue | undefined
|
|
646
|
+
return v !== undefined && currentValues.includes(v)
|
|
647
|
+
})
|
|
648
|
+
if (selectedIndex !== undefined) {
|
|
649
|
+
setActiveIndex(selectedIndex)
|
|
650
|
+
return
|
|
651
|
+
}
|
|
652
|
+
|
|
653
|
+
if (!defaultActiveFirstOption || suppressFirstActivationRef.current) {
|
|
654
|
+
setActiveIndex(-1)
|
|
655
|
+
return
|
|
656
|
+
}
|
|
657
|
+
setActiveIndex(selectableIndexes[0] ?? -1)
|
|
658
|
+
}, [
|
|
659
|
+
isOpen,
|
|
660
|
+
selectableIndexes,
|
|
661
|
+
filteredOptions,
|
|
662
|
+
currentValues,
|
|
663
|
+
fields.value,
|
|
664
|
+
defaultActiveFirstOption,
|
|
665
|
+
])
|
|
666
|
+
|
|
667
|
+
// ── Event helpers ──────────────────────────────────────────────────────────
|
|
668
|
+
const handleOpenChange = React.useCallback(
|
|
669
|
+
(next: boolean) => {
|
|
670
|
+
if (next && (disabled || readOnly)) return
|
|
671
|
+
setOpen(next)
|
|
672
|
+
onOpenChange?.(next)
|
|
673
|
+
if (!next && effectiveAutoClear) {
|
|
674
|
+
setSearchValue('')
|
|
675
|
+
}
|
|
676
|
+
},
|
|
677
|
+
[disabled, readOnly, setOpen, onOpenChange, effectiveAutoClear, setSearchValue],
|
|
678
|
+
)
|
|
679
|
+
|
|
680
|
+
const fireChange = React.useCallback(
|
|
681
|
+
(
|
|
682
|
+
nextValue: RawValue | RawValue[] | undefined,
|
|
683
|
+
option?: SelectOptionType | SelectOptionType[],
|
|
684
|
+
) => {
|
|
685
|
+
// 消费方可能在 onChange 中同步清空搜索结果;先记住本次选中数据。
|
|
686
|
+
for (const item of Array.isArray(option) ? option : option ? [option] : []) {
|
|
687
|
+
const v = item[fields.value]
|
|
688
|
+
if (typeof v === 'string' || typeof v === 'number') {
|
|
689
|
+
selectedOptionsRef.current.set(v, item)
|
|
690
|
+
}
|
|
691
|
+
}
|
|
692
|
+
// C13/C16: 内部统一以 RawValue 形态调度(实际运行时不回传 LabeledValue);
|
|
693
|
+
// 公开 SelectValue 类型更宽,故经 `as` 强转到内部 state 与判别联合 onChange。
|
|
694
|
+
// 判别联合在 single/multi 分支各自收窄;call site 已按 mode 构造正确 shape。
|
|
695
|
+
setInnerValue(nextValue as SelectValue | undefined)
|
|
696
|
+
onChange?.(nextValue as never, option as never)
|
|
697
|
+
},
|
|
698
|
+
[setInnerValue, onChange, fields.value],
|
|
699
|
+
)
|
|
700
|
+
|
|
701
|
+
const handleSearchChange = React.useCallback(
|
|
702
|
+
(next: string) => {
|
|
703
|
+
suppressFirstActivationRef.current = false
|
|
704
|
+
setSearchValue(next)
|
|
705
|
+
effectiveOnSearch?.(next)
|
|
706
|
+
},
|
|
707
|
+
[setSearchValue, effectiveOnSearch],
|
|
708
|
+
)
|
|
709
|
+
|
|
710
|
+
const handleSelectOption = React.useCallback(
|
|
711
|
+
(opt: SelectFlattenOptionData, index: number) => {
|
|
712
|
+
if (opt.disabled || opt.isGroupOption) return
|
|
713
|
+
const v = (opt as Record<string, unknown>)[fields.value] as RawValue | undefined
|
|
714
|
+
if (v === undefined) return
|
|
715
|
+
|
|
716
|
+
onSelect?.(v, opt as SelectOptionType)
|
|
717
|
+
|
|
718
|
+
if (isMulti) {
|
|
719
|
+
const exists = currentValues.includes(v)
|
|
720
|
+
let next: RawValue[]
|
|
721
|
+
if (exists) {
|
|
722
|
+
next = currentValues.filter((x) => x !== v)
|
|
723
|
+
onDeselect?.(v)
|
|
724
|
+
} else {
|
|
725
|
+
if (maxCount !== undefined && currentValues.length >= maxCount) return
|
|
726
|
+
next = [...currentValues, v]
|
|
727
|
+
}
|
|
728
|
+
const nextOptions = next.map(
|
|
729
|
+
(x) => (valueOptionMap.get(x) ?? { [fields.value]: x }) as SelectOptionType,
|
|
730
|
+
)
|
|
731
|
+
fireChange(next, nextOptions)
|
|
732
|
+
if (effectiveAutoClear) setSearchValue('')
|
|
733
|
+
setActiveIndex(index)
|
|
734
|
+
// keep focus on input for continued search/select
|
|
735
|
+
inputRef.current?.focus()
|
|
736
|
+
} else {
|
|
737
|
+
fireChange(v, opt as SelectOptionType)
|
|
738
|
+
handleOpenChange(false)
|
|
739
|
+
}
|
|
740
|
+
},
|
|
741
|
+
[
|
|
742
|
+
currentValues,
|
|
743
|
+
effectiveAutoClear,
|
|
744
|
+
fields.value,
|
|
745
|
+
fireChange,
|
|
746
|
+
handleOpenChange,
|
|
747
|
+
isMulti,
|
|
748
|
+
maxCount,
|
|
749
|
+
onDeselect,
|
|
750
|
+
onSelect,
|
|
751
|
+
setSearchValue,
|
|
752
|
+
valueOptionMap,
|
|
753
|
+
],
|
|
754
|
+
)
|
|
755
|
+
|
|
756
|
+
const handleRemoveTag = React.useCallback(
|
|
757
|
+
(v: RawValue) => {
|
|
758
|
+
if (disabled || readOnly) return
|
|
759
|
+
const next = currentValues.filter((x) => x !== v)
|
|
760
|
+
const nextOptions = next.map(
|
|
761
|
+
(x) => (valueOptionMap.get(x) ?? { [fields.value]: x }) as SelectOptionType,
|
|
762
|
+
)
|
|
763
|
+
fireChange(next, nextOptions)
|
|
764
|
+
onDeselect?.(v)
|
|
765
|
+
},
|
|
766
|
+
[currentValues, disabled, fields.value, fireChange, onDeselect, readOnly, valueOptionMap],
|
|
767
|
+
)
|
|
768
|
+
|
|
769
|
+
const handleClear = React.useCallback(
|
|
770
|
+
(e: React.MouseEvent<HTMLElement>) => {
|
|
771
|
+
e.stopPropagation()
|
|
772
|
+
if (disabled || readOnly) return
|
|
773
|
+
const empty = isMulti ? ([] as RawValue[]) : undefined
|
|
774
|
+
fireChange(empty, isMulti ? [] : undefined)
|
|
775
|
+
setSearchValue('')
|
|
776
|
+
onClear?.()
|
|
777
|
+
},
|
|
778
|
+
[disabled, readOnly, fireChange, isMulti, onClear, setSearchValue],
|
|
779
|
+
)
|
|
780
|
+
|
|
781
|
+
const removeValue = React.useCallback(
|
|
782
|
+
(v: RawValue) => {
|
|
783
|
+
if (isMulti) {
|
|
784
|
+
handleRemoveTag(v)
|
|
785
|
+
return
|
|
786
|
+
}
|
|
787
|
+
fireChange(undefined, undefined)
|
|
788
|
+
setSearchValue('')
|
|
789
|
+
onDeselect?.(v)
|
|
790
|
+
},
|
|
791
|
+
[fireChange, handleRemoveTag, isMulti, onDeselect, setSearchValue],
|
|
792
|
+
)
|
|
793
|
+
|
|
794
|
+
// ── Keyboard navigation ────────────────────────────────────────────────────
|
|
795
|
+
const setKeyboardActiveIndex = React.useCallback((index: number) => {
|
|
796
|
+
suppressFirstActivationRef.current = false
|
|
797
|
+
setActiveIndex(index)
|
|
798
|
+
scrollToIndexRef.current?.(index)
|
|
799
|
+
}, [])
|
|
800
|
+
|
|
801
|
+
const handleKeyDown = (e: React.KeyboardEvent<HTMLElement>) => {
|
|
802
|
+
onInputKeyDown?.(e as React.KeyboardEvent<HTMLElement>)
|
|
803
|
+
if (disabled || readOnly || e.defaultPrevented) return
|
|
804
|
+
if (composingRef.current || e.nativeEvent.isComposing || e.keyCode === 229) {
|
|
805
|
+
if (e.key === 'Enter') e.preventDefault()
|
|
806
|
+
return
|
|
807
|
+
}
|
|
808
|
+
|
|
809
|
+
const idxInSel = selectableIndexes.indexOf(activeIndex)
|
|
810
|
+
const searchEmpty = search.trim() === ''
|
|
811
|
+
|
|
812
|
+
switch (e.key) {
|
|
813
|
+
case 'ArrowDown': {
|
|
814
|
+
e.preventDefault()
|
|
815
|
+
if (!isOpen) {
|
|
816
|
+
suppressFirstActivationRef.current = false
|
|
817
|
+
handleOpenChange(true)
|
|
818
|
+
return
|
|
819
|
+
}
|
|
820
|
+
if (selectableIndexes.length === 0) return
|
|
821
|
+
const next =
|
|
822
|
+
idxInSel < 0
|
|
823
|
+
? selectableIndexes[0]
|
|
824
|
+
: selectableIndexes[(idxInSel + 1) % selectableIndexes.length]
|
|
825
|
+
setKeyboardActiveIndex(next)
|
|
826
|
+
const opt = filteredOptions[next]
|
|
827
|
+
if (opt) onActive?.((opt as Record<string, unknown>)[fields.value] as RawValue)
|
|
828
|
+
break
|
|
829
|
+
}
|
|
830
|
+
case 'ArrowUp': {
|
|
831
|
+
e.preventDefault()
|
|
832
|
+
if (!isOpen) {
|
|
833
|
+
suppressFirstActivationRef.current = false
|
|
834
|
+
handleOpenChange(true)
|
|
835
|
+
return
|
|
836
|
+
}
|
|
837
|
+
if (selectableIndexes.length === 0) return
|
|
838
|
+
const next =
|
|
839
|
+
idxInSel < 0
|
|
840
|
+
? selectableIndexes[selectableIndexes.length - 1]
|
|
841
|
+
: selectableIndexes[
|
|
842
|
+
(idxInSel - 1 + selectableIndexes.length) % selectableIndexes.length
|
|
843
|
+
]
|
|
844
|
+
setKeyboardActiveIndex(next)
|
|
845
|
+
const opt = filteredOptions[next]
|
|
846
|
+
if (opt) onActive?.((opt as Record<string, unknown>)[fields.value] as RawValue)
|
|
847
|
+
break
|
|
848
|
+
}
|
|
849
|
+
case 'Enter': {
|
|
850
|
+
if (!isOpen) {
|
|
851
|
+
e.preventDefault()
|
|
852
|
+
suppressFirstActivationRef.current = false
|
|
853
|
+
handleOpenChange(true)
|
|
854
|
+
return
|
|
855
|
+
}
|
|
856
|
+
if (activeIndex >= 0 && selectableIndexes.includes(activeIndex)) {
|
|
857
|
+
e.preventDefault()
|
|
858
|
+
handleSelectOption(filteredOptions[activeIndex], activeIndex)
|
|
859
|
+
} else if (mode === 'tags' && search.trim() !== '') {
|
|
860
|
+
// tags mode: create a new tag from the current search value when no
|
|
861
|
+
// existing option is active (no match highlighted).
|
|
862
|
+
e.preventDefault()
|
|
863
|
+
const newValue = search.trim() as RawValue
|
|
864
|
+
if (!currentValues.includes(newValue)) {
|
|
865
|
+
const newValues = [...currentValues, newValue]
|
|
866
|
+
const newOptions = newValues.map((v) => ({ value: v, label: v }))
|
|
867
|
+
fireChange(newValues, newOptions)
|
|
868
|
+
}
|
|
869
|
+
setSearchValue('')
|
|
870
|
+
}
|
|
871
|
+
break
|
|
872
|
+
}
|
|
873
|
+
case 'Escape': {
|
|
874
|
+
if (isOpen) {
|
|
875
|
+
e.preventDefault()
|
|
876
|
+
handleOpenChange(false)
|
|
877
|
+
}
|
|
878
|
+
break
|
|
879
|
+
}
|
|
880
|
+
case 'Backspace': {
|
|
881
|
+
if (!searchEmpty) break
|
|
882
|
+
|
|
883
|
+
if (isMulti) {
|
|
884
|
+
if (currentValues.length === 0) break
|
|
885
|
+
|
|
886
|
+
// 下拉打开且键盘高亮在某项上:若该项已选中则取消该项(否则删最后一个 tag)
|
|
887
|
+
if (isOpen && activeIndex >= 0 && selectableIndexes.includes(activeIndex)) {
|
|
888
|
+
const opt = filteredOptions[activeIndex]
|
|
889
|
+
const v = (opt as Record<string, unknown>)[fields.value] as RawValue | undefined
|
|
890
|
+
if (v !== undefined && currentValues.includes(v)) {
|
|
891
|
+
e.preventDefault()
|
|
892
|
+
removeValue(v)
|
|
893
|
+
break
|
|
894
|
+
}
|
|
895
|
+
}
|
|
896
|
+
|
|
897
|
+
e.preventDefault()
|
|
898
|
+
removeValue(currentValues[currentValues.length - 1])
|
|
899
|
+
break
|
|
900
|
+
}
|
|
901
|
+
|
|
902
|
+
if (hasSelection) {
|
|
903
|
+
e.preventDefault()
|
|
904
|
+
removeValue(currentValues[0])
|
|
905
|
+
}
|
|
906
|
+
break
|
|
907
|
+
}
|
|
908
|
+
case 'Tab': {
|
|
909
|
+
if (isOpen) handleOpenChange(false)
|
|
910
|
+
break
|
|
911
|
+
}
|
|
912
|
+
}
|
|
913
|
+
}
|
|
914
|
+
|
|
915
|
+
// ── Render helpers ─────────────────────────────────────────────────────────
|
|
916
|
+
const resolvedClassNames =
|
|
917
|
+
typeof classNames === 'function'
|
|
918
|
+
? classNames({ props: { ...restProps } as unknown as Readonly<SelectProps> })
|
|
919
|
+
: classNames
|
|
920
|
+
const resolvedStyles =
|
|
921
|
+
typeof styles === 'function'
|
|
922
|
+
? styles({ props: { ...restProps } as unknown as Readonly<SelectProps> })
|
|
923
|
+
: styles
|
|
924
|
+
|
|
925
|
+
const allowClearObj: SelectAllowClear | null =
|
|
926
|
+
allowClear === true ? {} : allowClear && typeof allowClear === 'object' ? allowClear : null
|
|
927
|
+
const showClear =
|
|
928
|
+
allowClearObj !== null && !disabled && !readOnly && (hasSelection || search.length > 0)
|
|
929
|
+
|
|
930
|
+
// 单选时的显示文案 — 使用 optionLabelProp 指定的字段(默认 'label')
|
|
931
|
+
const singleLabel: React.ReactNode = React.useMemo(() => {
|
|
932
|
+
if (isMulti || !hasSelection) return null
|
|
933
|
+
const v = currentValues[0]
|
|
934
|
+
const opt = valueOptionMap.get(v)
|
|
935
|
+
if (labelRender) {
|
|
936
|
+
return labelRender({ value: v, label: opt?.[fields.label] as React.ReactNode })
|
|
937
|
+
}
|
|
938
|
+
return (
|
|
939
|
+
(opt?.[optionLabelProp] as React.ReactNode) ??
|
|
940
|
+
(opt?.[fields.label] as React.ReactNode) ??
|
|
941
|
+
String(v)
|
|
942
|
+
)
|
|
943
|
+
}, [
|
|
944
|
+
currentValues,
|
|
945
|
+
fields.label,
|
|
946
|
+
hasSelection,
|
|
947
|
+
isMulti,
|
|
948
|
+
labelRender,
|
|
949
|
+
optionLabelProp,
|
|
950
|
+
valueOptionMap,
|
|
951
|
+
])
|
|
952
|
+
|
|
953
|
+
const selectionContent = React.useMemo(() => {
|
|
954
|
+
if (!hasSelection || isMulti) return null
|
|
955
|
+
if (labelRender) return singleLabel
|
|
956
|
+
return (
|
|
957
|
+
<Typography.Text ellipsis={{ tooltip: true }} className={`${prefixCls}__option-label`}>
|
|
958
|
+
{singleLabel}
|
|
959
|
+
</Typography.Text>
|
|
960
|
+
)
|
|
961
|
+
}, [hasSelection, isMulti, labelRender, singleLabel])
|
|
962
|
+
|
|
963
|
+
// selector 点击:打开下拉,并把焦点交给 input(若 showSearch)
|
|
964
|
+
const handleSelectorClick = () => {
|
|
965
|
+
if (disabled || readOnly) return
|
|
966
|
+
if (!isOpen) {
|
|
967
|
+
suppressFirstActivationRef.current = true
|
|
968
|
+
setActiveIndex(-1)
|
|
969
|
+
}
|
|
970
|
+
if (effectiveShowSearch) {
|
|
971
|
+
// 点击时确保 input 拿到焦点
|
|
972
|
+
requestAnimationFrame(() => inputRef.current?.focus())
|
|
973
|
+
}
|
|
974
|
+
handleOpenChange(!isOpen)
|
|
975
|
+
}
|
|
976
|
+
|
|
977
|
+
const placeholderText =
|
|
978
|
+
typeof resolvedPlaceholder === 'string' || typeof resolvedPlaceholder === 'number'
|
|
979
|
+
? String(resolvedPlaceholder)
|
|
980
|
+
: undefined
|
|
981
|
+
|
|
982
|
+
const popper = placementToPopper(placement)
|
|
983
|
+
warnDeprecatedGetPopupContainer(getPopupContainer)
|
|
984
|
+
|
|
985
|
+
const popupOverlay = useAnchoredOverlay({
|
|
986
|
+
open: isOpen,
|
|
987
|
+
onOpenChange: handleOpenChange,
|
|
988
|
+
referenceElement: triggerRef.current,
|
|
989
|
+
closeWhenReferenceHidden: true,
|
|
990
|
+
closeOnScroll,
|
|
991
|
+
side: popper.side,
|
|
992
|
+
align: popper.align,
|
|
993
|
+
sideOffset: 4,
|
|
994
|
+
onOpenAutoFocus: (e) => e.preventDefault(),
|
|
995
|
+
onEscapeKeyDown: (e) => {
|
|
996
|
+
if (composingRef.current && e.target === inputRef.current) e.preventDefault()
|
|
997
|
+
},
|
|
998
|
+
onPointerDownOutside: (e) => {
|
|
999
|
+
if (triggerRef.current?.contains(e.target as Node)) e.preventDefault()
|
|
1000
|
+
},
|
|
1001
|
+
onInteractOutside: (e) => {
|
|
1002
|
+
if (triggerRef.current?.contains(e.target as Node)) e.preventDefault()
|
|
1003
|
+
},
|
|
1004
|
+
})
|
|
1005
|
+
|
|
1006
|
+
const renderListItem = React.useCallback(
|
|
1007
|
+
(opt: SelectFlattenOptionData, i: number) => {
|
|
1008
|
+
if (opt.isGroupOption) {
|
|
1009
|
+
return (
|
|
1010
|
+
<div
|
|
1011
|
+
key={getVirtualItemKey(i)}
|
|
1012
|
+
className={`${prefixCls}__group-label`}
|
|
1013
|
+
role="presentation"
|
|
1014
|
+
>
|
|
1015
|
+
<Typography.Text variant="caption" ellipsis={{ tooltip: true }}>
|
|
1016
|
+
{opt.label ??
|
|
1017
|
+
((opt as Record<string, unknown>)[fields.groupLabel] as React.ReactNode)}
|
|
1018
|
+
</Typography.Text>
|
|
1019
|
+
</div>
|
|
1020
|
+
)
|
|
1021
|
+
}
|
|
1022
|
+
const v = (opt as Record<string, unknown>)[fields.value] as RawValue | undefined
|
|
1023
|
+
const selected = v !== undefined && currentValues.includes(v)
|
|
1024
|
+
const highlighted = i === activeIndex
|
|
1025
|
+
const optionLabel = (opt as Record<string, unknown>)[fields.label] as React.ReactNode
|
|
1026
|
+
return (
|
|
1027
|
+
<div
|
|
1028
|
+
key={getVirtualItemKey(i)}
|
|
1029
|
+
role="option"
|
|
1030
|
+
aria-selected={selected}
|
|
1031
|
+
aria-disabled={opt.disabled || undefined}
|
|
1032
|
+
data-highlighted={highlighted || undefined}
|
|
1033
|
+
data-selected={selected || undefined}
|
|
1034
|
+
data-disabled={opt.disabled || undefined}
|
|
1035
|
+
data-level={opt.level}
|
|
1036
|
+
title={opt.title}
|
|
1037
|
+
className={cn(selectOptionVariants(), opt.className, resolvedClassNames?.option)}
|
|
1038
|
+
style={resolvedStyles?.option}
|
|
1039
|
+
onMouseEnter={() => {
|
|
1040
|
+
if (!opt.disabled) setActiveIndex(i)
|
|
1041
|
+
}}
|
|
1042
|
+
onPointerDown={(event) => {
|
|
1043
|
+
if (event.pointerType === 'mouse' && event.button !== 0) return
|
|
1044
|
+
event.preventDefault()
|
|
1045
|
+
handleSelectOption(opt, i)
|
|
1046
|
+
}}
|
|
1047
|
+
>
|
|
1048
|
+
{optionRender ? (
|
|
1049
|
+
optionRender(opt, { index: i })
|
|
1050
|
+
) : (
|
|
1051
|
+
<>
|
|
1052
|
+
<Typography.Text
|
|
1053
|
+
ellipsis={{ tooltip: true }}
|
|
1054
|
+
className={`${prefixCls}__option-label`}
|
|
1055
|
+
>
|
|
1056
|
+
{optionLabel}
|
|
1057
|
+
</Typography.Text>
|
|
1058
|
+
{selected && isMulti ? (
|
|
1059
|
+
<span
|
|
1060
|
+
className="apex-dropdown__check"
|
|
1061
|
+
data-slot="select-option-check"
|
|
1062
|
+
aria-hidden="true"
|
|
1063
|
+
>
|
|
1064
|
+
<SelectSelectedCheckIcon />
|
|
1065
|
+
</span>
|
|
1066
|
+
) : null}
|
|
1067
|
+
</>
|
|
1068
|
+
)}
|
|
1069
|
+
</div>
|
|
1070
|
+
)
|
|
1071
|
+
},
|
|
1072
|
+
[
|
|
1073
|
+
activeIndex,
|
|
1074
|
+
currentValues,
|
|
1075
|
+
fields.groupLabel,
|
|
1076
|
+
fields.label,
|
|
1077
|
+
fields.value,
|
|
1078
|
+
getVirtualItemKey,
|
|
1079
|
+
handleSelectOption,
|
|
1080
|
+
isMulti,
|
|
1081
|
+
optionRender,
|
|
1082
|
+
resolvedClassNames?.option,
|
|
1083
|
+
resolvedStyles?.option,
|
|
1084
|
+
],
|
|
1085
|
+
)
|
|
1086
|
+
|
|
1087
|
+
return (
|
|
1088
|
+
<div
|
|
1089
|
+
data-slot="select"
|
|
1090
|
+
data-variant={resolveInputVariant(variant)}
|
|
1091
|
+
className={cn(
|
|
1092
|
+
prefixCls,
|
|
1093
|
+
'apex-input',
|
|
1094
|
+
resolveInputVariantClass(variant),
|
|
1095
|
+
resolveInputSizeClass(size),
|
|
1096
|
+
className,
|
|
1097
|
+
resolvedClassNames?.root,
|
|
1098
|
+
)}
|
|
1099
|
+
style={{ ...resolvedStyles?.root, ...style }}
|
|
1100
|
+
{...(restProps as React.HTMLAttributes<HTMLDivElement>)}
|
|
1101
|
+
>
|
|
1102
|
+
<div
|
|
1103
|
+
ref={setTriggerRef}
|
|
1104
|
+
data-slot="selector"
|
|
1105
|
+
data-state={isOpen ? 'open' : 'closed'}
|
|
1106
|
+
data-disabled={disabled || undefined}
|
|
1107
|
+
data-readonly={readOnly || undefined}
|
|
1108
|
+
data-status={status || undefined}
|
|
1109
|
+
data-mode={mode || undefined}
|
|
1110
|
+
data-size={size}
|
|
1111
|
+
data-variant={resolveInputVariant(variant)}
|
|
1112
|
+
className={cn(
|
|
1113
|
+
selectSelectorVariants({ size, variant: resolveInputVariant(variant) }),
|
|
1114
|
+
resolvedClassNames?.selector,
|
|
1115
|
+
)}
|
|
1116
|
+
style={resolvedStyles?.selector}
|
|
1117
|
+
role="combobox"
|
|
1118
|
+
aria-expanded={isOpen}
|
|
1119
|
+
aria-disabled={disabled || undefined}
|
|
1120
|
+
aria-readonly={readOnly || undefined}
|
|
1121
|
+
aria-haspopup="listbox"
|
|
1122
|
+
tabIndex={effectiveShowSearch ? -1 : disabled ? -1 : 0}
|
|
1123
|
+
onClick={handleSelectorClick}
|
|
1124
|
+
onKeyDown={effectiveShowSearch ? undefined : handleKeyDown}
|
|
1125
|
+
onFocus={onFocus}
|
|
1126
|
+
onBlur={onBlur}
|
|
1127
|
+
>
|
|
1128
|
+
{/* 视觉壳:边框 / 填充 / 内边距 / 状态。尺寸由外层 .apex-input 容器决定。
|
|
1129
|
+
data-status / data-disabled / data-readonly 同步到此层,复用 input.css 的 .apex-input__inner 状态样式;
|
|
1130
|
+
展开态(data-state='open')由 select.css 映射到本层的 focused 视觉。 */}
|
|
1131
|
+
<div
|
|
1132
|
+
className={`${prefixCls}__inner apex-input__inner`}
|
|
1133
|
+
data-status={status || undefined}
|
|
1134
|
+
data-disabled={disabled || undefined}
|
|
1135
|
+
data-readonly={readOnly || undefined}
|
|
1136
|
+
>
|
|
1137
|
+
{prefix ? (
|
|
1138
|
+
<span
|
|
1139
|
+
className={cn(`${prefixCls}__prefix`, resolvedClassNames?.prefix)}
|
|
1140
|
+
style={resolvedStyles?.prefix}
|
|
1141
|
+
>
|
|
1142
|
+
{prefix}
|
|
1143
|
+
</span>
|
|
1144
|
+
) : null}
|
|
1145
|
+
|
|
1146
|
+
{isMulti ? (
|
|
1147
|
+
<MaxTagList
|
|
1148
|
+
className={`${prefixCls}__tags`}
|
|
1149
|
+
values={currentValues}
|
|
1150
|
+
getKey={(v) => String(v)}
|
|
1151
|
+
getLabel={(v) => {
|
|
1152
|
+
const opt = valueOptionMap.get(v)
|
|
1153
|
+
return (opt?.[fields.label] as React.ReactNode) ?? String(v)
|
|
1154
|
+
}}
|
|
1155
|
+
maxTagCount={maxTagCount}
|
|
1156
|
+
maxTagPlaceholder={maxTagPlaceholder}
|
|
1157
|
+
maxTagPopover={maxTagPopover}
|
|
1158
|
+
tagSize={resolveInputTagSize(size)}
|
|
1159
|
+
tagRender={
|
|
1160
|
+
tagRender
|
|
1161
|
+
? (props) =>
|
|
1162
|
+
tagRender({
|
|
1163
|
+
...props,
|
|
1164
|
+
disabled: Boolean(valueOptionMap.get(props.value)?.disabled) || disabled,
|
|
1165
|
+
closable: !props.disabled && !readOnly,
|
|
1166
|
+
onClose:
|
|
1167
|
+
readOnly || props.disabled
|
|
1168
|
+
? undefined
|
|
1169
|
+
: () => handleRemoveTag(props.value),
|
|
1170
|
+
})
|
|
1171
|
+
: undefined
|
|
1172
|
+
}
|
|
1173
|
+
disabled={disabled}
|
|
1174
|
+
readOnly={readOnly}
|
|
1175
|
+
onRemoveTag={handleRemoveTag}
|
|
1176
|
+
closeIcon={removeIcon}
|
|
1177
|
+
isTagDisabled={(v) => Boolean(valueOptionMap.get(v)?.disabled)}
|
|
1178
|
+
reserveSearchWidth={effectiveShowSearch}
|
|
1179
|
+
>
|
|
1180
|
+
{effectiveShowSearch ? (
|
|
1181
|
+
<input
|
|
1182
|
+
ref={inputRef}
|
|
1183
|
+
className={cn(
|
|
1184
|
+
`${prefixCls}__search`,
|
|
1185
|
+
shouldHideEmptyMultiSearch && `${prefixCls}__search--hidden`,
|
|
1186
|
+
)}
|
|
1187
|
+
value={search}
|
|
1188
|
+
disabled={disabled}
|
|
1189
|
+
readOnly={readOnly}
|
|
1190
|
+
placeholder={currentValues.length === 0 ? placeholderText : undefined}
|
|
1191
|
+
onChange={(e) => {
|
|
1192
|
+
if (readOnly) return
|
|
1193
|
+
if (!isOpen) handleOpenChange(true)
|
|
1194
|
+
handleSearchChange(e.target.value)
|
|
1195
|
+
}}
|
|
1196
|
+
onKeyDown={handleKeyDown}
|
|
1197
|
+
onCompositionStart={() => {
|
|
1198
|
+
composingRef.current = true
|
|
1199
|
+
setIsComposing(true)
|
|
1200
|
+
}}
|
|
1201
|
+
onCompositionEnd={() => {
|
|
1202
|
+
composingRef.current = false
|
|
1203
|
+
setIsComposing(false)
|
|
1204
|
+
}}
|
|
1205
|
+
autoComplete="off"
|
|
1206
|
+
aria-autocomplete="list"
|
|
1207
|
+
aria-controls={isOpen ? `${prefixCls}-listbox` : undefined}
|
|
1208
|
+
/>
|
|
1209
|
+
) : currentValues.length === 0 ? (
|
|
1210
|
+
<span
|
|
1211
|
+
className={cn(`${prefixCls}__placeholder`, resolvedClassNames?.placeholder)}
|
|
1212
|
+
style={resolvedStyles?.placeholder}
|
|
1213
|
+
>
|
|
1214
|
+
{resolvedPlaceholder}
|
|
1215
|
+
</span>
|
|
1216
|
+
) : null}
|
|
1217
|
+
</MaxTagList>
|
|
1218
|
+
) : effectiveShowSearch ? (
|
|
1219
|
+
<>
|
|
1220
|
+
{/* 单选 + 可搜索:未打开时显示选中文案;打开后由 input 占位接管 */}
|
|
1221
|
+
{!isOpen && hasSelection ? (
|
|
1222
|
+
<span
|
|
1223
|
+
className={cn(`${prefixCls}__selection`, resolvedClassNames?.selection)}
|
|
1224
|
+
data-selected={hasSelection || undefined}
|
|
1225
|
+
style={resolvedStyles?.selection}
|
|
1226
|
+
>
|
|
1227
|
+
{selectionContent}
|
|
1228
|
+
</span>
|
|
1229
|
+
) : null}
|
|
1230
|
+
<input
|
|
1231
|
+
ref={inputRef}
|
|
1232
|
+
className={cn(
|
|
1233
|
+
`${prefixCls}__search`,
|
|
1234
|
+
// C18: 单选+搜索+已选+关闭态时隐藏 input(CSS class 代替原 inline style hack)
|
|
1235
|
+
!isOpen && hasSelection && `${prefixCls}__search--hidden`,
|
|
1236
|
+
)}
|
|
1237
|
+
value={isOpen ? search : ''}
|
|
1238
|
+
disabled={disabled}
|
|
1239
|
+
readOnly={readOnly}
|
|
1240
|
+
placeholder={
|
|
1241
|
+
!isOpen && hasSelection
|
|
1242
|
+
? undefined
|
|
1243
|
+
: hasSelection && isOpen
|
|
1244
|
+
? typeof singleLabel === 'string'
|
|
1245
|
+
? singleLabel
|
|
1246
|
+
: placeholderText
|
|
1247
|
+
: placeholderText
|
|
1248
|
+
}
|
|
1249
|
+
onChange={(e) => {
|
|
1250
|
+
if (readOnly) return
|
|
1251
|
+
if (!isOpen) handleOpenChange(true)
|
|
1252
|
+
handleSearchChange(e.target.value)
|
|
1253
|
+
}}
|
|
1254
|
+
onKeyDown={handleKeyDown}
|
|
1255
|
+
onCompositionStart={() => {
|
|
1256
|
+
composingRef.current = true
|
|
1257
|
+
}}
|
|
1258
|
+
onCompositionEnd={() => {
|
|
1259
|
+
composingRef.current = false
|
|
1260
|
+
}}
|
|
1261
|
+
autoComplete="off"
|
|
1262
|
+
aria-autocomplete="list"
|
|
1263
|
+
aria-controls={isOpen ? `${prefixCls}-listbox` : undefined}
|
|
1264
|
+
/>
|
|
1265
|
+
</>
|
|
1266
|
+
) : hasSelection ? (
|
|
1267
|
+
<span
|
|
1268
|
+
className={cn(`${prefixCls}__selection`, resolvedClassNames?.selection)}
|
|
1269
|
+
data-selected={hasSelection || undefined}
|
|
1270
|
+
style={resolvedStyles?.selection}
|
|
1271
|
+
>
|
|
1272
|
+
{selectionContent}
|
|
1273
|
+
</span>
|
|
1274
|
+
) : (
|
|
1275
|
+
<span
|
|
1276
|
+
className={cn(`${prefixCls}__placeholder`, resolvedClassNames?.placeholder)}
|
|
1277
|
+
style={resolvedStyles?.placeholder}
|
|
1278
|
+
>
|
|
1279
|
+
{resolvedPlaceholder}
|
|
1280
|
+
</span>
|
|
1281
|
+
)}
|
|
1282
|
+
|
|
1283
|
+
{showClear ? (
|
|
1284
|
+
<Clear
|
|
1285
|
+
className={resolvedClassNames?.clear}
|
|
1286
|
+
style={resolvedStyles?.clear}
|
|
1287
|
+
data-slot="input-clear"
|
|
1288
|
+
icon={allowClearObj?.clearIcon}
|
|
1289
|
+
onClick={handleClear}
|
|
1290
|
+
/>
|
|
1291
|
+
) : null}
|
|
1292
|
+
|
|
1293
|
+
{!readOnly ? (
|
|
1294
|
+
<span
|
|
1295
|
+
className={cn(`${prefixCls}__suffix`, resolvedClassNames?.suffix)}
|
|
1296
|
+
data-disabled={disabled || undefined}
|
|
1297
|
+
aria-disabled={disabled || undefined}
|
|
1298
|
+
style={resolvedStyles?.suffix}
|
|
1299
|
+
aria-hidden="true"
|
|
1300
|
+
>
|
|
1301
|
+
{suffixIcon ?? <SelectCaretDownIcon />}
|
|
1302
|
+
</span>
|
|
1303
|
+
) : null}
|
|
1304
|
+
</div>
|
|
1305
|
+
</div>
|
|
1306
|
+
|
|
1307
|
+
<AnchoredOverlayContent
|
|
1308
|
+
overlay={popupOverlay}
|
|
1309
|
+
overlayKind="select"
|
|
1310
|
+
data-slot="popup"
|
|
1311
|
+
className={cn(selectPopupVariants({ size }), resolvedClassNames?.popup)}
|
|
1312
|
+
onWheel={(e) => e.stopPropagation()}
|
|
1313
|
+
onTouchMove={(e) => e.stopPropagation()}
|
|
1314
|
+
style={{
|
|
1315
|
+
...resolvedStyles?.popup,
|
|
1316
|
+
pointerEvents: 'auto',
|
|
1317
|
+
}}
|
|
1318
|
+
>
|
|
1319
|
+
<div
|
|
1320
|
+
ref={setListRef}
|
|
1321
|
+
id={`${prefixCls}-listbox`}
|
|
1322
|
+
data-slot="list"
|
|
1323
|
+
data-virtual={useVirtualList || undefined}
|
|
1324
|
+
role="listbox"
|
|
1325
|
+
aria-multiselectable={isMulti || undefined}
|
|
1326
|
+
className={cn(selectListVariants(), resolvedClassNames?.list)}
|
|
1327
|
+
style={{
|
|
1328
|
+
...resolvedStyles?.list,
|
|
1329
|
+
...(useVirtualList ? { maxHeight: listHeight } : undefined),
|
|
1330
|
+
}}
|
|
1331
|
+
onScroll={onPopupScroll}
|
|
1332
|
+
>
|
|
1333
|
+
{filteredOptions.length === 0 ? (
|
|
1334
|
+
<div className={`${prefixCls}__empty`}>{resolvedNotFoundContent}</div>
|
|
1335
|
+
) : useVirtualList ? (
|
|
1336
|
+
<SelectVirtualList
|
|
1337
|
+
key={listElement ? 'ready' : 'pending'}
|
|
1338
|
+
options={filteredOptions}
|
|
1339
|
+
scrollElement={listElement}
|
|
1340
|
+
scrollToIndexRef={scrollToIndexRef}
|
|
1341
|
+
estimateSize={virtualConfig.estimateSize}
|
|
1342
|
+
overscan={virtualConfig.overscan}
|
|
1343
|
+
getItemKey={getVirtualItemKey}
|
|
1344
|
+
renderItem={(option, index, measureRef) => (
|
|
1345
|
+
<div
|
|
1346
|
+
key={getVirtualItemKey(index)}
|
|
1347
|
+
data-index={index}
|
|
1348
|
+
ref={measureRef}
|
|
1349
|
+
className={`${prefixCls}__virtual-item`}
|
|
1350
|
+
>
|
|
1351
|
+
{renderListItem(option, index)}
|
|
1352
|
+
</div>
|
|
1353
|
+
)}
|
|
1354
|
+
/>
|
|
1355
|
+
) : (
|
|
1356
|
+
filteredOptions.map((opt, i) => renderListItem(opt, i))
|
|
1357
|
+
)}
|
|
1358
|
+
</div>
|
|
1359
|
+
</AnchoredOverlayContent>
|
|
1360
|
+
</div>
|
|
1361
|
+
)
|
|
1362
|
+
}
|
|
1363
|
+
|
|
1364
|
+
Select.displayName = 'ApexSelect'
|
|
1365
|
+
|
|
1366
|
+
export default Select
|