Skip to content
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

Use button CSS vars for border-color to support a feature flag #3861

Merged
merged 8 commits into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/flat-oranges-tease.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@primer/react": patch
---

Use `button` CSS vars for border-color to support a feature flag
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 11 additions & 9 deletions .storybook/primitives-v8.css
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@
@import '@primer/primitives/tokens-next-private/css/functional/typography/typography.css';

/* color */
@import '@primer/primitives/tokens-next-private/css/functional/themes/light.css';
@import '@primer/primitives/tokens-next-private/css/functional/themes/light-tritanopia.css';
@import '@primer/primitives/tokens-next-private/css/functional/themes/light-high-contrast.css';
@import '@primer/primitives/tokens-next-private/css/functional/themes/light-colorblind.css';
@import '@primer/primitives/tokens-next-private/css/functional/themes/dark.css';
@import '@primer/primitives/tokens-next-private/css/functional/themes/dark-colorblind.css';
@import '@primer/primitives/tokens-next-private/css/functional/themes/dark-dimmed.css';
@import '@primer/primitives/tokens-next-private/css/functional/themes/dark-high-contrast.css';
@import '@primer/primitives/tokens-next-private/css/functional/themes/dark-tritanopia.css';
/* temporarily disabiling these to ensure visual regression tests work on production code
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we want to keep these disabled in storybook?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to add a toolbar addon to let you toggle them on, like how we have it in Primer View Components Lookbook

primitives toggle

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea, should we do that in a different PR though and get this one quickly?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah totally agree

* @import '@primer/primitives/tokens-next-private/css/functional/themes/light.css';
* @import '@primer/primitives/tokens-next-private/css/functional/themes/light-tritanopia.css';
* @import '@primer/primitives/tokens-next-private/css/functional/themes/light-high-contrast.css';
* @import '@primer/primitives/tokens-next-private/css/functional/themes/light-colorblind.css';
* @import '@primer/primitives/tokens-next-private/css/functional/themes/dark.css';
* @import '@primer/primitives/tokens-next-private/css/functional/themes/dark-colorblind.css';
* @import '@primer/primitives/tokens-next-private/css/functional/themes/dark-dimmed.css';
* @import '@primer/primitives/tokens-next-private/css/functional/themes/dark-high-contrast.css';
* @import '@primer/primitives/tokens-next-private/css/functional/themes/dark-tritanopia.css';
*/
37 changes: 21 additions & 16 deletions src/Button/__tests__/__snapshots__/Button.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ exports[`Button renders consistently 1`] = `
.c0 {
border-radius: 6px;
border: 1px solid;
border-color: rgba(31,35,40,0.15);
border-color: var(--button-default-borderColor-rest,rgba(31,35,40,0.15));
font-family: inherit;
font-weight: 500;
font-size: 14px;
Expand Down Expand Up @@ -196,17 +196,17 @@ exports[`Button renders consistently 1`] = `

.c0:hover:not([disabled]) {
background-color: #f3f4f6;
border-color: rgba(31,35,40,0.15);
border-color: var(--button-default-borderColor-hover,rgba(31,35,40,0.15));
}

.c0:active:not([disabled]) {
background-color: hsla(220,14%,93%,1);
border-color: rgba(31,35,40,0.15);
border-color: var(--button-default-borderColor-active,rgba(31,35,40,0.15));
}

.c0[aria-expanded=true] {
background-color: hsla(220,14%,93%,1);
border-color: rgba(31,35,40,0.15);
border-color: var(--button-default-borderColor-active,rgba(31,35,40,0.15));
}

.c0 [data-component="leadingVisual"],
Expand Down Expand Up @@ -246,6 +246,7 @@ exports[`Button respects block prop 1`] = `
.c0 {
border-radius: 2;
border: 1px solid;
border-color: var(--button-default-borderColor-rest,undefined);
font-family: inherit;
font-weight: semibold;
font-size: 14px;
Expand Down Expand Up @@ -430,17 +431,17 @@ exports[`Button respects block prop 1`] = `

.c0:hover:not([disabled]) {
background-color: btn.hoverBg;
border-color: btn.hoverBorder;
border-color: var(--button-default-borderColor-hover,undefined);
}

.c0:active:not([disabled]) {
background-color: btn.activeBg;
border-color: btn.activeBorder;
border-color: var(--button-default-borderColor-active,undefined);
}

