@blankways/ui 0.1.0-alpha.1 → 0.2.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 (185) hide show
  1. package/README.md +157 -139
  2. package/dist/cli/cli.options.js +21 -1
  3. package/dist/cli/cli.types.d.ts +1 -0
  4. package/dist/cli.js +2 -1
  5. package/dist/commands/add.command.d.ts +2 -0
  6. package/dist/commands/add.command.js +30 -82
  7. package/dist/commands/dev.command.d.ts +3 -0
  8. package/dist/commands/dev.command.js +76 -0
  9. package/dist/commands/doctor.command.js +12 -1
  10. package/dist/commands/index.d.ts +3 -0
  11. package/dist/commands/index.js +3 -0
  12. package/dist/commands/init.command.js +15 -10
  13. package/dist/commands/install.command.d.ts +2 -0
  14. package/dist/commands/install.command.js +36 -0
  15. package/dist/commands/list.command.js +10 -5
  16. package/dist/commands/registry.command.d.ts +2 -0
  17. package/dist/commands/registry.command.js +69 -0
  18. package/dist/commands/styles.command.d.ts +1 -2
  19. package/dist/commands/styles.command.js +15 -39
  20. package/dist/config/config.helpers.d.ts +4 -1
  21. package/dist/config/config.helpers.js +61 -8
  22. package/dist/constants/cli.constants.d.ts +14 -3
  23. package/dist/constants/cli.constants.js +14 -9
  24. package/dist/doctor/checks/barrels.check.d.ts +1 -0
  25. package/dist/doctor/checks/barrels.check.js +60 -0
  26. package/dist/doctor/checks/contracts.check.d.ts +1 -0
  27. package/dist/doctor/checks/contracts.check.js +45 -0
  28. package/dist/doctor/checks/icons.check.js +8 -3
  29. package/dist/doctor/checks/index.d.ts +3 -0
  30. package/dist/doctor/checks/index.js +3 -0
  31. package/dist/doctor/checks/motion.check.js +2 -2
  32. package/dist/doctor/checks/namespaces.check.d.ts +1 -0
  33. package/dist/doctor/checks/namespaces.check.js +76 -0
  34. package/dist/doctor/checks/themes.check.js +18 -40
  35. package/dist/doctor/doctor.helpers.js +5 -1
  36. package/dist/doctor/doctor.types.d.ts +4 -0
  37. package/dist/helpers/args.helpers.d.ts +2 -0
  38. package/dist/helpers/args.helpers.js +9 -0
  39. package/dist/helpers/barrels.helpers.d.ts +15 -0
  40. package/dist/helpers/barrels.helpers.js +157 -0
  41. package/dist/index.d.ts +12 -9
  42. package/dist/index.js +11 -9
  43. package/dist/registry/index.d.ts +2 -0
  44. package/dist/registry/index.js +2 -0
  45. package/dist/registry/lockfile.d.ts +18 -0
  46. package/dist/registry/lockfile.js +32 -0
  47. package/dist/registry/registry.helpers.d.ts +3 -13
  48. package/dist/registry/registry.helpers.js +30 -116
  49. package/dist/registry/registry.providers.d.ts +13 -0
  50. package/dist/registry/registry.providers.js +159 -0
  51. package/dist/registry/registry.service.d.ts +14 -0
  52. package/dist/registry/registry.service.js +126 -0
  53. package/dist/types/config.types.d.ts +29 -0
  54. package/dist/types/registry.types.d.ts +31 -0
  55. package/dist/types/registry.types.js +2 -0
  56. package/dist/ui-api/index.d.ts +16 -0
  57. package/dist/ui-api/index.js +30 -0
  58. package/dist/ui-api/ui-api.d.ts +18 -0
  59. package/dist/ui-api/ui-api.js +194 -0
  60. package/package.json +7 -5
  61. package/styles.css +16 -0
  62. package/dist/registry-data/README.md +0 -71
  63. package/dist/registry-data/avatar/Avatar.tsx +0 -64
  64. package/dist/registry-data/avatar/component.json +0 -30
  65. package/dist/registry-data/avatar/index.ts +0 -1
  66. package/dist/registry-data/badge/Badge.tsx +0 -76
  67. package/dist/registry-data/badge/component.json +0 -30
  68. package/dist/registry-data/badge/index.ts +0 -1
  69. package/dist/registry-data/brand-logo/BrandLogo.tsx +0 -24
  70. package/dist/registry-data/brand-logo/component.json +0 -26
  71. package/dist/registry-data/brand-logo/index.ts +0 -1
  72. package/dist/registry-data/button/Button.tsx +0 -76
  73. package/dist/registry-data/button/component.json +0 -33
  74. package/dist/registry-data/button/index.ts +0 -1
  75. package/dist/registry-data/button-link/ButtonLink.tsx +0 -83
  76. package/dist/registry-data/button-link/component.json +0 -33
  77. package/dist/registry-data/button-link/index.ts +0 -5
  78. package/dist/registry-data/button-styles/component.json +0 -19
  79. package/dist/registry-data/button-styles/index.ts +0 -45
  80. package/dist/registry-data/cn/cn.ts +0 -6
  81. package/dist/registry-data/cn/component.json +0 -16
  82. package/dist/registry-data/confirm-dialog/ConfirmDialog.tsx +0 -134
  83. package/dist/registry-data/confirm-dialog/component.json +0 -34
  84. package/dist/registry-data/confirm-dialog/index.ts +0 -1
  85. package/dist/registry-data/container/Container.tsx +0 -22
  86. package/dist/registry-data/container/component.json +0 -28
  87. package/dist/registry-data/container/index.ts +0 -1
  88. package/dist/registry-data/cursor-glow/CursorGlow.tsx +0 -29
  89. package/dist/registry-data/cursor-glow/component.json +0 -28
  90. package/dist/registry-data/cursor-glow/index.ts +0 -1
  91. package/dist/registry-data/dropdown-menu/DropdownMenu.tsx +0 -157
  92. package/dist/registry-data/dropdown-menu/component.json +0 -34
  93. package/dist/registry-data/dropdown-menu/index.ts +0 -5
  94. package/dist/registry-data/empty-state/EmptyState.tsx +0 -92
  95. package/dist/registry-data/empty-state/component.json +0 -30
  96. package/dist/registry-data/empty-state/index.ts +0 -5
  97. package/dist/registry-data/eyebrow/Eyebrow.tsx +0 -68
  98. package/dist/registry-data/eyebrow/component.json +0 -30
  99. package/dist/registry-data/eyebrow/index.ts +0 -1
  100. package/dist/registry-data/field-styles/component.json +0 -19
  101. package/dist/registry-data/field-styles/index.ts +0 -42
  102. package/dist/registry-data/form-dialog/FormDialog.tsx +0 -128
  103. package/dist/registry-data/form-dialog/component.json +0 -34
  104. package/dist/registry-data/form-dialog/index.ts +0 -1
  105. package/dist/registry-data/icons/component.json +0 -22
  106. package/dist/registry-data/icons/index.ts +0 -21
  107. package/dist/registry-data/icons-form/component.json +0 -17
  108. package/dist/registry-data/icons-form/index.ts +0 -1
  109. package/dist/registry-data/icons-sidebar/component.json +0 -17
  110. package/dist/registry-data/icons-sidebar/index.ts +0 -1
  111. package/dist/registry-data/icons-theme/component.json +0 -17
  112. package/dist/registry-data/icons-theme/index.ts +0 -1
  113. package/dist/registry-data/icons-toast/component.json +0 -17
  114. package/dist/registry-data/icons-toast/index.ts +0 -1
  115. package/dist/registry-data/info-dialog/InfoDialog.tsx +0 -119
  116. package/dist/registry-data/info-dialog/component.json +0 -36
  117. package/dist/registry-data/info-dialog/index.ts +0 -1
  118. package/dist/registry-data/input/Input.tsx +0 -96
  119. package/dist/registry-data/input/component.json +0 -33
  120. package/dist/registry-data/input/index.ts +0 -1
  121. package/dist/registry-data/multi-combobox/MultiCombobox.tsx +0 -205
  122. package/dist/registry-data/multi-combobox/component.json +0 -35
  123. package/dist/registry-data/multi-combobox/index.ts +0 -5
  124. package/dist/registry-data/remote-provider/RemoteProvider.tsx +0 -8
  125. package/dist/registry-data/remote-provider/component.json +0 -25
  126. package/dist/registry-data/remote-provider/index.ts +0 -3
  127. package/dist/registry-data/reveal/Reveal.tsx +0 -22
  128. package/dist/registry-data/reveal/component.json +0 -30
  129. package/dist/registry-data/reveal/index.ts +0 -1
  130. package/dist/registry-data/section/Section.tsx +0 -80
  131. package/dist/registry-data/section/component.json +0 -30
  132. package/dist/registry-data/section/index.ts +0 -1
  133. package/dist/registry-data/section-heading/SectionHeading.tsx +0 -105
  134. package/dist/registry-data/section-heading/component.json +0 -32
  135. package/dist/registry-data/section-heading/index.ts +0 -1
  136. package/dist/registry-data/select/Select.tsx +0 -197
  137. package/dist/registry-data/select/component.json +0 -34
  138. package/dist/registry-data/select/index.ts +0 -1
  139. package/dist/registry-data/sidebar/Sidebar.tsx +0 -432
  140. package/dist/registry-data/sidebar/SidebarCollapsible.tsx +0 -77
  141. package/dist/registry-data/sidebar/SidebarParts.tsx +0 -373
  142. package/dist/registry-data/sidebar/component.json +0 -47
  143. package/dist/registry-data/sidebar/index.ts +0 -4
  144. package/dist/registry-data/sidebar/useSidebar.ts +0 -29
  145. package/dist/registry-data/styles-base/component.json +0 -19
  146. package/dist/registry-data/styles-base/index.css +0 -67
  147. package/dist/registry-data/styles-components/component.json +0 -19
  148. package/dist/registry-data/styles-components/index.css +0 -30
  149. package/dist/registry-data/styles-motion/component.json +0 -20
  150. package/dist/registry-data/styles-motion/index.css +0 -381
  151. package/dist/registry-data/styles-tokens/component.json +0 -17
  152. package/dist/registry-data/styles-tokens/index.css +0 -77
  153. package/dist/registry-data/styles-utilities/component.json +0 -19
  154. package/dist/registry-data/styles-utilities/index.css +0 -29
  155. package/dist/registry-data/switch/Switch.tsx +0 -91
  156. package/dist/registry-data/switch/component.json +0 -34
  157. package/dist/registry-data/switch/index.ts +0 -1
  158. package/dist/registry-data/tabs/Tabs.tsx +0 -226
  159. package/dist/registry-data/tabs/component.json +0 -32
  160. package/dist/registry-data/tabs/index.ts +0 -1
  161. package/dist/registry-data/textarea/Textarea.tsx +0 -94
  162. package/dist/registry-data/textarea/component.json +0 -33
  163. package/dist/registry-data/textarea/index.ts +0 -1
  164. package/dist/registry-data/theme-core/component.json +0 -17
  165. package/dist/registry-data/theme-core/theme.ts +0 -84
  166. package/dist/registry-data/theme-dark/component.json +0 -19
  167. package/dist/registry-data/theme-dark/index.ts +0 -7
  168. package/dist/registry-data/theme-light/component.json +0 -19
  169. package/dist/registry-data/theme-light/index.ts +0 -7
  170. package/dist/registry-data/theme-provider/ThemeContext.tsx +0 -177
  171. package/dist/registry-data/theme-provider/component.json +0 -30
  172. package/dist/registry-data/theme-provider/index.ts +0 -2
  173. package/dist/registry-data/theme-selector/ThemeSelector.tsx +0 -269
  174. package/dist/registry-data/theme-selector/component.json +0 -35
  175. package/dist/registry-data/theme-selector/selector.ts +0 -1
  176. package/dist/registry-data/theme-system/component.json +0 -19
  177. package/dist/registry-data/theme-system/index.ts +0 -7
  178. package/dist/registry-data/theme-toggle/ThemeToggle.tsx +0 -71
  179. package/dist/registry-data/theme-toggle/component.json +0 -31
  180. package/dist/registry-data/theme-toggle/toggle.ts +0 -1
  181. package/dist/registry-data/toast/Toast.tsx +0 -260
  182. package/dist/registry-data/toast/ToastTypeIcon.tsx +0 -83
  183. package/dist/registry-data/toast/component.json +0 -43
  184. package/dist/registry-data/toast/index.ts +0 -3
  185. package/dist/registry-data/toast/useToast.ts +0 -47
