@blankways/ui 0.0.0-stage → 0.1.0-alpha.1

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 (216) hide show
  1. package/README.md +228 -2
  2. package/dist/cli/cli.options.d.ts +5 -0
  3. package/dist/cli/cli.options.js +53 -0
  4. package/dist/cli/cli.registry.d.ts +6 -0
  5. package/dist/cli/cli.registry.js +37 -0
  6. package/dist/cli/cli.types.d.ts +32 -0
  7. package/dist/cli/cli.types.js +1 -0
  8. package/dist/cli/index.d.ts +3 -0
  9. package/dist/cli/index.js +3 -0
  10. package/dist/cli.d.ts +2 -0
  11. package/dist/cli.js +47 -0
  12. package/dist/commands/add.command.d.ts +2 -0
  13. package/dist/commands/add.command.js +101 -0
  14. package/dist/commands/doctor.command.d.ts +3 -0
  15. package/dist/commands/doctor.command.js +92 -0
  16. package/dist/commands/index.d.ts +6 -0
  17. package/dist/commands/index.js +6 -0
  18. package/dist/commands/init.command.d.ts +2 -0
  19. package/dist/commands/init.command.js +38 -0
  20. package/dist/commands/list.command.d.ts +2 -0
  21. package/dist/commands/list.command.js +54 -0
  22. package/dist/commands/meta.command.d.ts +1 -0
  23. package/dist/commands/meta.command.js +19 -0
  24. package/dist/commands/styles.command.d.ts +6 -0
  25. package/dist/commands/styles.command.js +68 -0
  26. package/dist/config/config.helpers.d.ts +7 -0
  27. package/dist/config/config.helpers.js +63 -0
  28. package/dist/config/framework.helpers.d.ts +3 -0
  29. package/dist/config/framework.helpers.js +14 -0
  30. package/dist/config/index.d.ts +2 -0
  31. package/dist/config/index.js +2 -0
  32. package/dist/constants/cli.constants.d.ts +9 -0
  33. package/dist/constants/cli.constants.js +15 -0
  34. package/dist/constants/framework.constants.d.ts +3 -0
  35. package/dist/constants/framework.constants.js +2 -0
  36. package/dist/constants/index.d.ts +2 -0
  37. package/dist/constants/index.js +2 -0
  38. package/dist/doctor/checks/entries.check.d.ts +1 -0
  39. package/dist/doctor/checks/entries.check.js +21 -0
  40. package/dist/doctor/checks/icons.check.d.ts +1 -0
  41. package/dist/doctor/checks/icons.check.js +55 -0
  42. package/dist/doctor/checks/imports.check.d.ts +1 -0
  43. package/dist/doctor/checks/imports.check.js +45 -0
  44. package/dist/doctor/checks/index.d.ts +7 -0
  45. package/dist/doctor/checks/index.js +7 -0
  46. package/dist/doctor/checks/motion.check.d.ts +1 -0
  47. package/dist/doctor/checks/motion.check.js +66 -0
  48. package/dist/doctor/checks/peers.check.d.ts +1 -0
  49. package/dist/doctor/checks/peers.check.js +55 -0
  50. package/dist/doctor/checks/styles.check.d.ts +1 -0
  51. package/dist/doctor/checks/styles.check.js +45 -0
  52. package/dist/doctor/checks/themes.check.d.ts +1 -0
  53. package/dist/doctor/checks/themes.check.js +64 -0
  54. package/dist/doctor/doctor.helpers.d.ts +6 -0
  55. package/dist/doctor/doctor.helpers.js +39 -0
  56. package/dist/doctor/doctor.registry.d.ts +10 -0
  57. package/dist/doctor/doctor.registry.js +24 -0
  58. package/dist/doctor/doctor.types.d.ts +27 -0
  59. package/dist/doctor/doctor.types.js +1 -0
  60. package/dist/doctor/index.d.ts +3 -0
  61. package/dist/doctor/index.js +3 -0
  62. package/dist/errors/cli-error.d.ts +3 -0
  63. package/dist/errors/cli-error.js +6 -0
  64. package/dist/errors/index.d.ts +1 -0
  65. package/dist/errors/index.js +1 -0
  66. package/dist/helpers/args.helpers.d.ts +4 -0
  67. package/dist/helpers/args.helpers.js +75 -0
  68. package/dist/helpers/help.helpers.d.ts +1 -0
  69. package/dist/helpers/help.helpers.js +30 -0
  70. package/dist/helpers/index.d.ts +5 -0
  71. package/dist/helpers/index.js +5 -0
  72. package/dist/helpers/package.helpers.d.ts +2 -0
  73. package/dist/helpers/package.helpers.js +12 -0
  74. package/dist/helpers/path.helpers.d.ts +3 -0
  75. package/dist/helpers/path.helpers.js +15 -0
  76. package/dist/helpers/styles.helpers.d.ts +21 -0
  77. package/dist/helpers/styles.helpers.js +164 -0
  78. package/dist/index.d.ts +9 -0
  79. package/dist/index.js +9 -0
  80. package/dist/registry/index.d.ts +1 -0
  81. package/dist/registry/index.js +1 -0
  82. package/dist/registry/registry.helpers.d.ts +22 -0
  83. package/dist/registry/registry.helpers.js +328 -0
  84. package/dist/registry-data/README.md +71 -0
  85. package/dist/registry-data/avatar/Avatar.tsx +64 -0
  86. package/dist/registry-data/avatar/component.json +30 -0
  87. package/dist/registry-data/avatar/index.ts +1 -0
  88. package/dist/registry-data/badge/Badge.tsx +76 -0
  89. package/dist/registry-data/badge/component.json +30 -0
  90. package/dist/registry-data/badge/index.ts +1 -0
  91. package/dist/registry-data/brand-logo/BrandLogo.tsx +24 -0
  92. package/dist/registry-data/brand-logo/component.json +26 -0
  93. package/dist/registry-data/brand-logo/index.ts +1 -0
  94. package/dist/registry-data/button/Button.tsx +76 -0
  95. package/dist/registry-data/button/component.json +33 -0
  96. package/dist/registry-data/button/index.ts +1 -0
  97. package/dist/registry-data/button-link/ButtonLink.tsx +83 -0
  98. package/dist/registry-data/button-link/component.json +33 -0
  99. package/dist/registry-data/button-link/index.ts +5 -0
  100. package/dist/registry-data/button-styles/component.json +19 -0
  101. package/dist/registry-data/button-styles/index.ts +45 -0
  102. package/dist/registry-data/cn/cn.ts +6 -0
  103. package/dist/registry-data/cn/component.json +16 -0
  104. package/dist/registry-data/confirm-dialog/ConfirmDialog.tsx +134 -0
  105. package/dist/registry-data/confirm-dialog/component.json +34 -0
  106. package/dist/registry-data/confirm-dialog/index.ts +1 -0
  107. package/dist/registry-data/container/Container.tsx +22 -0
  108. package/dist/registry-data/container/component.json +28 -0
  109. package/dist/registry-data/container/index.ts +1 -0
  110. package/dist/registry-data/cursor-glow/CursorGlow.tsx +29 -0
  111. package/dist/registry-data/cursor-glow/component.json +28 -0
  112. package/dist/registry-data/cursor-glow/index.ts +1 -0
  113. package/dist/registry-data/dropdown-menu/DropdownMenu.tsx +157 -0
  114. package/dist/registry-data/dropdown-menu/component.json +34 -0
  115. package/dist/registry-data/dropdown-menu/index.ts +5 -0
  116. package/dist/registry-data/empty-state/EmptyState.tsx +92 -0
  117. package/dist/registry-data/empty-state/component.json +30 -0
  118. package/dist/registry-data/empty-state/index.ts +5 -0
  119. package/dist/registry-data/eyebrow/Eyebrow.tsx +68 -0
  120. package/dist/registry-data/eyebrow/component.json +30 -0
  121. package/dist/registry-data/eyebrow/index.ts +1 -0
  122. package/dist/registry-data/field-styles/component.json +19 -0
  123. package/dist/registry-data/field-styles/index.ts +42 -0
  124. package/dist/registry-data/form-dialog/FormDialog.tsx +128 -0
  125. package/dist/registry-data/form-dialog/component.json +34 -0
  126. package/dist/registry-data/form-dialog/index.ts +1 -0
  127. package/dist/registry-data/icons/component.json +22 -0
  128. package/dist/registry-data/icons/index.ts +21 -0
  129. package/dist/registry-data/icons-form/component.json +17 -0
  130. package/dist/registry-data/icons-form/index.ts +1 -0
  131. package/dist/registry-data/icons-sidebar/component.json +17 -0
  132. package/dist/registry-data/icons-sidebar/index.ts +1 -0
  133. package/dist/registry-data/icons-theme/component.json +17 -0
  134. package/dist/registry-data/icons-theme/index.ts +1 -0
  135. package/dist/registry-data/icons-toast/component.json +17 -0
  136. package/dist/registry-data/icons-toast/index.ts +1 -0
  137. package/dist/registry-data/info-dialog/InfoDialog.tsx +119 -0
  138. package/dist/registry-data/info-dialog/component.json +36 -0
  139. package/dist/registry-data/info-dialog/index.ts +1 -0
  140. package/dist/registry-data/input/Input.tsx +96 -0
  141. package/dist/registry-data/input/component.json +33 -0
  142. package/dist/registry-data/input/index.ts +1 -0
  143. package/dist/registry-data/multi-combobox/MultiCombobox.tsx +205 -0
  144. package/dist/registry-data/multi-combobox/component.json +35 -0
  145. package/dist/registry-data/multi-combobox/index.ts +5 -0
  146. package/dist/registry-data/remote-provider/RemoteProvider.tsx +8 -0
  147. package/dist/registry-data/remote-provider/component.json +25 -0
  148. package/dist/registry-data/remote-provider/index.ts +3 -0
  149. package/dist/registry-data/reveal/Reveal.tsx +22 -0
  150. package/dist/registry-data/reveal/component.json +30 -0
  151. package/dist/registry-data/reveal/index.ts +1 -0
  152. package/dist/registry-data/section/Section.tsx +80 -0
  153. package/dist/registry-data/section/component.json +30 -0
  154. package/dist/registry-data/section/index.ts +1 -0
  155. package/dist/registry-data/section-heading/SectionHeading.tsx +105 -0
  156. package/dist/registry-data/section-heading/component.json +32 -0
  157. package/dist/registry-data/section-heading/index.ts +1 -0
  158. package/dist/registry-data/select/Select.tsx +197 -0
  159. package/dist/registry-data/select/component.json +34 -0
  160. package/dist/registry-data/select/index.ts +1 -0
  161. package/dist/registry-data/sidebar/Sidebar.tsx +432 -0
  162. package/dist/registry-data/sidebar/SidebarCollapsible.tsx +77 -0
  163. package/dist/registry-data/sidebar/SidebarParts.tsx +373 -0
  164. package/dist/registry-data/sidebar/component.json +47 -0
  165. package/dist/registry-data/sidebar/index.ts +4 -0
  166. package/dist/registry-data/sidebar/useSidebar.ts +29 -0
  167. package/dist/registry-data/styles-base/component.json +19 -0
  168. package/dist/registry-data/styles-base/index.css +67 -0
  169. package/dist/registry-data/styles-components/component.json +19 -0
  170. package/dist/registry-data/styles-components/index.css +30 -0
  171. package/dist/registry-data/styles-motion/component.json +20 -0
  172. package/dist/registry-data/styles-motion/index.css +381 -0
  173. package/dist/registry-data/styles-tokens/component.json +17 -0
  174. package/dist/registry-data/styles-tokens/index.css +77 -0
  175. package/dist/registry-data/styles-utilities/component.json +19 -0
  176. package/dist/registry-data/styles-utilities/index.css +29 -0
  177. package/dist/registry-data/switch/Switch.tsx +91 -0
  178. package/dist/registry-data/switch/component.json +34 -0
  179. package/dist/registry-data/switch/index.ts +1 -0
  180. package/dist/registry-data/tabs/Tabs.tsx +226 -0
  181. package/dist/registry-data/tabs/component.json +32 -0
  182. package/dist/registry-data/tabs/index.ts +1 -0
  183. package/dist/registry-data/textarea/Textarea.tsx +94 -0
  184. package/dist/registry-data/textarea/component.json +33 -0
  185. package/dist/registry-data/textarea/index.ts +1 -0
  186. package/dist/registry-data/theme-core/component.json +17 -0
  187. package/dist/registry-data/theme-core/theme.ts +84 -0
  188. package/dist/registry-data/theme-dark/component.json +19 -0
  189. package/dist/registry-data/theme-dark/index.ts +7 -0
  190. package/dist/registry-data/theme-light/component.json +19 -0
  191. package/dist/registry-data/theme-light/index.ts +7 -0
  192. package/dist/registry-data/theme-provider/ThemeContext.tsx +177 -0
  193. package/dist/registry-data/theme-provider/component.json +30 -0
  194. package/dist/registry-data/theme-provider/index.ts +2 -0
  195. package/dist/registry-data/theme-selector/ThemeSelector.tsx +269 -0
  196. package/dist/registry-data/theme-selector/component.json +35 -0
  197. package/dist/registry-data/theme-selector/selector.ts +1 -0
  198. package/dist/registry-data/theme-system/component.json +19 -0
  199. package/dist/registry-data/theme-system/index.ts +7 -0
  200. package/dist/registry-data/theme-toggle/ThemeToggle.tsx +71 -0
  201. package/dist/registry-data/theme-toggle/component.json +31 -0
  202. package/dist/registry-data/theme-toggle/toggle.ts +1 -0
  203. package/dist/registry-data/toast/Toast.tsx +260 -0
  204. package/dist/registry-data/toast/ToastTypeIcon.tsx +83 -0
  205. package/dist/registry-data/toast/component.json +43 -0
  206. package/dist/registry-data/toast/index.ts +3 -0
  207. package/dist/registry-data/toast/useToast.ts +47 -0
  208. package/dist/types/cli.types.d.ts +6 -0
  209. package/dist/types/cli.types.js +1 -0
  210. package/dist/types/config.types.d.ts +41 -0
  211. package/dist/types/config.types.js +1 -0
  212. package/dist/types/index.d.ts +3 -0
  213. package/dist/types/index.js +3 -0
  214. package/dist/types/registry.types.d.ts +37 -0
  215. package/dist/types/registry.types.js +1 -0
  216. package/package.json +35 -3
