@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,21 +0,0 @@
1
- export {
2
- Check,
3
- ChevronDown,
4
- ChevronRight,
5
- X,
6
- Moon,
7
- Sun,
8
- Monitor,
9
- PanelLeftClose,
10
- PanelLeftOpen,
11
- Menu,
12
- Search,
13
- Plus,
14
- Info,
15
- CircleCheck,
16
- TriangleAlert,
17
- CircleAlert,
18
- ArrowRight,
19
- } from 'lucide-react'
20
-
21
- export type { LucideIcon } from 'lucide-react'
@@ -1,17 +0,0 @@
1
- {
2
- "name": "icons-form",
3
- "kind": "icon",
4
- "framework": "react",
5
- "description": "Lucide icons for form controls, selects and confirmations.",
6
- "dependencies": [],
7
- "peers": [
8
- "lucide-react"
9
- ],
10
- "suggestions": [],
11
- "files": [
12
- {
13
- "source": "index.ts",
14
- "target": "icons/form.ts"
15
- }
16
- ]
17
- }
@@ -1 +0,0 @@
1
- export { Check, ChevronDown, ChevronRight, X, Search, Plus } from 'lucide-react'
@@ -1,17 +0,0 @@
1
- {
2
- "name": "icons-sidebar",
3
- "kind": "icon",
4
- "framework": "react",
5
- "description": "Lucide icons for sidebar toggles and collapsible navigation.",
6
- "dependencies": [],
7
- "peers": [
8
- "lucide-react"
9
- ],
10
- "suggestions": [],
11
- "files": [
12
- {
13
- "source": "index.ts",
14
- "target": "icons/sidebar.ts"
15
- }
16
- ]
17
- }
@@ -1 +0,0 @@
1
- export { PanelLeftClose, PanelLeftOpen, Menu, ChevronRight } from 'lucide-react'
@@ -1,17 +0,0 @@
1
- {
2
- "name": "icons-theme",
3
- "kind": "icon",
4
- "framework": "react",
5
- "description": "Lucide icons for light, dark and system theme controls.",
6
- "dependencies": [],
7
- "peers": [
8
- "lucide-react"
9
- ],
10
- "suggestions": [],
11
- "files": [
12
- {
13
- "source": "index.ts",
14
- "target": "icons/theme.ts"
15
- }
16
- ]
17
- }
@@ -1 +0,0 @@
1
- export { Moon, Sun, Monitor } from 'lucide-react'
@@ -1,17 +0,0 @@
1
- {
2
- "name": "icons-toast",
3
- "kind": "icon",
4
- "framework": "react",
5
- "description": "Lucide icons for informational and status toast messages.",
6
- "dependencies": [],
7
- "peers": [
8
- "lucide-react"
9
- ],
10
- "suggestions": [],
11
- "files": [
12
- {
13
- "source": "index.ts",
14
- "target": "icons/toast.ts"
15
- }
16
- ]
17
- }
@@ -1 +0,0 @@
1
- export { Info, CircleCheck, TriangleAlert, CircleAlert, X } from 'lucide-react'
@@ -1,119 +0,0 @@
1
- import { useEffect, useMemo, useRef } from 'react'
2
- import type { 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 { X } from '../../icons/form.js'
15
-
16
- export type InfoDialogProps = {
17
- open: boolean
18
- onOpenChange: (open: boolean) => void
19
- title: string
20
- description?: string
21
- children: ReactNode
22
- /** Names the close button. */
23
- closeLabel: string
24
- }
25
-
26
- function useSyncedState<Type>(value: Type): StateId<Type> {
27
- const state = useState(value)
28
- useEffect(() => {
29
- if (!Object.is(State.get(state), value)) State.set(state, value)
30
- }, [state, value])
31
- return state
32
- }
33
-
34
- /** Controlled information dialog with a close button, Escape and outside click. */
35
- export function InfoDialog({
36
- open,
37
- onOpenChange,
38
- title,
39
- description,
40
- children,
41
- closeLabel,
42
- }: InfoDialogProps) {
43
- const openState = useState(open)
44
- const titleState = useSyncedState(title)
45
- const descriptionState = useSyncedState(description ?? '')
46
- const hasDescription = useSyncedState(Boolean(description))
47
- const modalState = useState('true')
48
- const stateName = useCompute([openState] as const, ([isOpen]) =>
49
- isOpen ? 'open' : 'closed',
50
- )
51
-
52
- useEffect(() => {
53
- State.set(openState, open)
54
- }, [open, openState])
55
-
56
- const panelRef = useRef<HTMLDivElement | null>(null)
57
- const attributes = useMemo<ReactiveAttributes<HTMLDivElement>>(
58
- () => ({ 'aria-modal': modalState, 'data-state': stateName }),
59
- [modalState, stateName],
60
- )
61
- useAttributes(panelRef, attributes)
62
-
63
- useEffect(() => {
64
- if (!open) return
65
- const onKeyDown = (event: KeyboardEvent) => {
66
- if (event.key === 'Escape') onOpenChange(false)
67
- }
68
- document.addEventListener('keydown', onKeyDown)
69
- panelRef.current?.focus()
70
- return () => document.removeEventListener('keydown', onKeyDown)
71
- }, [open, onOpenChange])
72
-
73
- if (typeof document === 'undefined') return null
74
-
75
- return createPortal(
76
- <>
77
- <Show when={openState}>
78
- <div
79
- data-state="open"
80
- className="backdrop-enter fixed inset-0 z-50 bg-black/50 backdrop-blur-[2px]"
81
- onClick={() => onOpenChange(false)}
82
- />
83
- </Show>
84
- <Show when={openState}>
85
- <div
86
- ref={panelRef}
87
- role="dialog"
88
- tabIndex={-1}
89
- className={cn(
90
- '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',
91
- )}
92
- >
93
- <div className="flex items-start justify-between gap-4">
94
- <div className="flex flex-col gap-1.5">
95
- <h2 className="text-lg font-semibold tracking-[-0.01em] text-ink">
96
- <Text as="span" value={titleState} />
97
- </h2>
98
- <Show when={hasDescription}>
99
- <p className="text-sm leading-relaxed text-ink-soft">
100
- <Text as="span" value={descriptionState} />
101
- </p>
102
- </Show>
103
- </div>
104
- <button
105
- type="button"
106
- aria-label={closeLabel}
107
- onClick={() => onOpenChange(false)}
108
- className="inline-flex size-8 shrink-0 items-center justify-center rounded-2xl text-ink-soft motion-color outline-none hover:bg-surface-2 hover:text-ink focus-visible:ring-2 focus-visible:ring-brand-500"
109
- >
110
- <X className="size-4" aria-hidden="true" />
111
- </button>
112
- </div>
113
- {children}
114
- </div>
115
- </Show>
116
- </>,
117
- document.body,
118
- )
119
- }
@@ -1,36 +0,0 @@
1
- {
2
- "name": "info-dialog",
3
- "kind": "component",
4
- "framework": "react",
5
- "description": "Controlled read-only dialog with a native portal and close button.",
6
- "dependencies": [
7
- "cn",
8
- "button",
9
- "icons-form",
10
- "styles-motion"
11
- ],
12
- "peers": [
13
- "@blankways/state",
14
- "@blankways/state-react@0.1.0-alpha.1",
15
- "react",
16
- "react-dom",
17
- "lucide-react"
18
- ],
19
- "suggestions": [
20
- "styles-tokens",
21
- "styles-base",
22
- "styles-components",
23
- "styles-utilities",
24
- "styles-motion"
25
- ],
26
- "files": [
27
- {
28
- "source": "InfoDialog.tsx",
29
- "target": "components/info-dialog/InfoDialog.tsx"
30
- },
31
- {
32
- "source": "index.ts",
33
- "target": "components/info-dialog/index.ts"
34
- }
35
- ]
36
- }
@@ -1 +0,0 @@
1
- export { InfoDialog, type InfoDialogProps } from './InfoDialog.js'
@@ -1,96 +0,0 @@
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 InputProps = Omit<ComponentPropsWithoutRef<'input'>, 'value'> & {
16
- value?: string | StateId<string>
17
- invalid?: boolean | StateId<boolean>
18
- shape?: FieldShape
19
- tone?: FieldTone
20
- }
21
-
22
- /** Text input with the shared field recipes and optional state-bound value. */
23
- export const Input = forwardRef<HTMLInputElement, InputProps>(function Input(
24
- {
25
- className,
26
- tone = 'default',
27
- shape = 'rounded',
28
- invalid = false,
29
- value,
30
- onChange,
31
- ...rest
32
- },
33
- forwardedRef,
34
- ) {
35
- const localValue = useState<string>(typeof value === 'string' ? value : '')
36
- const localInvalid = useState<boolean>(
37
- typeof invalid === 'boolean' ? invalid : false,
38
- )
39
-
40
- const valueState = typeof value === 'number' ? value : localValue
41
- const invalidState = typeof invalid === 'number' ? invalid : localInvalid
42
-
43
- useEffect(() => {
44
- if (typeof value === 'string') State.set(localValue, value)
45
- }, [value, localValue])
46
-
47
- useEffect(() => {
48
- if (typeof invalid === 'boolean') State.set(localInvalid, invalid)
49
- }, [invalid, localInvalid])
50
-
51
- const ref = useRef<HTMLInputElement | null>(null)
52
- const attributes = useMemo<ReactiveAttributes<HTMLInputElement>>(
53
- () => ({
54
- ...(value !== undefined ? { value: valueState } : {}),
55
- ...(typeof invalid === 'number'
56
- ? { 'aria-invalid': invalidState, 'data-invalid': invalidState }
57
- : {}),
58
- }),
59
- [invalid, invalidState, value, valueState],
60
- )
61
- useAttributes(ref, attributes)
62
-
63
- const setRef = useCallback(
64
- (element: HTMLInputElement | null) => {
65
- ref.current = element
66
- if (typeof forwardedRef === 'function') forwardedRef(element)
67
- else if (forwardedRef) {
68
- ;(forwardedRef as { current: HTMLInputElement | null }).current = element
69
- }
70
- },
71
- [forwardedRef],
72
- )
73
-
74
- const handleChange = (event: ChangeEvent<HTMLInputElement>) => {
75
- State.set(valueState, event.currentTarget.value)
76
- onChange?.(event)
77
- }
78
-
79
- return (
80
- <input
81
- {...rest}
82
- ref={setRef}
83
- value={typeof value === 'string' ? value : undefined}
84
- onChange={handleChange}
85
- aria-invalid={typeof invalid === 'boolean' ? invalid || undefined : undefined}
86
- className={cn(
87
- fieldBase,
88
- fieldShapeClasses[shape],
89
- fieldToneClasses[tone],
90
- typeof invalid === 'boolean' && invalid && fieldErrorClasses,
91
- 'data-[invalid=true]:border-brand-500 aria-[invalid=true]:ring-2 aria-[invalid=true]:ring-brand-500/30',
92
- className,
93
- )}
94
- />
95
- )
96
- })
@@ -1,33 +0,0 @@
1
- {
2
- "name": "input",
3
- "kind": "component",
4
- "framework": "react",
5
- "description": "Native input 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": "Input.tsx",
26
- "target": "components/input/Input.tsx"
27
- },
28
- {
29
- "source": "index.ts",
30
- "target": "components/input/index.ts"
31
- }
32
- ]
33
- }
@@ -1 +0,0 @@
1
- export { Input, type InputProps } from './Input.js'
@@ -1,205 +0,0 @@
1
- import { useEffect, useRef } from 'react'
2
- import { useState as useReactState } from 'react'
3
- import type { CSSProperties, KeyboardEvent } from 'react'
4
- import { State, type StateId } from '@blankways/state'
5
- import { Show, Text, useCompute, useState } from '@blankways/state-react'
6
- import { cn } from '../../internals/cn.js'
7
- import { Check, Search, X } from '../../icons/form.js'
8
- import type { SelectOption } from '../select/index.js'
9
-
10
- export type { SelectOption } from '../select/index.js'
11
-
12
- export type MultiComboboxProps = {
13
- options: SelectOption[]
14
- value?: string[]
15
- onValueChange?: (value: string[]) => void
16
- placeholder?: string
17
- invalid?: boolean
18
- /** Shown when the typed text matches no option. */
19
- emptyLabel?: string
20
- /** Names each chip's remove button. */
21
- removeLabel?: string
22
- className?: string
23
- 'aria-label'?: string
24
- }
25
-
26
- function ChipLabel({ labels, index }: { labels: StateId<string[]>; index: number }) {
27
- const label = useCompute([labels] as const, ([all]) => all[index] ?? '')
28
- return <Text as="span" value={label} />
29
- }
30
-
31
- /** Multi-select with typed filtering and removable chips, built from native elements. */
32
- export function MultiCombobox({
33
- options,
34
- value = [],
35
- onValueChange,
36
- placeholder = 'Buscar…',
37
- invalid = false,
38
- emptyLabel = 'Sin resultados',
39
- removeLabel = 'Quitar',
40
- className,
41
- 'aria-label': ariaLabel,
42
- }: MultiComboboxProps) {
43
- const queryState = useState('')
44
- const openState = useState(false)
45
- const [query, setQuery] = useReactState('')
46
- const [open, setOpen] = useReactState(false)
47
-
48
- const valueState = useState(value)
49
- const optionsState = useState(options)
50
- useEffect(() => {
51
- State.set(valueState, value)
52
- }, [value, valueState])
53
- useEffect(() => {
54
- State.set(optionsState, options)
55
- }, [options, optionsState])
56
-
57
- const filteredOptions = useCompute(
58
- [queryState, optionsState] as const,
59
- ([text, list]) => {
60
- const needle = text.trim().toLowerCase()
61
- if (!needle) return list
62
- return list.filter(
63
- (option) =>
64
- option.label.toLowerCase().includes(needle) ||
65
- option.value.toLowerCase().includes(needle),
66
- )
67
- },
68
- )
69
- const selectedLabels = useCompute([valueState, optionsState] as const, ([selected, list]) =>
70
- selected.map((item) => list.find((option) => option.value === item)?.label ?? item),
71
- )
72
- const hasChips = useCompute([valueState] as const, ([selected]) => selected.length > 0)
73
- const hasResults = useCompute([filteredOptions] as const, ([list]) => list.length > 0)
74
- const isEmpty = useCompute([hasResults] as const, ([has]) => !has)
75
-
76
- const containerRef = useRef<HTMLDivElement | null>(null)
77
- const inputRef = useRef<HTMLInputElement | null>(null)
78
-
79
- const setQueryValue = (next: string) => {
80
- State.set(queryState, next)
81
- setQuery(next)
82
- }
83
- const setOpenValue = (next: boolean) => {
84
- State.set(openState, next)
85
- setOpen(next)
86
- }
87
-
88
- const choose = (option: SelectOption) => {
89
- if (!State.get(valueState).includes(option.value)) {
90
- onValueChange?.([...State.get(valueState), option.value])
91
- }
92
- setQueryValue('')
93
- inputRef.current?.focus()
94
- }
95
- const remove = (item: string) => {
96
- onValueChange?.(State.get(valueState).filter((entry) => entry !== item))
97
- }
98
-
99
- useEffect(() => {
100
- if (!open) return
101
- const onPointerDown = (event: PointerEvent) => {
102
- if (containerRef.current && !containerRef.current.contains(event.target as Node)) {
103
- setOpenValue(false)
104
- }
105
- }
106
- document.addEventListener('pointerdown', onPointerDown)
107
- return () => document.removeEventListener('pointerdown', onPointerDown)
108
- }, [open])
109
-
110
- const handleKeyDown = (event: KeyboardEvent<HTMLInputElement>) => {
111
- if (event.key === 'Escape') {
112
- setOpenValue(false)
113
- } else if (event.key === 'Enter' && open) {
114
- const first = State.get(filteredOptions)[0]
115
- if (first) {
116
- event.preventDefault()
117
- choose(first)
118
- }
119
- }
120
- }
121
-
122
- return (
123
- <div ref={containerRef} className={cn('relative w-full', className)}>
124
- <div
125
- className={cn(
126
- 'flex min-h-12 w-full flex-wrap items-center gap-1.5 rounded-2xl border border-line bg-paper px-[0.469rem] py-1.5 motion-color',
127
- 'focus-within:border-brand-500 hover:border-line-strong',
128
- invalid && 'border-brand-500',
129
- )}
130
- >
131
- <Show when={hasChips}>
132
- <div className="flex flex-wrap items-center gap-1.5">
133
- {value.map((item, index) => (
134
- <span
135
- key={item}
136
- className="motion-icon-swap inline-flex items-center gap-1 rounded-2xl bg-accent-soft py-[0.188rem] pr-[0.188rem] pl-[0.5625rem] text-xs font-medium text-ink"
137
- >
138
- <ChipLabel labels={selectedLabels} index={index} />
139
- <button
140
- type="button"
141
- aria-label={`${removeLabel} ${State.get(selectedLabels)[index] ?? item}`}
142
- onClick={() => remove(item)}
143
- className="inline-flex size-5 items-center justify-center rounded-full text-ink-soft outline-none motion-color hover:bg-paper hover:text-ink focus-visible:ring-2 focus-visible:ring-brand-500"
144
- >
145
- <X className="size-3" aria-hidden="true" />
146
- </button>
147
- </span>
148
- ))}
149
- </div>
150
- </Show>
151
-
152
- <div className="flex min-w-24 flex-1 items-center gap-2">
153
- <Search className="size-4 shrink-0 text-ink-muted" aria-hidden="true" />
154
- <input
155
- ref={inputRef}
156
- value={query}
157
- placeholder={value.length === 0 ? placeholder : undefined}
158
- onChange={(event) => {
159
- setQueryValue(event.currentTarget.value)
160
- setOpenValue(true)
161
- }}
162
- onFocus={() => setOpenValue(true)}
163
- onKeyDown={handleKeyDown}
164
- aria-label={ariaLabel}
165
- aria-invalid={invalid || undefined}
166
- className="h-8 w-full min-w-24 flex-1 bg-transparent text-sm text-ink outline-none placeholder:text-ink-muted/70"
167
- />
168
- </div>
169
- </div>
170
-
171
- <Show when={openState}>
172
- <div
173
- role="listbox"
174
- aria-multiselectable="true"
175
- data-state="open"
176
- className="popup-enter absolute top-full left-0 z-[70] mt-1 max-h-64 w-full overflow-y-auto rounded-2xl border border-line bg-paper p-[0.281rem] text-ink shadow-xl outline-none"
177
- >
178
- <Show when={hasResults}>
179
- <ul className="stagger-children flex flex-col gap-0.5" role="presentation">
180
- {State.get(filteredOptions).map((option, index) => (
181
- <li
182
- key={option.value}
183
- role="option"
184
- aria-selected={value.includes(option.value)}
185
- style={{ '--index': index } as CSSProperties}
186
- onMouseDown={(event) => event.preventDefault()}
187
- onClick={() => choose(option)}
188
- className="flex cursor-pointer items-center gap-2.5 rounded-2xl px-[0.5625rem] py-1.5 text-sm text-ink outline-none select-none hover:bg-surface-2"
189
- >
190
- <span className="flex-1">{option.label}</span>
191
- {value.includes(option.value) ? (
192
- <Check className="size-4 text-brand-500" aria-hidden="true" />
193
- ) : null}
194
- </li>
195
- ))}
196
- </ul>
197
- </Show>
198
- <Show when={isEmpty}>
199
- <p className="px-[0.5625rem] py-[0.5625rem] text-sm text-ink-soft">{emptyLabel}</p>
200
- </Show>
201
- </div>
202
- </Show>
203
- </div>
204
- )
205
- }
@@ -1,35 +0,0 @@
1
- {
2
- "name": "multi-combobox",
3
- "kind": "component",
4
- "framework": "react",
5
- "description": "Multi-select with search, chips and a native listbox popup.",
6
- "dependencies": [
7
- "cn",
8
- "icons-form",
9
- "select",
10
- "styles-motion"
11
- ],
12
- "peers": [
13
- "@blankways/state",
14
- "@blankways/state-react@0.1.0-alpha.1",
15
- "react",
16
- "lucide-react"
17
- ],
18
- "suggestions": [
19
- "styles-tokens",
20
- "styles-base",
21
- "styles-components",
22
- "styles-utilities",
23
- "styles-motion"
24
- ],
25
- "files": [
26
- {
27
- "source": "MultiCombobox.tsx",
28
- "target": "components/multi-combobox/MultiCombobox.tsx"
29
- },
30
- {
31
- "source": "index.ts",
32
- "target": "components/multi-combobox/index.ts"
33
- }
34
- ]
35
- }
@@ -1,5 +0,0 @@
1
- export {
2
- MultiCombobox,
3
- type MultiComboboxProps,
4
- type SelectOption,
5
- } from './MultiCombobox.js'
@@ -1,8 +0,0 @@
1
- import { RemoteProvider as BaseRemoteProvider } from '@blankways/remote-react'
2
- import type { ComponentProps } from 'react'
3
-
4
- export type RemoteProviderProps = ComponentProps<typeof BaseRemoteProvider>
5
-
6
- export function RemoteProvider({ children, ...props }: RemoteProviderProps) {
7
- return <BaseRemoteProvider {...props}>{children}</BaseRemoteProvider>
8
- }
@@ -1,25 +0,0 @@
1
- {
2
- "name": "remote-provider",
3
- "kind": "component",
4
- "framework": "react",
5
- "description": "RemoteProvider wrapper and useCall re-export from the published @blankways/remote-react package.",
6
- "dependencies": [],
7
- "peers": [
8
- "@blankways/remote-react@0.1.0-alpha.1",
9
- "@blankways/remote@0.1.0-alpha.4",
10
- "@blankways/serial@0.1.0-alpha.fa636be",
11
- "@blankways/state@0.2.0-alpha.85cba23",
12
- "react"
13
- ],
14
- "suggestions": ["styles-tokens", "styles-base"],
15
- "files": [
16
- {
17
- "source": "RemoteProvider.tsx",
18
- "target": "components/remote-provider/RemoteProvider.tsx"
19
- },
20
- {
21
- "source": "index.ts",
22
- "target": "components/remote-provider/index.ts"
23
- }
24
- ]
25
- }