Skip to content

feat(Popover): add composable header and alert variants#6664

Merged
tlabaj merged 22 commits into
patternfly:mainfrom
kmcfaul:popover-alert
Dec 9, 2021
Merged

feat(Popover): add composable header and alert variants#6664
tlabaj merged 22 commits into
patternfly:mainfrom
kmcfaul:popover-alert

Conversation

@kmcfaul
Copy link
Copy Markdown
Contributor

@kmcfaul kmcfaul commented Dec 1, 2021

What: Closes #6267

  • Adds header as an alternative, composable way to build a popover header
  • Adds PopoverHeader, PopoverHeaderIcon, PopoverHeaderText components to build headers
  • Adds alertVariant prop to Popover to control alert styling
  • Renames the previous PopoverHeader to PopoverInternalHeader. This component wasn't exported before so this shouldn't be breaking.

After some review, the initial approach was altered. Now:

  • Adds alertSeverityVariant and alertSeverityScreenReaderText prop to Popover to control alert styling
  • Adds PopoverHeader, PopoverHeaderIcon, PopoverHeaderText components to build headers (not exposed)
  • Adds headerIcon
  • When headerIcon or alertSeverityVariant are defined, the headerContent is placed in PopoverHeaderText rather than a Title component, and the whole header is wrapped in a header element.

@patternfly-build
Copy link
Copy Markdown
Collaborator

patternfly-build commented Dec 1, 2021

Copy link
Copy Markdown
Member

@mcarrano mcarrano left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great. Thanks @kmcfaul !

Copy link
Copy Markdown
Contributor

@nicolethoen nicolethoen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread packages/react-core/src/components/Popover/examples/Popover.md Outdated
Comment thread packages/react-core/src/components/Popover/examples/Popover.md Outdated
</Title>
)}
</PopoverContext.Consumer>
<header className={css('pf-c-popover__header')} {...props}>
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

import { css } from '@patternfly/react-styles';

export interface PopoverFooterProps extends React.HTMLProps<HTMLDivElement> {
/** Additional classes added to the Popover Footer */
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit. sentence case

*/
header?: React.ReactNode | ((hide: () => void) => React.ReactNode);
/** Variants for an alert popover */
alertVariant?: 'default' | 'info' | 'warning' | 'success' | 'danger';
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tlabaj how about alertLevelVariant or alertSeverityVariant

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nicole, those suggestions are good. Maybe some more context in the description of what it does will also help.

Copy link
Copy Markdown
Collaborator

@jschuler jschuler Dec 7, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Beat me to it. I was going to ask for beta tag :)

Copy link
Copy Markdown
Contributor

@tlabaj tlabaj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you also mark new exported componets Beta please.

Comment on lines +6 to +7
/** ID of the popover header. */
id?: string;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should headerComponent set the heading level here, too.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kmcfaul is the only reason you built this to be composable because you needed to put the hasIcon prop at the outermost level?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

@tlabaj tlabaj Dec 8, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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>}
Copy link
Copy Markdown
Contributor

@tlabaj tlabaj Dec 8, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The "alert" text in this span needs to be configurable.

alertSeverityVariant={alertSeverityVariant}
titleHeadingLevel={headerComponent}
>
<React.Fragment>{typeof headerContent === 'function' ? headerContent(hide) : headerContent}</React.Fragment>
Copy link
Copy Markdown
Contributor

@tlabaj tlabaj Dec 8, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need the <React.Fragment>


```ts isBeta
import React from 'react';
import { Popover, PopoverHeader, PopoverHeaderIcon, PopoverHeaderText, Button } from '@patternfly/react-core';
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can remove PopoverHeaderText, PopoverHeaderIcon and PopoverHeader


```ts isBeta
import React from 'react';
import { Popover, PopoverHeader, PopoverHeaderIcon, PopoverHeaderText, Button } from '@patternfly/react-core';
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can remove PopoverHeaderText, PopoverHeaderIcon and PopoverHeader

children,
icon,
className,
titleHeadingLevel = 'h1',
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would probably expect this to be h6 to match the existing headerComponent default value.

icon={headerIcon}
alertSeverityVariant={alertSeverityVariant}
alertSeverityScreenReaderText={
alertSeverityVariant ? alertSeverityScreenReaderText || `${alertSeverityVariant} alert:` : undefined
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of undefined, can we just default it to ${alertSeverityVariant} alert:?

Copy link
Copy Markdown
Contributor

@tlabaj tlabaj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Copy Markdown
Contributor

@mcoker mcoker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🥳

@tlabaj tlabaj merged commit 9028e8b into patternfly:main Dec 9, 2021
@patternfly-build
Copy link
Copy Markdown
Collaborator

Your changes have been released in:

  • eslint-plugin-patternfly-react@4.20.0
  • @patternfly/react-catalog-view-extension@4.32.0
  • @patternfly/react-charts@6.34.0
  • @patternfly/react-code-editor@4.22.0
  • @patternfly/react-console@4.32.0
  • @patternfly/react-core@4.181.0
  • @patternfly/react-docs@5.42.0
  • @patternfly/react-icons@4.32.0
  • @patternfly/react-inline-edit-extension@4.26.0
  • demo-app-ts@4.141.0
  • @patternfly/react-integration@4.143.0
  • @patternfly/react-log-viewer@4.26.0
  • @patternfly/react-styles@4.31.0
  • @patternfly/react-table@4.50.0
  • @patternfly/react-tokens@4.33.0
  • @patternfly/react-topology@4.28.0
  • @patternfly/react-virtualized-extension@4.28.0
  • transformer-cjs-imports@4.19.0

Thanks for your contribution! 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Popover: add alert variants

8 participants