11import React , { forwardRef } from 'react'
2- import type { BetterSystemStyleObject , SxProp } from '../sx'
3- import { merge } from '../sx'
4- import { defaultSxProp } from '../utils/defaultSxProp'
2+ import type { SxProp } from '../sx'
53import { useRefObjectAsForwardedRef } from '../hooks'
64import type { ForwardRefComponent as PolymorphicForwardRefComponent } from '../utils/polymorphic'
75import { default as HeadingComponent } from '../Heading'
@@ -10,9 +8,7 @@ import VisuallyHidden from '../_VisuallyHidden'
108import { ActionListContainerContext } from './ActionListContainerContext'
119import { invariant } from '../utils/invariant'
1210import { clsx } from 'clsx'
13- import { useFeatureFlag } from '../FeatureFlags'
1411import classes from './Heading.module.css'
15- import { actionListCssModulesFlag } from './featureflag'
1612
1713type HeadingLevels = 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6'
1814type HeadingVariants = 'large' | 'medium' | 'small'
@@ -23,75 +19,35 @@ export type ActionListHeadingProps = {
2319 className ?: string
2420} & SxProp
2521
26- export const Heading = forwardRef (
27- ( { as, size, children, sx = defaultSxProp , visuallyHidden = false , className, ...props } , forwardedRef ) => {
28- const innerRef = React . useRef < HTMLHeadingElement > ( null )
29- useRefObjectAsForwardedRef ( forwardedRef , innerRef )
30-
31- const enabled = useFeatureFlag ( actionListCssModulesFlag )
32-
33- const { headingId : headingId , variant : listVariant } = React . useContext ( ListContext )
34- const { container} = React . useContext ( ActionListContainerContext )
35-
36- // Semantic <menu>s don't have a place for headers within them, they should be aria-labelledby the menu button's name.
37- invariant (
38- container !== 'ActionMenu' ,
39- `ActionList.Heading shouldn't be used within an ActionMenu container. Menus are labelled by the menu button's name.` ,
40- )
41-
42- const styles = {
43- marginBottom : 2 ,
44- marginX : listVariant === 'full' ? 2 : 3 ,
45- }
46-
47- return (
48- < VisuallyHidden isVisible = { ! visuallyHidden } >
49- { enabled ? (
50- sx !== defaultSxProp ? (
51- < HeadingComponent
52- as = { as }
53- variant = { size }
54- ref = { innerRef }
55- // use custom id if it is provided. Otherwise, use the id from the context
56- id = { props . id ?? headingId }
57- className = { clsx ( className , classes . ActionListHeader ) }
58- data-list-variant = { listVariant }
59- sx = { sx }
60- { ...props }
61- >
62- { children }
63- </ HeadingComponent >
64- ) : (
65- < HeadingComponent
66- as = { as }
67- variant = { size }
68- ref = { innerRef }
69- // use custom id if it is provided. Otherwise, use the id from the context
70- id = { props . id ?? headingId }
71- className = { clsx ( className , classes . ActionListHeader ) }
72- data-list-variant = { listVariant }
73- { ...props }
74- >
75- { children }
76- </ HeadingComponent >
77- )
78- ) : (
79- < HeadingComponent
80- as = { as }
81- variant = { size }
82- ref = { innerRef }
83- // use custom id if it is provided. Otherwise, use the id from the context
84- id = { props . id ?? headingId }
85- sx = { merge < BetterSystemStyleObject > ( styles , sx ) }
86- className = { className }
87- { ...props }
88- >
89- { children }
90- </ HeadingComponent >
91- ) }
92- </ VisuallyHidden >
93- )
94- } ,
95- ) as PolymorphicForwardRefComponent < HeadingLevels , ActionListHeadingProps >
22+ export const Heading = forwardRef ( ( { as, size, children, visuallyHidden = false , className, ...props } , forwardedRef ) => {
23+ const innerRef = React . useRef < HTMLHeadingElement > ( null )
24+ useRefObjectAsForwardedRef ( forwardedRef , innerRef )
25+
26+ const { headingId : headingId , variant : listVariant } = React . useContext ( ListContext )
27+ const { container} = React . useContext ( ActionListContainerContext )
28+
29+ // Semantic <menu>s don't have a place for headers within them, they should be aria-labelledby the menu button's name.
30+ invariant (
31+ container !== 'ActionMenu' ,
32+ `ActionList.Heading shouldn't be used within an ActionMenu container. Menus are labelled by the menu button's name.` ,
33+ )
34+
35+ return (
36+ < VisuallyHidden isVisible = { ! visuallyHidden } >
37+ < HeadingComponent
38+ as = { as }
39+ variant = { size }
40+ ref = { innerRef }
41+ // use custom id if it is provided. Otherwise, use the id from the context
42+ id = { props . id ?? headingId }
43+ className = { clsx ( className , classes . ActionListHeader ) }
44+ data-list-variant = { listVariant }
45+ { ...props }
46+ >
47+ { children }
48+ </ HeadingComponent >
49+ </ VisuallyHidden >
50+ )
51+ } ) as PolymorphicForwardRefComponent < HeadingLevels , ActionListHeadingProps >
9652
9753Heading . displayName = 'ActionList.Heading'
0 commit comments