-
Notifications
You must be signed in to change notification settings - Fork 567
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve programmatic state management of UnderlinePanels (#5527)
* add onSelect prop to UnderlinePanels and UnderlinePanels.Tab * UnderlinePanels doc updates * unit test for programmatically selecting tab + updates to underline panels * rename unit test + code clean-up * add test for tab onSelect prop * comment explaining UnderlinePanels changes * pr feedback * add changeset * storybook updates * fixed UnderlinePanels.Tab story rendering issues * fix playwright vrt regressions * added UnderlinePanels.Tab story to .dev * remove no tabs selected case from dev story --------- Co-authored-by: Marie Lucca <40550942+francinelucca@users.noreply.github.com>
- Loading branch information
1 parent
16c572e
commit ccc3c99
Showing
6 changed files
with
246 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@primer/react": minor | ||
--- | ||
|
||
Add an onSelect callback for UnderlinePanels.Tab |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 73 additions & 14 deletions
87
packages/react/src/experimental/UnderlinePanels/UnderlinePanels.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,79 @@ | ||
import React from 'react' | ||
import type {Meta} from '@storybook/react' | ||
import type {Meta, StoryFn} from '@storybook/react' | ||
import UnderlinePanels from './UnderlinePanels' | ||
import type {ComponentProps} from '../../utils/types' | ||
|
||
export default { | ||
const meta: Meta<typeof UnderlinePanels> = { | ||
title: 'Experimental/Components/UnderlinePanels', | ||
component: UnderlinePanels, | ||
} as Meta<ComponentProps<typeof UnderlinePanels>> | ||
parameters: { | ||
controls: { | ||
expanded: true, | ||
}, | ||
}, | ||
argTypes: { | ||
'aria-label': { | ||
type: { | ||
name: 'string', | ||
}, | ||
}, | ||
'aria-labelledby': { | ||
type: { | ||
name: 'string', | ||
}, | ||
}, | ||
id: { | ||
type: { | ||
name: 'string', | ||
}, | ||
}, | ||
loadingCounters: { | ||
control: { | ||
type: 'boolean', | ||
}, | ||
}, | ||
}, | ||
args: { | ||
'aria-label': 'Select a tab', | ||
'aria-labelledby': 'tab', | ||
id: 'test', | ||
loadingCounters: false, | ||
}, | ||
} | ||
|
||
export const Default = () => ( | ||
<UnderlinePanels aria-label="Select a tab"> | ||
<UnderlinePanels.Tab>Tab 1</UnderlinePanels.Tab> | ||
<UnderlinePanels.Tab>Tab 2</UnderlinePanels.Tab> | ||
<UnderlinePanels.Tab>Tab 3</UnderlinePanels.Tab> | ||
<UnderlinePanels.Panel>Panel 1</UnderlinePanels.Panel> | ||
<UnderlinePanels.Panel>Panel 2</UnderlinePanels.Panel> | ||
<UnderlinePanels.Panel>Panel 3</UnderlinePanels.Panel> | ||
</UnderlinePanels> | ||
) | ||
export default meta | ||
|
||
export const Default: StoryFn<typeof UnderlinePanels> = () => { | ||
const tabs = ['Tab 1', 'Tab 2', 'Tab 3'] | ||
const panels = ['Panel 1', 'Panel 2', 'Panel 3'] | ||
|
||
return ( | ||
<UnderlinePanels aria-label="Select a tab"> | ||
{tabs.map((tab: string, index: number) => ( | ||
<UnderlinePanels.Tab key={index} aria-selected={index === 0 ? true : undefined}> | ||
{tab} | ||
</UnderlinePanels.Tab> | ||
))} | ||
{panels.map((panel: string, index: number) => ( | ||
<UnderlinePanels.Panel key={index}>{panel}</UnderlinePanels.Panel> | ||
))} | ||
</UnderlinePanels> | ||
) | ||
} | ||
|
||
export const Playgound: StoryFn<typeof UnderlinePanels> = args => { | ||
const tabs = ['Tab 1', 'Tab 2', 'Tab 3'] | ||
const panels = ['Panel 1', 'Panel 2', 'Panel 3'] | ||
|
||
return ( | ||
<UnderlinePanels {...args}> | ||
{tabs.map((tab: string, index: number) => ( | ||
<UnderlinePanels.Tab key={index} aria-selected={index === 0 ? true : undefined}> | ||
{tab} | ||
</UnderlinePanels.Tab> | ||
))} | ||
{panels.map((panel: string, index: number) => ( | ||
<UnderlinePanels.Panel key={index}>{panel}</UnderlinePanels.Panel> | ||
))} | ||
</UnderlinePanels> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.