-
Notifications
You must be signed in to change notification settings - Fork 646
Remove use of useResponsiveValue hook - SegmentedControl #7134
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
hectahertz
wants to merge
16
commits into
main
Choose a base branch
from
hectahertz/getResponsiveAttributes-SegmentedControl
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
1b0a508
Implementation
hectahertz 0f1a1ef
Add stories
hectahertz 4c22f75
Add changelog
hectahertz cd04070
Improve stories
hectahertz 19c9113
Fix fullWidth rules
hectahertz 42c5bde
Reorganize css
hectahertz 993431c
Update packages/react/src/SegmentedControl/SegmentedControl.tsx
hectahertz 05c6a82
Merge branch 'main' into hectahertz/getResponsiveAttributes-Segmented…
hectahertz baa385a
Fix types
hectahertz 18a5499
Fix types
hectahertz 4b58f33
Fix stylelint
hectahertz 5a996e8
Add story for {narrow: 'dropdown'}
hectahertz ed0ac84
Fix tests
hectahertz d27c6d0
Remove outdated test
hectahertz acd9830
Adapt test for proper aria labels on icon buttons
hectahertz 902c011
Merge branch 'main' into hectahertz/getResponsiveAttributes-Segmented…
hectahertz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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": patch | ||
| --- | ||
|
|
||
| SegmentedControl: Remove useResponsiveValue hook from fullWidth and variant props to use `getResponsiveAttributes` instead. |
This file contains hidden or 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
148 changes: 148 additions & 0 deletions
148
packages/react/src/SegmentedControl/SegmentedControl.responsive.stories.tsx
This file contains hidden or 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,148 @@ | ||
| import type {Meta, StoryFn} from '@storybook/react-vite' | ||
| import React from 'react' | ||
| import {SegmentedControl} from './SegmentedControl' | ||
| import {EyeIcon, FileCodeIcon, PeopleIcon} from '@primer/octicons-react' | ||
|
|
||
| const meta: Meta = { | ||
| title: 'Components/SegmentedControl/Responsive Tests', | ||
| parameters: { | ||
| layout: 'padded', | ||
| controls: {expanded: true}, | ||
| }, | ||
| } | ||
|
|
||
| export default meta | ||
|
|
||
| /** | ||
| * Test responsive fullWidth behavior. | ||
| * Resize the viewport to see the control change width at different breakpoints. | ||
| */ | ||
| export const FullWidthResponsive: StoryFn = () => ( | ||
| <div> | ||
| <p style={{marginBottom: '16px'}}>Full width: yes (narrow) → no (regular + wide)</p> | ||
| <SegmentedControl aria-label="File view" fullWidth={{narrow: true, regular: false, wide: false}}> | ||
| <SegmentedControl.Button defaultSelected leadingVisual={EyeIcon}> | ||
| Preview | ||
| </SegmentedControl.Button> | ||
| <SegmentedControl.Button leadingVisual={FileCodeIcon}>Raw</SegmentedControl.Button> | ||
| <SegmentedControl.Button leadingVisual={PeopleIcon}>Blame</SegmentedControl.Button> | ||
| </SegmentedControl> | ||
| </div> | ||
| ) | ||
|
|
||
| FullWidthResponsive.parameters = { | ||
| docs: { | ||
| description: { | ||
| story: | ||
| 'The control fills the full width on **narrow** viewports and uses inline width on **regular** and **wide** viewports.', | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
| /** | ||
| * Test responsive variant behavior with hideLabels. | ||
| * Resize the viewport to see labels hide/show at different breakpoints. | ||
| */ | ||
| export const VariantHideLabelsResponsive: StoryFn = () => ( | ||
| <div> | ||
| <p style={{marginBottom: '16px'}}>Labels: hidden (narrow) → visible (regular + wide)</p> | ||
| <SegmentedControl aria-label="File view" variant={{narrow: 'hideLabels', regular: 'default', wide: 'default'}}> | ||
| <SegmentedControl.Button defaultSelected leadingVisual={EyeIcon}> | ||
| Preview | ||
| </SegmentedControl.Button> | ||
| <SegmentedControl.Button leadingVisual={FileCodeIcon}>Raw</SegmentedControl.Button> | ||
| <SegmentedControl.Button leadingVisual={PeopleIcon}>Blame</SegmentedControl.Button> | ||
| </SegmentedControl> | ||
| </div> | ||
| ) | ||
|
|
||
| VariantHideLabelsResponsive.parameters = { | ||
| docs: { | ||
| description: { | ||
| story: | ||
| 'Labels are **hidden** (icon-only) on narrow viewports and **visible** on regular and wide viewports. Note: leadingVisual prop is required for hideLabels variant.', | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
| /** | ||
| * Test responsive variant behavior with dropdown. | ||
| * Resize the viewport to see the control switch between dropdown and buttons. | ||
| */ | ||
| export const VariantDropdownResponsive: StoryFn = () => ( | ||
| <div> | ||
| <p style={{marginBottom: '16px'}}>Variant: dropdown (narrow) → buttons (regular + wide)</p> | ||
| <SegmentedControl aria-label="File view" variant={{narrow: 'dropdown', regular: 'default', wide: 'default'}}> | ||
| <SegmentedControl.Button defaultSelected leadingVisual={EyeIcon}> | ||
| Preview | ||
| </SegmentedControl.Button> | ||
| <SegmentedControl.Button leadingVisual={FileCodeIcon}>Raw</SegmentedControl.Button> | ||
| <SegmentedControl.Button leadingVisual={PeopleIcon}>Blame</SegmentedControl.Button> | ||
| </SegmentedControl> | ||
| </div> | ||
| ) | ||
|
|
||
| VariantDropdownResponsive.parameters = { | ||
| docs: { | ||
| description: { | ||
| story: | ||
| 'Renders as a **dropdown menu** on narrow viewports and as **segmented buttons** on regular and wide viewports.', | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
| /** | ||
| * Test responsive variant behavior when only the narrow breakpoint is specified. | ||
| */ | ||
| export const VariantDropdownNarrowOnly: StoryFn = () => ( | ||
| <div> | ||
| <p style={{marginBottom: '16px'}}>Variant: dropdown (narrow) → buttons (others inherit default)</p> | ||
| <SegmentedControl aria-label="File view" variant={{narrow: 'dropdown'}}> | ||
| <SegmentedControl.Button defaultSelected leadingVisual={EyeIcon}> | ||
| Preview | ||
| </SegmentedControl.Button> | ||
| <SegmentedControl.Button leadingVisual={FileCodeIcon}>Raw</SegmentedControl.Button> | ||
| <SegmentedControl.Button leadingVisual={PeopleIcon}>Blame</SegmentedControl.Button> | ||
| </SegmentedControl> | ||
| </div> | ||
| ) | ||
|
|
||
| VariantDropdownNarrowOnly.parameters = { | ||
| docs: { | ||
| description: { | ||
| story: | ||
| 'Only the **narrow** breakpoint sets the dropdown variant; wider breakpoints fall back to the default segmented buttons.', | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
| /** | ||
| * Test complex responsive behavior combining fullWidth and variant. | ||
| */ | ||
| export const ComplexResponsive: StoryFn = () => ( | ||
| <div> | ||
| <p style={{marginBottom: '16px'}}> | ||
| Complex: full-width + icon-only (narrow) → full-width + labels (regular) → inline + labels (wide) | ||
| </p> | ||
| <SegmentedControl | ||
| aria-label="File view" | ||
| fullWidth={{narrow: true, regular: true, wide: false}} | ||
| variant={{narrow: 'hideLabels', regular: 'default', wide: 'default'}} | ||
| > | ||
| <SegmentedControl.Button defaultSelected leadingVisual={EyeIcon}> | ||
| Preview | ||
| </SegmentedControl.Button> | ||
| <SegmentedControl.Button leadingVisual={FileCodeIcon}>Raw</SegmentedControl.Button> | ||
| <SegmentedControl.Button leadingVisual={PeopleIcon}>Blame</SegmentedControl.Button> | ||
| </SegmentedControl> | ||
| </div> | ||
| ) | ||
|
|
||
| ComplexResponsive.parameters = { | ||
| docs: { | ||
| description: { | ||
| story: | ||
| 'Complex: **full-width + icon-only** (narrow) → **full-width + labels** (regular) → **inline + labels** (wide)', | ||
| }, | ||
| }, | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reminder to add to VRT if desired