@deepseek-ai/dsh-client-ui-primitives 0.2.2-rc.1 → 0.2.2-rc.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.i18n.yaml +16 -16
- package/README.md +21 -14
- package/README.zh.md +21 -14
- package/lib/HoverCard.module.css +8 -3
- package/lib/JsonTree.module.css +7 -17
- package/lib/Menu.module.css +157 -37
- package/lib/Modal.module.css +16 -0
- package/lib/QuotePreview.module.css +37 -0
- package/lib/RiskConfirmation.module.css +11 -37
- package/lib/Toast.module.css +2 -3
- package/lib/Tooltip.module.css +2 -1
- package/lib/index.js +1447 -776
- package/lib/index.js.map +1 -0
- package/lib/markdown/CodeBlock.module.css +64 -0
- package/lib/markdown/MarkdownText.module.css +20 -1
- package/lib/types/AnimatedRows.d.ts +3 -0
- package/lib/types/AnimatedRows.d.ts.map +1 -0
- package/lib/types/AnimatedRows.js.map +1 -0
- package/lib/types/BrandWordmark.d.ts.map +1 -0
- package/lib/types/BrandWordmark.js.map +1 -0
- package/lib/types/Button.d.ts.map +1 -0
- package/lib/types/Button.js.map +1 -0
- package/lib/types/Checkbox.d.ts +3 -1
- package/lib/types/Checkbox.d.ts.map +1 -0
- package/lib/types/Checkbox.js.map +1 -0
- package/lib/types/CodeFileIcon.d.ts.map +1 -0
- package/lib/types/CodeFileIcon.js.map +1 -0
- package/lib/types/CodeToolbar.d.ts.map +1 -0
- package/lib/types/CodeToolbar.js.map +1 -0
- package/lib/types/CommandText.d.ts.map +1 -0
- package/lib/types/CommandText.js.map +1 -0
- package/lib/types/ConfigField.d.ts.map +1 -0
- package/lib/types/ConfigField.js.map +1 -0
- package/lib/types/ConnectionIndicator.d.ts.map +1 -0
- package/lib/types/ConnectionIndicator.js.map +1 -0
- package/lib/types/DetailDocument.d.ts.map +1 -0
- package/lib/types/DetailDocument.js.map +1 -0
- package/lib/types/DiffBlock.d.ts.map +1 -0
- package/lib/types/DiffBlock.js.map +1 -0
- package/lib/types/DisclosureRow.d.ts.map +1 -0
- package/lib/types/DisclosureRow.js.map +1 -0
- package/lib/types/DraggableImage.d.ts.map +1 -0
- package/lib/types/DraggableImage.js.map +1 -0
- package/lib/types/FileTypeIcon.d.ts.map +1 -0
- package/lib/types/FileTypeIcon.js.map +1 -0
- package/lib/types/FishLogo.d.ts.map +1 -0
- package/lib/types/FishLogo.js.map +1 -0
- package/lib/types/FoldToggle.d.ts.map +1 -0
- package/lib/types/FoldToggle.js.map +1 -0
- package/lib/types/HoverCard.d.ts.map +1 -0
- package/lib/types/HoverCard.js.map +1 -0
- package/lib/types/HoverCardGroup.d.ts.map +1 -0
- package/lib/types/HoverCardGroup.js.map +1 -0
- package/lib/types/ImageLightbox.d.ts.map +1 -0
- package/lib/types/ImageLightbox.js.map +1 -0
- package/lib/types/ImagePreview.d.ts.map +1 -0
- package/lib/types/ImagePreview.js.map +1 -0
- package/lib/types/InlineEditor.d.ts.map +1 -0
- package/lib/types/InlineEditor.js.map +1 -0
- package/lib/types/Input.d.ts.map +1 -0
- package/lib/types/Input.js.map +1 -0
- package/lib/types/JsonTree.d.ts.map +1 -0
- package/lib/types/JsonTree.js.map +1 -0
- package/lib/types/LinkIcon.d.ts.map +1 -0
- package/lib/types/LinkIcon.js.map +1 -0
- package/lib/types/Menu.d.ts +26 -14
- package/lib/types/Menu.d.ts.map +1 -0
- package/lib/types/Menu.js.map +1 -0
- package/lib/types/MenuGroup.d.ts.map +1 -0
- package/lib/types/MenuGroup.js.map +1 -0
- package/lib/types/MenuRow.d.ts +37 -0
- package/lib/types/MenuRow.d.ts.map +1 -0
- package/lib/types/MenuRow.js.map +1 -0
- package/lib/types/MenuSurface.d.ts.map +1 -0
- package/lib/types/MenuSurface.js.map +1 -0
- package/lib/types/Modal.d.ts +3 -1
- package/lib/types/Modal.d.ts.map +1 -0
- package/lib/types/Modal.js.map +1 -0
- package/lib/types/PathLabel.d.ts.map +1 -0
- package/lib/types/PathLabel.js.map +1 -0
- package/lib/types/PermissionIcon.d.ts.map +1 -0
- package/lib/types/PermissionIcon.js.map +1 -0
- package/lib/types/Pill.d.ts.map +1 -0
- package/lib/types/Pill.js.map +1 -0
- package/lib/types/QuotePreview.d.ts +17 -4
- package/lib/types/QuotePreview.d.ts.map +1 -0
- package/lib/types/QuotePreview.js.map +1 -0
- package/lib/types/ReadBlock.d.ts.map +1 -0
- package/lib/types/ReadBlock.js.map +1 -0
- package/lib/types/ReferenceIcon.d.ts.map +1 -0
- package/lib/types/ReferenceIcon.js.map +1 -0
- package/lib/types/RiskConfirmation.d.ts.map +1 -0
- package/lib/types/RiskConfirmation.js.map +1 -0
- package/lib/types/SearchBlock.d.ts.map +1 -0
- package/lib/types/SearchBlock.js.map +1 -0
- package/lib/types/SegmentedControl.d.ts.map +1 -0
- package/lib/types/SegmentedControl.js.map +1 -0
- package/lib/types/SegmentedTabs.d.ts.map +1 -0
- package/lib/types/SegmentedTabs.js.map +1 -0
- package/lib/types/ShortcutKeys.d.ts.map +1 -0
- package/lib/types/ShortcutKeys.js.map +1 -0
- package/lib/types/SiteGlyph.d.ts.map +1 -0
- package/lib/types/SiteGlyph.js.map +1 -0
- package/lib/types/StateDot.d.ts.map +1 -0
- package/lib/types/StateDot.js.map +1 -0
- package/lib/types/SubmenuPanel.d.ts +19 -0
- package/lib/types/SubmenuPanel.d.ts.map +1 -0
- package/lib/types/SubmenuPanel.js.map +1 -0
- package/lib/types/Switch.d.ts.map +1 -0
- package/lib/types/Switch.js.map +1 -0
- package/lib/types/Tag.d.ts.map +1 -0
- package/lib/types/Tag.js.map +1 -0
- package/lib/types/TerminalBlock.d.ts.map +1 -0
- package/lib/types/TerminalBlock.js.map +1 -0
- package/lib/types/TextShimmer.d.ts.map +1 -0
- package/lib/types/TextShimmer.js.map +1 -0
- package/lib/types/Toast.d.ts.map +1 -0
- package/lib/types/Toast.js.map +1 -0
- package/lib/types/Tooltip.d.ts.map +1 -0
- package/lib/types/Tooltip.js.map +1 -0
- package/lib/types/UserMessageBubble.d.ts.map +1 -0
- package/lib/types/UserMessageBubble.js.map +1 -0
- package/lib/types/WebBlock.d.ts.map +1 -0
- package/lib/types/WebBlock.js.map +1 -0
- package/lib/types/ZoomControls.d.ts.map +1 -0
- package/lib/types/ZoomControls.js.map +1 -0
- package/lib/types/ansi.d.ts.map +1 -0
- package/lib/types/ansi.js.map +1 -0
- package/lib/types/clipboard.d.ts.map +1 -0
- package/lib/types/clipboard.js.map +1 -0
- package/lib/types/code-file-icon-artwork.d.ts.map +1 -0
- package/lib/types/code-file-icon-artwork.js.map +1 -0
- package/lib/types/code-file-types.d.ts.map +1 -0
- package/lib/types/code-file-types.js.map +1 -0
- package/lib/types/code-highlighting.d.ts.map +1 -0
- package/lib/types/code-highlighting.js.map +1 -0
- package/lib/types/darwin-desktop.d.ts.map +1 -0
- package/lib/types/darwin-desktop.js.map +1 -0
- package/lib/types/document-zoom.d.ts.map +1 -0
- package/lib/types/document-zoom.js.map +1 -0
- package/lib/types/file-drag-actions.d.ts.map +1 -0
- package/lib/types/file-drag-actions.js.map +1 -0
- package/lib/types/file-size.d.ts.map +1 -0
- package/lib/types/file-size.js.map +1 -0
- package/lib/types/focus.d.ts.map +1 -0
- package/lib/types/focus.js.map +1 -0
- package/lib/types/guide-artwork.d.ts.map +1 -0
- package/lib/types/guide-artwork.js.map +1 -0
- package/lib/types/head-tail-cap.d.ts.map +1 -0
- package/lib/types/head-tail-cap.js.map +1 -0
- package/lib/types/icons/artwork.d.ts +12 -0
- package/lib/types/icons/artwork.d.ts.map +1 -0
- package/lib/types/icons/artwork.js.map +1 -0
- package/lib/types/icons/index.d.ts +12 -0
- package/lib/types/icons/index.d.ts.map +1 -0
- package/lib/types/icons/index.js.map +1 -0
- package/lib/types/icons/props.d.ts.map +1 -0
- package/lib/types/icons/props.js.map +1 -0
- package/lib/types/icons/shared-artwork.d.ts.map +1 -0
- package/lib/types/icons/shared-artwork.js.map +1 -0
- package/lib/types/image-drag.d.ts.map +1 -0
- package/lib/types/image-drag.js.map +1 -0
- package/lib/types/index.d.ts +5 -4
- package/lib/types/index.d.ts.map +1 -0
- package/lib/types/index.js.map +1 -0
- package/lib/types/input-modality.d.ts.map +1 -0
- package/lib/types/input-modality.js.map +1 -0
- package/lib/types/keyboard-composition.d.ts.map +1 -0
- package/lib/types/keyboard-composition.js.map +1 -0
- package/lib/types/markdown/CodeBlock.d.ts +8 -1
- package/lib/types/markdown/CodeBlock.d.ts.map +1 -0
- package/lib/types/markdown/CodeBlock.js.map +1 -0
- package/lib/types/markdown/FenceBlocks.d.ts +31 -0
- package/lib/types/markdown/FenceBlocks.d.ts.map +1 -0
- package/lib/types/markdown/FenceBlocks.js.map +1 -0
- package/lib/types/markdown/JsonBlock.d.ts.map +1 -0
- package/lib/types/markdown/JsonBlock.js.map +1 -0
- package/lib/types/markdown/MarkdownDelegate.d.ts +23 -1
- package/lib/types/markdown/MarkdownDelegate.d.ts.map +1 -0
- package/lib/types/markdown/MarkdownDelegate.js.map +1 -0
- package/lib/types/markdown/MarkdownText.d.ts +2 -0
- package/lib/types/markdown/MarkdownText.d.ts.map +1 -0
- package/lib/types/markdown/MarkdownText.js.map +1 -0
- package/lib/types/markdown/cjkFriendlyStrong.d.ts.map +1 -0
- package/lib/types/markdown/cjkFriendlyStrong.js.map +1 -0
- package/lib/types/markdown/copy-tex.d.ts +14 -0
- package/lib/types/markdown/copy-tex.d.ts.map +1 -0
- package/lib/types/markdown/copy-tex.js.map +1 -0
- package/lib/types/markdown/diff-fence.d.ts +58 -0
- package/lib/types/markdown/diff-fence.d.ts.map +1 -0
- package/lib/types/markdown/diff-fence.js.map +1 -0
- package/lib/types/markdown/file-link.d.ts.map +1 -0
- package/lib/types/markdown/file-link.js.map +1 -0
- package/lib/types/markdown/highlight.d.ts +18 -0
- package/lib/types/markdown/highlight.d.ts.map +1 -0
- package/lib/types/markdown/highlight.js.map +1 -0
- package/lib/types/markdown/incremental.d.ts.map +1 -0
- package/lib/types/markdown/incremental.js.map +1 -0
- package/lib/types/markdown/katex.d.ts.map +1 -0
- package/lib/types/markdown/katex.js.map +1 -0
- package/lib/types/markdown/local-image-syntax.d.ts.map +1 -0
- package/lib/types/markdown/local-image-syntax.js.map +1 -0
- package/lib/types/markdown/mathCompatibility.d.ts.map +1 -0
- package/lib/types/markdown/mathCompatibility.js.map +1 -0
- package/lib/types/markdown/parse.d.ts.map +1 -0
- package/lib/types/markdown/parse.js.map +1 -0
- package/lib/types/markdown/plain-text.d.ts.map +1 -0
- package/lib/types/markdown/plain-text.js.map +1 -0
- package/lib/types/markdown/quote-text.d.ts.map +1 -0
- package/lib/types/markdown/quote-text.js.map +1 -0
- package/lib/types/markdown/render.d.ts.map +1 -0
- package/lib/types/markdown/render.js.map +1 -0
- package/lib/types/markdown/useViewportHighlighting.d.ts.map +1 -0
- package/lib/types/markdown/useViewportHighlighting.js.map +1 -0
- package/lib/types/markdown/windows-path-destinations.d.ts.map +1 -0
- package/lib/types/markdown/windows-path-destinations.js.map +1 -0
- package/lib/types/menu-submenu-position.d.ts +15 -0
- package/lib/types/menu-submenu-position.d.ts.map +1 -0
- package/lib/types/menu-submenu-position.js.map +1 -0
- package/lib/types/overlay-top-margin.d.ts.map +1 -0
- package/lib/types/overlay-top-margin.js.map +1 -0
- package/lib/types/plugin-artwork.d.ts.map +1 -0
- package/lib/types/plugin-artwork.js.map +1 -0
- package/lib/types/pointer-grace.d.ts.map +1 -0
- package/lib/types/pointer-grace.js.map +1 -0
- package/lib/types/rank-by-name.d.ts.map +1 -0
- package/lib/types/rank-by-name.js.map +1 -0
- package/lib/types/relative-time.d.ts.map +1 -0
- package/lib/types/relative-time.js.map +1 -0
- package/lib/types/settings-form/SettingsForm.d.ts.map +1 -0
- package/lib/types/settings-form/SettingsForm.js.map +1 -0
- package/lib/types/settings-form/fields.d.ts.map +1 -0
- package/lib/types/settings-form/fields.js.map +1 -0
- package/lib/types/settings-form/form-model.d.ts.map +1 -0
- package/lib/types/settings-form/form-model.js.map +1 -0
- package/lib/types/tooltip-placement.d.ts.map +1 -0
- package/lib/types/tooltip-placement.js.map +1 -0
- package/lib/types/use-clipboard-copy.d.ts.map +1 -0
- package/lib/types/use-clipboard-copy.js.map +1 -0
- package/lib/types/useAnchoredMaxHeight.d.ts.map +1 -0
- package/lib/types/useAnchoredMaxHeight.js.map +1 -0
- package/lib/types/useDismissOnOutsidePointer.d.ts.map +1 -0
- package/lib/types/useDismissOnOutsidePointer.js.map +1 -0
- package/lib/types/useMenuSubmenu.d.ts +43 -0
- package/lib/types/useMenuSubmenu.d.ts.map +1 -0
- package/lib/types/useMenuSubmenu.js.map +1 -0
- package/lib/types/useModalLayer.d.ts.map +1 -0
- package/lib/types/useModalLayer.js.map +1 -0
- package/lib/types/useRowDragPreview.d.ts.map +1 -0
- package/lib/types/useRowDragPreview.js.map +1 -0
- package/lib/types/user-text.d.ts.map +1 -0
- package/lib/types/user-text.js.map +1 -0
- package/package.json +9 -6
- package/src/AnimatedRows.module.css +7 -0
- package/src/AnimatedRows.tsx +195 -0
- package/src/BrandWordmark.tsx +59 -0
- package/src/Button.module.css +84 -0
- package/src/Button.tsx +36 -0
- package/src/Checkbox.module.css +28 -0
- package/src/Checkbox.tsx +34 -0
- package/src/CodeCard.module.css +85 -0
- package/src/CodeFileIcon.tsx +28 -0
- package/src/CodeToolbar.tsx +62 -0
- package/src/CommandText.module.css +12 -0
- package/src/CommandText.tsx +46 -0
- package/src/ConfigField.module.css +12 -0
- package/src/ConfigField.tsx +53 -0
- package/src/ConnectionIndicator.module.css +120 -0
- package/src/ConnectionIndicator.tsx +103 -0
- package/src/DetailDocument.module.css +67 -0
- package/src/DetailDocument.tsx +120 -0
- package/src/DiffBlock.module.css +82 -0
- package/src/DiffBlock.tsx +221 -0
- package/src/DisclosureRow.module.css +115 -0
- package/src/DisclosureRow.tsx +124 -0
- package/src/DraggableImage.tsx +26 -0
- package/src/FileTypeIcon.module.css +50 -0
- package/src/FileTypeIcon.tsx +285 -0
- package/src/FishLogo.tsx +28 -0
- package/src/FoldToggle.tsx +33 -0
- package/src/HoverCard.module.css +108 -0
- package/src/HoverCard.tsx +356 -0
- package/src/HoverCardGroup.tsx +77 -0
- package/src/ImageLightbox.module.css +54 -0
- package/src/ImageLightbox.tsx +72 -0
- package/src/ImagePreview.module.css +24 -0
- package/src/ImagePreview.tsx +36 -0
- package/src/InlineEditor.module.css +23 -0
- package/src/InlineEditor.tsx +69 -0
- package/src/Input.module.css +38 -0
- package/src/Input.tsx +24 -0
- package/src/JsonTree.module.css +371 -0
- package/src/JsonTree.tsx +850 -0
- package/src/LinkIcon.tsx +118 -0
- package/src/Menu.module.css +443 -0
- package/src/Menu.tsx +553 -0
- package/src/MenuGroup.module.css +37 -0
- package/src/MenuGroup.tsx +103 -0
- package/src/MenuRow.tsx +89 -0
- package/src/MenuSurface.module.css +65 -0
- package/src/MenuSurface.tsx +54 -0
- package/src/Modal.module.css +147 -0
- package/src/Modal.tsx +96 -0
- package/src/PathLabel.module.css +28 -0
- package/src/PathLabel.tsx +41 -0
- package/src/PermissionIcon.tsx +119 -0
- package/src/Pill.module.css +30 -0
- package/src/Pill.tsx +36 -0
- package/src/QuotePreview.module.css +138 -0
- package/src/QuotePreview.tsx +133 -0
- package/src/ReadBlock.module.css +45 -0
- package/src/ReadBlock.tsx +151 -0
- package/src/ReferenceIcon.tsx +49 -0
- package/src/RiskConfirmation.module.css +47 -0
- package/src/RiskConfirmation.tsx +79 -0
- package/src/RowDragPreview.module.css +12 -0
- package/src/SearchBlock.module.css +114 -0
- package/src/SearchBlock.tsx +281 -0
- package/src/SegmentedControl.module.css +81 -0
- package/src/SegmentedControl.tsx +140 -0
- package/src/SegmentedTabs.module.css +77 -0
- package/src/SegmentedTabs.tsx +84 -0
- package/src/ShortcutKeys.module.css +33 -0
- package/src/ShortcutKeys.tsx +12 -0
- package/src/SiteGlyph.tsx +149 -0
- package/src/StateDot.module.css +100 -0
- package/src/StateDot.tsx +77 -0
- package/src/SubmenuPanel.tsx +51 -0
- package/src/Switch.module.css +49 -0
- package/src/Switch.tsx +42 -0
- package/src/Tag.module.css +57 -0
- package/src/Tag.tsx +42 -0
- package/src/TerminalBlock.module.css +207 -0
- package/src/TerminalBlock.tsx +294 -0
- package/src/TextShimmer.module.css +88 -0
- package/src/TextShimmer.tsx +58 -0
- package/src/Toast.module.css +102 -0
- package/src/Toast.tsx +101 -0
- package/src/Tooltip.module.css +68 -0
- package/src/Tooltip.tsx +273 -0
- package/src/UserMessageBubble.module.css +11 -0
- package/src/UserMessageBubble.tsx +16 -0
- package/src/WebBlock.module.css +153 -0
- package/src/WebBlock.tsx +196 -0
- package/src/ZoomControls.module.css +54 -0
- package/src/ZoomControls.tsx +92 -0
- package/src/ansi.ts +447 -0
- package/src/clipboard.ts +47 -0
- package/src/code-file-icon-artwork.manifest.json +71 -0
- package/src/code-file-icon-artwork.ts +60 -0
- package/src/code-file-types.ts +340 -0
- package/src/code-highlighting.ts +25 -0
- package/src/css-modules.d.ts +6 -0
- package/src/darwin-desktop.ts +11 -0
- package/src/document-zoom.ts +12 -0
- package/src/file-drag-actions.ts +29 -0
- package/src/file-size.ts +16 -0
- package/src/focus.ts +44 -0
- package/src/guide-artwork.tsx +32 -0
- package/src/head-tail-cap.ts +27 -0
- package/src/icons/artwork.ts +156 -0
- package/src/icons/index.tsx +634 -0
- package/src/icons/props.ts +8 -0
- package/src/icons/shared-artwork.tsx +71 -0
- package/src/image-drag.ts +84 -0
- package/src/index.ts +142 -0
- package/src/input-modality.ts +59 -0
- package/src/keyboard-composition.ts +36 -0
- package/src/markdown/CodeBlock.module.css +209 -0
- package/src/markdown/CodeBlock.tsx +268 -0
- package/src/markdown/FenceBlocks.tsx +51 -0
- package/src/markdown/JsonBlock.module.css +34 -0
- package/src/markdown/JsonBlock.tsx +36 -0
- package/src/markdown/MarkdownDelegate.tsx +102 -0
- package/src/markdown/MarkdownText.module.css +511 -0
- package/src/markdown/MarkdownText.tsx +218 -0
- package/src/markdown/cjkFriendlyStrong.ts +83 -0
- package/src/markdown/copy-tex.ts +53 -0
- package/src/markdown/diff-fence.ts +212 -0
- package/src/markdown/file-link.ts +45 -0
- package/src/markdown/highlight.ts +689 -0
- package/src/markdown/incremental.ts +360 -0
- package/src/markdown/katex.tsx +90 -0
- package/src/markdown/local-image-syntax.ts +29 -0
- package/src/markdown/mathCompatibility.ts +349 -0
- package/src/markdown/parse.ts +49 -0
- package/src/markdown/plain-text.ts +121 -0
- package/src/markdown/quote-text.ts +10 -0
- package/src/markdown/render.tsx +834 -0
- package/src/markdown/useViewportHighlighting.ts +72 -0
- package/src/markdown/windows-path-destinations.ts +34 -0
- package/src/menu-submenu-position.ts +20 -0
- package/src/overlay-top-margin.ts +18 -0
- package/src/plugin-artwork.tsx +110 -0
- package/src/pointer-grace.ts +47 -0
- package/src/rank-by-name.ts +93 -0
- package/src/relative-time.ts +36 -0
- package/src/settings-form/SettingsForm.module.css +53 -0
- package/src/settings-form/SettingsForm.tsx +74 -0
- package/src/settings-form/fields.module.css +153 -0
- package/src/settings-form/fields.tsx +151 -0
- package/src/settings-form/form-model.ts +393 -0
- package/src/tooltip-placement.ts +60 -0
- package/src/use-clipboard-copy.ts +44 -0
- package/src/useAnchoredMaxHeight.ts +45 -0
- package/src/useDismissOnOutsidePointer.ts +34 -0
- package/src/useMenuSubmenu.ts +182 -0
- package/src/useModalLayer.ts +108 -0
- package/src/useRowDragPreview.ts +76 -0
- package/src/user-text.module.css +46 -0
- package/src/user-text.tsx +67 -0
- package/lib/types/useAnchoredPosition.d.ts +0 -36
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
// SegmentedControl: a tablist of two or more equal-width segments with one
|
|
2
|
+
// sliding indicator, for switching a card or panel between a few modes. The
|
|
3
|
+
// owner holds the selection; `label` is required so the tablist never ships
|
|
4
|
+
// without an accessible name, and every segment label is owner-localized.
|
|
5
|
+
// Each tab is `<id>-<value>` and controls the panel `<id>-<value>-panel`, the
|
|
6
|
+
// element the owner renders for that mode and points back at the tab with
|
|
7
|
+
// `aria-labelledby`.
|
|
8
|
+
|
|
9
|
+
import { useEffect, useRef } from 'react'
|
|
10
|
+
import type { CSSProperties, KeyboardEvent } from 'react'
|
|
11
|
+
import clsx from 'clsx'
|
|
12
|
+
import css from './SegmentedControl.module.css'
|
|
13
|
+
|
|
14
|
+
/** One segment of a {@link SegmentedControl}. */
|
|
15
|
+
export interface SegmentedControlOption<Value extends string> {
|
|
16
|
+
/** The value the owner receives when this segment is chosen. */
|
|
17
|
+
value: Value
|
|
18
|
+
/** Localized segment text. */
|
|
19
|
+
label: string
|
|
20
|
+
/** Whether the segment refuses selection. */
|
|
21
|
+
disabled?: boolean
|
|
22
|
+
/** Localized hover text, typically why the segment is locked. */
|
|
23
|
+
title?: string
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** The keys that walk the tablist, per the WAI-ARIA tabs pattern. */
|
|
27
|
+
type WalkKey = 'ArrowLeft' | 'ArrowRight' | 'ArrowUp' | 'ArrowDown' | 'Home' | 'End'
|
|
28
|
+
|
|
29
|
+
function isWalkKey(key: string): key is WalkKey {
|
|
30
|
+
return key === 'ArrowLeft' || key === 'ArrowRight' || key === 'ArrowUp' || key === 'ArrowDown'
|
|
31
|
+
|| key === 'Home' || key === 'End'
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* The enabled option a walk key lands on from the selected one: arrows step
|
|
36
|
+
* to the nearest enabled neighbour and wrap, Home and End jump to the first
|
|
37
|
+
* and last enabled option.
|
|
38
|
+
*/
|
|
39
|
+
function walk<Value extends string>(
|
|
40
|
+
options: readonly SegmentedControlOption<Value>[],
|
|
41
|
+
from: number,
|
|
42
|
+
key: WalkKey,
|
|
43
|
+
): SegmentedControlOption<Value> | undefined {
|
|
44
|
+
const enabled = options.filter(option => option.disabled !== true)
|
|
45
|
+
if (key === 'Home') return enabled[0]
|
|
46
|
+
if (key === 'End') return enabled[enabled.length - 1]
|
|
47
|
+
const step = key === 'ArrowRight' || key === 'ArrowDown' ? 1 : -1
|
|
48
|
+
const count = options.length
|
|
49
|
+
for (let offset = 1; offset < count; offset += 1) {
|
|
50
|
+
const candidate = options[((from + step * offset) % count + count) % count]
|
|
51
|
+
if (candidate !== undefined && candidate.disabled !== true) return candidate
|
|
52
|
+
}
|
|
53
|
+
return undefined
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Render a segmented control.
|
|
58
|
+
* @param props.id - the owner's base id: each tab is `<id>-<value>` and names
|
|
59
|
+
* `<id>-<value>-panel` as the panel it controls.
|
|
60
|
+
* @param props.value - the selected option's value; the control is fully controlled.
|
|
61
|
+
* @param props.options - the segments in display order; at least two.
|
|
62
|
+
* @param props.onChange - called with the value a click or a walk key asks for,
|
|
63
|
+
* never with the value already selected.
|
|
64
|
+
* @param props.label - localized accessible name of the tablist.
|
|
65
|
+
* @param props.disabled - lock every segment, typically while the shown panel
|
|
66
|
+
* has a write or a fetch in flight that switching would orphan.
|
|
67
|
+
* @param props.className - extra class for layout placement.
|
|
68
|
+
* @returns the tablist element.
|
|
69
|
+
*/
|
|
70
|
+
export function SegmentedControl<Value extends string>({
|
|
71
|
+
id, value, options, onChange, label, disabled = false, className,
|
|
72
|
+
}: {
|
|
73
|
+
id: string
|
|
74
|
+
value: Value
|
|
75
|
+
options: readonly SegmentedControlOption<Value>[]
|
|
76
|
+
onChange: (next: Value) => void
|
|
77
|
+
label: string
|
|
78
|
+
disabled?: boolean
|
|
79
|
+
// `| undefined` so a caller can forward an optional class straight through
|
|
80
|
+
// under exactOptionalPropertyTypes (a CSS-module lookup is string|undefined).
|
|
81
|
+
className?: string | undefined
|
|
82
|
+
}) {
|
|
83
|
+
const list = useRef<HTMLDivElement>(null)
|
|
84
|
+
const selected = options.findIndex(option => option.value === value)
|
|
85
|
+
|
|
86
|
+
// A walk key reports the next value and the owner re-renders with it; the
|
|
87
|
+
// keyboard then follows the selection so the roving tabindex stays usable.
|
|
88
|
+
useEffect(() => {
|
|
89
|
+
const root = list.current
|
|
90
|
+
/* v8 ignore next -- the ref is attached to the always-rendered root before any effect runs. */
|
|
91
|
+
if (root === null) return
|
|
92
|
+
if (!root.contains(document.activeElement)) return
|
|
93
|
+
root.querySelector<HTMLButtonElement>('[role="tab"][aria-selected="true"]')?.focus()
|
|
94
|
+
}, [value])
|
|
95
|
+
|
|
96
|
+
const onKeyDown = (event: KeyboardEvent<HTMLButtonElement>): void => {
|
|
97
|
+
if (!isWalkKey(event.key)) return
|
|
98
|
+
event.preventDefault()
|
|
99
|
+
const target = walk(options, selected, event.key)
|
|
100
|
+
if (target !== undefined && target.value !== value) onChange(target.value)
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const indicator = {
|
|
104
|
+
'--dsh-segment-count': String(options.length),
|
|
105
|
+
'--dsh-segment-index': String(selected),
|
|
106
|
+
} as CSSProperties
|
|
107
|
+
|
|
108
|
+
return (
|
|
109
|
+
<div
|
|
110
|
+
ref={list}
|
|
111
|
+
role="tablist"
|
|
112
|
+
aria-label={label}
|
|
113
|
+
className={clsx(css.control, className)}
|
|
114
|
+
style={indicator}
|
|
115
|
+
>
|
|
116
|
+
<span aria-hidden="true" className={css.indicator} />
|
|
117
|
+
{options.map((option) => {
|
|
118
|
+
const active = option.value === value
|
|
119
|
+
return (
|
|
120
|
+
<button
|
|
121
|
+
key={option.value}
|
|
122
|
+
id={`${id}-${option.value}`}
|
|
123
|
+
type="button"
|
|
124
|
+
role="tab"
|
|
125
|
+
aria-selected={active}
|
|
126
|
+
aria-controls={`${id}-${option.value}-panel`}
|
|
127
|
+
tabIndex={active ? 0 : -1}
|
|
128
|
+
disabled={disabled || option.disabled === true}
|
|
129
|
+
title={option.title}
|
|
130
|
+
className={css.tab}
|
|
131
|
+
onClick={() => { if (!active) onChange(option.value) }}
|
|
132
|
+
onKeyDown={onKeyDown}
|
|
133
|
+
>
|
|
134
|
+
{option.label}
|
|
135
|
+
</button>
|
|
136
|
+
)
|
|
137
|
+
})}
|
|
138
|
+
</div>
|
|
139
|
+
)
|
|
140
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
.tabs {
|
|
2
|
+
--segmented-tabs-inset: 4px;
|
|
3
|
+
|
|
4
|
+
position: relative;
|
|
5
|
+
display: grid;
|
|
6
|
+
padding: var(--segmented-tabs-inset);
|
|
7
|
+
border-radius: var(--dsw-radius-lg);
|
|
8
|
+
background: var(--dsw-alias-bg-module-platform);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
.indicator {
|
|
12
|
+
position: absolute;
|
|
13
|
+
inset: var(--segmented-tabs-inset) auto var(--segmented-tabs-inset) var(--segmented-tabs-inset);
|
|
14
|
+
box-sizing: border-box;
|
|
15
|
+
border: 0.5px solid var(--dsw-alias-border-l3);
|
|
16
|
+
border-radius: var(--dsw-radius-md);
|
|
17
|
+
background: var(--dsw-alias-bg-layer-3);
|
|
18
|
+
transition: transform 180ms ease;
|
|
19
|
+
pointer-events: none;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
.tab {
|
|
23
|
+
position: relative;
|
|
24
|
+
justify-content: center;
|
|
25
|
+
height: 34px;
|
|
26
|
+
padding: 0 12px;
|
|
27
|
+
border-radius: var(--dsw-radius-md);
|
|
28
|
+
font-size: 14px;
|
|
29
|
+
line-height: 20px;
|
|
30
|
+
background: transparent;
|
|
31
|
+
color: var(--dsw-alias-label-secondary);
|
|
32
|
+
transition: color 180ms ease;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
.tab[aria-selected='true'] {
|
|
36
|
+
background: transparent;
|
|
37
|
+
color: var(--dsw-alias-label-primary);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
@media (hover: hover) {
|
|
41
|
+
.tab:hover {
|
|
42
|
+
background: transparent;
|
|
43
|
+
color: var(--dsw-alias-label-primary);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
.tab[aria-selected='true'] {
|
|
48
|
+
font-weight: 600;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
.tabs[data-size='sm'] {
|
|
52
|
+
--segmented-tabs-inset: 2px;
|
|
53
|
+
|
|
54
|
+
border-radius: calc(var(--dsw-radius-md) + var(--segmented-tabs-inset));
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
.tabs[data-size='sm'] .tab {
|
|
58
|
+
height: 30px;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
.tabs[data-size='sm'] .tab[aria-selected='true'] {
|
|
62
|
+
font-weight: 500;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
.tab:focus-visible {
|
|
66
|
+
outline: none;
|
|
67
|
+
text-decoration: underline;
|
|
68
|
+
text-decoration-thickness: 1px;
|
|
69
|
+
text-underline-offset: 4px;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
@media (prefers-reduced-motion: reduce) {
|
|
73
|
+
.indicator,
|
|
74
|
+
.tab {
|
|
75
|
+
transition: none;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import type { KeyboardEvent, ReactNode } from 'react'
|
|
2
|
+
import clsx from 'clsx'
|
|
3
|
+
import { Pill } from './Pill.tsx'
|
|
4
|
+
import css from './SegmentedTabs.module.css'
|
|
5
|
+
|
|
6
|
+
/** A tab links its localized label to a caller-owned panel. */
|
|
7
|
+
export interface SegmentedTab<Value extends string = string> {
|
|
8
|
+
value: Value
|
|
9
|
+
label: ReactNode
|
|
10
|
+
id: string
|
|
11
|
+
panelId: string
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Render equal-width, controlled tabs with a sliding selection indicator.
|
|
16
|
+
* @param props.items - non-empty ordered tabs with unique values and DOM ids.
|
|
17
|
+
* @param props.value - selected value, which must belong to items.
|
|
18
|
+
* @param props.onChange - selection requested by click, Left/Right, or Home/End.
|
|
19
|
+
* Keyboard selection also moves focus; only the selected tab is a tab stop.
|
|
20
|
+
* @param props.label - localized accessible name for the tab list.
|
|
21
|
+
* @param props.className - layout placement; panels remain caller-owned.
|
|
22
|
+
* @param props.size - `sm` draws 30px tabs with a 2px inset (34px tall); the default `md` draws 34px tabs with a 4px inset (42px tall).
|
|
23
|
+
* @returns the tab list, without its panels.
|
|
24
|
+
*/
|
|
25
|
+
export function SegmentedTabs<Value extends string>({ items, value, onChange, label, className, size = 'md' }: {
|
|
26
|
+
items: readonly [SegmentedTab<Value>, ...SegmentedTab<Value>[]]
|
|
27
|
+
value: Value
|
|
28
|
+
onChange: (value: Value) => void
|
|
29
|
+
label: string
|
|
30
|
+
className?: string | undefined
|
|
31
|
+
size?: 'sm' | 'md' | undefined
|
|
32
|
+
}): ReactNode {
|
|
33
|
+
const selectedIndex = items.findIndex(item => item.value === value)
|
|
34
|
+
|
|
35
|
+
const onKeyDown = (event: KeyboardEvent<HTMLButtonElement>, index: number) => {
|
|
36
|
+
let next: number
|
|
37
|
+
switch (event.key) {
|
|
38
|
+
case 'ArrowLeft': next = (index + items.length - 1) % items.length; break
|
|
39
|
+
case 'ArrowRight': next = (index + 1) % items.length; break
|
|
40
|
+
case 'Home': next = 0; break
|
|
41
|
+
case 'End': next = items.length - 1; break
|
|
42
|
+
default: return
|
|
43
|
+
}
|
|
44
|
+
event.preventDefault()
|
|
45
|
+
event.stopPropagation()
|
|
46
|
+
const tablist = event.currentTarget.parentElement
|
|
47
|
+
const nextItem = items[next]
|
|
48
|
+
/* v8 ignore next -- the event comes from a mounted direct child and next is bounded by non-empty items. */
|
|
49
|
+
if (tablist === null || nextItem === undefined) return
|
|
50
|
+
tablist.querySelectorAll<HTMLButtonElement>('[role="tab"]').item(next).focus()
|
|
51
|
+
onChange(nextItem.value)
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return (
|
|
55
|
+
<div
|
|
56
|
+
role="tablist"
|
|
57
|
+
data-size={size}
|
|
58
|
+
aria-label={label}
|
|
59
|
+
className={clsx(css.tabs, className)}
|
|
60
|
+
style={{ gridTemplateColumns: `repeat(${items.length}, minmax(0, 1fr))` }}
|
|
61
|
+
>
|
|
62
|
+
<span
|
|
63
|
+
className={css.indicator}
|
|
64
|
+
aria-hidden="true"
|
|
65
|
+
style={{ width: `calc((100% - 2 * var(--segmented-tabs-inset)) / ${items.length})`, transform: `translateX(${selectedIndex * 100}%)` }}
|
|
66
|
+
/>
|
|
67
|
+
{items.map((item, index) => (
|
|
68
|
+
<Pill
|
|
69
|
+
key={item.value}
|
|
70
|
+
id={item.id}
|
|
71
|
+
role="tab"
|
|
72
|
+
className={css.tab}
|
|
73
|
+
aria-selected={value === item.value}
|
|
74
|
+
aria-controls={item.panelId}
|
|
75
|
+
tabIndex={value === item.value ? 0 : -1}
|
|
76
|
+
onClick={() => { onChange(item.value) }}
|
|
77
|
+
onKeyDown={(event) => { onKeyDown(event, index) }}
|
|
78
|
+
>
|
|
79
|
+
{item.label}
|
|
80
|
+
</Pill>
|
|
81
|
+
))}
|
|
82
|
+
</div>
|
|
83
|
+
)
|
|
84
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
.keys {
|
|
2
|
+
display: inline-flex;
|
|
3
|
+
flex: none;
|
|
4
|
+
align-items: center;
|
|
5
|
+
gap: 3px;
|
|
6
|
+
color: var(--dsw-alias-label-tertiary);
|
|
7
|
+
font-size: 12px;
|
|
8
|
+
line-height: 16px;
|
|
9
|
+
white-space: nowrap;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
.key {
|
|
13
|
+
box-sizing: border-box;
|
|
14
|
+
display: inline-flex;
|
|
15
|
+
align-items: center;
|
|
16
|
+
justify-content: center;
|
|
17
|
+
font: inherit;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
.tooltip { color: inherit; font-size: 11px; line-height: 14px; gap: 2px; }
|
|
21
|
+
.tooltip .key {
|
|
22
|
+
min-width: 16px;
|
|
23
|
+
height: 16px;
|
|
24
|
+
padding: 0 2px;
|
|
25
|
+
border-radius: 4px;
|
|
26
|
+
border: 0;
|
|
27
|
+
background: var(--dsw-alias-tooltip-key-bg);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
.separator { font: inherit; }
|
|
31
|
+
|
|
32
|
+
.joined { box-sizing: border-box; height: 16px; padding: 0 4px; border-radius: 4px; background: var(--dsw-alias-tooltip-key-bg); }
|
|
33
|
+
.joined .key { min-width: 0; height: auto; padding: 0; border: 0; background: transparent; }
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/** Shared shortcut keycaps; callers supply the effective platform presentation. */
|
|
2
|
+
import css from './ShortcutKeys.module.css'
|
|
3
|
+
import clsx from 'clsx'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Render one command's keycaps without owning binding defaults or localized copy.
|
|
7
|
+
* @param props - effective key labels, presentation variant and optional interaction styling.
|
|
8
|
+
* @returns unboxed keys by default, or tooltip keycaps with plus-separated combinations grouped together.
|
|
9
|
+
*/
|
|
10
|
+
export function ShortcutKeys({ keys, variant = 'plain', className }: { keys: readonly string[]; variant?: 'plain' | 'tooltip'; className?: string | undefined }) {
|
|
11
|
+
return <span className={clsx(css.keys, variant === 'tooltip' && css.tooltip, variant === 'tooltip' && keys.includes('+') && css.joined, className)}>{keys.map((key, index) => <kbd key={index} className={key === '+' ? css.separator : css.key}>{key}</kbd>)}</span>
|
|
12
|
+
}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Site marks for well-known external link hosts. {@link LinkIconMedium} renders one in
|
|
3
|
+
* the leading glyph seat, so a familiar destination leads with its own mark
|
|
4
|
+
* instead of the generic globe. The marks are the `simple-icons` artwork set
|
|
5
|
+
* (CC0-1.0), pinned by this package's dependency on it; each mark takes the
|
|
6
|
+
* link's `currentColor` rather than the brand fill that set records.
|
|
7
|
+
*/
|
|
8
|
+
import type { ReactElement } from 'react'
|
|
9
|
+
import {
|
|
10
|
+
siAliexpress,
|
|
11
|
+
siApple,
|
|
12
|
+
siBaidu,
|
|
13
|
+
siBilibili,
|
|
14
|
+
siCsdn,
|
|
15
|
+
siDuckduckgo,
|
|
16
|
+
siEbay,
|
|
17
|
+
siFacebook,
|
|
18
|
+
siGithub,
|
|
19
|
+
siGitlab,
|
|
20
|
+
siGoogle,
|
|
21
|
+
siInstagram,
|
|
22
|
+
siJuejin,
|
|
23
|
+
siMdnwebdocs,
|
|
24
|
+
siNetflix,
|
|
25
|
+
siNpm,
|
|
26
|
+
siPypi,
|
|
27
|
+
siQq,
|
|
28
|
+
siQuora,
|
|
29
|
+
siReddit,
|
|
30
|
+
siSinaweibo,
|
|
31
|
+
siSpotify,
|
|
32
|
+
siStackoverflow,
|
|
33
|
+
siTaobao,
|
|
34
|
+
siTelegram,
|
|
35
|
+
siTiktok,
|
|
36
|
+
siV2ex,
|
|
37
|
+
siWechat,
|
|
38
|
+
siWhatsapp,
|
|
39
|
+
siWikipedia,
|
|
40
|
+
siX,
|
|
41
|
+
siYcombinator,
|
|
42
|
+
siYoutube,
|
|
43
|
+
siZhihu,
|
|
44
|
+
} from 'simple-icons'
|
|
45
|
+
import type { SimpleIcon } from 'simple-icons'
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Host suffix to site mark, covering the developer sites the transcript
|
|
49
|
+
* usually cites plus the mainstream search, video, social, shopping, and
|
|
50
|
+
* reference sites a general audience links. A host matches a suffix when it
|
|
51
|
+
* equals it or is a subdomain of it, and the longest matching suffix wins, so
|
|
52
|
+
* `weixin.qq.com` keeps WeChat while `qq.com` keeps QQ and `gist.github.com`
|
|
53
|
+
* needs no entry of its own.
|
|
54
|
+
*/
|
|
55
|
+
const SITE_HOSTS: Readonly<Record<string, SimpleIcon>> = {
|
|
56
|
+
'github.com': siGithub,
|
|
57
|
+
'github.io': siGithub,
|
|
58
|
+
'raw.githubusercontent.com': siGithub,
|
|
59
|
+
'gitlab.com': siGitlab,
|
|
60
|
+
'npmjs.com': siNpm,
|
|
61
|
+
'pypi.org': siPypi,
|
|
62
|
+
'stackoverflow.com': siStackoverflow,
|
|
63
|
+
'developer.mozilla.org': siMdnwebdocs,
|
|
64
|
+
'wikipedia.org': siWikipedia,
|
|
65
|
+
'news.ycombinator.com': siYcombinator,
|
|
66
|
+
'youtube.com': siYoutube,
|
|
67
|
+
'youtu.be': siYoutube,
|
|
68
|
+
'x.com': siX,
|
|
69
|
+
'twitter.com': siX,
|
|
70
|
+
'bilibili.com': siBilibili,
|
|
71
|
+
'zhihu.com': siZhihu,
|
|
72
|
+
'juejin.cn': siJuejin,
|
|
73
|
+
'csdn.net': siCsdn,
|
|
74
|
+
'google.com': siGoogle,
|
|
75
|
+
'baidu.com': siBaidu,
|
|
76
|
+
'duckduckgo.com': siDuckduckgo,
|
|
77
|
+
'tiktok.com': siTiktok,
|
|
78
|
+
'netflix.com': siNetflix,
|
|
79
|
+
'spotify.com': siSpotify,
|
|
80
|
+
'facebook.com': siFacebook,
|
|
81
|
+
'instagram.com': siInstagram,
|
|
82
|
+
'reddit.com': siReddit,
|
|
83
|
+
'telegram.org': siTelegram,
|
|
84
|
+
't.me': siTelegram,
|
|
85
|
+
'weixin.qq.com': siWechat,
|
|
86
|
+
'qq.com': siQq,
|
|
87
|
+
'whatsapp.com': siWhatsapp,
|
|
88
|
+
'wa.me': siWhatsapp,
|
|
89
|
+
'weibo.com': siSinaweibo,
|
|
90
|
+
'taobao.com': siTaobao,
|
|
91
|
+
'aliexpress.com': siAliexpress,
|
|
92
|
+
'ebay.com': siEbay,
|
|
93
|
+
'quora.com': siQuora,
|
|
94
|
+
'v2ex.com': siV2ex,
|
|
95
|
+
'apple.com': siApple,
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Resolve the mark named by an external destination.
|
|
100
|
+
* @param href - The link destination; only an absolute http(s) URL can name a host.
|
|
101
|
+
* @returns The matched site mark, or undefined when the host is unknown or not http(s).
|
|
102
|
+
*/
|
|
103
|
+
function siteIcon(href: string): SimpleIcon | undefined {
|
|
104
|
+
let host: string
|
|
105
|
+
try {
|
|
106
|
+
const url = new URL(href)
|
|
107
|
+
if (url.protocol !== 'http:' && url.protocol !== 'https:') return undefined
|
|
108
|
+
host = url.hostname.toLowerCase()
|
|
109
|
+
} catch {
|
|
110
|
+
// Not an absolute URL: nothing here can name a host.
|
|
111
|
+
return undefined
|
|
112
|
+
}
|
|
113
|
+
let match: SimpleIcon | undefined
|
|
114
|
+
let matched = 0
|
|
115
|
+
for (const [suffix, icon] of Object.entries(SITE_HOSTS)) {
|
|
116
|
+
if ((host === suffix || host.endsWith(`.${suffix}`)) && suffix.length > matched) {
|
|
117
|
+
match = icon
|
|
118
|
+
matched = suffix.length
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
return match
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/** Props for {@link siteGlyph}: the destination plus the shared icon sizing seat. */
|
|
125
|
+
interface SiteGlyphProps {
|
|
126
|
+
/** The link destination; only an absolute http(s) URL can name a host. */
|
|
127
|
+
href: string | undefined
|
|
128
|
+
/** Square edge in px. */
|
|
129
|
+
size: number
|
|
130
|
+
/** Extra class for layout placement. */
|
|
131
|
+
className?: string | undefined
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Render the site mark for a known external destination.
|
|
136
|
+
* @param props - The destination and the icon sizing seat.
|
|
137
|
+
* @returns The site's mark riding currentColor, or undefined for an unknown site.
|
|
138
|
+
*/
|
|
139
|
+
export function siteGlyph({ href, size, className }: SiteGlyphProps): ReactElement | undefined {
|
|
140
|
+
const icon = href === undefined ? undefined : siteIcon(href)
|
|
141
|
+
if (icon === undefined) return undefined
|
|
142
|
+
return (
|
|
143
|
+
// Simple Icons fill their 24-unit box edge to edge; the -2 inset leaves the
|
|
144
|
+
// same ~8% margin the 20-unit ic_ds_* glyphs draw inside their own box.
|
|
145
|
+
<svg width={size} height={size} className={className} viewBox="-2 -2 28 28" fill="none" xmlns="http://www.w3.org/2000/svg" aria-hidden>
|
|
146
|
+
<path d={icon.path} fill="currentColor" />
|
|
147
|
+
</svg>
|
|
148
|
+
)
|
|
149
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/* Solid states keep the 10px layout slot but paint one 6px currentColor core. */
|
|
2
|
+
.dot {
|
|
3
|
+
position: relative;
|
|
4
|
+
display: inline-block;
|
|
5
|
+
flex: none;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
.dot::after {
|
|
9
|
+
content: '';
|
|
10
|
+
position: absolute;
|
|
11
|
+
inset: 20%;
|
|
12
|
+
border-radius: 50%;
|
|
13
|
+
corner-shape: round;
|
|
14
|
+
background: currentColor;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
.dot[data-state='done'] {
|
|
18
|
+
color: var(--dsw-alias-state-success-primary);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
.dot[data-state='warning'] {
|
|
22
|
+
color: var(--dsw-alias-state-warn-primary);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
.dot[data-state='error'] {
|
|
26
|
+
color: var(--dsw-alias-state-error-primary);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/* Idle is the absence of activity and uses the theme's neutral state step. */
|
|
30
|
+
.dot[data-state='idle'] {
|
|
31
|
+
color: var(--dsw-alias-state-idle-primary);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/* Ongoing is the sole non-dot state: a quiet full ring sits behind a centered
|
|
35
|
+
* breathing arc while the complete glyph rotates continuously. Both animations
|
|
36
|
+
* share one 1.5s period so pinning their start times aligns them together. */
|
|
37
|
+
.spinner {
|
|
38
|
+
flex: none;
|
|
39
|
+
color: var(--dsw-alias-label-tertiary);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
.spinnerMotion {
|
|
43
|
+
transform-origin: center;
|
|
44
|
+
animation: dsh-state-dot-spin 1.5s linear infinite;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
.spinnerTrack,
|
|
48
|
+
.spinnerArc {
|
|
49
|
+
fill: none;
|
|
50
|
+
stroke: currentColor;
|
|
51
|
+
stroke-width: 2;
|
|
52
|
+
stroke-linecap: round;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
.spinnerTrack {
|
|
56
|
+
opacity: 0.25;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
.spinnerArc {
|
|
60
|
+
stroke-dasharray: 12 150;
|
|
61
|
+
animation: dsh-state-dot-dash 1.5s ease-in-out infinite;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
@keyframes dsh-state-dot-spin {
|
|
65
|
+
to { transform: rotate(360deg); }
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
@keyframes dsh-state-dot-dash {
|
|
69
|
+
0% {
|
|
70
|
+
stroke-dasharray: 12 150;
|
|
71
|
+
stroke-dashoffset: 0;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
50% {
|
|
75
|
+
stroke-dasharray: 24 150;
|
|
76
|
+
stroke-dashoffset: -6;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
100% {
|
|
80
|
+
stroke-dasharray: 12 150;
|
|
81
|
+
stroke-dashoffset: 0;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
@media (prefers-reduced-motion: reduce) {
|
|
86
|
+
.spinnerMotion,
|
|
87
|
+
.spinnerArc {
|
|
88
|
+
animation: none;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
.spinnerArc {
|
|
92
|
+
stroke-dasharray: 18 150;
|
|
93
|
+
stroke-dashoffset: -3;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
.step { display: inline-flex; flex: none; align-items: center; justify-content: center; box-sizing: border-box; border-radius: 50%; corner-shape: round; border: 1.5px solid var(--dsw-alias-label-tertiary); color: var(--dsw-alias-label-primary-foreground); }
|
|
98
|
+
.step[data-state='done'] { border-color: var(--dsw-alias-state-success-primary); background: var(--dsw-alias-state-success-primary); }
|
|
99
|
+
.step[data-state='error'] { border-color: var(--dsw-alias-state-error-primary); background: var(--dsw-alias-state-error-primary); }
|
|
100
|
+
.step[data-state='warning'] { border-color: var(--dsw-alias-state-warn-primary); }
|
package/src/StateDot.tsx
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import clsx from 'clsx'
|
|
2
|
+
import css from './StateDot.module.css'
|
|
3
|
+
import { IconCheckOutlineRegular } from './icons/index.tsx'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* State semantic: green done / amber user-attention / tertiary-grey loading /
|
|
7
|
+
* red error / neutral-grey idle for a tracked subject with nothing in progress.
|
|
8
|
+
*/
|
|
9
|
+
export type StateDotState = 'done' | 'warning' | 'ongoing' | 'error' | 'idle'
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Pin the loader's CSS animations to document time zero. A CSS animation starts
|
|
13
|
+
* when its element is inserted and restarts when the element is moved or shown
|
|
14
|
+
* again, so loaders started at different moments rotate out of phase; one shared
|
|
15
|
+
* start time keeps every visible loader in step. Mount pins the first start; the
|
|
16
|
+
* element's own `animationstart` listener pins each restart.
|
|
17
|
+
* @param element - the mounted loader, or null on unmount.
|
|
18
|
+
*/
|
|
19
|
+
function syncSpinner(element: SVGSVGElement | null): void {
|
|
20
|
+
if (element === null) return
|
|
21
|
+
pinSpinner(element)
|
|
22
|
+
element.addEventListener('animationstart', () => { pinSpinner(element) })
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Set every CSS animation in the loader's subtree to start at document time zero.
|
|
27
|
+
* @param element - the mounted loader.
|
|
28
|
+
*/
|
|
29
|
+
function pinSpinner(element: SVGSVGElement): void {
|
|
30
|
+
// jsdom (the unit lane) implements no Web Animations despite lib.dom's
|
|
31
|
+
// non-optional typing; the optional call leaves that lane unsynced.
|
|
32
|
+
const spinner = element as { getAnimations?: SVGSVGElement['getAnimations'] }
|
|
33
|
+
for (const animation of spinner.getAnimations?.({ subtree: true }) ?? []) animation.startTime = 0
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Render a state dot.
|
|
38
|
+
* @param props.state - which of `done`, `warning`, `ongoing`, `error`, or `idle` to show.
|
|
39
|
+
* @param props.size - outer diameter in px; defaults to 14 for ongoing and 10 for solid states.
|
|
40
|
+
* @param props.className - extra class for layout placement.
|
|
41
|
+
* @param props.appearance - compact dot by default; step uses a filled check or hollow pending circle.
|
|
42
|
+
* @returns the dot element (aria-hidden; pair with text for accessibility).
|
|
43
|
+
*/
|
|
44
|
+
export function StateDot({ state, size, className, appearance = 'dot' }: {
|
|
45
|
+
state: StateDotState
|
|
46
|
+
size?: number | undefined
|
|
47
|
+
className?: string | undefined
|
|
48
|
+
appearance?: 'dot' | 'step'
|
|
49
|
+
}) {
|
|
50
|
+
const edge = size ?? (state === 'ongoing' ? 14 : 10)
|
|
51
|
+
if (state === 'ongoing') {
|
|
52
|
+
return (
|
|
53
|
+
<svg
|
|
54
|
+
ref={syncSpinner}
|
|
55
|
+
className={clsx(css.spinner, className)}
|
|
56
|
+
data-state="ongoing"
|
|
57
|
+
width={edge}
|
|
58
|
+
height={edge}
|
|
59
|
+
viewBox="0 0 24 24"
|
|
60
|
+
aria-hidden="true"
|
|
61
|
+
>
|
|
62
|
+
<g className={css.spinnerMotion}>
|
|
63
|
+
<circle className={css.spinnerTrack} cx="12" cy="12" r="9.5" />
|
|
64
|
+
<circle className={css.spinnerArc} cx="12" cy="12" r="9.5" />
|
|
65
|
+
</g>
|
|
66
|
+
</svg>
|
|
67
|
+
)
|
|
68
|
+
}
|
|
69
|
+
return (
|
|
70
|
+
<span
|
|
71
|
+
className={clsx(appearance === 'step' ? css.step : css.dot, className)}
|
|
72
|
+
data-state={state}
|
|
73
|
+
style={{ width: edge, height: edge }}
|
|
74
|
+
aria-hidden="true"
|
|
75
|
+
>{appearance === 'step' && state === 'done' && <IconCheckOutlineRegular size={edge - 2} />}</span>
|
|
76
|
+
)
|
|
77
|
+
}
|