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

feat(LabelGroup): Remove sxProp #5425

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 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/empty-feet-roll.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@primer/react": minor
---

Deprecate sx prop from LabelGroup
14 changes: 14 additions & 0 deletions packages/react/src/LabelGroup/LabelGroup.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
.IconButton_0 {
flex-shrink: 0;
}

.Div_0 {
display: flex;
align-items: flex-start;
}

.Div_1 {
gap: var(--base-size-4);
display: flex;
flex-wrap: wrap;
}
26 changes: 9 additions & 17 deletions packages/react/src/LabelGroup/LabelGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@ import {getFocusableChild} from '@primer/behaviors/utils'
import {get} from '../constants'
import VisuallyHidden from '../_VisuallyHidden'
import {AnchoredOverlay} from '../AnchoredOverlay'
import Box from '../Box'
import {Button, IconButton} from '../Button'
import {useTheme} from '../ThemeProvider'
import type {SxProp} from '../sx'
import sx from '../sx'
import classes from './LabelGroup.module.css'

export type LabelGroupProps = {
/** Customize the element type of the rendered container */
Expand All @@ -18,12 +16,12 @@ export type LabelGroupProps = {
overflowStyle?: 'inline' | 'overlay'
/** How many tokens to show. `'auto'` truncates the tokens to fit in the parent container. Passing a number will truncate after that number tokens. If this is undefined, tokens will never be truncated. */
visibleChildCount?: 'auto' | number
} & SxProp
}

const StyledLabelGroupContainer = styled.div<SxProp>`
const StyledLabelGroupContainer = styled.div`
display: flex;
flex-wrap: nowrap;
gap: ${get('space.1')};
gap: var(--base-size-4);
line-height: 1;
max-width: 100%;
overflow: hidden;
Expand All @@ -38,8 +36,6 @@ const StyledLabelGroupContainer = styled.div<SxProp>`
margin-block-end: 0;
list-style-type: none;
}

${sx};
`

const ItemWrapper = styled.div`
Expand Down Expand Up @@ -136,18 +132,16 @@ const OverlayToggle: React.FC<
)}
focusZoneSettings={{disabled: true}}
>
<Box alignItems="flex-start" display="flex" width={overlayWidth} padding={`${overlayPaddingPx}px`}>
<Box display="flex" flexWrap="wrap" sx={{gap: 1}}>
{children}
</Box>
<div className={classes.Div_0} style={{width: overlayWidth, padding: `${overlayPaddingPx}px`}}>
<div className={classes.Div_1}>{children}</div>
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
<div className={classes.Div_0} style={{width: overlayWidth, padding: `${overlayPaddingPx}px`}}>
<div className={classes.Div_1}>{children}</div>
<Stack align="start" style={{width: overlayWidth, padding: `${overlayPaddingPx}px`}}>
<StackItem><Stack wrap="wrap" gap="condensed">{children}</Stack></StackItem>

I guess condensed is 8px, though 🤷

<IconButton
onClick={closeOverflowOverlay}
icon={XIcon}
aria-label="Close"
variant="invisible"
sx={{flexShrink: 0}}
className={classes.IconButton_0}
JelloBagel marked this conversation as resolved.
Show resolved Hide resolved
/>
</Box>
</div>
JelloBagel marked this conversation as resolved.
Show resolved Hide resolved
</AnchoredOverlay>
) : null

Expand All @@ -156,7 +150,6 @@ const LabelGroup: React.FC<React.PropsWithChildren<LabelGroupProps>> = ({
children,
visibleChildCount,
overflowStyle = 'overlay',
sx: sxProp,
as = 'ul',
}) => {
const containerRef = React.useRef<HTMLElement>(null)
Expand Down Expand Up @@ -336,7 +329,6 @@ const LabelGroup: React.FC<React.PropsWithChildren<LabelGroupProps>> = ({
ref={containerRef}
data-overflow={overflowStyle === 'inline' && isOverflowShown ? 'inline' : undefined}
data-list={isList || undefined}
sx={sxProp}
as={as}
>
{React.Children.map(children, (child, index) => (
Expand Down Expand Up @@ -378,7 +370,7 @@ const LabelGroup: React.FC<React.PropsWithChildren<LabelGroupProps>> = ({
</ToggleWrapper>
</StyledLabelGroupContainer>
) : (
<StyledLabelGroupContainer data-overflow="inline" data-list={isList || undefined} sx={sxProp} as={as}>
<StyledLabelGroupContainer data-overflow="inline" data-list={isList || undefined} as={as}>
{isList
? React.Children.map(children, (child, index) => {
return <li key={index}>{child}</li>
Expand Down
2 changes: 1 addition & 1 deletion packages/react/src/__tests__/LabelGroup.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ describe('LabelGroup', () => {
thresholds: [],
})) as jest.Mock<IntersectionObserver>

behavesAsComponent({Component: LabelGroup, options: {skipAs: true}})
behavesAsComponent({Component: LabelGroup, options: {skipAs: true, skipSx: true}})

checkExports('LabelGroup', {
default: LabelGroup,
Expand Down
5 changes: 5 additions & 0 deletions packages/react/src/sx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ export interface SxProp {
sx?: BetterSystemStyleObject
}

export interface DeprecatedSxProp {
Copy link
Contributor Author

@JelloBagel JelloBagel Dec 12, 2024

Choose a reason for hiding this comment

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

Adding DeprecatedSxProp for other components to use in the batch: https://github.com/github/primer/issues/4261

cc: @lindseywild

/** @deprecated Update `sx` using CSS modules or style. */
sx?: BetterSystemStyleObject
}

const sx = (props: SxProp) => css(props.sx)

export default sx
Expand Down
Loading