oneslash-design-system 2.20.0 → 2.21.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.
Files changed (151) hide show
  1. package/README.md +1 -1
  2. package/dist/DESIGN.md +34 -1
  3. package/dist/cases/about-page/profile.d.ts +1 -0
  4. package/dist/cases/about-page/profile.jsx +64 -0
  5. package/dist/cases/about-page.md +114 -0
  6. package/dist/cases/admin-inbox/list.d.ts +1 -0
  7. package/dist/cases/admin-inbox/list.jsx +104 -0
  8. package/dist/cases/admin-inbox/split.d.ts +1 -0
  9. package/dist/cases/admin-inbox/split.jsx +68 -0
  10. package/dist/cases/admin-inbox.md +254 -0
  11. package/dist/cases/api-keys.md +1 -1
  12. package/dist/cases/blog-index/cards.d.ts +1 -0
  13. package/dist/cases/blog-index/cards.jsx +45 -0
  14. package/dist/cases/blog-index/list.d.ts +1 -0
  15. package/dist/cases/blog-index/list.jsx +46 -0
  16. package/dist/cases/blog-index.md +160 -0
  17. package/dist/cases/changelog/by-month.d.ts +1 -0
  18. package/dist/cases/changelog/by-month.jsx +70 -0
  19. package/dist/cases/changelog/one-page.d.ts +1 -0
  20. package/dist/cases/changelog/one-page.jsx +70 -0
  21. package/dist/cases/changelog.md +200 -0
  22. package/dist/cases/code-sample/block.d.ts +1 -0
  23. package/dist/cases/code-sample/block.jsx +19 -0
  24. package/dist/cases/code-sample/command.d.ts +1 -0
  25. package/dist/cases/code-sample/command.jsx +17 -0
  26. package/dist/cases/code-sample.md +96 -0
  27. package/dist/cases/contact-page/form.d.ts +1 -0
  28. package/dist/cases/contact-page/form.jsx +83 -0
  29. package/dist/cases/contact-page/links.d.ts +1 -0
  30. package/dist/cases/contact-page/links.jsx +19 -0
  31. package/dist/cases/contact-page.md +142 -0
  32. package/dist/cases/docs-component-page/reference.d.ts +1 -0
  33. package/dist/cases/docs-component-page/reference.jsx +93 -0
  34. package/dist/cases/docs-component-page.md +144 -0
  35. package/dist/cases/faq/accordion.d.ts +1 -0
  36. package/dist/cases/faq/accordion.jsx +25 -0
  37. package/dist/cases/faq/open-list.d.ts +1 -0
  38. package/dist/cases/faq/open-list.jsx +27 -0
  39. package/dist/cases/faq.md +110 -0
  40. package/dist/cases/feature-grid/cards.d.ts +1 -0
  41. package/dist/cases/feature-grid/cards.jsx +33 -0
  42. package/dist/cases/feature-grid/rows.d.ts +1 -0
  43. package/dist/cases/feature-grid/rows.jsx +30 -0
  44. package/dist/cases/feature-grid.md +132 -0
  45. package/dist/cases/image-viewer/gallery.d.ts +1 -0
  46. package/dist/cases/image-viewer/gallery.jsx +32 -0
  47. package/dist/cases/image-viewer/single.d.ts +1 -0
  48. package/dist/cases/image-viewer/single.jsx +25 -0
  49. package/dist/cases/image-viewer.md +123 -0
  50. package/dist/cases/landing-hero/centered.d.ts +1 -0
  51. package/dist/cases/landing-hero/centered.jsx +22 -0
  52. package/dist/cases/landing-hero/split.d.ts +1 -0
  53. package/dist/cases/landing-hero/split.jsx +30 -0
  54. package/dist/cases/landing-hero.md +114 -0
  55. package/dist/cases/legal-page/sections.d.ts +1 -0
  56. package/dist/cases/legal-page/sections.jsx +61 -0
  57. package/dist/cases/legal-page.md +96 -0
  58. package/dist/cases/long-form-page/article.d.ts +1 -0
  59. package/dist/cases/long-form-page/article.jsx +58 -0
  60. package/dist/cases/long-form-page/with-contents.d.ts +1 -0
  61. package/dist/cases/long-form-page/with-contents.jsx +41 -0
  62. package/dist/cases/long-form-page.md +170 -0
  63. package/dist/cases/message-actions/hover-toolbar.jsx +11 -8
  64. package/dist/cases/message-actions/menu.jsx +10 -7
  65. package/dist/cases/message-actions.md +19 -13
  66. package/dist/cases/message-attachments/in-composer.jsx +2 -2
  67. package/dist/cases/message-attachments/in-message.jsx +16 -11
  68. package/dist/cases/message-attachments.md +29 -17
  69. package/dist/cases/one-main-action.md +33 -0
  70. package/dist/cases/overflow-menu/in-a-header.jsx +9 -6
  71. package/dist/cases/overflow-menu/on-a-row.jsx +9 -6
  72. package/dist/cases/overflow-menu.md +16 -10
  73. package/dist/cases/page-end/cta-band.d.ts +1 -0
  74. package/dist/cases/page-end/cta-band.jsx +24 -0
  75. package/dist/cases/page-end/next-link.d.ts +1 -0
  76. package/dist/cases/page-end/next-link.jsx +18 -0
  77. package/dist/cases/page-end.md +88 -0
  78. package/dist/cases/password-gate/inline.d.ts +1 -0
  79. package/dist/cases/password-gate/inline.jsx +94 -0
  80. package/dist/cases/password-gate/modal.d.ts +1 -0
  81. package/dist/cases/password-gate/modal.jsx +81 -0
  82. package/dist/cases/password-gate/page.d.ts +1 -0
  83. package/dist/cases/password-gate/page.jsx +82 -0
  84. package/dist/cases/password-gate.md +351 -0
  85. package/dist/cases/pricing-section/cards.d.ts +1 -0
  86. package/dist/cases/pricing-section/cards.jsx +40 -0
  87. package/dist/cases/pricing-section.md +85 -0
  88. package/dist/cases/product-cards/grid.d.ts +1 -0
  89. package/dist/cases/product-cards/grid.jsx +20 -0
  90. package/dist/cases/product-cards.md +71 -0
  91. package/dist/cases/reply-feedback/thumbs.jsx +11 -8
  92. package/dist/cases/reply-feedback/with-reason.jsx +11 -8
  93. package/dist/cases/reply-feedback.md +20 -14
  94. package/dist/cases/section-index/cards.d.ts +1 -0
  95. package/dist/cases/section-index/cards.jsx +25 -0
  96. package/dist/cases/section-index/list.d.ts +1 -0
  97. package/dist/cases/section-index/list.jsx +56 -0
  98. package/dist/cases/section-index.md +140 -0
  99. package/dist/cases/site-header.md +1 -1
  100. package/dist/cases/site-search/dialog.d.ts +1 -0
  101. package/dist/cases/site-search/dialog.jsx +131 -0
  102. package/dist/cases/site-search.md +176 -0
  103. package/dist/cases/tabbed-panels/tabs.d.ts +1 -0
  104. package/dist/cases/tabbed-panels/tabs.jsx +40 -0
  105. package/dist/cases/tabbed-panels.md +81 -0
  106. package/dist/cases.json +1173 -29
  107. package/dist/components/accordion.d.ts +31 -0
  108. package/dist/components/accordion.jsx +103 -0
  109. package/dist/components/codeBlock.d.ts +26 -0
  110. package/dist/components/codeBlock.jsx +101 -0
  111. package/dist/components/lightbox.d.ts +31 -0
  112. package/dist/components/lightbox.jsx +161 -0
  113. package/dist/components/linkCard.d.ts +10 -1
  114. package/dist/components/linkCard.jsx +32 -6
  115. package/dist/components/modal.d.ts +10 -2
  116. package/dist/components/modal.jsx +17 -12
  117. package/dist/components/pageHeader.jsx +1 -1
  118. package/dist/components/searchDialog.d.ts +44 -0
  119. package/dist/components/searchDialog.jsx +152 -0
  120. package/dist/components/tab.d.ts +5 -1
  121. package/dist/components/tab.jsx +2 -2
  122. package/dist/components/tabPanel.d.ts +16 -0
  123. package/dist/components/tabPanel.jsx +12 -0
  124. package/dist/components/tabsContainer.d.ts +5 -1
  125. package/dist/components/tabsContainer.jsx +2 -2
  126. package/dist/index.d.ts +5 -0
  127. package/dist/index.js +5 -0
  128. package/dist/internal/accordion.d.ts +4 -0
  129. package/dist/internal/accordion.js +53 -0
  130. package/dist/internal/combobox.d.ts +20 -0
  131. package/dist/internal/combobox.js +28 -0
  132. package/dist/internal/highlight.d.ts +5 -0
  133. package/dist/internal/highlight.js +18 -0
  134. package/dist/native-mapping.json +31 -1
  135. package/dist/stories/Accordion.stories.d.ts +11 -0
  136. package/dist/stories/Accordion.stories.jsx +93 -0
  137. package/dist/stories/Cases.generated.stories.d.ts +34 -0
  138. package/dist/stories/Cases.generated.stories.jsx +68 -0
  139. package/dist/stories/CodeBlock.stories.d.ts +12 -0
  140. package/dist/stories/CodeBlock.stories.jsx +65 -0
  141. package/dist/stories/Lightbox.stories.d.ts +8 -0
  142. package/dist/stories/Lightbox.stories.jsx +40 -0
  143. package/dist/stories/LinkCard.stories.d.ts +6 -0
  144. package/dist/stories/LinkCard.stories.jsx +17 -0
  145. package/dist/stories/PageHeader.stories.d.ts +2 -0
  146. package/dist/stories/PageHeader.stories.jsx +13 -0
  147. package/dist/stories/SearchDialog.stories.d.ts +17 -0
  148. package/dist/stories/SearchDialog.stories.jsx +111 -0
  149. package/dist/stories/TabPanel.stories.d.ts +7 -0
  150. package/dist/stories/TabPanel.stories.jsx +31 -0
  151. package/package.json +1 -1
