Skip to content

Commit b59fc9e

Browse files
Yuraima Estevezkyledurand
andauthored
[ButtonGroup] Removed segmented boolean prop and replaced with variant (#9997)
<!-- ☝️How to write a good PR title: - Prefix it with [ComponentName] (if applicable), for example: [Button] - Start with a verb, for example: Add, Delete, Improve, Fix… - Give as much context as necessary and as little as possible - Prefix it with [WIP] while it’s a work in progress --> ### WHY are these changes introduced? Fixes #9981 Removing boolean props from various components. Renaming spacing prop to `gap` for consistency <!-- Context about the problem that’s being addressed. --> ### WHAT is this pull request doing? * Replaces the `segmented` boolean prop with a `variant='segmented'` prop * Updates `ButtonGroup` story * Updates css attributed selector in `Button` to match `variant='segmented'` * Renames `spacing` to `gap` <!-- Summary of the changes committed. Before / after screenshots are appreciated for UI changes. Make sure to include alt text that describes the screenshot. If you include an animated gif showing your change, wrapping it in a details tag is recommended. Gifs usually autoplay, which can cause accessibility issues for people reviewing your PR: <details> <summary>Summary of your gif(s)</summary> <img src="..." alt="Description of what the gif shows"> </details> --> <!-- ℹ️ Delete the following for small / trivial changes --> ### How to 🎩 Review in storybook, there should be no visual changes 🖥 [Local development instructions](https://github.com/Shopify/polaris/blob/main/README.md#local-development) 🗒 [General tophatting guidelines](https://github.com/Shopify/polaris/blob/main/documentation/Tophatting.md) 📄 [Changelog guidelines](https://github.com/Shopify/polaris/blob/main/.github/CONTRIBUTING.md#changelog) <!-- Give as much information as needed to experiment with the component in the playground. --> <details> <summary>Copy-paste this code in <code>playground/Playground.tsx</code>:</summary> ```jsx import React from 'react'; import {Page} from '../src'; export function Playground() { return ( <Page title="Playground"> {/* Add the code you want to test in here */} </Page> ); } ``` </details> ### 🎩 checklist - [ ] Tested on [mobile](https://github.com/Shopify/polaris/blob/main/documentation/Tophatting.md#cross-browser-testing) - [ ] Tested on [multiple browsers](https://help.shopify.com/en/manual/shopify-admin/supported-browsers) - [ ] Tested for [accessibility](https://github.com/Shopify/polaris/blob/main/documentation/Accessibility%20testing.md) - [ ] Updated the component's `README.md` with documentation changes - [ ] [Tophatted documentation](https://github.com/Shopify/polaris/blob/main/documentation/Tophatting%20documentation.md) changes in the style guide --------- Co-authored-by: kyledurand <kyle.durand@shopify.com>
1 parent 776f28a commit b59fc9e

File tree

19 files changed

+66
-36
lines changed

19 files changed

+66
-36
lines changed

.changeset/fuzzy-coats-study.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@shopify/polaris': major
3+
---
4+
5+
[ButtonGroup] Removed `segmented` boolean prop and replaced with `variant`. Replaced `spacing` prop with `gap`

polaris-react/src/components/ActionMenu/components/Actions/Actions.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ export function Actions({actions = [], groups = [], onActionRollup}: Props) {
311311
});
312312

