@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.
- package/README.md +228 -2
- package/dist/cli/cli.options.d.ts +5 -0
- package/dist/cli/cli.options.js +53 -0
- package/dist/cli/cli.registry.d.ts +6 -0
- package/dist/cli/cli.registry.js +37 -0
- package/dist/cli/cli.types.d.ts +32 -0
- package/dist/cli/cli.types.js +1 -0
- package/dist/cli/index.d.ts +3 -0
- package/dist/cli/index.js +3 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +47 -0
- package/dist/commands/add.command.d.ts +2 -0
- package/dist/commands/add.command.js +101 -0
- package/dist/commands/doctor.command.d.ts +3 -0
- package/dist/commands/doctor.command.js +92 -0
- package/dist/commands/index.d.ts +6 -0
- package/dist/commands/index.js +6 -0
- package/dist/commands/init.command.d.ts +2 -0
- package/dist/commands/init.command.js +38 -0
- package/dist/commands/list.command.d.ts +2 -0
- package/dist/commands/list.command.js +54 -0
- package/dist/commands/meta.command.d.ts +1 -0
- package/dist/commands/meta.command.js +19 -0
- package/dist/commands/styles.command.d.ts +6 -0
- package/dist/commands/styles.command.js +68 -0
- package/dist/config/config.helpers.d.ts +7 -0
- package/dist/config/config.helpers.js +63 -0
- package/dist/config/framework.helpers.d.ts +3 -0
- package/dist/config/framework.helpers.js +14 -0
- package/dist/config/index.d.ts +2 -0
- package/dist/config/index.js +2 -0
- package/dist/constants/cli.constants.d.ts +9 -0
- package/dist/constants/cli.constants.js +15 -0
- package/dist/constants/framework.constants.d.ts +3 -0
- package/dist/constants/framework.constants.js +2 -0
- package/dist/constants/index.d.ts +2 -0
- package/dist/constants/index.js +2 -0
- package/dist/doctor/checks/entries.check.d.ts +1 -0
- package/dist/doctor/checks/entries.check.js +21 -0
- package/dist/doctor/checks/icons.check.d.ts +1 -0
- package/dist/doctor/checks/icons.check.js +55 -0
- package/dist/doctor/checks/imports.check.d.ts +1 -0
- package/dist/doctor/checks/imports.check.js +45 -0
- package/dist/doctor/checks/index.d.ts +7 -0
- package/dist/doctor/checks/index.js +7 -0
- package/dist/doctor/checks/motion.check.d.ts +1 -0
- package/dist/doctor/checks/motion.check.js +66 -0
- package/dist/doctor/checks/peers.check.d.ts +1 -0
- package/dist/doctor/checks/peers.check.js +55 -0
- package/dist/doctor/checks/styles.check.d.ts +1 -0
- package/dist/doctor/checks/styles.check.js +45 -0
- package/dist/doctor/checks/themes.check.d.ts +1 -0
- package/dist/doctor/checks/themes.check.js +64 -0
- package/dist/doctor/doctor.helpers.d.ts +6 -0
- package/dist/doctor/doctor.helpers.js +39 -0
- package/dist/doctor/doctor.registry.d.ts +10 -0
- package/dist/doctor/doctor.registry.js +24 -0
- package/dist/doctor/doctor.types.d.ts +27 -0
- package/dist/doctor/doctor.types.js +1 -0
- package/dist/doctor/index.d.ts +3 -0
- package/dist/doctor/index.js +3 -0
- package/dist/errors/cli-error.d.ts +3 -0
- package/dist/errors/cli-error.js +6 -0
- package/dist/errors/index.d.ts +1 -0
- package/dist/errors/index.js +1 -0
- package/dist/helpers/args.helpers.d.ts +4 -0
- package/dist/helpers/args.helpers.js +75 -0
- package/dist/helpers/help.helpers.d.ts +1 -0
- package/dist/helpers/help.helpers.js +30 -0
- package/dist/helpers/index.d.ts +5 -0
- package/dist/helpers/index.js +5 -0
- package/dist/helpers/package.helpers.d.ts +2 -0
- package/dist/helpers/package.helpers.js +12 -0
- package/dist/helpers/path.helpers.d.ts +3 -0
- package/dist/helpers/path.helpers.js +15 -0
- package/dist/helpers/styles.helpers.d.ts +21 -0
- package/dist/helpers/styles.helpers.js +164 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +9 -0
- package/dist/registry/index.d.ts +1 -0
- package/dist/registry/index.js +1 -0
- package/dist/registry/registry.helpers.d.ts +22 -0
- package/dist/registry/registry.helpers.js +328 -0
- package/dist/registry-data/README.md +71 -0
- package/dist/registry-data/avatar/Avatar.tsx +64 -0
- package/dist/registry-data/avatar/component.json +30 -0
- package/dist/registry-data/avatar/index.ts +1 -0
- package/dist/registry-data/badge/Badge.tsx +76 -0
- package/dist/registry-data/badge/component.json +30 -0
- package/dist/registry-data/badge/index.ts +1 -0
- package/dist/registry-data/brand-logo/BrandLogo.tsx +24 -0
- package/dist/registry-data/brand-logo/component.json +26 -0
- package/dist/registry-data/brand-logo/index.ts +1 -0
- package/dist/registry-data/button/Button.tsx +76 -0
- package/dist/registry-data/button/component.json +33 -0
- package/dist/registry-data/button/index.ts +1 -0
- package/dist/registry-data/button-link/ButtonLink.tsx +83 -0
- package/dist/registry-data/button-link/component.json +33 -0
- package/dist/registry-data/button-link/index.ts +5 -0
- package/dist/registry-data/button-styles/component.json +19 -0
- package/dist/registry-data/button-styles/index.ts +45 -0
- package/dist/registry-data/cn/cn.ts +6 -0
- package/dist/registry-data/cn/component.json +16 -0
- package/dist/registry-data/confirm-dialog/ConfirmDialog.tsx +134 -0
- package/dist/registry-data/confirm-dialog/component.json +34 -0
- package/dist/registry-data/confirm-dialog/index.ts +1 -0
- package/dist/registry-data/container/Container.tsx +22 -0
- package/dist/registry-data/container/component.json +28 -0
- package/dist/registry-data/container/index.ts +1 -0
- package/dist/registry-data/cursor-glow/CursorGlow.tsx +29 -0
- package/dist/registry-data/cursor-glow/component.json +28 -0
- package/dist/registry-data/cursor-glow/index.ts +1 -0
- package/dist/registry-data/dropdown-menu/DropdownMenu.tsx +157 -0
- package/dist/registry-data/dropdown-menu/component.json +34 -0
- package/dist/registry-data/dropdown-menu/index.ts +5 -0
- package/dist/registry-data/empty-state/EmptyState.tsx +92 -0
- package/dist/registry-data/empty-state/component.json +30 -0
- package/dist/registry-data/empty-state/index.ts +5 -0
- package/dist/registry-data/eyebrow/Eyebrow.tsx +68 -0
- package/dist/registry-data/eyebrow/component.json +30 -0
- package/dist/registry-data/eyebrow/index.ts +1 -0
- package/dist/registry-data/field-styles/component.json +19 -0
- package/dist/registry-data/field-styles/index.ts +42 -0
- package/dist/registry-data/form-dialog/FormDialog.tsx +128 -0
- package/dist/registry-data/form-dialog/component.json +34 -0
- package/dist/registry-data/form-dialog/index.ts +1 -0
- package/dist/registry-data/icons/component.json +22 -0
- package/dist/registry-data/icons/index.ts +21 -0
- package/dist/registry-data/icons-form/component.json +17 -0
- package/dist/registry-data/icons-form/index.ts +1 -0
- package/dist/registry-data/icons-sidebar/component.json +17 -0
- package/dist/registry-data/icons-sidebar/index.ts +1 -0
- package/dist/registry-data/icons-theme/component.json +17 -0
- package/dist/registry-data/icons-theme/index.ts +1 -0
- package/dist/registry-data/icons-toast/component.json +17 -0
- package/dist/registry-data/icons-toast/index.ts +1 -0
- package/dist/registry-data/info-dialog/InfoDialog.tsx +119 -0
- package/dist/registry-data/info-dialog/component.json +36 -0
- package/dist/registry-data/info-dialog/index.ts +1 -0
- package/dist/registry-data/input/Input.tsx +96 -0
- package/dist/registry-data/input/component.json +33 -0
- package/dist/registry-data/input/index.ts +1 -0
- package/dist/registry-data/multi-combobox/MultiCombobox.tsx +205 -0
- package/dist/registry-data/multi-combobox/component.json +35 -0
- package/dist/registry-data/multi-combobox/index.ts +5 -0
- package/dist/registry-data/remote-provider/RemoteProvider.tsx +8 -0
- package/dist/registry-data/remote-provider/component.json +25 -0
- package/dist/registry-data/remote-provider/index.ts +3 -0
- package/dist/registry-data/reveal/Reveal.tsx +22 -0
- package/dist/registry-data/reveal/component.json +30 -0
- package/dist/registry-data/reveal/index.ts +1 -0
- package/dist/registry-data/section/Section.tsx +80 -0
- package/dist/registry-data/section/component.json +30 -0
- package/dist/registry-data/section/index.ts +1 -0
- package/dist/registry-data/section-heading/SectionHeading.tsx +105 -0
- package/dist/registry-data/section-heading/component.json +32 -0
- package/dist/registry-data/section-heading/index.ts +1 -0
- package/dist/registry-data/select/Select.tsx +197 -0
- package/dist/registry-data/select/component.json +34 -0
- package/dist/registry-data/select/index.ts +1 -0
- package/dist/registry-data/sidebar/Sidebar.tsx +432 -0
- package/dist/registry-data/sidebar/SidebarCollapsible.tsx +77 -0
- package/dist/registry-data/sidebar/SidebarParts.tsx +373 -0
- package/dist/registry-data/sidebar/component.json +47 -0
- package/dist/registry-data/sidebar/index.ts +4 -0
- package/dist/registry-data/sidebar/useSidebar.ts +29 -0
- package/dist/registry-data/styles-base/component.json +19 -0
- package/dist/registry-data/styles-base/index.css +67 -0
- package/dist/registry-data/styles-components/component.json +19 -0
- package/dist/registry-data/styles-components/index.css +30 -0
- package/dist/registry-data/styles-motion/component.json +20 -0
- package/dist/registry-data/styles-motion/index.css +381 -0
- package/dist/registry-data/styles-tokens/component.json +17 -0
- package/dist/registry-data/styles-tokens/index.css +77 -0
- package/dist/registry-data/styles-utilities/component.json +19 -0
- package/dist/registry-data/styles-utilities/index.css +29 -0
- package/dist/registry-data/switch/Switch.tsx +91 -0
- package/dist/registry-data/switch/component.json +34 -0
- package/dist/registry-data/switch/index.ts +1 -0
- package/dist/registry-data/tabs/Tabs.tsx +226 -0
- package/dist/registry-data/tabs/component.json +32 -0
- package/dist/registry-data/tabs/index.ts +1 -0
- package/dist/registry-data/textarea/Textarea.tsx +94 -0
- package/dist/registry-data/textarea/component.json +33 -0
- package/dist/registry-data/textarea/index.ts +1 -0
- package/dist/registry-data/theme-core/component.json +17 -0
- package/dist/registry-data/theme-core/theme.ts +84 -0
- package/dist/registry-data/theme-dark/component.json +19 -0
- package/dist/registry-data/theme-dark/index.ts +7 -0
- package/dist/registry-data/theme-light/component.json +19 -0
- package/dist/registry-data/theme-light/index.ts +7 -0
- package/dist/registry-data/theme-provider/ThemeContext.tsx +177 -0
- package/dist/registry-data/theme-provider/component.json +30 -0
- package/dist/registry-data/theme-provider/index.ts +2 -0
- package/dist/registry-data/theme-selector/ThemeSelector.tsx +269 -0
- package/dist/registry-data/theme-selector/component.json +35 -0
- package/dist/registry-data/theme-selector/selector.ts +1 -0
- package/dist/registry-data/theme-system/component.json +19 -0
- package/dist/registry-data/theme-system/index.ts +7 -0
- package/dist/registry-data/theme-toggle/ThemeToggle.tsx +71 -0
- package/dist/registry-data/theme-toggle/component.json +31 -0
- package/dist/registry-data/theme-toggle/toggle.ts +1 -0
- package/dist/registry-data/toast/Toast.tsx +260 -0
- package/dist/registry-data/toast/ToastTypeIcon.tsx +83 -0
- package/dist/registry-data/toast/component.json +43 -0
- package/dist/registry-data/toast/index.ts +3 -0
- package/dist/registry-data/toast/useToast.ts +47 -0
- package/dist/types/cli.types.d.ts +6 -0
- package/dist/types/cli.types.js +1 -0
- package/dist/types/config.types.d.ts +41 -0
- package/dist/types/config.types.js +1 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/index.js +3 -0
- package/dist/types/registry.types.d.ts +37 -0
- package/dist/types/registry.types.js +1 -0
- package/package.json +35 -3
|
@@ -0,0 +1,22 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Reveal, type RevealProps } from './Reveal.js'
|
|
@@ -0,0 +1,80 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Section, type SectionProps, type SectionTone } from './Section.js'
|
|
@@ -0,0 +1,105 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { SectionHeading, type SectionHeadingProps } from './SectionHeading.js'
|
|
@@ -0,0 +1,197 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Select, type SelectProps, type SelectOption } from './Select.js'
|