.c0[aria-expanded=true] {
background-color: btn.activeBg;
border-color: btn.activeBorder;
border-color: var(--button-default-borderColor-active,undefined);
}

.c0 [data-component="leadingVisual"],
Expand Down Expand Up @@ -485,6 +486,7 @@ exports[`Button respects the alignContent prop 1`] = `
.c0 {
border-radius: 2;
border: 1px solid;
border-color: var(--button-default-borderColor-rest,undefined);
font-family: inherit;
font-weight: semibold;
font-size: 14px;
Expand Down Expand Up @@ -669,17 +671,17 @@ exports[`Button respects the alignContent prop 1`] = `

.c0:hover:not([disabled]) {
background-color: btn.hoverBg;
border-color: btn.hoverBorder;
border-color: var(--button-default-borderColor-hover,undefined);
}

.c0:active:not([disabled]) {
background-color: btn.activeBg;
border-color: btn.activeBorder;
border-color: var(--button-default-borderColor-active,undefined);
}

.c0[aria-expanded=true] {
background-color: btn.activeBg;
border-color: btn.activeBorder;
border-color: var(--button-default-borderColor-active,undefined);
}

.c0 [data-component="leadingVisual"],
Expand Down Expand Up @@ -723,6 +725,7 @@ exports[`Button respects the large size prop 1`] = `
.c0 {
border-radius: 2;
border: 1px solid;
border-color: var(--button-default-borderColor-rest,undefined);
font-family: inherit;
font-weight: semibold;
font-size: 14px;
Expand Down Expand Up @@ -907,17 +910,17 @@ exports[`Button respects the large size prop 1`] = `

.c0:hover:not([disabled]) {
background-color: btn.hoverBg;
border-color: btn.hoverBorder;
border-color: var(--button-default-borderColor-hover,undefined);
}

.c0:active:not([disabled]) {
background-color: btn.activeBg;
border-color: btn.activeBorder;
border-color: var(--button-default-borderColor-active,undefined);
}

.c0[aria-expanded=true] {
background-color: btn.activeBg;
border-color: btn.activeBorder;
border-color: var(--button-default-borderColor-active,undefined);
}

.c0 [data-component="leadingVisual"],
Expand Down Expand Up @@ -962,6 +965,7 @@ exports[`Button respects the small size prop 1`] = `
.c0 {
border-radius: 2;
border: 1px solid;
border-color: var(--button-default-borderColor-rest,undefined);
font-family: inherit;
font-weight: semibold;
font-size: 14px;
Expand Down Expand Up @@ -1146,17 +1150,17 @@ exports[`Button respects the small size prop 1`] = `

.c0:hover:not([disabled]) {
background-color: btn.hoverBg;
border-color: btn.hoverBorder;
border-color: var(--button-default-borderColor-hover,undefined);
}

.c0:active:not([disabled]) {
background-color: btn.activeBg;
border-color: btn.activeBorder;
border-color: var(--button-default-borderColor-active,undefined);
}

.c0[aria-expanded=true] {
background-color: btn.activeBg;
border-color: btn.activeBorder;
border-color: var(--button-default-borderColor-active,undefined);
}

