@astryxdesign/cli 0.7.11 → 0.7.12-canary.0840fcc

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 (160) hide show
  1. package/api/build/blocks/blocks.d.mts +41 -0
  2. package/api/build/blocks/blocks.mjs +118 -68
  3. package/api/build/kit/rank.mjs +21 -4
  4. package/api/build/kit/words.d.mts +1 -0
  5. package/api/build/kit/words.mjs +1 -1
  6. package/api/component/__fixtures__/resolutions/modules.txt +5 -5
  7. package/api/docs/_adapter.d.mts +22 -0
  8. package/api/docs/_adapter.mjs +81 -3
  9. package/api/docs/docs.doc.mjs +5 -5
  10. package/api/docs/docs.type.d.mts +21 -0
  11. package/api/docs/docs.type.mjs +11 -0
  12. package/api/docs/list/list.d.mts +5 -1
  13. package/api/docs/list/list.mjs +72 -6
  14. package/api/docs/node/node.mjs +2 -40
  15. package/api/icon/_adapter.d.mts +3 -2
  16. package/api/icon/_adapter.mjs +8 -2
  17. package/api/icon/_authoring.d.mts +1 -0
  18. package/api/icon/_authoring.mjs +594 -67
  19. package/api/icon/_default-look.d.mts +155 -0
  20. package/api/icon/_default-look.mjs +474 -0
  21. package/api/icon/_records.d.mts +1 -1
  22. package/api/icon/_records.mjs +1 -0
  23. package/api/icon/add/add.mjs +269 -43
  24. package/api/icon/icon.type.d.mts +46 -2
  25. package/api/icon/icon.type.mjs +12 -2
  26. package/api/icon/iconAdd.doc.mjs +2 -2
  27. package/api/icon/iconNewDefinition.doc.mjs +3 -2
  28. package/api/icon/iconNewSet.doc.mjs +4 -4
  29. package/api/icon/map/map.mjs +11 -4
  30. package/api/icon/search/search.mjs +10 -9
  31. package/api/index.d.mts +1 -0
  32. package/api/index.mjs +1 -0
  33. package/api/integration/add-helpers.d.mts +15 -1
  34. package/api/integration/add-helpers.mjs +5 -2
  35. package/api/integration/authoring-checks.d.mts +0 -2
  36. package/api/integration/authoring-checks.mjs +1 -6
  37. package/api/logger.mjs +2 -1
  38. package/api/render/_adapter.mjs +9 -0
  39. package/api/render/render.doc.mjs +3 -3
  40. package/api/render/render.type.d.mts +1 -1
  41. package/api/render/render.type.mjs +1 -1
  42. package/api/search/ORDERING.md +3 -0
  43. package/api/search/_adapter.d.mts +32 -3
  44. package/api/search/_adapter.mjs +50 -22
  45. package/api/search/_fit-order.d.mts +47 -0
  46. package/api/search/_fit-order.mjs +257 -0
  47. package/api/search/_main-searcher.mjs +15 -5
  48. package/api/search/exportSearchIndex.doc.d.mts +10 -0
  49. package/api/search/exportSearchIndex.doc.mjs +58 -0
  50. package/api/search/rankSearchIndex.doc.d.mts +10 -0
  51. package/api/search/rankSearchIndex.doc.mjs +79 -0
  52. package/api/search/search-index.d.mts +44 -0
  53. package/api/search/search-index.mjs +270 -0
  54. package/api/search/search.type.d.mts +28 -0
  55. package/api/search/search.type.mjs +17 -0
  56. package/api/swizzle/_adapter.d.mts +1 -0
  57. package/api/swizzle/_adapter.mjs +4 -1
  58. package/api/swizzle/_moduleGraph.d.mts +178 -0
  59. package/api/swizzle/_moduleGraph.mjs +903 -0
  60. package/api/swizzle/copy/copy.d.mts +2 -43
  61. package/api/swizzle/copy/copy.mjs +287 -315
  62. package/api/swizzle/swizzle.d.mts +0 -2
  63. package/api/swizzle/swizzle.doc.mjs +13 -4
  64. package/api/swizzle/swizzle.mjs +3 -7
  65. package/api/swizzle/swizzle.type.d.mts +7 -1
  66. package/api/swizzle/swizzle.type.mjs +4 -2
  67. package/api/template/template.mjs +1 -0
  68. package/assets/discover/official-packages.json +36 -0
  69. package/assets/docs/browser-support.doc.mjs +2 -2
  70. package/assets/docs/styling-overview.doc.mjs +6 -2
  71. package/assets/docs/tree/icon-sets.doc.mjs +13 -7
  72. package/assets/docs/tree/render-pages.doc.mjs +3 -3
  73. package/assets/docs/tree/tailwind.doc.mjs +41 -1
  74. package/assets/docs/tree/type-scale.doc.mjs +19 -2
  75. package/assets/templates/blocks/components/Calendar/useCalendarConstraintsHookUsage.doc.mjs +14 -0
  76. package/assets/templates/blocks/components/Calendar/useCalendarConstraintsHookUsage.tsx +146 -0
  77. package/assets/templates/blocks/components/Calendar/useCalendarNavigationHookUsage.doc.mjs +14 -0
  78. package/assets/templates/blocks/components/Calendar/useCalendarNavigationHookUsage.tsx +173 -0
  79. package/assets/templates/blocks/components/Hooks/useInputStatusIconHookUsage.tsx +1 -0
  80. package/assets/templates/blocks/components/Hooks/useInteractiveRoleHookUsage.doc.mjs +14 -0
  81. package/assets/templates/blocks/components/Hooks/useInteractiveRoleHookUsage.tsx +56 -0
  82. package/assets/templates/blocks/components/Hooks/useStreamingTextHookUsage.doc.mjs +2 -2
  83. package/assets/templates/blocks/components/Hooks/useStreamingTextHookUsage.tsx +66 -10
  84. package/assets/templates/blocks/components/Link/useLinkifyHookUsage.doc.mjs +14 -0
  85. package/assets/templates/blocks/components/Link/useLinkifyHookUsage.tsx +39 -0
  86. package/assets/templates/blocks/components/PowerSearch/usePowerSearchConfigHookUsage.doc.mjs +14 -0
  87. package/assets/templates/blocks/components/PowerSearch/usePowerSearchConfigHookUsage.tsx +83 -0
  88. package/assets/templates/blocks/components/Table/RowsVirtualizationHookUsage.doc.mjs +14 -0
  89. package/assets/templates/blocks/components/Table/RowsVirtualizationHookUsage.tsx +41 -0
  90. package/assets/templates/blocks/components/Table/TableRowIndexTable.doc.mjs +1 -1
  91. package/assets/templates/blocks/components/Table/TableRowIndexTable.tsx +2 -2
  92. package/assets/templates/blocks/components/Table/useTableColumnSettingsStateHookUsage.doc.mjs +14 -0
  93. package/assets/templates/blocks/components/Table/useTableColumnSettingsStateHookUsage.tsx +97 -0
  94. package/assets/templates/pages/course-detail/page.tsx +699 -0
  95. package/assets/templates/pages/course-detail/template.doc.mjs +37 -0
  96. package/assets/templates/pages/file-explorer/page.tsx +103 -79
  97. package/assets/templates/pages/table-filter/page.tsx +15 -23
  98. package/assets/templates/pages/table-grouped/page.tsx +160 -232
  99. package/assets/templates/pages/table-grouped/template.doc.mjs +0 -2
  100. package/assets/templates/pages/table-inbox/page.tsx +3 -6
  101. package/assets/templates/pages/theme-showcase/page.tsx +724 -792
  102. package/assets/templates/pages/theme-showcase/template.doc.mjs +4 -5
  103. package/assets/templates/themes/butter/butterTheme.ts +2 -2
  104. package/assets/templates/themes/gothic/gothicTheme.ts +16 -0
  105. package/assets/templates/themes/matcha/matchaTheme.ts +1 -1
  106. package/assets/templates/themes/neutral/neutralTheme.ts +6 -0
  107. package/assets/templates/themes/stone/stoneTheme.ts +1 -1
  108. package/assets/templates/themes/y2k/y2kPaletteRefs.generated.ts +1 -1
  109. package/assets/templates/themes/y2k/y2kTheme.ts +2 -2
  110. package/authoring/doctypes/template/type.ts +1 -0
  111. package/clients/cli/commands/docs.doc.mjs +5 -1
  112. package/clients/cli/commands/docs.mjs +30 -2
  113. package/clients/cli/commands/experimental/icon.mjs +56 -14
  114. package/clients/cli/commands/experimental-icon-add.doc.mjs +1 -1
  115. package/clients/cli/commands/experimental-icon-new-definition.doc.mjs +2 -1
  116. package/clients/cli/commands/experimental-icon-new-set.doc.mjs +2 -2
  117. package/clients/cli/commands/experimental-render.doc.mjs +1 -1
  118. package/clients/cli/commands/swizzle.doc.mjs +12 -3
  119. package/clients/cli/commands/swizzle.mjs +33 -9
  120. package/clients/cli/lib/resolve-theme.mjs +16 -7
  121. package/foundation/discovery/component-loader.d.mts +1 -1
  122. package/foundation/discovery/doc-types.mjs +9 -2
  123. package/foundation/discovery/hook-discovery.mjs +31 -8
  124. package/foundation/discovery/icon-ranking.d.mts +27 -3
  125. package/foundation/discovery/icon-ranking.mjs +125 -8
  126. package/foundation/discovery/icon-set-checks.mjs +44 -35
  127. package/foundation/discovery/icon-set-discovery.d.mts +13 -0
  128. package/foundation/discovery/icon-set-discovery.mjs +25 -0
  129. package/foundation/discovery/icon-set-writer.d.mts +258 -20
  130. package/foundation/discovery/icon-set-writer.mjs +785 -87
  131. package/foundation/discovery/module-exports.d.mts +3 -2
  132. package/foundation/discovery/module-exports.mjs +167 -37
  133. package/foundation/doc-compiler/import.d.mts +5 -1
  134. package/foundation/doc-compiler/import.mjs +40 -6
  135. package/foundation/fs/import-url.d.mts +20 -0
  136. package/foundation/fs/import-url.mjs +22 -0
  137. package/foundation/fs/module-loader.d.mts +24 -3
  138. package/foundation/fs/module-loader.mjs +69 -47
  139. package/foundation/fs/paths.d.mts +2 -1
  140. package/foundation/fs/paths.mjs +3 -4
  141. package/foundation/render/charts.d.mts +59 -0
  142. package/foundation/render/charts.mjs +216 -0
  143. package/foundation/render/embedded-imports.d.mts +7 -7
  144. package/foundation/render/embedded-imports.mjs +63 -54
  145. package/foundation/render/page-host.d.mts +4 -0
  146. package/foundation/render/page-host.mjs +45 -0
  147. package/foundation/render/page-worker.mjs +350 -57
  148. package/foundation/render/render-page.d.mts +11 -6
  149. package/foundation/render/render-page.mjs +164 -54
  150. package/foundation/render/ts-paths.d.mts +63 -0
  151. package/foundation/render/ts-paths.mjs +138 -0
  152. package/foundation/response/error-codes.doc.mjs +3 -3
  153. package/foundation/response/error-codes.mjs +3 -2
  154. package/foundation/text/levenshtein.d.mts +6 -1
  155. package/foundation/text/levenshtein.mjs +25 -9
  156. package/foundation/text/shell-arg.d.mts +14 -0
  157. package/foundation/text/shell-arg.mjs +17 -0
  158. package/foundation/text/suggest-order.d.mts +8 -1
  159. package/foundation/text/suggest-order.mjs +72 -6
  160. package/package.json +7 -6