313313
const groupedActionsMarkup = (
314-
<ButtonGroup spacing="tight">
314+
<ButtonGroup gap="tight">
315315
{rollUppableActionsMarkup}
316316
{actionsMarkup}
317317
{groupsMarkup}

polaris-react/src/components/Button/Button.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -970,7 +970,7 @@
970970
}
971971
// stylelint-enable selector-max-specificity, selector-max-class
972972
// stylelint-disable selector-max-combinators, selector-max-specificity -- generated by polaris-migrator DO NOT COPY
973-
[data-buttongroup-segmented='true'] {
973+
[data-buttongroup-variant='segmented'] {
974974
.Button,
975975
.Button::after {
976976
border-radius: 0;

polaris-react/src/components/Button/Button.stories.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,7 @@ export function Pressed() {
576576
}, [isFirstButtonActive]);
577577

578578
return (
579-
<ButtonGroup segmented>
579+
<ButtonGroup variant="segmented">
580580
<Button pressed={isFirstButtonActive} onClick={handleFirstButtonClick}>
581581
First button
582582
</Button>
@@ -634,7 +634,7 @@ export function Split() {
634634
const [active, setActive] = React.useState(false);
635635
return (
636636
<div style={{height: '100px'}}>
637-
<ButtonGroup segmented>
637+
<ButtonGroup variant="segmented">
638638
<Button variant="primary">Save</Button>
639639

640640
<div style={{width: '0px'}} />

polaris-react/src/components/ButtonGroup/ButtonGroup.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
}
2828
}
2929

30-
.segmented {
30+
.variantSegmented {
3131
display: flex;
3232
flex-wrap: nowrap;
3333
margin-top: 0;

polaris-react/src/components/ButtonGroup/ButtonGroup.stories.tsx

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React, {useCallback, useState} from 'react';
22
import type {ComponentMeta} from '@storybook/react';
3-
import {Button, ButtonGroup} from '@shopify/polaris';
3+
import {Button, ButtonGroup, BlockStack} from '@shopify/polaris';
44

55
export default {
66
component: ButtonGroup,
@@ -27,13 +27,13 @@ export function WithSegmentedButtons() {
2727
);
2828
return (
2929
<div>
30-
<ButtonGroup segmented>
30+
<ButtonGroup variant="segmented">
3131
<Button>Bold</Button>
3232
<Button pressed>Italic</Button>
3333
<Button>Underline</Button>
3434
</ButtonGroup>
3535
<br />
36-
<ButtonGroup segmented>
36+
<ButtonGroup variant="segmented">
3737
<Button
3838
pressed={activeButtonIndex === 0}
3939
onClick={() => handleButtonClick(0)}
@@ -89,14 +89,36 @@ export function WithSegmentedButtons() {
8989

9090
export function OutlineWithSegmentedButtons() {
9191
return (
92-
<ButtonGroup segmented>
92+
<ButtonGroup variant="segmented">
9393
<Button>Bold</Button>
9494
<Button>Italic</Button>
9595
<Button>Underline</Button>
9696
</ButtonGroup>
9797
);
9898
}
9999

100+
export function WithAllGaps() {
101+
return (
102+
<BlockStack gap="4">
103+
<ButtonGroup gap="extraTight" connectedTop>
104+
<Button>Bold</Button>
105+
<Button>Italic</Button>
106+
<Button>Underline</Button>
107+
</ButtonGroup>
108+
<ButtonGroup gap="tight">
109+
<Button>Bold</Button>
110+
<Button>Italic</Button>
111+
<Button>Underline</Button>
112+
</ButtonGroup>
113+
<ButtonGroup gap="loose">
114+
<Button>Bold</Button>
115+
<Button>Italic</Button>
116+
<Button>Underline</Button>
117+
</ButtonGroup>
118+
</BlockStack>
119+
);
120+
}
121+
100122
export function NoWrapButtons() {
101123
return (
102124
<>

polaris-react/src/components/ButtonGroup/ButtonGroup.tsx

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
import React from 'react';
22

3-
import {classNames} from '../../utilities/css';
3+
import {classNames, variationName} from '../../utilities/css';
44
import {elementChildren} from '../../utilities/components';
55

66
import {Item} from './components';
77
import styles from './ButtonGroup.scss';
88

9-
type Spacing = 'extraTight' | 'tight' | 'loose';
9+
type Gap = 'extraTight' | 'tight' | 'loose';
10+
11+
type Variant = 'segmented';
1012

1113
export interface ButtonGroupProps {
1214
/** Determines the space between button group items */
13-
spacing?: Spacing;
14-
/** Join buttons as segmented group */
15-
segmented?: boolean;
15+
gap?: Gap;
16+
/** Styling variant for group */
17+
variant?: Variant;
1618
/** Buttons will stretch/shrink to occupy the full width */
1719
fullWidth?: boolean;
1820
/** Remove top left and right border radius */
@@ -25,16 +27,16 @@ export interface ButtonGroupProps {
2527

2628
export function ButtonGroup({
2729
children,
28-
spacing,
29-
segmented,
30+
gap,
31+
variant,
3032
fullWidth,
3133
connectedTop,
3234
noWrap,
3335
}: ButtonGroupProps) {
3436
const className = classNames(
3537
styles.ButtonGroup,
36-
spacing && styles[spacing],
37-
segmented && styles.segmented,
38+
gap && styles[gap],
39+
variant && styles[variationName('variant', variant)],
3840
fullWidth && styles.fullWidth,
3941
noWrap && styles.noWrap,
4042
);
@@ -46,7 +48,7 @@ export function ButtonGroup({
4648
return (
4749
<div
4850
className={className}
49-
data-buttongroup-segmented={segmented}
51+
data-buttongroup-variant={variant}
5052
data-buttongroup-connected-top={connectedTop}
5153
data-buttongroup-full-width={fullWidth}
5254
data-buttongroup-no-wrap={noWrap}

polaris-react/src/components/ButtonGroup/tests/ButtonGroup.test.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,15 @@ describe('<ButtonGroup />', () => {
2929
expect(item.find(Button)).toContainReactText('Cancel');
3030
});
3131

32-
it('adds a data-buttongroup-segmented to the outter div when segmented', () => {
32+
it('adds a data-buttongroup-variant to the outter div when variant is passed', () => {
33+
const variant = 'segmented';
3334
const buttonGroup = mountWithApp(
34-
<ButtonGroup segmented>
35+
<ButtonGroup variant={variant}>
3536
<Button />
3637
</ButtonGroup>,
3738
);
3839
const selector: any = {
39-
'data-buttongroup-segmented': true,
40+
'data-buttongroup-variant': variant,
4041
};
4142
expect(buttonGroup).toContainReactComponent('div', selector);
4243
});

polaris-react/src/components/Pagination/Pagination.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ export function Pagination({
175175
<nav aria-label={navLabel} ref={node} className={styles.Pagination}>
176176
{previousButtonEvents}
177177
{nextButtonEvents}
178-
<ButtonGroup segmented>
178+
<ButtonGroup variant="segmented">
179179
{constructedPrevious}
180180
{labelMarkup}
181181
{constructedNext}

polaris-react/src/components/Pagination/tests/Pagination.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ describe('<Pagination />', () => {
248248
);
249249

250250
expect(pagination).toContainReactComponent(ButtonGroup, {
251-
segmented: true,
251+
variant: 'segmented',
252252
});
253253
expect(pagination).toContainReactComponent(Button, {url: '/prev'});
254254
expect(pagination).toContainReactComponent(Button, {url: '/next'});
@@ -260,7 +260,7 @@ describe('<Pagination />', () => {
260260
);
261261

262262
expect(pagination).toContainReactComponent(ButtonGroup, {
263-
segmented: true,
263+
variant: 'segmented',
264264
});
265265
});
266266
});

0 commit comments

Comments
 (0)