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

chore(Details): Remove CSS modules feature flag from Details #5458

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

Remove CSS modules feature flag from Details
40 changes: 15 additions & 25 deletions packages/react/src/Details/Details.tsx
Original file line number Diff line number Diff line change
@@ -1,33 +1,13 @@
import React, {useEffect, useState, type ComponentPropsWithoutRef, type ReactElement} from 'react'
import styled from 'styled-components'
import type {SxProp} from '../sx'
import sx from '../sx'
import {toggleStyledComponent} from '../internal/utils/toggleStyledComponent'
import {useFeatureFlag} from '../FeatureFlags'
import {clsx} from 'clsx'
import classes from './Details.module.css'
import {useMergedRefs} from '../internal/hooks/useMergedRefs'

const CSS_MODULES_FEATURE_FLAG = 'primer_react_css_modules_ga'

const StyledDetails = toggleStyledComponent(
CSS_MODULES_FEATURE_FLAG,
'details',
styled.details<SxProp>`
& > summary {
list-style: none;
}
& > summary::-webkit-details-marker {
display: none;
}

${sx};
`,
)
import {defaultSxProp} from '../utils/defaultSxProp'
import Box from '../Box'

const Root = React.forwardRef<HTMLDetailsElement, DetailsProps>(
({className, children, ...rest}, forwardRef): ReactElement => {
const enabled = useFeatureFlag(CSS_MODULES_FEATURE_FLAG)
({className, children, sx: sxProp = defaultSxProp, ...rest}, forwardRef): ReactElement => {
const detailsRef = React.useRef<HTMLDetailsElement>(null)
const ref = useMergedRefs(forwardRef, detailsRef)
const [hasSummary, setHasSummary] = useState(false)
Expand Down Expand Up @@ -60,12 +40,22 @@ const Root = React.forwardRef<HTMLDetailsElement, DetailsProps>(
}
}, [])

if (sxProp !== defaultSxProp) {
return (
<Box as={'details'} className={clsx(className, classes.Details)} {...rest} sx={sxProp} ref={ref}>
{/* Include default summary if summary is not provided */}
{!hasSummary && <Details.Summary data-default-summary>{'See Details'}</Details.Summary>}
{children}
</Box>
)
}

return (
<StyledDetails className={clsx(className, {[classes.Details]: enabled})} {...rest} ref={ref}>
<details className={clsx(className, classes.Details)} {...rest} ref={ref}>
{/* Include default summary if summary is not provided */}
{!hasSummary && <Details.Summary data-default-summary>{'See Details'}</Details.Summary>}
{children}
</StyledDetails>
</details>
)
},
)
Expand Down
2 changes: 1 addition & 1 deletion packages/react/src/Details/__tests__/Details.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {behavesAsComponent, checkExports} from '../../utils/testing'
import axe from 'axe-core'

describe('Details', () => {
behavesAsComponent({Component: Details})
behavesAsComponent({Component: Details, options: {skipAs: true}})

checkExports('Details', {
default: Details,
Expand Down
Loading