-
Notifications
You must be signed in to change notification settings - Fork 374
feat(banner): add support for new styles in penta #9891
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,10 @@ import * as React from 'react'; | |
| import styles from '@patternfly/react-styles/css/components/Banner/banner'; | ||
| import { css } from '@patternfly/react-styles'; | ||
|
|
||
| export type BannerColor = 'red' | 'orangered' | 'orange' | 'gold' | 'green' | 'cyan' | 'blue' | 'purple'; | ||
|
|
||
| export type BannerStatus = 'success' | 'warning' | 'danger' | 'info' | 'custom'; | ||
|
|
||
| export interface BannerProps extends React.HTMLProps<HTMLDivElement> { | ||
| /** Content rendered inside the banner. */ | ||
| children?: React.ReactNode; | ||
|
|
@@ -13,29 +17,48 @@ export interface BannerProps extends React.HTMLProps<HTMLDivElement> { | |
| * be passed in when the banner conveys status/severity. | ||
| */ | ||
| screenReaderText?: string; | ||
| /** Variant styles for the banner. */ | ||
| variant?: 'default' | 'blue' | 'red' | 'green' | 'gold'; | ||
| /** Color options for the banner, will be overwritten by any applied using the status prop. */ | ||
| color?: BannerColor; | ||
| /** Status style options for the banner, will overwrite any color applied using the color prop. */ | ||
| status?: BannerStatus; | ||
| } | ||
| interface StatusBanner extends BannerProps { | ||
| color?: never; | ||
| status?: BannerStatus; | ||
| } | ||
|
|
||
| export const Banner: React.FunctionComponent<BannerProps> = ({ | ||
| interface NonStatusBanner extends BannerProps { | ||
| color?: BannerColor; | ||
| status?: never; | ||
| } | ||
|
|
||
| export const Banner: React.FunctionComponent<StatusBanner | NonStatusBanner> = ({ | ||
|
Comment on lines
+25
to
+35
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tried this out as a way of preventing both
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not entirely sure how I feel about this. It's definitely an improvement from what was attempted in 91d7907 (with the main issue being it didn't render props in the prop table correctly, whereas this PR does). At the same time I'm almost wondering if it'd be better to just keep the Otherwise this looks good. If anything we could have a followup discussion about it since it's only going into the v6 branch so I wouldn't block over this going in now. |
||
| children, | ||
| className, | ||
| variant = 'default', | ||
| screenReaderText, | ||
| isSticky = false, | ||
| color, | ||
| status, | ||
| ...props | ||
| }: BannerProps) => ( | ||
| <div | ||
| className={css( | ||
| styles.banner, | ||
| styles.modifiers[variant as 'green' | 'red' | 'gold' | 'blue'], | ||
| isSticky && styles.modifiers.sticky, | ||
| className | ||
| )} | ||
| {...props} | ||
| > | ||
| {screenReaderText && <span className="pf-v5-screen-reader">{screenReaderText}</span>} | ||
| {children} | ||
| </div> | ||
| ); | ||
| }: BannerProps) => { | ||
| const getStatusOrColorModifier = () => { | ||
| if (status) { | ||
| return styles.modifiers[status]; | ||
| } | ||
|
|
||
| if (color) { | ||
| return styles.modifiers[color]; | ||
| } | ||
| }; | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not a big deal and maybe more of a preference thing, but as color and status are used exactly the same way, i think i'd just get rid of |
||
| return ( | ||
| <div | ||
| className={css(styles.banner, getStatusOrColorModifier(), isSticky && styles.modifiers.sticky, className)} | ||
| {...props} | ||
| > | ||
| {screenReaderText && <span className="pf-v5-screen-reader">{screenReaderText}</span>} | ||
| {children} | ||
| </div> | ||
| ); | ||
| }; | ||
| Banner.displayName = 'Banner'; | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Exported union types so that consumers can import them if needed, I remember that being talked about at an office hours not long ago.