Skip to content

An open source design system that's fully customizable and agent ready

TypeScript

docs(ListInput): add a docsite showcase and three example blocks (#7953)

Ernestfaa934f8c61f
diff --git a/.changeset/discover-data-list-the-lab-listinput-blocks-the--bqb4.md b/.changeset/discover-data-list-the-lab-listinput-blocks-the--bqb4.md
new file mode 100644
index 0000000000..8359abf942
--- /dev/null
+++ b/.changeset/discover-data-list-the-lab-listinput-blocks-the--bqb4.md
@@ -0,0 +1,6 @@
+---
+'@astryxdesign/cli': patch
+---
+
+[docs] Discover data: list the Lab ListInput blocks (the Tag options showcase and the Mailing list, Budget allocation, and Family member declaration examples) as templates. (#7953)
+@ernestt
diff --git a/internal/shadcn-registry/routes.lock.json b/internal/shadcn-registry/routes.lock.json
index 786a241ce6..cdb7420cee 100644
--- a/internal/shadcn-registry/routes.lock.json
+++ b/internal/shadcn-registry/routes.lock.json
@@ -2424,6 +2424,21 @@
"path": "examples/link/with-tooltips",
"aliases": []
},
+ {
+ "name": "example-list-input-budget-allocation",
+ "path": "examples/list-input/budget-allocation",
+ "aliases": []
+ },
+ {
+ "name": "example-list-input-family-member-declaration",
+ "path": "examples/list-input/family-member-declaration",
+ "aliases": []
+ },
+ {
+ "name": "example-list-input-mailing-list",
+ "path": "examples/list-input/mailing-list",
+ "aliases": []
+ },
{
"name": "example-list-item-basic",
"path": "examples/list-item/basic",
@@ -4494,6 +4509,11 @@
"path": "showcases/link/default",
"aliases": []
},
+ {
+ "name": "showcase-list-input-tag-options",
+ "path": "showcases/list-input/tag-options",
+ "aliases": []
+ },
{
"name": "showcase-list-item-default",
"path": "showcases/list-item/default",
diff --git a/packages/cli/assets/discover/official-packages.json b/packages/cli/assets/discover/official-packages.json
index d1e65e928c..953dda382d 100644
--- a/packages/cli/assets/discover/official-packages.json
+++ b/packages/cli/assets/discover/official-packages.json
@@ -239,6 +239,22 @@
{
"kind": "template",
"name": "EmojiPickerShowcase"
+ },
+ {
+ "kind": "template",
+ "name": "ListInputBudgetAllocation"
+ },
+ {
+ "kind": "template",
+ "name": "ListInputFamilyMembers"
+ },
+ {
+ "kind": "template",
+ "name": "ListInputMailingList"
+ },
+ {
+ "kind": "template",
+ "name": "ListInputShowcase"
}
]
},
diff --git a/packages/lab/blocks/ListInputBudgetAllocation.doc.mjs b/packages/lab/blocks/ListInputBudgetAllocation.doc.mjs
new file mode 100644
index 0000000000..6fe9eb3605
--- /dev/null
+++ b/packages/lab/blocks/ListInputBudgetAllocation.doc.mjs
@@ -0,0 +1,14 @@
+// Copyright (c) Meta Platforms, Inc. and affiliates.
+
+/** @type {import('@astryxdesign/cli/authoring').TemplateDoc} */
+export default {
+ type: 'block',
+ name: 'Budget allocation',
+ displayName: 'Budget allocation',
+ description:
+ 'Mixed control types in one record: a team Selector in a proportional column beside a percentage NumberInput in a fixed 132px column. Each team can appear once (a record error), the rows must total 100% (a list error), and Add stops at four teams.',
+ exampleFor: 'ListInput',
+ isReady: true,
+ aspectRatio: 4 / 3,
+ componentsUsed: ['ListInput', 'Selector', 'NumberInput', 'VStack'],
+};
diff --git a/packages/lab/blocks/ListInputBudgetAllocation.tsx b/packages/lab/blocks/ListInputBudgetAllocation.tsx
new file mode 100644
index 0000000000..3613439313
--- /dev/null
+++ b/packages/lab/blocks/ListInputBudgetAllocation.tsx
@@ -0,0 +1,132 @@
+// Copyright (c) Meta Platforms, Inc. and affiliates.
+
+'use client';
+
+/**
+ * @input Controlled team allocation records
+ * @output A ListInput pairing a team Selector with a fixed-width percentage
+ * NumberInput, checking that teams are unique and the total is 100%
+ * @position Copyable Lab ListInput example
+ */
+
+import {useState} from 'react';
+import {VStack} from '@astryxdesign/core/Layout';
+import {NumberInput} from '@astryxdesign/core/NumberInput';
+import {Selector} from '@astryxdesign/core/Selector';
+import {pixel, proportional} from '@astryxdesign/core/Table';
+import {ListInput, type ListInputColumn} from '@astryxdesign/lab';
+
+type Allocation = {id: string; team: string; percent: number | null};
+
+const TEAM_OPTIONS = [
+ {value: 'design', label: 'Design'},
+ {value: 'engineering', label: 'Engineering'},
+ {value: 'marketing', label: 'Marketing'},
+ {value: 'operations', label: 'Operations'},
+];
+
+const COLUMNS: ListInputColumn<Allocation>[] = [
+ {
+ key: 'team',
+ header: 'Team',
+ width: proportional(2, {minWidth: 180}),
+ renderInput: ({
+ item,
+ label,
+ isLabelHidden,
+ status,
+ statusVariant,
+ isDisabled,
+ isLoading,
+ updateItem,
+ }) => (
+ <Selector
+ label={label}
+ isLabelHidden={isLabelHidden}
+ options={TEAM_OPTIONS}
+ value={item.team}
+ placeholder="Choose a team"
+ onChange={team => updateItem({...item, team}, 'team')}
+ status={status}
+ statusVariant={statusVariant}
+ isDisabled={isDisabled || isLoading}
+ />
+ ),
+ },
+ {
+ key: 'percent',
+ header: 'Allocation',
+ width: pixel(132),
+ renderInput: ({
+ item,
+ label,
+ isLabelHidden,
+ status,
+ statusVariant,
+ isDisabled,
+ isLoading,
+ updateItem,
+ }) => (
+ <NumberInput
+ label={label}
+ isLabelHidden={isLabelHidden}
+ value={item.percent}
+ onChange={percent => updateItem({...item, percent}, 'percent')}
+ status={status}
+ statusVariant={statusVariant}
+ isDisabled={isDisabled || isLoading}
+ min={0}
+ max={100}
+ units="%"
+ isIntegerOnly
+ />
+ ),
+ },
+];
+
+export default function ListInputBudgetAllocation() {
+ const [allocations, setAllocations] = useState<Allocation[]>([
+ {id: 'design', team: 'design', percent: 35},
+ {id: 'engineering', team: 'engineering', percent: 40},
+ {id: 'marketing', team: 'marketing', percent: 15},
+ ]);
+ const total = allocations.reduce(
+ (sum, allocation) => sum + (allocation.percent ?? 0),
+ 0,
+ );
+
+ return (
+ <VStack width={680} maxWidth="100%">
+ <ListInput<Allocation>
+ label="Quarterly budget allocation"
+ description="Assign each team once. The percentages must total 100%."
+ value={allocations}
+ onChange={setAllocations}
+ getItemKey={allocation => allocation.id}
+ createItem={() => ({id: crypto.randomUUID(), team: '', percent: null})}
+ columns={COLUMNS}
+ itemName="allocation"
+ isRequired
+ maxItems={4}
+ status={
+ total === 100
+ ? undefined
+ : {
+ type: 'error',
+ message: `Allocations must total 100%. Current total: ${total}%.`,
+ }
+ }
+ getItemStatus={allocation =>
+ allocation.team !== '' &&
+ allocations.some(
+ candidate =>
+ candidate.id !== allocation.id &&
+ candidate.team === allocation.team,
+ )
+ ? {type: 'error', message: 'Each team can only appear once.'}
+ : undefined
+ }
+ />
+ </VStack>
+ );
+}
diff --git a/packages/lab/blocks/ListInputFamilyMembers.doc.mjs b/packages/lab/blocks/ListInputFamilyMembers.doc.mjs
new file mode 100644
index 0000000000..371ca133c2
--- /dev/null
+++ b/packages/lab/blocks/ListInputFamilyMembers.doc.mjs
@@ -0,0 +1,14 @@
+// Copyright (c) Meta Platforms, Inc. and affiliates.
+
+/** @type {import('@astryxdesign/cli/authoring').TemplateDoc} */
+export default {
+ type: 'block',
+ name: 'Family member declaration',
+ displayName: 'Family member declaration',
+ description:
+ 'Three simple fields per record, the recommended ceiling: a full legal name, a relationship Selector, and a DateInput in a fixed 176px column. Order is immaterial, so the list is not reorderable. At 640px or narrower each record stacks its fields with repeated labels.',
+ exampleFor: 'ListInput',
+ isReady: true,
+ aspectRatio: 4 / 3,
+ componentsUsed: ['ListInput', 'TextInput', 'Selector', 'DateInput', 'VStack'],
+};
diff --git a/packages/lab/blocks/ListInputFamilyMembers.tsx b/packages/lab/blocks/ListInputFamilyMembers.tsx
new file mode 100644
index 0000000000..263050f138
--- /dev/null
+++ b/packages/lab/blocks/ListInputFamilyMembers.tsx
@@ -0,0 +1,164 @@
+// Copyright (c) Meta Platforms, Inc. and affiliates.
+
+'use client';
+
+/**
+ * @input Controlled family member records
+ * @output A three-field ListInput (name, relationship, date of birth) whose
+ * records stack their fields when the list is narrow
+ * @position Copyable Lab ListInput example
+ */
+
+import {useState} from 'react';
+import type {ISODateString} from '@astryxdesign/core/Calendar';
+import {DateInput} from '@astryxdesign/core/DateInput';
+import {VStack} from '@astryxdesign/core/Layout';
+import {Selector} from '@astryxdesign/core/Selector';
+import {pixel, proportional} from '@astryxdesign/core/Table';
+import {TextInput} from '@astryxdesign/core/TextInput';
+import {ListInput, type ListInputColumn} from '@astryxdesign/lab';
+
+type FamilyMember = {
+ id: string;
+ fullName: string;
+ relationship: string;
+ dateOfBirth: ISODateString | undefined;
+};
+
+const RELATIONSHIP_OPTIONS = [
+ {value: 'spouse-or-partner', label: 'Spouse or partner'},
+ {value: 'child', label: 'Child'},
+ {value: 'parent', label: 'Parent'},
+ {value: 'sibling', label: 'Sibling'},
+ {value: 'other-dependent', label: 'Other dependent'},
+];
+
+const COLUMNS: ListInputColumn<FamilyMember>[] = [
+ {
+ key: 'fullName',
+ header: 'Full legal name',
+ width: proportional(2, {minWidth: 200}),
+ renderInput: ({
+ item,
+ label,
+ isLabelHidden,
+ status,
+ statusVariant,
+ isDisabled,
+ isLoading,
+ updateItem,
+ }) => (
+ <TextInput
+ label={label}
+ isLabelHidden={isLabelHidden}
+ value={item.fullName}
+ onChange={fullName => updateItem({...item, fullName}, 'fullName')}
+ status={status}
+ statusVariant={statusVariant}
+ isDisabled={isDisabled}
+ isLoading={isLoading}
+ />
+ ),
+ },
+ {
+ key: 'relationship',
+ header: 'Relationship',
+ width: proportional(1.25, {minWidth: 160}),
+ renderInput: ({
+ item,
+ label,
+ isLabelHidden,
+ status,
+ statusVariant,
+ isDisabled,
+ isLoading,
+ updateItem,
+ }) => (
+ <Selector
+ label={label}
+ isLabelHidden={isLabelHidden}
+ options={RELATIONSHIP_OPTIONS}
+ value={item.relationship}
+ placeholder="Choose relationship"
+ onChange={relationship =>
+ updateItem({...item, relationship}, 'relationship')
+ }
+ status={status}
+ statusVariant={statusVariant}
+ isDisabled={isDisabled || isLoading}
+ />
+ ),
+ },
+ {
+ key: 'dateOfBirth',
+ header: 'Date of birth',
+ width: pixel(176),
+ renderInput: ({
+ item,
+ label,
+ isLabelHidden,
+ status,
+ statusVariant,
+ isDisabled,
+ isLoading,
+ updateItem,
+ }) => (
+ <DateInput
+ label={label}
+ isLabelHidden={isLabelHidden}
+ value={item.dateOfBirth}
+ onChange={dateOfBirth =>
+ updateItem({...item, dateOfBirth}, 'dateOfBirth')
+ }
+ status={status}
+ statusVariant={statusVariant}
+ isDisabled={isDisabled}
+ isLoading={isLoading}
+ />
+ ),
+ },
+];
+
+export default function ListInputFamilyMembers() {
+ const [members, setMembers] = useState<FamilyMember[]>([
+ {
+ id: 'jordan',
+ fullName: 'Jordan Lee',
+ relationship: 'spouse-or-partner',
+ dateOfBirth: '1988-11-02',
+ },
+ {
+ id: 'alexandria',
+ fullName: 'Alexandria María de la Cruz',
+ relationship: 'child',
+ dateOfBirth: '2012-06-24',
+ },
+ {
+ id: 'grace',
+ fullName: 'Grace Lee',
+ relationship: 'parent',
+ dateOfBirth: '1958-04-17',
+ },
+ ]);
+
+ return (
+ <VStack width={680} maxWidth="100%">
+ <ListInput<FamilyMember>
+ label="Family member declaration"
+ description="Declare each immediate family member, their relationship to you, and their date of birth."
+ value={members}
+ onChange={setMembers}
+ getItemKey={member => member.id}
+ createItem={() => ({
+ id: crypto.randomUUID(),
+ fullName: '',
+ relationship: '',
+ dateOfBirth: undefined,
+ })}
+ columns={COLUMNS}
+ itemName="family member"
+ isRequired
+ />
+ </VStack>
+ );
+}
diff --git a/packages/lab/blocks/ListInputMailingList.doc.mjs b/packages/lab/blocks/ListInputMailingList.doc.mjs
new file mode 100644
index 0000000000..a137b2170a
--- /dev/null
+++ b/packages/lab/blocks/ListInputMailingList.doc.mjs
@@ -0,0 +1,14 @@
+// Copyright (c) Meta Platforms, Inc. and affiliates.
+
+/** @type {import('@astryxdesign/cli/authoring').TemplateDoc} */
+export default {
+ type: 'block',
+ name: 'Mailing list',
+ displayName: 'Mailing list',
+ description:
+ 'A one-column list that starts empty, shows the empty state with Add still available, and stops adding at six addresses. A repeated address is a record error, a malformed address is a field error after blur, and removing the last address shows the required-list error.',
+ exampleFor: 'ListInput',
+ isReady: true,
+ aspectRatio: 4 / 3,
+ componentsUsed: ['ListInput', 'TextInput', 'VStack'],
+};
diff --git a/packages/lab/blocks/ListInputMailingList.tsx b/packages/lab/blocks/ListInputMailingList.tsx
new file mode 100644
index 0000000000..00ce85fe90
--- /dev/null
+++ b/packages/lab/blocks/ListInputMailingList.tsx
@@ -0,0 +1,115 @@
+// Copyright (c) Meta Platforms, Inc. and affiliates.
+
+'use client';
+
+/**
+ * @input Controlled subscriber records, starting empty
+ * @output A one-column ListInput of email addresses with a six-record limit,
+ * duplicate detection, and blur validation
+ * @position Copyable Lab ListInput example
+ */
+
+import {useMemo, useState} from 'react';
+import {VStack} from '@astryxdesign/core/Layout';
+import {TextInput} from '@astryxdesign/core/TextInput';
+import {ListInput, type ListInputColumn} from '@astryxdesign/lab';
+
+type Subscriber = {id: string; email: string};
+
+function isValidEmail(email: string): boolean {
+ return /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email.trim());
+}
+
+export default function ListInputMailingList() {
+ const [subscribers, setSubscribers] = useState<Subscriber[]>([]);
+ const [hasChanged, setHasChanged] = useState(false);
+ // Field errors wait until the field has been left once.
+ const [touched, setTouched] = useState<ReadonlySet<string>>(() => new Set());
+
+ const columns = useMemo<ListInputColumn<Subscriber>[]>(
+ () => [
+ {
+ key: 'email',
+ header: 'Email address',
+ renderInput: ({
+ item,
+ label,
+ isLabelHidden,
+ status,
+ statusVariant,
+ isDisabled,
+ isLoading,
+ updateItem,
+ }) => (
+ <TextInput
+ type="email"
+ label={label}
+ isLabelHidden={isLabelHidden}
+ value={item.email}
+ placeholder="[email protected]"
+ onChange={email => updateItem({...item, email}, 'email')}
+ onBlur={() =>
+ setTouched(current =>
+ current.has(item.id) ? current : new Set(current).add(item.id),
+ )
+ }
+ status={status}
+ statusVariant={statusVariant}
+ isDisabled={isDisabled}
+ isLoading={isLoading}
+ />
+ ),
+ },
+ ],
+ [],
+ );
+
+ return (
+ <VStack width={680} maxWidth="100%">
+ <ListInput<Subscriber>
+ label="Mailing list"
+ description="Add up to six addresses."
+ value={subscribers}
+ onChange={nextSubscribers => {
+ setSubscribers(nextSubscribers);
+ setHasChanged(true);
+ }}
+ getItemKey={subscriber => subscriber.id}
+ createItem={() => ({id: crypto.randomUUID(), email: ''})}
+ columns={columns}
+ itemName="subscriber"
+ isRequired
+ maxItems={6}
+ status={
+ hasChanged && subscribers.length === 0
+ ? {type: 'error', message: 'Add at least one subscriber.'}
+ : undefined
+ }
+ getItemStatus={subscriber => {
+ const email = subscriber.email.trim().toLowerCase();
+ const isDuplicate =
+ email !== '' &&
+ subscribers.some(
+ candidate =>
+ candidate.id !== subscriber.id &&
+ candidate.email.trim().toLowerCase() === email,
+ );
+ return isDuplicate
+ ? {type: 'error', message: 'This address is already in the list.'}
+ : undefined;
+ }}
+ getFieldStatus={subscriber => {
+ if (!touched.has(subscriber.id)) {
+ return undefined;
+ }
+ if (subscriber.email.trim() === '') {
+ return {type: 'error', message: 'Enter an email address.'};
+ }
+ return isValidEmail(subscriber.email)
+ ? undefined
+ : {type: 'error', message: 'Enter a valid email address.'};
+ }}
+ />
+ </VStack>
+ );
+}
diff --git a/packages/lab/blocks/ListInputShowcase.doc.mjs b/packages/lab/blocks/ListInputShowcase.doc.mjs
new file mode 100644
index 0000000000..52cbaebb21
--- /dev/null
+++ b/packages/lab/blocks/ListInputShowcase.doc.mjs
@@ -0,0 +1,15 @@
+// Copyright (c) Meta Platforms, Inc. and affiliates.
+
+/** @type {import('@astryxdesign/cli/authoring').TemplateDoc} */
+export default {
+ type: 'block',
+ name: 'Tag options',
+ displayName: 'Tag options',
+ description:
+ 'A reorderable tag editor. Each record pairs a color Selector with a label TextInput; drag a grip or use the keyboard to reorder. Validation sits at the narrowest useful level: an empty label after blur is a field error, a disallowed color and label pair is a record error, and fewer than five tags is a list error.',
+ exampleFor: 'ListInput',
+ isReady: true,
+ isShowcase: true,
+ aspectRatio: 4 / 3,
+ componentsUsed: ['ListInput', 'Selector', 'TextInput', 'VStack'],
+};
diff --git a/packages/lab/blocks/ListInputShowcase.tsx b/packages/lab/blocks/ListInputShowcase.tsx
new file mode 100644
index 0000000000..72f115ea21
--- /dev/null
+++ b/packages/lab/blocks/ListInputShowcase.tsx
@@ -0,0 +1,139 @@
+// Copyright (c) Meta Platforms, Inc. and affiliates.
+
+'use client';
+
+/**
+ * @input Controlled tag records and blur-tracked fields
+ * @output A reorderable ListInput of tag options with field, record, and list
+ * validation
+ * @position Lab ListInput's docsite showcase and copyable CLI block
+ */
+
+import {useMemo, useState} from 'react';
+import {VStack} from '@astryxdesign/core/Layout';
+import {Selector} from '@astryxdesign/core/Selector';
+import {proportional} from '@astryxdesign/core/Table';
+import {TextInput} from '@astryxdesign/core/TextInput';
+import {ListInput, type ListInputColumn} from '@astryxdesign/lab';
+
+type TagOption = {id: string; color: string; label: string};
+
+const COLOR_OPTIONS = [
+ {value: 'blue', label: 'Blue'},
+ {value: 'green', label: 'Green'},
+ {value: 'amber', label: 'Amber'},
+ {value: 'red', label: 'Red'},
+ {value: 'purple', label: 'Purple'},
+];
+
+const INITIAL_TAGS: TagOption[] = [
+ {id: 'tag-new', color: 'blue', label: 'New'},
+ {id: 'tag-blocked', color: 'green', label: 'Blocked'},
+ {id: 'tag-draft', color: 'amber', label: ''},
+ {id: 'tag-review', color: 'purple', label: 'In review'},
+];
+
+export default function ListInputShowcase() {
+ const [tags, setTags] = useState(INITIAL_TAGS);
+ // Field errors wait until the field has been left once.
+ const [touchedLabels, setTouchedLabels] = useState<ReadonlySet<string>>(
+ () => new Set(),
+ );
+
+ const columns = useMemo<ListInputColumn<TagOption>[]>(
+ () => [
+ {
+ key: 'color',
+ header: 'Color',
+ width: proportional(1, {minWidth: 120}),
+ renderInput: ({
+ item,
+ label,
+ isLabelHidden,
+ status,
+ statusVariant,
+ isDisabled,
+ updateItem,
+ }) => (
+ <Selector
+ label={label}
+ isLabelHidden={isLabelHidden}
+ options={COLOR_OPTIONS}
+ value={item.color}
+ onChange={color => updateItem({...item, color}, 'color')}
+ status={status}
+ statusVariant={statusVariant}
+ isDisabled={isDisabled}
+ />
+ ),
+ },
+ {
+ key: 'label',
+ header: 'Label',
+ width: proportional(2, {minWidth: 200}),
+ renderInput: ({
+ item,
+ label,
+ isLabelHidden,
+ status,
+ statusVariant,
+ isDisabled,
+ isLoading,
+ updateItem,
+ }) => (
+ <TextInput
+ label={label}
+ isLabelHidden={isLabelHidden}
+ value={item.label}
+ onChange={nextLabel =>
+ updateItem({...item, label: nextLabel}, 'label')
+ }
+ onBlur={() =>
+ setTouchedLabels(current =>
+ current.has(item.id) ? current : new Set(current).add(item.id),
+ )
+ }
+ status={status}
+ statusVariant={statusVariant}
+ isDisabled={isDisabled}
+ isLoading={isLoading}
+ />
+ ),
+ },
+ ],
+ [],
+ );
+
+ return (
+ <VStack width={680} maxWidth="100%">
+ <ListInput<TagOption>
+ label="Tag options"
+ description="Add at least five tags and drag rows to set their order."
+ value={tags}
+ onChange={setTags}
+ getItemKey={tag => tag.id}
+ createItem={() => ({id: crypto.randomUUID(), color: 'blue', label: ''})}
+ columns={columns}
+ itemName="tag"
+ isReorderable
+ status={
+ tags.length < 5
+ ? {type: 'error', message: 'Add at least five tag options.'}
+ : undefined
+ }
+ getItemStatus={tag =>
+ tag.color === 'green' && tag.label.trim().toLowerCase() === 'blocked'
+ ? {type: 'error', message: `“${tag.label}” cannot use green.`}
+ : undefined
+ }
+ getFieldStatus={(tag, columnKey) =>
+ columnKey === 'label' &&
+ touchedLabels.has(tag.id) &&
+ tag.label.trim() === ''
+ ? {type: 'error', message: 'Enter a label.'}
+ : undefined
+ }
+ />
+ </VStack>
+ );
+}
diff --git a/packages/lab/src/ListInput/ListInput.doc.mjs b/packages/lab/src/ListInput/ListInput.doc.mjs
index 187dead0d4..6ed88a2d11 100644
--- a/packages/lab/src/ListInput/ListInput.doc.mjs
+++ b/packages/lab/src/ListInput/ListInput.doc.mjs
@@ -250,6 +250,71 @@ export const docs = {
],
},
examples: [
+ {
+ label: 'Tag options',
+ code: `import {Selector} from '@astryxdesign/core/Selector';
+import {proportional} from '@astryxdesign/core/Table';
+import {TextInput} from '@astryxdesign/core/TextInput';
+
+type TagOption = {id: string; color: string; label: string};
+
+const columns = [
+ {
+ key: 'color',
+ header: 'Color',
+ width: proportional(1, {minWidth: 120}),
+ renderInput: ({item, label, isLabelHidden, status, statusVariant, isDisabled, updateItem}) => (
+ <Selector
+ label={label}
+ isLabelHidden={isLabelHidden}
+ options={colorOptions}
+ value={item.color}
+ onChange={color => updateItem({...item, color}, 'color')}
+ status={status}
+ statusVariant={statusVariant}
+ isDisabled={isDisabled}
+ />
+ ),
+ },
+ {
+ key: 'label',
+ header: 'Label',
+ width: proportional(2, {minWidth: 200}),
+ renderInput: ({item, label, isLabelHidden, status, statusVariant, isDisabled, updateItem}) => (
+ <TextInput
+ label={label}
+ isLabelHidden={isLabelHidden}
+ value={item.label}
+ onChange={nextLabel => updateItem({...item, label: nextLabel}, 'label')}
+ status={status}
+ statusVariant={statusVariant}
+ isDisabled={isDisabled}
+ />
+ ),
+ },
+] satisfies ListInputColumn<TagOption>[];
+
+<ListInput
+ label="Tag options"
+ itemName="tag"
+ value={tags}
+ onChange={setTags}
+ getItemKey={tag => tag.id}
+ createItem={() => ({id: crypto.randomUUID(), color: 'blue', label: ''})}
+ columns={columns}
+ isReorderable
+ status={
+ tags.length < 5
+ ? {type: 'error', message: 'Add at least five tag options.'}
+ : undefined
+ }
+ getItemStatus={tag =>
+ tag.color === 'green' && tag.label === 'Blocked'
+ ? {type: 'error', message: '"Blocked" cannot use green.'}
+ : undefined
+ }
+/>`,
+ },
{
label: 'Controlled guest list',
code: `import {proportional} from '@astryxdesign/core/Table';
@@ -314,6 +379,186 @@ const columns = [
? {type: 'error', message: 'Add at least one guest'}
: undefined
}
+/>`,
+ },
+ {
+ label: 'Mailing list',
+ code: `import {TextInput} from '@astryxdesign/core/TextInput';
+
+type Subscriber = {id: string; email: string};
+
+<ListInput
+ label="Mailing list"
+ itemName="subscriber"
+ value={subscribers}
+ onChange={setSubscribers}
+ getItemKey={subscriber => subscriber.id}
+ createItem={() => ({id: crypto.randomUUID(), email: ''})}
+ columns={[
+ {
+ key: 'email',
+ header: 'Email address',
+ renderInput: ({item, label, isLabelHidden, status, statusVariant, isDisabled, updateItem}) => (
+ <TextInput
+ type="email"
+ label={label}
+ isLabelHidden={isLabelHidden}
+ value={item.email}
+ onChange={email => updateItem({...item, email}, 'email')}
+ status={status}
+ statusVariant={statusVariant}
+ isDisabled={isDisabled}
+ />
+ ),
+ },
+ ] satisfies ListInputColumn<Subscriber>[]}
+ isRequired
+ maxItems={6}
+ getItemStatus={subscriber =>
+ isDuplicateAddress(subscriber)
+ ? {type: 'error', message: 'This address is already in the list.'}
+ : undefined
+ }
+/>`,
+ },
+ {
+ label: 'Budget allocation',
+ code: `import {NumberInput} from '@astryxdesign/core/NumberInput';
+import {Selector} from '@astryxdesign/core/Selector';
+import {pixel, proportional} from '@astryxdesign/core/Table';
+
+type Allocation = {id: string; team: string; percent: number | null};
+
+const columns = [
+ {
+ key: 'team',
+ header: 'Team',
+ width: proportional(2, {minWidth: 180}),
+ renderInput: ({item, label, isLabelHidden, status, statusVariant, isDisabled, updateItem}) => (
+ <Selector
+ label={label}
+ isLabelHidden={isLabelHidden}
+ options={teamOptions}
+ value={item.team}
+ placeholder="Choose a team"
+ onChange={team => updateItem({...item, team}, 'team')}
+ status={status}
+ statusVariant={statusVariant}
+ isDisabled={isDisabled}
+ />
+ ),
+ },
+ {
+ key: 'percent',
+ header: 'Allocation',
+ width: pixel(132),
+ renderInput: ({item, label, isLabelHidden, status, statusVariant, isDisabled, updateItem}) => (
+ <NumberInput
+ label={label}
+ isLabelHidden={isLabelHidden}
+ value={item.percent}
+ onChange={percent => updateItem({...item, percent}, 'percent')}
+ status={status}
+ statusVariant={statusVariant}
+ isDisabled={isDisabled}
+ min={0}
+ max={100}
+ units="%"
+ isIntegerOnly
+ />
+ ),
+ },
+] satisfies ListInputColumn<Allocation>[];
+
+<ListInput
+ label="Quarterly budget allocation"
+ itemName="allocation"
+ value={allocations}
+ onChange={setAllocations}
+ getItemKey={allocation => allocation.id}
+ createItem={() => ({id: crypto.randomUUID(), team: '', percent: null})}
+ columns={columns}
+ maxItems={4}
+ status={
+ total === 100
+ ? undefined
+ : {type: 'error', message: 'Allocations must total 100%.'}
+ }
+/>`,
+ },
+ {
+ label: 'Family member declaration',
+ code: `import {DateInput} from '@astryxdesign/core/DateInput';
+import {Selector} from '@astryxdesign/core/Selector';
+import {pixel, proportional} from '@astryxdesign/core/Table';
+import {TextInput} from '@astryxdesign/core/TextInput';
+
+const columns = [
+ {
+ key: 'fullName',
+ header: 'Full legal name',
+ width: proportional(2, {minWidth: 200}),
+ renderInput: ({item, label, isLabelHidden, status, statusVariant, isDisabled, updateItem}) => (
+ <TextInput
+ label={label}
+ isLabelHidden={isLabelHidden}
+ value={item.fullName}
+ onChange={fullName => updateItem({...item, fullName}, 'fullName')}
+ status={status}
+ statusVariant={statusVariant}
+ isDisabled={isDisabled}
+ />
+ ),
+ },
+ {
+ key: 'relationship',
+ header: 'Relationship',
+ width: proportional(1.25, {minWidth: 160}),
+ renderInput: ({item, label, isLabelHidden, status, statusVariant, isDisabled, updateItem}) => (
+ <Selector
+ label={label}
+ isLabelHidden={isLabelHidden}
+ options={relationshipOptions}
+ value={item.relationship}
+ onChange={relationship => updateItem({...item, relationship}, 'relationship')}
+ status={status}
+ statusVariant={statusVariant}
+ isDisabled={isDisabled}
+ />
+ ),
+ },
+ {
+ key: 'dateOfBirth',
+ header: 'Date of birth',
+ width: pixel(176),
+ renderInput: ({item, label, isLabelHidden, status, statusVariant, isDisabled, updateItem}) => (
+ <DateInput
+ label={label}
+ isLabelHidden={isLabelHidden}
+ value={item.dateOfBirth}
+ onChange={dateOfBirth => updateItem({...item, dateOfBirth}, 'dateOfBirth')}
+ status={status}
+ statusVariant={statusVariant}
+ isDisabled={isDisabled}
+ />
+ ),
+ },
+] satisfies ListInputColumn<FamilyMember>[];
+
+<ListInput
+ label="Family member declaration"
+ itemName="family member"
+ value={members}
+ onChange={setMembers}
+ getItemKey={member => member.id}
+ createItem={() => ({
+ id: crypto.randomUUID(),
+ fullName: '',
+ relationship: '',
+ dateOfBirth: undefined,
+ })}
+ columns={columns}
+ isRequired
/>`,
},
],