willa-workspace 0.0.3-alpha.2739b3e
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/.github/workflows/deploy.yml +45 -0
- package/.husky/pre-commit +1 -0
- package/AGENTS.md +128 -0
- package/CONTRIBUTING.md +138 -0
- package/README.md +27 -0
- package/docs/architecture.md +337 -0
- package/docs/component.md +333 -0
- package/docs/css.md +400 -0
- package/docs/style.md +146 -0
- package/example/index.html +12 -0
- package/example/package.json +28 -0
- package/example/src/App.tsx +613 -0
- package/example/src/UsageGuide.tsx +179 -0
- package/example/src/catalog/DocView.tsx +413 -0
- package/example/src/catalog/defineDoc.tsx +352 -0
- package/example/src/catalog/registry.ts +206 -0
- package/example/src/catalog/types.ts +38 -0
- package/example/src/docs/Alert.demo.tsx +233 -0
- package/example/src/docs/Anchor.demo.tsx +244 -0
- package/example/src/docs/AppShell.demo.tsx +192 -0
- package/example/src/docs/AttachmentList.demo.tsx +425 -0
- package/example/src/docs/AudioEmbed.demo.tsx +102 -0
- package/example/src/docs/AudioLink.demo.tsx +84 -0
- package/example/src/docs/Avatar.demo.tsx +342 -0
- package/example/src/docs/Badge.demo.tsx +196 -0
- package/example/src/docs/BorderBeam.demo.tsx +261 -0
- package/example/src/docs/Breadcrumb.demo.tsx +194 -0
- package/example/src/docs/Button.demo.tsx +304 -0
- package/example/src/docs/Calendar.demo.tsx +742 -0
- package/example/src/docs/Callout.demo.tsx +143 -0
- package/example/src/docs/Card.demo.tsx +254 -0
- package/example/src/docs/Carousel.demo.tsx +764 -0
- package/example/src/docs/ChatMessage.demo.tsx +356 -0
- package/example/src/docs/ChatThread.demo.tsx +107 -0
- package/example/src/docs/Checkbox.demo.tsx +112 -0
- package/example/src/docs/Citation.demo.tsx +297 -0
- package/example/src/docs/CodeBlock.demo.tsx +175 -0
- package/example/src/docs/CodeTabs.demo.tsx +285 -0
- package/example/src/docs/Collapse.demo.tsx +306 -0
- package/example/src/docs/ColorPicker.demo.tsx +491 -0
- package/example/src/docs/Comment.demo.tsx +333 -0
- package/example/src/docs/CommentInput.demo.tsx +894 -0
- package/example/src/docs/CommentList.demo.tsx +344 -0
- package/example/src/docs/Composer.demo.tsx +435 -0
- package/example/src/docs/Container.demo.tsx +125 -0
- package/example/src/docs/ContextPanel.demo.tsx +344 -0
- package/example/src/docs/ContextWindowMeter.demo.tsx +212 -0
- package/example/src/docs/ConversationList.demo.tsx +289 -0
- package/example/src/docs/CopyButton.demo.tsx +274 -0
- package/example/src/docs/DatePicker.demo.tsx +502 -0
- package/example/src/docs/DescriptionList.demo.tsx +265 -0
- package/example/src/docs/Dialog.demo.tsx +492 -0
- package/example/src/docs/DiffViewer.demo.tsx +307 -0
- package/example/src/docs/Download.demo.tsx +182 -0
- package/example/src/docs/Drawer.demo.tsx +300 -0
- package/example/src/docs/EmptyState.demo.tsx +406 -0
- package/example/src/docs/EnglishCards.demo.tsx +133 -0
- package/example/src/docs/FeedbackBar.demo.tsx +219 -0
- package/example/src/docs/FileCard.demo.tsx +234 -0
- package/example/src/docs/FilePreview.demo.tsx +333 -0
- package/example/src/docs/FileTree.demo.tsx +463 -0
- package/example/src/docs/FilterBar.demo.tsx +290 -0
- package/example/src/docs/FloatButton.demo.tsx +726 -0
- package/example/src/docs/Form.demo.tsx +278 -0
- package/example/src/docs/FormActions.demo.tsx +198 -0
- package/example/src/docs/FormField.demo.tsx +193 -0
- package/example/src/docs/FormGroup.demo.tsx +188 -0
- package/example/src/docs/FormMessage.demo.tsx +158 -0
- package/example/src/docs/GenerationCard.demo.tsx +393 -0
- package/example/src/docs/GitHubMention.demo.tsx +83 -0
- package/example/src/docs/GitHubRepo.demo.tsx +88 -0
- package/example/src/docs/Grid.demo.tsx +218 -0
- package/example/src/docs/Group.demo.tsx +315 -0
- package/example/src/docs/HumanApprovalCard.demo.tsx +275 -0
- package/example/src/docs/IconButton.demo.tsx +354 -0
- package/example/src/docs/Image.demo.tsx +124 -0
- package/example/src/docs/ImageGallery.demo.tsx +206 -0
- package/example/src/docs/Input.demo.tsx +238 -0
- package/example/src/docs/InputPanel.demo.tsx +255 -0
- package/example/src/docs/Kbd.demo.tsx +162 -0
- package/example/src/docs/Lightbox.demo.tsx +184 -0
- package/example/src/docs/List.demo.tsx +1009 -0
- package/example/src/docs/LogoWall.demo.tsx +178 -0
- package/example/src/docs/Masonry.demo.tsx +170 -0
- package/example/src/docs/MathExpression.demo.tsx +164 -0
- package/example/src/docs/Mdx.demo.tsx +343 -0
- package/example/src/docs/MentionInput.demo.tsx +543 -0
- package/example/src/docs/Menu.demo.tsx +430 -0
- package/example/src/docs/MessageActions.demo.tsx +355 -0
- package/example/src/docs/MessageList.demo.tsx +410 -0
- package/example/src/docs/ModelSelector.demo.tsx +297 -0
- package/example/src/docs/NumberInput.demo.tsx +816 -0
- package/example/src/docs/PageHeader.demo.tsx +198 -0
- package/example/src/docs/Pagination.demo.tsx +257 -0
- package/example/src/docs/Panel.demo.tsx +184 -0
- package/example/src/docs/Picker.demo.tsx +257 -0
- package/example/src/docs/Poem.demo.tsx +98 -0
- package/example/src/docs/Popover.demo.tsx +362 -0
- package/example/src/docs/ProfileCard.demo.tsx +161 -0
- package/example/src/docs/Progress.demo.tsx +243 -0
- package/example/src/docs/PromptInput.demo.tsx +497 -0
- package/example/src/docs/PromptTemplatePicker.demo.tsx +344 -0
- package/example/src/docs/QRCode.demo.tsx +364 -0
- package/example/src/docs/Radio.demo.tsx +120 -0
- package/example/src/docs/RangeInput.demo.tsx +405 -0
- package/example/src/docs/Rate.demo.tsx +396 -0
- package/example/src/docs/ReasoningSteps.demo.tsx +470 -0
- package/example/src/docs/Result.demo.tsx +121 -0
- package/example/src/docs/ScheduleCalendar.demo.tsx +459 -0
- package/example/src/docs/SearchInput.demo.tsx +217 -0
- package/example/src/docs/SectionHeader.demo.tsx +186 -0
- package/example/src/docs/Segmented.demo.tsx +598 -0
- package/example/src/docs/Select.demo.tsx +164 -0
- package/example/src/docs/SelectionBar.demo.tsx +315 -0
- package/example/src/docs/Separator.demo.tsx +179 -0
- package/example/src/docs/SidebarLayout.demo.tsx +183 -0
- package/example/src/docs/SiteFooter.demo.tsx +189 -0
- package/example/src/docs/SiteNav.demo.tsx +168 -0
- package/example/src/docs/Skeleton.demo.tsx +154 -0
- package/example/src/docs/SourceCard.demo.tsx +241 -0
- package/example/src/docs/Spinner.demo.tsx +166 -0
- package/example/src/docs/SplitPane.demo.tsx +544 -0
- package/example/src/docs/Stack.demo.tsx +135 -0
- package/example/src/docs/Statistic.demo.tsx +124 -0
- package/example/src/docs/Steps.demo.tsx +88 -0
- package/example/src/docs/SuggestionChips.demo.tsx +259 -0
- package/example/src/docs/Switch.demo.tsx +110 -0
- package/example/src/docs/Table.demo.tsx +2071 -0
- package/example/src/docs/Tabs.demo.tsx +285 -0
- package/example/src/docs/Tag.demo.tsx +264 -0
- package/example/src/docs/TagInput.demo.tsx +385 -0
- package/example/src/docs/TextArea.demo.tsx +185 -0
- package/example/src/docs/ThinkingIndicator.demo.tsx +248 -0
- package/example/src/docs/TimePicker.demo.tsx +464 -0
- package/example/src/docs/Timeline.demo.tsx +311 -0
- package/example/src/docs/Toast.demo.tsx +351 -0
- package/example/src/docs/ToolCallCard.demo.tsx +286 -0
- package/example/src/docs/Toolbar.demo.tsx +372 -0
- package/example/src/docs/Tooltip.demo.tsx +274 -0
- package/example/src/docs/Tour.demo.tsx +423 -0
- package/example/src/docs/TraceViewer.demo.tsx +416 -0
- package/example/src/docs/Tree.demo.tsx +507 -0
- package/example/src/docs/TreeSelect.demo.tsx +476 -0
- package/example/src/docs/Typography.demo.tsx +953 -0
- package/example/src/docs/Upload.demo.tsx +299 -0
- package/example/src/docs/VideoEmbed.demo.tsx +108 -0
- package/example/src/docs/VideoLink.demo.tsx +83 -0
- package/example/src/docs/Watermark.demo.tsx +352 -0
- package/example/src/docs/WebEmbed.demo.tsx +96 -0
- package/example/src/docs/XPostEmbed.demo.tsx +57 -0
- package/example/src/main.tsx +36 -0
- package/example/src/styles.css +919 -0
- package/example/src/vite-env.d.ts +1 -0
- package/example/vite.config.ts +11 -0
- package/package.json +40 -0
- package/packages/willa/README.md +47 -0
- package/packages/willa/auklet.config.mjs +23 -0
- package/packages/willa/package.json +83 -0
- package/packages/willa/src/Alert/index.tsx +8 -0
- package/packages/willa/src/Anchor/index.tsx +8 -0
- package/packages/willa/src/AppShell/index.tsx +2 -0
- package/packages/willa/src/AttachmentList/index.tsx +10 -0
- package/packages/willa/src/AudioEmbed/index.tsx +4 -0
- package/packages/willa/src/AudioLink/index.tsx +4 -0
- package/packages/willa/src/Avatar/index.tsx +6 -0
- package/packages/willa/src/Badge/index.tsx +7 -0
- package/packages/willa/src/BorderBeam/index.tsx +6 -0
- package/packages/willa/src/Breadcrumb/index.tsx +6 -0
- package/packages/willa/src/Button/index.tsx +6 -0
- package/packages/willa/src/Calendar/index.tsx +19 -0
- package/packages/willa/src/Callout/index.tsx +5 -0
- package/packages/willa/src/Card/index.tsx +6 -0
- package/packages/willa/src/Carousel/index.tsx +8 -0
- package/packages/willa/src/ChatMessage/index.tsx +6 -0
- package/packages/willa/src/ChatThread/index.tsx +4 -0
- package/packages/willa/src/Checkbox/index.tsx +5 -0
- package/packages/willa/src/Citation/index.tsx +6 -0
- package/packages/willa/src/CodeBlock/index.tsx +5 -0
- package/packages/willa/src/CodeTabs/index.tsx +6 -0
- package/packages/willa/src/Collapse/index.tsx +5 -0
- package/packages/willa/src/ColorPicker/index.tsx +12 -0
- package/packages/willa/src/Comment/index.tsx +6 -0
- package/packages/willa/src/CommentInput/index.tsx +8 -0
- package/packages/willa/src/CommentList/index.tsx +5 -0
- package/packages/willa/src/Composer/index.tsx +1 -0
- package/packages/willa/src/Container/index.tsx +6 -0
- package/packages/willa/src/ContextPanel/index.tsx +7 -0
- package/packages/willa/src/ContextWindowMeter/index.tsx +7 -0
- package/packages/willa/src/ConversationList/index.tsx +8 -0
- package/packages/willa/src/CopyButton/index.tsx +6 -0
- package/packages/willa/src/DatePicker/index.tsx +15 -0
- package/packages/willa/src/DescriptionList/index.tsx +8 -0
- package/packages/willa/src/Dialog/index.tsx +6 -0
- package/packages/willa/src/DiffViewer/index.tsx +5 -0
- package/packages/willa/src/Download/index.tsx +6 -0
- package/packages/willa/src/Drawer/index.tsx +6 -0
- package/packages/willa/src/EmptyState/index.tsx +7 -0
- package/packages/willa/src/EnglishCards/index.tsx +4 -0
- package/packages/willa/src/FeedbackBar/index.tsx +7 -0
- package/packages/willa/src/FileCard/index.tsx +7 -0
- package/packages/willa/src/FilePreview/index.tsx +6 -0
- package/packages/willa/src/FileTree/index.tsx +10 -0
- package/packages/willa/src/FilterBar/index.tsx +7 -0
- package/packages/willa/src/FloatButton/index.tsx +14 -0
- package/packages/willa/src/Form/index.tsx +5 -0
- package/packages/willa/src/FormActions/index.tsx +6 -0
- package/packages/willa/src/FormField/index.tsx +6 -0
- package/packages/willa/src/FormGroup/index.tsx +6 -0
- package/packages/willa/src/FormMessage/index.tsx +5 -0
- package/packages/willa/src/GenerationCard/index.tsx +6 -0
- package/packages/willa/src/GitHubMention/index.tsx +4 -0
- package/packages/willa/src/GitHubRepo/index.tsx +4 -0
- package/packages/willa/src/Grid/index.tsx +8 -0
- package/packages/willa/src/Group/index.tsx +9 -0
- package/packages/willa/src/HumanApprovalCard/index.tsx +8 -0
- package/packages/willa/src/IconButton/index.tsx +7 -0
- package/packages/willa/src/Image/index.tsx +1 -0
- package/packages/willa/src/ImageGallery/index.tsx +5 -0
- package/packages/willa/src/Input/index.tsx +6 -0
- package/packages/willa/src/InputPanel/index.tsx +8 -0
- package/packages/willa/src/Kbd/index.tsx +9 -0
- package/packages/willa/src/Lightbox/index.tsx +7 -0
- package/packages/willa/src/List/index.tsx +10 -0
- package/packages/willa/src/LogoWall/index.tsx +6 -0
- package/packages/willa/src/Masonry/index.tsx +6 -0
- package/packages/willa/src/MathExpression/index.tsx +5 -0
- package/packages/willa/src/Mdx/index.tsx +1 -0
- package/packages/willa/src/MentionInput/index.tsx +5 -0
- package/packages/willa/src/Menu/index.tsx +11 -0
- package/packages/willa/src/MessageActions/index.tsx +8 -0
- package/packages/willa/src/MessageList/index.tsx +4 -0
- package/packages/willa/src/ModelSelector/index.tsx +9 -0
- package/packages/willa/src/NumberInput/index.tsx +15 -0
- package/packages/willa/src/PageHeader/index.tsx +5 -0
- package/packages/willa/src/Pagination/index.tsx +6 -0
- package/packages/willa/src/Panel/index.tsx +6 -0
- package/packages/willa/src/Picker/index.tsx +8 -0
- package/packages/willa/src/Poem/index.tsx +1 -0
- package/packages/willa/src/Popover/index.tsx +7 -0
- package/packages/willa/src/ProfileCard/index.tsx +5 -0
- package/packages/willa/src/Progress/index.tsx +6 -0
- package/packages/willa/src/PromptInput/index.tsx +6 -0
- package/packages/willa/src/PromptTemplatePicker/index.tsx +6 -0
- package/packages/willa/src/QRCode/index.tsx +9 -0
- package/packages/willa/src/Radio/index.tsx +5 -0
- package/packages/willa/src/RangeInput/index.tsx +2 -0
- package/packages/willa/src/Rate/index.tsx +6 -0
- package/packages/willa/src/ReasoningSteps/index.tsx +8 -0
- package/packages/willa/src/ResizablePanel/index.tsx +10 -0
- package/packages/willa/src/Result/index.tsx +7 -0
- package/packages/willa/src/SearchInput/index.tsx +4 -0
- package/packages/willa/src/SectionHeader/index.tsx +6 -0
- package/packages/willa/src/Segmented/index.tsx +9 -0
- package/packages/willa/src/Select/index.tsx +7 -0
- package/packages/willa/src/SelectionBar/index.tsx +5 -0
- package/packages/willa/src/Separator/index.tsx +7 -0
- package/packages/willa/src/SidebarLayout/index.tsx +7 -0
- package/packages/willa/src/SiteFooter/index.tsx +6 -0
- package/packages/willa/src/SiteNav/index.tsx +5 -0
- package/packages/willa/src/Skeleton/index.tsx +4 -0
- package/packages/willa/src/SourceCard/index.tsx +6 -0
- package/packages/willa/src/Spinner/index.tsx +7 -0
- package/packages/willa/src/SplitPane/index.tsx +10 -0
- package/packages/willa/src/Stack/index.tsx +8 -0
- package/packages/willa/src/Statistic/index.tsx +7 -0
- package/packages/willa/src/Step/index.tsx +1 -0
- package/packages/willa/src/Steps/index.tsx +1 -0
- package/packages/willa/src/SuggestionChips/index.tsx +7 -0
- package/packages/willa/src/Switch/index.tsx +5 -0
- package/packages/willa/src/Table/index.tsx +19 -0
- package/packages/willa/src/Tabs/index.tsx +6 -0
- package/packages/willa/src/Tag/index.tsx +9 -0
- package/packages/willa/src/TagInput/index.tsx +8 -0
- package/packages/willa/src/TextArea/index.tsx +7 -0
- package/packages/willa/src/ThinkingIndicator/index.tsx +7 -0
- package/packages/willa/src/TimePicker/index.tsx +10 -0
- package/packages/willa/src/Timeline/index.tsx +8 -0
- package/packages/willa/src/Toast/index.tsx +10 -0
- package/packages/willa/src/ToolCallCard/index.tsx +5 -0
- package/packages/willa/src/Toolbar/index.tsx +6 -0
- package/packages/willa/src/Tooltip/index.tsx +7 -0
- package/packages/willa/src/Tour/index.tsx +10 -0
- package/packages/willa/src/TraceViewer/index.tsx +8 -0
- package/packages/willa/src/Tree/index.tsx +11 -0
- package/packages/willa/src/TreeSelect/index.tsx +8 -0
- package/packages/willa/src/Typography/index.tsx +20 -0
- package/packages/willa/src/Upload/index.tsx +11 -0
- package/packages/willa/src/VideoEmbed/index.tsx +4 -0
- package/packages/willa/src/VideoLink/index.tsx +4 -0
- package/packages/willa/src/Watermark/index.tsx +5 -0
- package/packages/willa/src/WebEmbed/index.tsx +4 -0
- package/packages/willa/src/XPostEmbed/index.tsx +4 -0
- package/packages/willa/src/index.ts +5 -0
- package/packages/willa/vitest.config.ts +9 -0
- package/packages/willa-ai/README.md +32 -0
- package/packages/willa-ai/auklet.config.mjs +25 -0
- package/packages/willa-ai/package.json +84 -0
- package/packages/willa-ai/src/components/AttachmentList/index.css +223 -0
- package/packages/willa-ai/src/components/AttachmentList/index.tsx +256 -0
- package/packages/willa-ai/src/components/ChatMessage/index.css +211 -0
- package/packages/willa-ai/src/components/ChatMessage/index.tsx +126 -0
- package/packages/willa-ai/src/components/Composer/index.css +137 -0
- package/packages/willa-ai/src/components/Composer/index.tsx +92 -0
- package/packages/willa-ai/src/components/ContextPanel/index.css +252 -0
- package/packages/willa-ai/src/components/ContextPanel/index.tsx +513 -0
- package/packages/willa-ai/src/components/ContextWindowMeter/index.css +237 -0
- package/packages/willa-ai/src/components/ContextWindowMeter/index.tsx +266 -0
- package/packages/willa-ai/src/components/ConversationList/index.css +260 -0
- package/packages/willa-ai/src/components/ConversationList/index.tsx +549 -0
- package/packages/willa-ai/src/components/FeedbackBar/index.css +83 -0
- package/packages/willa-ai/src/components/FeedbackBar/index.tsx +357 -0
- package/packages/willa-ai/src/components/GenerationCard/index.css +275 -0
- package/packages/willa-ai/src/components/GenerationCard/index.tsx +156 -0
- package/packages/willa-ai/src/components/HumanApprovalCard/index.css +205 -0
- package/packages/willa-ai/src/components/HumanApprovalCard/index.tsx +262 -0
- package/packages/willa-ai/src/components/MessageActions/index.css +174 -0
- package/packages/willa-ai/src/components/MessageActions/index.tsx +152 -0
- package/packages/willa-ai/src/components/MessageList/index.css +80 -0
- package/packages/willa-ai/src/components/MessageList/index.tsx +96 -0
- package/packages/willa-ai/src/components/ModelSelector/index.css +177 -0
- package/packages/willa-ai/src/components/ModelSelector/index.tsx +421 -0
- package/packages/willa-ai/src/components/PromptInput/index.css +12 -0
- package/packages/willa-ai/src/components/PromptInput/index.tsx +230 -0
- package/packages/willa-ai/src/components/PromptTemplatePicker/index.css +173 -0
- package/packages/willa-ai/src/components/PromptTemplatePicker/index.tsx +389 -0
- package/packages/willa-ai/src/components/ReasoningSteps/index.css +190 -0
- package/packages/willa-ai/src/components/ReasoningSteps/index.tsx +199 -0
- package/packages/willa-ai/src/components/SuggestionChips/index.css +164 -0
- package/packages/willa-ai/src/components/SuggestionChips/index.tsx +142 -0
- package/packages/willa-ai/src/components/ThinkingIndicator/index.css +230 -0
- package/packages/willa-ai/src/components/ThinkingIndicator/index.tsx +162 -0
- package/packages/willa-ai/src/components/ToolCallCard/index.css +244 -0
- package/packages/willa-ai/src/components/ToolCallCard/index.tsx +131 -0
- package/packages/willa-ai/src/components/TraceViewer/index.css +438 -0
- package/packages/willa-ai/src/components/TraceViewer/index.tsx +445 -0
- package/packages/willa-ai/src/index.ts +123 -0
- package/packages/willa-ai/src/internal/cardCollapse.tsx +90 -0
- package/packages/willa-ai/src/internal/searchText.ts +50 -0
- package/packages/willa-ai/src/themes/dark.css +308 -0
- package/packages/willa-ai/src/themes/light.css +303 -0
- package/packages/willa-ai/vitest.config.ts +15 -0
- package/packages/willa-content/README.md +47 -0
- package/packages/willa-content/auklet.config.mjs +25 -0
- package/packages/willa-content/package.json +86 -0
- package/packages/willa-content/src/components/Alert/index.css +158 -0
- package/packages/willa-content/src/components/Alert/index.tsx +182 -0
- package/packages/willa-content/src/components/Anchor/index.css +131 -0
- package/packages/willa-content/src/components/Anchor/index.tsx +253 -0
- package/packages/willa-content/src/components/Avatar/index.css +248 -0
- package/packages/willa-content/src/components/Avatar/index.tsx +331 -0
- package/packages/willa-content/src/components/Badge/index.css +111 -0
- package/packages/willa-content/src/components/Badge/index.tsx +56 -0
- package/packages/willa-content/src/components/Breadcrumb/index.css +92 -0
- package/packages/willa-content/src/components/Breadcrumb/index.tsx +129 -0
- package/packages/willa-content/src/components/Button/index.css +215 -0
- package/packages/willa-content/src/components/Button/index.tsx +295 -0
- package/packages/willa-content/src/components/Callout/index.css +102 -0
- package/packages/willa-content/src/components/Callout/index.tsx +61 -0
- package/packages/willa-content/src/components/Carousel/index.css +236 -0
- package/packages/willa-content/src/components/Carousel/index.tsx +488 -0
- package/packages/willa-content/src/components/ChatThread/index.css +141 -0
- package/packages/willa-content/src/components/ChatThread/index.tsx +118 -0
- package/packages/willa-content/src/components/Citation/index.css +226 -0
- package/packages/willa-content/src/components/Citation/index.tsx +135 -0
- package/packages/willa-content/src/components/CodeBlock/index.css +267 -0
- package/packages/willa-content/src/components/CodeBlock/index.tsx +173 -0
- package/packages/willa-content/src/components/CodeTabs/index.css +116 -0
- package/packages/willa-content/src/components/CodeTabs/index.tsx +88 -0
- package/packages/willa-content/src/components/Collapse/index.css +135 -0
- package/packages/willa-content/src/components/Collapse/index.tsx +108 -0
- package/packages/willa-content/src/components/Comment/index.css +184 -0
- package/packages/willa-content/src/components/Comment/index.tsx +106 -0
- package/packages/willa-content/src/components/CommentInput/index.css +96 -0
- package/packages/willa-content/src/components/CommentInput/index.tsx +84 -0
- package/packages/willa-content/src/components/CommentList/index.css +43 -0
- package/packages/willa-content/src/components/CommentList/index.tsx +79 -0
- package/packages/willa-content/src/components/CopyButton/index.css +26 -0
- package/packages/willa-content/src/components/CopyButton/index.tsx +227 -0
- package/packages/willa-content/src/components/DescriptionList/index.css +176 -0
- package/packages/willa-content/src/components/DescriptionList/index.tsx +96 -0
- package/packages/willa-content/src/components/Dialog/index.css +225 -0
- package/packages/willa-content/src/components/Dialog/index.tsx +303 -0
- package/packages/willa-content/src/components/DiffViewer/index.css +321 -0
- package/packages/willa-content/src/components/DiffViewer/index.tsx +486 -0
- package/packages/willa-content/src/components/Download/index.css +118 -0
- package/packages/willa-content/src/components/Download/index.tsx +96 -0
- package/packages/willa-content/src/components/Drawer/index.css +160 -0
- package/packages/willa-content/src/components/Drawer/index.tsx +323 -0
- package/packages/willa-content/src/components/EmptyState/index.css +220 -0
- package/packages/willa-content/src/components/EmptyState/index.tsx +78 -0
- package/packages/willa-content/src/components/FileCard/fileIcon.tsx +215 -0
- package/packages/willa-content/src/components/FileCard/index.css +242 -0
- package/packages/willa-content/src/components/FileCard/index.tsx +133 -0
- package/packages/willa-content/src/components/FilePreview/index.css +589 -0
- package/packages/willa-content/src/components/FilePreview/index.tsx +750 -0
- package/packages/willa-content/src/components/FileTree/index.css +169 -0
- package/packages/willa-content/src/components/FileTree/index.tsx +341 -0
- package/packages/willa-content/src/components/FloatButton/index.css +276 -0
- package/packages/willa-content/src/components/FloatButton/index.tsx +558 -0
- package/packages/willa-content/src/components/IconButton/index.css +196 -0
- package/packages/willa-content/src/components/IconButton/index.tsx +272 -0
- package/packages/willa-content/src/components/Image/index.css +72 -0
- package/packages/willa-content/src/components/Image/index.tsx +141 -0
- package/packages/willa-content/src/components/ImageGallery/index.css +82 -0
- package/packages/willa-content/src/components/ImageGallery/index.tsx +170 -0
- package/packages/willa-content/src/components/InputPanel/index.css +181 -0
- package/packages/willa-content/src/components/InputPanel/index.tsx +255 -0
- package/packages/willa-content/src/components/Kbd/index.css +61 -0
- package/packages/willa-content/src/components/Kbd/index.tsx +102 -0
- package/packages/willa-content/src/components/Lightbox/index.css +127 -0
- package/packages/willa-content/src/components/Lightbox/index.tsx +328 -0
- package/packages/willa-content/src/components/List/index.css +439 -0
- package/packages/willa-content/src/components/List/index.tsx +403 -0
- package/packages/willa-content/src/components/MathExpression/index.css +65 -0
- package/packages/willa-content/src/components/MathExpression/index.tsx +105 -0
- package/packages/willa-content/src/components/MentionInput/index.css +92 -0
- package/packages/willa-content/src/components/MentionInput/index.tsx +1138 -0
- package/packages/willa-content/src/components/Menu/index.css +151 -0
- package/packages/willa-content/src/components/Menu/index.tsx +356 -0
- package/packages/willa-content/src/components/Pagination/index.css +139 -0
- package/packages/willa-content/src/components/Pagination/index.tsx +373 -0
- package/packages/willa-content/src/components/Popover/index.css +128 -0
- package/packages/willa-content/src/components/Popover/index.tsx +226 -0
- package/packages/willa-content/src/components/Progress/index.css +137 -0
- package/packages/willa-content/src/components/Progress/index.tsx +117 -0
- package/packages/willa-content/src/components/Result/index.css +142 -0
- package/packages/willa-content/src/components/Result/index.tsx +85 -0
- package/packages/willa-content/src/components/Segmented/index.css +136 -0
- package/packages/willa-content/src/components/Segmented/index.tsx +283 -0
- package/packages/willa-content/src/components/SelectionBar/index.css +104 -0
- package/packages/willa-content/src/components/SelectionBar/index.tsx +120 -0
- package/packages/willa-content/src/components/Skeleton/index.css +68 -0
- package/packages/willa-content/src/components/Skeleton/index.tsx +126 -0
- package/packages/willa-content/src/components/SourceCard/index.css +177 -0
- package/packages/willa-content/src/components/SourceCard/index.tsx +108 -0
- package/packages/willa-content/src/components/Spinner/index.css +124 -0
- package/packages/willa-content/src/components/Spinner/index.tsx +55 -0
- package/packages/willa-content/src/components/Statistic/index.css +135 -0
- package/packages/willa-content/src/components/Statistic/index.tsx +90 -0
- package/packages/willa-content/src/components/Steps/index.css +167 -0
- package/packages/willa-content/src/components/Steps/index.tsx +170 -0
- package/packages/willa-content/src/components/Table/TableBody.tsx +389 -0
- package/packages/willa-content/src/components/Table/TableHeader.tsx +256 -0
- package/packages/willa-content/src/components/Table/TablePagination.tsx +46 -0
- package/packages/willa-content/src/components/Table/TableView.tsx +341 -0
- package/packages/willa-content/src/components/Table/columnState.ts +37 -0
- package/packages/willa-content/src/components/Table/columns.ts +63 -0
- package/packages/willa-content/src/components/Table/group.ts +114 -0
- package/packages/willa-content/src/components/Table/index.css +620 -0
- package/packages/willa-content/src/components/Table/index.tsx +100 -0
- package/packages/willa-content/src/components/Table/layout.ts +80 -0
- package/packages/willa-content/src/components/Table/tree.ts +28 -0
- package/packages/willa-content/src/components/Table/types.ts +177 -0
- package/packages/willa-content/src/components/Table/useTableColumnResize.ts +227 -0
- package/packages/willa-content/src/components/Table/useTableColumnState.ts +153 -0
- package/packages/willa-content/src/components/Table/useTableExpansion.ts +69 -0
- package/packages/willa-content/src/components/Table/useTableInfiniteScroll.ts +77 -0
- package/packages/willa-content/src/components/Table/useTableSelection.ts +102 -0
- package/packages/willa-content/src/components/Table/useTableState.ts +436 -0
- package/packages/willa-content/src/components/Table/useTableViewModel.ts +222 -0
- package/packages/willa-content/src/components/Table/utils.ts +251 -0
- package/packages/willa-content/src/components/Tabs/index.css +126 -0
- package/packages/willa-content/src/components/Tabs/index.tsx +154 -0
- package/packages/willa-content/src/components/Tag/index.css +171 -0
- package/packages/willa-content/src/components/Tag/index.tsx +91 -0
- package/packages/willa-content/src/components/Timeline/index.css +355 -0
- package/packages/willa-content/src/components/Timeline/index.tsx +153 -0
- package/packages/willa-content/src/components/Toast/index.css +226 -0
- package/packages/willa-content/src/components/Toast/index.tsx +280 -0
- package/packages/willa-content/src/components/Toolbar/index.css +59 -0
- package/packages/willa-content/src/components/Toolbar/index.tsx +73 -0
- package/packages/willa-content/src/components/Tooltip/index.css +83 -0
- package/packages/willa-content/src/components/Tooltip/index.tsx +265 -0
- package/packages/willa-content/src/components/Tour/index.css +312 -0
- package/packages/willa-content/src/components/Tour/index.tsx +788 -0
- package/packages/willa-content/src/components/Tree/index.css +274 -0
- package/packages/willa-content/src/components/Tree/index.tsx +564 -0
- package/packages/willa-content/src/components/Typography/TypographyActions.tsx +125 -0
- package/packages/willa-content/src/components/Typography/TypographyContent.tsx +406 -0
- package/packages/willa-content/src/components/Typography/TypographyEdit.tsx +161 -0
- package/packages/willa-content/src/components/Typography/index.css +575 -0
- package/packages/willa-content/src/components/Typography/index.tsx +145 -0
- package/packages/willa-content/src/components/Typography/types.ts +144 -0
- package/packages/willa-content/src/components/Typography/utils.tsx +192 -0
- package/packages/willa-content/src/components/Watermark/index.css +37 -0
- package/packages/willa-content/src/components/Watermark/index.tsx +294 -0
- package/packages/willa-content/src/index.ts +408 -0
- package/packages/willa-content/src/internal/buttonActionUtils.ts +46 -0
- package/packages/willa-content/src/internal/syntaxHighlight.css +82 -0
- package/packages/willa-content/src/internal/useSingleSelection.ts +80 -0
- package/packages/willa-content/src/themes/dark.css +777 -0
- package/packages/willa-content/src/themes/light.css +780 -0
- package/packages/willa-content/vitest.config.ts +15 -0
- package/packages/willa-form/README.md +33 -0
- package/packages/willa-form/auklet.config.mjs +24 -0
- package/packages/willa-form/package.json +85 -0
- package/packages/willa-form/src/components/Calendar/ScheduleCalendar.tsx +1036 -0
- package/packages/willa-form/src/components/Calendar/index.css +1081 -0
- package/packages/willa-form/src/components/Calendar/index.tsx +876 -0
- package/packages/willa-form/src/components/Calendar/utils.ts +67 -0
- package/packages/willa-form/src/components/Checkbox/index.css +133 -0
- package/packages/willa-form/src/components/Checkbox/index.tsx +104 -0
- package/packages/willa-form/src/components/ColorPicker/index.css +617 -0
- package/packages/willa-form/src/components/ColorPicker/index.tsx +724 -0
- package/packages/willa-form/src/components/ColorPicker/types.ts +21 -0
- package/packages/willa-form/src/components/DatePicker/index.css +395 -0
- package/packages/willa-form/src/components/DatePicker/index.tsx +631 -0
- package/packages/willa-form/src/components/FilterBar/index.css +122 -0
- package/packages/willa-form/src/components/FilterBar/index.tsx +98 -0
- package/packages/willa-form/src/components/Form/index.css +49 -0
- package/packages/willa-form/src/components/Form/index.tsx +50 -0
- package/packages/willa-form/src/components/FormActions/index.css +62 -0
- package/packages/willa-form/src/components/FormActions/index.tsx +44 -0
- package/packages/willa-form/src/components/FormField/index.css +71 -0
- package/packages/willa-form/src/components/FormField/index.tsx +85 -0
- package/packages/willa-form/src/components/FormGroup/index.css +62 -0
- package/packages/willa-form/src/components/FormGroup/index.tsx +64 -0
- package/packages/willa-form/src/components/FormMessage/index.css +77 -0
- package/packages/willa-form/src/components/FormMessage/index.tsx +57 -0
- package/packages/willa-form/src/components/Input/index.css +131 -0
- package/packages/willa-form/src/components/Input/index.tsx +116 -0
- package/packages/willa-form/src/components/NumberInput/index.css +315 -0
- package/packages/willa-form/src/components/NumberInput/index.tsx +567 -0
- package/packages/willa-form/src/components/Picker/index.css +323 -0
- package/packages/willa-form/src/components/Picker/index.tsx +359 -0
- package/packages/willa-form/src/components/Radio/index.css +131 -0
- package/packages/willa-form/src/components/Radio/index.tsx +70 -0
- package/packages/willa-form/src/components/RangeInput/index.css +224 -0
- package/packages/willa-form/src/components/RangeInput/index.tsx +288 -0
- package/packages/willa-form/src/components/Rate/index.css +97 -0
- package/packages/willa-form/src/components/Rate/index.tsx +378 -0
- package/packages/willa-form/src/components/SearchInput/index.css +32 -0
- package/packages/willa-form/src/components/SearchInput/index.tsx +101 -0
- package/packages/willa-form/src/components/Select/index.css +4 -0
- package/packages/willa-form/src/components/Select/index.tsx +79 -0
- package/packages/willa-form/src/components/Switch/index.css +133 -0
- package/packages/willa-form/src/components/Switch/index.tsx +75 -0
- package/packages/willa-form/src/components/TagInput/index.css +209 -0
- package/packages/willa-form/src/components/TagInput/index.tsx +497 -0
- package/packages/willa-form/src/components/TextArea/index.css +91 -0
- package/packages/willa-form/src/components/TextArea/index.tsx +87 -0
- package/packages/willa-form/src/components/TimePicker/index.css +485 -0
- package/packages/willa-form/src/components/TimePicker/index.tsx +649 -0
- package/packages/willa-form/src/components/TimePicker/types.ts +8 -0
- package/packages/willa-form/src/components/TreeSelect/index.css +331 -0
- package/packages/willa-form/src/components/TreeSelect/index.tsx +497 -0
- package/packages/willa-form/src/components/Upload/index.css +345 -0
- package/packages/willa-form/src/components/Upload/index.tsx +581 -0
- package/packages/willa-form/src/index.ts +176 -0
- package/packages/willa-form/src/internal/colorUtils.ts +206 -0
- package/packages/willa-form/src/internal/comboboxField.tsx +114 -0
- package/packages/willa-form/src/internal/floatingPanelParts.tsx +80 -0
- package/packages/willa-form/src/internal/selectablePanelKeyboard.ts +93 -0
- package/packages/willa-form/src/internal/selectablePanelParts.tsx +212 -0
- package/packages/willa-form/src/internal/timePickerParts.ts +205 -0
- package/packages/willa-form/src/internal/useComboboxState.ts +21 -0
- package/packages/willa-form/src/internal/useFloatingPanel.ts +114 -0
- package/packages/willa-form/src/internal/useSelectablePanel.ts +152 -0
- package/packages/willa-form/src/internal/useSelectionModel.ts +115 -0
- package/packages/willa-form/src/themes/dark.css +197 -0
- package/packages/willa-form/src/themes/light.css +201 -0
- package/packages/willa-form/vitest.config.ts +15 -0
- package/packages/willa-layout/README.md +33 -0
- package/packages/willa-layout/auklet.config.mjs +11 -0
- package/packages/willa-layout/package.json +83 -0
- package/packages/willa-layout/src/components/AppShell/index.css +100 -0
- package/packages/willa-layout/src/components/AppShell/index.tsx +70 -0
- package/packages/willa-layout/src/components/BorderBeam/index.css +86 -0
- package/packages/willa-layout/src/components/BorderBeam/index.tsx +161 -0
- package/packages/willa-layout/src/components/Card/index.css +179 -0
- package/packages/willa-layout/src/components/Card/index.tsx +174 -0
- package/packages/willa-layout/src/components/Container/index.css +55 -0
- package/packages/willa-layout/src/components/Container/index.tsx +43 -0
- package/packages/willa-layout/src/components/Grid/index.css +9 -0
- package/packages/willa-layout/src/components/Grid/index.tsx +100 -0
- package/packages/willa-layout/src/components/Group/index.css +21 -0
- package/packages/willa-layout/src/components/Group/index.tsx +146 -0
- package/packages/willa-layout/src/components/Masonry/index.css +12 -0
- package/packages/willa-layout/src/components/Masonry/index.tsx +71 -0
- package/packages/willa-layout/src/components/PageHeader/index.css +130 -0
- package/packages/willa-layout/src/components/PageHeader/index.tsx +76 -0
- package/packages/willa-layout/src/components/Panel/index.css +123 -0
- package/packages/willa-layout/src/components/Panel/index.tsx +63 -0
- package/packages/willa-layout/src/components/SectionHeader/index.css +104 -0
- package/packages/willa-layout/src/components/SectionHeader/index.tsx +69 -0
- package/packages/willa-layout/src/components/Separator/index.css +155 -0
- package/packages/willa-layout/src/components/Separator/index.tsx +61 -0
- package/packages/willa-layout/src/components/SidebarLayout/index.css +43 -0
- package/packages/willa-layout/src/components/SidebarLayout/index.tsx +73 -0
- package/packages/willa-layout/src/components/SplitPane/index.css +148 -0
- package/packages/willa-layout/src/components/SplitPane/index.tsx +434 -0
- package/packages/willa-layout/src/components/Stack/index.css +8 -0
- package/packages/willa-layout/src/components/Stack/index.tsx +99 -0
- package/packages/willa-layout/src/index.ts +91 -0
- package/packages/willa-layout/src/internal/headerBlock.tsx +49 -0
- package/packages/willa-layout/src/themes/dark.css +55 -0
- package/packages/willa-layout/src/themes/light.css +59 -0
- package/packages/willa-layout/vitest.config.ts +15 -0
- package/packages/willa-shared/README.md +24 -0
- package/packages/willa-shared/package.json +46 -0
- package/packages/willa-shared/src/clipboard.ts +23 -0
- package/packages/willa-shared/src/codeHighlight.ts +109 -0
- package/packages/willa-shared/src/controllableState.ts +42 -0
- package/packages/willa-shared/src/copy.ts +79 -0
- package/packages/willa-shared/src/css.ts +10 -0
- package/packages/willa-shared/src/dom.ts +12 -0
- package/packages/willa-shared/src/file.ts +214 -0
- package/packages/willa-shared/src/floating.ts +160 -0
- package/packages/willa-shared/src/floatingLayer.ts +310 -0
- package/packages/willa-shared/src/heading.ts +69 -0
- package/packages/willa-shared/src/index.ts +88 -0
- package/packages/willa-shared/src/media.ts +23 -0
- package/packages/willa-shared/src/nodes.ts +24 -0
- package/packages/willa-shared/src/number.ts +9 -0
- package/packages/willa-shared/src/refs.ts +16 -0
- package/packages/willa-shared/src/request.ts +46 -0
- package/packages/willa-shared/src/types.ts +27 -0
- package/packages/willa-shared/src/viewport.ts +12 -0
- package/packages/willa-shared/src/virtualScroll.ts +137 -0
- package/packages/willa-shared/vitest.config.ts +9 -0
- package/packages/willa-widgets/README.md +33 -0
- package/packages/willa-widgets/auklet.config.mjs +25 -0
- package/packages/willa-widgets/package.json +89 -0
- package/packages/willa-widgets/src/components/AudioEmbed/index.css +424 -0
- package/packages/willa-widgets/src/components/AudioEmbed/index.tsx +270 -0
- package/packages/willa-widgets/src/components/AudioLink/index.css +165 -0
- package/packages/willa-widgets/src/components/AudioLink/index.tsx +169 -0
- package/packages/willa-widgets/src/components/EnglishCards/Card.tsx +116 -0
- package/packages/willa-widgets/src/components/EnglishCards/Content.tsx +203 -0
- package/packages/willa-widgets/src/components/EnglishCards/Practice.tsx +91 -0
- package/packages/willa-widgets/src/components/EnglishCards/Resources.tsx +91 -0
- package/packages/willa-widgets/src/components/EnglishCards/index.css +531 -0
- package/packages/willa-widgets/src/components/EnglishCards/index.tsx +142 -0
- package/packages/willa-widgets/src/components/EnglishCards/speech.ts +29 -0
- package/packages/willa-widgets/src/components/EnglishCards/types.ts +43 -0
- package/packages/willa-widgets/src/components/GitHubMention/index.css +206 -0
- package/packages/willa-widgets/src/components/GitHubMention/index.tsx +168 -0
- package/packages/willa-widgets/src/components/GitHubRepo/index.css +194 -0
- package/packages/willa-widgets/src/components/GitHubRepo/index.tsx +172 -0
- package/packages/willa-widgets/src/components/LogoWall/index.css +122 -0
- package/packages/willa-widgets/src/components/LogoWall/index.tsx +104 -0
- package/packages/willa-widgets/src/components/Mdx/index.css +273 -0
- package/packages/willa-widgets/src/components/Mdx/index.tsx +377 -0
- package/packages/willa-widgets/src/components/Poem/index.css +101 -0
- package/packages/willa-widgets/src/components/Poem/index.tsx +74 -0
- package/packages/willa-widgets/src/components/ProfileCard/index.css +107 -0
- package/packages/willa-widgets/src/components/ProfileCard/index.tsx +116 -0
- package/packages/willa-widgets/src/components/QRCode/index.css +175 -0
- package/packages/willa-widgets/src/components/QRCode/index.tsx +257 -0
- package/packages/willa-widgets/src/components/SiteFooter/index.css +109 -0
- package/packages/willa-widgets/src/components/SiteFooter/index.tsx +104 -0
- package/packages/willa-widgets/src/components/SiteNav/index.css +93 -0
- package/packages/willa-widgets/src/components/SiteNav/index.tsx +71 -0
- package/packages/willa-widgets/src/components/VideoEmbed/index.css +230 -0
- package/packages/willa-widgets/src/components/VideoEmbed/index.tsx +134 -0
- package/packages/willa-widgets/src/components/VideoLink/index.css +118 -0
- package/packages/willa-widgets/src/components/VideoLink/index.tsx +161 -0
- package/packages/willa-widgets/src/components/WebEmbed/index.css +106 -0
- package/packages/willa-widgets/src/components/WebEmbed/index.tsx +98 -0
- package/packages/willa-widgets/src/components/XPostEmbed/index.css +52 -0
- package/packages/willa-widgets/src/components/XPostEmbed/index.tsx +88 -0
- package/packages/willa-widgets/src/index.ts +57 -0
- package/packages/willa-widgets/src/internal/media.ts +84 -0
- package/packages/willa-widgets/src/internal/mediaEmbed.tsx +52 -0
- package/packages/willa-widgets/src/internal/useGitHubHoverCardResource.ts +120 -0
- package/packages/willa-widgets/src/themes/dark.css +209 -0
- package/packages/willa-widgets/src/themes/light.css +207 -0
- package/packages/willa-widgets/vitest.config.ts +15 -0
- package/pnpm-workspace.yaml +29 -0
- package/tsconfig.json +50 -0
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type ButtonHTMLAttributes,
|
|
3
|
+
type ChangeEventHandler,
|
|
4
|
+
type KeyboardEventHandler,
|
|
5
|
+
type ReactNode,
|
|
6
|
+
type Ref,
|
|
7
|
+
} from "react";
|
|
8
|
+
import { ChevronDownIcon, Cross2Icon } from "@radix-ui/react-icons";
|
|
9
|
+
import classNames from "classnames";
|
|
10
|
+
|
|
11
|
+
import {
|
|
12
|
+
FloatingPanelPortal,
|
|
13
|
+
FloatingPanelShell,
|
|
14
|
+
} from "#form/internal/floatingPanelParts";
|
|
15
|
+
import type { FloatingPanelPosition } from "#form/internal/useFloatingPanel";
|
|
16
|
+
|
|
17
|
+
export type SelectablePanelPortalProps = {
|
|
18
|
+
children: ReactNode;
|
|
19
|
+
open: boolean;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export function SelectablePanelPortal(props: SelectablePanelPortalProps) {
|
|
23
|
+
return (
|
|
24
|
+
<FloatingPanelPortal open={props.open}>
|
|
25
|
+
{props.children}
|
|
26
|
+
</FloatingPanelPortal>
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export type SelectablePanelTriggerProps = Omit<
|
|
31
|
+
ButtonHTMLAttributes<HTMLButtonElement>,
|
|
32
|
+
"children"
|
|
33
|
+
> & {
|
|
34
|
+
buttonRef: Ref<HTMLButtonElement>;
|
|
35
|
+
controls?: string;
|
|
36
|
+
displayValue: ReactNode;
|
|
37
|
+
expanded: boolean;
|
|
38
|
+
hasValue: boolean;
|
|
39
|
+
invalid?: boolean;
|
|
40
|
+
placeholderClassName: string;
|
|
41
|
+
popupRole: "listbox" | "tree";
|
|
42
|
+
triggerClassName: string;
|
|
43
|
+
valueClassName: string;
|
|
44
|
+
iconClassName: string;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
export function SelectablePanelTrigger(props: SelectablePanelTriggerProps) {
|
|
48
|
+
const {
|
|
49
|
+
buttonRef,
|
|
50
|
+
controls,
|
|
51
|
+
displayValue,
|
|
52
|
+
expanded,
|
|
53
|
+
hasValue,
|
|
54
|
+
invalid,
|
|
55
|
+
placeholderClassName,
|
|
56
|
+
popupRole,
|
|
57
|
+
triggerClassName,
|
|
58
|
+
valueClassName,
|
|
59
|
+
iconClassName,
|
|
60
|
+
...buttonProps
|
|
61
|
+
} = props;
|
|
62
|
+
|
|
63
|
+
return (
|
|
64
|
+
<button
|
|
65
|
+
{...buttonProps}
|
|
66
|
+
ref={buttonRef}
|
|
67
|
+
type="button"
|
|
68
|
+
className={triggerClassName}
|
|
69
|
+
aria-haspopup={popupRole}
|
|
70
|
+
aria-expanded={expanded}
|
|
71
|
+
aria-controls={controls}
|
|
72
|
+
aria-invalid={invalid || undefined}
|
|
73
|
+
>
|
|
74
|
+
<span
|
|
75
|
+
className={classNames(
|
|
76
|
+
valueClassName,
|
|
77
|
+
!hasValue && placeholderClassName,
|
|
78
|
+
)}
|
|
79
|
+
>
|
|
80
|
+
{displayValue}
|
|
81
|
+
</span>
|
|
82
|
+
<ChevronDownIcon className={iconClassName} aria-hidden="true" />
|
|
83
|
+
</button>
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export type SelectablePanelClearButtonProps = {
|
|
88
|
+
ariaLabel: string;
|
|
89
|
+
className: string;
|
|
90
|
+
onClear: () => void;
|
|
91
|
+
triggerRef: { current: HTMLElement | null };
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
export function SelectablePanelClearButton(
|
|
95
|
+
props: SelectablePanelClearButtonProps,
|
|
96
|
+
) {
|
|
97
|
+
const { ariaLabel, className, onClear, triggerRef } = props;
|
|
98
|
+
|
|
99
|
+
return (
|
|
100
|
+
<button
|
|
101
|
+
className={className}
|
|
102
|
+
type="button"
|
|
103
|
+
aria-label={ariaLabel}
|
|
104
|
+
onClick={(event) => {
|
|
105
|
+
event.stopPropagation();
|
|
106
|
+
onClear();
|
|
107
|
+
triggerRef.current?.focus();
|
|
108
|
+
}}
|
|
109
|
+
>
|
|
110
|
+
<Cross2Icon />
|
|
111
|
+
</button>
|
|
112
|
+
);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export type SelectablePanelHiddenInputProps = {
|
|
116
|
+
name?: string;
|
|
117
|
+
value: string;
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
export function SelectablePanelHiddenInput(
|
|
121
|
+
props: SelectablePanelHiddenInputProps,
|
|
122
|
+
) {
|
|
123
|
+
if (!props.name) return null;
|
|
124
|
+
|
|
125
|
+
return <input type="hidden" name={props.name} value={props.value} readOnly />;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
export type SelectablePanelShellProps = {
|
|
129
|
+
children: ReactNode;
|
|
130
|
+
className: string;
|
|
131
|
+
id: string;
|
|
132
|
+
labelledBy: string;
|
|
133
|
+
multiselectable?: boolean;
|
|
134
|
+
panelRef: Ref<HTMLDivElement>;
|
|
135
|
+
position: FloatingPanelPosition | null;
|
|
136
|
+
role: "listbox" | "tree";
|
|
137
|
+
onKeyDown?: KeyboardEventHandler<HTMLDivElement>;
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
export function SelectablePanelShell(props: SelectablePanelShellProps) {
|
|
141
|
+
const {
|
|
142
|
+
children,
|
|
143
|
+
className,
|
|
144
|
+
id,
|
|
145
|
+
labelledBy,
|
|
146
|
+
multiselectable,
|
|
147
|
+
panelRef,
|
|
148
|
+
position,
|
|
149
|
+
role,
|
|
150
|
+
onKeyDown,
|
|
151
|
+
} = props;
|
|
152
|
+
|
|
153
|
+
return (
|
|
154
|
+
<FloatingPanelShell
|
|
155
|
+
panelRef={panelRef}
|
|
156
|
+
id={id}
|
|
157
|
+
className={className}
|
|
158
|
+
role={role}
|
|
159
|
+
ariaMultiselectable={multiselectable}
|
|
160
|
+
ariaLabelledBy={labelledBy}
|
|
161
|
+
onKeyDown={onKeyDown}
|
|
162
|
+
position={position}
|
|
163
|
+
>
|
|
164
|
+
{children}
|
|
165
|
+
</FloatingPanelShell>
|
|
166
|
+
);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
export type SelectablePanelSearchProps = {
|
|
170
|
+
className: string;
|
|
171
|
+
inputRef: Ref<HTMLInputElement>;
|
|
172
|
+
placeholder: string;
|
|
173
|
+
value: string;
|
|
174
|
+
onChange: ChangeEventHandler<HTMLInputElement>;
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
export function SelectablePanelSearch(props: SelectablePanelSearchProps) {
|
|
178
|
+
const { className, inputRef, placeholder, value, onChange } = props;
|
|
179
|
+
|
|
180
|
+
return (
|
|
181
|
+
<div className={className}>
|
|
182
|
+
<input
|
|
183
|
+
ref={inputRef}
|
|
184
|
+
value={value}
|
|
185
|
+
placeholder={placeholder}
|
|
186
|
+
onChange={onChange}
|
|
187
|
+
/>
|
|
188
|
+
</div>
|
|
189
|
+
);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
export type SelectablePanelListProps = {
|
|
193
|
+
children: ReactNode;
|
|
194
|
+
className: string;
|
|
195
|
+
listRef: Ref<HTMLDivElement>;
|
|
196
|
+
scrollable: boolean;
|
|
197
|
+
scrollableClassName: string;
|
|
198
|
+
};
|
|
199
|
+
|
|
200
|
+
export function SelectablePanelList(props: SelectablePanelListProps) {
|
|
201
|
+
const { children, className, listRef, scrollable, scrollableClassName } =
|
|
202
|
+
props;
|
|
203
|
+
|
|
204
|
+
return (
|
|
205
|
+
<div
|
|
206
|
+
ref={listRef}
|
|
207
|
+
className={classNames(className, scrollable && scrollableClassName)}
|
|
208
|
+
>
|
|
209
|
+
{children}
|
|
210
|
+
</div>
|
|
211
|
+
);
|
|
212
|
+
}
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
import { clampNumber } from "@willa-ui/shared";
|
|
2
|
+
|
|
3
|
+
import type {
|
|
4
|
+
TimePickerDisabledTime,
|
|
5
|
+
TimePickerWheelColumn,
|
|
6
|
+
TimePickerWheelColumns,
|
|
7
|
+
} from "#form/components/TimePicker/types";
|
|
8
|
+
|
|
9
|
+
export type TimePickerParts = {
|
|
10
|
+
hour: number;
|
|
11
|
+
minute: number;
|
|
12
|
+
second: number;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export type TimePickerWheelOption = {
|
|
16
|
+
value: number;
|
|
17
|
+
label: string;
|
|
18
|
+
disabled: boolean;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export function normalizeTimeWheelColumns(columns: TimePickerWheelColumns) {
|
|
22
|
+
if (Array.isArray(columns)) return columns;
|
|
23
|
+
return ["hour", "minute", "second"] satisfies Array<TimePickerWheelColumn>;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function getTimeWheelParts(value: string) {
|
|
27
|
+
const now = new Date();
|
|
28
|
+
const fallback = {
|
|
29
|
+
hour: now.getHours(),
|
|
30
|
+
minute: now.getMinutes(),
|
|
31
|
+
second: now.getSeconds(),
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
if (!value) return normalizeTimeWheelParts(fallback);
|
|
35
|
+
|
|
36
|
+
const timeMatch = value.match(/^(\d{2}):(\d{2})(?::(\d{2}))?$/);
|
|
37
|
+
if (timeMatch) {
|
|
38
|
+
return normalizeTimeWheelParts({
|
|
39
|
+
hour: Number(timeMatch[1]),
|
|
40
|
+
minute: Number(timeMatch[2]),
|
|
41
|
+
second: Number(timeMatch[3] ?? fallback.second),
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const timeWithPrefixMatch = value.match(
|
|
46
|
+
/^(?:\d{4}-\d{2}-\d{2}[ T])?(\d{1,2}):(\d{2})(?::(\d{2}))?\s*([AaPp][Mm])?$/,
|
|
47
|
+
);
|
|
48
|
+
if (timeWithPrefixMatch) {
|
|
49
|
+
const meridiem = timeWithPrefixMatch[4]?.toLowerCase();
|
|
50
|
+
const hour = Number(timeWithPrefixMatch[1]);
|
|
51
|
+
|
|
52
|
+
return normalizeTimeWheelParts({
|
|
53
|
+
hour:
|
|
54
|
+
meridiem === "pm" && hour < 12
|
|
55
|
+
? hour + 12
|
|
56
|
+
: meridiem === "am" && hour === 12
|
|
57
|
+
? 0
|
|
58
|
+
: hour,
|
|
59
|
+
minute: Number(timeWithPrefixMatch[2]),
|
|
60
|
+
second: Number(timeWithPrefixMatch[3] ?? fallback.second),
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return normalizeTimeWheelParts(fallback);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export function normalizeTimeWheelParts(parts: {
|
|
68
|
+
hour: number;
|
|
69
|
+
minute: number;
|
|
70
|
+
second: number;
|
|
71
|
+
}) {
|
|
72
|
+
return {
|
|
73
|
+
hour: clampNumber(Math.trunc(parts.hour), 0, 23),
|
|
74
|
+
minute: clampNumber(Math.trunc(parts.minute), 0, 59),
|
|
75
|
+
second: clampNumber(Math.trunc(parts.second), 0, 59),
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export function formatTimeWheelValue(
|
|
80
|
+
parts: TimePickerParts,
|
|
81
|
+
columns: Array<TimePickerWheelColumn>,
|
|
82
|
+
) {
|
|
83
|
+
const hasHour = columns.includes("hour");
|
|
84
|
+
const hasMinute = columns.includes("minute");
|
|
85
|
+
const hasSecond = columns.includes("second");
|
|
86
|
+
|
|
87
|
+
if (!hasHour && !hasMinute && !hasSecond) {
|
|
88
|
+
return "";
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const timeParts = [
|
|
92
|
+
hasHour ? padNumber(parts.hour) : null,
|
|
93
|
+
hasMinute ? padNumber(parts.minute) : null,
|
|
94
|
+
hasSecond ? padNumber(parts.second) : null,
|
|
95
|
+
].filter((part): part is string => part !== null);
|
|
96
|
+
|
|
97
|
+
return timeParts.join(":");
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export function formatTimeWheelDisplayValue(
|
|
101
|
+
value: string,
|
|
102
|
+
columns: Array<TimePickerWheelColumn>,
|
|
103
|
+
) {
|
|
104
|
+
const parts = getTimeWheelParts(value);
|
|
105
|
+
|
|
106
|
+
return formatTimeWheelValue(parts, columns);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export function createTimeWheelOptions(
|
|
110
|
+
column: TimePickerWheelColumn,
|
|
111
|
+
options?: {
|
|
112
|
+
hourStep?: number;
|
|
113
|
+
minuteStep?: number;
|
|
114
|
+
secondStep?: number;
|
|
115
|
+
use12Hours?: boolean;
|
|
116
|
+
disabledTime?: TimePickerDisabledTime | null;
|
|
117
|
+
selectedParts?: TimePickerParts;
|
|
118
|
+
period?: "am" | "pm";
|
|
119
|
+
},
|
|
120
|
+
) {
|
|
121
|
+
const hourStep = Math.max(1, Math.trunc(options?.hourStep ?? 1));
|
|
122
|
+
const minuteStep = Math.max(1, Math.trunc(options?.minuteStep ?? 1));
|
|
123
|
+
const secondStep = Math.max(1, Math.trunc(options?.secondStep ?? 1));
|
|
124
|
+
const use12Hours = options?.use12Hours ?? false;
|
|
125
|
+
const disabledHours = options?.disabledTime?.disabledHours?.() ?? [];
|
|
126
|
+
const selectedParts = options?.selectedParts ?? getTimeWheelParts("");
|
|
127
|
+
|
|
128
|
+
if (column === "hour") {
|
|
129
|
+
const start = use12Hours ? 1 : 0;
|
|
130
|
+
const end = use12Hours ? 12 : 23;
|
|
131
|
+
const period = options?.period;
|
|
132
|
+
|
|
133
|
+
return createNumberOptions(start, end, hourStep).map((option) => {
|
|
134
|
+
const currentHour = use12Hours
|
|
135
|
+
? convertDisplayHourTo24Hour(option.value, period)
|
|
136
|
+
: option.value;
|
|
137
|
+
|
|
138
|
+
return {
|
|
139
|
+
...option,
|
|
140
|
+
disabled: disabledHours.includes(currentHour),
|
|
141
|
+
};
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
if (column === "minute") {
|
|
146
|
+
const disabledMinutes =
|
|
147
|
+
options?.disabledTime?.disabledMinutes?.(selectedParts.hour) ?? [];
|
|
148
|
+
|
|
149
|
+
return createNumberOptions(0, 59, minuteStep).map((option) => {
|
|
150
|
+
return {
|
|
151
|
+
...option,
|
|
152
|
+
disabled: disabledMinutes.includes(option.value),
|
|
153
|
+
};
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
const disabledSeconds =
|
|
158
|
+
options?.disabledTime?.disabledSeconds?.(
|
|
159
|
+
selectedParts.hour,
|
|
160
|
+
selectedParts.minute,
|
|
161
|
+
) ?? [];
|
|
162
|
+
|
|
163
|
+
return createNumberOptions(0, 59, secondStep).map((option) => {
|
|
164
|
+
return {
|
|
165
|
+
...option,
|
|
166
|
+
disabled: disabledSeconds.includes(option.value),
|
|
167
|
+
};
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
export function getTimeWheelPanelMinWidth(columnCount: number) {
|
|
172
|
+
return Math.max(244, columnCount * 4.25 * 16);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
const createNumberOptions = (start: number, end: number, step: number) => {
|
|
176
|
+
return Array.from(
|
|
177
|
+
{ length: Math.floor((end - start) / step) + 1 },
|
|
178
|
+
(_, index) => {
|
|
179
|
+
const value = start + index * step;
|
|
180
|
+
return {
|
|
181
|
+
value,
|
|
182
|
+
label: padNumber(value),
|
|
183
|
+
};
|
|
184
|
+
},
|
|
185
|
+
).filter((option) => option.value <= end);
|
|
186
|
+
};
|
|
187
|
+
|
|
188
|
+
const convertDisplayHourTo24Hour = (
|
|
189
|
+
displayHour: number,
|
|
190
|
+
period?: "am" | "pm",
|
|
191
|
+
) => {
|
|
192
|
+
const normalizedDisplayHour = Math.trunc(displayHour);
|
|
193
|
+
|
|
194
|
+
if (period === "pm") {
|
|
195
|
+
return normalizedDisplayHour === 12 ? 12 : normalizedDisplayHour + 12;
|
|
196
|
+
}
|
|
197
|
+
if (period === "am") {
|
|
198
|
+
return normalizedDisplayHour === 12 ? 0 : normalizedDisplayHour;
|
|
199
|
+
}
|
|
200
|
+
return normalizedDisplayHour;
|
|
201
|
+
};
|
|
202
|
+
|
|
203
|
+
const padNumber = (value: number) => {
|
|
204
|
+
return String(value).padStart(2, "0");
|
|
205
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import {
|
|
2
|
+
useSelectionModel,
|
|
3
|
+
type SelectionModelItem,
|
|
4
|
+
type UseSelectionModelOptions,
|
|
5
|
+
} from "#form/internal/useSelectionModel";
|
|
6
|
+
import {
|
|
7
|
+
useSelectablePanel,
|
|
8
|
+
type UseSelectablePanelOptions,
|
|
9
|
+
} from "#form/internal/useSelectablePanel";
|
|
10
|
+
|
|
11
|
+
export type UseComboboxStateOptions<Item extends SelectionModelItem> =
|
|
12
|
+
UseSelectionModelOptions<Item> & UseSelectablePanelOptions;
|
|
13
|
+
|
|
14
|
+
export function useComboboxState<Item extends SelectionModelItem>(
|
|
15
|
+
options: UseComboboxStateOptions<Item>,
|
|
16
|
+
) {
|
|
17
|
+
return {
|
|
18
|
+
...useSelectionModel(options),
|
|
19
|
+
...useSelectablePanel(options),
|
|
20
|
+
};
|
|
21
|
+
}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import {
|
|
2
|
+
useCallback,
|
|
3
|
+
useEffect,
|
|
4
|
+
useMemo,
|
|
5
|
+
useState,
|
|
6
|
+
type RefObject,
|
|
7
|
+
} from "react";
|
|
8
|
+
import { useFloatingLayer } from "@willa-ui/shared";
|
|
9
|
+
|
|
10
|
+
export type FloatingPanelPosition = {
|
|
11
|
+
left: number;
|
|
12
|
+
top: number;
|
|
13
|
+
width?: number;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export type UseFloatingPanelOptions = {
|
|
17
|
+
open: boolean;
|
|
18
|
+
rootRef: RefObject<HTMLElement | null>;
|
|
19
|
+
triggerRef: RefObject<HTMLElement | null>;
|
|
20
|
+
panelRef: RefObject<HTMLElement | null>;
|
|
21
|
+
listRef?: RefObject<HTMLElement | null>;
|
|
22
|
+
minWidth?: number;
|
|
23
|
+
matchTriggerWidth?: boolean;
|
|
24
|
+
fullWidthBelow?: number;
|
|
25
|
+
fallbackHeight?: number;
|
|
26
|
+
gap?: number;
|
|
27
|
+
viewportPadding?: number;
|
|
28
|
+
onClose: () => void;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export const useFloatingPanel = ({
|
|
32
|
+
open,
|
|
33
|
+
rootRef,
|
|
34
|
+
triggerRef,
|
|
35
|
+
panelRef,
|
|
36
|
+
listRef,
|
|
37
|
+
minWidth,
|
|
38
|
+
matchTriggerWidth = true,
|
|
39
|
+
fullWidthBelow,
|
|
40
|
+
fallbackHeight = 320,
|
|
41
|
+
gap = 6,
|
|
42
|
+
viewportPadding = 8,
|
|
43
|
+
onClose,
|
|
44
|
+
}: UseFloatingPanelOptions) => {
|
|
45
|
+
const [scrollable, setScrollable] = useState(false);
|
|
46
|
+
const outsideRefs = useMemo(() => [rootRef], [rootRef]);
|
|
47
|
+
const { position: layerPosition, updatePosition } = useFloatingLayer({
|
|
48
|
+
open,
|
|
49
|
+
triggerRef,
|
|
50
|
+
floatingRef: panelRef,
|
|
51
|
+
minWidth,
|
|
52
|
+
matchAnchorWidth: matchTriggerWidth,
|
|
53
|
+
fallbackHeight,
|
|
54
|
+
fullWidthBelow,
|
|
55
|
+
applyResolvedWidth: true,
|
|
56
|
+
flipToFit: true,
|
|
57
|
+
side: "bottom",
|
|
58
|
+
align: "start",
|
|
59
|
+
offset: gap,
|
|
60
|
+
viewportPadding,
|
|
61
|
+
outsideRefs,
|
|
62
|
+
onClose,
|
|
63
|
+
});
|
|
64
|
+
const position: FloatingPanelPosition | null = layerPosition
|
|
65
|
+
? {
|
|
66
|
+
left: layerPosition.left,
|
|
67
|
+
top: layerPosition.top,
|
|
68
|
+
width: layerPosition.width,
|
|
69
|
+
}
|
|
70
|
+
: null;
|
|
71
|
+
|
|
72
|
+
const updateScrollable = useCallback(() => {
|
|
73
|
+
const list = listRef?.current;
|
|
74
|
+
|
|
75
|
+
if (!list) {
|
|
76
|
+
setScrollable(false);
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
window.requestAnimationFrame(() => {
|
|
81
|
+
setScrollable(list.scrollHeight > list.clientHeight + 1);
|
|
82
|
+
});
|
|
83
|
+
}, [listRef]);
|
|
84
|
+
|
|
85
|
+
useEffect(() => {
|
|
86
|
+
if (!open) return;
|
|
87
|
+
|
|
88
|
+
const handleViewportChange = () => {
|
|
89
|
+
updateScrollable();
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
updateScrollable();
|
|
93
|
+
window.addEventListener("resize", handleViewportChange);
|
|
94
|
+
window.addEventListener("scroll", handleViewportChange, true);
|
|
95
|
+
|
|
96
|
+
return () => {
|
|
97
|
+
window.removeEventListener("resize", handleViewportChange);
|
|
98
|
+
window.removeEventListener("scroll", handleViewportChange, true);
|
|
99
|
+
};
|
|
100
|
+
}, [open, updateScrollable]);
|
|
101
|
+
|
|
102
|
+
useEffect(() => {
|
|
103
|
+
if (open) return;
|
|
104
|
+
|
|
105
|
+
setScrollable(false);
|
|
106
|
+
}, [open]);
|
|
107
|
+
|
|
108
|
+
return {
|
|
109
|
+
position,
|
|
110
|
+
scrollable,
|
|
111
|
+
updatePosition,
|
|
112
|
+
updateScrollable,
|
|
113
|
+
};
|
|
114
|
+
};
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import {
|
|
2
|
+
useCallback,
|
|
3
|
+
useEffect,
|
|
4
|
+
useId,
|
|
5
|
+
useRef,
|
|
6
|
+
useState,
|
|
7
|
+
type KeyboardEvent,
|
|
8
|
+
} from "react";
|
|
9
|
+
|
|
10
|
+
import {
|
|
11
|
+
focusSelectablePanelItem,
|
|
12
|
+
type SelectablePanelFocusTarget,
|
|
13
|
+
} from "#form/internal/selectablePanelKeyboard";
|
|
14
|
+
import { useFloatingPanel } from "#form/internal/useFloatingPanel";
|
|
15
|
+
|
|
16
|
+
export type UseSelectablePanelOptions = {
|
|
17
|
+
contentVersion: unknown;
|
|
18
|
+
fallbackHeight: number;
|
|
19
|
+
id?: string;
|
|
20
|
+
minWidth: number;
|
|
21
|
+
searchable: boolean;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
type SelectablePanelPendingFocus = {
|
|
25
|
+
selector: string;
|
|
26
|
+
target: SelectablePanelFocusTarget;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export function useSelectablePanel(options: UseSelectablePanelOptions) {
|
|
30
|
+
const { contentVersion, fallbackHeight, id, minWidth, searchable } = options;
|
|
31
|
+
const generatedId = useId();
|
|
32
|
+
const buttonId = id ?? generatedId;
|
|
33
|
+
const panelId = `${buttonId}-panel`;
|
|
34
|
+
const rootRef = useRef<HTMLSpanElement>(null);
|
|
35
|
+
const triggerRef = useRef<HTMLButtonElement | null>(null);
|
|
36
|
+
const panelRef = useRef<HTMLDivElement | null>(null);
|
|
37
|
+
const listRef = useRef<HTMLDivElement | null>(null);
|
|
38
|
+
const searchRef = useRef<HTMLInputElement | null>(null);
|
|
39
|
+
const focusTargetRef = useRef<SelectablePanelPendingFocus | null>(null);
|
|
40
|
+
const [open, setOpen] = useState(false);
|
|
41
|
+
const [query, setQuery] = useState("");
|
|
42
|
+
const closePanel = useCallback(() => setOpen(false), []);
|
|
43
|
+
const { position, scrollable, updatePosition, updateScrollable } =
|
|
44
|
+
useFloatingPanel({
|
|
45
|
+
open,
|
|
46
|
+
rootRef,
|
|
47
|
+
triggerRef,
|
|
48
|
+
panelRef,
|
|
49
|
+
listRef,
|
|
50
|
+
minWidth,
|
|
51
|
+
fallbackHeight,
|
|
52
|
+
onClose: closePanel,
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
const focusPanelItem = useCallback(
|
|
56
|
+
(selector: string, target: SelectablePanelFocusTarget) => {
|
|
57
|
+
window.setTimeout(() => {
|
|
58
|
+
focusSelectablePanelItem(panelRef.current, selector, target);
|
|
59
|
+
}, 0);
|
|
60
|
+
},
|
|
61
|
+
[],
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
useEffect(() => {
|
|
65
|
+
if (open) {
|
|
66
|
+
updatePosition();
|
|
67
|
+
updateScrollable();
|
|
68
|
+
const focusTarget = focusTargetRef.current;
|
|
69
|
+
focusTargetRef.current = null;
|
|
70
|
+
|
|
71
|
+
if (focusTarget) {
|
|
72
|
+
focusPanelItem(focusTarget.selector, focusTarget.target);
|
|
73
|
+
} else if (searchable) {
|
|
74
|
+
window.setTimeout(() => searchRef.current?.focus(), 0);
|
|
75
|
+
}
|
|
76
|
+
} else {
|
|
77
|
+
setQuery("");
|
|
78
|
+
}
|
|
79
|
+
}, [
|
|
80
|
+
contentVersion,
|
|
81
|
+
focusPanelItem,
|
|
82
|
+
open,
|
|
83
|
+
searchable,
|
|
84
|
+
updatePosition,
|
|
85
|
+
updateScrollable,
|
|
86
|
+
]);
|
|
87
|
+
|
|
88
|
+
useEffect(() => {
|
|
89
|
+
if (!open) return;
|
|
90
|
+
|
|
91
|
+
updatePosition();
|
|
92
|
+
updateScrollable();
|
|
93
|
+
}, [contentVersion, open, query, updatePosition, updateScrollable]);
|
|
94
|
+
|
|
95
|
+
const focusOrOpen = (
|
|
96
|
+
selector: string,
|
|
97
|
+
target: SelectablePanelFocusTarget,
|
|
98
|
+
) => {
|
|
99
|
+
if (open) {
|
|
100
|
+
focusPanelItem(selector, target);
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
focusTargetRef.current = { selector, target };
|
|
105
|
+
setOpen(true);
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
const handleTriggerKeyDown = (
|
|
109
|
+
event: KeyboardEvent<HTMLButtonElement>,
|
|
110
|
+
options: {
|
|
111
|
+
selector: string;
|
|
112
|
+
onKeyDown?: (event: KeyboardEvent<HTMLButtonElement>) => void;
|
|
113
|
+
},
|
|
114
|
+
) => {
|
|
115
|
+
options.onKeyDown?.(event);
|
|
116
|
+
if (event.defaultPrevented) return;
|
|
117
|
+
|
|
118
|
+
if (event.key === "Escape") {
|
|
119
|
+
setOpen(false);
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
if (event.key === "ArrowDown" || event.key === "ArrowUp") {
|
|
124
|
+
event.preventDefault();
|
|
125
|
+
focusOrOpen(options.selector, event.key === "ArrowUp" ? "last" : "first");
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
if (event.key === "Enter" || event.key === " ") {
|
|
130
|
+
event.preventDefault();
|
|
131
|
+
setOpen((currentOpen) => !currentOpen);
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
return {
|
|
136
|
+
buttonId,
|
|
137
|
+
closePanel,
|
|
138
|
+
listRef,
|
|
139
|
+
open,
|
|
140
|
+
panelId,
|
|
141
|
+
panelRef,
|
|
142
|
+
position,
|
|
143
|
+
query,
|
|
144
|
+
rootRef,
|
|
145
|
+
scrollable,
|
|
146
|
+
searchRef,
|
|
147
|
+
setOpen,
|
|
148
|
+
setQuery,
|
|
149
|
+
triggerRef,
|
|
150
|
+
handleTriggerKeyDown,
|
|
151
|
+
};
|
|
152
|
+
}
|