-
Notifications
You must be signed in to change notification settings - Fork 842
/
Copy pathdescription_list.tsx
126 lines (111 loc) Β· 3.39 KB
/
description_list.tsx
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
import React, { HTMLAttributes, ReactNode, FunctionComponent } from 'react';
import classNames from 'classnames';
import { EuiDescriptionListTitle } from './description_list_title';
import { EuiDescriptionListDescription } from './description_list_description';
import { CommonProps, keysOf } from '../common';
export type EuiDescriptionListType = keyof typeof typesToClassNameMap;
export type EuiDescriptionListAlignment = keyof typeof alignmentsToClassNameMap;
export type EuiDescriptionListTextStyle = keyof typeof textStylesToClassNameMap;
export interface EuiDescriptionListProps {
listItems?: Array<{
title: NonNullable<ReactNode>;
description: NonNullable<ReactNode>;
}>;
/**
* Text alignment
*/
align?: EuiDescriptionListAlignment;
/**
* Smaller text and condensed spacing
*/
compressed?: boolean;
/**
* How should the content be styled, by default
* this will emphasize the title
*/
textStyle?: EuiDescriptionListTextStyle;
/**
* How each item should be laid out
*/
type?: EuiDescriptionListType;
/**
* Props object to be passed to `EuiDescriptionListTitle`
*/
titleProps?: HTMLAttributes<HTMLElement>;
/**
* Props object to be passed to `EuiDescriptionListDescription`
*/
descriptionProps?: HTMLAttributes<HTMLElement>;
}
const typesToClassNameMap = {
row: 'euiDescriptionList--row',
inline: 'euiDescriptionList--inline',
column: 'euiDescriptionList--column',
responsiveColumn: 'euiDescriptionList--responsiveColumn',
};
export const TYPES = keysOf(typesToClassNameMap);
const alignmentsToClassNameMap = {
center: 'euiDescriptionList--center',
left: '',
};
export const ALIGNMENTS = keysOf(alignmentsToClassNameMap);
const textStylesToClassNameMap = {
normal: '',
reverse: 'euiDescriptionList--reverse',
};
export const TEXT_STYLES = keysOf(textStylesToClassNameMap);
export const EuiDescriptionList: FunctionComponent<
CommonProps & HTMLAttributes<HTMLDListElement> & EuiDescriptionListProps
> = ({
align = 'left',
children,
className,
compressed = false,
descriptionProps,
listItems,
textStyle = 'normal',
titleProps,
type = 'row',
...rest
}) => {
const classes = classNames(
'euiDescriptionList',
type ? typesToClassNameMap[type] : undefined,
align ? alignmentsToClassNameMap[align] : undefined,
textStyle ? textStylesToClassNameMap[textStyle] : undefined,
{
'euiDescriptionList--compressed': compressed,
},
className
);
let childrenOrListItems = null;
if (listItems) {
childrenOrListItems = listItems.map((item, index) => {
return [
<EuiDescriptionListTitle key={`title-${index}`} {...titleProps}>
{item.title}
</EuiDescriptionListTitle>,
<EuiDescriptionListDescription
key={`description-${index}`}
{...descriptionProps}
>
{item.description}
</EuiDescriptionListDescription>,
];
});
} else {
childrenOrListItems = children;
}
return (
<dl className={classes} {...rest}>
{childrenOrListItems}
</dl>
);
};