Skip to content

Commit 45157e0

Browse files
committed
Revert "chore(CounterLabel): Remove the CSS modules feature flag from the CounterLabel component (#5337)"
This reverts commit 7d9bb0c.
1 parent cba527c commit 45157e0

File tree

3 files changed

+84
-16
lines changed

3 files changed

+84
-16
lines changed

.changeset/large-grasshoppers-work.md

Lines changed: 0 additions & 5 deletions
This file was deleted.

packages/react/src/CounterLabel/CounterLabel.tsx

Lines changed: 50 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
import {clsx} from 'clsx'
22
import type {HTMLAttributes} from 'react'
33
import React, {forwardRef} from 'react'
4+
import styled from 'styled-components'
5+
import {get} from '../constants'
6+
import sx from '../sx'
47
import type {SxProp} from '../sx'
58
import {VisuallyHidden} from '../VisuallyHidden'
69
import {defaultSxProp} from '../utils/defaultSxProp'
10+
import {useFeatureFlag} from '../FeatureFlags'
711
import Box from '../Box'
812
import classes from './CounterLabel.module.css'
913

@@ -16,6 +20,7 @@ export type CounterLabelProps = React.PropsWithChildren<
1620

1721
const CounterLabel = forwardRef<HTMLSpanElement, CounterLabelProps>(
1822
({scheme = 'secondary', sx = defaultSxProp, className, children, ...rest}, forwardedRef) => {
23+
const enabled = useFeatureFlag('primer_react_css_modules_ga')
1924
const label = <VisuallyHidden>&nbsp;({children})</VisuallyHidden>
2025
const counterProps = {
2126
ref: forwardedRef,
@@ -24,27 +29,67 @@ const CounterLabel = forwardRef<HTMLSpanElement, CounterLabelProps>(
2429
...rest,
2530
}
2631

27-
if (sx !== defaultSxProp) {
32+
if (enabled) {
33+
if (sx !== defaultSxProp) {
34+
return (
35+
<>
36+
<Box as="span" {...counterProps} className={clsx(className, classes.CounterLabel)} sx={sx}>
37+
{children}
38+
</Box>
39+
{label}
40+
</>
41+
)
42+
}
2843
return (
2944
<>
30-
<Box as="span" {...counterProps} className={clsx(className, classes.CounterLabel)} sx={sx}>
45+
<span {...counterProps} className={clsx(className, classes.CounterLabel)}>
3146
{children}
32-
</Box>
47+
</span>
3348
{label}
3449
</>
3550
)
3651
}
52+
3753
return (
3854
<>
39-
<span {...counterProps} className={clsx(className, classes.CounterLabel)}>
55+
<StyledCounterLabel {...counterProps} className={className} sx={sx}>
4056
{children}
41-
</span>
57+
</StyledCounterLabel>
4258
{label}
4359
</>
4460
)
4561
},
4662
)
4763

64+
const StyledCounterLabel = styled.span`
65+
display: inline-block;
66+
padding: var(--base-size-2, 0.125rem) var(--base-size-6, 0.375rem);
67+
font-size: 12px;
68+
font-weight: var(--base-text-weight-semibold, bold);
69+
line-height: 1;
70+
border-radius: 20px;
71+
border: var(--borderWidth-thin, max(1px, 0.0625rem)) solid var(--counter-borderColor, var(--color-counter-border));
72+
73+
&:where([data-scheme='primary']) {
74+
background-color: ${get('colors.neutral.emphasis')};
75+
color: ${get('colors.fg.onEmphasis')};
76+
}
77+
78+
&:where([data-scheme='secondary']) {
79+
background-color: ${get('colors.neutral.muted')};
80+
color: ${get('colors.fg.default')};
81+
}
82+
83+
&:where(:empty) {
84+
display: none;
85+
}
86+
87+
/* Place the sx prop styles after previously inserted styles so that it will win out in specificity */
88+
& {
89+
${sx}
90+
}
91+
`
92+
4893
CounterLabel.displayName = 'CounterLabel'
4994

5095
export default CounterLabel

packages/react/src/CounterLabel/__snapshots__/CounterLabel.test.tsx.snap

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

33
exports[`CounterLabel renders with secondary scheme when no "scheme" prop is provided 1`] = `
4-
.c0:not(:focus):not(:active):not(:focus-within) {
4+
.c1:not(:focus):not(:active):not(:focus-within) {
55
-webkit-clip-path: inset(50%);
66
clip-path: inset(50%);
77
height: 1px;
@@ -11,16 +11,30 @@ exports[`CounterLabel renders with secondary scheme when no "scheme" prop is pro
1111
width: 1px;
1212
}
1313
14+
.c0 {
15+
display: inline-block;
16+
padding: var(--base-size-2,0.125rem) var(--base-size-6,0.375rem);
17+
font-size: 12px;
18+
font-weight: var(--base-text-weight-semibold,bold);
19+
line-height: 1;
20+
border-radius: 20px;
21+
border: var(--borderWidth-thin,max(1px,0.0625rem)) solid var(--counter-borderColor,var(--color-counter-border));
22+
}
23+
24+
.c0:where(:empty) {
25+
display: none;
26+
}
27+
1428
<div>
1529
<span
1630
aria-hidden="true"
17-
class="CounterLabel"
31+
class="c0"
1832
data-scheme="secondary"
1933
>
2034
1234
2135
</span>
2236
<span
23-
class="c0"
37+
class="c1"
2438
>
2539
 (
2640
1234
@@ -30,7 +44,7 @@ exports[`CounterLabel renders with secondary scheme when no "scheme" prop is pro
3044
`;
3145

3246
exports[`CounterLabel respects the primary "scheme" prop 1`] = `
33-
.c0:not(:focus):not(:active):not(:focus-within) {
47+
.c1:not(:focus):not(:active):not(:focus-within) {
3448
-webkit-clip-path: inset(50%);
3549
clip-path: inset(50%);
3650
height: 1px;
@@ -40,16 +54,30 @@ exports[`CounterLabel respects the primary "scheme" prop 1`] = `
4054
width: 1px;
4155
}
4256
57+
.c0 {
58+
display: inline-block;
59+
padding: var(--base-size-2,0.125rem) var(--base-size-6,0.375rem);
60+
font-size: 12px;
61+
font-weight: var(--base-text-weight-semibold,bold);
62+
line-height: 1;
63+
border-radius: 20px;
64+
border: var(--borderWidth-thin,max(1px,0.0625rem)) solid var(--counter-borderColor,var(--color-counter-border));
65+
}
66+
67+
.c0:where(:empty) {
68+
display: none;
69+
}
70+
4371
<div>
4472
<span
4573
aria-hidden="true"
46-
class="CounterLabel"
74+
class="c0"
4775
data-scheme="primary"
4876
>
4977
1234
5078
</span>
5179
<span
52-
class="c0"
80+
class="c1"
5381
>
5482
 (
5583
1234

0 commit comments

Comments
 (0)