An open source design system that's fully customizable and agent ready
TypeScript
Improve DropdownMenu docs page and block examples (#1578)
rubyycheung83bae978ecea
diff --git a/packages/cli/templates/blocks/components/DropdownMenu/DropdownMenuActions.doc.mjs b/packages/cli/templates/blocks/components/DropdownMenu/DropdownMenuActions.doc.mjsnew file mode 100644index 0000000000..1c7729c790--- /dev/null+++ b/packages/cli/templates/blocks/components/DropdownMenu/DropdownMenuActions.doc.mjs@@ -0,0 +1,10 @@+/** @type {import('../../../../../core/src/docs-types').TemplateDoc} */+export const doc = {+ type: 'block',+ name: 'DropdownMenu — Actions',+ description:+ 'Action menu with dividers separating safe and destructive operations. Use for row-level actions on items like documents, projects, or records.',+ isReady: true,+ aspectRatio: 16 / 9,+ componentsUsed: ['DropdownMenu', 'Layout', 'Text'],+};diff --git a/packages/cli/templates/blocks/components/DropdownMenu/DropdownMenuActions.tsx b/packages/cli/templates/blocks/components/DropdownMenu/DropdownMenuActions.tsxnew file mode 100644index 0000000000..5485ca5edd--- /dev/null+++ b/packages/cli/templates/blocks/components/DropdownMenu/DropdownMenuActions.tsx@@ -0,0 +1,31 @@+'use client';++import {useState} from 'react';+import {XDSDropdownMenu} from '@xds/core/DropdownMenu';+import {XDSVStack} from '@xds/core/Layout';+import {XDSText} from '@xds/core/Text';++export default function DropdownMenuActions() {+ const [lastAction, setLastAction] = useState<string | null>(null);++ return (+ <XDSVStack gap={3}>+ <XDSDropdownMenu+ button={{label: 'Actions'}}+ items={[+ {label: 'Edit', onClick: () => setLastAction('Edit')},+ {label: 'Duplicate', onClick: () => setLastAction('Duplicate')},+ {label: 'Move to folder', onClick: () => setLastAction('Move')},+ {type: 'divider'},+ {label: 'Archive', onClick: () => setLastAction('Archive')},+ {label: 'Delete', onClick: () => setLastAction('Delete')},+ ]}+ />+ {lastAction && (+ <XDSText type="supporting" color="secondary">+ Last action: {lastAction}+ </XDSText>+ )}+ </XDSVStack>+ );+}diff --git a/packages/cli/templates/blocks/components/DropdownMenu/DropdownMenuCompoundMode.doc.mjs b/packages/cli/templates/blocks/components/DropdownMenu/DropdownMenuCompoundMode.doc.mjsdeleted file mode 100644index 6202cacd0e..0000000000--- a/packages/cli/templates/blocks/components/DropdownMenu/DropdownMenuCompoundMode.doc.mjs+++ /dev/null@@ -1,10 +0,0 @@-/** @type {import('../../../../../core/src/docs-types').TemplateDoc} */-export const doc = {- type: 'block',- name: 'DropdownMenu — Compound Mode',- description:- 'Compound-component pattern using JSX children instead of an items array.',- isReady: true,- aspectRatio: 4 / 3,- componentsUsed: ['DropdownMenu', 'Divider'],-};diff --git a/packages/cli/templates/blocks/components/DropdownMenu/DropdownMenuCompoundMode.tsx b/packages/cli/templates/blocks/components/DropdownMenu/DropdownMenuCompoundMode.tsxdeleted file mode 100644index 9bf11a0a49..0000000000--- a/packages/cli/templates/blocks/components/DropdownMenu/DropdownMenuCompoundMode.tsx+++ /dev/null@@ -1,15 +0,0 @@-'use client';--import {XDSDropdownMenu, XDSDropdownMenuItem} from '@xds/core/DropdownMenu';-import {XDSDivider} from '@xds/core/Divider';--export default function DropdownMenuCompoundMode() {- return (- <XDSDropdownMenu button={{label: 'Actions'}}>- <XDSDropdownMenuItem label="Edit" onClick={() => {}} />- <XDSDropdownMenuItem label="Duplicate" onClick={() => {}} />- <XDSDivider />- <XDSDropdownMenuItem label="Delete" onClick={() => {}} />- </XDSDropdownMenu>- );-}diff --git a/packages/cli/templates/blocks/components/DropdownMenu/DropdownMenuNoChevron.doc.mjs b/packages/cli/templates/blocks/components/DropdownMenu/DropdownMenuNoChevron.doc.mjsindex c716c9bbc3..2cb8cc5f69 100644--- a/packages/cli/templates/blocks/components/DropdownMenu/DropdownMenuNoChevron.doc.mjs+++ b/packages/cli/templates/blocks/components/DropdownMenu/DropdownMenuNoChevron.doc.mjs@@ -1,10 +1,10 @@/** @type {import('../../../../../core/src/docs-types').TemplateDoc} */export const doc = {type: 'block',- name: 'DropdownMenu — No Chevron',+ name: 'DropdownMenu — Icon Trigger',description:- 'Dropdown trigger without a chevron indicator, styled as a sort toggle.',+ 'Overflow menu triggered by an icon-only button with no chevron or label text. Use for row-level actions in tables, cards, or lists where a text button would take too much space.',isReady: true,- aspectRatio: 4 / 3,- componentsUsed: ['DropdownMenu'],+ aspectRatio: 16 / 9,+ componentsUsed: ['DropdownMenu', 'Icon', 'Layout', 'Text'],};diff --git a/packages/cli/templates/blocks/components/DropdownMenu/DropdownMenuNoChevron.tsx b/packages/cli/templates/blocks/components/DropdownMenu/DropdownMenuNoChevron.tsxindex 8b94686ea7..6386d15ff4 100644--- a/packages/cli/templates/blocks/components/DropdownMenu/DropdownMenuNoChevron.tsx+++ b/packages/cli/templates/blocks/components/DropdownMenu/DropdownMenuNoChevron.tsx@@ -1,17 +1,38 @@'use client';+import {useState} from 'react';import {XDSDropdownMenu} from '@xds/core/DropdownMenu';+import {XDSIcon} from '@xds/core/Icon';+import {XDSVStack} from '@xds/core/Layout';+import {XDSText} from '@xds/core/Text';+import {EllipsisHorizontalIcon} from '@heroicons/react/24/outline';export default function DropdownMenuNoChevron() {+ const [lastAction, setLastAction] = useState<string | null>(null);+return (- <XDSDropdownMenu- button={{label: 'Sort by: Name', variant: 'ghost'}}- hasChevron={false}- items={[- {label: 'Name', onClick: () => {}},- {label: 'Date', onClick: () => {}},- {label: 'Size', onClick: () => {}},- ]}- />+ <XDSVStack gap={3}>+ <XDSDropdownMenu+ button={{+ label: 'More actions',+ icon: <XDSIcon icon={EllipsisHorizontalIcon} />,+ variant: 'ghost',+ isIconOnly: true,+ }}+ hasChevron={false}+ items={[+ {label: 'Copy link', onClick: () => setLastAction('Copy link')},+ {label: 'Download', onClick: () => setLastAction('Download')},+ {label: 'Print', onClick: () => setLastAction('Print')},+ {type: 'divider'},+ {label: 'Report', onClick: () => setLastAction('Report')},+ ]}+ />+ {lastAction && (+ <XDSText type="supporting" color="secondary">+ Last action: {lastAction}+ </XDSText>+ )}+ </XDSVStack>);}diff --git a/packages/cli/templates/blocks/components/DropdownMenu/DropdownMenuWithDisabledItems.doc.mjs b/packages/cli/templates/blocks/components/DropdownMenu/DropdownMenuWithDisabledItems.doc.mjsindex cd3d9d37c4..72d902514a 100644--- a/packages/cli/templates/blocks/components/DropdownMenu/DropdownMenuWithDisabledItems.doc.mjs+++ b/packages/cli/templates/blocks/components/DropdownMenu/DropdownMenuWithDisabledItems.doc.mjs@@ -1,9 +1,10 @@/** @type {import('../../../../../core/src/docs-types').TemplateDoc} */export const doc = {type: 'block',- name: 'DropdownMenu — With Disabled Items',- description: 'Dropdown menu with selectively disabled menu items.',+ name: 'DropdownMenu — Disabled',+ description:+ 'Menu with selectively disabled items based on permissions. Use when some actions require higher privileges, like admin-only operations.',isReady: true,- aspectRatio: 4 / 3,- componentsUsed: ['DropdownMenu'],+ aspectRatio: 16 / 9,+ componentsUsed: ['DropdownMenu', 'Layout', 'Text'],};diff --git a/packages/cli/templates/blocks/components/DropdownMenu/DropdownMenuWithDisabledItems.tsx b/packages/cli/templates/blocks/components/DropdownMenu/DropdownMenuWithDisabledItems.tsxindex 7a49f27fd0..3627e7b222 100644--- a/packages/cli/templates/blocks/components/DropdownMenu/DropdownMenuWithDisabledItems.tsx+++ b/packages/cli/templates/blocks/components/DropdownMenu/DropdownMenuWithDisabledItems.tsx@@ -1,16 +1,33 @@'use client';+import {useState} from 'react';import {XDSDropdownMenu} from '@xds/core/DropdownMenu';+import {XDSVStack} from '@xds/core/Layout';+import {XDSText} from '@xds/core/Text';export default function DropdownMenuWithDisabledItems() {+ const [lastAction, setLastAction] = useState<string | null>(null);+return (- <XDSDropdownMenu- button={{label: 'Actions'}}- items={[- {label: 'Edit', onClick: () => {}},- {label: 'Duplicate', onClick: () => {}},- {label: 'Delete (disabled)', isDisabled: true},- ]}- />+ <XDSVStack gap={3}>+ <XDSDropdownMenu+ button={{label: 'Manage team'}}+ items={[+ {label: 'Invite member', onClick: () => setLastAction('Invite')},+ {label: 'Edit roles', onClick: () => setLastAction('Edit roles')},+ {type: 'divider'},+ {label: 'Transfer ownership', isDisabled: true},+ {label: 'Delete team', isDisabled: true},+ ]}+ />+ {lastAction && (+ <XDSText type="supporting" color="secondary">+ Last action: {lastAction}+ </XDSText>+ )}+ <XDSText type="supporting" color="secondary">+ Destructive actions are disabled for non-admin users+ </XDSText>+ </XDSVStack>);}diff --git a/packages/cli/templates/blocks/components/DropdownMenu/DropdownMenuWithDividers.doc.mjs b/packages/cli/templates/blocks/components/DropdownMenu/DropdownMenuWithDividers.doc.mjsdeleted file mode 100644index 237680ddae..0000000000--- a/packages/cli/templates/blocks/components/DropdownMenu/DropdownMenuWithDividers.doc.mjs+++ /dev/null@@ -1,9 +0,0 @@-/** @type {import('../../../../../core/src/docs-types').TemplateDoc} */-export const doc = {- type: 'block',- name: 'DropdownMenu — With Dividers',- description: 'Dropdown menu with divider lines separating action groups.',- isReady: true,- aspectRatio: 4 / 3,- componentsUsed: ['DropdownMenu'],-};diff --git a/packages/cli/templates/blocks/components/DropdownMenu/DropdownMenuWithDividers.tsx b/packages/cli/templates/blocks/components/DropdownMenu/DropdownMenuWithDividers.tsxdeleted file mode 100644index c5ae016869..0000000000--- a/packages/cli/templates/blocks/components/DropdownMenu/DropdownMenuWithDividers.tsx+++ /dev/null@@ -1,17 +0,0 @@-'use client';--import {XDSDropdownMenu} from '@xds/core/DropdownMenu';--export default function DropdownMenuWithDividers() {- return (- <XDSDropdownMenu- button={{label: 'Actions'}}- items={[- {label: 'Edit', onClick: () => {}},- {label: 'Duplicate', onClick: () => {}},- {type: 'divider'},- {label: 'Delete', onClick: () => {}},- ]}- />- );-}diff --git a/packages/cli/templates/blocks/components/DropdownMenu/DropdownMenuWithSections.doc.mjs b/packages/cli/templates/blocks/components/DropdownMenu/DropdownMenuWithSections.doc.mjsindex aca35ffdc1..9f571bbcfc 100644--- a/packages/cli/templates/blocks/components/DropdownMenu/DropdownMenuWithSections.doc.mjs+++ b/packages/cli/templates/blocks/components/DropdownMenu/DropdownMenuWithSections.doc.mjs@@ -1,9 +1,10 @@/** @type {import('../../../../../core/src/docs-types').TemplateDoc} */export const doc = {type: 'block',- name: 'DropdownMenu — With Sections',- description: 'Dropdown menu with titled sections grouping related actions.',+ name: 'DropdownMenu — Sections',+ description:+ 'Menu items organized into titled sections for easy scanning. Use when you have 6+ actions that fall into distinct categories, like Create vs Manage.',isReady: true,- aspectRatio: 4 / 3,- componentsUsed: ['DropdownMenu'],+ aspectRatio: 16 / 9,+ componentsUsed: ['DropdownMenu', 'Layout', 'Text'],};diff --git a/packages/cli/templates/blocks/components/DropdownMenu/DropdownMenuWithSections.tsx b/packages/cli/templates/blocks/components/DropdownMenu/DropdownMenuWithSections.tsxindex bfa1e0416d..0b41dd7886 100644--- a/packages/cli/templates/blocks/components/DropdownMenu/DropdownMenuWithSections.tsx+++ b/packages/cli/templates/blocks/components/DropdownMenu/DropdownMenuWithSections.tsx@@ -1,29 +1,49 @@'use client';+import {useState} from 'react';import {XDSDropdownMenu} from '@xds/core/DropdownMenu';+import {XDSVStack} from '@xds/core/Layout';+import {XDSText} from '@xds/core/Text';export default function DropdownMenuWithSections() {+ const [lastAction, setLastAction] = useState<string | null>(null);+return (- <XDSDropdownMenu- button={{label: 'File', variant: 'ghost'}}- items={[- {- type: 'section',- title: 'Create',- items: [- {label: 'New File', onClick: () => {}},- {label: 'New Folder', onClick: () => {}},- ],- },- {- type: 'section',- title: 'Share',- items: [- {label: 'Share', onClick: () => {}},- {label: 'Archive', onClick: () => {}},- ],- },- ]}- />+ <XDSVStack gap={3}>+ <XDSDropdownMenu+ button={{label: 'File', variant: 'ghost'}}+ items={[+ {+ type: 'section',+ title: 'Create',+ items: [+ {+ label: 'New document',+ onClick: () => setLastAction('New document'),+ },+ {+ label: 'New spreadsheet',+ onClick: () => setLastAction('New spreadsheet'),+ },+ {label: 'New folder', onClick: () => setLastAction('New folder')},+ ],+ },+ {+ type: 'section',+ title: 'Manage',+ items: [+ {label: 'Share', onClick: () => setLastAction('Share')},+ {label: 'Move', onClick: () => setLastAction('Move')},+ {label: 'Archive', onClick: () => setLastAction('Archive')},+ ],+ },+ ]}+ />+ {lastAction && (+ <XDSText type="supporting" color="secondary">+ Selected: {lastAction}+ </XDSText>+ )}+ </XDSVStack>);}