.c0 [data-component="leadingVisual"],
Expand Down Expand Up @@ -1201,6 +1205,7 @@ exports[`Button styles danger button appropriately 1`] = `
.c0 {
border-radius: 2;
border: 1px solid;
border-color: var(--button-default-borderColor-rest,undefined);
font-family: inherit;
font-weight: semibold;
font-size: 14px;
Expand Down
16 changes: 8 additions & 8 deletions src/Button/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ export const getVariantStyles = (variant: VariantType = 'default', theme?: Theme
boxShadow: `${theme?.shadows.btn.shadow}, ${theme?.shadows.btn.insetShadow}`,
'&:hover:not([disabled])': {
backgroundColor: 'btn.hoverBg',
borderColor: 'btn.hoverBorder',
borderColor: `var(--button-default-borderColor-hover, ${theme?.colors.btn.hoverBorder})`,
Copy link
Member

@siddharthkp siddharthkp Oct 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ has a fallback 10/10

},
'&:active:not([disabled])': {
backgroundColor: 'btn.activeBg',
borderColor: 'btn.activeBorder',
borderColor: `var(--button-default-borderColor-active, ${theme?.colors.btn.activeBorder})`,
},
'&:disabled': {
color: 'primer.fg.disabled',
Expand All @@ -23,7 +23,7 @@ export const getVariantStyles = (variant: VariantType = 'default', theme?: Theme
},
'&[aria-expanded=true]': {
backgroundColor: 'btn.activeBg',
borderColor: 'btn.activeBorder',
borderColor: `var(--button-default-borderColor-active, ${theme?.colors.btn.activeBorder})`,
},
'[data-component="leadingVisual"], [data-component="trailingVisual"], [data-component="trailingAction"]': {
color: `var(--button-color, ${theme?.colors.fg.muted})`,
Expand Down Expand Up @@ -149,13 +149,13 @@ export const getVariantStyles = (variant: VariantType = 'default', theme?: Theme
outline: {
color: 'btn.outline.text',
boxShadow: `${theme?.shadows.btn.shadow}`,
borderColor: 'btn.border',
borderColor: `var(--button-default-borderColor-rest, ${theme?.colors.btn.border})`,
backgroundColor: 'btn.bg',

'&:hover:not([disabled])': {
color: 'btn.outline.hoverText',
backgroundColor: 'btn.outline.hoverBg',
borderColor: 'btn.outline.hoverBorder',
borderColor: `${theme?.colors.btn.outline.hoverBorder}`,
boxShadow: `${theme?.shadows.btn.outline.hoverShadow}`,
'[data-component=ButtonCounter]': {
backgroundColor: 'btn.outline.hoverCounterBg',
Expand All @@ -166,7 +166,7 @@ export const getVariantStyles = (variant: VariantType = 'default', theme?: Theme
color: 'btn.outline.selectedText',
backgroundColor: 'btn.outline.selectedBg',
boxShadow: `${theme?.shadows.btn.outline.selectedShadow}`,
borderColor: 'btn.outline.selectedBorder',
borderColor: `${theme?.colors.btn.outline.selectedBorder}`,
},

'&:disabled': {
Expand All @@ -186,7 +186,7 @@ export const getVariantStyles = (variant: VariantType = 'default', theme?: Theme
color: 'btn.outline.selectedText',
backgroundColor: 'btn.outline.selectedBg',
boxShadow: `${theme?.shadows.btn.outline.selectedShadow}`,
borderColor: 'btn.outline.selectedBorder',
borderColor: `var(--button-default-borderColor-active, ${theme?.colors.btn.outline.selectedBorder})`,
},
},
}
Expand All @@ -196,7 +196,7 @@ export const getVariantStyles = (variant: VariantType = 'default', theme?: Theme
export const getBaseStyles = (theme?: Theme) => ({
borderRadius: '2',
border: '1px solid',
borderColor: theme?.colors.btn.border,
borderColor: `var(--button-default-borderColor-rest, ${theme?.colors.btn.border})`,
fontFamily: 'inherit',
fontWeight: 'semibold',
fontSize: '1',
Expand Down
8 changes: 4 additions & 4 deletions src/__tests__/__snapshots__/ActionMenu.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ exports[`ActionMenu renders consistently 1`] = `
.c1 {
border-radius: 6px;
border: 1px solid;
border-color: rgba(31,35,40,0.15);
border-color: var(--button-default-borderColor-rest,rgba(31,35,40,0.15));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ makes sense, ActionMenu uses Button

font-family: inherit;
font-weight: 500;
font-size: 14px;
Expand Down Expand Up @@ -210,17 +210,17 @@ exports[`ActionMenu renders consistently 1`] = `

.c1:hover:not([disabled]) {
background-color: #f3f4f6;
border-color: rgba(31,35,40,0.15);
border-color: var(--button-default-borderColor-hover,rgba(31,35,40,0.15));
}

.c1:active:not([disabled]) {
background-color: hsla(220,14%,93%,1);
border-color: rgba(31,35,40,0.15);
border-color: var(--button-default-borderColor-active,rgba(31,35,40,0.15));
}

.c1[aria-expanded=true] {
background-color: hsla(220,14%,93%,1);
border-color: rgba(31,35,40,0.15);
border-color: var(--button-default-borderColor-active,rgba(31,35,40,0.15));
}

.c1 [data-component="leadingVisual"],
Expand Down