@@ -0,0 +1,226 @@
1
+ import { State, type StateId } from '@blankways/state'
2
+ import {
3
+ Show,
4
+ useAttributes,
5
+ useCompute,
6
+ useMatch,
7
+ useState,
8
+ useStateValue,
9
+ } from '@blankways/state-react'
10
+ import {
11
+ createContext,
12
+ useCallback,
13
+ useContext,
14
+ useEffect,
15
+ useMemo,
16
+ Children,
17
+ isValidElement,
18
+ type ComponentPropsWithoutRef,
19
+ type CSSProperties,
20
+ type ReactElement,
21
+ } from 'react'
22
+ import { cn } from '../../internals/cn.js'
23
+
24
+ // Module-level, stable cases for `useMatch`.
25
+ const TAB_STATES = ['active', 'inactive'] as const
26
+ const PANEL_STATES = ['visible', 'hidden'] as const
27
+
28
+ type TabsContextValue = {
29
+ value: StateId<string>
30
+ setValue: (value: string) => void
31
+ }
32
+
33
+ const TabsContext = createContext<TabsContextValue | null>(null)
34
+
35
+ function useTabs(): TabsContextValue {
36
+ const context = useContext(TabsContext)
37
+ if (!context) {
38
+ throw new Error('Tabs parts must be used within a Tabs root')
39
+ }
40
+ return context
41
+ }
42
+
43
+ type TabsProps = ComponentPropsWithoutRef<'div'> & {
44
+ /** Controlled value, either plain or reactive. */
45
+ value?: string | StateId<string>
46
+ defaultValue?: string
47
+ onValueChange?: (value: string) => void
48
+ }
49
+
50
+ /** Groups a tab list and its panels around one shared value state. */
51
+ export function Tabs({
52
+ value,
53
+ defaultValue = '',
54
+ onValueChange,
55
+ className,
56
+ children,
57
+ ...props
58
+ }: TabsProps) {
59
+ const fallback = useState<string>(
60
+ typeof value === 'number' ? State.get(value) : (value ?? defaultValue),
61
+ )
62
+ useEffect(() => {
63
+ if (typeof value === 'string') State.set(fallback, value)
64
+ }, [fallback, value])
65
+
66
+ const valueState = typeof value === 'number' ? value : fallback
67
+ const setValue = useCallback(
68
+ (next: string) => {
69
+ State.set(valueState, next)
70
+ onValueChange?.(next)
71
+ },
72
+ [onValueChange, valueState],
73
+ )
74
+ const context = useMemo<TabsContextValue>(
75
+ () => ({ value: valueState, setValue }),
76
+ [setValue, valueState],
77
+ )
78
+
79
+ return (
80
+ <TabsContext.Provider value={context}>
81
+ <div
82
+ data-slot="tabs"
83
+ className={cn('flex flex-col gap-6', className)}
84
+ {...props}
85
+ >
86
+ {children}
87
+ </div>
88
+ </TabsContext.Provider>
89
+ )
90
+ }
91
+
92
+ /** Row of triggers with one pill that slides to the active tab. */
93
+ export function TabsList({
94
+ className,
95
+ children,
96
+ ...props
97
+ }: ComponentPropsWithoutRef<'div'>) {
98
+ const { value } = useTabs()
99
+ const activeValue = useStateValue(value)
100
+ const triggers = Children.toArray(children).filter(isValidElement) as ReactElement<{
101
+ value?: string
102
+ }>[]
103
+ const activeIndex = Math.max(
104
+ 0,
105
+ triggers.findIndex((trigger) => trigger.props.value === activeValue),
106
+ )
107
+ const style = {
108
+ '--active-index': activeIndex,
109
+ '--tab-count': Math.max(triggers.length, 1),
110
+ } as CSSProperties
111
+
112
+ return (
113
+ <div
114
+ className="relative inline-flex w-fit items-center rounded-2xl bg-surface-2 p-[0.188rem]"
115
+ style={style}
116
+ >
117
+ <span aria-hidden="true" className="tabs-indicator" />
118
+ <div
119
+ role="tablist"
120
+ data-slot="tabs-list"
121
+ className={cn(
122
+ 'relative z-[1] inline-grid w-fit grid-flow-col auto-cols-fr items-center rounded-2xl',
123
+ className,
124
+ )}
125
+ {...props}
126
+ >
127
+ {children}
128
+ </div>
129
+ </div>
130
+ )
131
+ }
132
+
133
+ type TabsTriggerProps = ComponentPropsWithoutRef<'button'> & {
134
+ value: string
135
+ }
136
+
137
+ /** A tab button. Its `role`, `aria-selected` and `data-state` are reactive. */
138
+ export function TabsTrigger({
139
+ value,
140
+ className,
141
+ onClick,
142
+ children,
143
+ ...props
144
+ }: TabsTriggerProps) {
145
+ const { value: activeValue, setValue } = useTabs()
146
+ const activeState = useCompute<[StateId<string>], 'active' | 'inactive'>(
147
+ [activeValue],
148
+ ([current]) => (current === value ? 'active' : 'inactive'),
149
+ )
150
+ const [active] = useMatch(activeState, TAB_STATES)
151
+ const role = useState<HTMLButtonElement['role']>('tab')
152
+ const bind = useAttributes<HTMLButtonElement>({
153
+ role,
154
+ 'aria-selected': active,
155
+ 'data-state': activeState,
156
+ })
157
+
158
+ return (
159
+ <button
160
+ ref={bind}
161
+ type="button"
162
+ data-slot="tabs-trigger"
163
+ onClick={(event) => {
164
+ onClick?.(event)
165
+ setValue(value)
166
+ }}
167
+ className={cn(
168
+ 'relative z-[1] inline-flex h-9 w-full items-center justify-center gap-2 rounded-2xl px-3 text-sm font-medium whitespace-nowrap text-ink-soft motion-color outline-none hover:text-ink focus-visible:ring-2 focus-visible:ring-brand-500 data-[state=active]:text-ink [&_svg]:size-4 [&_svg]:shrink-0',
169
+ className,
170
+ )}
171
+ {...props}
172
+ >
173
+ {children}
174
+ </button>
175
+ )
176
+ }
177
+
178
+ /** Optional wrapper for a group of panels. */
179
+ export function TabsContents({
180
+ className,
181
+ children,
182
+ ...props
183
+ }: ComponentPropsWithoutRef<'div'>) {
184
+ return (
185
+ <div data-slot="tabs-contents" className={className} {...props}>
186
+ {children}
187
+ </div>
188
+ )
189
+ }
190
+
191
+ type TabsContentProps = ComponentPropsWithoutRef<'div'> & {
192
+ value: string
193
+ }
194
+
195
+ /** Panel shown only while its value is active. */
196
+ export function TabsContent({
197
+ value,
198
+ className,
199
+ children,
200
+ ...props
201
+ }: TabsContentProps) {
202
+ const { value: activeValue } = useTabs()
203
+ const panelState = useCompute<[StateId<string>], 'visible' | 'hidden'>(
204
+ [activeValue],
205
+ ([current]) => (current === value ? 'visible' : 'hidden'),
206
+ )
207
+ const [visible] = useMatch(panelState, PANEL_STATES)
208
+ const role = useState<HTMLDivElement['role']>('tabpanel')
209
+ const bind = useAttributes<HTMLDivElement>({
210
+ role,
211
+ 'data-state': panelState,
212
+ })
213
+
214
+ return (
215
+ <Show when={visible}>
216
+ <div
217
+ ref={bind}
218
+ data-slot="tabs-content"
219
+ className={cn('surface-enter flex flex-col gap-6 outline-none', className)}
220
+ {...props}
221
+ >
222
+ {children}
223
+ </div>
224
+ </Show>
225
+ )
226
+ }
@@ -0,0 +1,32 @@
1
+ {
2
+ "name": "tabs",
3
+ "kind": "component",
4
+ "framework": "react",
5
+ "description": "Native React tabs with reactive active states and a static pill highlight.",
6
+ "dependencies": [
7
+ "cn",
8
+ "styles-motion"
9
+ ],
10
+ "peers": [
11
+ "@blankways/state",
12
+ "@blankways/state-react@0.1.0-alpha.1",
13
+ "react"
14
+ ],
15
+ "suggestions": [
16
+ "styles-tokens",
17
+ "styles-base",
18
+ "styles-components",
19
+ "styles-utilities",
20
+ "styles-motion"
21
+ ],
22
+ "files": [
23
+ {
24
+ "source": "Tabs.tsx",
25
+ "target": "components/tabs/Tabs.tsx"
26
+ },
27
+ {
28
+ "source": "index.ts",
29
+ "target": "components/tabs/index.ts"
30
+ }
31
+ ]
32
+ }
@@ -0,0 +1 @@
1
+ export * from './Tabs.js'
@@ -0,0 +1,94 @@
1
+ import { forwardRef, useCallback, useEffect, useMemo, useRef } from 'react'
2
+ import type { ChangeEvent, ComponentPropsWithoutRef } from 'react'
3
+ import { State, type StateId } from '@blankways/state'
4
+ import { useAttributes, useState, type ReactiveAttributes } from '@blankways/state-react'
5
+ import { cn } from '../../internals/cn.js'
6
+ import {
7
+ fieldBase,
8
+ fieldErrorClasses,
9
+ fieldShapeClasses,
10
+ fieldToneClasses,
11
+ type FieldShape,
12
+ type FieldTone,
13
+ } from '../../styles/field-styles.js'
14
+
15
+ export type TextareaProps = Omit<ComponentPropsWithoutRef<'textarea'>, 'value'> & {
16
+ value?: string | StateId<string>
17
+ invalid?: boolean | StateId<boolean>
18
+ shape?: FieldShape
19
+ tone?: FieldTone
20
+ }
21
+
22
+ /** Resizable text area with shared field styles and optional state-bound value. */
23
+ export const Textarea = forwardRef<HTMLTextAreaElement, TextareaProps>(function Textarea(
24
+ {
25
+ className,
26
+ tone = 'default',
27
+ shape = 'rounded',
28
+ invalid = false,
29
+ value,
30
+ onChange,
31
+ ...rest
32
+ },
33
+ forwardedRef,
34
+ ) {
35
+ const valueState = useState<string>(typeof value === 'number' ? State.get(value) : value ?? '')
36
+ const invalidState = useState<boolean>(
37
+ typeof invalid === 'number' ? State.get(invalid) : invalid,
38
+ )
39
+
40
+ useEffect(() => {
41
+ if (typeof value === 'string') State.set(valueState, value)
42
+ }, [value, valueState])
43
+
44
+ useEffect(() => {
45
+ if (typeof invalid === 'boolean') State.set(invalidState, invalid)
46
+ }, [invalid, invalidState])
47
+
48
+ const ref = useRef<HTMLTextAreaElement | null>(null)
49
+ const attributes = useMemo<ReactiveAttributes<HTMLTextAreaElement>>(
50
+ () => ({
51
+ ...(value !== undefined ? { value: valueState } : {}),
52
+ ...(typeof invalid === 'number'
53
+ ? { 'aria-invalid': invalidState, 'data-invalid': invalidState }
54
+ : {}),
55
+ }),
56
+ [value, invalid, valueState, invalidState],
57
+ )
58
+ useAttributes(ref, attributes)
59
+
60
+ const setRef = useCallback(
61
+ (element: HTMLTextAreaElement | null) => {
62
+ ref.current = element
63
+ if (typeof forwardedRef === 'function') forwardedRef(element)
64
+ else if (forwardedRef) {
65
+ ;(forwardedRef as { current: HTMLTextAreaElement | null }).current = element
66
+ }
67
+ },
68
+ [forwardedRef],
69
+ )
70
+
71
+ const handleChange = (event: ChangeEvent<HTMLTextAreaElement>) => {
72
+ if (typeof value === 'number') State.set(valueState, event.currentTarget.value)
73
+ onChange?.(event)
74
+ }
75
+
76
+ return (
77
+ <textarea
78
+ {...rest}
79
+ ref={setRef}
80
+ value={typeof value === 'string' ? value : undefined}
81
+ onChange={handleChange}
82
+ aria-invalid={typeof invalid === 'boolean' ? invalid || undefined : undefined}
83
+ className={cn(
84
+ fieldBase,
85
+ fieldShapeClasses[shape],
86
+ fieldToneClasses[tone],
87
+ 'resize-y',
88
+ typeof invalid === 'boolean' && invalid && fieldErrorClasses,
89
+ 'data-[invalid=true]:border-brand-500 aria-[invalid=true]:ring-2 aria-[invalid=true]:ring-brand-500/30',
90
+ className,
91
+ )}
92
+ />
93
+ )
94
+ })
@@ -0,0 +1,33 @@
1
+ {
2
+ "name": "textarea",
3
+ "kind": "component",
4
+ "framework": "react",
5
+ "description": "Resizable textarea with shared field styles and state-bound value and invalid flags.",
6
+ "dependencies": [
7
+ "cn",
8
+ "field-styles",
9
+ "styles-motion"
10
+ ],
11
+ "peers": [
12
+ "@blankways/state",
13
+ "@blankways/state-react@0.1.0-alpha.1",
14
+ "react"
15
+ ],
16
+ "suggestions": [
17
+ "styles-tokens",
18
+ "styles-base",
19
+ "styles-components",
20
+ "styles-utilities",
21
+ "styles-motion"
22
+ ],
23
+ "files": [
24
+ {
25
+ "source": "Textarea.tsx",
26
+ "target": "components/textarea/Textarea.tsx"
27
+ },
28
+ {
29
+ "source": "index.ts",
30
+ "target": "components/textarea/index.ts"
31
+ }
32
+ ]
33
+ }
@@ -0,0 +1 @@
1
+ export { Textarea, type TextareaProps } from './Textarea.js'
@@ -0,0 +1,17 @@
1
+ {
2
+ "name": "theme-core",
3
+ "kind": "theme",
4
+ "framework": "react",
5
+ "description": "SSR-safe theme types, storage key and resolution helpers.",
6
+ "dependencies": [],
7
+ "peers": [
8
+ "react"
9
+ ],
10
+ "suggestions": [],
11
+ "files": [
12
+ {
13
+ "source": "theme.ts",
14
+ "target": "themes/theme.ts"
15
+ }
16
+ ]
17
+ }
@@ -0,0 +1,84 @@
1
+ /** A theme is an open string; apps can register as many names as they need. */
2
+ export type Theme = string
3
+
4
+ /** `system` is a preference that resolves to one of the concrete themes. */
5
+ export type ThemePreference = Theme | 'system'
6
+
7
+ export const THEME_STORAGE_KEY = 'blankways.theme'
8
+
9
+ export const LIGHT_THEME: Theme = 'light'
10
+ export const DARK_THEME: Theme = 'dark'
11
+ export const SYSTEM_PREFERENCE: ThemePreference = 'system'
12
+
13
+ /** Themes available without any extra configuration. */
14
+ export const DEFAULT_THEMES = [LIGHT_THEME, DARK_THEME] as const
15
+
16
+ export type SystemThemes = {
17
+ light: Theme
18
+ dark: Theme
19
+ }
20
+
21
+ /** Maps the OS preference to two ordinary registered themes. */
22
+ export function systemTheme(
23
+ themes: SystemThemes = { light: LIGHT_THEME, dark: DARK_THEME }
24
+ ): Theme {
25
+ if (typeof window === 'undefined' || typeof window.matchMedia !== 'function') {
26
+ return themes.light
27
+ }
28
+
29
+ return window.matchMedia('(prefers-color-scheme: dark)').matches
30
+ ? themes.dark
31
+ : themes.light
32
+ }
33
+
34
+ export function isSystemPreference(value: unknown): value is 'system' {
35
+ return value === SYSTEM_PREFERENCE
36
+ }
37
+
38
+ export function isTheme(value: unknown): value is Theme {
39
+ return typeof value === 'string' && value.trim().length > 0
40
+ }
41
+
42
+ /** Returns the saved choice, or `system` when none is stored. */
43
+ export function getStoredPreference(
44
+ storageKey: string = THEME_STORAGE_KEY
45
+ ): ThemePreference {
46
+ if (typeof window === 'undefined') return SYSTEM_PREFERENCE
47
+
48
+ try {
49
+ const stored = window.localStorage.getItem(storageKey)
50
+ if (isTheme(stored)) return stored
51
+ } catch {
52
+ /* storage unavailable: follow the system */
53
+ }
54
+
55
+ return SYSTEM_PREFERENCE
56
+ }
57
+
58
+ /** Turns a preference into the concrete theme that should be applied. */
59
+ export function resolveTheme(
60
+ preference: ThemePreference,
61
+ currentSystem: Theme = systemTheme(),
62
+ fallback: Theme = LIGHT_THEME
63
+ ): Theme {
64
+ if (isSystemPreference(preference)) return currentSystem || fallback
65
+ return isTheme(preference) ? preference : fallback
66
+ }
67
+
68
+ /** Convenience helper for the initial resolved theme. */
69
+ export function getInitialTheme(
70
+ storageKey: string = THEME_STORAGE_KEY,
71
+ fallback: Theme = LIGHT_THEME
72
+ ): Theme {
73
+ return resolveTheme(getStoredPreference(storageKey), systemTheme(), fallback)
74
+ }
75
+
76
+ /** Keeps a stored value only when it belongs to the app's theme list. */
77
+ export function normalizePreference(
78
+ preference: ThemePreference,
79
+ themes: readonly Theme[],
80
+ fallback: Theme
81
+ ): ThemePreference {
82
+ const resolved = resolveTheme(preference, systemTheme(), fallback)
83
+ return themes.includes(resolved) ? preference : fallback
84
+ }
@@ -0,0 +1,19 @@
1
+ {
2
+ "name": "theme-dark",
3
+ "kind": "theme",
4
+ "framework": "react",
5
+ "description": "Dark theme constant and preference value.",
6
+ "dependencies": [
7
+ "theme-core"
8
+ ],
9
+ "peers": [
10
+ "react"
11
+ ],
12
+ "suggestions": [],
13
+ "files": [
14
+ {
15
+ "source": "index.ts",
16
+ "target": "themes/dark.ts"
17
+ }
18
+ ]
19
+ }
@@ -0,0 +1,7 @@
1
+ import type { Theme, ThemePreference } from './theme.js'
2
+
3
+ /** Fixed dark theme. */
4
+ export const DARK_THEME: Theme = 'dark'
5
+
6
+ /** Preference that always resolves to the dark theme. */
7
+ export const darkPreference: ThemePreference = 'dark'
@@ -0,0 +1,19 @@
1
+ {
2
+ "name": "theme-light",
3
+ "kind": "theme",
4
+ "framework": "react",
5
+ "description": "Light theme constant and preference value.",
6
+ "dependencies": [
7
+ "theme-core"
8
+ ],
9
+ "peers": [
10
+ "react"
11
+ ],
12
+ "suggestions": [],
13
+ "files": [
14
+ {
15
+ "source": "index.ts",
16
+ "target": "themes/light.ts"
17
+ }
18
+ ]
19
+ }
@@ -0,0 +1,7 @@
1
+ import type { Theme, ThemePreference } from './theme.js'
2
+
3
+ /** Fixed light theme. */
4
+ export const LIGHT_THEME: Theme = 'light'
5
+
6
+ /** Preference that always resolves to the light theme. */
7
+ export const lightPreference: ThemePreference = 'light'