@astryxdesign/core 0.6.2 → 0.6.3-canary.039a67e
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/CHANGELOG.md +81 -0
- package/dist/Avatar/Avatar.d.ts.map +1 -1
- package/dist/Avatar/Avatar.js +33 -12
- package/dist/BottomSheet/BottomSheet.d.ts +1 -1
- package/dist/BottomSheet/BottomSheet.d.ts.map +1 -1
- package/dist/BottomSheet/BottomSheet.js +3 -1
- package/dist/BottomSheet/BottomSheetPanel.d.ts +7 -5
- package/dist/BottomSheet/BottomSheetPanel.d.ts.map +1 -1
- package/dist/BottomSheet/BottomSheetPanel.js +56 -19
- package/dist/Button/Button.d.ts.map +1 -1
- package/dist/Button/Button.js +13 -28
- package/dist/Chat/ChatComposer.d.ts.map +1 -1
- package/dist/Chat/ChatComposer.js +10 -5
- package/dist/Chat/ChatComposerDrawer.d.ts +19 -5
- package/dist/Chat/ChatComposerDrawer.d.ts.map +1 -1
- package/dist/Chat/ChatComposerDrawer.js +48 -23
- package/dist/Chat/ChatComposerInput.d.ts +11 -3
- package/dist/Chat/ChatComposerInput.d.ts.map +1 -1
- package/dist/Chat/ChatComposerInput.js +63 -16
- package/dist/Chat/ChatDictationButton.d.ts +3 -2
- package/dist/Chat/ChatDictationButton.d.ts.map +1 -1
- package/dist/Chat/ChatDictationButton.js +6 -4
- package/dist/Chat/ChatLayout.d.ts +19 -0
- package/dist/Chat/ChatLayout.d.ts.map +1 -1
- package/dist/Chat/ChatLayout.js +19 -0
- package/dist/Chat/ChatLayoutScrollButton.d.ts.map +1 -1
- package/dist/Chat/ChatLayoutScrollButton.js +44 -34
- package/dist/Chat/ChatMessageBubble.d.ts +2 -0
- package/dist/Chat/ChatMessageBubble.d.ts.map +1 -1
- package/dist/Chat/ChatMessageBubble.js +5 -3
- package/dist/Chat/ChatMessageList.d.ts +2 -1
- package/dist/Chat/ChatMessageList.d.ts.map +1 -1
- package/dist/Chat/ChatMessageList.js +4 -3
- package/dist/Chat/ChatMessageMetadata.d.ts +5 -4
- package/dist/Chat/ChatMessageMetadata.d.ts.map +1 -1
- package/dist/Chat/ChatMessageMetadata.js +12 -9
- package/dist/Chat/ChatSendButton.d.ts +2 -1
- package/dist/Chat/ChatSendButton.d.ts.map +1 -1
- package/dist/Chat/ChatSendButton.js +6 -4
- package/dist/Chat/ChatSystemMessage.d.ts +3 -3
- package/dist/Chat/ChatSystemMessage.d.ts.map +1 -1
- package/dist/Chat/ChatSystemMessage.js +2 -2
- package/dist/Chat/ChatTokenizedText.d.ts +6 -6
- package/dist/Chat/ChatTokenizedText.js +10 -6
- package/dist/Chat/ChatToolCalls.d.ts +7 -9
- package/dist/Chat/ChatToolCalls.d.ts.map +1 -1
- package/dist/Chat/ChatToolCalls.js +43 -26
- package/dist/Chat/index.d.ts +1 -1
- package/dist/Chat/index.d.ts.map +1 -1
- package/dist/CheckboxInput/CheckboxInput.d.ts.map +1 -1
- package/dist/CheckboxInput/CheckboxInput.js +12 -2
- package/dist/Citation/Citation.d.ts +1 -1
- package/dist/Citation/Citation.d.ts.map +1 -1
- package/dist/Citation/Citation.js +3 -2
- package/dist/CodeBlock/highlightRanges.d.ts.map +1 -1
- package/dist/CodeBlock/highlightRanges.js +14 -3
- package/dist/Collapsible/Collapsible.d.ts.map +1 -1
- package/dist/Collapsible/Collapsible.js +6 -1
- package/dist/CommandPalette/CommandPaletteInput.d.ts.map +1 -1
- package/dist/CommandPalette/CommandPaletteInput.js +1 -1
- package/dist/ComplexSelector/ComplexSelector.d.ts.map +1 -1
- package/dist/ComplexSelector/ComplexSelector.js +1 -1
- package/dist/DateInput/DateInput.d.ts +25 -5
- package/dist/DateInput/DateInput.d.ts.map +1 -1
- package/dist/DateInput/DateInput.js +29 -17
- package/dist/DateInput/NativeDateField.d.ts.map +1 -1
- package/dist/DateInput/NativeDateField.js +16 -16
- package/dist/DateInput/TouchDateField.d.ts.map +1 -1
- package/dist/DateInput/TouchDateField.js +2 -2
- package/dist/DateInput/index.d.ts +1 -1
- package/dist/DateInput/index.d.ts.map +1 -1
- package/dist/DateRangeInput/DateRangeInput.d.ts.map +1 -1
- package/dist/DateRangeInput/DateRangeInput.js +4 -4
- package/dist/DateTimeInput/DateTimeInput.d.ts +32 -15
- package/dist/DateTimeInput/DateTimeInput.d.ts.map +1 -1
- package/dist/DateTimeInput/DateTimeInput.js +55 -30
- package/dist/DateTimeInput/TouchDateTimeField.d.ts.map +1 -1
- package/dist/DateTimeInput/TouchDateTimeField.js +4 -4
- package/dist/DateTimeInput/index.d.ts +1 -1
- package/dist/DateTimeInput/index.d.ts.map +1 -1
- package/dist/DateTimeInput/nativePickerSegmentStyles.d.ts +9 -3
- package/dist/DateTimeInput/nativePickerSegmentStyles.d.ts.map +1 -1
- package/dist/DateTimeInput/nativePickerSegmentStyles.js +3 -3
- package/dist/Dialog/DialogHeader.d.ts +8 -1
- package/dist/Dialog/DialogHeader.d.ts.map +1 -1
- package/dist/Dialog/DialogHeader.js +13 -4
- package/dist/Field/InputClearButton.d.ts +4 -2
- package/dist/Field/InputClearButton.d.ts.map +1 -1
- package/dist/Field/InputClearButton.js +4 -2
- package/dist/Field/PanelSearchInput.d.ts.map +1 -1
- package/dist/Field/PanelSearchInput.js +1 -1
- package/dist/FileInput/FileInput.d.ts.map +1 -1
- package/dist/FileInput/FileInput.js +7 -7
- package/dist/Icon/Icon.d.ts +6 -31
- package/dist/Icon/Icon.d.ts.map +1 -1
- package/dist/Icon/Icon.js +8 -71
- package/dist/Icon/IconDefaultSizeContext.d.ts +4 -0
- package/dist/Icon/IconDefaultSizeContext.d.ts.map +1 -0
- package/dist/Icon/IconDefaultSizeContext.js +18 -0
- package/dist/Icon/IconSize.stylex.d.ts +65 -0
- package/dist/Icon/IconSize.stylex.d.ts.map +1 -0
- package/dist/Icon/IconSize.stylex.js +75 -0
- package/dist/Item/Item.d.ts +1 -1
- package/dist/Item/Item.d.ts.map +1 -1
- package/dist/Item/Item.js +4 -3
- package/dist/Kbd/Kbd.d.ts +5 -3
- package/dist/Kbd/Kbd.d.ts.map +1 -1
- package/dist/Kbd/Kbd.js +36 -42
- package/dist/Link/Link.d.ts.map +1 -1
- package/dist/Link/Link.js +6 -2
- package/dist/Link/useLinkComponent.d.ts +5 -15
- package/dist/Link/useLinkComponent.d.ts.map +1 -1
- package/dist/Link/useLinkComponent.js +34 -51
- package/dist/List/List.d.ts +19 -1
- package/dist/List/List.d.ts.map +1 -1
- package/dist/List/List.js +9 -2
- package/dist/List/ListContext.d.ts +1 -0
- package/dist/List/ListContext.d.ts.map +1 -1
- package/dist/List/ListContext.js +2 -1
- package/dist/List/ListItem.d.ts +1 -1
- package/dist/List/ListItem.d.ts.map +1 -1
- package/dist/List/ListItem.js +9 -2
- package/dist/Markdown/Markdown.d.ts +8 -2
- package/dist/Markdown/Markdown.d.ts.map +1 -1
- package/dist/Markdown/Markdown.fr23.bench.d.ts +2 -0
- package/dist/Markdown/Markdown.fr23.bench.d.ts.map +1 -0
- package/dist/Markdown/Markdown.fr23.bench.js +150 -0
- package/dist/Markdown/Markdown.fr23.sampling.d.ts +2 -0
- package/dist/Markdown/Markdown.fr23.sampling.d.ts.map +1 -0
- package/dist/Markdown/Markdown.fr23.sampling.js +43 -0
- package/dist/Markdown/Markdown.js +262 -109
- package/dist/Markdown/ast.d.ts +162 -0
- package/dist/Markdown/ast.d.ts.map +1 -0
- package/dist/Markdown/ast.js +74 -0
- package/dist/Markdown/index.d.ts +5 -3
- package/dist/Markdown/index.d.ts.map +1 -1
- package/dist/Markdown/index.js +3 -2
- package/dist/Markdown/parser/index.d.ts +10 -0
- package/dist/Markdown/parser/index.d.ts.map +1 -0
- package/dist/Markdown/parser/index.js +10 -0
- package/dist/Markdown/parser.d.ts +126 -58
- package/dist/Markdown/parser.d.ts.map +1 -1
- package/dist/Markdown/parser.js +726 -177
- package/dist/Markdown/plugins/frontmatter.d.ts +32 -0
- package/dist/Markdown/plugins/frontmatter.d.ts.map +1 -0
- package/dist/Markdown/plugins/frontmatter.js +132 -0
- package/dist/Markdown/plugins/index.d.ts +17 -0
- package/dist/Markdown/plugins/index.d.ts.map +1 -0
- package/dist/Markdown/plugins/index.js +14 -0
- package/dist/Markdown/plugins/protocol.d.ts +191 -0
- package/dist/Markdown/plugins/protocol.d.ts.map +1 -0
- package/dist/Markdown/plugins/protocol.js +957 -0
- package/dist/Markdown/plugins/semanticFence.d.ts +36 -0
- package/dist/Markdown/plugins/semanticFence.d.ts.map +1 -0
- package/dist/Markdown/plugins/semanticFence.js +213 -0
- package/dist/Markdown/plugins/softBreaks.d.ts +3 -0
- package/dist/Markdown/plugins/softBreaks.d.ts.map +1 -0
- package/dist/Markdown/plugins/softBreaks.js +172 -0
- package/dist/Markdown/plugins/sourceDecoration.d.ts +76 -0
- package/dist/Markdown/plugins/sourceDecoration.d.ts.map +1 -0
- package/dist/Markdown/plugins/sourceDecoration.js +393 -0
- package/dist/Markdown/plugins/textTransform.d.ts +30 -0
- package/dist/Markdown/plugins/textTransform.d.ts.map +1 -0
- package/dist/Markdown/plugins/textTransform.js +374 -0
- package/dist/Markdown/remark.d.ts +196 -0
- package/dist/Markdown/remark.d.ts.map +1 -0
- package/dist/Markdown/remark.js +1062 -0
- package/dist/Markdown/url.d.ts +6 -0
- package/dist/Markdown/url.d.ts.map +1 -0
- package/dist/Markdown/url.js +31 -0
- package/dist/Markdown/utils.d.ts +4 -2
- package/dist/Markdown/utils.d.ts.map +1 -1
- package/dist/Markdown/utils.js +2 -1
- package/dist/MetadataList/MetadataList.js +3 -3
- package/dist/NumberInput/NumberInput.d.ts.map +1 -1
- package/dist/NumberInput/NumberInput.js +4 -4
- package/dist/Outline/index.d.ts +1 -0
- package/dist/Outline/index.d.ts.map +1 -1
- package/dist/Outline/parseOutlineFromMarkdown.d.ts +7 -1
- package/dist/Outline/parseOutlineFromMarkdown.d.ts.map +1 -1
- package/dist/Outline/parseOutlineFromMarkdown.js +14 -8
- package/dist/Outline/useOutlineFromMarkdown.d.ts +3 -1
- package/dist/Outline/useOutlineFromMarkdown.d.ts.map +1 -1
- package/dist/Outline/useOutlineFromMarkdown.js +8 -3
- package/dist/PowerSearch/PowerSearchEditPopover.d.ts.map +1 -1
- package/dist/PowerSearch/PowerSearchEditPopover.js +46 -30
- package/dist/PowerSearch/PowerSearchValueEditor.d.ts.map +1 -1
- package/dist/PowerSearch/PowerSearchValueEditor.js +5 -0
- package/dist/ProgressBar/ProgressBar.d.ts.map +1 -1
- package/dist/ProgressBar/ProgressBar.js +36 -31
- package/dist/RadioList/RadioListItem.d.ts.map +1 -1
- package/dist/RadioList/RadioListItem.js +13 -1
- package/dist/ScrollableArea/ScrollableArea.d.ts +1 -0
- package/dist/ScrollableArea/ScrollableArea.d.ts.map +1 -1
- package/dist/ScrollableArea/ScrollableArea.js +1 -0
- package/dist/SegmentedControl/SegmentedControl.d.ts +1 -1
- package/dist/SegmentedControl/SegmentedControl.d.ts.map +1 -1
- package/dist/SegmentedControl/SegmentedControl.js +1 -0
- package/dist/SegmentedControl/SegmentedControlItem.d.ts.map +1 -1
- package/dist/SegmentedControl/SegmentedControlItem.js +5 -5
- package/dist/Selector/Selector.d.ts +9 -7
- package/dist/Selector/Selector.d.ts.map +1 -1
- package/dist/Selector/Selector.js +16 -7
- package/dist/SideNav/SideNav.d.ts +2 -1
- package/dist/SideNav/SideNav.d.ts.map +1 -1
- package/dist/SideNav/SideNav.js +9 -3
- package/dist/Slider/Slider.d.ts.map +1 -1
- package/dist/Slider/Slider.js +28 -12
- package/dist/Spinner/Spinner.d.ts.map +1 -1
- package/dist/Spinner/Spinner.js +23 -7
- package/dist/Switch/Switch.d.ts.map +1 -1
- package/dist/Switch/Switch.js +11 -0
- package/dist/TabList/Tab.d.ts +1 -1
- package/dist/TabList/Tab.d.ts.map +1 -1
- package/dist/TabList/Tab.js +20 -7
- package/dist/Table/Table.d.ts +1 -0
- package/dist/Table/Table.d.ts.map +1 -1
- package/dist/Table/Table.js +29 -13
- package/dist/TextArea/TextArea.d.ts.map +1 -1
- package/dist/TextArea/TextArea.js +1 -1
- package/dist/TextInput/TextInput.d.ts.map +1 -1
- package/dist/TextInput/TextInput.js +2 -2
- package/dist/TimeInput/TimeInput.d.ts +30 -14
- package/dist/TimeInput/TimeInput.d.ts.map +1 -1
- package/dist/TimeInput/TimeInput.js +61 -13
- package/dist/TimeInput/TouchTimeField.d.ts +11 -0
- package/dist/TimeInput/TouchTimeField.d.ts.map +1 -0
- package/dist/TimeInput/TouchTimeField.js +417 -0
- package/dist/TimeInput/index.d.ts +1 -1
- package/dist/TimeInput/index.d.ts.map +1 -1
- package/dist/Timer/Timer.d.ts +49 -0
- package/dist/Timer/Timer.d.ts.map +1 -0
- package/dist/Timer/Timer.js +158 -0
- package/dist/Timer/index.d.ts +9 -0
- package/dist/Timer/index.d.ts.map +1 -0
- package/dist/Timer/index.js +10 -0
- package/dist/ToggleButton/ToggleButton.d.ts +9 -6
- package/dist/ToggleButton/ToggleButton.d.ts.map +1 -1
- package/dist/ToggleButton/ToggleButton.js +15 -27
- package/dist/TopNav/TopNavMenu.d.ts +1 -1
- package/dist/TopNav/TopNavMenu.d.ts.map +1 -1
- package/dist/TopNav/TopNavMenu.js +3 -2
- package/dist/TreeList/TreeList.d.ts.map +1 -1
- package/dist/TreeList/TreeList.js +3 -0
- package/dist/TreeList/TreeListItem.d.ts +6 -1
- package/dist/TreeList/TreeListItem.d.ts.map +1 -1
- package/dist/TreeList/TreeListItem.js +12 -2
- package/dist/TreeList/TreeListTypes.d.ts +8 -1
- package/dist/TreeList/TreeListTypes.d.ts.map +1 -1
- package/dist/Typeahead/BaseTypeahead.d.ts.map +1 -1
- package/dist/Typeahead/BaseTypeahead.js +16 -7
- package/dist/astryx.css +27 -11
- package/dist/hooks/scrollKeyboardDelegation.d.ts +3 -0
- package/dist/hooks/scrollKeyboardDelegation.d.ts.map +1 -0
- package/dist/hooks/scrollKeyboardDelegation.js +146 -0
- package/dist/hooks/useClickableContainer.d.ts +10 -1
- package/dist/hooks/useClickableContainer.d.ts.map +1 -1
- package/dist/hooks/useClickableContainer.js +15 -4
- package/dist/hooks/useScrollableArea.d.ts +6 -2
- package/dist/hooks/useScrollableArea.d.ts.map +1 -1
- package/dist/hooks/useScrollableArea.js +17 -5
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/dist/theme/declarationBoundary.d.ts +17 -0
- package/dist/theme/declarationBoundary.d.ts.map +1 -0
- package/dist/theme/declarationBoundary.js +343 -0
- package/dist/theme/defineTheme.d.ts +3 -0
- package/dist/theme/defineTheme.d.ts.map +1 -1
- package/dist/theme/defineTheme.js +4 -1
- package/dist/theme/derivedVarRegistry.d.ts.map +1 -1
- package/dist/theme/derivedVarRegistry.js +4 -0
- package/dist/theme/generateThemeRules.d.ts +15 -7
- package/dist/theme/generateThemeRules.d.ts.map +1 -1
- package/dist/theme/generateThemeRules.js +143 -35
- package/dist/theme/themeAdaptations.d.ts +5 -3
- package/dist/theme/themeAdaptations.d.ts.map +1 -1
- package/dist/theme/themeAdaptations.js +33 -5
- package/dist/utils/inputPresentation.d.ts +55 -0
- package/dist/utils/inputPresentation.d.ts.map +1 -0
- package/dist/utils/inputPresentation.js +108 -0
- package/dist/utils/interactionOverlay.stylex.d.ts +8 -0
- package/dist/utils/interactionOverlay.stylex.d.ts.map +1 -1
- package/dist/utils/interactionOverlay.stylex.js +9 -0
- package/dist/utils/safeUrl.d.ts +11 -0
- package/dist/utils/safeUrl.d.ts.map +1 -0
- package/dist/utils/safeUrl.js +78 -0
- package/locales/af-ZA.json +530 -1
- package/locales/ar-SA.json +490 -1
- package/locales/ca-ES.json +514 -1
- package/locales/cs-CZ.json +498 -1
- package/locales/da-DK.json +522 -1
- package/locales/de-DE.json +522 -1
- package/locales/el-GR.json +498 -1
- package/locales/es-ES.json +510 -1
- package/locales/fi-FI.json +498 -1
- package/locales/fr-FR.json +534 -1
- package/locales/he-IL.json +498 -1
- package/locales/hu-HU.json +498 -1
- package/locales/it-IT.json +510 -1
- package/locales/ja-JP.json +490 -1
- package/locales/ko-KR.json +498 -1
- package/locales/nl-NL.json +534 -1
- package/locales/no-NO.json +510 -1
- package/locales/pl-PL.json +506 -1
- package/locales/pt-BR.json +506 -1
- package/locales/pt-PT.json +506 -1
- package/locales/ro-RO.json +506 -1
- package/locales/ru-RU.json +498 -1
- package/locales/sr-SP.json +498 -1
- package/locales/sv-SE.json +502 -1
- package/locales/tr-TR.json +498 -1
- package/locales/uk-UA.json +498 -1
- package/locales/vi-VN.json +502 -1
- package/locales/zh-CN.json +490 -1
- package/locales/zh-TW.json +490 -1
- package/package.json +24 -4
- package/src/Avatar/Avatar.doc.mjs +1 -1
- package/src/Avatar/Avatar.test.tsx +30 -0
- package/src/Avatar/Avatar.tsx +38 -14
- package/src/BottomSheet/BottomSheet.doc.mjs +8 -1
- package/src/BottomSheet/BottomSheet.spec.md +46 -20
- package/src/BottomSheet/BottomSheet.test.tsx +6 -3
- package/src/BottomSheet/BottomSheet.tsx +3 -1
- package/src/BottomSheet/BottomSheetKeyboard.test.tsx +195 -0
- package/src/BottomSheet/BottomSheetPanel.test.tsx +11 -1
- package/src/BottomSheet/BottomSheetPanel.tsx +49 -16
- package/src/BottomSheet/__tests__/BottomSheetKeyboard.a11y.browser.spec.ts +344 -0
- package/src/Button/Button.doc.mjs +5 -5
- package/src/Button/Button.tsx +15 -13
- package/src/Button/__tests__/Button.a11y.chromium.spec.ts +17 -1
- package/src/Button/__tests__/Button.a11y.known-failures.ts +0 -29
- package/src/Button/__tests__/Button.a11y.renders.tsx +9 -2
- package/src/Button/__tests__/Button.a11y.states.ts +9 -0
- package/src/Chat/ChatComposer.doc.mjs +14 -0
- package/src/Chat/ChatComposer.spec.md +230 -0
- package/src/Chat/ChatComposer.test.tsx +57 -0
- package/src/Chat/ChatComposer.tsx +21 -9
- package/src/Chat/ChatComposerDrawer.doc.mjs +63 -5
- package/src/Chat/ChatComposerDrawer.spec.md +267 -0
- package/src/Chat/ChatComposerDrawer.test.tsx +81 -12
- package/src/Chat/ChatComposerDrawer.tsx +38 -9
- package/src/Chat/ChatComposerInput.doc.mjs +114 -26
- package/src/Chat/ChatComposerInput.spec.md +185 -0
- package/src/Chat/ChatComposerInput.test.tsx +113 -3
- package/src/Chat/ChatComposerInput.tsx +78 -13
- package/src/Chat/ChatComposerTokenElement.spec.md +152 -0
- package/src/Chat/ChatComposerTokenElement.test.tsx +85 -0
- package/src/Chat/ChatDictationButton.doc.mjs +3 -3
- package/src/Chat/ChatDictationButton.spec.md +160 -0
- package/src/Chat/ChatDictationButton.test.tsx +92 -27
- package/src/Chat/ChatDictationButton.tsx +8 -6
- package/src/Chat/ChatLayout.doc.mjs +12 -4
- package/src/Chat/ChatLayout.spec.md +271 -0
- package/src/Chat/ChatLayout.test.tsx +28 -0
- package/src/Chat/ChatLayout.tsx +19 -0
- package/src/Chat/ChatLayoutScrollButton.spec.md +338 -0
- package/src/Chat/ChatLayoutScrollButton.test.tsx +31 -0
- package/src/Chat/ChatLayoutScrollButton.tsx +31 -14
- package/src/Chat/ChatMessageBubble.doc.mjs +28 -15
- package/src/Chat/ChatMessageBubble.spec.md +263 -0
- package/src/Chat/ChatMessageBubble.test.tsx +93 -0
- package/src/Chat/ChatMessageBubble.tsx +8 -3
- package/src/Chat/ChatMessageList.spec.md +222 -0
- package/src/Chat/ChatMessageList.test.tsx +64 -2
- package/src/Chat/ChatMessageList.tsx +4 -3
- package/src/Chat/ChatMessageMetadata.doc.mjs +57 -3
- package/src/Chat/ChatMessageMetadata.spec.md +220 -0
- package/src/Chat/ChatMessageMetadata.test.tsx +34 -0
- package/src/Chat/ChatMessageMetadata.tsx +13 -13
- package/src/Chat/ChatSendButton.doc.mjs +32 -0
- package/src/Chat/ChatSendButton.spec.md +227 -0
- package/src/Chat/ChatSendButton.test.tsx +128 -8
- package/src/Chat/ChatSendButton.tsx +6 -4
- package/src/Chat/ChatSystemMessage.doc.mjs +115 -12
- package/src/Chat/ChatSystemMessage.spec.md +225 -0
- package/src/Chat/ChatSystemMessage.test.tsx +112 -20
- package/src/Chat/ChatSystemMessage.tsx +4 -6
- package/src/Chat/ChatTokenizedText.doc.mjs +96 -9
- package/src/Chat/ChatTokenizedText.spec.md +190 -0
- package/src/Chat/ChatTokenizedText.test.tsx +60 -1
- package/src/Chat/ChatTokenizedText.tsx +14 -8
- package/src/Chat/ChatToolCalls.doc.mjs +4 -1
- package/src/Chat/ChatToolCalls.spec.md +194 -0
- package/src/Chat/ChatToolCalls.test.tsx +83 -0
- package/src/Chat/ChatToolCalls.tsx +46 -21
- package/src/Chat/__tests__/ChatLayoutScrollButton.a11y.chromium.spec.ts +514 -0
- package/src/Chat/__tests__/ChatLayoutScrollButtonSurface.a11y.chromium.spec.ts +740 -0
- package/src/Chat/__tests__/ChatMessageBubble.a11y.chromium.spec.ts +457 -0
- package/src/Chat/__tests__/ChatMessageBubble.auditProvenance.test.ts +91 -0
- package/src/Chat/__tests__/ChatMessageBubble.auditProvenance.ts +91 -0
- package/src/Chat/__tests__/ChatMessageList.a11y.chromium.spec.ts +456 -0
- package/src/Chat/__tests__/ChatMessageMetadata.a11y.chromium.spec.ts +413 -0
- package/src/Chat/__tests__/ChatSendButton.a11y.chromium.spec.ts +1522 -0
- package/src/Chat/__tests__/ChatSystemMessage.a11y.chromium.spec.ts +1004 -0
- package/src/Chat/__tests__/ChatTokenizedText.a11y.chromium.spec.ts +573 -0
- package/src/Chat/index.ts +1 -0
- package/src/CheckboxInput/CheckboxInput.doc.mjs +11 -0
- package/src/CheckboxInput/CheckboxInput.test.tsx +34 -0
- package/src/CheckboxInput/CheckboxInput.tsx +21 -1
- package/src/Citation/Citation.doc.mjs +2 -2
- package/src/Citation/Citation.test.tsx +17 -0
- package/src/Citation/Citation.tsx +4 -2
- package/src/ClickableCard/ClickableCard.doc.mjs +2 -2
- package/src/ClickableCard/ClickableCard.test.tsx +102 -5
- package/src/CodeBlock/highlightRanges.test.ts +143 -1
- package/src/CodeBlock/highlightRanges.ts +15 -5
- package/src/Collapsible/Collapsible.doc.mjs +11 -0
- package/src/Collapsible/Collapsible.test.tsx +21 -0
- package/src/Collapsible/Collapsible.tsx +5 -0
- package/src/CommandPalette/CommandPaletteInput.tsx +6 -1
- package/src/ComplexSelector/ComplexSelector.tsx +6 -1
- package/src/DateInput/DateInput.doc.mjs +38 -9
- package/src/DateInput/DateInput.tsx +59 -17
- package/src/DateInput/NativeDateField.tsx +24 -8
- package/src/DateInput/Presentation.test.tsx +121 -0
- package/src/DateInput/TouchDateField.tsx +6 -2
- package/src/DateInput/index.ts +1 -0
- package/src/DateRangeInput/DateRangeInput.tsx +6 -1
- package/src/DateTimeInput/DateTimeInput.doc.mjs +28 -12
- package/src/DateTimeInput/DateTimeInput.tsx +93 -37
- package/src/DateTimeInput/Presentation.test.tsx +89 -0
- package/src/DateTimeInput/TouchDateTimeField.tsx +6 -1
- package/src/DateTimeInput/index.ts +1 -0
- package/src/DateTimeInput/nativePickerSegmentStyles.ts +24 -8
- package/src/Dialog/Dialog.doc.mjs +2 -0
- package/src/Dialog/DialogHeader.doc.mjs +22 -0
- package/src/Dialog/DialogHeader.test.tsx +167 -3
- package/src/Dialog/DialogHeader.tsx +37 -6
- package/src/Dialog/modules/DialogHeader.spec.md +101 -42
- package/src/DropdownMenu/DropdownMenu.test.tsx +5 -2
- package/src/Field/InputClearButton.test.tsx +17 -3
- package/src/Field/InputClearButton.tsx +5 -2
- package/src/Field/PanelSearchInput.tsx +5 -2
- package/src/FieldStatus/__tests__/StatusMessage.a11y.states.ts +1 -1
- package/src/FileInput/FileInput.tsx +11 -2
- package/src/Icon/Icon.doc.mjs +7 -5
- package/src/Icon/Icon.spec.md +81 -40
- package/src/Icon/Icon.test.tsx +6 -3
- package/src/Icon/Icon.tsx +20 -68
- package/src/Icon/IconDefaultSizeContext.ts +23 -0
- package/src/Icon/IconSize.stylex.ts +70 -0
- package/src/IconButton/IconButton.doc.mjs +3 -3
- package/src/IconButton/IconButton.test.tsx +40 -0
- package/src/Item/Item.doc.mjs +6 -2
- package/src/Item/Item.tsx +9 -3
- package/src/Kbd/Kbd.doc.mjs +3 -3
- package/src/Kbd/Kbd.test.tsx +57 -1
- package/src/Kbd/Kbd.tsx +57 -37
- package/src/Layout/LayoutFooter.doc.mjs +17 -0
- package/src/Link/Link.doc.mjs +17 -4
- package/src/Link/Link.test.tsx +24 -0
- package/src/Link/Link.tsx +5 -0
- package/src/Link/LinkProvider.doc.mjs +2 -2
- package/src/Link/__tests__/Link.navigation.a11y.chromium.spec.ts +261 -0
- package/src/Link/useLinkComponent.test.tsx +333 -0
- package/src/Link/useLinkComponent.ts +29 -57
- package/src/List/List.doc.mjs +6 -0
- package/src/List/List.spec.md +200 -0
- package/src/List/List.test.tsx +117 -1
- package/src/List/List.tsx +22 -2
- package/src/List/ListContext.tsx +3 -1
- package/src/List/ListItem.doc.mjs +2 -2
- package/src/List/ListItem.source-build.test.mjs +41 -0
- package/src/List/ListItem.tsx +26 -2
- package/src/Markdown/Markdown.doc.mjs +300 -2
- package/src/Markdown/Markdown.fr23.bench.ts +174 -0
- package/src/Markdown/Markdown.fr23.perf.test.ts +249 -0
- package/src/Markdown/Markdown.fr23.sampling.ts +49 -0
- package/src/Markdown/Markdown.helpers.perf.test.ts +489 -0
- package/src/Markdown/Markdown.public.test.ts +130 -3
- package/src/Markdown/Markdown.renderBoundary.test.tsx +72 -0
- package/src/Markdown/Markdown.spec.md +210 -45
- package/src/Markdown/Markdown.test.tsx +87 -3
- package/src/Markdown/Markdown.tsx +414 -135
- package/src/Markdown/ast.test.ts +307 -0
- package/src/Markdown/ast.ts +337 -0
- package/src/Markdown/incremental.test.ts +43 -0
- package/src/Markdown/index.ts +37 -1
- package/src/Markdown/modules/remark.spec.md +269 -0
- package/src/Markdown/modules/softBreaks.spec.md +137 -0
- package/src/Markdown/parser/index.ts +64 -0
- package/src/Markdown/parser.public.test.ts +103 -0
- package/src/Markdown/parser.test.ts +38 -6
- package/src/Markdown/parser.ts +1221 -242
- package/src/Markdown/plugins/frontmatter.test.tsx +125 -0
- package/src/Markdown/plugins/frontmatter.ts +198 -0
- package/src/Markdown/plugins/index.ts +54 -0
- package/src/Markdown/plugins/protocol.test.tsx +1022 -0
- package/src/Markdown/plugins/protocol.ts +1618 -0
- package/src/Markdown/plugins/semanticFence.test.tsx +546 -0
- package/src/Markdown/plugins/semanticFence.ts +424 -0
- package/src/Markdown/plugins/softBreaks.test.tsx +172 -0
- package/src/Markdown/plugins/softBreaks.ts +169 -0
- package/src/Markdown/plugins/sourceDecoration.test.tsx +799 -0
- package/src/Markdown/plugins/sourceDecoration.ts +539 -0
- package/src/Markdown/plugins/textTransform.test.ts +467 -0
- package/src/Markdown/plugins/textTransform.ts +554 -0
- package/src/Markdown/remark.test.tsx +1877 -0
- package/src/Markdown/remark.ts +1574 -0
- package/src/Markdown/url.ts +36 -0
- package/src/Markdown/utils.ts +13 -1
- package/src/MetadataList/MetadataList.test.tsx +4 -2
- package/src/MetadataList/MetadataList.tsx +3 -3
- package/src/MultiSelector/MultiSelector.test.tsx +1 -35
- package/src/MultiSelector/__tests__/MultiSelector.listbox.a11y.test.tsx +128 -0
- package/src/NumberInput/NumberInput.tsx +6 -1
- package/src/Outline/Outline.doc.mjs +7 -5
- package/src/Outline/Outline.spec.md +1 -1
- package/src/Outline/index.ts +1 -0
- package/src/Outline/modules/parseOutlineFromMarkdown.spec.md +142 -0
- package/src/Outline/parseOutlineFromMarkdown.ts +40 -10
- package/src/Outline/useOutlineFromMarkdown.ts +15 -3
- package/src/PowerSearch/PowerSearch.doc.mjs +2 -2
- package/src/PowerSearch/PowerSearchEditPopover.test.tsx +150 -1
- package/src/PowerSearch/PowerSearchEditPopover.tsx +51 -28
- package/src/PowerSearch/PowerSearchValueEditor.test.tsx +51 -0
- package/src/PowerSearch/PowerSearchValueEditor.tsx +4 -0
- package/src/ProgressBar/ProgressBar.test.tsx +29 -11
- package/src/ProgressBar/ProgressBar.tsx +59 -72
- package/src/RadioList/RadioList.doc.mjs +11 -0
- package/src/RadioList/RadioList.test.tsx +32 -0
- package/src/RadioList/RadioListItem.tsx +25 -1
- package/src/ScrollableArea/ScrollableArea.tsx +1 -0
- package/src/ScrollableArea/modules/useScrollableArea.spec.md +50 -22
- package/src/SegmentedControl/SegmentedControl.doc.mjs +2 -2
- package/src/SegmentedControl/SegmentedControl.test.tsx +61 -0
- package/src/SegmentedControl/SegmentedControl.tsx +2 -1
- package/src/SegmentedControl/SegmentedControlItem.tsx +6 -9
- package/src/Selector/Selector.doc.mjs +3 -3
- package/src/Selector/Selector.spec.md +51 -49
- package/src/Selector/Selector.test.tsx +61 -55
- package/src/Selector/Selector.tsx +34 -15
- package/src/Selector/__tests__/Listbox.a11y.chromium.spec.ts +130 -0
- package/src/Selector/__tests__/Listbox.a11y.dom.ts +38 -0
- package/src/Selector/__tests__/Listbox.a11y.inventory.test.ts +63 -0
- package/src/Selector/__tests__/Listbox.a11y.known-failures.ts +37 -0
- package/src/Selector/__tests__/Listbox.a11y.states.ts +232 -0
- package/src/Selector/__tests__/Selector.a11y.chromium.spec.ts +45 -0
- package/src/Selector/__tests__/Selector.listbox.a11y.test.tsx +121 -0
- package/src/SideNav/SideNav.doc.mjs +1 -1
- package/src/SideNav/SideNav.test.tsx +10 -0
- package/src/SideNav/SideNav.tsx +14 -2
- package/src/Slider/Slider.doc.mjs +17 -3
- package/src/Slider/Slider.test.tsx +221 -0
- package/src/Slider/Slider.tsx +40 -9
- package/src/Spinner/Spinner.test.tsx +4 -0
- package/src/Spinner/Spinner.tsx +31 -18
- package/src/Switch/Switch.doc.mjs +11 -0
- package/src/Switch/Switch.test.tsx +16 -0
- package/src/Switch/Switch.tsx +28 -0
- package/src/TabList/Tab.tsx +35 -7
- package/src/TabList/TabList.doc.mjs +11 -0
- package/src/TabList/TabList.spec.md +204 -0
- package/src/TabList/TabList.test.tsx +66 -0
- package/src/TabList/__tests__/Tabs.a11y.known-failures.ts +1 -34
- package/src/Table/Table.doc.mjs +1 -1
- package/src/Table/Table.spec.md +54 -40
- package/src/Table/Table.test.tsx +83 -10
- package/src/Table/Table.tsx +30 -22
- package/src/Table/__tests__/TableScroll.a11y.chromium.spec.ts +137 -0
- package/src/TextArea/TextArea.tsx +6 -1
- package/src/TextInput/TextInput.test.tsx +20 -1
- package/src/TextInput/TextInput.tsx +6 -1
- package/src/TimeInput/NativeTimeInput.test.tsx +36 -3
- package/src/TimeInput/Presentation.test.tsx +148 -0
- package/src/TimeInput/TimeInput.doc.mjs +21 -5
- package/src/TimeInput/TimeInput.tsx +102 -11
- package/src/TimeInput/TouchTimeField.tsx +572 -0
- package/src/TimeInput/index.ts +1 -0
- package/src/Timer/Timer.doc.mjs +183 -0
- package/src/Timer/Timer.spec.md +215 -0
- package/src/Timer/Timer.test.tsx +302 -0
- package/src/Timer/Timer.tsx +258 -0
- package/src/Timer/index.ts +11 -0
- package/src/ToggleButton/ToggleButton.doc.mjs +3 -3
- package/src/ToggleButton/ToggleButton.test.tsx +299 -4
- package/src/ToggleButton/ToggleButton.tsx +26 -33
- package/src/ToggleButton/ToggleButtonGroup.doc.mjs +3 -3
- package/src/ToggleButton/__tests__/ToggleButton.a11y.chromium.spec.ts +209 -0
- package/src/Token/Token.doc.mjs +2 -2
- package/src/Tokenizer/Tokenizer.spec.md +142 -75
- package/src/TopNav/TopNavMenu.doc.mjs +2 -2
- package/src/TopNav/TopNavMenu.test.tsx +30 -0
- package/src/TopNav/TopNavMenu.tsx +7 -2
- package/src/TreeList/TreeList.doc.mjs +3 -3
- package/src/TreeList/TreeList.spec.md +123 -75
- package/src/TreeList/TreeList.test.tsx +29 -0
- package/src/TreeList/TreeList.tsx +3 -0
- package/src/TreeList/TreeListItem.tsx +15 -1
- package/src/TreeList/TreeListTypes.ts +11 -1
- package/src/Typeahead/BaseTypeahead.spec.md +4 -3
- package/src/Typeahead/BaseTypeahead.tsx +21 -7
- package/src/Typeahead/Typeahead.test.tsx +53 -0
- package/src/__tests__/PressedState.a11y.chromium.spec.ts +813 -0
- package/src/__tests__/pressState.ts +93 -0
- package/src/hooks/scrollKeyboardDelegation.test.ts +155 -0
- package/src/hooks/scrollKeyboardDelegation.ts +233 -0
- package/src/hooks/useClickableContainer.test.tsx +236 -0
- package/src/hooks/useClickableContainer.ts +20 -4
- package/src/hooks/useScrollableArea.doc.mjs +15 -3
- package/src/hooks/useScrollableArea.test.tsx +59 -1
- package/src/hooks/useScrollableArea.ts +34 -10
- package/src/index.ts +3 -0
- package/src/inputFontFloor.test.ts +106 -0
- package/src/tailwind-theme.css +0 -6
- package/src/theme/Theme.test.tsx +32 -0
- package/src/theme/declarationBoundary.test.ts +126 -0
- package/src/theme/declarationBoundary.ts +347 -0
- package/src/theme/defineTheme.ts +4 -0
- package/src/theme/derivedVarRegistry.test.ts +7 -0
- package/src/theme/derivedVarRegistry.ts +1 -0
- package/src/theme/generateThemeRules.test.ts +526 -1
- package/src/theme/generateThemeRules.ts +231 -50
- package/src/theme/themeAdaptations.test.ts +211 -1
- package/src/theme/themeAdaptations.ts +50 -4
- package/src/theme/tokenValueCompat.test.ts +4 -1
- package/src/utils/inputPresentation.ts +143 -0
- package/src/utils/interactionOverlay.stylex.ts +20 -0
- package/src/utils/safeUrl.test.ts +88 -0
- package/src/utils/safeUrl.ts +85 -0
|
@@ -0,0 +1,417 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
'use client';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @file TouchTimeField.tsx
|
|
7
|
+
* @input Uses React, Field, BottomSheet, Wheel, DateInput touch geometry
|
|
8
|
+
* tokens, and shared time utilities
|
|
9
|
+
* @output Exports TouchTimeField — the bottom-sheet surface behind TimeInput
|
|
10
|
+
* @position Internal component; consumed by TimeInput.tsx for `presentation`
|
|
11
|
+
* sheet surfaces (`spec:AST-043` DEC-3: the time half of DateTimeInput's sheet)
|
|
12
|
+
*
|
|
13
|
+
* SYNC: When modified, update these files to stay in sync:
|
|
14
|
+
* - /packages/core/src/TimeInput/TimeInput.tsx
|
|
15
|
+
* - /packages/core/src/TimeInput/TimeInput.doc.mjs
|
|
16
|
+
* - /packages/core/src/DateTimeInput/TouchDateTimeField.tsx (wheel behavior)
|
|
17
|
+
*/
|
|
18
|
+
import { useCallback, useId, useMemo, useOptimistic, useRef, useState, useTransition } from 'react';
|
|
19
|
+
import * as stylex from '@stylexjs/stylex';
|
|
20
|
+
import { BottomSheet } from "../BottomSheet/index.js";
|
|
21
|
+
import { Button } from "../Button/index.js";
|
|
22
|
+
import { Field, InputClearButton, inputWrapperStyles, inputStatusBorderStyles, inputStatusHoverShadowStyles, inputStatusFocusWithinStyles } from "../Field/index.js";
|
|
23
|
+
import { useInputGroup } from "../InputGroup/InputGroupContext.js";
|
|
24
|
+
import { groupStyles } from "../InputGroup/groupStyles.js";
|
|
25
|
+
import { useInputStatusIcon } from "../hooks/useInputStatusIcon.js";
|
|
26
|
+
import { useMergedRefs } from "../hooks/useMergedRefs.js";
|
|
27
|
+
import { useResolvedRequired } from "../hooks/useResolvedRequired.js";
|
|
28
|
+
import { Icon } from "../Icon/index.js";
|
|
29
|
+
import { useTranslator } from "../i18n/index.js";
|
|
30
|
+
import "../theme/tokens.stylex.js";
|
|
31
|
+
import { sizeVars, spacingVars } from "../theme/tokens.stylex.js";
|
|
32
|
+
import { useSize } from "../SizeContext/SizeContext.js";
|
|
33
|
+
import { Spinner } from "../Spinner/index.js";
|
|
34
|
+
import { useTooltip } from "../Tooltip/index.js";
|
|
35
|
+
import { Wheel } from "../DateInput/Wheel.js";
|
|
36
|
+
import "../DateInput/tokens.stylex.js";
|
|
37
|
+
import { dateInputTouchGeometry } from "../DateInput/tokens.stylex.js";
|
|
38
|
+
import { focusOutlineStyles } from "../utils/focusOutline.stylex.js";
|
|
39
|
+
import { themeProps } from "../utils/themeProps.js";
|
|
40
|
+
import { clampTime, formatDisplayTime12h, formatDisplayTime24h, formatISOTime, getInputARIA, isTimeInRange, mergeProps, parseISOTime } from "../utils/index.js";
|
|
41
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
42
|
+
const sizeStyles = {
|
|
43
|
+
sm: {
|
|
44
|
+
kZKoxP: "x6k0iem",
|
|
45
|
+
k7Eaqz: "x1i9suas",
|
|
46
|
+
$$css: true
|
|
47
|
+
},
|
|
48
|
+
md: {
|
|
49
|
+
kZKoxP: "x1ueg155",
|
|
50
|
+
k7Eaqz: "x1i9suas",
|
|
51
|
+
$$css: true
|
|
52
|
+
},
|
|
53
|
+
lg: {
|
|
54
|
+
kZKoxP: "xssyfek",
|
|
55
|
+
k7Eaqz: "x1i9suas",
|
|
56
|
+
$$css: true
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
const styles = {
|
|
60
|
+
iconButton: {
|
|
61
|
+
k1xSpc: "x78zum5",
|
|
62
|
+
kGNEyG: "x6s0dn4",
|
|
63
|
+
kjj79g: "xl56j7k",
|
|
64
|
+
kmVPX3: "x1717udv",
|
|
65
|
+
kogj98: "x1ghz6dp",
|
|
66
|
+
kMzoRj: "xc342km",
|
|
67
|
+
ksu8eU: "xng3xce",
|
|
68
|
+
kWkggS: "xjbqb8w",
|
|
69
|
+
kkrTdU: "x1ypdohk x16khyan",
|
|
70
|
+
kmuXW: "x2lah0s",
|
|
71
|
+
$$css: true
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
function twoDigits(value) {
|
|
75
|
+
return String(value).padStart(2, '0');
|
|
76
|
+
}
|
|
77
|
+
function hour12From24(hour) {
|
|
78
|
+
return hour === 0 ? 12 : hour > 12 ? hour - 12 : hour;
|
|
79
|
+
}
|
|
80
|
+
function hour24From12(hour, meridiem) {
|
|
81
|
+
if (meridiem === 0) {
|
|
82
|
+
return hour === 12 ? 0 : hour;
|
|
83
|
+
}
|
|
84
|
+
return hour === 12 ? 12 : hour + 12;
|
|
85
|
+
}
|
|
86
|
+
function timeToSeconds(time) {
|
|
87
|
+
if (time == null) {
|
|
88
|
+
return null;
|
|
89
|
+
}
|
|
90
|
+
const parsed = parseISOTime(time);
|
|
91
|
+
return parsed == null ? null : parsed.hour * 3600 + parsed.minute * 60 + parsed.second;
|
|
92
|
+
}
|
|
93
|
+
function rangeOverlaps(startSecond, endSecond, min, max) {
|
|
94
|
+
const minSecond = timeToSeconds(min);
|
|
95
|
+
const maxSecond = timeToSeconds(max);
|
|
96
|
+
return (minSecond == null || endSecond >= minSecond) && (maxSecond == null || startSecond <= maxSecond);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* The Astryx bottom-sheet time surface: a read-only closed field that opens
|
|
101
|
+
* hour/minute(/second/meridiem) wheels in a BottomSheet. Wheels commit live,
|
|
102
|
+
* clamped to `min`/`max`; the footer Save button only closes the sheet.
|
|
103
|
+
*/
|
|
104
|
+
export function TouchTimeField({
|
|
105
|
+
label,
|
|
106
|
+
isLabelHidden = false,
|
|
107
|
+
description,
|
|
108
|
+
isOptional = false,
|
|
109
|
+
isRequired = false,
|
|
110
|
+
isDisabled = false,
|
|
111
|
+
disabledMessage,
|
|
112
|
+
value,
|
|
113
|
+
onChange,
|
|
114
|
+
changeAction,
|
|
115
|
+
isLoading = false,
|
|
116
|
+
min,
|
|
117
|
+
max,
|
|
118
|
+
hasSeconds = false,
|
|
119
|
+
hasClear = false,
|
|
120
|
+
hourFormat = '12h',
|
|
121
|
+
placeholder: placeholderFromProps,
|
|
122
|
+
size: sizeProp,
|
|
123
|
+
status,
|
|
124
|
+
statusVariant = 'attached',
|
|
125
|
+
labelTooltip,
|
|
126
|
+
width,
|
|
127
|
+
xstyle,
|
|
128
|
+
className,
|
|
129
|
+
style,
|
|
130
|
+
ref
|
|
131
|
+
}) {
|
|
132
|
+
const t = useTranslator();
|
|
133
|
+
const isEffectivelyRequired = useResolvedRequired({
|
|
134
|
+
isRequired,
|
|
135
|
+
isOptional
|
|
136
|
+
});
|
|
137
|
+
const placeholder = placeholderFromProps ?? t('@astryx.timeInput.placeholder');
|
|
138
|
+
const size = useSize(sizeProp, 'md');
|
|
139
|
+
const id = useId();
|
|
140
|
+
const inputLabelID = useId();
|
|
141
|
+
const descriptionID = useId();
|
|
142
|
+
const statusMessageID = useId();
|
|
143
|
+
const inputRef = useRef(null);
|
|
144
|
+
const mergedInputRef = useMergedRefs(ref, inputRef);
|
|
145
|
+
const inputGroup = useInputGroup();
|
|
146
|
+
const [isSheetOpen, setIsSheetOpen] = useState(false);
|
|
147
|
+
const [, startTransition] = useTransition();
|
|
148
|
+
const [optimisticValue, setOptimisticValue] = useOptimistic(value);
|
|
149
|
+
const isBusy = isLoading || optimisticValue !== value;
|
|
150
|
+
const isEffectivelyDisabled = isDisabled || isLoading;
|
|
151
|
+
const showsDisabledMessage = isDisabled && !!disabledMessage;
|
|
152
|
+
const disabledMessageTooltip = useTooltip({
|
|
153
|
+
placement: 'above',
|
|
154
|
+
focusTrigger: 'always',
|
|
155
|
+
isEnabled: showsDisabledMessage
|
|
156
|
+
});
|
|
157
|
+
const {
|
|
158
|
+
statusIcon,
|
|
159
|
+
describedBy: statusTooltipDescribedBy
|
|
160
|
+
} = useInputStatusIcon({
|
|
161
|
+
status,
|
|
162
|
+
statusVariant,
|
|
163
|
+
isInGroup: !!inputGroup
|
|
164
|
+
});
|
|
165
|
+
const {
|
|
166
|
+
ariaLabelledBy,
|
|
167
|
+
ariaDescribedBy
|
|
168
|
+
} = getInputARIA(inputLabelID, [description ? descriptionID : null, statusVariant !== 'tooltip' && status?.message ? statusMessageID : null, statusTooltipDescribedBy, showsDisabledMessage ? disabledMessageTooltip.describedBy : null], inputGroup);
|
|
169
|
+
const fireChange = useCallback(newValue => {
|
|
170
|
+
if (isEffectivelyDisabled) {
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
onChange?.(newValue);
|
|
174
|
+
if (changeAction) {
|
|
175
|
+
startTransition(async () => {
|
|
176
|
+
setOptimisticValue(newValue);
|
|
177
|
+
await changeAction(newValue);
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
}, [changeAction, isEffectivelyDisabled, onChange, setOptimisticValue]);
|
|
181
|
+
const formatDisplayTime = hourFormat === '12h' ? formatDisplayTime12h : formatDisplayTime24h;
|
|
182
|
+
const displayValue = optimisticValue ? formatDisplayTime(optimisticValue, hasSeconds) : '';
|
|
183
|
+
const fallbackTime = useMemo(() => {
|
|
184
|
+
const now = new Date();
|
|
185
|
+
return formatISOTime({
|
|
186
|
+
hour: now.getHours(),
|
|
187
|
+
minute: now.getMinutes(),
|
|
188
|
+
second: now.getSeconds()
|
|
189
|
+
}, hasSeconds);
|
|
190
|
+
}, [hasSeconds]);
|
|
191
|
+
const parsedWheelTime = useMemo(() => parseISOTime(optimisticValue ?? fallbackTime) ?? {
|
|
192
|
+
hour: 0,
|
|
193
|
+
minute: 0,
|
|
194
|
+
second: 0
|
|
195
|
+
}, [fallbackTime, optimisticValue]);
|
|
196
|
+
const composeWheelTime = useCallback(patch => {
|
|
197
|
+
const meridiem = patch.meridiem ?? (parsedWheelTime.hour < 12 ? 0 : 1);
|
|
198
|
+
let hour = parsedWheelTime.hour;
|
|
199
|
+
if (patch.hour24 !== undefined) {
|
|
200
|
+
hour = patch.hour24;
|
|
201
|
+
} else if (patch.hour12 !== undefined) {
|
|
202
|
+
hour = hour24From12(patch.hour12, meridiem);
|
|
203
|
+
} else if (patch.meridiem !== undefined) {
|
|
204
|
+
hour = hour24From12(hour12From24(hour), patch.meridiem);
|
|
205
|
+
}
|
|
206
|
+
return formatISOTime({
|
|
207
|
+
hour,
|
|
208
|
+
minute: patch.minute ?? parsedWheelTime.minute,
|
|
209
|
+
second: hasSeconds ? patch.second ?? parsedWheelTime.second : 0
|
|
210
|
+
}, hasSeconds);
|
|
211
|
+
}, [hasSeconds, parsedWheelTime]);
|
|
212
|
+
const commitWheelTime = useCallback(rawTime => {
|
|
213
|
+
const next = clampTime(rawTime, min, max, hasSeconds);
|
|
214
|
+
if (next !== optimisticValue && isTimeInRange(next, min, max)) {
|
|
215
|
+
fireChange(next);
|
|
216
|
+
}
|
|
217
|
+
}, [fireChange, hasSeconds, max, min, optimisticValue]);
|
|
218
|
+
const hourOptions = useMemo(() => {
|
|
219
|
+
if (hourFormat === '24h') {
|
|
220
|
+
return Array.from({
|
|
221
|
+
length: 24
|
|
222
|
+
}, (_, hour) => ({
|
|
223
|
+
value: hour,
|
|
224
|
+
label: twoDigits(hour),
|
|
225
|
+
isDisabled: !rangeOverlaps(hour * 3600, hour * 3600 + 3599, min, max)
|
|
226
|
+
}));
|
|
227
|
+
}
|
|
228
|
+
const meridiem = parsedWheelTime.hour < 12 ? 0 : 1;
|
|
229
|
+
return Array.from({
|
|
230
|
+
length: 12
|
|
231
|
+
}, (_, index) => {
|
|
232
|
+
const hour = index + 1;
|
|
233
|
+
const hour24 = hour24From12(hour, meridiem);
|
|
234
|
+
return {
|
|
235
|
+
value: hour,
|
|
236
|
+
label: String(hour),
|
|
237
|
+
isDisabled: !rangeOverlaps(hour24 * 3600, hour24 * 3600 + 3599, min, max)
|
|
238
|
+
};
|
|
239
|
+
});
|
|
240
|
+
}, [hourFormat, max, min, parsedWheelTime.hour]);
|
|
241
|
+
const minuteOptions = useMemo(() => Array.from({
|
|
242
|
+
length: 60
|
|
243
|
+
}, (_, minute) => {
|
|
244
|
+
const start = parsedWheelTime.hour * 3600 + minute * 60;
|
|
245
|
+
return {
|
|
246
|
+
value: minute,
|
|
247
|
+
label: twoDigits(minute),
|
|
248
|
+
isDisabled: !rangeOverlaps(start, start + (hasSeconds ? 59 : 0), min, max)
|
|
249
|
+
};
|
|
250
|
+
}), [hasSeconds, max, min, parsedWheelTime.hour]);
|
|
251
|
+
const secondOptions = useMemo(() => Array.from({
|
|
252
|
+
length: 60
|
|
253
|
+
}, (_, second) => ({
|
|
254
|
+
value: second,
|
|
255
|
+
label: twoDigits(second),
|
|
256
|
+
isDisabled: !isTimeInRange(formatISOTime({
|
|
257
|
+
hour: parsedWheelTime.hour,
|
|
258
|
+
minute: parsedWheelTime.minute,
|
|
259
|
+
second
|
|
260
|
+
}, true), min, max)
|
|
261
|
+
})), [max, min, parsedWheelTime.hour, parsedWheelTime.minute]);
|
|
262
|
+
const meridiemOptions = useMemo(() => [{
|
|
263
|
+
value: 0,
|
|
264
|
+
label: t('@astryx.dateTimeInput.meridiemAM'),
|
|
265
|
+
isDisabled: !rangeOverlaps(0, 11 * 3600 + 3599, min, max)
|
|
266
|
+
}, {
|
|
267
|
+
value: 1,
|
|
268
|
+
label: t('@astryx.dateTimeInput.meridiemPM'),
|
|
269
|
+
isDisabled: !rangeOverlaps(12 * 3600, 23 * 3600 + 3599, min, max)
|
|
270
|
+
}], [max, min, t]);
|
|
271
|
+
const openSheet = useCallback(() => {
|
|
272
|
+
if (!isEffectivelyDisabled) {
|
|
273
|
+
setIsSheetOpen(true);
|
|
274
|
+
}
|
|
275
|
+
}, [isEffectivelyDisabled]);
|
|
276
|
+
const inputWrapper = /*#__PURE__*/_jsxs("div", {
|
|
277
|
+
ref: el => {
|
|
278
|
+
disabledMessageTooltip.ref(el);
|
|
279
|
+
},
|
|
280
|
+
...mergeProps(themeProps('time-input', {
|
|
281
|
+
size,
|
|
282
|
+
status: status?.type ?? null,
|
|
283
|
+
disabled: isDisabled ? 'disabled' : null
|
|
284
|
+
}), stylex.props(inputWrapperStyles.base, sizeStyles[size], isDisabled && inputWrapperStyles.disabled, status && inputStatusBorderStyles[status.type], status && !isDisabled && inputStatusHoverShadowStyles[status.type], status && inputStatusFocusWithinStyles[status.type], inputGroup && groupStyles.inGroup, xstyle), className, style),
|
|
285
|
+
children: [/*#__PURE__*/_jsx("button", {
|
|
286
|
+
type: "button",
|
|
287
|
+
onClick: openSheet,
|
|
288
|
+
disabled: isEffectivelyDisabled,
|
|
289
|
+
"aria-label": t('@astryx.timeInput.openPicker', {
|
|
290
|
+
label
|
|
291
|
+
}),
|
|
292
|
+
tabIndex: -1,
|
|
293
|
+
...stylex.props(focusOutlineStyles.focusVisible, styles.iconButton),
|
|
294
|
+
children: /*#__PURE__*/_jsx(Icon, {
|
|
295
|
+
icon: "clock",
|
|
296
|
+
size: "sm",
|
|
297
|
+
color: "secondary"
|
|
298
|
+
})
|
|
299
|
+
}), /*#__PURE__*/_jsx("input", {
|
|
300
|
+
ref: mergedInputRef,
|
|
301
|
+
id: id,
|
|
302
|
+
type: "text",
|
|
303
|
+
role: "combobox",
|
|
304
|
+
value: displayValue,
|
|
305
|
+
readOnly: true,
|
|
306
|
+
inputMode: "none",
|
|
307
|
+
onChange: () => {},
|
|
308
|
+
onClick: openSheet,
|
|
309
|
+
placeholder: placeholder,
|
|
310
|
+
disabled: isEffectivelyDisabled && !showsDisabledMessage,
|
|
311
|
+
"aria-disabled": showsDisabledMessage ? 'true' : undefined,
|
|
312
|
+
"aria-describedby": ariaDescribedBy,
|
|
313
|
+
"aria-required": isEffectivelyRequired ? 'true' : undefined,
|
|
314
|
+
"aria-invalid": status?.type === 'error' ? 'true' : undefined,
|
|
315
|
+
"aria-busy": isBusy || undefined,
|
|
316
|
+
"aria-expanded": isSheetOpen,
|
|
317
|
+
"aria-haspopup": "dialog",
|
|
318
|
+
"aria-autocomplete": "none",
|
|
319
|
+
autoComplete: "off",
|
|
320
|
+
"aria-labelledby": ariaLabelledBy,
|
|
321
|
+
...{
|
|
322
|
+
className: "x1lliihq x98rzlu xeuugli xc342km xng3xce x1717udv xjbqb8w x1a2a7pz x1ypdohk x16khyan"
|
|
323
|
+
}
|
|
324
|
+
}), isBusy && /*#__PURE__*/_jsx(Spinner, {
|
|
325
|
+
size: "sm"
|
|
326
|
+
}), hasClear && optimisticValue && !isEffectivelyDisabled && /*#__PURE__*/_jsx(InputClearButton, {
|
|
327
|
+
label: t('@astryx.timeInput.clearLabel', {
|
|
328
|
+
label
|
|
329
|
+
}),
|
|
330
|
+
onClick: () => fireChange(undefined)
|
|
331
|
+
}), statusIcon, /*#__PURE__*/_jsx(BottomSheet, {
|
|
332
|
+
isOpen: isSheetOpen,
|
|
333
|
+
onOpenChange: setIsSheetOpen,
|
|
334
|
+
label: label,
|
|
335
|
+
height: "hug",
|
|
336
|
+
children: /*#__PURE__*/_jsxs("div", {
|
|
337
|
+
...{
|
|
338
|
+
className: "x9f619 x78zum5 xdt5ytf xh8yej3 xeuugli x1txdalj x1pzlopt x1adxfkp x1awphl8"
|
|
339
|
+
},
|
|
340
|
+
children: [/*#__PURE__*/_jsxs("div", {
|
|
341
|
+
...{
|
|
342
|
+
className: "x78zum5 xh8yej3 xeuugli xm8gem x1txdalj"
|
|
343
|
+
},
|
|
344
|
+
children: [/*#__PURE__*/_jsx(Wheel, {
|
|
345
|
+
label: t('@astryx.dateTimeInput.hourWheel'),
|
|
346
|
+
options: hourOptions,
|
|
347
|
+
value: hourFormat === '24h' ? parsedWheelTime.hour : hour12From24(parsedWheelTime.hour),
|
|
348
|
+
isActive: isSheetOpen,
|
|
349
|
+
onChange: hour => commitWheelTime(hourFormat === '24h' ? composeWheelTime({
|
|
350
|
+
hour24: hour
|
|
351
|
+
}) : composeWheelTime({
|
|
352
|
+
hour12: hour
|
|
353
|
+
}))
|
|
354
|
+
}), /*#__PURE__*/_jsx(Wheel, {
|
|
355
|
+
label: t('@astryx.dateTimeInput.minuteWheel'),
|
|
356
|
+
options: minuteOptions,
|
|
357
|
+
value: parsedWheelTime.minute,
|
|
358
|
+
isActive: isSheetOpen,
|
|
359
|
+
onChange: minute => commitWheelTime(composeWheelTime({
|
|
360
|
+
minute
|
|
361
|
+
}))
|
|
362
|
+
}), hasSeconds && /*#__PURE__*/_jsx(Wheel, {
|
|
363
|
+
label: t('@astryx.dateTimeInput.secondWheel'),
|
|
364
|
+
options: secondOptions,
|
|
365
|
+
value: parsedWheelTime.second,
|
|
366
|
+
isActive: isSheetOpen,
|
|
367
|
+
onChange: second => commitWheelTime(composeWheelTime({
|
|
368
|
+
second
|
|
369
|
+
}))
|
|
370
|
+
}), hourFormat === '12h' && /*#__PURE__*/_jsx(Wheel, {
|
|
371
|
+
label: t('@astryx.dateTimeInput.meridiemWheel'),
|
|
372
|
+
options: meridiemOptions,
|
|
373
|
+
value: parsedWheelTime.hour < 12 ? 0 : 1,
|
|
374
|
+
isActive: isSheetOpen,
|
|
375
|
+
onChange: meridiem => commitWheelTime(composeWheelTime({
|
|
376
|
+
meridiem
|
|
377
|
+
}))
|
|
378
|
+
})]
|
|
379
|
+
}), /*#__PURE__*/_jsx("div", {
|
|
380
|
+
...{
|
|
381
|
+
className: "x78zum5 xr1yuqi xfsso4q"
|
|
382
|
+
},
|
|
383
|
+
children: /*#__PURE__*/_jsx(Button, {
|
|
384
|
+
variant: "primary",
|
|
385
|
+
size: "md",
|
|
386
|
+
width: "100%",
|
|
387
|
+
label: t('@astryx.dateInput.savePicking'),
|
|
388
|
+
onClick: () => setIsSheetOpen(false)
|
|
389
|
+
})
|
|
390
|
+
})]
|
|
391
|
+
})
|
|
392
|
+
}), showsDisabledMessage && disabledMessageTooltip.renderTooltip(disabledMessage)]
|
|
393
|
+
});
|
|
394
|
+
if (inputGroup) {
|
|
395
|
+
return inputWrapper;
|
|
396
|
+
}
|
|
397
|
+
return /*#__PURE__*/_jsx(Field, {
|
|
398
|
+
label: label,
|
|
399
|
+
isLabelHidden: isLabelHidden,
|
|
400
|
+
description: description,
|
|
401
|
+
inputID: id,
|
|
402
|
+
descriptionID: description ? descriptionID : undefined,
|
|
403
|
+
isOptional: isOptional,
|
|
404
|
+
isRequired: isRequired,
|
|
405
|
+
isDisabled: isDisabled,
|
|
406
|
+
status: status ? {
|
|
407
|
+
type: status.type,
|
|
408
|
+
message: status.message,
|
|
409
|
+
messageID: status.message ? statusMessageID : undefined
|
|
410
|
+
} : undefined,
|
|
411
|
+
statusVariant: statusVariant,
|
|
412
|
+
labelTooltip: labelTooltip,
|
|
413
|
+
width: width,
|
|
414
|
+
children: inputWrapper
|
|
415
|
+
});
|
|
416
|
+
}
|
|
417
|
+
TouchTimeField.displayName = 'TouchTimeField';
|
|
@@ -7,6 +7,6 @@
|
|
|
7
7
|
* SYNC: When modified, update this header and /packages/core/src/TimeInput/TimeInput.doc.mjs
|
|
8
8
|
*/
|
|
9
9
|
export { TimeInput } from './TimeInput';
|
|
10
|
-
export type { TimeInputProps, TimeInputSize, TimeInputHourFormat, TimeInputNativePicker, TimeInputStatus, TimeInputStatusType, } from './TimeInput';
|
|
10
|
+
export type { TimeInputProps, TimeInputSize, TimeInputHourFormat, TimeInputNativePicker, TimeInputPresentation, TimeInputStatus, TimeInputStatusType, } from './TimeInput';
|
|
11
11
|
export type { ISOTimeString } from '../utils';
|
|
12
12
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/TimeInput/index.ts"],"names":[],"mappings":"AAIA;;;;;;;GAOG;AAEH,OAAO,EAAC,SAAS,EAAC,MAAM,aAAa,CAAC;AACtC,YAAY,EACV,cAAc,EACd,aAAa,EACb,mBAAmB,EACnB,qBAAqB,EACrB,eAAe,EACf,mBAAmB,GACpB,MAAM,aAAa,CAAC;AACrB,YAAY,EAAC,aAAa,EAAC,MAAM,UAAU,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/TimeInput/index.ts"],"names":[],"mappings":"AAIA;;;;;;;GAOG;AAEH,OAAO,EAAC,SAAS,EAAC,MAAM,aAAa,CAAC;AACtC,YAAY,EACV,cAAc,EACd,aAAa,EACb,mBAAmB,EACnB,qBAAqB,EACrB,qBAAqB,EACrB,eAAe,EACf,mBAAmB,GACpB,MAAM,aAAa,CAAC;AACrB,YAAY,EAAC,aAAa,EAAC,MAAM,UAAU,CAAC"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { BaseProps } from '../BaseProps';
|
|
2
|
+
import type { TextColor, TextSize, TextType, TextWeight } from '../theme/types';
|
|
3
|
+
export type TimerFormat = 'elapsed' | 'clock';
|
|
4
|
+
export interface TimerProps extends Omit<BaseProps<HTMLTimeElement>, 'dateTime'> {
|
|
5
|
+
/** Ref forwarded to the rendered `<time>` element. */
|
|
6
|
+
ref?: React.Ref<HTMLTimeElement>;
|
|
7
|
+
/**
|
|
8
|
+
* Unix time in milliseconds when the measured operation began. Omit it to
|
|
9
|
+
* start counting from this Timer's mount.
|
|
10
|
+
*/
|
|
11
|
+
startTime?: number;
|
|
12
|
+
/**
|
|
13
|
+
* Standard duration representation.
|
|
14
|
+
* @default 'elapsed'
|
|
15
|
+
*/
|
|
16
|
+
format?: TimerFormat;
|
|
17
|
+
/**
|
|
18
|
+
* Semantic text type. Matches Timestamp typography behavior.
|
|
19
|
+
* @default 'supporting'
|
|
20
|
+
*/
|
|
21
|
+
type?: TextType;
|
|
22
|
+
/** Explicit font size override. Overrides the size from `type`. */
|
|
23
|
+
size?: TextSize;
|
|
24
|
+
/**
|
|
25
|
+
* Text color.
|
|
26
|
+
* @default 'secondary'
|
|
27
|
+
*/
|
|
28
|
+
color?: TextColor;
|
|
29
|
+
/** Font weight override. */
|
|
30
|
+
weight?: TextWeight;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Displays a standardized elapsed duration without scheduling React tick renders.
|
|
34
|
+
*
|
|
35
|
+
* Timer writes changing text and its ISO 8601 duration directly to the owned
|
|
36
|
+
* `<time>` node. Use `elapsed` for compact duration text or `clock` for a
|
|
37
|
+
* stopwatch-like reading.
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* ```
|
|
41
|
+
* <Timer />
|
|
42
|
+
* <Timer format="clock" />
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
export declare function Timer({ startTime, format, type, size, color, weight, ref, xstyle, className, style, ...rest }: TimerProps): import("react").JSX.Element;
|
|
46
|
+
export declare namespace Timer {
|
|
47
|
+
var displayName: string;
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=Timer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Timer.d.ts","sourceRoot":"","sources":["../../src/Timer/Timer.tsx"],"names":[],"mappings":"AAqBA,OAAO,KAAK,EAAC,SAAS,EAAC,MAAM,cAAc,CAAC;AAG5C,OAAO,KAAK,EAAC,SAAS,EAAE,QAAQ,EAAE,QAAQ,EAAE,UAAU,EAAC,MAAM,gBAAgB,CAAC;AAsB9E,MAAM,MAAM,WAAW,GAAG,SAAS,GAAG,OAAO,CAAC;AA8E9C,MAAM,WAAW,UAAW,SAAQ,IAAI,CACtC,SAAS,CAAC,eAAe,CAAC,EAC1B,UAAU,CACX;IACC,sDAAsD;IACtD,GAAG,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;IACjC;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;OAGG;IACH,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB;;;OAGG;IACH,IAAI,CAAC,EAAE,QAAQ,CAAC;IAChB,mEAAmE;IACnE,IAAI,CAAC,EAAE,QAAQ,CAAC;IAChB;;;OAGG;IACH,KAAK,CAAC,EAAE,SAAS,CAAC;IAClB,4BAA4B;IAC5B,MAAM,CAAC,EAAE,UAAU,CAAC;CACrB;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,KAAK,CAAC,EACpB,SAAS,EACT,MAAkB,EAClB,IAAmB,EACnB,IAAI,EACJ,KAAmB,EACnB,MAAM,EACN,GAAG,EACH,MAAM,EACN,SAAS,EACT,KAAK,EACL,GAAG,IAAI,EACR,EAAE,UAAU,+BA0EZ;yBAtFe,KAAK"}
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
'use client';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @file Timer.tsx
|
|
7
|
+
* @input Uses an optional start time, standardized format, Timestamp typography, BaseProps, and React ref
|
|
8
|
+
* @output Exports Timer, TimerProps, and TimerFormat with non-rendering elapsed-time updates
|
|
9
|
+
* @position Core content primitive for elapsed duration in active operations
|
|
10
|
+
*
|
|
11
|
+
* SYNC: When modified, update these files to stay in sync:
|
|
12
|
+
* - /packages/core/src/Timer/Timer.spec.md
|
|
13
|
+
* - /packages/core/src/Timer/Timer.doc.mjs
|
|
14
|
+
* - /packages/core/src/Timer/Timer.test.tsx
|
|
15
|
+
* - /packages/core/src/Timer/index.ts
|
|
16
|
+
* - /apps/storybook/stories/Timer.stories.tsx
|
|
17
|
+
* - /packages/cli/assets/templates/blocks/components/Timer/
|
|
18
|
+
*/
|
|
19
|
+
import { useEffect, useRef, useState } from 'react';
|
|
20
|
+
import * as stylex from '@stylexjs/stylex';
|
|
21
|
+
import { useMergedRefs } from "../hooks/useMergedRefs.js";
|
|
22
|
+
import { Text } from "../Text/index.js";
|
|
23
|
+
import { mergeProps } from "../utils/index.js";
|
|
24
|
+
import { themeProps } from "../utils/themeProps.js";
|
|
25
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
26
|
+
const ONE_SECOND_MS = 1000;
|
|
27
|
+
const ONE_MINUTE_MS = 60 * ONE_SECOND_MS;
|
|
28
|
+
const ONE_HOUR_SECONDS = 60 * 60;
|
|
29
|
+
const MAX_TIMEOUT_MS = 2_147_483_647;
|
|
30
|
+
function pad(value) {
|
|
31
|
+
return String(value).padStart(2, '0');
|
|
32
|
+
}
|
|
33
|
+
function resolveFormat(format) {
|
|
34
|
+
return format === 'clock' ? 'clock' : 'elapsed';
|
|
35
|
+
}
|
|
36
|
+
function getElapsedMilliseconds(now, startTime) {
|
|
37
|
+
return Math.max(0, now - startTime);
|
|
38
|
+
}
|
|
39
|
+
function getPresentation(elapsedMilliseconds, format) {
|
|
40
|
+
const elapsedSeconds = Math.floor(elapsedMilliseconds / ONE_SECOND_MS);
|
|
41
|
+
if (format === 'clock') {
|
|
42
|
+
const hours = Math.floor(elapsedSeconds / ONE_HOUR_SECONDS);
|
|
43
|
+
const minutes = Math.floor(elapsedSeconds % ONE_HOUR_SECONDS / 60);
|
|
44
|
+
const seconds = elapsedSeconds % 60;
|
|
45
|
+
return {
|
|
46
|
+
dateTime: `PT${elapsedSeconds}S`,
|
|
47
|
+
text: hours > 0 ? `${String(hours)}:${pad(minutes)}:${pad(seconds)}` : `${String(minutes)}:${pad(seconds)}`
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
if (elapsedSeconds < 60) {
|
|
51
|
+
return {
|
|
52
|
+
dateTime: `PT${elapsedSeconds}S`,
|
|
53
|
+
text: `${String(elapsedSeconds)}s`
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
const totalMinutes = Math.floor(elapsedSeconds / 60);
|
|
57
|
+
if (totalMinutes < 60) {
|
|
58
|
+
return {
|
|
59
|
+
dateTime: `PT${elapsedSeconds}S`,
|
|
60
|
+
text: `${String(totalMinutes)}m ${pad(elapsedSeconds % 60)}s`
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
const representedSeconds = totalMinutes * 60;
|
|
64
|
+
return {
|
|
65
|
+
dateTime: `PT${representedSeconds}S`,
|
|
66
|
+
text: `${String(Math.floor(totalMinutes / 60))}h ${pad(totalMinutes % 60)}m`
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
function getMillisecondsUntilNextChange(now, startTime, elapsedMilliseconds, format) {
|
|
70
|
+
if (now < startTime) {
|
|
71
|
+
return Math.min(startTime - now + ONE_SECOND_MS, MAX_TIMEOUT_MS);
|
|
72
|
+
}
|
|
73
|
+
const precision = format === 'elapsed' && elapsedMilliseconds >= ONE_HOUR_SECONDS * ONE_SECOND_MS ? ONE_MINUTE_MS : ONE_SECOND_MS;
|
|
74
|
+
return precision - elapsedMilliseconds % precision;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Displays a standardized elapsed duration without scheduling React tick renders.
|
|
78
|
+
*
|
|
79
|
+
* Timer writes changing text and its ISO 8601 duration directly to the owned
|
|
80
|
+
* `<time>` node. Use `elapsed` for compact duration text or `clock` for a
|
|
81
|
+
* stopwatch-like reading.
|
|
82
|
+
*
|
|
83
|
+
* @example
|
|
84
|
+
* ```
|
|
85
|
+
* <Timer />
|
|
86
|
+
* <Timer format="clock" />
|
|
87
|
+
* ```
|
|
88
|
+
*/
|
|
89
|
+
export function Timer({
|
|
90
|
+
startTime,
|
|
91
|
+
format = 'elapsed',
|
|
92
|
+
type = 'supporting',
|
|
93
|
+
size,
|
|
94
|
+
color = 'secondary',
|
|
95
|
+
weight,
|
|
96
|
+
ref,
|
|
97
|
+
xstyle,
|
|
98
|
+
className,
|
|
99
|
+
style,
|
|
100
|
+
...rest
|
|
101
|
+
}) {
|
|
102
|
+
const [mountTime] = useState(() => Date.now());
|
|
103
|
+
const timerRef = useRef(null);
|
|
104
|
+
const mergedRef = useMergedRefs(ref, timerRef);
|
|
105
|
+
const resolvedFormat = resolveFormat(format);
|
|
106
|
+
const initialPresentation = getPresentation(0, resolvedFormat);
|
|
107
|
+
useEffect(() => {
|
|
108
|
+
const resolvedStartTime = startTime !== undefined && Number.isFinite(startTime) ? startTime : mountTime;
|
|
109
|
+
let timeoutID;
|
|
110
|
+
let previousDateTime;
|
|
111
|
+
let previousText;
|
|
112
|
+
const tick = () => {
|
|
113
|
+
const now = Date.now();
|
|
114
|
+
const elapsedMilliseconds = getElapsedMilliseconds(now, resolvedStartTime);
|
|
115
|
+
const presentation = getPresentation(elapsedMilliseconds, resolvedFormat);
|
|
116
|
+
const node = timerRef.current;
|
|
117
|
+
if (node != null) {
|
|
118
|
+
if (presentation.text !== previousText) {
|
|
119
|
+
node.textContent = presentation.text;
|
|
120
|
+
previousText = presentation.text;
|
|
121
|
+
}
|
|
122
|
+
if (presentation.dateTime !== previousDateTime) {
|
|
123
|
+
node.dateTime = presentation.dateTime;
|
|
124
|
+
previousDateTime = presentation.dateTime;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
timeoutID = setTimeout(tick, getMillisecondsUntilNextChange(now, resolvedStartTime, elapsedMilliseconds, resolvedFormat));
|
|
128
|
+
};
|
|
129
|
+
tick();
|
|
130
|
+
return () => {
|
|
131
|
+
if (timeoutID !== undefined) {
|
|
132
|
+
clearTimeout(timeoutID);
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
}, [mountTime, resolvedFormat, startTime]);
|
|
136
|
+
const timerProps = mergeProps(themeProps('timer'), {
|
|
137
|
+
className,
|
|
138
|
+
style
|
|
139
|
+
});
|
|
140
|
+
return /*#__PURE__*/_jsx(Text, {
|
|
141
|
+
type: type,
|
|
142
|
+
size: size,
|
|
143
|
+
color: color,
|
|
144
|
+
weight: weight,
|
|
145
|
+
xstyle: xstyle,
|
|
146
|
+
...timerProps,
|
|
147
|
+
children: /*#__PURE__*/_jsx("time", {
|
|
148
|
+
...rest,
|
|
149
|
+
ref: mergedRef,
|
|
150
|
+
dateTime: "PT0S",
|
|
151
|
+
...{
|
|
152
|
+
className: "x1heor9g xt0psk2 xjb2p0i x1qlqyl8 x1j61x8r xss6m8b x1pd3egz x15bjb6t"
|
|
153
|
+
},
|
|
154
|
+
children: initialPresentation.text
|
|
155
|
+
})
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
Timer.displayName = 'Timer';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file index.ts
|
|
3
|
+
* @input Imports Timer, TimerProps, and TimerFormat
|
|
4
|
+
* @output Public Timer component barrel
|
|
5
|
+
* @position Component subpath entry point for @astryxdesign/core/Timer
|
|
6
|
+
*/
|
|
7
|
+
export { Timer } from './Timer';
|
|
8
|
+
export type { TimerFormat, TimerProps } from './Timer';
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/Timer/index.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AAEH,OAAO,EAAC,KAAK,EAAC,MAAM,SAAS,CAAC;AAC9B,YAAY,EAAC,WAAW,EAAE,UAAU,EAAC,MAAM,SAAS,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @file index.ts
|
|
5
|
+
* @input Imports Timer, TimerProps, and TimerFormat
|
|
6
|
+
* @output Public Timer component barrel
|
|
7
|
+
* @position Component subpath entry point for @astryxdesign/core/Timer
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
export { Timer } from "./Timer.js";
|