feat(Popover): add composable header and alert variants#6664
Conversation
nicolethoen
left a comment
There was a problem hiding this comment.
VO is not announcing the alerts.
I think that @evwilkin has opened a PR to address that? I think if his gets merged first, then we should rebase and double check it.
| </Title> | ||
| )} | ||
| </PopoverContext.Consumer> | ||
| <header className={css('pf-c-popover__header')} {...props}> |
There was a problem hiding this comment.
can you add className as a prop and merge it in here, otherwise it would override this one if specified by consumer
Also applies to the other components in this PR
edcc4e5 to
1778593
Compare
| import { css } from '@patternfly/react-styles'; | ||
|
|
||
| export interface PopoverFooterProps extends React.HTMLProps<HTMLDivElement> { | ||
| /** Additional classes added to the Popover Footer */ |
| */ | ||
| header?: React.ReactNode | ((hide: () => void) => React.ReactNode); | ||
| /** Variants for an alert popover */ | ||
| alertVariant?: 'default' | 'info' | 'warning' | 'success' | 'danger'; |
There was a problem hiding this comment.
So, I think the alertVariant on its own does not make sense. Setting this prop does not make the popover an alert popover. I wonder if we can improve on the API?
@jschuler I would be interested in your thoughts.
There was a problem hiding this comment.
@tlabaj how about alertLevelVariant or alertSeverityVariant
There was a problem hiding this comment.
@nicole, those suggestions are good. Maybe some more context in the description of what it does will also help.
There was a problem hiding this comment.
It would make more sense for me to find a prop like that on the PopoverHeader component, since it affects the icon and text color in there. But if we anticipate more changes to the entire Popover it would make sense to be here.
If the prop comment explains that it modifies the header icon and text colors, that would make it clearer what change it does.
Edit: Saw the change to the PR and LGTM
| headerContent?: React.ReactNode | ((hide: () => void) => React.ReactNode); | ||
| /** Sets the heading level to use for the popover header. Default is h6. */ | ||
| headerComponent?: 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6'; | ||
| /** @beta Composable header component. Use with the PopoverHeader, PopoverHeaderText, and PopoverHeaderIcon components. To manually close |
There was a problem hiding this comment.
Beat me to it. I was going to ask for beta tag :)
tlabaj
left a comment
There was a problem hiding this comment.
Can you also mark new exported componets Beta please.
| /** ID of the popover header. */ | ||
| id?: string; |
There was a problem hiding this comment.
Should id still be in this interface? It doesn't look like it's used in the component anymore.
| )} | ||
| </PopoverContext.Consumer> | ||
| <header className={css('pf-c-popover__header', className)} {...props}> | ||
| <h1 className={css(styles.popoverTitle, hasIcon && styles.modifiers.icon)}>{children}</h1> |
There was a problem hiding this comment.
Should headerComponent set the heading level here, too.
There was a problem hiding this comment.
I'm not sure - I've been trying to figure out the real differences between PopoverHeader and PopoverInternalHeader and one of the main differences is that PopoverInternalHeader uses a Title component. @mcoker Do you think they should both use Title components?
There was a problem hiding this comment.
@kmcfaul is the only reason you built this to be composable because you needed to put the hasIcon prop at the outermost level?
There was a problem hiding this comment.
@mcoker Do you think they should both use Title components?
@nicolethoen no, I think the popover title is better as an element of the popover component instead of the title component. That way we can change the styling (size, weight, etc) of the title in the CSS as opposed to needing a markup change, which is on the user to make in some cases. When we introduced the new Red Hat font, for example, the change in font face made either the modal or popover title (can't remember which, but both used the <Title> component) look different, so we ended up styling .pf-c-title.pf-m-lg (or whatever the class name was) to a different font-size in that component, which is a bad practice. Having the title be an element of a component won't put us in a situation like that if the title styles need to change.
There was a problem hiding this comment.
In our next upcoming breaking change, I'd like to get rid of the <Title> component in the popover and make the header and title elements introduced in this PR the default structural elements for the popover's title.
There was a problem hiding this comment.
@mcoker, I think you are right, otherwise the heading level for the composable PopoverHeader is not configurable. We need to add a prop to this component to configure heading level.
| <header className={css('pf-c-popover__header', className)} {...props}> | ||
| <HeadingLevel className={css(styles.popoverTitle, icon && styles.modifiers.icon)}> | ||
| {icon && <PopoverHeaderIcon>{icon}</PopoverHeaderIcon>} | ||
| {alertSeverityVariant && <span className="pf-u-screen-reader">{alertSeverityVariant} alert:</span>} |
There was a problem hiding this comment.
The "alert" text in this span needs to be configurable.
| alertSeverityVariant={alertSeverityVariant} | ||
| titleHeadingLevel={headerComponent} | ||
| > | ||
| <React.Fragment>{typeof headerContent === 'function' ? headerContent(hide) : headerContent}</React.Fragment> |
There was a problem hiding this comment.
Why do we need the <React.Fragment>
|
|
||
| ```ts isBeta | ||
| import React from 'react'; | ||
| import { Popover, PopoverHeader, PopoverHeaderIcon, PopoverHeaderText, Button } from '@patternfly/react-core'; |
There was a problem hiding this comment.
You can remove PopoverHeaderText, PopoverHeaderIcon and PopoverHeader
|
|
||
| ```ts isBeta | ||
| import React from 'react'; | ||
| import { Popover, PopoverHeader, PopoverHeaderIcon, PopoverHeaderText, Button } from '@patternfly/react-core'; |
There was a problem hiding this comment.
You can remove PopoverHeaderText, PopoverHeaderIcon and PopoverHeader
adding modifier for icon Co-authored-by: Michael Coker <35148959+mcoker@users.noreply.github.com>
adding modifier for icon Co-authored-by: Michael Coker <35148959+mcoker@users.noreply.github.com>
| children, | ||
| icon, | ||
| className, | ||
| titleHeadingLevel = 'h1', |
There was a problem hiding this comment.
I would probably expect this to be h6 to match the existing headerComponent default value.
0d205c2 to
f979a64
Compare
| icon={headerIcon} | ||
| alertSeverityVariant={alertSeverityVariant} | ||
| alertSeverityScreenReaderText={ | ||
| alertSeverityVariant ? alertSeverityScreenReaderText || `${alertSeverityVariant} alert:` : undefined |
There was a problem hiding this comment.
instead of undefined, can we just default it to ${alertSeverityVariant} alert:?
|
Your changes have been released in:
Thanks for your contribution! 🎉 |
What: Closes #6267
headeras an alternative, composable way to build a popover headerPopoverHeader,PopoverHeaderIcon,PopoverHeaderTextcomponents to build headersalertVariantprop toPopoverto control alert stylingPopoverHeadertoPopoverInternalHeader. This component wasn't exported before so this shouldn't be breaking.After some review, the initial approach was altered. Now:
alertSeverityVariantandalertSeverityScreenReaderTextprop toPopoverto control alert stylingPopoverHeader,PopoverHeaderIcon,PopoverHeaderTextcomponents to build headers (not exposed)headerIconheaderIconoralertSeverityVariantare defined, theheaderContentis placed inPopoverHeaderTextrather than aTitlecomponent, and the whole header is wrapped in aheaderelement.