Skip to content

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

TypeScript

Add reusable Item document tabs block (#6652)

Ernest4d19926bb086
diff --git a/.changeset/add-a-reusable-item-document-tabs-block-template-spdp.md b/.changeset/add-a-reusable-item-document-tabs-block-template-spdp.md
new file mode 100644
index 0000000000..1751c171bd
--- /dev/null
+++ b/.changeset/add-a-reusable-item-document-tabs-block-template-spdp.md
@@ -0,0 +1,6 @@
+---
+'@astryxdesign/cli': patch
+---
+
+[feat] Add a reusable Item document tabs block template
+@ernestt
diff --git a/apps/sandbox/scripts/next-export-routes.json b/apps/sandbox/scripts/next-export-routes.json
index 38b4aaa876..f9bd90f148 100644
--- a/apps/sandbox/scripts/next-export-routes.json
+++ b/apps/sandbox/scripts/next-export-routes.json
@@ -352,6 +352,7 @@
"/templates/InternationalizationProvider02Overrides/",
"/templates/InternationalizationProvider03RtlDirection/",
"/templates/ItemBasicItem/",
+ "/templates/ItemDocumentTabs/",
"/templates/ItemShowcase/",
"/templates/ItemWithMedia/",
"/templates/ItemWithMetadata/",
diff --git a/docs/pr-assets/6652/item-document-tabs-dark.png b/docs/pr-assets/6652/item-document-tabs-dark.png
new file mode 100644
index 0000000000..9e24b3225b
Binary files /dev/null and b/docs/pr-assets/6652/item-document-tabs-dark.png differ
diff --git a/docs/pr-assets/6652/item-document-tabs-light.png b/docs/pr-assets/6652/item-document-tabs-light.png
new file mode 100644
index 0000000000..83673bc802
Binary files /dev/null and b/docs/pr-assets/6652/item-document-tabs-light.png differ
diff --git a/internal/shadcn-registry/routes.lock.json b/internal/shadcn-registry/routes.lock.json
index a847e190a3..735f0d7be2 100644
--- a/internal/shadcn-registry/routes.lock.json
+++ b/internal/shadcn-registry/routes.lock.json
@@ -2200,6 +2200,11 @@
"path": "examples/item/basic",
"aliases": []
},
+ {
+ "name": "example-item-document-tabs",
+ "path": "examples/item/document-tabs",
+ "aliases": []
+ },
{
"name": "example-item-metadata",
"path": "examples/item/metadata",
diff --git a/packages/cli/assets/templates/blocks/components/Item/ItemDocumentTabs.doc.mjs b/packages/cli/assets/templates/blocks/components/Item/ItemDocumentTabs.doc.mjs
new file mode 100644
index 0000000000..e86737afd9
--- /dev/null
+++ b/packages/cli/assets/templates/blocks/components/Item/ItemDocumentTabs.doc.mjs
@@ -0,0 +1,14 @@
+// Copyright (c) Meta Platforms, Inc. and affiliates.
+
+/** @type {import('@astryxdesign/cli/authoring').TemplateDoc} */
+export const doc = {
+ type: 'block',
+ exampleFor: 'Item',
+ name: 'Item — Document Tabs',
+ displayName: 'Item — Document Tabs',
+ description:
+ 'Single-row, horizontally scrollable document switcher with compact selected rows, leading file icons, instant reveal-on-hover close actions with reserved geometry, stable separators, and an add control outside the scroll area. Use for editor tabs, workspace tabs, open documents, files, canvases, or panels.',
+ isReady: true,
+ aspectRatio: 16 / 4,
+ componentsUsed: ['Item', 'Divider', 'Icon', 'IconButton', 'Layout'],
+};
diff --git a/packages/cli/assets/templates/blocks/components/Item/ItemDocumentTabs.tsx b/packages/cli/assets/templates/blocks/components/Item/ItemDocumentTabs.tsx
new file mode 100644
index 0000000000..8835cce45e
--- /dev/null
+++ b/packages/cli/assets/templates/blocks/components/Item/ItemDocumentTabs.tsx
@@ -0,0 +1,100 @@
+// Copyright (c) Meta Platforms, Inc. and affiliates.
+
+'use client';
+
+import {Fragment} from 'react';
+import * as stylex from '@stylexjs/stylex';
+
+import {Divider} from '@astryxdesign/core/Divider';
+import {useContainerReveal} from '@astryxdesign/core/hooks';
+import {Icon} from '@astryxdesign/core/Icon';
+import {IconButton} from '@astryxdesign/core/IconButton';
+import {Item} from '@astryxdesign/core/Item';
+import {HStack} from '@astryxdesign/core/Layout';
+import {mergeProps} from '@astryxdesign/core/utils';
+import {DocumentIcon, PlusIcon, XMarkIcon} from '@heroicons/react/24/outline';
+
+const TABS = [
+ {name: 'Project brief', isActive: true},
+ {name: 'Research notes', isActive: false},
+ {name: 'Interaction prototype', isActive: false},
+];
+
+const styles = stylex.create({
+ strip: {minWidth: 0, flexShrink: 1, scrollbarWidth: 'none'},
+ rule: {height: 16},
+ hidden: {visibility: 'hidden'},
+ tab: {flexShrink: 1, width: 164, minWidth: 96},
+ action: {margin: 'calc(-1 * var(--spacing-1))', transitionProperty: 'none'},
+});
+function DocumentTab({name, isActive}: (typeof TABS)[number]) {
+ const {getContainerProps, getContentRevealProps} = useContainerReveal();
+ const revealProps = getContentRevealProps({
+ forceVisibility: isActive ? 'shown' : undefined,
+ isLayoutPreserved: true,
+ });
+ return (
+ <Item
+ label={name}
+ density="compact"
+ isSelected={isActive}
+ onClick={() => {}}
+ aria-current={isActive ? 'true' : undefined}
+ {...getContainerProps()}
+ startContent={
+ <Icon
+ icon={DocumentIcon}
+ size="sm"
+ color={isActive ? 'primary' : 'secondary'}
+ />
+ }
+ endContent={
+ <IconButton
+ label={`Close ${name}`}
+ variant="ghost"
+ size="sm"
+ icon={<Icon icon={XMarkIcon} size="sm" />}
+ {...mergeProps(revealProps, stylex.props(styles.action))}
+ />
+ }
+ xstyle={styles.tab}
+ />
+ );
+}
+
+export default function ItemDocumentTabs() {
+ return (
+ <HStack width="100%" maxWidth={600} gap={0.5} vAlign="center">
+ <HStack
+ role="group"
+ aria-label="Open documents"
+ vAlign="center"
+ paddingInline={2}
+ paddingBlock={1}
+ isScrollable
+ xstyle={styles.strip}>
+ {TABS.map((tab, index) => (
+ <Fragment key={tab.name}>
+ {index > 0 ? (
+ <Divider
+ orientation="vertical"
+ xstyle={[
+ styles.rule,
+ (TABS[index - 1]?.isActive || tab.isActive) && styles.hidden,
+ ]}
+ />
+ ) : null}
+ <DocumentTab {...tab} />
+ </Fragment>
+ ))}
+ </HStack>
+ <IconButton
+ label="New document"
+ tooltip="New document"
+ variant="ghost"
+ size="sm"
+ icon={<Icon icon={PlusIcon} size="sm" color="secondary" />}
+ />
+ </HStack>
+ );
+}
diff --git a/packages/cli/test/doc-routes.ids.json b/packages/cli/test/doc-routes.ids.json
index e854074acb..001922783f 100644
--- a/packages/cli/test/doc-routes.ids.json
+++ b/packages/cli/test/doc-routes.ids.json
@@ -598,6 +598,7 @@
"InternationalizationProvider02Overrides",
"InternationalizationProvider03RtlDirection",
"ItemBasicItem",
+ "ItemDocumentTabs",
"ItemShowcase",
"ItemWithMedia",
"ItemWithMetadata",
diff --git a/packages/cli/test/doc-routes.json b/packages/cli/test/doc-routes.json
index c00598ddfc..6a663c59d7 100644
--- a/packages/cli/test/doc-routes.json
+++ b/packages/cli/test/doc-routes.json
@@ -3026,7 +3026,7 @@
"kind": "block",
"id": "@astryxdesign/core/block",
"provider": "@astryxdesign/core",
- "count": 656,
+ "count": 657,
"oldCliRoute": "astryx template <id> --type block",
"oldDocsiteUrl": null,
"placement": "generated:@astryxdesign/core/block",