@@ -0,0 +1,146 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ 'use client';
4
+
5
+ import {useState} from 'react';
6
+ import {
7
+ useCalendarConstraints,
8
+ useCalendarDays,
9
+ type CalendarDay,
10
+ } from '@astryxdesign/core/Calendar';
11
+ import {Button} from '@astryxdesign/core/Button';
12
+ import {HStack, VStack} from '@astryxdesign/core/Layout';
13
+ import {Text} from '@astryxdesign/core/Text';
14
+
15
+ // Hotel closed on Mondays (day === 1)
16
+ const isNotMonday = (date: Date) => date.getDay() !== 1;
17
+
18
+ export default function UseCalendarConstraintsHookUsage() {
19
+ const [checkIn, setCheckIn] = useState<CalendarDay['date'] | null>(null);
20
+ const [checkOut, setCheckOut] = useState<CalendarDay['date'] | null>(null);
21
+
22
+ // June 2026 season: open Jun 5 – Jun 25, max 7 nights (8-day span), closed Mondays.
23
+ // When checkOut is already chosen, clear rangeAnchor so full season remains viewable without lingering span restrictions.
24
+ const {isDateDisabled} = useCalendarConstraints({
25
+ min: '2026-06-05',
26
+ max: '2026-06-25',
27
+ maxRangeSpan: 8,
28
+ rangeAnchor: checkOut ? null : checkIn,
29
+ dateConstraints: [isNotMonday],
30
+ });
31
+
32
+ const {weeks, dayNames} = useCalendarDays({
33
+ year: 2026,
34
+ month: 6,
35
+ weekStartsOn: 0,
36
+ hasVariableRowCount: true,
37
+ });
38
+
39
+ const handleSelect = (day: CalendarDay) => {
40
+ if (day.isOutside || isDateDisabled(day.date)) {
41
+ return;
42
+ }
43
+ // If no check-in yet, or already booked, or clicking on/before current check-in: start new check-in
44
+ if (!checkIn || checkOut || day.date.day <= checkIn.day) {
45
+ setCheckIn(day.date);
46
+ setCheckOut(null);
47
+ } else {
48
+ // Pick is after checkIn: set as check-out
49
+ setCheckOut(day.date);
50
+ }
51
+ };
52
+
53
+ const handleReset = () => {
54
+ setCheckIn(null);
55
+ setCheckOut(null);
56
+ };
57
+
58
+ return (
59
+ <VStack gap={3}>
60
+ <VStack gap={1}>
61
+ <Text type="body" weight="bold">
62
+ Hotel Booking — June 2026
63
+ </Text>
64
+ <Text type="supporting" color="secondary">
65
+ Season: Jun 5 – Jun 25 · Max stay: 7 nights · Closed Mondays
66
+ </Text>
67
+ </VStack>
68
+ <HStack gap={2} vAlign="center">
69
+ <Text type="supporting">
70
+ {checkIn
71
+ ? checkOut
72
+ ? `Booked: Jun ${checkIn.day} – Jun ${checkOut.day}`
73
+ : `Check-in: Jun ${checkIn.day} (pick check-out)`
74
+ : 'Pick a check-in date'}
75
+ </Text>
76
+ {checkIn && (
77
+ <Button
78
+ label="Reset"
79
+ size="sm"
80
+ variant="secondary"
81
+ onClick={handleReset}
82
+ />
83
+ )}
84
+ </HStack>
85
+ <table style={{tableLayout: 'fixed', width: 280}}>
86
+ <thead>
87
+ <tr>
88
+ {dayNames.map((name, i) => (
89
+ <th key={i} scope="col">
90
+ <Text type="supporting" color="secondary">
91
+ {name}
92
+ </Text>
93
+ </th>
94
+ ))}
95
+ </tr>
96
+ </thead>
97
+ <tbody>
98
+ {weeks.map(week => (
99
+ <tr key={week[0].iso}>
100
+ {week.map(day => {
101
+ if (day.isOutside) {
102
+ return <td key={day.iso} align="center" />;
103
+ }
104
+
105
+ const disabled = isDateDisabled(day.date);
106
+ const isSelected =
107
+ (checkIn &&
108
+ checkIn.day === day.date.day &&
109
+ checkIn.month === day.date.month) ||
110
+ (checkOut &&
111
+ checkOut.day === day.date.day &&
112
+ checkOut.month === day.date.month);
113
+
114
+ return (
115
+ <td key={day.iso} align="center">
116
+ <button
117
+ type="button"
118
+ disabled={disabled}
119
+ onClick={() => handleSelect(day)}
120
+ aria-pressed={isSelected ? 'true' : 'false'}
121
+ aria-label={`June ${day.dayNumber}`}
122
+ style={{
123
+ width: 32,
124
+ height: 32,
125
+ borderRadius: 6,
126
+ border: isSelected ? '1px solid currentColor' : 'none',
127
+ background: 'transparent',
128
+ opacity: disabled ? 0.35 : 1,
129
+ cursor: disabled ? 'not-allowed' : 'pointer',
130
+ }}>
131
+ <Text
132
+ type="body"
133
+ color={disabled ? 'secondary' : 'primary'}>
134
+ {day.dayNumber}
135
+ </Text>
136
+ </button>
137
+ </td>
138
+ );
139
+ })}
140
+ </tr>
141
+ ))}
142
+ </tbody>
143
+ </table>
144
+ </VStack>
145
+ );
146
+ }
@@ -0,0 +1,14 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ /** @type {import('@astryxdesign/cli/authoring').TemplateDoc} */
4
+ export const doc = {
5
+ type: 'block',
6
+ exampleFor: 'useCalendarNavigation',
7
+ name: 'useCalendarNavigation — Month Pager',
8
+ displayName: 'useCalendarNavigation — Month Pager',
9
+ description:
10
+ 'A calendar month pager with previous/next navigation buttons, localized month-year label, and cross-month arrow key navigation using pendingFocus.',
11
+ isReady: true,
12
+ aspectRatio: 4 / 3,
13
+ componentsUsed: ['Button', 'Layout', 'Text'],
14
+ };
@@ -0,0 +1,173 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ 'use client';
4
+
5
+ import {useEffect, useRef, useState} from 'react';
6
+ import {
7
+ useCalendarDays,
8
+ useCalendarNavigation,
9
+ type CalendarDay,
10
+ type ISODateString,
11
+ } from '@astryxdesign/core/Calendar';
12
+ import {Button} from '@astryxdesign/core/Button';
13
+ import {HStack, VStack} from '@astryxdesign/core/Layout';
14
+ import {Text} from '@astryxdesign/core/Text';
15
+
16
+ export default function UseCalendarNavigationHookUsage() {
17
+ const [focusDate, setFocusDate] = useState<ISODateString>(
18
+ '2026-06-01' as ISODateString,
19
+ );
20
+
21
+ const {
22
+ monthYearLabel,
23
+ visibleCalendarMonths,
24
+ navigateMonth,
25
+ pendingFocus,
26
+ clearPendingFocus,
27
+ } = useCalendarNavigation({
28
+ focusDate,
29
+ onFocusDateChange: setFocusDate,
30
+ numberOfMonths: 1,
31
+ });
32
+
33
+ const {weeks, dayNames} = useCalendarDays({
34
+ ...visibleCalendarMonths[0],
35
+ weekStartsOn: 0,
36
+ hasVariableRowCount: true,
37
+ });
38
+
39
+ const dayButtonRefs = useRef<Map<string, HTMLButtonElement>>(new Map());
40
+
41
+ // Move focus to target date when navigating across month boundaries
42
+ useEffect(() => {
43
+ if (pendingFocus) {
44
+ const el = dayButtonRefs.current.get(pendingFocus);
45
+ if (el) {
46
+ el.focus();
47
+ clearPendingFocus();
48
+ }
49
+ }
50
+ }, [pendingFocus, clearPendingFocus, weeks]);
51
+
52
+ // Arrow key navigation moving across days and month boundaries with RTL awareness (DR6, DR11)
53
+ const handleKeyDown = (
54
+ e: React.KeyboardEvent<HTMLButtonElement>,
55
+ day: CalendarDay,
56
+ ) => {
57
+ if (day.isOutside) {
58
+ return;
59
+ }
60
+
61
+ const isRtl =
62
+ typeof window !== 'undefined' &&
63
+ getComputedStyle(e.currentTarget).direction === 'rtl';
64
+
65
+ const isNext = isRtl ? e.key === 'ArrowLeft' : e.key === 'ArrowRight';
66
+ const isPrev = isRtl ? e.key === 'ArrowRight' : e.key === 'ArrowLeft';
67
+
68
+ if (isNext) {
69
+ e.preventDefault();
70
+ const inMonthDays = weeks.flatMap(w => w.filter(d => !d.isOutside));
71
+ const currentIndex = inMonthDays.findIndex(d => d.iso === day.iso);
72
+ if (currentIndex === inMonthDays.length - 1) {
73
+ // Last day of month: advance month and focus next day across boundary
74
+ navigateMonth(1, day.iso, 1);
75
+ } else {
76
+ const nextDay = inMonthDays[currentIndex + 1];
77
+ dayButtonRefs.current.get(nextDay.iso)?.focus();
78
+ }
79
+ } else if (isPrev) {
80
+ e.preventDefault();
81
+ const inMonthDays = weeks.flatMap(w => w.filter(d => !d.isOutside));
82
+ const currentIndex = inMonthDays.findIndex(d => d.iso === day.iso);
83
+ if (currentIndex === 0) {
84
+ // First day of month: step back month and focus previous day across boundary
85
+ navigateMonth(-1, day.iso, 1);
86
+ } else {
87
+ const prevDay = inMonthDays[currentIndex - 1];
88
+ dayButtonRefs.current.get(prevDay.iso)?.focus();
89
+ }
90
+ }
91
+ };
92
+
93
+ return (
94
+ <VStack gap={3} style={{width: 280}}>
95
+ <HStack gap={2} vAlign="center" hAlign="between">
96
+ <Button
97
+ label="Previous"
98
+ size="sm"
99
+ variant="secondary"
100
+ onClick={() => navigateMonth(-1)}
101
+ aria-label="Previous month"
102
+ />
103
+ <Text type="body" weight="bold">
104
+ {monthYearLabel}
105
+ </Text>
106
+ <Button
107
+ label="Next"
108
+ size="sm"
109
+ variant="secondary"
110
+ onClick={() => navigateMonth(1)}
111
+ aria-label="Next month"
112
+ />
113
+ </HStack>
114
+
115
+ <table style={{tableLayout: 'fixed', width: 280}}>
116
+ <thead>
117
+ <tr>
118
+ {dayNames.map((name, i) => (
119
+ <th key={i} scope="col">
120
+ <Text type="supporting" color="secondary">
121
+ {name}
122
+ </Text>
123
+ </th>
124
+ ))}
125
+ </tr>
126
+ </thead>
127
+ <tbody>
128
+ {weeks.map(week => (
129
+ <tr key={week[0].iso}>
130
+ {week.map(day => (
131
+ <td key={day.iso} align="center">
132
+ <button
133
+ type="button"
134
+ ref={el => {
135
+ if (el) {
136
+ dayButtonRefs.current.set(day.iso, el);
137
+ } else {
138
+ dayButtonRefs.current.delete(day.iso);
139
+ }
140
+ }}
141
+ disabled={day.isOutside}
142
+ aria-hidden={day.isOutside || undefined}
143
+ onKeyDown={e => handleKeyDown(e, day)}
144
+ aria-label={
145
+ day.isOutside
146
+ ? undefined
147
+ : `${monthYearLabel} ${day.dayNumber}`
148
+ }
149
+ tabIndex={day.isOutside ? -1 : 0}
150
+ style={{
151
+ width: 32,
152
+ height: 32,
153
+ borderRadius: 6,
154
+ border: 'none',
155
+ background: 'transparent',
156
+ opacity: day.isOutside ? 0.35 : 1,
157
+ cursor: day.isOutside ? 'not-allowed' : 'pointer',
158
+ }}>
159
+ <Text
160
+ type="body"
161
+ color={day.isOutside ? 'secondary' : 'primary'}>
162
+ {day.dayNumber}
163
+ </Text>
164
+ </button>
165
+ </td>
166
+ ))}
167
+ </tr>
168
+ ))}
169
+ </tbody>
170
+ </table>
171
+ </VStack>
172
+ );
173
+ }
@@ -74,6 +74,7 @@ function CouponField({statusVariant}: {statusVariant: FieldStatusPlacement}) {
74
74
  <div
75
75
  {...stylex.props(
76
76
  inputWrapperStyles.base,
77
+ inputWrapperStyles.textField,
77
78
  styles.field,
78
79
  status && inputStatusBorderStyles[status.type],
79
80
  )}>
@@ -0,0 +1,14 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ /** @type {import('@astryxdesign/cli/authoring').TemplateDoc} */
4
+ export const doc = {
5
+ type: 'block',
6
+ exampleFor: 'useInteractiveRole',
7
+ name: 'useInteractiveRole — One Tile, Four Roles',
8
+ displayName: 'useInteractiveRole — One Tile, Four Roles',
9
+ description:
10
+ 'A polymorphic Tile used four ways: with an href it renders as a link, with an onClick as a button, with neither as plain content, and placed as a Popover trigger it becomes the trigger button through context — the resolution order in one place.',
11
+ isReady: true,
12
+ aspectRatio: 4 / 3,
13
+ componentsUsed: ['Popover', 'Card', 'Text', 'Layout', 'Link'],
14
+ };
@@ -0,0 +1,56 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ 'use client';
4
+
5
+ import {useInteractiveRole} from '@astryxdesign/core/hooks';
6
+ import {Link} from '@astryxdesign/core/Link';
7
+ import {Popover} from '@astryxdesign/core/Popover';
8
+ import {Card} from '@astryxdesign/core/Card';
9
+ import {Text} from '@astryxdesign/core/Text';
10
+ import {VStack} from '@astryxdesign/core/Layout';
11
+
12
+ // A polymorphic Tile: the hook alone decides what it renders as — href wins,
13
+ // then onClick, then a trigger context (Popover), then inert.
14
+ function Tile({
15
+ href,
16
+ onClick,
17
+ children,
18
+ }: {
19
+ href?: string;
20
+ onClick?: () => void;
21
+ children: React.ReactNode;
22
+ }) {
23
+ const role = useInteractiveRole({href, onClick});
24
+ const body = (
25
+ <Card padding={3} width={200}>
26
+ <Text type="body">{children}</Text>
27
+ </Card>
28
+ );
29
+ switch (role) {
30
+ case 'link':
31
+ return <Link href={href}>{body}</Link>;
32
+ case 'button':
33
+ return <button onClick={onClick}>{body}</button>;
34
+ default:
35
+ return body;
36
+ }
37
+ }
38
+
39
+ export default function UseInteractiveRoleHookUsage() {
40
+ return (
41
+ <VStack gap={3} hAlign="center" style={{width: '100%'}}>
42
+ <Tile href="https://example.com/docs">Renders as a link</Tile>
43
+ <Tile onClick={() => {}}>Renders as a button</Tile>
44
+ <Popover
45
+ label="Tile details"
46
+ content={
47
+ <Card padding={3}>
48
+ <Text type="body">Opened through the tile's context role</Text>
49
+ </Card>
50
+ }>
51
+ <Tile>Trigger via context</Tile>
52
+ </Popover>
53
+ <Tile>Plain content</Tile>
54
+ </VStack>
55
+ );
56
+ }
@@ -7,8 +7,8 @@ export const doc = {
7
7
  name: 'useStreamingText — Streaming Response',
8
8
  displayName: 'useStreamingText — Streaming Response',
9
9
  description:
10
- 'Smooth bursty generated text into a steady reveal with useStreamingText.',
10
+ 'A chat-style reply card: while the response streams in bursts, useStreamingText reveals it steadily character by character; when streaming ends the full text snaps into place. Regenerate replays the stream.',
11
11
  isReady: true,
12
12
  aspectRatio: 4 / 3,
13
- componentsUsed: ['Card', 'Text', 'Layout'],
13
+ componentsUsed: ['Button', 'Card', 'Text', 'Layout'],
14
14
  };
@@ -2,29 +2,85 @@
2
2
 
3
3
  'use client';
4
4
 
5
+ import {useCallback, useEffect, useRef, useState} from 'react';
5
6
  import {useStreamingText} from '@astryxdesign/core/hooks';
7
+ import {Button} from '@astryxdesign/core/Button';
6
8
  import {Card} from '@astryxdesign/core/Card';
7
- import {VStack} from '@astryxdesign/core/Layout';
8
9
  import {Text} from '@astryxdesign/core/Text';
10
+ import {VStack} from '@astryxdesign/core/Layout';
11
+
12
+ const CHUNKS = [
13
+ 'Astryx hooks keep behavior reusable ',
14
+ 'while components keep visuals consistent. ',
15
+ 'Streaming text arrives in bursts; ',
16
+ 'the hook smooths it into a steady reveal.',
17
+ ];
9
18
 
10
- const response =
11
- 'Astryx hooks keep behavior reusable while components keep visuals consistent.';
19
+ // A fake stream: chunks land in bursts, the way a model streams tokens.
20
+ // Starting again stops the stream in progress, and the last chunk ends it.
21
+ function useFakeStream(onChunk: (chunk: string) => void, onEnd: () => void) {
22
+ const timer = useRef<ReturnType<typeof setTimeout> | null>(null);
23
+ const start = useCallback(() => {
24
+ if (timer.current) {
25
+ clearTimeout(timer.current);
26
+ }
27
+ let index = 0;
28
+ const tick = () => {
29
+ onChunk(CHUNKS[index]);
30
+ index += 1;
31
+ if (index < CHUNKS.length) {
32
+ timer.current = setTimeout(tick, 350);
33
+ } else {
34
+ timer.current = null;
35
+ onEnd();
36
+ }
37
+ };
38
+ timer.current = setTimeout(tick, 350);
39
+ }, [onChunk, onEnd]);
40
+ useEffect(
41
+ () => () => {
42
+ if (timer.current) {
43
+ clearTimeout(timer.current);
44
+ }
45
+ },
46
+ [],
47
+ );
48
+ return start;
49
+ }
12
50
 
13
51
  export default function UseStreamingTextHookUsage() {
14
- const displayedText = useStreamingText(response, false, {
15
- speed: 'fast',
16
- });
52
+ const [target, setTarget] = useState('');
53
+ const [isStreaming, setIsStreaming] = useState(false);
54
+
55
+ const appendChunk = useCallback((chunk: string) => {
56
+ setTarget(previous => previous + chunk);
57
+ }, []);
58
+ // When the last chunk has landed, end the stream so the hook snaps to the
59
+ // full text.
60
+ const endStream = useCallback(() => setIsStreaming(false), []);
61
+ const startStream = useFakeStream(appendChunk, endStream);
62
+
63
+ const regenerate = useCallback(() => {
64
+ setTarget('');
65
+ setIsStreaming(true);
66
+ startStream();
67
+ }, [startStream]);
68
+
69
+ const displayedText = useStreamingText(target, isStreaming, {speed: 'fast'});
17
70
 
18
71
  return (
19
72
  <Card width={420} padding={4}>
20
- <VStack gap={2}>
73
+ <VStack gap={3}>
21
74
  <Text type="body" weight="bold">
22
75
  Assistant response
23
76
  </Text>
24
77
  <Text type="body">{displayedText}</Text>
25
- <Text type="supporting" color="secondary">
26
- Complete
27
- </Text>
78
+ <Button
79
+ label={isStreaming ? 'Streaming…' : 'Regenerate'}
80
+ variant="secondary"
81
+ size="sm"
82
+ onClick={regenerate}
83
+ />
28
84
  </VStack>
29
85
  </Card>
30
86
  );
@@ -0,0 +1,14 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ /** @type {import('@astryxdesign/cli/authoring').TemplateDoc} */
4
+ export const doc = {
5
+ type: 'block',
6
+ exampleFor: 'useLinkify',
7
+ name: 'useLinkify — Links in a Comment Thread',
8
+ displayName: 'useLinkify — Links in a Comment Thread',
9
+ description:
10
+ 'Plain-text comments where useLinkify turns the URL and the email address into Links, and a custom pattern turns issue references like #123 into tracker links — the patterns option in action. The comment without matches stays plain text.',
11
+ isReady: true,
12
+ aspectRatio: 4 / 3,
13
+ componentsUsed: ['Link', 'Layout', 'Text'],
14
+ };
@@ -0,0 +1,39 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ 'use client';
4
+
5
+ import {useLinkify, type LinkifyPattern} from '@astryxdesign/core/Link';
6
+ import {VStack} from '@astryxdesign/core/Layout';
7
+ import {Text} from '@astryxdesign/core/Text';
8
+
9
+ const COMMENTS = [
10
+ 'See https://example.com/spec or email support@example.com.',
11
+ 'Fixed by #123, tracking the regression in #456.',
12
+ 'No links here, just a plain note.',
13
+ ];
14
+
15
+ // Issue references like #123 link into the tracker; the capture group maps
16
+ // onto its URL scheme, showing the patterns option.
17
+ const ISSUE_PATTERN: LinkifyPattern = {
18
+ pattern: /#(\d+)/g,
19
+ href: match => `https://example.com/issues/${match[1]}`,
20
+ };
21
+
22
+ function Comment({children}: {children: string}) {
23
+ const nodes = useLinkify(children, {patterns: [ISSUE_PATTERN]});
24
+ return (
25
+ <Text type="body" color="secondary">
26
+ {nodes}
27
+ </Text>
28
+ );
29
+ }
30
+
31
+ export default function UseLinkifyHookUsage() {
32
+ return (
33
+ <VStack gap={3} style={{width: '100%', maxWidth: 360}}>
34
+ {COMMENTS.map(comment => (
35
+ <Comment key={comment}>{comment}</Comment>
36
+ ))}
37
+ </VStack>
38
+ );
39
+ }
@@ -0,0 +1,14 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ /** @type {import('@astryxdesign/cli/authoring').TemplateDoc} */
4
+ export const doc = {
5
+ type: 'block',
6
+ exampleFor: 'usePowerSearchConfig',
7
+ name: 'usePowerSearchConfig — Filtered Directory Table',
8
+ displayName: 'usePowerSearchConfig — Filtered Directory Table',
9
+ description:
10
+ 'A people directory with a PowerSearch bar over a Table: typed field definitions feed usePowerSearchConfig, returning the search config and an applyFilters helper that updates Table rows.',
11
+ isReady: true,
12
+ aspectRatio: 4 / 3,
13
+ componentsUsed: ['PowerSearch', 'Table', 'Layout'],
14
+ };
@@ -0,0 +1,83 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ 'use client';
4
+
5
+ import {useState} from 'react';
6
+ import {VStack} from '@astryxdesign/core/Layout';
7
+ import {
8
+ PowerSearch,
9
+ usePowerSearchConfig,
10
+ } from '@astryxdesign/core/PowerSearch';
11
+ import type {PowerSearchFilter} from '@astryxdesign/core/PowerSearch';
12
+ import {Table} from '@astryxdesign/core/Table';
13
+ import type {TableColumn} from '@astryxdesign/core/Table';
14
+
15
+ const statusValues = [
16
+ {value: 'active', label: 'Active'},
17
+ {value: 'on-leave', label: 'On Leave'},
18
+ {value: 'contractor', label: 'Contractor'},
19
+ ];
20
+
21
+ const fieldDefs = [
22
+ {key: 'name', type: 'string', label: 'Name'},
23
+ {key: 'status', type: 'enum', label: 'Status', enumValues: statusValues},
24
+ {key: 'startDate', type: 'date', label: 'Start date'},
25
+ ] as const;
26
+
27
+ interface Person extends Record<string, unknown> {
28
+ id: string;
29
+ name: string;
30
+ status: string;
31
+ startDate: number;
32
+ }
33
+
34
+ const people: Person[] = [
35
+ {id: '1', name: 'Alice Chen', status: 'active', startDate: 1672531200},
36
+ {id: '2', name: 'Bob Dylan', status: 'on-leave', startDate: 1680307200},
37
+ {id: '3', name: 'Charlie Kim', status: 'active', startDate: 1688169600},
38
+ {id: '4', name: 'Dana Scully', status: 'contractor', startDate: 1696118400},
39
+ {id: '5', name: 'Evan Wright', status: 'active', startDate: 1704067200},
40
+ ];
41
+
42
+ const columns: TableColumn<Person>[] = [
43
+ {key: 'name', header: 'Name'},
44
+ {
45
+ key: 'status',
46
+ header: 'Status',
47
+ renderCell: (person: Person) =>
48
+ statusValues.find(s => s.value === person.status)?.label ?? person.status,
49
+ },
50
+ {
51
+ key: 'startDate',
52
+ header: 'Start Date',
53
+ renderCell: (person: Person) =>
54
+ new Date(person.startDate * 1000).toLocaleDateString('en-US', {
55
+ timeZone: 'UTC',
56
+ year: 'numeric',
57
+ month: 'short',
58
+ day: 'numeric',
59
+ }),
60
+ },
61
+ ];
62
+
63
+ export default function UsePowerSearchConfigHookUsage() {
64
+ const [filters, setFilters] = useState<PowerSearchFilter[]>([]);
65
+ const {config, applyFilters} = usePowerSearchConfig(
66
+ fieldDefs,
67
+ 'PeopleDirectory',
68
+ );
69
+ const filteredPeople = applyFilters(filters, people);
70
+
71
+ return (
72
+ <VStack gap={4}>
73
+ <PowerSearch
74
+ config={config}
75
+ filters={filters}
76
+ onChange={newFilters => setFilters([...newFilters])}
77
+ placeholder="Filter directory by name, status, start date..."
78
+ resultCount={filteredPeople.length}
79
+ />
80
+ <Table data={filteredPeople} columns={columns} idKey="id" hasHover />
81
+ </VStack>
82
+ );
83
+ }