@astronox/core 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +66 -0
- package/package.json +77 -0
- package/src/client/clipboard.ts +7 -0
- package/src/client/focus.ts +17 -0
- package/src/client/index.ts +3 -0
- package/src/client/scroll.ts +15 -0
- package/src/components/actions/ActionListItem/ActionListItem.astro +78 -0
- package/src/components/actions/ActionListItem/ActionListItem.css +43 -0
- package/src/components/actions/Button/Button.astro +100 -0
- package/src/components/actions/Button/Button.css +165 -0
- package/src/components/actions/CardAction/CardAction.astro +97 -0
- package/src/components/actions/CardAction/CardAction.css +188 -0
- package/src/components/actions/MediaTrigger/MediaTrigger.astro +55 -0
- package/src/components/actions/MediaTrigger/MediaTrigger.css +175 -0
- package/src/components/actions/ScrollToTop/ScrollToTop.astro +36 -0
- package/src/components/actions/ScrollToTop/ScrollToTop.css +19 -0
- package/src/components/actions/ScrollToTop/scrollToTopController.ts +32 -0
- package/src/components/content/CardBody/CardBody.astro +31 -0
- package/src/components/content/CardBody/CardBody.css +74 -0
- package/src/components/content/CardFooter/CardFooter.astro +58 -0
- package/src/components/content/CardFooter/CardFooter.css +102 -0
- package/src/components/content/CardHeader/CardHeader.astro +96 -0
- package/src/components/content/CardHeader/CardHeader.css +164 -0
- package/src/components/content/CardLink/CardLink.astro +138 -0
- package/src/components/content/CardLink/CardLink.css +362 -0
- package/src/components/content/CodeBlock/CodeBlock.astro +102 -0
- package/src/components/content/CodeBlock/CodeBlock.css +85 -0
- package/src/components/content/CodeBlock/codeBlockController.ts +60 -0
- package/src/components/content/CodeBlock/contracts.ts +8 -0
- package/src/components/content/InlineDefinition/InlineDefinition.astro +31 -0
- package/src/components/content/InlineDefinition/InlineDefinition.css +9 -0
- package/src/components/content/MarkdownContent/MarkdownContent.astro +32 -0
- package/src/components/content/MarkdownContent/MarkdownContent.css +358 -0
- package/src/components/content/MarkdownContent/MarkdownInline.astro +44 -0
- package/src/components/content/MarkdownContent/MarkdownNode.astro +280 -0
- package/src/components/content/MarkdownContent/MarkdownSymbol.astro +47 -0
- package/src/components/content/MarkdownContent/contracts.ts +181 -0
- package/src/components/data-display/BadgeList/BadgeList.astro +54 -0
- package/src/components/data-display/BadgeList/BadgeList.css +29 -0
- package/src/components/data-display/IconList/IconList.astro +64 -0
- package/src/components/data-display/IconList/IconList.css +55 -0
- package/src/components/data-display/MetricTile/MetricTile.astro +68 -0
- package/src/components/data-display/MetricTile/MetricTile.css +103 -0
- package/src/components/data-display/MetricTile/MetricTileContent.astro +70 -0
- package/src/components/data-display/MetricTile/metricTileController.ts +9 -0
- package/src/components/data-display/Tag/Tag.astro +67 -0
- package/src/components/data-display/Tag/Tag.css +134 -0
- package/src/components/data-display/Tag/TagAffix.astro +33 -0
- package/src/components/data-display/TextPair/TextPair.astro +63 -0
- package/src/components/data-display/TextPair/TextPair.css +99 -0
- package/src/components/feedback/Spinner/Spinner.astro +32 -0
- package/src/components/feedback/Spinner/Spinner.css +37 -0
- package/src/components/feedback/Tooltip/Tooltip.astro +66 -0
- package/src/components/feedback/Tooltip/Tooltip.css +67 -0
- package/src/components/feedback/Tooltip/tooltipController.ts +371 -0
- package/src/components/forms/FieldError/FieldError.astro +31 -0
- package/src/components/forms/FieldError/FieldError.css +12 -0
- package/src/components/forms/FieldError/fieldErrorState.ts +21 -0
- package/src/components/forms/FieldLabel/FieldLabel.astro +32 -0
- package/src/components/forms/FieldLabel/FieldLabel.css +17 -0
- package/src/components/forms/TextInput/TextInput.astro +79 -0
- package/src/components/forms/TextInput/TextInput.css +121 -0
- package/src/components/forms/TextInput/textInputController.ts +53 -0
- package/src/components/icons/ArrowDownIcon.astro +26 -0
- package/src/components/icons/ArrowLeftIcon.astro +26 -0
- package/src/components/icons/ArrowRightIcon.astro +26 -0
- package/src/components/icons/ArrowUpDownIcon.astro +26 -0
- package/src/components/icons/ArrowUpIcon.astro +26 -0
- package/src/components/icons/BulletIcon.astro +21 -0
- package/src/components/icons/BurnIcon.astro +24 -0
- package/src/components/icons/CircleSymbolIcon.css +66 -0
- package/src/components/icons/ClearIcon.astro +28 -0
- package/src/components/icons/CloseIcon.astro +21 -0
- package/src/components/icons/CopyIcon.astro +30 -0
- package/src/components/icons/CurrencyIcon.css +9 -0
- package/src/components/icons/DayIcon.astro +33 -0
- package/src/components/icons/DollarIcon.astro +28 -0
- package/src/components/icons/DownloadIcon.astro +22 -0
- package/src/components/icons/EnterFullscreenIcon.astro +22 -0
- package/src/components/icons/EqualIcon.astro +25 -0
- package/src/components/icons/ExitFullscreenIcon.astro +22 -0
- package/src/components/icons/ExternalLinkIcon.astro +22 -0
- package/src/components/icons/FieldIcon.astro +28 -0
- package/src/components/icons/GrassIcon.astro +29 -0
- package/src/components/icons/InfoIcon.astro +24 -0
- package/src/components/icons/MinusIcon.astro +21 -0
- package/src/components/icons/MountainIcon.astro +31 -0
- package/src/components/icons/NightIcon.astro +32 -0
- package/src/components/icons/PlayIcon.astro +22 -0
- package/src/components/icons/PlusIcon.astro +21 -0
- package/src/components/icons/PoisonIcon.astro +24 -0
- package/src/components/icons/RibbonIcon.astro +25 -0
- package/src/components/icons/SlashIcon.astro +22 -0
- package/src/components/icons/SlowIcon.astro +25 -0
- package/src/components/icons/StarIcon.astro +28 -0
- package/src/components/icons/StunIcon.astro +22 -0
- package/src/components/icons/TableSortIcon.astro +34 -0
- package/src/components/icons/WaterIcon.astro +30 -0
- package/src/components/index.ts +83 -0
- package/src/components/media/CanvasFrame/CanvasFrame.astro +130 -0
- package/src/components/media/CanvasFrame/CanvasFrame.css +59 -0
- package/src/components/media/CanvasFrame/canvasFrameController.ts +104 -0
- package/src/components/media/EmbedFrame/EmbedFrame.astro +147 -0
- package/src/components/media/EmbedFrame/EmbedFrame.css +51 -0
- package/src/components/media/EmbedFrame/embedFrameController.ts +66 -0
- package/src/components/media/MediaFrame/MediaFrame.astro +34 -0
- package/src/components/media/MediaFrame/MediaFrame.css +66 -0
- package/src/components/navigation/Breadcrumbs/Breadcrumbs.astro +55 -0
- package/src/components/navigation/Breadcrumbs/Breadcrumbs.css +89 -0
- package/src/components/navigation/DesktopNavigation.astro +92 -0
- package/src/components/navigation/DesktopNavigation.css +99 -0
- package/src/components/navigation/Header.astro +73 -0
- package/src/components/navigation/Header.css +20 -0
- package/src/components/navigation/MobileNavigation.astro +124 -0
- package/src/components/navigation/MobileNavigation.css +177 -0
- package/src/components/navigation/NavigationBrand.astro +63 -0
- package/src/components/navigation/NavigationBrand.css +52 -0
- package/src/components/navigation/NavigationControl.css +166 -0
- package/src/components/navigation/NavigationItemContent.astro +24 -0
- package/src/components/navigation/NavigationLink.astro +121 -0
- package/src/components/navigation/NavigationLinks.astro +27 -0
- package/src/components/navigation/NavigationMenuList.astro +37 -0
- package/src/components/navigation/NavigationMenuList.css +6 -0
- package/src/components/navigation/SkipLink/SkipLink.astro +18 -0
- package/src/components/navigation/SkipLink/SkipLink.css +26 -0
- package/src/components/navigation/SubNavigation/SubNavigation.astro +124 -0
- package/src/components/navigation/SubNavigation/SubNavigation.css +211 -0
- package/src/components/navigation/mobileNavigationController.ts +122 -0
- package/src/components/navigation/navigationState.ts +35 -0
- package/src/components/navigation/navigationTypes.ts +18 -0
- package/src/components/seo/SeoHead.astro +194 -0
- package/src/components/widgetTypes.ts +3 -0
- package/src/composition/Grid/Grid.astro +82 -0
- package/src/composition/Grid/Grid.css +314 -0
- package/src/composition/GridItem/GridItem.astro +50 -0
- package/src/composition/GridItem/GridItem.css +95 -0
- package/src/composition/Inline/Inline.astro +48 -0
- package/src/composition/Inline/Inline.css +65 -0
- package/src/composition/Stack/Stack.astro +37 -0
- package/src/composition/Stack/Stack.css +31 -0
- package/src/composition/SurfaceGroup/SurfaceGroup.astro +44 -0
- package/src/composition/SurfaceGroup/SurfaceGroup.css +76 -0
- package/src/composition/SurfaceGroup/stickySurfaceGroupController.ts +89 -0
- package/src/composition/index.ts +6 -0
- package/src/config/index.ts +2 -0
- package/src/config/pageMeta.ts +55 -0
- package/src/config/siteConfig.ts +90 -0
- package/src/data/collectionValidation.ts +61 -0
- package/src/data/index.ts +1 -0
- package/src/display/contracts.ts +284 -0
- package/src/display/index.ts +1 -0
- package/src/index.ts +6 -0
- package/src/layouts/BaseLayout.astro +74 -0
- package/src/layouts/PageSurface.astro +15 -0
- package/src/layouts/PageSurface.css +24 -0
- package/src/layouts/index.ts +2 -0
- package/src/patterns/CircuitPuzzle/CircuitPuzzle.astro +93 -0
- package/src/patterns/CircuitPuzzle/CircuitPuzzle.css +118 -0
- package/src/patterns/CircuitPuzzle/circuitPuzzleController.ts +205 -0
- package/src/patterns/CircuitPuzzle/contracts.ts +42 -0
- package/src/patterns/Combobox/Combobox.astro +462 -0
- package/src/patterns/Combobox/Combobox.css +403 -0
- package/src/patterns/Combobox/comboboxController.ts +788 -0
- package/src/patterns/Combobox/contracts.ts +18 -0
- package/src/patterns/Dropdown/Dropdown.astro +127 -0
- package/src/patterns/Dropdown/Dropdown.css +100 -0
- package/src/patterns/Dropdown/dropdownController.ts +157 -0
- package/src/patterns/Fullscreen/FullscreenControl.astro +103 -0
- package/src/patterns/Fullscreen/FullscreenControl.css +49 -0
- package/src/patterns/Fullscreen/fullscreenController.ts +73 -0
- package/src/patterns/GlitchOverlay/GlitchOverlay.astro +50 -0
- package/src/patterns/GlitchOverlay/GlitchOverlay.css +234 -0
- package/src/patterns/GlitchOverlay/glitchOverlayController.ts +152 -0
- package/src/patterns/GuidedFlow/GuidedFlow.astro +60 -0
- package/src/patterns/GuidedFlow/GuidedFlow.css +82 -0
- package/src/patterns/GuidedFlow/contracts.ts +3 -0
- package/src/patterns/GuidedFlow/guidedFlowController.ts +49 -0
- package/src/patterns/MagneticFieldPuzzle/MagneticFieldPuzzle.astro +217 -0
- package/src/patterns/MagneticFieldPuzzle/MagneticFieldPuzzle.css +383 -0
- package/src/patterns/MagneticFieldPuzzle/contracts.ts +81 -0
- package/src/patterns/MagneticFieldPuzzle/magneticFieldPuzzleController.ts +802 -0
- package/src/patterns/MagneticFieldPuzzle/simulation.ts +244 -0
- package/src/patterns/MapViewport/MapViewport.astro +296 -0
- package/src/patterns/MapViewport/MapViewport.css +257 -0
- package/src/patterns/MapViewport/contracts.ts +79 -0
- package/src/patterns/MapViewport/geometry.ts +80 -0
- package/src/patterns/MapViewport/mapViewportController.ts +636 -0
- package/src/patterns/Modal/Modal.astro +64 -0
- package/src/patterns/Modal/Modal.css +87 -0
- package/src/patterns/Modal/ModalClose.astro +37 -0
- package/src/patterns/Modal/ModalOpen.astro +36 -0
- package/src/patterns/Modal/modalController.ts +118 -0
- package/src/patterns/PuzzleGrid/PuzzleGrid.astro +22 -0
- package/src/patterns/PuzzleGrid/PuzzleGrid.css +149 -0
- package/src/patterns/PuzzleGrid/contracts.ts +2 -0
- package/src/patterns/PuzzleGrid/selectionDismissal.ts +27 -0
- package/src/patterns/PuzzleGrid/state.ts +25 -0
- package/src/patterns/SpriteProjectilePreview/SpriteProjectilePreview.astro +65 -0
- package/src/patterns/SpriteProjectilePreview/SpriteProjectilePreview.css +35 -0
- package/src/patterns/SpriteProjectilePreview/contracts.ts +33 -0
- package/src/patterns/SpriteProjectilePreview/spriteProjectilePreviewController.ts +586 -0
- package/src/patterns/StageFlow/StageFlow.astro +57 -0
- package/src/patterns/StageFlow/StageFlow.css +54 -0
- package/src/patterns/StageFlow/StageFlowAlternative.astro +23 -0
- package/src/patterns/StageFlow/StageFlowArrow.astro +22 -0
- package/src/patterns/StageFlow/StageFlowConnector.astro +7 -0
- package/src/patterns/StageFlow/StageFlowConnector.css +4 -0
- package/src/patterns/StageFlow/StageFlowStage.astro +51 -0
- package/src/patterns/StageFlow/StageFlowStage.css +106 -0
- package/src/patterns/StageFlow/StageFlowStep.astro +24 -0
- package/src/patterns/StageFlow/StageFlowStep.css +19 -0
- package/src/patterns/StageFlow/StageFlowSymbol.css +28 -0
- package/src/patterns/Table/Table.astro +176 -0
- package/src/patterns/Table/Table.css +70 -0
- package/src/patterns/Table/TableBody.astro +185 -0
- package/src/patterns/Table/TableBody.css +262 -0
- package/src/patterns/Table/TableCell.astro +59 -0
- package/src/patterns/Table/TableCell.css +99 -0
- package/src/patterns/Table/TableCellValue.astro +86 -0
- package/src/patterns/Table/TableFooter.astro +32 -0
- package/src/patterns/Table/TableFooter.css +31 -0
- package/src/patterns/Table/TableHeader.astro +118 -0
- package/src/patterns/Table/TableHeader.css +209 -0
- package/src/patterns/Table/TablePagination.astro +70 -0
- package/src/patterns/Table/TablePagination.css +133 -0
- package/src/patterns/Table/TableSkeleton.astro +36 -0
- package/src/patterns/Table/TableSkeleton.css +81 -0
- package/src/patterns/Table/tableCellController.ts +11 -0
- package/src/patterns/Table/tableFilterController.ts +206 -0
- package/src/patterns/Table/tableHeaderOverflowController.ts +105 -0
- package/src/patterns/Table/tableLayout.ts +113 -0
- package/src/patterns/Table/tableProgressiveController.ts +319 -0
- package/src/patterns/Table/tableRowNavigationController.ts +91 -0
- package/src/patterns/Table/tableScrollController.ts +192 -0
- package/src/patterns/Table/tableSortController.ts +272 -0
- package/src/patterns/index.ts +46 -0
- package/src/primitives/index.ts +4 -0
- package/src/primitives/layout/Separator/Separator.astro +29 -0
- package/src/primitives/layout/Separator/Separator.css +20 -0
- package/src/primitives/media/AmbientAudio/AmbientAudio.astro +28 -0
- package/src/primitives/media/Media/Media.astro +122 -0
- package/src/primitives/media/Media/Media.css +161 -0
- package/src/primitives/text/TextBlock/TextBlock.astro +46 -0
- package/src/primitives/text/TextBlock/TextBlock.css +21 -0
- package/src/seo/StaticRedirect.astro +32 -0
- package/src/seo/index.ts +6 -0
- package/src/seo/pageSeo.ts +99 -0
- package/src/seo/robots.ts +16 -0
- package/src/seo/sitemap.ts +38 -0
- package/src/seo/structuredData.ts +133 -0
- package/src/seo/url.ts +64 -0
- package/src/styles/base.css +148 -0
- package/src/styles/interaction.css +108 -0
- package/src/styles/style.css +93 -0
- package/src/styles/tokens.css +256 -0
- package/src/theme/contracts.ts +7 -0
- package/src/theme/index.ts +1 -0
- package/tsconfig.json +20 -0
|
@@ -0,0 +1,462 @@
|
|
|
1
|
+
---
|
|
2
|
+
import type { HTMLAttributes } from 'astro/types';
|
|
3
|
+
import type { Tone } from '../../theme/contracts';
|
|
4
|
+
import type {
|
|
5
|
+
ComboboxOption,
|
|
6
|
+
ComboboxSelectionMode,
|
|
7
|
+
ComboboxSize,
|
|
8
|
+
} from './contracts';
|
|
9
|
+
import Tag from '../../components/data-display/Tag/Tag.astro';
|
|
10
|
+
import TextInput from '../../components/forms/TextInput/TextInput.astro';
|
|
11
|
+
import ArrowDownIcon from '../../components/icons/ArrowDownIcon.astro';
|
|
12
|
+
import Media from '../../primitives/media/Media/Media.astro';
|
|
13
|
+
|
|
14
|
+
type SharedProps = Omit<HTMLAttributes<'div'>, 'id'> & {
|
|
15
|
+
id: string;
|
|
16
|
+
label: string;
|
|
17
|
+
disabled?: boolean;
|
|
18
|
+
size?: ComboboxSize;
|
|
19
|
+
tone?: Tone;
|
|
20
|
+
width?: 'auto' | 'fill';
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
type OptionsProps = SharedProps & {
|
|
24
|
+
mode?: 'options';
|
|
25
|
+
options: readonly ComboboxOption[];
|
|
26
|
+
clearable?: boolean;
|
|
27
|
+
closeOnSelect?: boolean;
|
|
28
|
+
emptyLabel: string;
|
|
29
|
+
placeholder: string;
|
|
30
|
+
removeLabel: string;
|
|
31
|
+
searchPlaceholder: string;
|
|
32
|
+
selectionMode?: ComboboxSelectionMode;
|
|
33
|
+
value?: string | readonly string[];
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
type NumberProps = SharedProps & {
|
|
37
|
+
mode: 'number';
|
|
38
|
+
min: number;
|
|
39
|
+
max: number;
|
|
40
|
+
step?: number;
|
|
41
|
+
value: number;
|
|
42
|
+
decrementLabel: string;
|
|
43
|
+
incrementLabel: string;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
type Props = OptionsProps | NumberProps;
|
|
47
|
+
|
|
48
|
+
function getNativeAttributes(
|
|
49
|
+
props: Props,
|
|
50
|
+
ownedKeys: readonly string[],
|
|
51
|
+
): HTMLAttributes<'div'> {
|
|
52
|
+
const nativeAttributes = { ...props } as Record<string, unknown>;
|
|
53
|
+
for (const key of ownedKeys) delete nativeAttributes[key];
|
|
54
|
+
|
|
55
|
+
return nativeAttributes as HTMLAttributes<'div'>;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const props: Props = Astro.props;
|
|
59
|
+
const mode = props.mode ?? 'options';
|
|
60
|
+
const disabled = props.disabled ?? false;
|
|
61
|
+
const size = props.size ?? (mode === 'number' ? 'sm' : undefined);
|
|
62
|
+
const width = props.width ?? 'auto';
|
|
63
|
+
const resolvedTone = props.tone ?? props['data-tone'];
|
|
64
|
+
const listboxId = `${props.id}-listbox`;
|
|
65
|
+
|
|
66
|
+
let attrs: HTMLAttributes<'div'>;
|
|
67
|
+
let options: readonly ComboboxOption[];
|
|
68
|
+
let selectedValues: string[];
|
|
69
|
+
let clearable = false;
|
|
70
|
+
let closeOnSelect = true;
|
|
71
|
+
let emptyLabel = '';
|
|
72
|
+
let placeholder = '';
|
|
73
|
+
let removeLabel = '';
|
|
74
|
+
let searchPlaceholder = '';
|
|
75
|
+
let selectionMode: ComboboxSelectionMode = 'single';
|
|
76
|
+
let numberValue: number | undefined;
|
|
77
|
+
let min: number | undefined;
|
|
78
|
+
let max: number | undefined;
|
|
79
|
+
let step: number | undefined;
|
|
80
|
+
let decrementLabel = '';
|
|
81
|
+
let incrementLabel = '';
|
|
82
|
+
|
|
83
|
+
if (mode === 'number') {
|
|
84
|
+
const numberProps = props as NumberProps;
|
|
85
|
+
const requestedDecrementLabel = numberProps.decrementLabel;
|
|
86
|
+
const requestedIncrementLabel = numberProps.incrementLabel;
|
|
87
|
+
const requestedMin = numberProps.min;
|
|
88
|
+
const requestedMax = numberProps.max;
|
|
89
|
+
const requestedStep = numberProps.step ?? 1;
|
|
90
|
+
const requestedValue = numberProps.value;
|
|
91
|
+
|
|
92
|
+
if (
|
|
93
|
+
!Number.isInteger(requestedMin) ||
|
|
94
|
+
!Number.isInteger(requestedMax) ||
|
|
95
|
+
requestedMin > requestedMax
|
|
96
|
+
) {
|
|
97
|
+
throw new RangeError('Combobox number bounds must be ordered integers');
|
|
98
|
+
}
|
|
99
|
+
if (!Number.isFinite(requestedValue)) {
|
|
100
|
+
throw new RangeError('Combobox number value must be finite');
|
|
101
|
+
}
|
|
102
|
+
if (
|
|
103
|
+
!Number.isInteger(requestedStep) ||
|
|
104
|
+
requestedStep < 1 ||
|
|
105
|
+
(requestedMax - requestedMin) % requestedStep !== 0
|
|
106
|
+
) {
|
|
107
|
+
throw new RangeError(
|
|
108
|
+
'Combobox number step must be a positive integer that divides the range',
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const normalizedValue = Math.min(
|
|
113
|
+
requestedMax,
|
|
114
|
+
Math.max(
|
|
115
|
+
requestedMin,
|
|
116
|
+
requestedMin +
|
|
117
|
+
Math.round((requestedValue - requestedMin) / requestedStep) *
|
|
118
|
+
requestedStep,
|
|
119
|
+
),
|
|
120
|
+
);
|
|
121
|
+
|
|
122
|
+
attrs = getNativeAttributes(numberProps, [
|
|
123
|
+
'class',
|
|
124
|
+
'data-tone',
|
|
125
|
+
'decrementLabel',
|
|
126
|
+
'disabled',
|
|
127
|
+
'id',
|
|
128
|
+
'incrementLabel',
|
|
129
|
+
'label',
|
|
130
|
+
'max',
|
|
131
|
+
'min',
|
|
132
|
+
'mode',
|
|
133
|
+
'size',
|
|
134
|
+
'step',
|
|
135
|
+
'tone',
|
|
136
|
+
'value',
|
|
137
|
+
'width',
|
|
138
|
+
]);
|
|
139
|
+
min = requestedMin;
|
|
140
|
+
max = requestedMax;
|
|
141
|
+
step = requestedStep;
|
|
142
|
+
numberValue = normalizedValue;
|
|
143
|
+
decrementLabel = requestedDecrementLabel;
|
|
144
|
+
incrementLabel = requestedIncrementLabel;
|
|
145
|
+
options = Array.from(
|
|
146
|
+
{
|
|
147
|
+
length: Math.floor((requestedMax - requestedMin) / requestedStep) + 1,
|
|
148
|
+
},
|
|
149
|
+
(_, index): ComboboxOption => {
|
|
150
|
+
const value = requestedMin + index * requestedStep;
|
|
151
|
+
return { value: String(value), label: String(value) };
|
|
152
|
+
},
|
|
153
|
+
);
|
|
154
|
+
selectedValues = [String(normalizedValue)];
|
|
155
|
+
} else {
|
|
156
|
+
const optionsProps = props as OptionsProps;
|
|
157
|
+
const requestedClearable = optionsProps.clearable ?? true;
|
|
158
|
+
const requestedCloseOnSelect = optionsProps.closeOnSelect;
|
|
159
|
+
const requestedEmptyLabel = optionsProps.emptyLabel;
|
|
160
|
+
const requestedOptions = optionsProps.options;
|
|
161
|
+
const requestedPlaceholder = optionsProps.placeholder;
|
|
162
|
+
const requestedRemoveLabel = optionsProps.removeLabel;
|
|
163
|
+
const requestedSearchPlaceholder = optionsProps.searchPlaceholder;
|
|
164
|
+
const requestedSelectionMode = optionsProps.selectionMode ?? 'single';
|
|
165
|
+
const requestedValues = Array.isArray(optionsProps.value)
|
|
166
|
+
? optionsProps.value
|
|
167
|
+
: typeof optionsProps.value === 'string'
|
|
168
|
+
? [optionsProps.value]
|
|
169
|
+
: [];
|
|
170
|
+
const optionValues = new Set(
|
|
171
|
+
requestedOptions
|
|
172
|
+
.filter((option) => !option.disabled)
|
|
173
|
+
.map((option) => option.value),
|
|
174
|
+
);
|
|
175
|
+
|
|
176
|
+
attrs = getNativeAttributes(optionsProps, [
|
|
177
|
+
'class',
|
|
178
|
+
'data-tone',
|
|
179
|
+
'clearable',
|
|
180
|
+
'closeOnSelect',
|
|
181
|
+
'disabled',
|
|
182
|
+
'emptyLabel',
|
|
183
|
+
'id',
|
|
184
|
+
'label',
|
|
185
|
+
'mode',
|
|
186
|
+
'options',
|
|
187
|
+
'placeholder',
|
|
188
|
+
'removeLabel',
|
|
189
|
+
'searchPlaceholder',
|
|
190
|
+
'selectionMode',
|
|
191
|
+
'size',
|
|
192
|
+
'tone',
|
|
193
|
+
'value',
|
|
194
|
+
'width',
|
|
195
|
+
]);
|
|
196
|
+
clearable = requestedClearable;
|
|
197
|
+
closeOnSelect = requestedCloseOnSelect ?? requestedSelectionMode === 'single';
|
|
198
|
+
emptyLabel = requestedEmptyLabel;
|
|
199
|
+
options = requestedOptions;
|
|
200
|
+
placeholder = requestedPlaceholder;
|
|
201
|
+
removeLabel = requestedRemoveLabel;
|
|
202
|
+
searchPlaceholder = requestedSearchPlaceholder;
|
|
203
|
+
selectionMode = requestedSelectionMode;
|
|
204
|
+
selectedValues = [
|
|
205
|
+
...new Set(requestedValues.filter((item) => optionValues.has(item))),
|
|
206
|
+
];
|
|
207
|
+
if (selectionMode === 'single') selectedValues.splice(1);
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
const selectedValueSet = new Set(selectedValues);
|
|
211
|
+
const selectedOptions = selectedValues
|
|
212
|
+
.map((selectedValue) =>
|
|
213
|
+
options.find((option) => option.value === selectedValue),
|
|
214
|
+
)
|
|
215
|
+
.filter((option): option is ComboboxOption => option !== undefined);
|
|
216
|
+
const className = props.class;
|
|
217
|
+
const searchId = `${props.id}-search`;
|
|
218
|
+
---
|
|
219
|
+
|
|
220
|
+
<div
|
|
221
|
+
{...attrs}
|
|
222
|
+
class:list={['combobox', className]}
|
|
223
|
+
data-pattern="combobox"
|
|
224
|
+
data-combobox
|
|
225
|
+
data-combobox-mode={mode}
|
|
226
|
+
data-combobox-size={size}
|
|
227
|
+
data-combobox-width={width}
|
|
228
|
+
data-combobox-clearable={mode === 'options' && clearable ? 'true' : 'false'}
|
|
229
|
+
data-combobox-close-on-select={closeOnSelect ? 'true' : 'false'}
|
|
230
|
+
data-combobox-selection-mode={selectionMode}
|
|
231
|
+
data-combobox-number-min={min}
|
|
232
|
+
data-combobox-number-max={max}
|
|
233
|
+
data-combobox-number-step={step}
|
|
234
|
+
data-disabled={disabled ? true : undefined}
|
|
235
|
+
data-tone={resolvedTone}
|
|
236
|
+
>
|
|
237
|
+
<span class="combobox__sizer" aria-hidden="true">
|
|
238
|
+
{
|
|
239
|
+
(mode === 'number'
|
|
240
|
+
? options.map((option) => option.label)
|
|
241
|
+
: [placeholder, ...options.map((option) => option.label)]
|
|
242
|
+
).map((item) => <span class="combobox__sizer-label">{item}</span>)
|
|
243
|
+
}
|
|
244
|
+
</span>
|
|
245
|
+
|
|
246
|
+
{
|
|
247
|
+
mode === 'number' ? (
|
|
248
|
+
<div class="combobox__control" data-combobox-control>
|
|
249
|
+
<button
|
|
250
|
+
class="combobox__step"
|
|
251
|
+
type="button"
|
|
252
|
+
aria-label={decrementLabel}
|
|
253
|
+
disabled={disabled || numberValue === min}
|
|
254
|
+
data-combobox-number-step="decrement"
|
|
255
|
+
>
|
|
256
|
+
<span aria-hidden="true">−</span>
|
|
257
|
+
</button>
|
|
258
|
+
<input
|
|
259
|
+
class="combobox__number-input"
|
|
260
|
+
id={props.id}
|
|
261
|
+
type="text"
|
|
262
|
+
inputmode="numeric"
|
|
263
|
+
autocomplete="off"
|
|
264
|
+
role="combobox"
|
|
265
|
+
aria-autocomplete="list"
|
|
266
|
+
aria-controls={listboxId}
|
|
267
|
+
aria-expanded="false"
|
|
268
|
+
aria-haspopup="listbox"
|
|
269
|
+
aria-label={props.label}
|
|
270
|
+
disabled={disabled}
|
|
271
|
+
value={numberValue}
|
|
272
|
+
data-combobox-number-input
|
|
273
|
+
/>
|
|
274
|
+
<button
|
|
275
|
+
class="combobox__step"
|
|
276
|
+
type="button"
|
|
277
|
+
aria-label={incrementLabel}
|
|
278
|
+
disabled={disabled || numberValue === max}
|
|
279
|
+
data-combobox-number-step="increment"
|
|
280
|
+
>
|
|
281
|
+
<span aria-hidden="true">+</span>
|
|
282
|
+
</button>
|
|
283
|
+
</div>
|
|
284
|
+
) : (
|
|
285
|
+
<div class="combobox__control" data-combobox-control>
|
|
286
|
+
<span class="combobox__values" data-combobox-values>
|
|
287
|
+
{selectedOptions.map((option) => (
|
|
288
|
+
<Tag
|
|
289
|
+
leading={
|
|
290
|
+
option.icon
|
|
291
|
+
? { icon: option.icon, iconTone: option.iconTone }
|
|
292
|
+
: option.media
|
|
293
|
+
? { media: option.media }
|
|
294
|
+
: undefined
|
|
295
|
+
}
|
|
296
|
+
label={option.label}
|
|
297
|
+
removable={clearable && !disabled}
|
|
298
|
+
removeLabel={`${removeLabel} ${option.label}`}
|
|
299
|
+
size="sm"
|
|
300
|
+
data-combobox-tag={option.value}
|
|
301
|
+
/>
|
|
302
|
+
))}
|
|
303
|
+
<span
|
|
304
|
+
class="combobox__placeholder"
|
|
305
|
+
data-combobox-placeholder
|
|
306
|
+
hidden={selectedOptions.length > 0}
|
|
307
|
+
>
|
|
308
|
+
{placeholder}
|
|
309
|
+
</span>
|
|
310
|
+
</span>
|
|
311
|
+
|
|
312
|
+
<button
|
|
313
|
+
class="combobox__trigger"
|
|
314
|
+
id={props.id}
|
|
315
|
+
type="button"
|
|
316
|
+
role="combobox"
|
|
317
|
+
aria-autocomplete="list"
|
|
318
|
+
aria-controls={listboxId}
|
|
319
|
+
aria-expanded="false"
|
|
320
|
+
aria-haspopup="listbox"
|
|
321
|
+
aria-label={props.label}
|
|
322
|
+
disabled={disabled}
|
|
323
|
+
data-combobox-trigger
|
|
324
|
+
>
|
|
325
|
+
<span class="combobox__trigger-icon" aria-hidden="true">
|
|
326
|
+
<ArrowDownIcon />
|
|
327
|
+
</span>
|
|
328
|
+
</button>
|
|
329
|
+
</div>
|
|
330
|
+
)
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
<div class="combobox__panel" popover="manual" hidden data-combobox-panel>
|
|
334
|
+
{
|
|
335
|
+
mode === 'options' ? (
|
|
336
|
+
<div class="combobox__search">
|
|
337
|
+
<TextInput
|
|
338
|
+
id={searchId}
|
|
339
|
+
type="search"
|
|
340
|
+
framing="embedded"
|
|
341
|
+
autocomplete="off"
|
|
342
|
+
placeholder={searchPlaceholder}
|
|
343
|
+
aria-label={searchPlaceholder}
|
|
344
|
+
aria-controls={listboxId}
|
|
345
|
+
disabled={disabled}
|
|
346
|
+
data-combobox-search
|
|
347
|
+
/>
|
|
348
|
+
</div>
|
|
349
|
+
) : null
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
<div
|
|
353
|
+
class="combobox__options"
|
|
354
|
+
id={listboxId}
|
|
355
|
+
role="listbox"
|
|
356
|
+
aria-label={props.label}
|
|
357
|
+
aria-multiselectable={mode === 'options' && selectionMode === 'multiple'
|
|
358
|
+
? 'true'
|
|
359
|
+
: undefined}
|
|
360
|
+
data-combobox-options
|
|
361
|
+
>
|
|
362
|
+
{
|
|
363
|
+
options.map((option, index) => {
|
|
364
|
+
const OptionIcon = option.icon;
|
|
365
|
+
|
|
366
|
+
return (
|
|
367
|
+
<button
|
|
368
|
+
class="combobox__option"
|
|
369
|
+
id={`${props.id}-option-${index}`}
|
|
370
|
+
type="button"
|
|
371
|
+
role="option"
|
|
372
|
+
tabindex="-1"
|
|
373
|
+
aria-disabled={option.disabled ? 'true' : undefined}
|
|
374
|
+
aria-selected={
|
|
375
|
+
selectedValueSet.has(option.value) ? 'true' : 'false'
|
|
376
|
+
}
|
|
377
|
+
disabled={option.disabled}
|
|
378
|
+
data-combobox-option={option.value}
|
|
379
|
+
data-combobox-search-text={
|
|
380
|
+
mode === 'options'
|
|
381
|
+
? [
|
|
382
|
+
option.label,
|
|
383
|
+
option.description ?? '',
|
|
384
|
+
...(option.keywords ?? []),
|
|
385
|
+
].join(' ')
|
|
386
|
+
: undefined
|
|
387
|
+
}
|
|
388
|
+
data-interaction-accent="start"
|
|
389
|
+
>
|
|
390
|
+
{OptionIcon ? (
|
|
391
|
+
<OptionIcon
|
|
392
|
+
class="combobox__option-icon"
|
|
393
|
+
data-tone={option.iconTone}
|
|
394
|
+
/>
|
|
395
|
+
) : option.media ? (
|
|
396
|
+
<Media
|
|
397
|
+
class="combobox__option-media"
|
|
398
|
+
media={option.media}
|
|
399
|
+
fit="contain"
|
|
400
|
+
size="intrinsic"
|
|
401
|
+
/>
|
|
402
|
+
) : null}
|
|
403
|
+
<span class="combobox__option-content">
|
|
404
|
+
<span class="combobox__option-label">{option.label}</span>
|
|
405
|
+
{option.description ? (
|
|
406
|
+
<span class="combobox__option-description">
|
|
407
|
+
{option.description}
|
|
408
|
+
</span>
|
|
409
|
+
) : null}
|
|
410
|
+
</span>
|
|
411
|
+
</button>
|
|
412
|
+
);
|
|
413
|
+
})
|
|
414
|
+
}
|
|
415
|
+
{
|
|
416
|
+
mode === 'options' ? (
|
|
417
|
+
<p
|
|
418
|
+
class="combobox__empty"
|
|
419
|
+
role="status"
|
|
420
|
+
data-combobox-empty
|
|
421
|
+
hidden={options.length > 0}
|
|
422
|
+
>
|
|
423
|
+
{emptyLabel}
|
|
424
|
+
</p>
|
|
425
|
+
) : null
|
|
426
|
+
}
|
|
427
|
+
</div>
|
|
428
|
+
</div>
|
|
429
|
+
|
|
430
|
+
{
|
|
431
|
+
mode === 'options'
|
|
432
|
+
? options.map((option) => (
|
|
433
|
+
<template data-combobox-tag-template={option.value}>
|
|
434
|
+
<Tag
|
|
435
|
+
leading={
|
|
436
|
+
option.icon
|
|
437
|
+
? { icon: option.icon, iconTone: option.iconTone }
|
|
438
|
+
: option.media
|
|
439
|
+
? { media: option.media }
|
|
440
|
+
: undefined
|
|
441
|
+
}
|
|
442
|
+
label={option.label}
|
|
443
|
+
removable={clearable && !disabled}
|
|
444
|
+
removeLabel={`${removeLabel} ${option.label}`}
|
|
445
|
+
size="sm"
|
|
446
|
+
data-combobox-tag={option.value}
|
|
447
|
+
/>
|
|
448
|
+
</template>
|
|
449
|
+
))
|
|
450
|
+
: null
|
|
451
|
+
}
|
|
452
|
+
</div>
|
|
453
|
+
|
|
454
|
+
<script>
|
|
455
|
+
import { initCombobox } from './comboboxController';
|
|
456
|
+
|
|
457
|
+
for (const root of document.querySelectorAll('[data-combobox]')) {
|
|
458
|
+
if (root instanceof HTMLElement) {
|
|
459
|
+
initCombobox(root);
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
</script>
|