@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,157 +0,0 @@
1
- import { cloneElement, useEffect, useRef } from 'react'
2
- import { useState as useReactState } from 'react'
3
- import type { CSSProperties, KeyboardEvent, MouseEvent, ReactElement } from 'react'
4
- import { State } from '@blankways/state'
5
- import { Show, useState } from '@blankways/state-react'
6
- import { cn } from '../../internals/cn.js'
7
- import { ChevronRight } from '../../icons/form.js'
8
-
9
- export type DropdownMenuItem = {
10
- label: string
11
- onSelect?: () => void
12
- disabled?: boolean
13
- destructive?: boolean
14
- }
15
-
16
- export type DropdownMenuProps = {
17
- trigger: ReactElement<TriggerProps>
18
- items: DropdownMenuItem[]
19
- align?: 'start' | 'end'
20
- /** Adds a chevron to each row. */
21
- showArrow?: boolean
22
- className?: string
23
- }
24
-
25
- type TriggerProps = {
26
- onClick?: (event: MouseEvent<HTMLElement>) => void
27
- onKeyDown?: (event: KeyboardEvent<HTMLElement>) => void
28
- 'aria-haspopup'?: string
29
- 'aria-expanded'?: boolean
30
- }
31
-
32
- /** Native menu popup with arrow-key and Escape handling; the trigger is cloned. */
33
- export function DropdownMenu({
34
- trigger,
35
- items,
36
- align = 'start',
37
- showArrow = false,
38
- className,
39
- }: DropdownMenuProps) {
40
- const openState = useState(false)
41
- const activeState = useState(0)
42
- const [open, setOpen] = useReactState(false)
43
- const [activeIndex, setActiveIndex] = useReactState(0)
44
- const containerRef = useRef<HTMLDivElement | null>(null)
45
-
46
- const setActive = (index: number) => {
47
- State.set(activeState, index)
48
- setActiveIndex(index)
49
- }
50
-
51
- const setOpenValue = (next: boolean) => {
52
- State.set(openState, next)
53
- setOpen(next)
54
- if (next) setActive(0)
55
- }
56
-
57
- const choose = (index: number) => {
58
- const item = items[index]
59
- if (!item || item.disabled) return
60
- item.onSelect?.()
61
- setOpenValue(false)
62
- }
63
-
64
- useEffect(() => {
65
- if (!open) return
66
- const onPointerDown = (event: PointerEvent) => {
67
- if (containerRef.current && !containerRef.current.contains(event.target as Node)) {
68
- setOpenValue(false)
69
- }
70
- }
71
- const onEscape = (event: globalThis.KeyboardEvent) => {
72
- if (event.key === 'Escape') setOpenValue(false)
73
- }
74
- document.addEventListener('pointerdown', onPointerDown)
75
- document.addEventListener('keydown', onEscape)
76
- return () => {
77
- document.removeEventListener('pointerdown', onPointerDown)
78
- document.removeEventListener('keydown', onEscape)
79
- }
80
- }, [open])
81
-
82
- const handleKeyDown = (event: KeyboardEvent<HTMLElement>) => {
83
- if (event.key === 'ArrowDown') {
84
- event.preventDefault()
85
- if (!open) setOpenValue(true)
86
- else setActive((activeIndex + 1) % Math.max(items.length, 1))
87
- } else if (event.key === 'ArrowUp') {
88
- event.preventDefault()
89
- if (!open) setOpenValue(true)
90
- else setActive((activeIndex - 1 + Math.max(items.length, 1)) % Math.max(items.length, 1))
91
- } else if (event.key === 'Home' && open) {
92
- event.preventDefault()
93
- setActive(0)
94
- } else if (event.key === 'End' && open) {
95
- event.preventDefault()
96
- setActive(Math.max(items.length - 1, 0))
97
- } else if (event.key === 'Enter' && open) {
98
- event.preventDefault()
99
- choose(activeIndex)
100
- } else if (event.key === 'Tab') {
101
- setOpenValue(false)
102
- }
103
- }
104
-
105
- const original = trigger.props as TriggerProps
106
- const triggerNode = cloneElement(trigger, {
107
- 'aria-haspopup': 'menu',
108
- 'aria-expanded': open,
109
- onClick: (event: MouseEvent<HTMLElement>) => {
110
- original.onClick?.(event)
111
- setOpenValue(!State.get(openState))
112
- },
113
- onKeyDown: (event: KeyboardEvent<HTMLElement>) => {
114
- original.onKeyDown?.(event)
115
- handleKeyDown(event)
116
- },
117
- })
118
-
119
- return (
120
- <div ref={containerRef} className={cn('relative inline-flex', className)}>
121
- {triggerNode}
122
- <Show when={openState}>
123
- <div
124
- role="menu"
125
- data-state="open"
126
- className={cn(
127
- 'popup-enter stagger-children absolute top-full z-50 mt-2 min-w-56 rounded-2xl border border-line bg-paper p-[0.281rem] text-ink shadow-xl outline-none',
128
- align === 'end' ? 'right-0' : 'left-0',
129
- )}
130
- >
131
- {items.map((item, index) => (
132
- <button
133
- key={`${item.label}-${index}`}
134
- type="button"
135
- role="menuitem"
136
- disabled={item.disabled}
137
- data-highlighted={index === activeIndex ? 'true' : undefined}
138
- style={{ '--index': index } as CSSProperties}
139
- onMouseEnter={() => setActive(index)}
140
- onClick={() => choose(index)}
141
- className={cn(
142
- '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',
143
- 'data-[highlighted]:bg-surface-2 disabled:cursor-not-allowed disabled:opacity-50',
144
- item.destructive && 'font-semibold text-ink',
145
- )}
146
- >
147
- <span className="flex-1">{item.label}</span>
148
- {showArrow ? (
149
- <ChevronRight className="size-4 shrink-0 text-ink-soft" aria-hidden="true" />
150
- ) : null}
151
- </button>
152
- ))}
153
- </div>
154
- </Show>
155
- </div>
156
- )
157
- }
@@ -1,34 +0,0 @@
1
- {
2
- "name": "dropdown-menu",
3
- "kind": "component",
4
- "framework": "react",
5
- "description": "Native dropdown menu with keyboard navigation and a reactive popup.",
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": "DropdownMenu.tsx",
27
- "target": "components/dropdown-menu/DropdownMenu.tsx"
28
- },
29
- {
30
- "source": "index.ts",
31
- "target": "components/dropdown-menu/index.ts"
32
- }
33
- ]
34
- }
@@ -1,5 +0,0 @@
1
- export {
2
- DropdownMenu,
3
- type DropdownMenuProps,
4
- type DropdownMenuItem,
5
- } from './DropdownMenu.js'
@@ -1,92 +0,0 @@
1
- import { useEffect } from 'react'
2
- import type { ReactNode } from 'react'
3
- import { State, type StateId } from '@blankways/state'
4
- import { Show, Text, useState } from '@blankways/state-react'
5
- import { cn } from '../../internals/cn.js'
6
-
7
- export type EmptyStateTone = 'light' | 'dark'
8
-
9
- export type EmptyStateProps = {
10
- icon?: ReactNode
11
- title: string | StateId<string>
12
- description?: string | StateId<string>
13
- action?: ReactNode
14
- tone?: EmptyStateTone
15
- className?: string
16
- }
17
-
18
- const toneClasses: Record<EmptyStateTone, { panel: string; title: string; body: string; icon: string }> = {
19
- light: {
20
- panel: 'border-line-strong',
21
- title: 'text-ink',
22
- body: 'text-ink-soft',
23
- icon: 'bg-accent-soft text-accent-soft-fg',
24
- },
25
- dark: {
26
- panel: 'border-on-contrast/25 bg-on-contrast/5',
27
- title: 'text-on-contrast',
28
- body: 'text-on-contrast/65',
29
- icon: 'bg-brand-500/15 text-brand-300',
30
- },
31
- }
32
-
33
- function useSyncedState<Type>(value: 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
- function TextOrNode({ value }: { value: string | StateId<string> }) {
42
- return typeof value === 'number' ? <Text as="span" value={value} /> : <>{value}</>
43
- }
44
-
45
- /** Quiet placeholder for areas that will fill up later. */
46
- export function EmptyState({
47
- icon,
48
- title,
49
- description,
50
- action,
51
- tone = 'light',
52
- className,
53
- }: EmptyStateProps) {
54
- const hasDescription = useSyncedState(Boolean(description))
55
- const hasAction = useSyncedState(Boolean(action))
56
- const classes = toneClasses[tone]
57
-
58
- return (
59
- <div
60
- className={cn(
61
- 'flex flex-col items-center rounded-2xl border border-dashed px-[1.125rem] py-[2.625rem] text-center sm:py-[3.75rem]',
62
- classes.panel,
63
- className,
64
- )}
65
- >
66
- {icon ? (
67
- <span className={cn('inline-flex size-12 items-center justify-center rounded-2xl', classes.icon)}>
68
- {icon}
69
- </span>
70
- ) : null}
71
-
72
- <h2
73
- className={cn(
74
- 'mt-5 max-w-lg text-xl leading-tight font-semibold tracking-[-0.02em] sm:text-2xl',
75
- classes.title,
76
- )}
77
- >
78
- <TextOrNode value={title} />
79
- </h2>
80
-
81
- <Show when={hasDescription}>
82
- <p className={cn('mt-2 max-w-md text-sm leading-relaxed sm:text-base', classes.body)}>
83
- <TextOrNode value={description ?? ''} />
84
- </p>
85
- </Show>
86
-
87
- <Show when={hasAction}>
88
- <div className="mt-6">{action}</div>
89
- </Show>
90
- </div>
91
- )
92
- }
@@ -1,30 +0,0 @@
1
- {
2
- "name": "empty-state",
3
- "kind": "component",
4
- "framework": "react",
5
- "description": "Placeholder card with icon, title, description and optional action.",
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": "EmptyState.tsx",
23
- "target": "components/empty-state/EmptyState.tsx"
24
- },
25
- {
26
- "source": "index.ts",
27
- "target": "components/empty-state/index.ts"
28
- }
29
- ]
30
- }
@@ -1,5 +0,0 @@
1
- export {
2
- EmptyState,
3
- type EmptyStateProps,
4
- type EmptyStateTone,
5
- } from './EmptyState.js'
@@ -1,68 +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
- Text,
6
- useAttributes,
7
- useMatch,
8
- useState,
9
- type ReactiveAttributes,
10
- } from '@blankways/state-react'
11
- import { cn } from '../../internals/cn.js'
12
-
13
- const TONE_CASES = ['light', 'dark'] as const
14
-
15
- export type EyebrowTone = (typeof TONE_CASES)[number]
16
-
17
- export type EyebrowProps = {
18
- children: ReactNode | StateId<string>
19
- tone?: EyebrowTone
20
- className?: string
21
- }
22
-
23
- const toneClasses: Record<EyebrowTone, string> = {
24
- light: 'text-ink-muted',
25
- dark: 'text-on-contrast/60',
26
- }
27
-
28
- function useSyncedState<Type>(value: Type): StateId<Type> {
29
- const state = useState(value)
30
- useEffect(() => {
31
- if (!Object.is(State.get(state), value)) State.set(state, value)
32
- }, [state, value])
33
- return state
34
- }
35
-
36
- /** Small uppercase label with a neutral dot; children may be a text state. */
37
- export function Eyebrow({ children, tone = 'light', className }: EyebrowProps) {
38
- const toneState = useSyncedState(tone)
39
- const [isLight, isDark] = useMatch(toneState, TONE_CASES)
40
- const ref = useRef<HTMLSpanElement | null>(null)
41
- const attributes = useMemo<ReactiveAttributes<HTMLSpanElement>>(
42
- () => ({
43
- 'data-tone': toneState,
44
- 'data-tone-light': isLight,
45
- 'data-tone-dark': isDark,
46
- }),
47
- [toneState, isLight, isDark],
48
- )
49
- useAttributes(ref, attributes)
50
-
51
- return (
52
- <span
53
- ref={ref}
54
- className={cn(
55
- 'inline-flex items-center gap-2 text-xs font-semibold tracking-[0.18em] uppercase',
56
- toneClasses[tone],
57
- className,
58
- )}
59
- >
60
- <span className="size-1.5 rounded-full bg-brand-500" aria-hidden="true" />
61
- {typeof children === 'number' ? (
62
- <Text as="span" value={children as StateId<string>} />
63
- ) : (
64
- children
65
- )}
66
- </span>
67
- )
68
- }
@@ -1,30 +0,0 @@
1
- {
2
- "name": "eyebrow",
3
- "kind": "component",
4
- "framework": "react",
5
- "description": "Uppercase section label with a neutral dot and reactive text support.",
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": "Eyebrow.tsx",
23
- "target": "components/eyebrow/Eyebrow.tsx"
24
- },
25
- {
26
- "source": "index.ts",
27
- "target": "components/eyebrow/index.ts"
28
- }
29
- ]
30
- }
@@ -1 +0,0 @@
1
- export { Eyebrow, type EyebrowProps, type EyebrowTone } from './Eyebrow.js'
@@ -1,19 +0,0 @@
1
- {
2
- "name": "field-styles",
3
- "kind": "utility",
4
- "framework": "react",
5
- "description": "Tailwind class recipes for form fields, tones and shapes.",
6
- "dependencies": [
7
- "cn"
8
- ],
9
- "peers": [
10
- "react"
11
- ],
12
- "suggestions": [],
13
- "files": [
14
- {
15
- "source": "index.ts",
16
- "target": "styles/field-styles.ts"
17
- }
18
- ]
19
- }
@@ -1,42 +0,0 @@
1
- import { cn } from '../internals/cn.js'
2
-
3
- export type FieldTone = 'default' | 'success' | 'warning' | 'error'
4
-
5
- export type FieldShape = 'rounded' | 'pill'
6
-
7
- /** Classes shared by every text-like form control. */
8
- export const fieldBase = cn(
9
- 'motion-focus w-full border px-3 py-[0.5625rem] text-sm',
10
- 'focus:outline-none focus-visible:ring-2 focus-visible:ring-brand-500/40',
11
- 'disabled:cursor-not-allowed disabled:opacity-60',
12
- )
13
-
14
- export const fieldShapeClasses: Record<FieldShape, string> = {
15
- rounded: 'rounded-2xl',
16
- pill: 'rounded-full',
17
- }
18
-
19
- export const fieldToneClasses: Record<FieldTone, string> = {
20
- default: cn(
21
- 'border-line bg-paper text-ink placeholder:text-ink-muted/70',
22
- 'hover:border-line-strong focus:border-brand-500',
23
- ),
24
- success: cn(
25
- 'border-ink/30 bg-ink/5 text-ink placeholder:text-ink-muted/70',
26
- 'focus:border-ink/50',
27
- ),
28
- warning: cn(
29
- 'border-ink/50 bg-ink/10 text-ink placeholder:text-ink-muted/70',
30
- 'focus:border-ink/70',
31
- ),
32
- error: cn(
33
- 'border-brand-500 bg-brand-500/5 text-ink placeholder:text-ink-muted/70',
34
- 'focus:border-brand-500',
35
- ),
36
- }
37
-
38
- /** Extra classes applied when a field is in an error state. */
39
- export const fieldErrorClasses = cn(
40
- 'border-brand-500 text-ink',
41
- 'aria-[invalid=true]:ring-2 aria-[invalid=true]:ring-brand-500/30',
42
- )
@@ -1,128 +0,0 @@
1
- import { useEffect, useMemo, useRef } from 'react'
2
- import type { FormEvent, ReactNode } from 'react'
3
- import { createPortal } from 'react-dom'
4
- import { State, type StateId } from '@blankways/state'
5
- import {
6
- Show,
7
- Text,
8
- useAttributes,
9
- useCompute,
10
- useState,
11
- type ReactiveAttributes,
12
- } from '@blankways/state-react'
13
- import { cn } from '../../internals/cn.js'
14
- import { Button } from '../button/index.js'
15
-
16
- export type FormDialogProps = {
17
- open: boolean
18
- onOpenChange: (open: boolean) => void
19
- title: string
20
- description?: string
21
- /** The form fields. */
22
- children: ReactNode
23
- submitLabel: string
24
- cancelLabel: string
25
- onSubmit: () => void
26
- }
27
-
28
- function useSyncedState<Type>(value: Type): StateId<Type> {
29
- const state = useState(value)
30
- useEffect(() => {
31
- if (!Object.is(State.get(state), value)) State.set(state, value)
32
- }, [state, value])
33
- return state
34
- }
35
-
36
- /** Controlled form dialog with native submit, Escape and outside-click closing. */
37
- export function FormDialog({
38
- open,
39
- onOpenChange,
40
- title,
41
- description,
42
- children,
43
- submitLabel,
44
- cancelLabel,
45
- onSubmit,
46
- }: FormDialogProps) {
47
- const openState = useState(open)
48
- const titleState = useSyncedState(title)
49
- const descriptionState = useSyncedState(description ?? '')
50
- const hasDescription = useSyncedState(Boolean(description))
51
- const modalState = useState('true')
52
- const stateName = useCompute([openState] as const, ([isOpen]) =>
53
- isOpen ? 'open' : 'closed',
54
- )
55
-
56
- useEffect(() => {
57
- State.set(openState, open)
58
- }, [open, openState])
59
-
60
- const panelRef = useRef<HTMLDivElement | null>(null)
61
- const attributes = useMemo<ReactiveAttributes<HTMLDivElement>>(
62
- () => ({ 'aria-modal': modalState, 'data-state': stateName }),
63
- [modalState, stateName],
64
- )
65
- useAttributes(panelRef, attributes)
66
-
67
- useEffect(() => {
68
- if (!open) return
69
- const onKeyDown = (event: KeyboardEvent) => {
70
- if (event.key === 'Escape') onOpenChange(false)
71
- }
72
- document.addEventListener('keydown', onKeyDown)
73
- panelRef.current?.focus()
74
- return () => document.removeEventListener('keydown', onKeyDown)
75
- }, [open, onOpenChange])
76
-
77
- if (typeof document === 'undefined') return null
78
-
79
- return createPortal(
80
- <>
81
- <Show when={openState}>
82
- <div
83
- data-state="open"
84
- className="backdrop-enter fixed inset-0 z-50 bg-black/50 backdrop-blur-[2px]"
85
- onClick={() => onOpenChange(false)}
86
- />
87
- </Show>
88
- <Show when={openState}>
89
- <div
90
- ref={panelRef}
91
- role="dialog"
92
- tabIndex={-1}
93
- className={cn(
94
- 'surface-enter fixed top-1/2 left-1/2 z-50 flex max-h-[calc(100dvh-2rem)] w-[calc(100%-2rem)] max-w-lg -translate-x-1/2 -translate-y-1/2 flex-col gap-5 overflow-y-auto rounded-2xl border border-line bg-paper p-[1.125rem] shadow-2xl outline-none',
95
- )}
96
- >
97
- <div className="flex flex-col gap-2">
98
- <h2 className="text-lg font-semibold tracking-[-0.01em] text-ink">
99
- <Text as="span" value={titleState} />
100
- </h2>
101
- <Show when={hasDescription}>
102
- <p className="text-sm leading-relaxed text-ink-soft">
103
- <Text as="span" value={descriptionState} />
104
- </p>
105
- </Show>
106
- </div>
107
-
108
- <form
109
- className="flex flex-col gap-5"
110
- onSubmit={(event: FormEvent<HTMLFormElement>) => {
111
- event.preventDefault()
112
- onSubmit()
113
- }}
114
- >
115
- {children}
116
- <div className="flex flex-col-reverse gap-2 sm:flex-row sm:justify-end">
117
- <Button type="button" variant="secondary" onClick={() => onOpenChange(false)}>
118
- {cancelLabel}
119
- </Button>
120
- <Button type="submit">{submitLabel}</Button>
121
- </div>
122
- </form>
123
- </div>
124
- </Show>
125
- </>,
126
- document.body,
127
- )
128
- }
@@ -1,34 +0,0 @@
1
- {
2
- "name": "form-dialog",
3
- "kind": "component",
4
- "framework": "react",
5
- "description": "Controlled dialog that gathers values in a native form.",
6
- "dependencies": [
7
- "cn",
8
- "button",
9
- "styles-motion"
10
- ],
11
- "peers": [
12
- "@blankways/state",
13
- "@blankways/state-react@0.1.0-alpha.1",
14
- "react",
15
- "react-dom"
16
- ],
17
- "suggestions": [
18
- "styles-tokens",
19
- "styles-base",
20
- "styles-components",
21
- "styles-utilities",
22
- "styles-motion"
23
- ],
24
- "files": [
25
- {
26
- "source": "FormDialog.tsx",
27
- "target": "components/form-dialog/FormDialog.tsx"
28
- },
29
- {
30
- "source": "index.ts",
31
- "target": "components/form-dialog/index.ts"
32
- }
33
- ]
34
- }
@@ -1 +0,0 @@
1
- export { FormDialog, type FormDialogProps } from './FormDialog.js'
@@ -1,22 +0,0 @@
1
- {
2
- "name": "icons",
3
- "kind": "icon",
4
- "framework": "react",
5
- "description": "Curated set of Lucide icons shared across the component library.",
6
- "dependencies": [],
7
- "peers": [
8
- "lucide-react"
9
- ],
10
- "suggestions": [
11
- "icons-theme",
12
- "icons-form",
13
- "icons-sidebar",
14
- "icons-toast"
15
- ],
16
- "files": [
17
- {
18
- "source": "index.ts",
19
- "target": "icons/index.ts"
20
- }
21
- ]
22
- }