@@ -1,3 +0,0 @@
1
- export { RemoteProvider } from './RemoteProvider.js'
2
- export type { RemoteProviderProps } from './RemoteProvider.js'
3
- export { useCall } from '@blankways/remote-react'
@@ -1,22 +0,0 @@
1
- import type { CSSProperties, ReactNode } from 'react'
2
- import { cn } from '../../internals/cn.js'
3
-
4
- export type RevealProps = {
5
- children: ReactNode
6
- className?: string
7
- /** Animation delay in milliseconds. */
8
- delay?: number
9
- }
10
-
11
- /** CSS scroll-driven reveal; visibility is left to the consumer. */
12
- export function Reveal({ children, className, delay = 0 }: RevealProps) {
13
- const style: CSSProperties | undefined = delay
14
- ? { '--delay': `${delay}ms` } as CSSProperties
15
- : undefined
16
-
17
- return (
18
- <div data-reveal className={cn('reveal-up', className)} style={style}>
19
- {children}
20
- </div>
21
- )
22
- }
@@ -1,30 +0,0 @@
1
- {
2
- "name": "reveal",
3
- "kind": "component",
4
- "framework": "react",
5
- "description": "Static fade/slide transition wrapper with an optional delay.",
6
- "dependencies": [
7
- "cn",
8
- "styles-motion"
9
- ],
10
- "peers": [
11
- "react"
12
- ],
13
- "suggestions": [
14
- "styles-tokens",
15
- "styles-base",
16
- "styles-components",
17
- "styles-utilities",
18
- "styles-motion"
19
- ],
20
- "files": [
21
- {
22
- "source": "Reveal.tsx",
23
- "target": "components/reveal/Reveal.tsx"
24
- },
25
- {
26
- "source": "index.ts",
27
- "target": "components/reveal/index.ts"
28
- }
29
- ]
30
- }
@@ -1 +0,0 @@
1
- export { Reveal, type RevealProps } from './Reveal.js'
@@ -1,80 +0,0 @@
1
- import { useEffect, useMemo, useRef } from 'react'
2
- import type { ReactNode } from 'react'
3
- import { State, type StateId } from '@blankways/state'
4
- import {
5
- useAttributes,
6
- useMatch,
7
- useState,
8
- type ReactiveAttributes,
9
- } from '@blankways/state-react'
10
- import { cn } from '../../internals/cn.js'
11
-
12
- const TONE_CASES = ['paper', 'surface', 'ink', 'contrast'] as const
13
-
14
- export type SectionTone = (typeof TONE_CASES)[number]
15
-
16
- export type SectionProps = {
17
- id?: string
18
- children?: ReactNode
19
- className?: string
20
- tone?: SectionTone
21
- padding?: boolean
22
- /** Alias of `padding`, kept for parity with the original API. */
23
- padded?: boolean
24
- }
25
-
26
- const toneClasses: Record<SectionTone, string> = {
27
- paper: 'bg-paper text-ink',
28
- surface: 'bg-surface text-ink',
29
- ink: 'bg-contrast text-on-contrast',
30
- contrast: 'bg-accent text-on-contrast',
31
- }
32
-
33
- function useSyncedState<Type>(value: Type): StateId<Type> {
34
- const state = useState(value)
35
- useEffect(() => {
36
- if (!Object.is(State.get(state), value)) State.set(state, value)
37
- }, [state, value])
38
- return state
39
- }
40
-
41
- /** Page section with a reactive tone marker and optional standard padding. */
42
- export function Section({
43
- id,
44
- children,
45
- className,
46
- tone = 'paper',
47
- padding,
48
- padded,
49
- }: SectionProps) {
50
- const toneState = useSyncedState(tone)
51
- const [isPaper, isSurface, isInk, isContrast] = useMatch(toneState, TONE_CASES)
52
- const ref = useRef<HTMLElement | null>(null)
53
- const attributes = useMemo<ReactiveAttributes<HTMLElement>>(
54
- () => ({
55
- 'data-tone': toneState,
56
- 'data-tone-paper': isPaper,
57
- 'data-tone-surface': isSurface,
58
- 'data-tone-ink': isInk,
59
- 'data-tone-contrast': isContrast,
60
- }),
61
- [toneState, isPaper, isSurface, isInk, isContrast],
62
- )
63
- useAttributes(ref, attributes)
64
- const withPadding = padding ?? padded ?? true
65
-
66
- return (
67
- <section
68
- id={id}
69
- ref={ref}
70
- className={cn(
71
- 'relative w-full',
72
- toneClasses[tone],
73
- withPadding && 'section-padding',
74
- className,
75
- )}
76
- >
77
- {children}
78
- </section>
79
- )
80
- }
@@ -1,30 +0,0 @@
1
- {
2
- "name": "section",
3
- "kind": "component",
4
- "framework": "react",
5
- "description": "Page section with tone variants, reactive tone markers and padding toggle.",
6
- "dependencies": [
7
- "cn"
8
- ],
9
- "peers": [
10
- "@blankways/state",
11
- "@blankways/state-react@0.1.0-alpha.1",
12
- "react"
13
- ],
14
- "suggestions": [
15
- "styles-tokens",
16
- "styles-base",
17
- "styles-components",
18
- "styles-utilities"
19
- ],
20
- "files": [
21
- {
22
- "source": "Section.tsx",
23
- "target": "components/section/Section.tsx"
24
- },
25
- {
26
- "source": "index.ts",
27
- "target": "components/section/index.ts"
28
- }
29
- ]
30
- }
@@ -1 +0,0 @@
1
- export { Section, type SectionProps, type SectionTone } from './Section.js'
@@ -1,105 +0,0 @@
1
- import { useEffect, type CSSProperties } from 'react'
2
- import { State, type StateId } from '@blankways/state'
3
- import { Show, Text, useState } from '@blankways/state-react'
4
- import { cn } from '../../internals/cn.js'
5
-
6
- export type SectionHeadingProps = {
7
- eyebrow?: string | StateId<string>
8
- title: string | StateId<string>
9
- description?: string | StateId<string>
10
- align?: 'left' | 'center'
11
- tone?: 'light' | 'dark'
12
- className?: string
13
- titleClassName?: string
14
- }
15
-
16
- function useSyncedState<Type>(value: Type) {
17
- const state = useState(value)
18
- useEffect(() => {
19
- if (!Object.is(State.get(state), value)) State.set(state, value)
20
- }, [state, value])
21
- return state
22
- }
23
-
24
- function TextOrNode({ value }: { value: string | StateId<string> }) {
25
- return typeof value === 'number' ? <Text as="span" value={value} /> : <>{value}</>
26
- }
27
-
28
- function StaggerText({ value }: { value: string | StateId<string> }) {
29
- if (typeof value === 'number') return <Text as="span" value={value} />
30
-
31
- return (
32
- <>
33
- {value.split(' ').map((word, index) => (
34
- <span
35
- key={`${word}-${index}`}
36
- className="stagger-word"
37
- style={{ '--index': index } as CSSProperties}
38
- >
39
- {word}{' '}
40
- </span>
41
- ))}
42
- </>
43
- )
44
- }
45
-
46
- /** Static section heading; text values may be plain strings or text states. */
47
- export function SectionHeading({
48
- eyebrow,
49
- title,
50
- description,
51
- align = 'left',
52
- tone = 'light',
53
- className,
54
- titleClassName,
55
- }: SectionHeadingProps) {
56
- const hasEyebrow = useSyncedState(Boolean(eyebrow))
57
- const hasDescription = useSyncedState(Boolean(description))
58
- const dark = tone === 'dark'
59
-
60
- return (
61
- <div
62
- className={cn(
63
- 'stagger-children flex flex-col gap-4',
64
- align === 'center' && 'items-center text-center',
65
- className,
66
- )}
67
- >
68
- <Show when={hasEyebrow}>
69
- <span
70
- className={cn(
71
- 'inline-flex items-center gap-2 text-xs font-semibold tracking-[0.18em] uppercase',
72
- dark ? 'text-on-contrast/60' : 'text-ink-muted',
73
- )}
74
- style={{ '--index': 0 } as CSSProperties}
75
- >
76
- <span className="size-1.5 rounded-full bg-brand-500" aria-hidden="true" />
77
- <TextOrNode value={eyebrow ?? ''} />
78
- </span>
79
- </Show>
80
-
81
- <h2
82
- className={cn(
83
- 'stagger-words max-w-3xl text-3xl leading-[1.05] font-semibold tracking-[-0.03em] sm:text-4xl lg:text-5xl',
84
- dark ? 'text-on-contrast' : 'text-ink',
85
- titleClassName,
86
- )}
87
- style={{ '--index': 1 } as CSSProperties}
88
- >
89
- <StaggerText value={title} />
90
- </h2>
91
-
92
- <Show when={hasDescription}>
93
- <p
94
- className={cn(
95
- 'max-w-2xl text-base leading-relaxed sm:text-lg',
96
- dark ? 'text-on-contrast/70' : 'text-ink-soft',
97
- )}
98
- style={{ '--index': 2 } as CSSProperties}
99
- >
100
- <TextOrNode value={description ?? ''} />
101
- </p>
102
- </Show>
103
- </div>
104
- )
105
- }
@@ -1,32 +0,0 @@
1
- {
2
- "name": "section-heading",
3
- "kind": "component",
4
- "framework": "react",
5
- "description": "Static heading block with optional eyebrow, description and reactive text.",
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": "SectionHeading.tsx",
25
- "target": "components/section-heading/SectionHeading.tsx"
26
- },
27
- {
28
- "source": "index.ts",
29
- "target": "components/section-heading/index.ts"
30
- }
31
- ]
32
- }
@@ -1 +0,0 @@
1
- export { SectionHeading, type SectionHeadingProps } from './SectionHeading.js'
@@ -1,197 +0,0 @@
1
- import { useEffect, useMemo, useRef } from 'react'
2
- import { useState as useReactState } from 'react'
3
- import type { CSSProperties, KeyboardEvent } from 'react'
4
- import { State } from '@blankways/state'
5
- import {
6
- Show,
7
- Text,
8
- useAttributes,
9
- useCompute,
10
- useMatch,
11
- useState,
12
- type ReactiveAttributes,
13
- } from '@blankways/state-react'
14
- import { cn } from '../../internals/cn.js'
15
- import { Check, ChevronDown } from '../../icons/form.js'
16
-
17
- const OPEN_CASES = ['open', 'closed'] as const
18
-
19
- /** A single option of a `Select` or `MultiCombobox`. */
20
- export type SelectOption = { value: string; label: string }
21
-
22
- export type SelectProps = {
23
- options: SelectOption[]
24
- /** The chosen value, or an empty string for none. */
25
- value?: string
26
- onValueChange?: (value: string) => void
27
- placeholder?: string
28
- invalid?: boolean
29
- disabled?: boolean
30
- className?: string
31
- 'aria-label'?: string
32
- }
33
-
34
- /** Custom listbox with keyboard support, built without a headless UI library. */
35
- export function Select({
36
- options,
37
- value = '',
38
- onValueChange,
39
- placeholder = 'Selecciona una opción',
40
- invalid = false,
41
- disabled = false,
42
- className,
43
- 'aria-label': ariaLabel,
44
- }: SelectProps) {
45
- const openState = useState(false)
46
- const activeState = useState(0)
47
- const [open, setOpen] = useReactState(false)
48
- const [activeIndex, setActiveIndex] = useReactState(0)
49
-
50
- const valueState = useState(value)
51
- const optionsState = useState(options)
52
- useEffect(() => {
53
- State.set(valueState, value)
54
- }, [value, valueState])
55
- useEffect(() => {
56
- State.set(optionsState, options)
57
- }, [options, optionsState])
58
-
59
- const selectedLabel = useCompute(
60
- [valueState, optionsState] as const,
61
- ([current, list]) => list.find((option) => option.value === current)?.label ?? placeholder,
62
- )
63
- const stateName = useCompute([openState] as const, ([isOpen]) =>
64
- isOpen ? 'open' : 'closed',
65
- )
66
- const [isOpenCase, isClosedCase] = useMatch(stateName, OPEN_CASES)
67
-
68
- const containerRef = useRef<HTMLDivElement | null>(null)
69
- const buttonRef = useRef<HTMLButtonElement | null>(null)
70
- const attributes = useMemo<ReactiveAttributes<HTMLButtonElement>>(
71
- () => ({
72
- 'aria-expanded': openState,
73
- 'data-state': stateName,
74
- 'data-open': isOpenCase,
75
- 'data-closed': isClosedCase,
76
- }),
77
- [openState, stateName, isOpenCase, isClosedCase],
78
- )
79
- useAttributes(buttonRef, attributes)
80
-
81
- const setActive = (index: number) => {
82
- State.set(activeState, index)
83
- setActiveIndex(index)
84
- }
85
-
86
- const setOpenValue = (next: boolean) => {
87
- State.set(openState, next)
88
- setOpen(next)
89
- if (next) {
90
- const index = options.findIndex((option) => option.value === value)
91
- setActive(index < 0 ? 0 : index)
92
- }
93
- }
94
-
95
- const choose = (next: string) => {
96
- onValueChange?.(next)
97
- setOpenValue(false)
98
- }
99
-
100
- useEffect(() => {
101
- if (!open) return
102
- const onPointerDown = (event: PointerEvent) => {
103
- if (containerRef.current && !containerRef.current.contains(event.target as Node)) {
104
- setOpenValue(false)
105
- }
106
- }
107
- const onEscape = (event: globalThis.KeyboardEvent) => {
108
- if (event.key === 'Escape') setOpenValue(false)
109
- }
110
- document.addEventListener('pointerdown', onPointerDown)
111
- document.addEventListener('keydown', onEscape)
112
- return () => {
113
- document.removeEventListener('pointerdown', onPointerDown)
114
- document.removeEventListener('keydown', onEscape)
115
- }
116
- }, [open])
117
-
118
- const handleKeyDown = (event: KeyboardEvent<HTMLButtonElement>) => {
119
- if (disabled) return
120
- if (event.key === 'ArrowDown') {
121
- event.preventDefault()
122
- if (!open) setOpenValue(true)
123
- else setActive((activeIndex + 1) % Math.max(options.length, 1))
124
- } else if (event.key === 'ArrowUp') {
125
- event.preventDefault()
126
- if (!open) setOpenValue(true)
127
- else setActive((activeIndex - 1 + Math.max(options.length, 1)) % Math.max(options.length, 1))
128
- } else if (event.key === 'Home' && open) {
129
- event.preventDefault()
130
- setActive(0)
131
- } else if (event.key === 'End' && open) {
132
- event.preventDefault()
133
- setActive(Math.max(options.length - 1, 0))
134
- } else if (event.key === 'Enter' || event.key === ' ') {
135
- event.preventDefault()
136
- if (open) {
137
- const option = options[activeIndex]
138
- if (option) choose(option.value)
139
- } else {
140
- setOpenValue(true)
141
- }
142
- }
143
- }
144
-
145
- return (
146
- <div ref={containerRef} className={cn('relative w-full', className)}>
147
- <button
148
- ref={buttonRef}
149
- type="button"
150
- role="combobox"
151
- aria-haspopup="listbox"
152
- aria-label={ariaLabel}
153
- aria-invalid={invalid || undefined}
154
- disabled={disabled}
155
- onClick={() => setOpenValue(!open)}
156
- onKeyDown={handleKeyDown}
157
- className={cn(
158
- 'motion-press flex h-12 w-full items-center justify-between gap-2 rounded-2xl border border-line bg-paper px-3 text-left text-sm text-ink outline-none',
159
- 'hover:border-line-strong focus-visible:border-brand-500 disabled:cursor-not-allowed disabled:opacity-60',
160
- 'data-[state=open]:border-brand-500',
161
- invalid && 'border-brand-500',
162
- )}
163
- >
164
- <Text as="span" value={selectedLabel} className={!value ? 'text-ink-muted' : undefined} />
165
- <ChevronDown className="size-4 shrink-0 text-ink-muted" aria-hidden="true" />
166
- </button>
167
-
168
- <Show when={openState}>
169
- <div
170
- role="listbox"
171
- aria-label={ariaLabel}
172
- data-state="open"
173
- className="popup-enter stagger-children absolute top-full left-0 z-[70] mt-1 max-h-72 w-full overflow-y-auto rounded-2xl border border-line bg-paper p-[0.281rem] text-ink shadow-xl outline-none"
174
- >
175
- {options.map((option, index) => (
176
- <button
177
- key={option.value}
178
- type="button"
179
- role="option"
180
- aria-selected={option.value === value}
181
- data-highlighted={index === activeIndex ? 'true' : undefined}
182
- style={{ '--index': index } as CSSProperties}
183
- onMouseEnter={() => setActive(index)}
184
- onClick={() => choose(option.value)}
185
- className="flex w-full cursor-pointer items-center gap-2.5 rounded-2xl px-[0.5625rem] py-1.5 text-left text-sm text-ink outline-none select-none data-[highlighted]:bg-surface-2"
186
- >
187
- <span className="flex-1">{option.label}</span>
188
- {option.value === value ? (
189
- <Check className="size-4 text-brand-500" aria-hidden="true" />
190
- ) : null}
191
- </button>
192
- ))}
193
- </div>
194
- </Show>
195
- </div>
196
- )
197
- }
@@ -1,34 +0,0 @@
1
- {
2
- "name": "select",
3
- "kind": "component",
4
- "framework": "react",
5
- "description": "Custom keyboard-accessible listbox with reactive open state.",
6
- "dependencies": [
7
- "cn",
8
- "icons-form",
9
- "styles-motion"
10
- ],
11
- "peers": [
12
- "@blankways/state",
13
- "@blankways/state-react@0.1.0-alpha.1",
14
- "react",
15
- "lucide-react"
16
- ],
17
- "suggestions": [
18
- "styles-tokens",
19
- "styles-base",
20
- "styles-components",
21
- "styles-utilities",
22
- "styles-motion"
23
- ],
24
- "files": [
25
- {
26
- "source": "Select.tsx",
27
- "target": "components/select/Select.tsx"
28
- },
29
- {
30
- "source": "index.ts",
31
- "target": "components/select/index.ts"
32
- }
33
- ]
34
- }
@@ -1 +0,0 @@
1
- export { Select, type SelectProps, type SelectOption } from './Select.js'