Debian Codegraph @

node/@patternfly/react-core/src/components/Banner/Banner.tsx

raw
1 import styles from '@patternfly/react-styles/css/components/Banner/banner';
2 import { css } from '@patternfly/react-styles';
3
4 export type BannerColor = 'red' | 'orangered' | 'orange' | 'yellow' | 'green' | 'teal' | 'blue' | 'purple';
5
6 export type BannerStatus = 'success' | 'warning' | 'danger' | 'info' | 'custom';
7
8 export interface BannerProps extends React.HTMLProps<HTMLDivElement> {
9 /** Content rendered inside the banner. */
10 children?: React.ReactNode;
11 /** Additional classes added to the banner. */
12 className?: string;
13 /** If set to true, the banner sticks to the top of its container */
14 isSticky?: boolean;
15 /** If set to true, the banner will have a pill shape */
16 isPill?: boolean;
17 /** Text announced by screen readers to indicate the type of banner. This prop should only
18 * be passed in when the banner conveys status/severity.
19 */
20 screenReaderText?: string;
21 /** Color options for the banner, will be overwritten by any applied using the status prop. */
22 color?: BannerColor;
23 /** Status style options for the banner, will overwrite any color applied using the color prop. */
24 status?: BannerStatus;
25 }
26 interface StatusBanner extends BannerProps {
27 color?: never;
28 status?: BannerStatus;
29 }
30
31 interface NonStatusBanner extends BannerProps {
32 color?: BannerColor;
33 status?: never;
34 }
35
36 export const Banner: React.FunctionComponent<StatusBanner | NonStatusBanner> = ({
37 children,
38 className,
39 screenReaderText,
40 isSticky = false,
41 isPill = false,
42 color,
43 status,
44 ...props
45 }: BannerProps) => {
46 const getStatusOrColorModifier = () => {
47 if (status) {
48 return styles.modifiers[status];
49 }
50
51 if (color) {
52 return styles.modifiers[color];
53 }
54 };
55
56 return (
57 <div
58 className={css(
59 styles.banner,
60 getStatusOrColorModifier(),
61 isSticky && styles.modifiers.sticky,
62 isPill && styles.modifiers.pill,
63 className
64 )}
65 {...props}
66 >
67 {screenReaderText && <span className="pf-v6-screen-reader">{screenReaderText}</span>}
68 {children}
69 </div>
70 );
71 };
72 Banner.displayName = 'Banner';