Debian Codegraph @

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

raw
1 import styles from '@patternfly/react-styles/css/components/List/list';
2 import { css } from '@patternfly/react-styles';
3
4 export enum OrderType {
5 number = '1',
6 lowercaseLetter = 'a',
7 uppercaseLetter = 'A',
8 lowercaseRomanNumber = 'i',
9 uppercaseRomanNumber = 'I'
10 }
11
12 export enum ListVariant {
13 inline = 'inline'
14 }
15
16 export enum ListComponent {
17 ol = 'ol',
18 ul = 'ul'
19 }
20
21 export interface ListProps extends Omit<React.HTMLProps<HTMLUListElement | HTMLOListElement>, 'type'> {
22 /** Anything that can be rendered inside of the list */
23 children?: React.ReactNode;
24 /** Additional classes added to the list */
25 className?: string;
26 /** Adds list variant styles */
27 variant?: ListVariant.inline;
28 /** Modifies the list to add borders between items */
29 isBordered?: boolean;
30 /** Modifies the list to include plain styling */
31 isPlain?: boolean;
32 /** Modifies the size of the icons in the list */
33 iconSize?: 'default' | 'large';
34 /** Sets the way items are numbered if component is set to "ol". */
35 type?: OrderType;
36 /** Sets the type of the list component. */
37 component?: 'ol' | 'ul';
38 /** Adds an accessible label to the list. */
39 'aria-label'?: string;
40 }
41
42 export const List: React.FunctionComponent<ListProps> = ({
43 className = '',
44 children = null,
45 variant = null,
46 isBordered = false,
47 isPlain = false,
48 iconSize = 'default',
49 type = OrderType.number,
50 ref = null,
51 component = ListComponent.ul,
52 'aria-label': ariaLabel,
53 ...props
54 }: ListProps) =>
55 component === ListComponent.ol ? (
56 <ol
57 ref={ref as React.Ref<HTMLOListElement>}
58 type={type}
59 aria-label={ariaLabel}
60 {...(isPlain && { role: 'list' })}
61 {...props}
62 className={css(
63 styles.list,
64 variant && styles.modifiers[variant],
65 isBordered && styles.modifiers.bordered,
66 isPlain && styles.modifiers.plain,
67 iconSize && iconSize === 'large' && styles.modifiers.iconLg,
68 className
69 )}
70 >
71 {children}
72 </ol>
73 ) : (
74 <ul
75 ref={ref as React.Ref<HTMLUListElement>}
76 aria-label={ariaLabel}
77 {...(isPlain && { role: 'list' })}
78 {...props}
79 className={css(
80 styles.list,
81 variant && styles.modifiers[variant],
82 isBordered && styles.modifiers.bordered,
83 isPlain && styles.modifiers.plain,
84 iconSize && iconSize === 'large' && styles.modifiers.iconLg,
85 className
86 )}
87 >
88 {children}
89 </ul>
90 );
91 List.displayName = 'List';