@@ -0,0 +1,44 @@
1
+ import React from 'react';
2
+ export interface SearchResult {
3
+ id: string;
4
+ title: string;
5
+ /** A line of the text around the match. The query's words are marked in it, as in the title. */
6
+ excerpt?: string;
7
+ /** Where it is, such as the workspace or the section. */
8
+ secondLabel?: string;
9
+ href: string;
10
+ /** A Lucide icon name for the kind of thing it is. */
11
+ iconName?: string;
12
+ }
13
+ export interface SearchGroup {
14
+ /** Names the group, such as 'Docs' or 'Tasks'. */
15
+ label: string;
16
+ items: SearchResult[];
17
+ }
18
+ interface SearchDialogProps {
19
+ isOpen: boolean;
20
+ onClose: () => void;
21
+ query: string;
22
+ onQueryChange: (query: string) => void;
23
+ /** The results for `query`. While `status` is 'loading', the last results stay on screen. */
24
+ groups: SearchGroup[];
25
+ /**
26
+ * 'idle' before anything is typed, 'loading' while the caller fetches, 'done' with the results, 'error' when the
27
+ * fetch failed. The caller drops a reply for an older query, so `groups` always answer the current `query`.
28
+ */
29
+ status: 'idle' | 'loading' | 'done' | 'error';
30
+ /** Called by 'Try Again' after a failure. */
31
+ onRetry?: () => void;
32
+ /** Shown before anything is typed, at most 6, most recent first. */
33
+ recent?: SearchResult[];
34
+ /** Names the dialog and the field. Defaults to 'Search'. */
35
+ 'aria-label'?: string;
36
+ placeholder?: string;
37
+ }
38
+ /**
39
+ * Site search in a Modal: the field first, then the results in groups. Focus stays in the field; the arrows move the
40
+ * highlight, Enter follows the highlighted link, and Escape closes. One polite status says the count, 'Searching'
41
+ * after 300 ms of waiting, that nothing matched, or that search failed. The caller fetches and passes the results.
42
+ */
43
+ export default function SearchDialog({ isOpen, onClose, query, onQueryChange, groups, status, onRetry, recent, 'aria-label': ariaLabel, placeholder, }: SearchDialogProps): React.JSX.Element;
44
+ export { SearchDialog };
@@ -0,0 +1,152 @@
1
+ 'use client';
2
+ import React, { useEffect, useId, useRef, useState } from 'react';
3
+ import NextLink from 'next/link';
4
+ import Modal from './modal';
5
+ import TextField from './textField';
6
+ import Button from './button';
7
+ import EmptyBox from './emptyBox';
8
+ import Menu from './menu';
9
+ import IconSlot from './iconSlot';
10
+ import { formatCount } from './formatNumber';
11
+ import { focusRing, stateTransition } from './sharedStyles';
12
+ import { comboboxKey, comboboxProps } from '../internal/combobox';
13
+ import { highlightParts } from '../internal/highlight';
14
+ var SLOW_MS = 300;
15
+ var MAX_RECENT = 6;
16
+ function Marked(_a) {
17
+ var text = _a.text, query = _a.query;
18
+ return (<>
19
+ {highlightParts(text, query).map(function (part, i) {
20
+ return part.match ? (<mark key={i} className="rounded-inline bg-accent-main text-accent-contrast">{part.text}</mark>) : (<React.Fragment key={i}>{part.text}</React.Fragment>);
21
+ })}
22
+ </>);
23
+ }
24
+ /**
25
+ * Site search in a Modal: the field first, then the results in groups. Focus stays in the field; the arrows move the
26
+ * highlight, Enter follows the highlighted link, and Escape closes. One polite status says the count, 'Searching'
27
+ * after 300 ms of waiting, that nothing matched, or that search failed. The caller fetches and passes the results.
28
+ */
29
+ export default function SearchDialog(_a) {
30
+ var isOpen = _a.isOpen, onClose = _a.onClose, query = _a.query, onQueryChange = _a.onQueryChange, groups = _a.groups, status = _a.status, onRetry = _a.onRetry, _b = _a.recent, recent = _b === void 0 ? [] : _b, _c = _a["aria-label"], ariaLabel = _c === void 0 ? 'Search' : _c, _d = _a.placeholder, placeholder = _d === void 0 ? 'Search' : _d;
31
+ var uid = useId();
32
+ var fieldId = "".concat(uid, "-field");
33
+ var listId = "".concat(uid, "-results");
34
+ var optionId = function (i) { return "".concat(uid, "-option-").concat(i); };
35
+ var words = query.trim();
36
+ var typed = words !== '';
37
+ // The last results stay on screen while the next ones load
38
+ var lastGroups = useRef(groups);
39
+ if (status !== 'loading')
40
+ lastGroups.current = groups;
41
+ var shown = !typed
42
+ ? recent.length > 0
43
+ ? [{ label: 'Recent', items: recent.slice(0, MAX_RECENT) }]
44
+ : []
45
+ : status === 'error'
46
+ ? []
47
+ : status === 'loading'
48
+ ? lastGroups.current
49
+ : groups;
50
+ var options = shown.flatMap(function (g) { return g.items; });
51
+ var listOpen = options.length > 0;
52
+ var _e = useState(0), active = _e[0], setActive = _e[1];
53
+ var at = Math.min(active, Math.max(options.length - 1, 0));
54
+ useEffect(function () { return setActive(0); }, [query]);
55
+ // 'Searching' only once a reply takes longer than 300 ms, so a fast one does not flash it
56
+ var _f = useState(false), slow = _f[0], setSlow = _f[1];
57
+ useEffect(function () {
58
+ if (status !== 'loading') {
59
+ setSlow(false);
60
+ return;
61
+ }
62
+ var timer = setTimeout(function () { return setSlow(true); }, SLOW_MS);
63
+ return function () { return clearTimeout(timer); };
64
+ }, [status, query]);
65
+ var failed = typed && status === 'error';
66
+ var empty = typed && status === 'done' && options.length === 0;
67
+ var count = options.length;
68
+ // Until 'Searching' is due the status keeps its words, so it says nothing new
69
+ var lastStatus = useRef('');
70
+ var statusText = lastStatus.current;
71
+ if (!(status === 'loading' && !slow)) {
72
+ statusText = failed
73
+ ? 'Search is not working right now.'
74
+ : status === 'loading'
75
+ ? 'Searching'
76
+ : !typed || status === 'idle'
77
+ ? ''
78
+ : empty
79
+ ? "No results for \"".concat(words, "\"")
80
+ : "".concat(formatCount(count), " ").concat(count === 1 ? 'result' : 'results');
81
+ }
82
+ lastStatus.current = statusText;
83
+ // The status keeps its old visibility with its old words, so the old words never show
84
+ var lastHidden = useRef(true);
85
+ var hideStatus = lastHidden.current;
86
+ if (!(status === 'loading' && !slow))
87
+ hideStatus = failed || empty || !statusText;
88
+ lastHidden.current = hideStatus;
89
+ // Keep the highlighted row in view as the arrows move it
90
+ var activeId = listOpen ? optionId(at) : undefined;
91
+ useEffect(function () {
92
+ var _a, _b;
93
+ if (activeId)
94
+ (_b = (_a = document.getElementById(activeId)) === null || _a === void 0 ? void 0 : _a.scrollIntoView) === null || _b === void 0 ? void 0 : _b.call(_a, { block: 'nearest' });
95
+ }, [activeId]);
96
+ var focusField = function () { var _a; return (_a = document.getElementById(fieldId)) === null || _a === void 0 ? void 0 : _a.focus(); };
97
+ function keyDown(e) {
98
+ var _a;
99
+ var action = comboboxKey({ key: e.key, isComposing: e.nativeEvent.isComposing, keyCode: e.keyCode }, at, count);
100
+ if (!action)
101
+ return;
102
+ e.preventDefault();
103
+ if ('move' in action)
104
+ setActive(action.move);
105
+ else
106
+ (_a = document.getElementById(optionId(action.pick))) === null || _a === void 0 ? void 0 : _a.click();
107
+ }
108
+ var index = -1;
109
+ return (<Modal isOpen={isOpen} onClose={onClose} size="medium" initialFocus="body" aria-label={ariaLabel} placement="top">
110
+ <div className="flex flex-col gap-medium">
111
+ <TextField id={fieldId} type="search" aria-label={ariaLabel} placeholder={placeholder} value={query} onChange={function (e) { return onQueryChange(e.target.value); }} onKeyDown={keyDown} {...comboboxProps({ listId: listId, open: listOpen, activeId: activeId })}/>
112
+ {/* The empty and error boxes show their own words, so the status is read but not shown twice */}
113
+ <p role="status" className={hideStatus ? 'sr-only' : 'text-caption text-fg-secondary'}>
114
+ {statusText}
115
+ </p>
116
+ {failed ? (<EmptyBox size="small" icon="SearchX" text="Search is not working right now." secondText="Check your connection, then try again." action={<Button size="medium" type="secondary" state="enabled" label="Try Again" onClickButton={function () {
117
+ focusField();
118
+ onRetry === null || onRetry === void 0 ? void 0 : onRetry();
119
+ }}/>}/>) : empty ? (<EmptyBox size="small" icon="Search" text={"No results for \"".concat(words, "\"")} secondText="Check the spelling, or search for fewer words." action={<Button size="medium" type="secondary" state="enabled" label="Clear Search" onClickButton={function () {
120
+ focusField();
121
+ onQueryChange('');
122
+ }}/>}/>) : (listOpen && (
123
+ // On a phone the list scrolls under the field, which stays put
124
+ <div aria-busy={status === 'loading' || undefined} className="max-h-[60dvh] overflow-y-auto" style={{ scrollbarWidth: 'thin' }}>
125
+ <Menu role="listbox" id={listId} aria-label={typed ? 'Results' : 'Recent'} width="100%">
126
+ {shown.map(function (group, gi) { return (<div key={gi} role="group" aria-labelledby={"".concat(uid, "-group-").concat(gi)}>
127
+ <div id={"".concat(uid, "-group-").concat(gi)} className="px-2 pb-1 pt-2 text-caption text-fg-secondary">
128
+ {group.label}
129
+ </div>
130
+ {group.items.map(function (item) {
131
+ index += 1;
132
+ var i = index;
133
+ return (<NextLink key={item.id} id={optionId(i)} role="option" aria-selected={i === at} tabIndex={-1} onClick={onClose} onMouseMove={function () { return setActive(i); }} className={"flex items-start gap-2 rounded-control p-2 text-left ".concat(stateTransition, " ").concat(focusRing, " hover:bg-background-accent200 ").concat(i === at ? 'bg-background-accent200' : '')} href={item.href}>
134
+ <IconSlot icon={item.iconName} className="size-5 shrink-0 text-fg-secondary"/>
135
+ <span className="flex min-w-0 flex-col">
136
+ <span className="text-body2 text-fg-primary">
137
+ <Marked text={item.title} query={words}/>
138
+ </span>
139
+ {item.secondLabel && <span className="truncate text-caption text-fg-secondary">{item.secondLabel}</span>}
140
+ {item.excerpt && (<span className="line-clamp-2 text-caption text-fg-secondary">
141
+ <Marked text={item.excerpt} query={words}/>
142
+ </span>)}
143
+ </span>
144
+ </NextLink>);
145
+ })}
146
+ </div>); })}
147
+ </Menu>
148
+ </div>))}
149
+ </div>
150
+ </Modal>);
151
+ }
152
+ export { SearchDialog };
@@ -13,6 +13,10 @@ type TabProps = {
13
13
  actionIcon?: string;
14
14
  router?: RouterLike;
15
15
  size?: 'medium' | 'small' | 'tiny';
16
+ /** The tab's id, for a `TabPanel`'s `labelledBy` */
17
+ id?: string;
18
+ /** The id of the `TabPanel` this tab shows (`aria-controls`) */
19
+ controls?: string;
16
20
  };
