cursedbelt 5.28.0 → 5.30.0
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/dist/react/components/ColorField.d.ts.map +1 -1
- package/dist/react/components/ColorField.js +2 -1
- package/dist/react/components/ColorField.js.map +1 -1
- package/dist/react/components/ComboboxField.d.ts.map +1 -1
- package/dist/react/components/ComboboxField.js +2 -1
- package/dist/react/components/ComboboxField.js.map +1 -1
- package/dist/react/components/DataTable/DataTable.d.ts +39 -2
- package/dist/react/components/DataTable/DataTable.d.ts.map +1 -1
- package/dist/react/components/DataTable/DataTable.js +92 -22
- package/dist/react/components/DataTable/DataTable.js.map +1 -1
- package/dist/react/components/DataTable/ViewOptionsMenu.d.ts.map +1 -1
- package/dist/react/components/DataTable/ViewOptionsMenu.js +20 -7
- package/dist/react/components/DataTable/ViewOptionsMenu.js.map +1 -1
- package/dist/react/components/DataTable/types.d.ts +11 -1
- package/dist/react/components/DataTable/types.d.ts.map +1 -1
- package/dist/react/components/DataTable/types.js +6 -0
- package/dist/react/components/DataTable/types.js.map +1 -1
- package/dist/react/components/DatePicker.d.ts.map +1 -1
- package/dist/react/components/DatePicker.js +2 -1
- package/dist/react/components/DatePicker.js.map +1 -1
- package/dist/react/components/DateTimeField.d.ts.map +1 -1
- package/dist/react/components/DateTimeField.js +2 -1
- package/dist/react/components/DateTimeField.js.map +1 -1
- package/dist/react/components/ExpandableRow.d.ts +56 -0
- package/dist/react/components/ExpandableRow.d.ts.map +1 -0
- package/dist/react/components/ExpandableRow.js +54 -0
- package/dist/react/components/ExpandableRow.js.map +1 -0
- package/dist/react/components/Field.d.ts +20 -1
- package/dist/react/components/Field.d.ts.map +1 -1
- package/dist/react/components/Field.js +24 -11
- package/dist/react/components/Field.js.map +1 -1
- package/dist/react/components/FieldInput.d.ts +15 -0
- package/dist/react/components/FieldInput.d.ts.map +1 -1
- package/dist/react/components/FieldInput.js +20 -0
- package/dist/react/components/FieldInput.js.map +1 -1
- package/dist/react/components/FileDropZone.d.ts +23 -1
- package/dist/react/components/FileDropZone.d.ts.map +1 -1
- package/dist/react/components/FileDropZone.js +56 -8
- package/dist/react/components/FileDropZone.js.map +1 -1
- package/dist/react/components/FormPreviewLayout.d.ts +49 -0
- package/dist/react/components/FormPreviewLayout.d.ts.map +1 -0
- package/dist/react/components/FormPreviewLayout.js +36 -0
- package/dist/react/components/FormPreviewLayout.js.map +1 -0
- package/dist/react/components/Input.d.ts.map +1 -1
- package/dist/react/components/Input.js +3 -1
- package/dist/react/components/Input.js.map +1 -1
- package/dist/react/components/KeyBadge.d.ts +34 -0
- package/dist/react/components/KeyBadge.d.ts.map +1 -0
- package/dist/react/components/KeyBadge.js +24 -0
- package/dist/react/components/KeyBadge.js.map +1 -0
- package/dist/react/components/Modal.d.ts.map +1 -1
- package/dist/react/components/Modal.js +35 -9
- package/dist/react/components/Modal.js.map +1 -1
- package/dist/react/components/NativeSelect.d.ts.map +1 -1
- package/dist/react/components/NativeSelect.js +2 -1
- package/dist/react/components/NativeSelect.js.map +1 -1
- package/dist/react/components/RenderField.d.ts.map +1 -1
- package/dist/react/components/RenderField.js +2 -2
- package/dist/react/components/RenderField.js.map +1 -1
- package/dist/react/components/RevealAction.d.ts +33 -0
- package/dist/react/components/RevealAction.d.ts.map +1 -0
- package/dist/react/components/RevealAction.js +45 -0
- package/dist/react/components/RevealAction.js.map +1 -0
- package/dist/react/components/SecretInput.d.ts.map +1 -1
- package/dist/react/components/SecretInput.js +2 -1
- package/dist/react/components/SecretInput.js.map +1 -1
- package/dist/react/components/SelectField.d.ts.map +1 -1
- package/dist/react/components/SelectField.js +2 -1
- package/dist/react/components/SelectField.js.map +1 -1
- package/dist/react/components/SettingsStrip.d.ts +22 -0
- package/dist/react/components/SettingsStrip.d.ts.map +1 -0
- package/dist/react/components/SettingsStrip.js +18 -0
- package/dist/react/components/SettingsStrip.js.map +1 -0
- package/dist/react/components/formKit.css +555 -0
- package/dist/react/components/formKit.d.ts +12 -0
- package/dist/react/components/formKit.d.ts.map +1 -0
- package/dist/react/components/formKit.js +14 -0
- package/dist/react/components/formKit.js.map +1 -0
- package/dist/react/filter-rail/RailSection.d.ts +2 -2
- package/dist/react/filter-rail/RailSection.d.ts.map +1 -1
- package/dist/react/filter-rail/RailSection.js +6 -61
- package/dist/react/filter-rail/RailSection.js.map +1 -1
- package/dist/react/index.d.ts +8 -3
- package/dist/react/index.d.ts.map +1 -1
- package/dist/react/index.js +8 -3
- package/dist/react/index.js.map +1 -1
- package/dist/react/lib/field.d.ts +43 -0
- package/dist/react/lib/field.d.ts.map +1 -1
- package/dist/react/lib/field.js +68 -0
- package/dist/react/lib/field.js.map +1 -1
- package/dist/react/media/PlayerStrip.d.ts +9 -1
- package/dist/react/media/PlayerStrip.d.ts.map +1 -1
- package/dist/react/media/PlayerStrip.js +29 -2
- package/dist/react/media/PlayerStrip.js.map +1 -1
- package/dist/react/media-gallery/rememberedPreference.d.ts +2 -0
- package/dist/react/media-gallery/rememberedPreference.d.ts.map +1 -0
- package/dist/react/media-gallery/rememberedPreference.js +75 -0
- package/dist/react/media-gallery/rememberedPreference.js.map +1 -0
- package/dist/styles-areas/analytics.css +2 -2
- package/dist/styles-areas/core.css +34 -28
- package/dist/styles-areas/data-table.css +2 -2
- package/dist/styles-areas/fields.css +3 -3
- package/dist/styles-areas/layout-engine.css +2 -2
- package/dist/styles-areas/nav.css +3 -3
- package/dist/styles-areas/wizard.css +2 -2
- package/dist/styles-areas/workbench.css +2 -2
- package/dist/styles-utilities.css +111 -9
- package/package.json +14 -1
- package/scripts/styleAreas.ts +2 -0
- package/src/react/components/ColorField.tsx +3 -1
- package/src/react/components/ComboboxField.tsx +3 -1
- package/src/react/components/DataTable/DataTable.spec.tsx +18 -0
- package/src/react/components/DataTable/DataTable.tsx +136 -22
- package/src/react/components/DataTable/ViewOptionsMenu.tsx +24 -9
- package/src/react/components/DataTable/selection.spec.tsx +57 -1
- package/src/react/components/DataTable/types.ts +12 -1
- package/src/react/components/DataTable/virtualize.spec.tsx +20 -0
- package/src/react/components/DatePicker.tsx +3 -1
- package/src/react/components/DateTimeField.tsx +3 -1
- package/src/react/components/ExpandableRow.tsx +146 -0
- package/src/react/components/Field.tsx +89 -13
- package/src/react/components/Field.width.spec.tsx +162 -0
- package/src/react/components/FieldInput.tsx +30 -0
- package/src/react/components/FileDropZone.spec.tsx +65 -0
- package/src/react/components/FileDropZone.tsx +83 -5
- package/src/react/components/FormPreviewLayout.tsx +94 -0
- package/src/react/components/Input.tsx +4 -1
- package/src/react/components/KeyBadge.tsx +52 -0
- package/src/react/components/Modal.tsx +58 -14
- package/src/react/components/NativeSelect.tsx +3 -1
- package/src/react/components/RenderField.tsx +2 -1
- package/src/react/components/RevealAction.tsx +83 -0
- package/src/react/components/SecretInput.tsx +3 -1
- package/src/react/components/SelectField.tsx +3 -1
- package/src/react/components/SettingsStrip.tsx +37 -0
- package/src/react/components/formKit.css +555 -0
- package/src/react/components/formKit.spec.tsx +138 -0
- package/src/react/components/formKit.ts +19 -0
- package/src/react/filter-rail/RailSection.tsx +6 -65
- package/src/react/index.ts +20 -2
- package/src/react/lib/field.ts +93 -0
- package/src/react/media/PlayerStrip.tsx +65 -20
- package/src/react/media/playerStrip.spec.tsx +23 -0
- package/src/react/media-gallery/rememberedPreference.ts +79 -0
- package/src/styles-areas/analytics.css +2 -2
- package/src/styles-areas/core.css +34 -28
- package/src/styles-areas/data-table.css +2 -2
- package/src/styles-areas/fields.css +3 -3
- package/src/styles-areas/layout-engine.css +2 -2
- package/src/styles-areas/nav.css +3 -3
- package/src/styles-areas/wizard.css +2 -2
- package/src/styles-areas/workbench.css +2 -2
- package/src/styles-utilities.css +111 -9
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { ChevronDown } from 'lucide-react';
|
|
2
|
+
import {
|
|
3
|
+
type ElementType,
|
|
4
|
+
type MouseEvent,
|
|
5
|
+
type ReactNode,
|
|
6
|
+
useCallback,
|
|
7
|
+
useId,
|
|
8
|
+
useState,
|
|
9
|
+
} from 'react';
|
|
10
|
+
import { cn } from '../lib/cn.js';
|
|
11
|
+
import './formKit.css';
|
|
12
|
+
|
|
13
|
+
export interface ExpandableRowProps {
|
|
14
|
+
/** The row's identity — a name, or the input that edits it. Always visible. */
|
|
15
|
+
title: ReactNode;
|
|
16
|
+
/** A drag handle, or a glyph. Its presence also indents the settings panel under the title. */
|
|
17
|
+
leading?: ReactNode;
|
|
18
|
+
/**
|
|
19
|
+
* What KIND of thing the row is — a type picker or a type badge. Drawn quiet: a control put
|
|
20
|
+
* here loses its border until hovered or focused, so it confirms the row rather than
|
|
21
|
+
* competing with its name.
|
|
22
|
+
*/
|
|
23
|
+
meta?: ReactNode;
|
|
24
|
+
/**
|
|
25
|
+
* Small indicators that say what is configured inside while the row is collapsed —
|
|
26
|
+
* *Required*, *2 rules*. Without them a collapsed list hides the thing you were looking for.
|
|
27
|
+
*/
|
|
28
|
+
summary?: ReactNode;
|
|
29
|
+
/** Row utilities — reorder, duplicate, delete. Stay visible when collapsed. */
|
|
30
|
+
actions?: ReactNode;
|
|
31
|
+
/** The settings panel. Rendered only while expanded, so a long list stays light. */
|
|
32
|
+
children?: ReactNode;
|
|
33
|
+
/** Controlled open state. */
|
|
34
|
+
expanded?: boolean;
|
|
35
|
+
/** Uncontrolled initial state. Default `false`: collapsed is what makes a long list scannable. */
|
|
36
|
+
defaultExpanded?: boolean;
|
|
37
|
+
onExpandedChange?: (expanded: boolean) => void;
|
|
38
|
+
/** Accessible name of the chevron — default "Settings". It reads "Settings, expanded". */
|
|
39
|
+
toggleLabel?: string;
|
|
40
|
+
/** The element the row renders as. Use `'li'` inside an `<ol>`/`<ul>`. Default `'div'`. */
|
|
41
|
+
as?: 'div' | 'li';
|
|
42
|
+
className?: string;
|
|
43
|
+
'data-testid'?: string;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** Anything a click on the header should leave alone, because it is a control of its own. */
|
|
47
|
+
const INTERACTIVE =
|
|
48
|
+
'button, a[href], input, select, textarea, label, summary, [role="button"], [role="checkbox"], [role="switch"], [role="combobox"], [contenteditable="true"], [data-row-no-toggle]';
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* One row of a builder list — a field in a template, a rule, an env entry — that shows its
|
|
52
|
+
* identity in one compact line and keeps its configuration folded away until asked for.
|
|
53
|
+
*
|
|
54
|
+
* The owner's cb-form review (2026-09-30), on a template with 24 fields each drawn wide open:
|
|
55
|
+
* *"everything is given the exact same visual weight … when every setting is wide open the form
|
|
56
|
+
* becomes exceptionally tall."* So a row is two tiers:
|
|
57
|
+
*
|
|
58
|
+
* - **The header** — `leading` (a drag handle), `title` (the name), `summary` (what is set
|
|
59
|
+
* inside), `meta` (the type, drawn quiet), `actions` and a chevron. A click anywhere on the
|
|
60
|
+
* header that is not itself a control toggles it, as a row in Linear or Notion does.
|
|
61
|
+
* - **The panel** — `children`, indented under the title on a hairline, only while expanded.
|
|
62
|
+
*
|
|
63
|
+
* It lays itself out by its CONTAINER's width, not the viewport's: under 30rem the header
|
|
64
|
+
* becomes a block (handle · name · chevron, then the type, then a utility strip of actions),
|
|
65
|
+
* which is the phone layout and also the narrow-side-panel layout on a desktop.
|
|
66
|
+
*
|
|
67
|
+
* Draws from its own plain stylesheet (`formKit.css`), so it works in an app with no Tailwind —
|
|
68
|
+
* reach it through `cursedbelt/react/form-kit` there.
|
|
69
|
+
*/
|
|
70
|
+
export function ExpandableRow({
|
|
71
|
+
title,
|
|
72
|
+
leading,
|
|
73
|
+
meta,
|
|
74
|
+
summary,
|
|
75
|
+
actions,
|
|
76
|
+
children,
|
|
77
|
+
expanded: controlled,
|
|
78
|
+
defaultExpanded = false,
|
|
79
|
+
onExpandedChange,
|
|
80
|
+
toggleLabel = 'Settings',
|
|
81
|
+
as = 'div',
|
|
82
|
+
className,
|
|
83
|
+
'data-testid': testId,
|
|
84
|
+
}: ExpandableRowProps) {
|
|
85
|
+
const [uncontrolled, setUncontrolled] = useState(defaultExpanded);
|
|
86
|
+
const expanded = controlled ?? uncontrolled;
|
|
87
|
+
const panelId = useId();
|
|
88
|
+
|
|
89
|
+
const setExpanded = useCallback(
|
|
90
|
+
(next: boolean) => {
|
|
91
|
+
if (controlled === undefined) setUncontrolled(next);
|
|
92
|
+
onExpandedChange?.(next);
|
|
93
|
+
},
|
|
94
|
+
[controlled, onExpandedChange],
|
|
95
|
+
);
|
|
96
|
+
|
|
97
|
+
const onHeaderClick = (event: MouseEvent<HTMLDivElement>) => {
|
|
98
|
+
const target = event.target as Element | null;
|
|
99
|
+
// A control inside the header does its own job; only the row's bare surface toggles.
|
|
100
|
+
if (target && target !== event.currentTarget && target.closest(INTERACTIVE)) return;
|
|
101
|
+
// A text selection that ended here is somebody copying a name, not asking to expand.
|
|
102
|
+
if (typeof window !== 'undefined' && window.getSelection()?.toString()) return;
|
|
103
|
+
setExpanded(!expanded);
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
const Root = as as ElementType;
|
|
107
|
+
const hasPanel = children !== undefined && children !== null && children !== false;
|
|
108
|
+
|
|
109
|
+
return (
|
|
110
|
+
<Root
|
|
111
|
+
className={cn('cbfk-row', className)}
|
|
112
|
+
data-expanded={expanded && hasPanel ? 'true' : 'false'}
|
|
113
|
+
data-has-lead={leading ? 'true' : undefined}
|
|
114
|
+
data-testid={testId}
|
|
115
|
+
>
|
|
116
|
+
{/* biome-ignore lint/a11y/useKeyWithClickEvents: the chevron is the keyboard path — this click is the pointer's larger target for the same toggle. */}
|
|
117
|
+
{/* biome-ignore lint/a11y/noStaticElementInteractions: see above; the row surface is not a control of its own. */}
|
|
118
|
+
<div className='cbfk-row-head' onClick={hasPanel ? onHeaderClick : undefined}>
|
|
119
|
+
{leading ? <span className='cbfk-row-lead'>{leading}</span> : null}
|
|
120
|
+
<div className='cbfk-row-title'>{title}</div>
|
|
121
|
+
{summary ? <span className='cbfk-row-summary'>{summary}</span> : null}
|
|
122
|
+
{meta ? <span className='cbfk-row-meta'>{meta}</span> : null}
|
|
123
|
+
{actions ? <span className='cbfk-row-actions'>{actions}</span> : null}
|
|
124
|
+
{hasPanel ? (
|
|
125
|
+
<button
|
|
126
|
+
// guardrails-ignore no-raw-action-button: the disclosure chevron — presentational
|
|
127
|
+
// expand/collapse, no data-mutating intent; it must draw without Tailwind.
|
|
128
|
+
type='button'
|
|
129
|
+
className='cbfk-row-toggle'
|
|
130
|
+
aria-label={toggleLabel}
|
|
131
|
+
aria-expanded={expanded}
|
|
132
|
+
aria-controls={expanded ? panelId : undefined}
|
|
133
|
+
onClick={() => setExpanded(!expanded)}
|
|
134
|
+
>
|
|
135
|
+
<ChevronDown aria-hidden />
|
|
136
|
+
</button>
|
|
137
|
+
) : null}
|
|
138
|
+
</div>
|
|
139
|
+
{hasPanel && expanded ? (
|
|
140
|
+
<div id={panelId} className='cbfk-row-panel'>
|
|
141
|
+
{children}
|
|
142
|
+
</div>
|
|
143
|
+
) : null}
|
|
144
|
+
</Root>
|
|
145
|
+
);
|
|
146
|
+
}
|
|
@@ -2,8 +2,16 @@ import { AlertCircle } from 'lucide-react';
|
|
|
2
2
|
import { cloneElement, isValidElement, type ReactElement, type ReactNode } from 'react';
|
|
3
3
|
import { get, useFormContext } from 'react-hook-form';
|
|
4
4
|
import { cn } from '../lib/cn.js';
|
|
5
|
+
import {
|
|
6
|
+
DESCRIPTION_FOLD_CHARS,
|
|
7
|
+
FIELD_WIDTH_CLASS,
|
|
8
|
+
type FieldWidth,
|
|
9
|
+
naturalFieldWidth,
|
|
10
|
+
} from '../lib/field.js';
|
|
5
11
|
import { InfoHint } from './InfoHint.js';
|
|
6
12
|
|
|
13
|
+
export { DESCRIPTION_FOLD_CHARS };
|
|
14
|
+
|
|
7
15
|
/** The id + aria a control needs to be wired to its label, description, and error.
|
|
8
16
|
* Injected into a single child via `cloneElement`, or handed to a render-prop child
|
|
9
17
|
* (e.g. inside a `<Controller>`, where cloneElement can't reach the real control). */
|
|
@@ -45,6 +53,23 @@ export interface FieldProps {
|
|
|
45
53
|
* reachability gate caught exactly that: "Create an account" did nothing.
|
|
46
54
|
*/
|
|
47
55
|
reserveErrorSpace?: boolean;
|
|
56
|
+
/**
|
|
57
|
+
* How wide the CONTROL may grow — a cap, never a fixed width (see {@link FieldWidth}). The
|
|
58
|
+
* label, description and error keep the row's full width.
|
|
59
|
+
*
|
|
60
|
+
* Omitted, it is read off the control: a one-line text input or select is `md` (28rem), a
|
|
61
|
+
* number `xs`, a date `sm`, a URL `lg`, and anything multi-line, composite or built in a
|
|
62
|
+
* render-prop is `full` — so a short field no longer stretches across a wide dialog, and a
|
|
63
|
+
* textarea still does. A control declares its own with `declareFieldWidth`.
|
|
64
|
+
*/
|
|
65
|
+
width?: FieldWidth;
|
|
66
|
+
/**
|
|
67
|
+
* What a phone does with `description` (below the `sm` breakpoint). `'auto'` (default) folds a
|
|
68
|
+
* description longer than {@link DESCRIPTION_FOLD_CHARS} into the label's ⓘ, because on a
|
|
69
|
+
* short viewport a paragraph under every field pushes the rest of the form out of sight
|
|
70
|
+
* (DESIGN.md §4, *Help Context Disclosing*). `'inline'` always shows it; `'hint'` always folds.
|
|
71
|
+
*/
|
|
72
|
+
descriptionOnNarrow?: 'auto' | 'inline' | 'hint';
|
|
48
73
|
}
|
|
49
74
|
|
|
50
75
|
/**
|
|
@@ -74,6 +99,8 @@ export function Field({
|
|
|
74
99
|
children,
|
|
75
100
|
className,
|
|
76
101
|
reserveErrorSpace = false,
|
|
102
|
+
width,
|
|
103
|
+
descriptionOnNarrow = 'auto',
|
|
77
104
|
}: FieldProps) {
|
|
78
105
|
const form = useFormContext();
|
|
79
106
|
const errors = form?.formState.errors;
|
|
@@ -91,9 +118,34 @@ export function Field({
|
|
|
91
118
|
'aria-describedby': describedBy,
|
|
92
119
|
};
|
|
93
120
|
|
|
121
|
+
const resolvedWidth: FieldWidth =
|
|
122
|
+
width ??
|
|
123
|
+
(typeof children !== 'function' && isValidElement(children)
|
|
124
|
+
? naturalFieldWidth(children.type, (children.props ?? {}) as Record<string, unknown>)
|
|
125
|
+
: 'full');
|
|
126
|
+
const widthClass = FIELD_WIDTH_CLASS[resolvedWidth];
|
|
127
|
+
|
|
128
|
+
const folds =
|
|
129
|
+
description != null &&
|
|
130
|
+
(descriptionOnNarrow === 'hint' ||
|
|
131
|
+
(descriptionOnNarrow === 'auto' &&
|
|
132
|
+
typeof description === 'string' &&
|
|
133
|
+
description.length > DESCRIPTION_FOLD_CHARS));
|
|
134
|
+
|
|
135
|
+
const control =
|
|
136
|
+
typeof children === 'function'
|
|
137
|
+
? children(aria)
|
|
138
|
+
: isValidElement(children)
|
|
139
|
+
? cloneElement(children, {
|
|
140
|
+
id,
|
|
141
|
+
'aria-invalid': aria['aria-invalid'],
|
|
142
|
+
'aria-describedby': describedBy,
|
|
143
|
+
} as Partial<Record<string, unknown>>)
|
|
144
|
+
: children;
|
|
145
|
+
|
|
94
146
|
return (
|
|
95
|
-
<div className={cn('flex flex-col gap-1.5', className)}>
|
|
96
|
-
{label != null || hint != null ? (
|
|
147
|
+
<div className={cn('flex flex-col gap-1.5', className)} data-cb-field-width={resolvedWidth}>
|
|
148
|
+
{label != null || hint != null || folds ? (
|
|
97
149
|
<div className='flex items-center gap-1'>
|
|
98
150
|
{label != null ? (
|
|
99
151
|
<label htmlFor={id} className='text-sm font-medium text-foreground'>
|
|
@@ -106,27 +158,51 @@ export function Field({
|
|
|
106
158
|
) : null}
|
|
107
159
|
</label>
|
|
108
160
|
) : null}
|
|
109
|
-
{hint != null ? (
|
|
161
|
+
{hint != null && !folds ? (
|
|
110
162
|
<InfoHint title={typeof label === 'string' ? label : undefined}>{hint}</InfoHint>
|
|
111
163
|
) : null}
|
|
164
|
+
{folds ? (
|
|
165
|
+
// Two triggers, one shown per breakpoint: wide screens keep `hint` alone in the ⓘ
|
|
166
|
+
// (the description is on screen below), a phone gets the description folded in.
|
|
167
|
+
<>
|
|
168
|
+
{hint != null ? (
|
|
169
|
+
<span className='inline-flex max-sm:hidden'>
|
|
170
|
+
<InfoHint title={typeof label === 'string' ? label : undefined}>{hint}</InfoHint>
|
|
171
|
+
</span>
|
|
172
|
+
) : null}
|
|
173
|
+
<span className='inline-flex sm:hidden'>
|
|
174
|
+
<InfoHint title={typeof label === 'string' ? label : undefined}>
|
|
175
|
+
{hint != null ? <p className='mb-1'>{hint}</p> : null}
|
|
176
|
+
{description}
|
|
177
|
+
</InfoHint>
|
|
178
|
+
</span>
|
|
179
|
+
</>
|
|
180
|
+
) : null}
|
|
112
181
|
</div>
|
|
113
182
|
) : null}
|
|
114
183
|
|
|
115
184
|
{description != null ? (
|
|
116
|
-
|
|
185
|
+
// Help copy recedes behind the label and the value: 12px, regular weight, muted.
|
|
186
|
+
// `aria-describedby` still reaches it when a phone hides it — a referenced node is
|
|
187
|
+
// read whether or not it is displayed.
|
|
188
|
+
<p
|
|
189
|
+
id={descId}
|
|
190
|
+
className={cn(
|
|
191
|
+
'text-xs font-normal leading-snug text-muted-foreground',
|
|
192
|
+
folds && 'max-sm:hidden',
|
|
193
|
+
)}
|
|
194
|
+
>
|
|
117
195
|
{description}
|
|
118
196
|
</p>
|
|
119
197
|
) : null}
|
|
120
198
|
|
|
121
|
-
{
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
} as Partial<Record<string, unknown>>)
|
|
129
|
-
: children}
|
|
199
|
+
{widthClass ? (
|
|
200
|
+
<div className={cn('w-full', widthClass)} data-cb-field-control=''>
|
|
201
|
+
{control}
|
|
202
|
+
</div>
|
|
203
|
+
) : (
|
|
204
|
+
control
|
|
205
|
+
)}
|
|
130
206
|
|
|
131
207
|
{error ? (
|
|
132
208
|
<p id={errId} role='alert' className='flex items-center gap-1.5 text-sm text-field-error'>
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import { afterEach, describe, expect, test } from 'bun:test';
|
|
2
|
+
import { cleanup, render } from '@testing-library/react';
|
|
3
|
+
import { declareFieldWidth, inputTypeWidth, naturalFieldWidth } from '../lib/field.js';
|
|
4
|
+
import { DESCRIPTION_FOLD_CHARS, Field } from './Field.js';
|
|
5
|
+
import { fieldSpecWidth } from './FieldInput.js';
|
|
6
|
+
import { Input } from './Input.js';
|
|
7
|
+
import { NativeSelect } from './NativeSelect.js';
|
|
8
|
+
|
|
9
|
+
afterEach(cleanup);
|
|
10
|
+
|
|
11
|
+
// The owner's cb-form review (2026-09-30): a short control is capped by what it holds, a wide
|
|
12
|
+
// one keeps the row — and the cap lives on the control's wrapper, never on the label.
|
|
13
|
+
describe('Field width', () => {
|
|
14
|
+
const widthOf = (container: HTMLElement) =>
|
|
15
|
+
container.querySelector('[data-cb-field-width]')?.getAttribute('data-cb-field-width');
|
|
16
|
+
|
|
17
|
+
test('a text Input is md, and only the control is capped', () => {
|
|
18
|
+
const { container } = render(
|
|
19
|
+
<Field name='name' label='Name' description='What it is called'>
|
|
20
|
+
<Input />
|
|
21
|
+
</Field>,
|
|
22
|
+
);
|
|
23
|
+
expect(widthOf(container)).toBe('md');
|
|
24
|
+
const wrap = container.querySelector('[data-cb-field-control]');
|
|
25
|
+
expect(wrap?.className).toContain('max-w-md');
|
|
26
|
+
expect(wrap?.querySelector('input')).not.toBeNull();
|
|
27
|
+
expect(wrap?.contains(container.querySelector('label'))).toBe(false);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
test('an Input answers from its type — number xs, date sm, url lg', () => {
|
|
31
|
+
for (const [type, width] of [
|
|
32
|
+
['number', 'xs'],
|
|
33
|
+
['date', 'sm'],
|
|
34
|
+
['url', 'lg'],
|
|
35
|
+
] as const) {
|
|
36
|
+
const { container, unmount } = render(
|
|
37
|
+
<Field name={type} label={type}>
|
|
38
|
+
<Input type={type} />
|
|
39
|
+
</Field>,
|
|
40
|
+
);
|
|
41
|
+
expect(widthOf(container)).toBe(width);
|
|
42
|
+
unmount();
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
test('a NativeSelect is md; a textarea and a render-prop stay full, with no wrapper', () => {
|
|
47
|
+
const select = render(
|
|
48
|
+
<Field name='s' label='S'>
|
|
49
|
+
<NativeSelect options={[{ value: 'a', label: 'A' }]} />
|
|
50
|
+
</Field>,
|
|
51
|
+
);
|
|
52
|
+
expect(widthOf(select.container)).toBe('md');
|
|
53
|
+
select.unmount();
|
|
54
|
+
|
|
55
|
+
const area = render(
|
|
56
|
+
<Field name='t' label='T'>
|
|
57
|
+
<textarea
|
|
58
|
+
// guardrails-ignore no-raw-inputs: test fixture, not product UI
|
|
59
|
+
/>
|
|
60
|
+
</Field>,
|
|
61
|
+
);
|
|
62
|
+
expect(widthOf(area.container)).toBe('full');
|
|
63
|
+
expect(area.container.querySelector('[data-cb-field-control]')).toBeNull();
|
|
64
|
+
area.unmount();
|
|
65
|
+
|
|
66
|
+
const prop = render(
|
|
67
|
+
<Field name='r' label='R'>
|
|
68
|
+
{(aria) => (
|
|
69
|
+
<input
|
|
70
|
+
// guardrails-ignore no-raw-inputs: test fixture, not product UI
|
|
71
|
+
{...aria}
|
|
72
|
+
/>
|
|
73
|
+
)}
|
|
74
|
+
</Field>,
|
|
75
|
+
);
|
|
76
|
+
expect(widthOf(prop.container)).toBe('full');
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
test('an explicit width wins over the control', () => {
|
|
80
|
+
const { container } = render(
|
|
81
|
+
<Field name='n' label='N' width='full'>
|
|
82
|
+
<Input />
|
|
83
|
+
</Field>,
|
|
84
|
+
);
|
|
85
|
+
expect(widthOf(container)).toBe('full');
|
|
86
|
+
expect(container.querySelector('[data-cb-field-control]')).toBeNull();
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
test('an app control declares its own width', () => {
|
|
90
|
+
function Stars(_props: { max: number }) {
|
|
91
|
+
return <span />;
|
|
92
|
+
}
|
|
93
|
+
declareFieldWidth(Stars, (props) => (Number(props.max) > 5 ? 'md' : 'sm'));
|
|
94
|
+
expect(naturalFieldWidth(Stars, { max: 5 })).toBe('sm');
|
|
95
|
+
expect(naturalFieldWidth(Stars, { max: 10 })).toBe('md');
|
|
96
|
+
expect(naturalFieldWidth(() => null, {})).toBe('full');
|
|
97
|
+
expect(inputTypeWidth(undefined)).toBe('md');
|
|
98
|
+
expect(inputTypeWidth('checkbox')).toBe('full');
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
test('a schema field takes its registered type width, and a spec may override it', () => {
|
|
102
|
+
expect(fieldSpecWidth({ key: 'a', type: 'text' })).toBe('md');
|
|
103
|
+
expect(fieldSpecWidth({ key: 'a', type: 'number' })).toBe('xs');
|
|
104
|
+
expect(fieldSpecWidth({ key: 'a', type: 'longtext' })).toBe('full');
|
|
105
|
+
expect(fieldSpecWidth({ key: 'a', type: 'text', width: 'lg' })).toBe('lg');
|
|
106
|
+
expect(fieldSpecWidth({ key: 'a', type: 'no-such-type' })).toBe('md');
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
describe('Field description', () => {
|
|
111
|
+
const long = 'x'.repeat(DESCRIPTION_FOLD_CHARS + 1);
|
|
112
|
+
|
|
113
|
+
test('recedes — 12px, regular weight, muted', () => {
|
|
114
|
+
const { container } = render(
|
|
115
|
+
<Field name='d' label='D' description='Short.'>
|
|
116
|
+
<Input />
|
|
117
|
+
</Field>,
|
|
118
|
+
);
|
|
119
|
+
const p = container.querySelector('#cb-f-d-desc');
|
|
120
|
+
expect(p?.className).toContain('text-xs');
|
|
121
|
+
expect(p?.className).toContain('font-normal');
|
|
122
|
+
expect(p?.className).toContain('text-muted-foreground');
|
|
123
|
+
// Short: never folded, so no phone-only ⓘ.
|
|
124
|
+
expect(p?.className).not.toContain('max-sm:hidden');
|
|
125
|
+
expect(container.querySelectorAll('button[aria-label="More info"]').length).toBe(0);
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
test('a long one folds into an ⓘ on a phone, and stays described', () => {
|
|
129
|
+
const { container } = render(
|
|
130
|
+
<Field name='d' label='D' description={long}>
|
|
131
|
+
<Input />
|
|
132
|
+
</Field>,
|
|
133
|
+
);
|
|
134
|
+
const p = container.querySelector('#cb-f-d-desc');
|
|
135
|
+
expect(p?.className).toContain('max-sm:hidden');
|
|
136
|
+
expect(container.querySelectorAll('button[aria-label="More info"]').length).toBe(1);
|
|
137
|
+
expect(container.querySelector('input')?.getAttribute('aria-describedby')).toBe('cb-f-d-desc');
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
test("descriptionOnNarrow='inline' keeps even a long one on screen", () => {
|
|
141
|
+
const { container } = render(
|
|
142
|
+
<Field name='d' label='D' description={long} descriptionOnNarrow='inline'>
|
|
143
|
+
<Input />
|
|
144
|
+
</Field>,
|
|
145
|
+
);
|
|
146
|
+
expect(container.querySelector('#cb-f-d-desc')?.className).not.toContain('max-sm:hidden');
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
test('with a hint too: one ⓘ per breakpoint, never two on screen', () => {
|
|
150
|
+
const { container } = render(
|
|
151
|
+
<Field name='d' label='D' hint='Why' description={long}>
|
|
152
|
+
<Input />
|
|
153
|
+
</Field>,
|
|
154
|
+
);
|
|
155
|
+
const hosts = [...container.querySelectorAll('button[aria-label="More info"]')].map(
|
|
156
|
+
(b) => b.parentElement?.className ?? '',
|
|
157
|
+
);
|
|
158
|
+
expect(hosts.length).toBe(2);
|
|
159
|
+
expect(hosts.some((c) => c.includes('max-sm:hidden'))).toBe(true);
|
|
160
|
+
expect(hosts.some((c) => c.includes('sm:hidden') && !c.includes('max-sm:hidden'))).toBe(true);
|
|
161
|
+
});
|
|
162
|
+
});
|
|
@@ -32,6 +32,7 @@ import { SelectField } from './SelectField.js';
|
|
|
32
32
|
import { Slider } from './Slider.js';
|
|
33
33
|
import { Switch } from './Switch.js';
|
|
34
34
|
import { TagsInput } from './TagsInput.js';
|
|
35
|
+
import type { FieldWidth } from '../lib/field.js';
|
|
35
36
|
|
|
36
37
|
/** A choice for select / multiselect / tags-like types. */
|
|
37
38
|
export interface FieldOption {
|
|
@@ -66,6 +67,8 @@ export interface FieldSpec {
|
|
|
66
67
|
step?: number;
|
|
67
68
|
/** App-specific config a custom control reads (column settings, language, etc.). */
|
|
68
69
|
meta?: Record<string, unknown>;
|
|
70
|
+
/** Overrides the registered type's {@link FieldRegistryEntry.width} for this one field. */
|
|
71
|
+
width?: FieldWidth;
|
|
69
72
|
}
|
|
70
73
|
|
|
71
74
|
/**
|
|
@@ -93,6 +96,12 @@ export type FieldControl = FC<ControlProps>;
|
|
|
93
96
|
* the rebuilt column editor (task 34) renders as a dead-simple inline add button. */
|
|
94
97
|
export interface FieldRegistryEntry {
|
|
95
98
|
control: FieldControl;
|
|
99
|
+
/**
|
|
100
|
+
* How wide a {@link Field} lets this type's control grow — see {@link FieldWidth}. Omitted is
|
|
101
|
+
* `full`, which is right for anything multi-line or composite and is what an app-registered
|
|
102
|
+
* type drew before widths existed.
|
|
103
|
+
*/
|
|
104
|
+
width?: FieldWidth;
|
|
96
105
|
/** Inline "Add an X field" entry point with a sensible-default spec factory. */
|
|
97
106
|
addFieldAffordance?: {
|
|
98
107
|
label: string;
|
|
@@ -343,6 +352,7 @@ const spec = (type: string, label: string, extra: Partial<FieldSpec> = {}): Fiel
|
|
|
343
352
|
*/
|
|
344
353
|
const BASE_REGISTRY: Record<string, FieldRegistryEntry> = {
|
|
345
354
|
text: {
|
|
355
|
+
width: 'md',
|
|
346
356
|
control: TextControl,
|
|
347
357
|
addFieldAffordance: { label: 'Text', icon: <Type />, defaultSpec: () => spec('text', 'Text') },
|
|
348
358
|
},
|
|
@@ -355,6 +365,7 @@ const BASE_REGISTRY: Record<string, FieldRegistryEntry> = {
|
|
|
355
365
|
},
|
|
356
366
|
},
|
|
357
367
|
number: {
|
|
368
|
+
width: 'xs',
|
|
358
369
|
control: NumberControl,
|
|
359
370
|
addFieldAffordance: {
|
|
360
371
|
label: 'Number',
|
|
@@ -363,6 +374,7 @@ const BASE_REGISTRY: Record<string, FieldRegistryEntry> = {
|
|
|
363
374
|
},
|
|
364
375
|
},
|
|
365
376
|
date: {
|
|
377
|
+
width: 'sm',
|
|
366
378
|
control: DateControl,
|
|
367
379
|
addFieldAffordance: {
|
|
368
380
|
label: 'Date',
|
|
@@ -371,6 +383,7 @@ const BASE_REGISTRY: Record<string, FieldRegistryEntry> = {
|
|
|
371
383
|
},
|
|
372
384
|
},
|
|
373
385
|
datetime: {
|
|
386
|
+
width: 'sm',
|
|
374
387
|
control: DateTimeControl,
|
|
375
388
|
addFieldAffordance: {
|
|
376
389
|
label: 'Date & time',
|
|
@@ -379,6 +392,7 @@ const BASE_REGISTRY: Record<string, FieldRegistryEntry> = {
|
|
|
379
392
|
},
|
|
380
393
|
},
|
|
381
394
|
url: {
|
|
395
|
+
width: 'lg',
|
|
382
396
|
control: UrlControl,
|
|
383
397
|
addFieldAffordance: {
|
|
384
398
|
label: 'Link',
|
|
@@ -395,6 +409,7 @@ const BASE_REGISTRY: Record<string, FieldRegistryEntry> = {
|
|
|
395
409
|
},
|
|
396
410
|
},
|
|
397
411
|
select: {
|
|
412
|
+
width: 'md',
|
|
398
413
|
control: SelectControl,
|
|
399
414
|
addFieldAffordance: {
|
|
400
415
|
label: 'Choice',
|
|
@@ -415,6 +430,7 @@ const BASE_REGISTRY: Record<string, FieldRegistryEntry> = {
|
|
|
415
430
|
addFieldAffordance: { label: 'Tags', icon: <Tag />, defaultSpec: () => spec('tags', 'Tags') },
|
|
416
431
|
},
|
|
417
432
|
slider: {
|
|
433
|
+
width: 'md',
|
|
418
434
|
control: SliderControl,
|
|
419
435
|
addFieldAffordance: {
|
|
420
436
|
label: 'Slider',
|
|
@@ -423,6 +439,7 @@ const BASE_REGISTRY: Record<string, FieldRegistryEntry> = {
|
|
|
423
439
|
},
|
|
424
440
|
},
|
|
425
441
|
color: {
|
|
442
|
+
width: 'sm',
|
|
426
443
|
control: ColorControl,
|
|
427
444
|
addFieldAffordance: {
|
|
428
445
|
label: 'Color',
|
|
@@ -431,6 +448,7 @@ const BASE_REGISTRY: Record<string, FieldRegistryEntry> = {
|
|
|
431
448
|
},
|
|
432
449
|
},
|
|
433
450
|
rating: {
|
|
451
|
+
width: 'sm',
|
|
434
452
|
control: RatingControl,
|
|
435
453
|
addFieldAffordance: {
|
|
436
454
|
label: 'Rating',
|
|
@@ -439,6 +457,7 @@ const BASE_REGISTRY: Record<string, FieldRegistryEntry> = {
|
|
|
439
457
|
},
|
|
440
458
|
},
|
|
441
459
|
emoji: {
|
|
460
|
+
width: 'xs',
|
|
442
461
|
control: EmojiControl,
|
|
443
462
|
addFieldAffordance: {
|
|
444
463
|
label: 'Emoji',
|
|
@@ -447,6 +466,7 @@ const BASE_REGISTRY: Record<string, FieldRegistryEntry> = {
|
|
|
447
466
|
},
|
|
448
467
|
},
|
|
449
468
|
password: {
|
|
469
|
+
width: 'md',
|
|
450
470
|
control: PasswordControl,
|
|
451
471
|
addFieldAffordance: {
|
|
452
472
|
label: 'Secret',
|
|
@@ -463,6 +483,7 @@ const BASE_REGISTRY: Record<string, FieldRegistryEntry> = {
|
|
|
463
483
|
},
|
|
464
484
|
},
|
|
465
485
|
combobox: {
|
|
486
|
+
width: 'md',
|
|
466
487
|
control: ComboboxControl,
|
|
467
488
|
addFieldAffordance: {
|
|
468
489
|
label: 'Combobox',
|
|
@@ -489,6 +510,15 @@ export function getFieldType(type: string): FieldRegistryEntry | undefined {
|
|
|
489
510
|
return FIELD_REGISTRY[type];
|
|
490
511
|
}
|
|
491
512
|
|
|
513
|
+
/**
|
|
514
|
+
* The width a {@link Field} should give this spec's control: the spec's own `width`, else its
|
|
515
|
+
* registered type's, else `full`. {@link RenderField} passes it; a hand-built form over
|
|
516
|
+
* `FieldInput` can too.
|
|
517
|
+
*/
|
|
518
|
+
export function fieldSpecWidth(spec: FieldSpec): FieldWidth {
|
|
519
|
+
return spec.width ?? (FIELD_REGISTRY[spec.type] ?? FIELD_REGISTRY.text)?.width ?? 'full';
|
|
520
|
+
}
|
|
521
|
+
|
|
492
522
|
/** Every registered type key (base + app-injected) — drives the column editor's
|
|
493
523
|
* type picker and the "add a field" affordance menu. */
|
|
494
524
|
export function listFieldTypes(): string[] {
|
|
@@ -221,6 +221,12 @@ describe('FileDropZone', () => {
|
|
|
221
221
|
const got = result as { accepted: File[]; rejected: File[] } | null;
|
|
222
222
|
expect(got?.accepted.map((f) => f.name)).toEqual(['Loaded.cue', 'Loaded (Track 01).bin', 'Loaded (Track 02).bin']);
|
|
223
223
|
expect(got?.rejected).toEqual([]);
|
|
224
|
+
// Each file keeps its path from the dropped folder, as a folder PICKER's files do natively.
|
|
225
|
+
expect(got?.accepted.map((f) => f.webkitRelativePath)).toEqual([
|
|
226
|
+
'Loaded (USA) (En,Fr)/Loaded (USA) (En,Fr)/Loaded.cue',
|
|
227
|
+
'Loaded (USA) (En,Fr)/Loaded (USA) (En,Fr)/Loaded (Track 01).bin',
|
|
228
|
+
'Loaded (USA) (En,Fr)/Loaded (USA) (En,Fr)/Loaded (Track 02).bin',
|
|
229
|
+
]);
|
|
224
230
|
});
|
|
225
231
|
|
|
226
232
|
test('a folder with nothing acceptable in it is still a refusal, under its own name — never silence', async () => {
|
|
@@ -241,6 +247,65 @@ describe('FileDropZone', () => {
|
|
|
241
247
|
});
|
|
242
248
|
});
|
|
243
249
|
|
|
250
|
+
describe('the folder picker', () => {
|
|
251
|
+
/** A folder pick's files, as a browser hands them over: each with its path from the picked folder. */
|
|
252
|
+
const picked = (paths: string[]) =>
|
|
253
|
+
paths.map((path) => {
|
|
254
|
+
const f = file(path.split('/').pop() as string, '');
|
|
255
|
+
Object.defineProperty(f, 'webkitRelativePath', { value: path });
|
|
256
|
+
return f;
|
|
257
|
+
});
|
|
258
|
+
|
|
259
|
+
test("browse='both' is two real Buttons OUTSIDE the label — a folder press must not also open the file picker", () => {
|
|
260
|
+
const { container, getByRole } = render(<FileDropZone browse='both' onFiles={() => {}} />);
|
|
261
|
+
const folderButton = getByRole('button', { name: 'Choose a folder…' });
|
|
262
|
+
const filesButton = getByRole('button', { name: 'Choose files…' });
|
|
263
|
+
expect(folderButton.closest('label')).toBeNull();
|
|
264
|
+
expect(filesButton.closest('label')).toBeNull();
|
|
265
|
+
const inputs = [...container.querySelectorAll('input[type="file"]')] as HTMLInputElement[];
|
|
266
|
+
expect(inputs.filter((i) => i.hasAttribute('webkitdirectory'))).toHaveLength(1);
|
|
267
|
+
// The Buttons are the keyboard path, so the zone-sized input leaves the Tab order.
|
|
268
|
+
expect(inputs.every((i) => i.tabIndex === -1)).toBe(true);
|
|
269
|
+
});
|
|
270
|
+
|
|
271
|
+
test("each Button opens ITS picker", () => {
|
|
272
|
+
const { container, getByRole } = render(<FileDropZone browse='both' onFiles={() => {}} />);
|
|
273
|
+
const [zoneInput, folderInput] = [...container.querySelectorAll('input[type="file"]')] as HTMLInputElement[];
|
|
274
|
+
const opened: string[] = [];
|
|
275
|
+
zoneInput?.addEventListener('click', (e) => { e.preventDefault(); opened.push('files'); });
|
|
276
|
+
folderInput?.addEventListener('click', (e) => { e.preventDefault(); opened.push('folder'); });
|
|
277
|
+
fireEvent.click(getByRole('button', { name: 'Choose a folder…' }));
|
|
278
|
+
fireEvent.click(getByRole('button', { name: 'Choose files…' }));
|
|
279
|
+
expect(opened).toEqual(['folder', 'files']);
|
|
280
|
+
});
|
|
281
|
+
|
|
282
|
+
test('a picked folder is filtered like a dropped one — readme and hidden files skipped, paths kept', () => {
|
|
283
|
+
let received: File[] = [];
|
|
284
|
+
const { container } = render(<FileDropZone browse='both' accept='.mp3' onFiles={(f) => (received = f)} />);
|
|
285
|
+
const folderInput = container.querySelector('input[webkitdirectory]') as HTMLInputElement;
|
|
286
|
+
fireEvent.change(folderInput, {
|
|
287
|
+
target: { files: picked(['Rip/cover.jpg', 'Rip/.hidden/x.mp3', 'Rip/CD1/01.mp3', 'Rip/CD2/01.mp3']) },
|
|
288
|
+
});
|
|
289
|
+
expect(received.map((f) => f.webkitRelativePath)).toEqual(['Rip/CD1/01.mp3', 'Rip/CD2/01.mp3']);
|
|
290
|
+
});
|
|
291
|
+
|
|
292
|
+
test('a picked folder with nothing acceptable is refused under its own name', () => {
|
|
293
|
+
let rejected: File[] = [];
|
|
294
|
+
const { container } = render(
|
|
295
|
+
<FileDropZone browse='folder' accept='.mp3' onFiles={() => {}} onRejected={(f) => (rejected = f)} />,
|
|
296
|
+
);
|
|
297
|
+
const input = container.querySelector('input[webkitdirectory]') as HTMLInputElement;
|
|
298
|
+
fireEvent.change(input, { target: { files: picked(['Scans/a.png', 'Scans/b.png']) } });
|
|
299
|
+
expect(rejected.map((f) => f.name)).toEqual(['Scans']);
|
|
300
|
+
});
|
|
301
|
+
|
|
302
|
+
test("the default zone has no folder picker and no Buttons", () => {
|
|
303
|
+
const { container, queryByRole } = render(<FileDropZone onFiles={() => {}} />);
|
|
304
|
+
expect(container.querySelector('input[webkitdirectory]')).toBeNull();
|
|
305
|
+
expect(queryByRole('button')).toBeNull();
|
|
306
|
+
});
|
|
307
|
+
});
|
|
308
|
+
|
|
244
309
|
test('renders custom children and the default hint otherwise', () => {
|
|
245
310
|
const { getByText, rerender } = render(
|
|
246
311
|
<FileDropZone onFiles={() => {}}>
|