diff --git a/.changeset/two-snakes-brush.md b/.changeset/two-snakes-brush.md new file mode 100644 index 0000000000..ec45c697be --- /dev/null +++ b/.changeset/two-snakes-brush.md @@ -0,0 +1,5 @@ +--- +'@primer/react': minor +--- + +Adds support for `className` prop to PageHeader component and its children. diff --git a/packages/react/src/PageHeader/PageHeader.docs.json b/packages/react/src/PageHeader/PageHeader.docs.json index 824678e8c0..9f3c743e30 100644 --- a/packages/react/src/PageHeader/PageHeader.docs.json +++ b/packages/react/src/PageHeader/PageHeader.docs.json @@ -12,6 +12,12 @@ "defaultValue": "", "description": "A unique label for the rendered main landmark" }, + { + "name": "className", + "type": "string | undefined", + "defaultValue": "", + "description": "CSS string" + }, { "name": "hidden", "type": "| boolean | { narrow?: boolean regular?: boolean wide?: boolean }", @@ -32,6 +38,12 @@ { "name": "PageHeader.ContextArea", "props": [ + { + "name": "className", + "type": "string | undefined", + "defaultValue": "", + "description": "CSS string" + }, { "name": "hidden", "type": "| boolean | { narrow?: boolean regular?: boolean wide?: boolean }", @@ -47,6 +59,12 @@ { "name": "PageHeader.ParentLink", "props": [ + { + "name": "className", + "type": "string | undefined", + "defaultValue": "", + "description": "CSS string" + }, { "name": "href", "type": "string", @@ -68,6 +86,12 @@ { "name": "PageHeader.ContextBar", "props": [ + { + "name": "className", + "type": "string | undefined", + "defaultValue": "", + "description": "CSS string" + }, { "name": "hidden", "type": "| boolean | { narrow?: boolean regular?: boolean wide?: boolean }", @@ -83,6 +107,12 @@ { "name": "PageHeader.ContextAreaActions", "props": [ + { + "name": "className", + "type": "string | undefined", + "defaultValue": "", + "description": "CSS string" + }, { "name": "hidden", "type": "| boolean | { narrow?: boolean regular?: boolean wide?: boolean }", @@ -98,6 +128,12 @@ { "name": "PageHeader.TitleArea", "props": [ + { + "name": "className", + "type": "string | undefined", + "defaultValue": "", + "description": "CSS string" + }, { "name": "hidden", "type": "| boolean | { narrow?: boolean regular?: boolean wide?: boolean }", @@ -119,6 +155,12 @@ { "name": "PageHeader.LeadingAction", "props": [ + { + "name": "className", + "type": "string | undefined", + "defaultValue": "", + "description": "CSS string" + }, { "name": "hidden", "type": "| boolean | { narrow?: boolean regular?: boolean wide?: boolean }", @@ -134,6 +176,12 @@ { "name": "PageHeader.LeadingVisual", "props": [ + { + "name": "className", + "type": "string | undefined", + "defaultValue": "", + "description": "CSS string" + }, { "name": "hidden", "type": "| boolean | { narrow?: boolean regular?: boolean wide?: boolean }", @@ -149,6 +197,12 @@ { "name": "PageHeader.Title", "props": [ + { + "name": "className", + "type": "string | undefined", + "defaultValue": "", + "description": "CSS string" + }, { "name": "hidden", "type": "| boolean | { narrow?: boolean regular?: boolean wide?: boolean }", @@ -169,6 +223,12 @@ { "name": "PageHeader.TrailingVisual", "props": [ + { + "name": "className", + "type": "string | undefined", + "defaultValue": "", + "description": "CSS string" + }, { "name": "hidden", "type": "| boolean | { narrow?: boolean regular?: boolean wide?: boolean }", @@ -184,6 +244,12 @@ { "name": "PageHeader.TrailingAction", "props": [ + { + "name": "className", + "type": "string | undefined", + "defaultValue": "", + "description": "CSS string" + }, { "name": "hidden", "type": "| boolean | { narrow?: boolean regular?: boolean wide?: boolean }", @@ -199,6 +265,12 @@ { "name": "PageHeader.Actions", "props": [ + { + "name": "className", + "type": "string | undefined", + "defaultValue": "", + "description": "CSS string" + }, { "name": "hidden", "type": "| boolean | { narrow?: boolean regular?: boolean wide?: boolean }", @@ -214,6 +286,12 @@ { "name": "PageHeader.Description", "props": [ + { + "name": "className", + "type": "string | undefined", + "defaultValue": "", + "description": "CSS string" + }, { "name": "hidden", "type": "| boolean | { narrow?: boolean regular?: boolean wide?: boolean }", @@ -245,6 +323,12 @@ "defaultValue": "\"div\"", "description": "The HTML element used to render the navigation." }, + { + "name": "className", + "type": "string | undefined", + "defaultValue": "", + "description": "CSS string" + }, { "name": "hidden", "type": "| boolean | { narrow?: boolean regular?: boolean wide?: boolean }", diff --git a/packages/react/src/PageHeader/PageHeader.tsx b/packages/react/src/PageHeader/PageHeader.tsx index 85a9220eb9..604182572b 100644 --- a/packages/react/src/PageHeader/PageHeader.tsx +++ b/packages/react/src/PageHeader/PageHeader.tsx @@ -42,6 +42,7 @@ const LARGE_TITLE_HEIGHT = '3rem' // Types that are shared between PageHeader children components export type ChildrenPropTypes = { + className?: string hidden?: boolean | ResponsiveValue } & SxProp @@ -64,10 +65,11 @@ const hiddenOnNarrow = { export type PageHeaderProps = { 'aria-label'?: React.AriaAttributes['aria-label'] as?: React.ElementType | 'header' | 'div' + className?: string } & SxProp const Root = React.forwardRef>( - ({children, sx = {}, as = 'div'}, forwardedRef) => { + ({children, className, sx = {}, as = 'div'}, forwardedRef) => { const rootStyles = { display: 'grid', // We have max 5 columns. @@ -156,7 +158,13 @@ const Root = React.forwardRef(rootStyles, sx)} data-size-variant={titleVariant}> + (rootStyles, sx)} + data-size-variant={titleVariant} + > {children} ) @@ -169,6 +177,7 @@ const Root = React.forwardRef> = ({ children, + className, hidden = hiddenOnRegularAndWide, sx = {}, }) => { @@ -186,7 +195,11 @@ const ContextArea: React.FC> = ({ }), } - return (contentNavStyles, sx)}>{children} + return ( + (contentNavStyles, sx)}> + {children} + + ) } type LinkProps = Pick< React.AnchorHTMLAttributes & BaseLinkProps, @@ -198,7 +211,7 @@ export type ParentLinkProps = React.PropsWithChildren( - ({children, sx = {}, href, 'aria-label': ariaLabel, as = 'a', hidden = hiddenOnRegularAndWide}, ref) => { + ({children, className, sx = {}, href, 'aria-label': ariaLabel, as = 'a', hidden = hiddenOnRegularAndWide}, ref) => { return ( <> ( as={as} aria-label={ariaLabel} muted + className={className} sx={merge( { display: 'flex', @@ -234,11 +248,13 @@ const ParentLink = React.forwardRef( const ContextBar: React.FC> = ({ children, + className, sx = {}, hidden = hiddenOnRegularAndWide, }) => { return ( ( { display: 'flex', @@ -259,11 +275,13 @@ const ContextBar: React.FC> = ({ // --------------------------------------------------------------------- const ContextAreaActions: React.FC> = ({ children, + className, sx = {}, hidden = hiddenOnRegularAndWide, }) => { return ( ( { display: 'flex', @@ -293,7 +311,7 @@ type TitleAreaProps = { // --------------------------------------------------------------------- const TitleArea = React.forwardRef>( - ({children, sx = {}, hidden = false, variant = 'medium'}, forwardedRef) => { + ({children, className, sx = {}, hidden = false, variant = 'medium'}, forwardedRef) => { const titleAreaRef = useProvidedRefOrCreate(forwardedRef as React.RefObject) const currentVariant = useResponsiveValue(variant, 'medium') const [fontSize, setFontSize] = useState(null) @@ -317,6 +335,7 @@ const TitleArea = React.forwardRef