forked from patternfly/patternfly-react
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPanel.tsx
More file actions
60 lines (55 loc) · 1.55 KB
/
Panel.tsx
File metadata and controls
60 lines (55 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import * as React from 'react';
import styles from '@patternfly/react-styles/css/components/Panel/panel';
import { css } from '@patternfly/react-styles';
export interface PanelProps extends React.HTMLProps<HTMLDivElement> {
/** Content rendered inside the panel */
children?: React.ReactNode;
/** Class to add to outer div */
className?: string;
/** Adds panel variant styles */
variant?: 'raised' | 'bordered' | 'secondary';
/** Flag to add scrollable styling to the panel */
isScrollable?: boolean;
/** Enable better a11y */
a11y?: any;
/** @hide Forwarded ref */
innerRef?: React.Ref<any>;
}
import { getA11y } from './utils';
export enum a11yEnum {
/** Adds aria-live="off" to the panel */
off = 'off',
/** Adds aria-live="assertive" to the panel */
assertive = 'assertive',
/** Adds aria-live="polite" to the panel */
polite = 'polite'
}
const PanelBase: React.FunctionComponent<PanelProps> = ({
className,
children,
variant,
isScrollable,
innerRef,
...props
}: PanelProps) => (
<div
className={css(
styles.panel,
variant && styles.modifiers[variant],
isScrollable && styles.modifiers.scrollable,
className
)}
ref={innerRef}
aria-live={convertGetA11yForAriaLive(getA11y(props)) as any}
{...props}
>
{children}
</div>
);
function convertGetA11yForAriaLive(response: string) {
return a11yEnum[response as 'off'];
}
export const Panel = React.forwardRef((props: PanelProps, ref: React.Ref<any>) => (
<PanelBase innerRef={ref} {...props} />
));
Panel.displayName = 'Panel';