11import { clsx } from 'clsx'
22import type { HTMLAttributes } from 'react'
33import React , { forwardRef } from 'react'
4+ import styled from 'styled-components'
5+ import { get } from '../constants'
6+ import sx from '../sx'
47import type { SxProp } from '../sx'
58import { VisuallyHidden } from '../VisuallyHidden'
69import { defaultSxProp } from '../utils/defaultSxProp'
10+ import { useFeatureFlag } from '../FeatureFlags'
711import Box from '../Box'
812import classes from './CounterLabel.module.css'
913
@@ -16,6 +20,7 @@ export type CounterLabelProps = React.PropsWithChildren<
1620
1721const 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 > ({ 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+
4893CounterLabel . displayName = 'CounterLabel'
4994
5095export default CounterLabel
0 commit comments