import React from 'react'
import { type Meta, type StoryObj } from '@storybook/react'
import { expect, waitFor, within } from '@storybook/test'
import { Heading } from 'react-aria-components'
import { Icon } from '~components/Icon'
import { assetUrl } from '~components/utils/hostedAssets'
import { StickerSheet } from '~storybook/components/StickerSheet'
import { NavigationTab, TitleBlock } from '../index'
const SECONDARY_ACTIONS = [
{
label: 'Secondary menu',
menuItems: [
{
onClick: (): void => alert('test'),
label: 'Secondary menu action 1',
},
{
onClick: (): void => alert('test'),
label: 'Secondary menu action 2',
icon: ,
},
],
},
{
onClick: (): void => alert('test'),
label: 'Secondary action',
},
]
const viewports = {
viewports: {
default: {
name: 'desktop (above or equal to 1366)',
styles: { width: '1366px', height: '800px' },
type: 'desktop',
},
desktopSm: {
name: 'desktop-sm (1024 - 1365)',
styles: { width: '1365px', height: '800px' },
type: 'desktop',
},
tablet: {
name: 'tablet (672 - 1023)',
styles: { width: '1023px', height: '800px' },
type: 'desktop',
},
mobileResponsive: {
name: 'mobile-responsive (512 - 671)',
styles: { width: '671px', height: '800px' },
type: 'desktop',
},
mobile: {
name: 'mobile (361 - 512)',
styles: { width: '511px', height: '800px' },
type: 'desktop',
},
mobileXs: {
name: 'mobile (under 360)',
styles: { width: '360px', height: '800px' },
type: 'desktop',
},
},
defaultViewport: 'default',
}
const chromaticViewports = {
disable: false,
viewports: [1366, 1365, 1079, 360, 320],
}
const meta = {
title: 'Components/TitleBlock',
component: TitleBlock,
parameters: {
chromatic: { disable: false },
layout: 'fullscreen',
},
args: {
title: 'Page title',
surveyStatus: { text: 'Due July 8, 2030', status: 'default' },
avatar: {
avatarSrc: assetUrl('site/empty-state.png'),
fullName: 'Blanca Wheeler',
},
primaryAction: {
label: 'Primary link',
icon: ,
disabled: true,
href: '#',
},
defaultAction: {
label: 'Default link',
href: '#',
},
secondaryActions: SECONDARY_ACTIONS,
secondaryOverflowMenuItems: [
{
label: 'Overflow action 1',
icon: ,
},
{
label: 'Overflow link 1',
icon: ,
},
],
handleHamburgerClick: (): void => alert('Hamburger clicked'),
breadcrumb: {
path: '#',
text: 'Back to home',
handleClick: (): void => alert('breadcrumb clicked!'),
},
navigationTabs: [
,
,
,
,
,
,
],
},
} satisfies Meta
export default meta
type Story = StoryObj
export const Playground: Story = {
parameters: {
docs: {
canvas: {
sourceState: 'shown',
},
},
},
}
export const Viewports: Story = {
parameters: {
viewport: viewports,
chromatic: chromaticViewports,
},
}
export const WithTabNavigation: Story = {
parameters: {
viewport: viewports,
chromatic: chromaticViewports,
},
play: async ({ canvasElement, step }) => {
const canvas = within(canvasElement.parentElement!)
const TabNavigation = await canvas.findByRole('navigation', {
name: 'Page title',
})
await step('Navigation Tab is present', async () => {
await waitFor(() => expect(TabNavigation).toBeInTheDocument())
})
await step('Navigation is focusable', async () => {
const NavigationList = canvas.getByRole('list')
const listItems = within(NavigationList).getAllByRole('listitem')
const thirdNavigationLink = within(listItems[2]).getByRole('link')
thirdNavigationLink.focus()
expect(thirdNavigationLink).toHaveFocus()
})
},
}
export const HasLongTitle: Story = {
parameters: {
viewport: viewports,
chromatic: chromaticViewports,
},
args: { title: 'A long title with over thirty characters' },
}
export const LightVariant: Story = {
parameters: {
docs: {
canvas: {
sourceState: 'shown',
},
},
viewport: viewports,
chromatic: chromaticViewports,
},
args: {
variant: 'light',
title: 'Light TitleBlock',
navigationTabs: [
,
,
,
,
,
,
],
},
}
export const AdminVariant: Story = {
parameters: {
viewport: viewports,
chromatic: chromaticViewports,
},
args: {
variant: 'admin',
navigationTabs: [
,
,
,
,
,
,
],
},
}
export const EducationVariant: Story = {
parameters: {
viewport: viewports,
chromatic: chromaticViewports,
},
args: {
variant: 'education',
navigationTabs: [
,
,
,
,
,
,
],
},
}
export const StickerSheetVariants: Story = {
name: 'Sticker Sheet (Variants)',
render: () => (
,
,
]}
/>
,
,
]}
/>
,
,
]}
/>
,
,
]}
/>
),
}
export const StickerSheetWithDefaultAvatar: Story = {
name: 'Sticker Sheet (DefaultAvatar)',
render: () => (
),
}
export const StickerSheetVariantsWithSection: Story = {
name: 'Sticker Sheet (Variants With Section)',
render: () => (
),
}
export const StickerSheetVariantsWithSectionTitleOnly: Story = {
name: 'Sticker Sheet (Section Title Only)',
render: () => (
),
}
export const StickerSheetVariantsWithCollapseNavigationAreaWhenPossible: Story = {
name: 'Sticker Sheet (Variants WithCollapseNavigationAreaWhenPossible)',
render: () => (
),
}
export const StickerSheetBreadcrumbs: Story = {
name: 'Sticker Sheet (Breadcrumb)',
parameters: {
docs: {
canvas: {
sourceState: 'shown',
},
},
pseudo: {
hover: [
'#tab-hover-example [class^="TitleBlock-TitleBlock-module__navigationTabsList"] li:nth-child(2) a',
'#Breadcrumbs-hover-example [class^="TitleBlock-TitleBlock-module__breadcrumb"]',
],
focus: [
'#tab-focus-example [class^="TitleBlock-TitleBlock-module__navigationTabsList"] li:nth-child(2) a',
'#Breadcrumbs-focus-example [class^="TitleBlock-TitleBlock-module__breadcrumb"]',
],
},
a11y: {
config: {
rules: [
{
id: 'color-contrast', // false positive from animate in on the breadcrumbs
enabled: false,
},
{
id: 'landmark-unique', // false positive from having multiple TitleBlocks on a page
enabled: false,
},
],
},
},
},
render: (args) => (
),
}
export const StickerSheetSurveyStatus: Story = {
name: 'Sticker Sheet (Survey Status)',
render: () => (
Draft
Default
Due
Overdue
Completed
Completed
),
}
export const WithSection: Story = {
parameters: {
viewport: viewports,
chromatic: chromaticViewports,
},
args: {
title: 'A extra long title with over thirty characters so it truncates in a mobile viewport',
sectionTitle: 'Section title',
sectionTitleDescription: 'Description of section can go here',
navigationTabs: undefined,
surveyStatus: undefined,
},
}
export const WithCustomSectionTitleOnly: Story = {
parameters: {
viewport: viewports,
chromatic: chromaticViewports,
},
args: {
title: 'Page title',
renderSectionTitle: () => (
Custom Section Title
),
navigationTabs: undefined,
surveyStatus: undefined,
secondaryActions: undefined,
secondaryOverflowMenuItems: undefined,
primaryAction: undefined,
defaultAction: undefined,
},
}
export const WithTitleCollapseNavigationAreaWhenPossible: Story = {
parameters: {
viewport: viewports,
chromatic: chromaticViewports,
},
args: {
title: 'Page title',
navigationTabs: undefined,
surveyStatus: undefined,
primaryAction: undefined,
defaultAction: undefined,
secondaryActions: undefined,
secondaryOverflowMenuItems: undefined,
breadcrumb: undefined,
avatar: undefined,
collapseNavigationAreaWhenPossible: true,
},
}
export const WithOnlySecondaryActions: Story = {
parameters: {
viewport: viewports,
chromatic: chromaticViewports,
},
args: {
title: 'Page title',
navigationTabs: undefined,
surveyStatus: undefined,
primaryAction: undefined,
defaultAction: undefined,
sectionTitle: undefined,
sectionTitleDescription: undefined,
breadcrumb: undefined,
avatar: undefined,
},
}