-
Notifications
You must be signed in to change notification settings - Fork 537
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(ButtonGroup): Migrate ButtonGroup component to use CSS modules …
…behind the primer_react_css_modules_team feature flag (#5001) * Convert ButtonGroup to css modules * Update tests * Create orange-steaks-do.md * Disable lint * Update displayName
- Loading branch information
Showing
4 changed files
with
242 additions
and
47 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": patch | ||
--- | ||
|
||
Migrate `ButtonGroup` component to use CSS modules behind the `primer_react_css_modules_team` feature flag |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
.ButtonGroup { | ||
display: inline-flex; | ||
vertical-align: middle; | ||
isolation: isolate; | ||
|
||
& > *:not([data-loading-wrapper]) { | ||
/* stylelint-disable-next-line primer/spacing */ | ||
margin-inline-end: -1px; | ||
position: relative; | ||
border-radius: 0; | ||
|
||
&:first-child { | ||
border-top-left-radius: var(--borderRadius-medium); | ||
border-bottom-left-radius: var(--borderRadius-medium); | ||
} | ||
|
||
&:last-child { | ||
border-top-right-radius: var(--borderRadius-medium); | ||
border-bottom-right-radius: var(--borderRadius-medium); | ||
} | ||
|
||
&:focus, | ||
&:active, | ||
&:hover { | ||
z-index: 1; | ||
} | ||
} | ||
|
||
/* if child is loading button */ | ||
[data-loading-wrapper] { | ||
&:first-child { | ||
button, | ||
a { | ||
border-top-left-radius: var(--borderRadius-medium); | ||
border-bottom-left-radius: var(--borderRadius-medium); | ||
} | ||
} | ||
|
||
&:last-child { | ||
button, | ||
a { | ||
border-top-right-radius: var(--borderRadius-medium); | ||
border-bottom-right-radius: var(--borderRadius-medium); | ||
} | ||
} | ||
} | ||
|
||
[data-loading-wrapper] > * { | ||
/* stylelint-disable-next-line primer/spacing */ | ||
margin-inline-end: -1px; | ||
position: relative; | ||
border-radius: 0; | ||
|
||
&:focus, | ||
&:active, | ||
&:hover { | ||
z-index: 1; | ||
} | ||
} | ||
} |
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,68 +1,96 @@ | ||
import styled from 'styled-components' | ||
import React from 'react' | ||
import {get} from '../constants' | ||
import sx from '../sx' | ||
import type {ComponentProps} from '../utils/types' | ||
import classes from './ButtonGroup.module.css' | ||
import {toggleStyledComponent} from '../internal/utils/toggleStyledComponent' | ||
import {clsx} from 'clsx' | ||
import {useFeatureFlag} from '../FeatureFlags' | ||
|
||
const ButtonGroup = styled.div` | ||
display: inline-flex; | ||
vertical-align: middle; | ||
isolation: isolate; | ||
const StyledButtonGroup = toggleStyledComponent( | ||
'primer_react_css_modules_team', | ||
styled.div` | ||
display: inline-flex; | ||
vertical-align: middle; | ||
isolation: isolate; | ||
&& > *:not([data-loading-wrapper]) { | ||
margin-inline-end: -1px; | ||
position: relative; | ||
border-radius: 0; | ||
&& > *:not([data-loading-wrapper]) { | ||
margin-inline-end: -1px; | ||
position: relative; | ||
border-radius: 0; | ||
:first-child { | ||
border-top-left-radius: ${get('radii.2')}; | ||
border-bottom-left-radius: ${get('radii.2')}; | ||
} | ||
:last-child { | ||
border-top-right-radius: ${get('radii.2')}; | ||
border-bottom-right-radius: ${get('radii.2')}; | ||
} | ||
:focus, | ||
:active, | ||
:hover { | ||
z-index: 1; | ||
} | ||
} | ||
// if child is loading button | ||
[data-loading-wrapper] { | ||
:first-child { | ||
button, | ||
a { | ||
:first-child { | ||
border-top-left-radius: ${get('radii.2')}; | ||
border-bottom-left-radius: ${get('radii.2')}; | ||
} | ||
} | ||
:last-child { | ||
button, | ||
a { | ||
:last-child { | ||
border-top-right-radius: ${get('radii.2')}; | ||
border-bottom-right-radius: ${get('radii.2')}; | ||
} | ||
:focus, | ||
:active, | ||
:hover { | ||
z-index: 1; | ||
} | ||
} | ||
} | ||
[data-loading-wrapper] > * { | ||
margin-inline-end: -1px; | ||
position: relative; | ||
border-radius: 0; | ||
// if child is loading button | ||
[data-loading-wrapper] { | ||
:first-child { | ||
button, | ||
a { | ||
border-top-left-radius: ${get('radii.2')}; | ||
border-bottom-left-radius: ${get('radii.2')}; | ||
} | ||
} | ||
:last-child { | ||
button, | ||
a { | ||
border-top-right-radius: ${get('radii.2')}; | ||
border-bottom-right-radius: ${get('radii.2')}; | ||
} | ||
} | ||
} | ||
:focus, | ||
:active, | ||
:hover { | ||
z-index: 1; | ||
[data-loading-wrapper] > * { | ||
margin-inline-end: -1px; | ||
position: relative; | ||
border-radius: 0; | ||
:focus, | ||
:active, | ||
:hover { | ||
z-index: 1; | ||
} | ||
} | ||
} | ||
${sx}; | ||
` | ||
${sx}; | ||
`, | ||
) | ||
|
||
export type ButtonGroupProps = ComponentProps<typeof StyledButtonGroup> | ||
const ButtonGroup = React.forwardRef<HTMLElement, ButtonGroupProps>(function ButtonGroup( | ||
{children, className, ...rest}, | ||
forwardRef, | ||
) { | ||
const enabled = useFeatureFlag('primer_react_css_modules_team') | ||
return ( | ||
<StyledButtonGroup | ||
ref={forwardRef} | ||
className={clsx(className, { | ||
[classes.ButtonGroup]: enabled, | ||
})} | ||
{...rest} | ||
> | ||
{children} | ||
</StyledButtonGroup> | ||
) | ||
}) | ||
|
||
ButtonGroup.displayName = 'ButtonGroup' | ||
|
||
export type ButtonGroupProps = ComponentProps<typeof ButtonGroup> | ||
export default ButtonGroup |