Skip to content

Commit a67df3e

Browse files
francineluccaliuliu-devllastflowersCopilot
authored
Chore: remove styled system components (#6941)
Co-authored-by: Liu Liu <[email protected]> Co-authored-by: llastflowers <[email protected]> Co-authored-by: Copilot <[email protected]>
1 parent 76f1ca3 commit a67df3e

24 files changed

+405
-631
lines changed

.changeset/chilled-spoons-roll.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@primer/react": major
3+
---
4+
5+
Chore/remove styled. components: deprecated UnderlineNav, ValidationAnimation, LabelGroup, Tooltip

packages/react/src/DialogV1/Dialog.test.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ const Component = () => {
2323
<div data-testid="inner">
2424
<Dialog.Header id="header">Title</Dialog.Header>
2525
<div style={{padding: 'var(--stack-gap-normal)'}}>
26-
<Text fontFamily="sans-serif">Some content</Text>
26+
<Text style={{fontFamily: 'sans-serif'}}>Some content</Text>
2727
</div>
2828
</div>
2929
</Dialog>
@@ -37,7 +37,7 @@ const ClosedDialog = () => {
3737
<div data-testid="inner">
3838
<Dialog.Header id="header">Title</Dialog.Header>
3939
<div style={{padding: 'var(--stack-gap-normal)'}}>
40-
<Text fontFamily="sans-serif">Some content</Text>
40+
<Text style={{fontFamily: 'sans-serif'}}>Some content</Text>
4141
</div>
4242
</div>
4343
</Dialog>
@@ -51,7 +51,7 @@ const DialogWithCustomFocusRef = () => {
5151
<div data-testid="inner">
5252
<Dialog.Header id="header">Title</Dialog.Header>
5353
<div style={{padding: 'var(--stack-gap-normal)'}}>
54-
<Text fontFamily="sans-serif">Some content</Text>
54+
<Text style={{fontFamily: 'sans-serif'}}>Some content</Text>
5555
<button type="button" data-testid="inner-button" ref={buttonRef}>
5656
hi
5757
</button>
@@ -80,7 +80,7 @@ const DialogWithCustomFocusRefAndReturnFocusRef = () => {
8080
<div data-testid="inner">
8181
<Dialog.Header id="header">Title</Dialog.Header>
8282
<div style={{padding: 'var(--stack-gap-normal)'}}>
83-
<Text fontFamily="sans-serif">Some content</Text>
83+
<Text style={{fontFamily: 'sans-serif'}}>Some content</Text>
8484
<button type="button" data-testid="inner-button" ref={buttonRef}>
8585
hi
8686
</button>

packages/react/src/FormControl/FormControlLeadingVisual.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import type React from 'react'
2-
import {get} from '../constants'
32
import type {SxProp} from '../sx'
43
import {useFormControlContext} from './_FormControlContext'
54
import styled from 'styled-components'
@@ -24,7 +23,7 @@ const FormControlLeadingVisual: React.FC<React.PropsWithChildren<SxProp & {style
2423
}
2524

2625
const StyledLeadingVisual = styled.div`
27-
--leadingVisual-size: ${get('fontSizes.2')};
26+
--leadingVisual-size: var(--text-title-size-small);
2827
2928
color: var(--fgColor-default);
3029
@@ -42,7 +41,7 @@ const StyledLeadingVisual = styled.div`
4241
}
4342
4443
&:where([data-has-caption]) {
45-
--leadingVisual-size: ${get('fontSizes.4')};
44+
--leadingVisual-size: var(--base-size-24);
4645
}
4746
4847
${sx}

packages/react/src/LabelGroup/LabelGroup.module.css

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,41 @@
1+
.Container {
2+
display: flex;
3+
flex-wrap: nowrap;
4+
gap: var(--base-size-4);
5+
/* stylelint-disable-next-line primer/typography */
6+
line-height: 1;
7+
max-width: 100%;
8+
overflow: hidden;
9+
10+
&:where([data-overflow='inline']) {
11+
flex-wrap: wrap;
12+
}
13+
14+
&:where([data-list]) {
15+
padding-inline-start: 0;
16+
margin-block-start: 0;
17+
margin-block-end: 0;
18+
list-style-type: none;
19+
}
20+
}
21+
22+
.ItemWrapper {
23+
display: flex;
24+
align-items: center;
25+
/* This min-height matches the height of the expand/collapse button.
26+
Without it, the labels/tokens will do a slight layout shift when expanded.
27+
This is because the height of the first row will match the token sizes,
28+
but the height of the second row will be the height of the collapse button.
29+
*/
30+
min-height: 28px;
31+
}
32+
33+
.ItemWrapper--hidden {
34+
order: 9999;
35+
pointer-events: none;
36+
visibility: hidden;
37+
}
38+
139
.OverlayContainer {
240
align-items: flex-start;
341
display: flex;

packages/react/src/LabelGroup/LabelGroup.tsx

Lines changed: 15 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import React from 'react'
2-
import styled from 'styled-components'
32
import {XIcon} from '@primer/octicons-react'
43
import {getFocusableChild} from '@primer/behaviors/utils'
5-
import {get} from '../constants'
64
import VisuallyHidden from '../_VisuallyHidden'
75
import {AnchoredOverlay} from '../AnchoredOverlay'
86
import {Button, IconButton} from '../Button'
7+
import {clsx} from 'clsx'
98
import theme from '../theme'
109
import classes from './LabelGroup.module.css'
1110

@@ -18,45 +17,6 @@ export type LabelGroupProps = {
1817
visibleChildCount?: 'auto' | number
1918
className?: string
2019
}
21-
22-
const StyledLabelGroupContainer = styled.div`
23-
display: flex;
24-
flex-wrap: nowrap;
25-
gap: ${get('space.1')};
26-
line-height: 1;
27-
max-width: 100%;
28-
overflow: hidden;
29-
30-
&[data-overflow='inline'] {
31-
flex-wrap: wrap;
32-
}
33-
34-
&[data-list] {
35-
padding-inline-start: 0;
36-
margin-block-start: 0;
37-
margin-block-end: 0;
38-
list-style-type: none;
39-
}
40-
`
41-
42-
const ItemWrapper = styled.div`
43-
display: flex;
44-
align-items: center;
45-
46-
/* This min-height matches the height of the expand/collapse button.
47-
Without it, the labels/tokens will do a slight layout shift when expanded.
48-
This is because the height of the first row will match the token sizes,
49-
but the height of the second row will be the height of the collapse button.
50-
*/
51-
min-height: 28px;
52-
53-
&.ItemWrapper--hidden {
54-
order: 9999;
55-
pointer-events: none;
56-
visibility: hidden;
57-
}
58-
`
59-
6020
// Calculates the width of the overlay to cover the labels/tokens and the expand button.
6121
const getOverlayWidth = (
6222
buttonClientRect: DOMRect,
@@ -151,7 +111,7 @@ const LabelGroup: React.FC<React.PropsWithChildren<LabelGroupProps>> = ({
151111
children,
152112
visibleChildCount,
153113
overflowStyle = 'overlay',
154-
as = 'ul',
114+
as: Component = 'ul',
155115
className,
156116
}) => {
157117
const containerRef = React.useRef<HTMLElement>(null)
@@ -320,28 +280,30 @@ const LabelGroup: React.FC<React.PropsWithChildren<LabelGroupProps>> = ({
320280
}
321281
}, [overflowStyle, isOverflowShown])
322282

323-
const isList = as === 'ul' || as === 'ol'
283+
const isList = Component === 'ul' || Component === 'ol'
324284
const ToggleWrapper = isList ? 'li' : React.Fragment
325285

286+
const ItemWrapperComponent = isList ? 'li' : 'span'
287+
326288
// If truncation is enabled, we need to render based on truncation logic.
327289
return visibleChildCount ? (
328-
<StyledLabelGroupContainer
290+
<Component
329291
ref={containerRef}
330292
data-overflow={overflowStyle === 'inline' && isOverflowShown ? 'inline' : undefined}
331293
data-list={isList || undefined}
332-
className={className}
333-
as={as}
294+
className={clsx(className, classes.Container)}
334295
>
335296
{React.Children.map(children, (child, index) => (
336-
<ItemWrapper
297+
<ItemWrapperComponent
337298
// data-index is used as an identifier we can use in the IntersectionObserver
338299
data-index={index}
339-
className={hiddenItemIds.includes(index.toString()) ? 'ItemWrapper--hidden' : undefined}
340-
as={isList ? 'li' : 'span'}
300+
className={clsx(classes.ItemWrapper, {
301+
[classes['ItemWrapper--hidden']]: hiddenItemIds.includes(index.toString()),
302+
})}
341303
key={index}
342304
>
343305
{child}
344-
</ItemWrapper>
306+
</ItemWrapperComponent>
345307
))}
346308
<ToggleWrapper>
347309
{overflowStyle === 'inline' ? (
@@ -369,15 +331,15 @@ const LabelGroup: React.FC<React.PropsWithChildren<LabelGroupProps>> = ({
369331
</OverlayToggle>
370332
)}
371333
</ToggleWrapper>
372-
</StyledLabelGroupContainer>
334+
</Component>
373335
) : (
374-
<StyledLabelGroupContainer data-overflow="inline" data-list={isList || undefined} as={as} className={className}>
336+
<Component data-overflow="inline" data-list={isList || undefined} className={clsx(className, classes.Container)}>
375337
{isList
376338
? React.Children.map(children, (child, index) => {
377339
return <li key={index}>{child}</li>
378340
})
379341
: children}
380-
</StyledLabelGroupContainer>
342+
</Component>
381343
)
382344
}
383345

0 commit comments

Comments
 (0)