Skip to content

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

TypeScript

fix(docsite): add AppShell mobile hook example (#2775)

Cindy Zhang070d9bc815b4
diff --git a/packages/cli/templates/blocks/components/AppShell/AppShellMobileHookUsage.doc.mjs b/packages/cli/templates/blocks/components/AppShell/AppShellMobileHookUsage.doc.mjs
new file mode 100644
index 0000000000..2fe9e39245
--- /dev/null
+++ b/packages/cli/templates/blocks/components/AppShell/AppShellMobileHookUsage.doc.mjs
@@ -0,0 +1,14 @@
+// Copyright (c) Meta Platforms, Inc. and affiliates.
+
+/** @type {import('../../../../../core/src/docs-types').TemplateDoc} */
+export const doc = {
+ type: 'block',
+ exampleFor: 'useXDSAppShellMobile',
+ name: 'useXDSAppShellMobile — Custom Mobile Trigger',
+ displayName: 'useXDSAppShellMobile — Custom Mobile Trigger',
+ description:
+ 'Custom mobile navigation trigger built with useXDSAppShellMobile. The trigger consumes the surrounding AppShell context instead of rendering its own shell.',
+ isReady: true,
+ aspectRatio: 4 / 3,
+ componentsUsed: ['AppShell', 'Button', 'Text', 'Layout'],
+};
diff --git a/packages/cli/templates/blocks/components/AppShell/AppShellMobileHookUsage.tsx b/packages/cli/templates/blocks/components/AppShell/AppShellMobileHookUsage.tsx
new file mode 100644
index 0000000000..9bf7264174
--- /dev/null
+++ b/packages/cli/templates/blocks/components/AppShell/AppShellMobileHookUsage.tsx
@@ -0,0 +1,62 @@
+// Copyright (c) Meta Platforms, Inc. and affiliates.
+
+'use client';
+
+import {useXDSAppShellMobile} from '@xds/core/AppShell';
+import {XDSButton} from '@xds/core/Button';
+import {XDSHStack, XDSVStack} from '@xds/core/Layout';
+import {XDSText} from '@xds/core/Text';
+
+export default function AppShellMobileHookUsage() {
+ const {
+ closeMobileNav,
+ isMobile,
+ isMobileNavEnabled,
+ isMobileNavOpen,
+ openMobileNav,
+ } = useXDSAppShellMobile();
+
+ if (!isMobileNavEnabled) {
+ return (
+ <XDSVStack gap={2}>
+ <XDSButton label="Open navigation" variant="secondary" isDisabled />
+ <XDSText type="body" color="secondary">
+ No active AppShell mobile navigation context was detected. This hook
+ returns safe defaults outside AppShell, or when the surrounding
+ AppShell has mobile navigation disabled.
+ </XDSText>
+ </XDSVStack>
+ );
+ }
+
+ if (!isMobile) {
+ return (
+ <XDSVStack gap={2}>
+ <XDSButton label="Open navigation" variant="secondary" isDisabled />
+ <XDSText type="body" color="secondary">
+ AppShell mobile navigation context is available. Narrow the viewport
+ below the AppShell mobile breakpoint to make the custom trigger active.
+ </XDSText>
+ </XDSVStack>
+ );
+ }
+
+ return (
+ <XDSVStack gap={2}>
+ <XDSHStack gap={2} vAlign="center">
+ <XDSButton
+ label={isMobileNavOpen ? 'Close navigation' : 'Open navigation'}
+ variant="secondary"
+ onClick={isMobileNavOpen ? closeMobileNav : openMobileNav}
+ />
+ <XDSText type="body" color="secondary">
+ {isMobileNavOpen ? 'Mobile nav is open' : 'Mobile nav is closed'}
+ </XDSText>
+ </XDSHStack>
+ <XDSText type="body" color="secondary">
+ This button controls the nearest AppShell mobile nav from context — in
+ the docsite it opens and closes the surrounding page navigation.
+ </XDSText>
+ </XDSVStack>
+ );
+}
diff --git a/packages/cli/templates/blocks/components/AppShell/AppShellTopNavWithSideNav.doc.mjs b/packages/cli/templates/blocks/components/AppShell/AppShellTopNavWithSideNav.doc.mjs
index c7d3b43991..73be6835f1 100644
--- a/packages/cli/templates/blocks/components/AppShell/AppShellTopNavWithSideNav.doc.mjs
+++ b/packages/cli/templates/blocks/components/AppShell/AppShellTopNavWithSideNav.doc.mjs
@@ -4,7 +4,6 @@
export const doc = {
type: 'block',
exampleFor: 'AppShell',
- alsoExampleFor: ['useXDSAppShellMobile'],
name: 'AppShell — Top Nav with Side Nav',
displayName: 'AppShell — Top Nav with Side Nav',
description: