Skip to content

Commit

Permalink
[Button] Replace booleans with new props (#10090)
Browse files Browse the repository at this point in the history
### WHY are these changes introduced?

Fixes #10047

### WHAT is this pull request doing?

- Adds `variant` and `tone` props
- Removes `primary`, `outline`, `plain`, `monochrome`, and
`primarySuccess` booleans
- Updates props on usages of `Button`
- Renames `primaryPlain` variant to `tertiary`
  • Loading branch information
aveline authored Aug 22, 2023
1 parent 92c3d96 commit 4caed28
Show file tree
Hide file tree
Showing 76 changed files with 286 additions and 612 deletions.
5 changes: 5 additions & 0 deletions .changeset/silent-brooms-confess.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@shopify/polaris': major
---

Consolidated boolean `Button` props into `variant` prop
3 changes: 3 additions & 0 deletions documentation/guides/migrating-from-v11-to-v12.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,6 @@ Secondary, becomes oneThird:
**HorizontalGrid**

`npx @shopify/polaris-migrator react-rename-component <path> --renameFrom="HorizontalGrid" --renameTo="InlineGrid" --renamePropsFrom="HorizontalGridProps" --renamePropsTo="InlineGridProps"`

**Button**
// TODO
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export function AccountConnection({
) : null;

const actionElement = action
? buttonFrom(action, {primary: !connected})
? buttonFrom(action, {variant: connected ? undefined : 'primary'})
: null;

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ describe('<AccountConnection />', () => {
expect(accountConnection).toContainReactComponent(Button, {
children: action.content,
onClick: action.onAction,
primary: true,
variant: 'primary',
});
});

Expand All @@ -78,7 +78,6 @@ describe('<AccountConnection />', () => {
expect(accountConnection).toContainReactComponent(Button, {
children: action.content,
onClick: action.onAction,
primary: false,
});
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ export function RollupActions({
const activatorMarkup = (
<div className={styles.RollupActivator}>
<Button
outline
icon={HorizontalDotsMinor}
accessibilityLabel={
accessibilityLabel ||
Expand Down
3 changes: 1 addition & 2 deletions polaris-react/src/components/Banner/Banner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,7 @@ export function BannerLayout({
) : null,
dismissButton: onDismiss ? (
<Button
plain
primary
variant="tertiary"
icon={
<span
className={
Expand Down
157 changes: 2 additions & 155 deletions polaris-react/src/components/Button/Button.scss
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@

.primary,
.destructive,
.primaryPlain {
.tertiary {
// stylelint-disable-next-line -- generated by polaris-migrator DO NOT COPY
@include focus-ring($border-width: 0);
// stylelint-disable-next-line -- generated by polaris-migrator DO NOT COPY
Expand Down Expand Up @@ -470,7 +470,7 @@
}
}

.primaryPlain {
.tertiary {
// stylelint-disable -- Button custom properties
--pc-button-color: transparent;
--pc-button-text: var(--p-color-text);
Expand Down Expand Up @@ -584,91 +584,6 @@
}
}

.outline {
background: transparent;
border: var(--p-border-width-1) solid var(--p-color-border);
box-shadow: none;
color: var(--p-color-text);
// stylelint-disable-next-line -- generated by polaris-migrator DO NOT COPY
@include focus-ring($border-width: 1px);

&:hover {
border: var(--p-border-width-1) solid var(--p-color-border);
box-shadow: none;
background: var(--p-color-bg-hover);
}

&:focus-visible {
border: var(--p-border-width-1) solid var(--p-color-border);
box-shadow: none;
// stylelint-disable-next-line -- generated by polaris-migrator DO NOT COPY
@include focus-ring($style: 'focused');
}

&:active {
border: var(--p-border-width-1) solid var(--p-color-border);
box-shadow: none;
background: var(--p-color-bg-active);

&::after {
box-shadow: none;
}
}

&.pressed {
background: var(--p-color-bg-subdued-active);
border: var(--p-border-width-1) solid var(--p-color-border);
box-shadow: none;
// stylelint-disable-next-line -- generated by polaris-migrator DO NOT COPY
color: var(--pc-button-text);
}

&.disabled {
border: var(--p-border-width-1) solid var(--p-color-border-disabled);
color: var(--p-color-text-disabled);
}

&.destructive {
background: transparent;
border: var(--p-border-width-1) solid var(--p-color-border-critical);
box-shadow: none;
color: var(--p-color-text-critical);

svg {
fill: var(--p-color-icon-critical);
}

&:hover {
border: var(--p-border-width-1) solid var(--p-color-border-critical);
background: var(--p-color-bg-critical-subdued);
}

&:focus-visible {
border: var(--p-border-width-1) solid var(--p-color-border-critical);
// stylelint-disable-next-line -- generated by polaris-migrator DO NOT COPY
@include focus-ring($style: 'focused');
}

&:active {
border: var(--p-border-width-1) solid var(--p-color-border-critical);
background: var(--p-color-bg-critical-subdued);
}

// stylelint-disable-next-line selector-max-class -- too many classes
&.disabled {
border: var(--p-border-width-1) solid var(--p-color-border-disabled);
color: var(--p-color-text-disabled);
}

// stylelint-disable-next-line selector-max-class -- too many classes
&.pressed {
border: var(--p-border-width-1) solid var(--p-color-border-critical);
background: var(--p-color-bg-critical-subdued);
color: var(--p-color-text-critical);
}
}
}

.disabled {
cursor: default;
pointer-events: none;
Expand Down Expand Up @@ -1024,7 +939,6 @@
}

.monochrome {
&.outline,
&.plain {
color: currentColor;

Expand Down Expand Up @@ -1070,72 +984,11 @@
fill: currentColor;
}
}
}

&.plain {
.Text:not(.removeUnderline) {
text-decoration: underline;
}
}

&.outline {
position: relative;
border-color: currentColor;
box-shadow: 0 0 0 var(--p-border-width-1) currentColor;
// stylelint-disable-next-line -- generated by polaris-migrator DO NOT COPY
@include focus-ring($border-width: 2px);

&::before {
content: '';
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
background-color: currentColor;
opacity: 0;
// stylelint-disable-next-line -- generated by polaris-migrator DO NOT COPY
z-index: 0;
}

&.pressed {
background: transparent;
box-shadow: none;
color: currentColor;

&::before {
opacity: 0.2;
}
}

&:hover,
&:focus,
&:active {
background-color: transparent;
border-color: currentColor;

&::before {
opacity: 0.07;
}
}

&:focus-visible {
box-shadow: 0 0 0 var(--p-border-width-1) currentColor;
// stylelint-disable-next-line -- generated by polaris-migrator DO NOT COPY
@include focus-ring($style: 'focused');
}

&:active::after {
box-shadow: none;
}

&:hover,
&:active {
&::before {
opacity: 0.05;
}
}
}
}
// stylelint-enable selector-max-specificity, selector-max-class

Expand All @@ -1160,12 +1013,6 @@
&.primary,
&.destructive {
margin-left: calc(var(--p-space-05) * -1);

// stylelint-disable-next-line selector-max-class -- generated by polaris-migrator DO NOT COPY
&.outline {
margin-left: 0;
border-left: 0;
}
}

&:active {
Expand Down
Loading

0 comments on commit 4caed28

Please sign in to comment.