17
- export default function Tab({ label, secondLabel, href, isSelected, onClickTab, onClickActionIcon, decoIcon, actionIcon, router, size, }: TabProps): React.JSX.Element;
21
+ export default function Tab({ label, secondLabel, href, isSelected, onClickTab, onClickActionIcon, decoIcon, actionIcon, router, size, id, controls, }: TabProps): React.JSX.Element;
18
22
  export {};
@@ -4,7 +4,7 @@ import IconSlot from './iconSlot';
4
4
  import { TabsContainerContext, TabsFillContext } from './tabsContainer';
5
5
  import { segmentIdleClasses, segmentItemClasses, segmentSelectedClasses, segmentSizes } from './slidingIndicator';
6
6
  export default function Tab(_a) {
7
- var label = _a.label, secondLabel = _a.secondLabel, href = _a.href, isSelected = _a.isSelected, onClickTab = _a.onClickTab, onClickActionIcon = _a.onClickActionIcon, decoIcon = _a.decoIcon, actionIcon = _a.actionIcon, router = _a.router, _b = _a.size, size = _b === void 0 ? 'medium' : _b;
7
+ var label = _a.label, secondLabel = _a.secondLabel, href = _a.href, isSelected = _a.isSelected, onClickTab = _a.onClickTab, onClickActionIcon = _a.onClickActionIcon, decoIcon = _a.decoIcon, actionIcon = _a.actionIcon, router = _a.router, _b = _a.size, size = _b === void 0 ? 'medium' : _b, id = _a.id, controls = _a.controls;
8
8
  var inContainer = useContext(TabsContainerContext);
9
9
  var fill = useContext(TabsFillContext);
10
10
  var handleClick = function () {
@@ -18,7 +18,7 @@ export default function Tab(_a) {
18
18
  var selectedClasses = inContainer
19
19
  ? segmentSelectedClasses
20
20
  : "bg-primary-dark ".concat(segmentSelectedClasses);
21
- return (<div data-tab-selected={isSelected} role="tab" aria-selected={isSelected}
21
+ return (<div data-tab-selected={isSelected} role="tab" id={id} aria-controls={controls} aria-selected={isSelected}
22
22
  // Inside a container only the selected tab is in the Tab order; arrow keys move between tabs
23
23
  tabIndex={inContainer && !isSelected ? -1 : 0} onKeyDown={function (e) {
24
24
  if (e.target === e.currentTarget && (e.key === 'Enter' || e.key === ' ')) {
@@ -0,0 +1,16 @@
1
+ import React from 'react';
2
+ interface TabPanelProps {
3
+ /** The panel's id: the `controls` of its `Tab` */
4
+ id: string;
5
+ /** The id of the `Tab` that shows this panel */
6
+ labelledBy: string;
7
+ /** The panel of the selected tab. The others stay in the page, `hidden`. */
8
+ selected: boolean;
9
+ children: React.ReactNode;
10
+ }
11
+ /**
12
+ * The panel a `Tab` shows. Every panel is in the server HTML and only the selected one is visible.
13
+ * It takes a Tab stop, so Tab from the selected tab lands on its panel.
14
+ */
15
+ export default function TabPanel({ id, labelledBy, selected, children }: TabPanelProps): React.JSX.Element;
16
+ export {};
@@ -0,0 +1,12 @@
1
+ import React from 'react';
2
+ import { focusRing } from './sharedStyles';
3
+ /**
4
+ * The panel a `Tab` shows. Every panel is in the server HTML and only the selected one is visible.
5
+ * It takes a Tab stop, so Tab from the selected tab lands on its panel.
6
+ */
7
+ export default function TabPanel(_a) {
8
+ var id = _a.id, labelledBy = _a.labelledBy, selected = _a.selected, children = _a.children;
9
+ return (<div role="tabpanel" id={id} aria-labelledby={labelledBy} hidden={!selected} tabIndex={0} className={"rounded-control ".concat(focusRing)}>
10
+ {children}
11
+ </div>);
12
+ }
@@ -3,8 +3,12 @@ interface TabsContainerProps {
3
3
  children: React.ReactNode;
4
4
  /** The container is as wide as its parent and every tab takes an equal share, label centered. */
5
5
  fill?: boolean;
6
+ /** Names the tablist */
7
+ 'aria-label'?: string;
8
+ /** The id of the heading that names the tablist */
9
+ 'aria-labelledby'?: string;
6
10
  }
7
11
  export declare const TabsContainerContext: React.Context<boolean>;
8
12
  export declare const TabsFillContext: React.Context<boolean>;
9
- export default function TabsContainer({ children, fill, }: TabsContainerProps): React.JSX.Element;
13
+ export default function TabsContainer({ children, fill, 'aria-label': ariaLabel, 'aria-labelledby': ariaLabelledBy, }: TabsContainerProps): React.JSX.Element;
10
14
  export {};
@@ -6,12 +6,12 @@ export var TabsContainerContext = createContext(false);
6
6
  // Lets a Tab know every tab in the container takes an equal share of the width
7
7
  export var TabsFillContext = createContext(false);
8
8
  export default function TabsContainer(_a) {
9
- var children = _a.children, _b = _a.fill, fill = _b === void 0 ? false : _b;
9
+ var children = _a.children, _b = _a.fill, fill = _b === void 0 ? false : _b, ariaLabel = _a["aria-label"], ariaLabelledBy = _a["aria-labelledby"];
10
10
  var tabCount = React.Children.count(children);
11
11
  var _c = useSlidingIndicator(children), containerRef = _c.containerRef, indicator = _c.indicator;
12
12
  return (<TabsContainerContext.Provider value={true}>
13
13
  <TabsFillContext.Provider value={fill}>
14
- <div ref={containerRef} role="tablist" onKeyDown={function (e) {
14
+ <div ref={containerRef} role="tablist" aria-label={ariaLabel} aria-labelledby={ariaLabelledBy} onKeyDown={function (e) {
15
15
  var _a, _b;
16
16
  // Arrow keys move focus to the next tab and select it
17
17
  var tabs = Array.from((_b = (_a = containerRef.current) === null || _a === void 0 ? void 0 : _a.querySelectorAll('[role="tab"]')) !== null && _b !== void 0 ? _b : []);
package/dist/index.d.ts CHANGED
@@ -1,8 +1,10 @@
1
1
  import './designTokens';
2
+ export * from './components/accordion';
2
3
  export * from './components/alert';
3
4
  export * from './components/appShell';
4
5
  export * from './components/button';
5
6
  export * from './components/checkBox';
7
+ export * from './components/codeBlock';
6
8
  export * from './components/copyField';
7
9
  export * from './components/drawer';
8
10
  export * from './components/emptyBox';
@@ -10,6 +12,7 @@ export * from './components/formField';
10
12
  export * from './components/formatNumber';
11
13
  export * from './components/iconButton';
12
14
  export * from './components/layout';
15
+ export * from './components/lightbox';
13
16
  export * from './components/loadingScreen';
14
17
  export * from './components/menu';
15
18
  export * from './components/menuItem';
@@ -20,6 +23,7 @@ export * from './components/pagination';
20
23
  export * from './components/popover';
21
24
  export * from './components/progress';
22
25
  export * from './components/radioGroup';
26
+ export * from './components/searchDialog';
23
27
  export * from './components/sectionIntro';
24
28
  export * from './components/segmentedControl';
25
29
  export * from './components/select';
@@ -36,6 +40,7 @@ export * from './components/tableContainer';
36
40
  export * from './components/tableHeader';
37
41
  export * from './components/tableHeaderCell';
38
42
  export * from './components/tableRow';
43
+ export * from './components/tabPanel';
39
44
  export * from './components/tabsContainer';
40
45
  export * from './components/tag';
41
46
  export * from './components/textarea';
package/dist/index.js CHANGED
@@ -1,8 +1,10 @@
1
1
  import './designTokens';
2
+ export * from './components/accordion';
2
3
  export * from './components/alert';
3
4
  export * from './components/appShell';
4
5
  export * from './components/button';
5
6
  export * from './components/checkBox';
7
+ export * from './components/codeBlock';
6
8
  export * from './components/copyField';
7
9
  export * from './components/drawer';
8
10
  export * from './components/emptyBox';
@@ -10,6 +12,7 @@ export * from './components/formField';
10
12
  export * from './components/formatNumber';
11
13
  export * from './components/iconButton';
12
14
  export * from './components/layout';
15
+ export * from './components/lightbox';
13
16
  export * from './components/loadingScreen';
14
17
  export * from './components/menu';
15
18
  export * from './components/menuItem';
@@ -20,6 +23,7 @@ export * from './components/pagination';
20
23
  export * from './components/popover';
21
24
  export * from './components/progress';
22
25
  export * from './components/radioGroup';
26
+ export * from './components/searchDialog';
23
27
  export * from './components/sectionIntro';
24
28
  export * from './components/segmentedControl';
25
29
  export * from './components/select';
@@ -36,6 +40,7 @@ export * from './components/tableContainer';
36
40
  export * from './components/tableHeader';
37
41
  export * from './components/tableHeaderCell';
38
42
  export * from './components/tableRow';
43
+ export * from './components/tabPanel';
39
44
  export * from './components/tabsContainer';
40
45
  export * from './components/tag';
41
46
  export * from './components/textarea';
@@ -0,0 +1,4 @@
1
+ export declare function normalizeOpen(open: readonly string[], ids: readonly string[], multiple: boolean): string[];
2
+ export declare function toggleOpen(open: readonly string[], id: string, multiple: boolean): string[];
3
+ export declare function hashItem(hash: string, prefix: string, ids: readonly string[]): string | null;
4
+ export declare function nextHeading(key: string, current: number, count: number): number;
@@ -0,0 +1,53 @@
1
+ // Accordion's pure helpers, kept out of the public API (index.ts and the package exports do not reach internal/)
2
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
3
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
4
+ if (ar || !(i in from)) {
5
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
6
+ ar[i] = from[i];
7
+ }
8
+ }
9
+ return to.concat(ar || Array.prototype.slice.call(from));
10
+ };
11
+ // The open ids to keep: only ids of real items, in item order, and at most one when only one may be open
12
+ export function normalizeOpen(open, ids, multiple) {
13
+ var known = ids.filter(function (id) { return open.includes(id); });
14
+ return multiple ? known : known.slice(0, 1);
15
+ }
16
+ // The open ids after the item `id` is toggled. In one-open mode opening an item closes the other.
17
+ export function toggleOpen(open, id, multiple) {
18
+ if (open.includes(id))
19
+ return open.filter(function (x) { return x !== id; });
20
+ return multiple ? __spreadArray(__spreadArray([], open, true), [id], false) : [id];
21
+ }
22
+ // The item a `#hash` names (`<prefix>-<item id>`), or null. A malformed hash names no item.
23
+ export function hashItem(hash, prefix, ids) {
24
+ var _a;
25
+ if (hash.length < 2)
26
+ return null;
27
+ var target;
28
+ try {
29
+ target = decodeURIComponent(hash.slice(1));
30
+ }
31
+ catch (_b) {
32
+ return null;
33
+ }
34
+ return (_a = ids.find(function (id) { return "".concat(prefix, "-").concat(id) === target; })) !== null && _a !== void 0 ? _a : null;
35
+ }
36
+ // The index of the heading a key moves focus to, or -1 when the key is not one of them.
37
+ // ArrowDown and ArrowUp wrap; Home and End go to the first and the last.
38
+ export function nextHeading(key, current, count) {
39
+ if (count === 0)
40
+ return -1;
41
+ switch (key) {
42
+ case 'ArrowDown':
43
+ return (current + 1) % count;
44
+ case 'ArrowUp':
45
+ return (current - 1 + count) % count;
46
+ case 'Home':
47
+ return 0;
48
+ case 'End':
49
+ return count - 1;
50
+ default:
51
+ return -1;
52
+ }
53
+ }
@@ -0,0 +1,20 @@
1
+ export declare function comboboxProps({ listId, open, activeId }: {
2
+ listId: string;
3
+ open: boolean;
4
+ activeId?: string;
5
+ }): {
6
+ role: "combobox";
7
+ 'aria-autocomplete': "list";
8
+ 'aria-expanded': boolean;
9
+ 'aria-controls': string | undefined;
10
+ 'aria-activedescendant': string | undefined;
11
+ };
12
+ export declare function comboboxKey(e: {
13
+ key: string;
14
+ isComposing?: boolean;
15
+ keyCode?: number;
16
+ }, active: number, count: number): {
17
+ move: number;
18
+ } | {
19
+ pick: number;
20
+ } | null;
@@ -0,0 +1,28 @@
1
+ // The search field that drives a list, kept out of the public API (index.ts and the package exports do not reach internal/).
2
+ // Focus stays in the field: the field is `role="combobox"`, points at the list with `aria-controls` and at the
3
+ // highlighted row with `aria-activedescendant`. The arrows move the highlight and stop at the ends, Enter picks the
4
+ // highlighted row, and Escape is the Modal's (it closes the dialog). The same pattern as the quick-switcher example.
5
+ export function comboboxProps(_a) {
6
+ var listId = _a.listId, open = _a.open, activeId = _a.activeId;
7
+ return {
8
+ role: 'combobox',
9
+ 'aria-autocomplete': 'list',
10
+ 'aria-expanded': open,
11
+ 'aria-controls': open ? listId : undefined,
12
+ 'aria-activedescendant': open ? activeId : undefined,
13
+ };
14
+ }
15
+ // What a key in the field does with `count` rows and row `active` highlighted: move the highlight, pick a row, or nothing.
16
+ // An input method (Korean, Japanese, Chinese) uses Enter and the arrows while it composes, so they are left to it.
17
+ export function comboboxKey(e, active, count) {
18
+ if (e.isComposing || e.keyCode === 229 || count === 0)
19
+ return null;
20
+ var at = Math.min(Math.max(active, 0), count - 1);
21
+ if (e.key === 'ArrowDown')
22
+ return { move: Math.min(at + 1, count - 1) };
23
+ if (e.key === 'ArrowUp')
24
+ return { move: Math.max(at - 1, 0) };
25
+ if (e.key === 'Enter')
26
+ return { pick: at };
27
+ return null;
28
+ }
@@ -0,0 +1,5 @@
1
+ export type HighlightPart = {
2
+ text: string;
3
+ match: boolean;
4
+ };
5
+ export declare function highlightParts(text: string, query: string): HighlightPart[];
@@ -0,0 +1,18 @@
1
+ // SearchDialog's pure helper, kept out of the public API (index.ts and the package exports do not reach internal/)
2
+ var escape = function (word) { return word.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); };
3
+ // Splits `text` on the words of `query` (split on white space), ignoring case. Every regex character in a word is
4
+ // taken literally, so 'c++ (beta)' marks 'c++' and '(beta)'. Longer words are tried first, so 'plan' and 'planning'
5
+ // mark all of 'planning'. Empty parts are left out.
6
+ export function highlightParts(text, query) {
7
+ var words = query.trim().split(/\s+/).filter(Boolean);
8
+ if (!text)
9
+ return [];
10
+ if (words.length === 0)
11
+ return [{ text: text, match: false }];
12
+ var pattern = new RegExp("(".concat(words.sort(function (a, b) { return b.length - a.length; }).map(escape).join('|'), ")"), 'gi');
13
+ // With one capture group, split puts each match at an odd index
14
+ return text
15
+ .split(pattern)
16
+ .map(function (part, i) { return ({ text: part, match: i % 2 === 1 }); })
17
+ .filter(function (part) { return part.text !== ''; });
18
+ }
@@ -1,5 +1,11 @@
1
1
  {
2
2
  "components": [
3
+ {
4
+ "ods": "accordion",
5
+ "swiftui": "`DisclosureGroup` per item, with the title as its label",
6
+ "compose": "A `Column` of rows with `AnimatedVisibility` for the panel and `semantics { stateDescription }` on the row",
7
+ "note": "One-open is app state (a selection the groups bind to). Deep links and the heading level are web only."
8
+ },
3
9
  {
4
10
  "ods": "alert",
5
11
  "swiftui": "`ODSBanner` for an inline message; `.alert` for one that needs a decision",
@@ -28,6 +34,12 @@
28
34
  "swiftui": "`Toggle` (switch on iOS, `.toggleStyle(.checkbox)` on macOS)",
29
35
  "compose": "`Checkbox`"
30
36
  },
37
+ {
38
+ "ods": "codeBlock",
39
+ "swiftui": "`ScrollView(.horizontal)` with `Text(code).monospaced().textSelection(.enabled)` and a Copy `Button`",
40
+ "compose": "`SelectionContainer` around a `Text` in the code family with `horizontalScroll`, and a Copy `TextButton`",
41
+ "note": "Show \"Copied\" for 2 seconds only after the write succeeds. No highlighting and no line numbers. One line to paste is a `copyField`."
42
+ },
31
43
  {
32
44
  "ods": "composer",
33
45
  "swiftui": "`TextField(_:text:axis: .vertical)` with `.lineLimit(1...6)` over a toolbar `HStack` of the tool `Button`s and a send `Button`",
@@ -108,6 +120,12 @@
108
120
  "compose": "Not applicable: web page pattern",
109
121
  "note": "In an app screen: `VStack` / `HStack` / `Grid`; Compose `Column` / `Row` / `LazyVerticalGrid`. `Center` and `Split` are for web pages; a native screen is already one column."
110
122
  },
123
+ {
124
+ "ods": "lightbox",
125
+ "swiftui": "`.fullScreenCover` holding a `TabView` with `.tabViewStyle(.page)`, one page per image",
126
+ "compose": "A full-width `Dialog` (`usePlatformDefaultWidth = false`) holding a `HorizontalPager`",
127
+ "note": "Images only. The system pager gives the swipe; keep a Close button and say \"2 of 5\" in the title."
128
+ },
111
129
  {
112
130
  "ods": "line",
113
131
  "swiftui": "`Divider`",
@@ -156,7 +174,7 @@
156
174
  "ods": "modal",
157
175
  "swiftui": "`.sheet` or `.alert`",
158
176
  "compose": "`ModalBottomSheet` or `AlertDialog`",
159
- "note": "`ModalBottomSheet` needs `@OptIn(ExperimentalMaterial3Api::class)`."
177
+ "note": "`ModalBottomSheet` needs `@OptIn(ExperimentalMaterial3Api::class)`. `size=\"fill\"` is the full-screen cover: `.fullScreenCover` / a full-width `Dialog` (`usePlatformDefaultWidth = false`)."
160
178
  },
161
179
  {
162
180
  "ods": "navigation",
@@ -216,6 +234,12 @@
216
234
  "compose": "`RadioButton`s in a `Column` with `Modifier.selectableGroup()`",
217
235
  "note": "`variant=\"card\"`: each option is a bordered card with the radio in it, a `Picker` with custom rows on iOS / selectable `Card`s with a `RadioButton` in a `selectableGroup` on Android."
218
236
  },
237
+ {
238
+ "ods": "searchDialog",
239
+ "swiftui": "`.searchable` on the screen that lists the results, with `.searchSuggestions` for recent items",
240
+ "compose": "`SearchBar` with its results in the expanded content",
241
+ "note": "The system places the field and moves focus. Say the count, \"Searching\" and a failure as text, not color alone."
242
+ },
219
243
  {
220
244
  "ods": "sectionIntro",
221
245
  "swiftui": "Not applicable: web page pattern",
@@ -299,6 +323,12 @@
299
323
  "compose": "`PrimaryTabRow`",
300
324
  "note": "One `Tab` inside `TabView` or one segment / one `Tab`. `TabRow` is deprecated in Material 3."
301
325
  },
326
+ {
327
+ "ods": "tabPanel",
328
+ "swiftui": "The content view of a `TabView` page, or the view under a segmented `Picker`",
329
+ "compose": "The content under a `PrimaryTabRow`, shown for the selected index",
330
+ "note": "The system tab views already pair a tab with its content and name it for VoiceOver / TalkBack. On the web it adds `role=\"tabpanel\"`."
331
+ },
302
332
  {
303
333
  "ods": "tableCell",
304
334
  "swiftui": "A `TableColumn` content view",
@@ -0,0 +1,11 @@
1
+ import type { Meta, StoryObj } from "@storybook/react";
2
+ import Accordion from "../components/accordion";
3
+ declare const meta: Meta<typeof Accordion>;
4
+ export default meta;
5
+ type Story = StoryObj<typeof Accordion>;
6
+ export declare const Faq: Story;
7
+ export declare const OneOpen: Story;
8
+ export declare const Single: Story;
9
+ export declare const DeepLink: Story;
10
+ export declare const DeepLinkJumped: Story;
11
+ export declare const DeepLinkScrolledOn: Story;