@commercetools-frontend/ui-kit 19.11.0 → 19.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@commercetools-frontend/ui-kit",
|
|
3
3
|
"description": "A preset of all the UI-Kit components.",
|
|
4
|
-
"version": "19.
|
|
4
|
+
"version": "19.12.0",
|
|
5
5
|
"bugs": "https://github.com/commercetools/ui-kit/issues",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -24,42 +24,42 @@
|
|
|
24
24
|
"dependencies": {
|
|
25
25
|
"@babel/runtime": "^7.20.13",
|
|
26
26
|
"@babel/runtime-corejs3": "^7.20.13",
|
|
27
|
-
"@commercetools-uikit/accessible-hidden": "19.
|
|
28
|
-
"@commercetools-uikit/avatar": "19.
|
|
29
|
-
"@commercetools-uikit/buttons": "19.
|
|
30
|
-
"@commercetools-uikit/card": "19.
|
|
31
|
-
"@commercetools-uikit/collapsible": "19.
|
|
32
|
-
"@commercetools-uikit/collapsible-motion": "19.
|
|
33
|
-
"@commercetools-uikit/collapsible-panel": "19.
|
|
34
|
-
"@commercetools-uikit/constraints": "19.
|
|
35
|
-
"@commercetools-uikit/data-table": "19.
|
|
36
|
-
"@commercetools-uikit/data-table-manager": "19.
|
|
37
|
-
"@commercetools-uikit/design-system": "19.
|
|
38
|
-
"@commercetools-uikit/dropdown-menu": "19.
|
|
39
|
-
"@commercetools-uikit/field-errors": "19.
|
|
40
|
-
"@commercetools-uikit/field-label": "19.
|
|
41
|
-
"@commercetools-uikit/fields": "19.
|
|
42
|
-
"@commercetools-uikit/grid": "19.
|
|
43
|
-
"@commercetools-uikit/hooks": "19.
|
|
44
|
-
"@commercetools-uikit/i18n": "19.
|
|
45
|
-
"@commercetools-uikit/icons": "19.
|
|
46
|
-
"@commercetools-uikit/inputs": "19.
|
|
47
|
-
"@commercetools-uikit/label": "19.
|
|
48
|
-
"@commercetools-uikit/link": "19.
|
|
49
|
-
"@commercetools-uikit/loading-spinner": "19.
|
|
50
|
-
"@commercetools-uikit/messages": "19.
|
|
51
|
-
"@commercetools-uikit/notifications": "19.
|
|
52
|
-
"@commercetools-uikit/pagination": "19.
|
|
53
|
-
"@commercetools-uikit/primary-action-dropdown": "19.
|
|
54
|
-
"@commercetools-uikit/progress-bar": "19.
|
|
55
|
-
"@commercetools-uikit/selectable-search-input": "19.
|
|
56
|
-
"@commercetools-uikit/spacings": "19.
|
|
57
|
-
"@commercetools-uikit/stamp": "19.
|
|
58
|
-
"@commercetools-uikit/tag": "19.
|
|
59
|
-
"@commercetools-uikit/text": "19.
|
|
60
|
-
"@commercetools-uikit/tooltip": "19.
|
|
61
|
-
"@commercetools-uikit/utils": "19.
|
|
62
|
-
"@commercetools-uikit/view-switcher": "19.
|
|
27
|
+
"@commercetools-uikit/accessible-hidden": "19.12.0",
|
|
28
|
+
"@commercetools-uikit/avatar": "19.12.0",
|
|
29
|
+
"@commercetools-uikit/buttons": "19.12.0",
|
|
30
|
+
"@commercetools-uikit/card": "19.12.0",
|
|
31
|
+
"@commercetools-uikit/collapsible": "19.12.0",
|
|
32
|
+
"@commercetools-uikit/collapsible-motion": "19.12.0",
|
|
33
|
+
"@commercetools-uikit/collapsible-panel": "19.12.0",
|
|
34
|
+
"@commercetools-uikit/constraints": "19.12.0",
|
|
35
|
+
"@commercetools-uikit/data-table": "19.12.0",
|
|
36
|
+
"@commercetools-uikit/data-table-manager": "19.12.0",
|
|
37
|
+
"@commercetools-uikit/design-system": "19.12.0",
|
|
38
|
+
"@commercetools-uikit/dropdown-menu": "19.12.0",
|
|
39
|
+
"@commercetools-uikit/field-errors": "19.12.0",
|
|
40
|
+
"@commercetools-uikit/field-label": "19.12.0",
|
|
41
|
+
"@commercetools-uikit/fields": "19.12.0",
|
|
42
|
+
"@commercetools-uikit/grid": "19.12.0",
|
|
43
|
+
"@commercetools-uikit/hooks": "19.12.0",
|
|
44
|
+
"@commercetools-uikit/i18n": "19.12.0",
|
|
45
|
+
"@commercetools-uikit/icons": "19.12.0",
|
|
46
|
+
"@commercetools-uikit/inputs": "19.12.0",
|
|
47
|
+
"@commercetools-uikit/label": "19.12.0",
|
|
48
|
+
"@commercetools-uikit/link": "19.12.0",
|
|
49
|
+
"@commercetools-uikit/loading-spinner": "19.12.0",
|
|
50
|
+
"@commercetools-uikit/messages": "19.12.0",
|
|
51
|
+
"@commercetools-uikit/notifications": "19.12.0",
|
|
52
|
+
"@commercetools-uikit/pagination": "19.12.0",
|
|
53
|
+
"@commercetools-uikit/primary-action-dropdown": "19.12.0",
|
|
54
|
+
"@commercetools-uikit/progress-bar": "19.12.0",
|
|
55
|
+
"@commercetools-uikit/selectable-search-input": "19.12.0",
|
|
56
|
+
"@commercetools-uikit/spacings": "19.12.0",
|
|
57
|
+
"@commercetools-uikit/stamp": "19.12.0",
|
|
58
|
+
"@commercetools-uikit/tag": "19.12.0",
|
|
59
|
+
"@commercetools-uikit/text": "19.12.0",
|
|
60
|
+
"@commercetools-uikit/tooltip": "19.12.0",
|
|
61
|
+
"@commercetools-uikit/utils": "19.12.0",
|
|
62
|
+
"@commercetools-uikit/view-switcher": "19.12.0"
|
|
63
63
|
},
|
|
64
64
|
"devDependencies": {
|
|
65
65
|
"moment": "2.30.1",
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
import styled from '@emotion/styled';
|
|
2
|
-
|
|
3
|
-
const BasicSample = styled.div``;
|
|
4
|
-
|
|
5
|
-
const BorderRadiusSample = styled.div`
|
|
6
|
-
width: calc(${(props) => props.value} + 2 * ${(props) => props.value});
|
|
7
|
-
min-width: 20px;
|
|
8
|
-
height: calc(${(props) => props.value} + 2 * ${(props) => props.value});
|
|
9
|
-
min-height: 20px;
|
|
10
|
-
background-color: pink;
|
|
11
|
-
border-radius: ${(props) => props.value};
|
|
12
|
-
display: inline-block;
|
|
13
|
-
margin: 0 10px;
|
|
14
|
-
`;
|
|
15
|
-
|
|
16
|
-
const ColorSample = styled.div`
|
|
17
|
-
width: 30px;
|
|
18
|
-
height: 30px;
|
|
19
|
-
background-color: ${(props) => props.value};
|
|
20
|
-
box-shadow: inset 0 0 5px 0 rgba(0, 0, 0, 0.1);
|
|
21
|
-
display: inline-block;
|
|
22
|
-
`;
|
|
23
|
-
|
|
24
|
-
const FontColorSampleStyle = styled.div`
|
|
25
|
-
color: ${(props) => props.value};
|
|
26
|
-
font-size: 24pt;
|
|
27
|
-
font-weight: bolder;
|
|
28
|
-
display: inline-block;
|
|
29
|
-
`;
|
|
30
|
-
const FontColorSample = (props) => (
|
|
31
|
-
<FontColorSampleStyle {...props}>Aa</FontColorSampleStyle>
|
|
32
|
-
);
|
|
33
|
-
|
|
34
|
-
const FontSizeSampleStyle = styled.div`
|
|
35
|
-
font-size: ${(props) => props.value};
|
|
36
|
-
font-weight: bolder;
|
|
37
|
-
display: inline-block;
|
|
38
|
-
`;
|
|
39
|
-
const FontSizeSample = (props) => (
|
|
40
|
-
<FontSizeSampleStyle {...props}>Aa</FontSizeSampleStyle>
|
|
41
|
-
);
|
|
42
|
-
|
|
43
|
-
const FontWeightSampleStyle = styled.div`
|
|
44
|
-
font-weight: ${(props) => props.value};
|
|
45
|
-
font-size: 2rem;
|
|
46
|
-
display: inline-block;
|
|
47
|
-
`;
|
|
48
|
-
const FontWeightSample = (props) => (
|
|
49
|
-
<FontWeightSampleStyle {...props}>Aa</FontWeightSampleStyle>
|
|
50
|
-
);
|
|
51
|
-
|
|
52
|
-
const ShadowSample = styled.div`
|
|
53
|
-
width: 50px;
|
|
54
|
-
height: 50px;
|
|
55
|
-
box-shadow: ${(props) => props.value};
|
|
56
|
-
display: inline-block;
|
|
57
|
-
margin: 0 10px;
|
|
58
|
-
`;
|
|
59
|
-
|
|
60
|
-
const SpacingSample = styled.div`
|
|
61
|
-
width: ${(props) => props.value};
|
|
62
|
-
height: ${(props) => props.value};
|
|
63
|
-
background-color: lightblue;
|
|
64
|
-
display: inline-block;
|
|
65
|
-
margin: 0 10px;
|
|
66
|
-
`;
|
|
67
|
-
|
|
68
|
-
const samplersMap = {
|
|
69
|
-
'background-color': ColorSample,
|
|
70
|
-
'border-color': ColorSample,
|
|
71
|
-
'border-radius': BorderRadiusSample,
|
|
72
|
-
color: ColorSample,
|
|
73
|
-
'font-color': FontColorSample,
|
|
74
|
-
'font-size': FontSizeSample,
|
|
75
|
-
'font-weight': FontWeightSample,
|
|
76
|
-
'icon-color': ColorSample,
|
|
77
|
-
shadow: ShadowSample,
|
|
78
|
-
spacing: SpacingSample,
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
export const getSampleComponent = (cssRuleName) =>
|
|
82
|
-
samplersMap[cssRuleName] || BasicSample;
|
|
@@ -1,270 +0,0 @@
|
|
|
1
|
-
/* eslint-disable jsx-a11y/anchor-is-valid */
|
|
2
|
-
/* eslint-disable jsx-a11y/anchor-has-content */
|
|
3
|
-
import styled from '@emotion/styled';
|
|
4
|
-
import PropTypes from 'prop-types';
|
|
5
|
-
import upperFirst from 'lodash/upperFirst';
|
|
6
|
-
import deprecatedTokens from '../deprecated-tokens';
|
|
7
|
-
|
|
8
|
-
const getIsDeprecated = (token) => deprecatedTokens.includes(token);
|
|
9
|
-
|
|
10
|
-
const filterGroupItemsValues = (groupItems, searchText) =>
|
|
11
|
-
Object.entries(groupItems).filter(
|
|
12
|
-
([key, value]) =>
|
|
13
|
-
key.toLowerCase().includes(searchText.toLowerCase()) ||
|
|
14
|
-
value?.toLowerCase?.().includes(searchText.toLowerCase()) ||
|
|
15
|
-
value?.description?.toLowerCase().includes(searchText.toLowerCase())
|
|
16
|
-
);
|
|
17
|
-
|
|
18
|
-
const Table = styled.table`
|
|
19
|
-
border: 1px solid #ccc;
|
|
20
|
-
border-collapse: collapse;
|
|
21
|
-
& tr td {
|
|
22
|
-
border: 1px solid #ccc;
|
|
23
|
-
padding: 15px;
|
|
24
|
-
text-align: left;
|
|
25
|
-
}
|
|
26
|
-
& thead td {
|
|
27
|
-
background-color: gray;
|
|
28
|
-
color: white;
|
|
29
|
-
font-weight: bold;
|
|
30
|
-
}
|
|
31
|
-
`;
|
|
32
|
-
|
|
33
|
-
const GroupStyle = styled.div`
|
|
34
|
-
padding: 10px;
|
|
35
|
-
display: ${(props) => (props.isVisible ? 'block' : 'none')};
|
|
36
|
-
`;
|
|
37
|
-
|
|
38
|
-
export const Token = styled.p`
|
|
39
|
-
font-family: monospace;
|
|
40
|
-
`;
|
|
41
|
-
|
|
42
|
-
const DeprecationBadge = () => <b style={{ color: 'orange' }}>DEPRECATED</b>;
|
|
43
|
-
DeprecationBadge.displayName = 'DeprecationBadge';
|
|
44
|
-
|
|
45
|
-
export const TokenBodyCell = (props) => (
|
|
46
|
-
<>
|
|
47
|
-
<Token>{props.tokenName}</Token>
|
|
48
|
-
{getIsDeprecated(props.tokenName) && <DeprecationBadge />}
|
|
49
|
-
</>
|
|
50
|
-
);
|
|
51
|
-
TokenBodyCell.propTypes = {
|
|
52
|
-
tokenName: PropTypes.string.isRequired,
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
export const TokenGroupLinks = (props) => {
|
|
56
|
-
return (
|
|
57
|
-
<>
|
|
58
|
-
<a
|
|
59
|
-
href={`#${props.id}`}
|
|
60
|
-
onClick={(event) => {
|
|
61
|
-
event.preventDefault();
|
|
62
|
-
window.scrollTo({
|
|
63
|
-
top: document.getElementById(props.id).offsetTop,
|
|
64
|
-
behavior: 'smooth',
|
|
65
|
-
});
|
|
66
|
-
}}
|
|
67
|
-
>
|
|
68
|
-
{props.children}
|
|
69
|
-
</a>
|
|
70
|
-
{Boolean(props.config) && (
|
|
71
|
-
<ul>
|
|
72
|
-
{Object.entries(props.config).map(
|
|
73
|
-
([key, configGroup]) =>
|
|
74
|
-
filterGroupItemsValues(
|
|
75
|
-
configGroup.choices || configGroup.decisions,
|
|
76
|
-
props.filterText
|
|
77
|
-
).length > 0 && (
|
|
78
|
-
<li key={key}>
|
|
79
|
-
<a
|
|
80
|
-
href={`#${props.id}-${configGroup.prefix}`}
|
|
81
|
-
onClick={(event) => {
|
|
82
|
-
event.preventDefault();
|
|
83
|
-
window.scrollTo({
|
|
84
|
-
top: document.getElementById(
|
|
85
|
-
`${props.id}-${configGroup.prefix}`
|
|
86
|
-
).offsetTop,
|
|
87
|
-
behavior: 'smooth',
|
|
88
|
-
});
|
|
89
|
-
}}
|
|
90
|
-
>
|
|
91
|
-
{configGroup.label}
|
|
92
|
-
</a>
|
|
93
|
-
</li>
|
|
94
|
-
)
|
|
95
|
-
)}
|
|
96
|
-
</ul>
|
|
97
|
-
)}
|
|
98
|
-
</>
|
|
99
|
-
);
|
|
100
|
-
};
|
|
101
|
-
TokenGroupLinks.propTypes = {
|
|
102
|
-
id: PropTypes.string.isRequired,
|
|
103
|
-
config: PropTypes.object,
|
|
104
|
-
filterText: PropTypes.string,
|
|
105
|
-
children: PropTypes.node.isRequired,
|
|
106
|
-
};
|
|
107
|
-
|
|
108
|
-
const TableBody = (props) => {
|
|
109
|
-
return (
|
|
110
|
-
<tbody>
|
|
111
|
-
{props.groupItems.map(([tokenName, tokenData]) => {
|
|
112
|
-
return (
|
|
113
|
-
<tr key={`${props.groupItemsPrefix}-${tokenName}-body-row-key`}>
|
|
114
|
-
{props.columnsConfig.map((columnConfig) => (
|
|
115
|
-
<td
|
|
116
|
-
key={`${props.groupItemsPrefix}-${tokenName}-${columnConfig.key}-body-cell-key`}
|
|
117
|
-
>
|
|
118
|
-
{props.cellRenderer({
|
|
119
|
-
columnKey: columnConfig.key,
|
|
120
|
-
groupItemsPrefix: props.groupItemsPrefix,
|
|
121
|
-
tokenName,
|
|
122
|
-
tokenData,
|
|
123
|
-
themeName: props.themeName,
|
|
124
|
-
})}
|
|
125
|
-
</td>
|
|
126
|
-
))}
|
|
127
|
-
</tr>
|
|
128
|
-
);
|
|
129
|
-
})}
|
|
130
|
-
</tbody>
|
|
131
|
-
);
|
|
132
|
-
};
|
|
133
|
-
TableBody.propTypes = {
|
|
134
|
-
groupItems: PropTypes.array.isRequired,
|
|
135
|
-
groupItemsPrefix: PropTypes.string,
|
|
136
|
-
themeName: PropTypes.string.isRequired,
|
|
137
|
-
columnsConfig: PropTypes.arrayOf(
|
|
138
|
-
PropTypes.shape({
|
|
139
|
-
key: PropTypes.string.isRequired,
|
|
140
|
-
label: PropTypes.string,
|
|
141
|
-
})
|
|
142
|
-
).isRequired,
|
|
143
|
-
cellRenderer: PropTypes.func.isRequired,
|
|
144
|
-
};
|
|
145
|
-
|
|
146
|
-
const TokensDetailsTable = (props) => (
|
|
147
|
-
<Table>
|
|
148
|
-
<thead>
|
|
149
|
-
<tr>
|
|
150
|
-
{props.columnsConfig.map((columnsConfig, index) => (
|
|
151
|
-
<td
|
|
152
|
-
key={columnsConfig.key}
|
|
153
|
-
style={{
|
|
154
|
-
minWidth: index === 0 ? 400 : 'auto',
|
|
155
|
-
}}
|
|
156
|
-
>
|
|
157
|
-
{columnsConfig.label || upperFirst(columnsConfig.key)}
|
|
158
|
-
</td>
|
|
159
|
-
))}
|
|
160
|
-
</tr>
|
|
161
|
-
</thead>
|
|
162
|
-
<TableBody
|
|
163
|
-
groupItems={props.tokensGroupData}
|
|
164
|
-
groupItemsPrefix={props.tokensGroupPrefix}
|
|
165
|
-
themeName={props.themeName}
|
|
166
|
-
columnsConfig={props.columnsConfig}
|
|
167
|
-
cellRenderer={props.cellRenderer}
|
|
168
|
-
/>
|
|
169
|
-
</Table>
|
|
170
|
-
);
|
|
171
|
-
TokensDetailsTable.propTypes = {
|
|
172
|
-
columnsConfig: PropTypes.arrayOf(
|
|
173
|
-
PropTypes.shape({
|
|
174
|
-
key: PropTypes.string.isRequired,
|
|
175
|
-
label: PropTypes.string,
|
|
176
|
-
})
|
|
177
|
-
).isRequired,
|
|
178
|
-
cellRenderer: PropTypes.func.isRequired,
|
|
179
|
-
themeName: PropTypes.string.isRequired,
|
|
180
|
-
tokensGroupPrefix: PropTypes.string,
|
|
181
|
-
tokensGroupData: PropTypes.array.isRequired,
|
|
182
|
-
};
|
|
183
|
-
|
|
184
|
-
export function SingleTokensGroupDetails(props) {
|
|
185
|
-
const filteredGroupItems = filterGroupItemsValues(
|
|
186
|
-
props.groupItems,
|
|
187
|
-
props.filterText
|
|
188
|
-
);
|
|
189
|
-
|
|
190
|
-
return (
|
|
191
|
-
<section>
|
|
192
|
-
<h2 id={props.id}>{props.title || upperFirst(props.id)}</h2>
|
|
193
|
-
{props.subtitle && <p>{props.subtitle}</p>}
|
|
194
|
-
<GroupStyle isVisible={filteredGroupItems.length > 0}>
|
|
195
|
-
<TokensDetailsTable
|
|
196
|
-
columnsConfig={props.columnsConfig}
|
|
197
|
-
cellRenderer={props.cellRenderer}
|
|
198
|
-
themeName={props.themeName}
|
|
199
|
-
tokensGroupPrefix=""
|
|
200
|
-
tokensGroupData={filteredGroupItems}
|
|
201
|
-
/>
|
|
202
|
-
</GroupStyle>
|
|
203
|
-
</section>
|
|
204
|
-
);
|
|
205
|
-
}
|
|
206
|
-
SingleTokensGroupDetails.propTypes = {
|
|
207
|
-
id: PropTypes.string.isRequired,
|
|
208
|
-
title: PropTypes.string,
|
|
209
|
-
subtitle: PropTypes.string,
|
|
210
|
-
filterText: PropTypes.string.isRequired,
|
|
211
|
-
groupItems: PropTypes.object.isRequired,
|
|
212
|
-
columnsConfig: PropTypes.arrayOf(
|
|
213
|
-
PropTypes.shape({
|
|
214
|
-
key: PropTypes.string.isRequired,
|
|
215
|
-
label: PropTypes.string,
|
|
216
|
-
})
|
|
217
|
-
).isRequired,
|
|
218
|
-
cellRenderer: PropTypes.func.isRequired,
|
|
219
|
-
themeName: PropTypes.string.isRequired,
|
|
220
|
-
};
|
|
221
|
-
|
|
222
|
-
export const MultiTokensGroupDetails = (props) => (
|
|
223
|
-
<section>
|
|
224
|
-
<h2 id={props.id}>{props.title || upperFirst(props.id)}</h2>
|
|
225
|
-
{props.subtitle && <p>{props.subtitle}</p>}
|
|
226
|
-
{Object.entries(props.tokensGroupData).map(
|
|
227
|
-
([tokenGroupKey, tokenGroupConfig]) => {
|
|
228
|
-
const filteredTokensGroups = filterGroupItemsValues(
|
|
229
|
-
tokenGroupConfig[props.id],
|
|
230
|
-
props.filterText
|
|
231
|
-
);
|
|
232
|
-
|
|
233
|
-
return (
|
|
234
|
-
<GroupStyle
|
|
235
|
-
key={`tokens-group_${tokenGroupKey}`}
|
|
236
|
-
isVisible={filteredTokensGroups.length > 0}
|
|
237
|
-
>
|
|
238
|
-
<a id={`${props.id}-${tokenGroupConfig.prefix}`} />
|
|
239
|
-
<h3>{tokenGroupConfig.label}</h3>
|
|
240
|
-
{Boolean(tokenGroupConfig.description) && (
|
|
241
|
-
<p>{tokenGroupConfig.description}</p>
|
|
242
|
-
)}
|
|
243
|
-
<TokensDetailsTable
|
|
244
|
-
columnsConfig={props.columnsConfig}
|
|
245
|
-
cellRenderer={props.cellRenderer}
|
|
246
|
-
themeName={props.themeName}
|
|
247
|
-
tokensGroupPrefix={tokenGroupConfig.prefix}
|
|
248
|
-
tokensGroupData={filteredTokensGroups}
|
|
249
|
-
/>
|
|
250
|
-
</GroupStyle>
|
|
251
|
-
);
|
|
252
|
-
}
|
|
253
|
-
)}
|
|
254
|
-
</section>
|
|
255
|
-
);
|
|
256
|
-
MultiTokensGroupDetails.propTypes = {
|
|
257
|
-
id: PropTypes.string.isRequired,
|
|
258
|
-
title: PropTypes.string,
|
|
259
|
-
subtitle: PropTypes.string,
|
|
260
|
-
filterText: PropTypes.string.isRequired,
|
|
261
|
-
tokensGroupData: PropTypes.object.isRequired,
|
|
262
|
-
columnsConfig: PropTypes.arrayOf(
|
|
263
|
-
PropTypes.shape({
|
|
264
|
-
key: PropTypes.string.isRequired,
|
|
265
|
-
label: PropTypes.string,
|
|
266
|
-
})
|
|
267
|
-
).isRequired,
|
|
268
|
-
cellRenderer: PropTypes.func.isRequired,
|
|
269
|
-
themeName: PropTypes.string.isRequired,
|
|
270
|
-
};
|
|
@@ -1,219 +0,0 @@
|
|
|
1
|
-
/* eslint-disable default-case */
|
|
2
|
-
import { useCallback, useMemo, useState } from 'react';
|
|
3
|
-
import { storiesOf } from '@storybook/react';
|
|
4
|
-
import styled from '@emotion/styled';
|
|
5
|
-
import merge from 'lodash/merge';
|
|
6
|
-
import TextInput from '@commercetools-uikit/text-input';
|
|
7
|
-
import { designTokens, useTheme } from '@commercetools-uikit/design-system';
|
|
8
|
-
import Readme from './TOKENS.md';
|
|
9
|
-
import definition from './definition.yaml';
|
|
10
|
-
import {
|
|
11
|
-
MultiTokensGroupDetails,
|
|
12
|
-
Token,
|
|
13
|
-
TokenBodyCell,
|
|
14
|
-
TokenGroupLinks,
|
|
15
|
-
SingleTokensGroupDetails,
|
|
16
|
-
} from './story/shared-components';
|
|
17
|
-
import { getSampleComponent } from './story/samplers';
|
|
18
|
-
|
|
19
|
-
const findChoiceValue = (theme, choiceName) => {
|
|
20
|
-
return Object.values(theme)
|
|
21
|
-
.map((choiceGroup) => choiceGroup.choices)
|
|
22
|
-
.find((choices) => choices[choiceName])?.[choiceName];
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
const Background = styled.div`
|
|
26
|
-
background-color: rgba(0, 0, 0, 0.01);
|
|
27
|
-
font-family: ${designTokens.fontFamily};
|
|
28
|
-
color: ${designTokens.colorSolid}
|
|
29
|
-
margin: 10px;
|
|
30
|
-
> * + * {
|
|
31
|
-
margin: 16px 0 0 0;
|
|
32
|
-
}
|
|
33
|
-
`;
|
|
34
|
-
|
|
35
|
-
const DetailsGroupsContainer = styled.main`
|
|
36
|
-
display: flex;
|
|
37
|
-
flex-direction: column;
|
|
38
|
-
gap: 40px;
|
|
39
|
-
`;
|
|
40
|
-
|
|
41
|
-
const BasicCellRenderer = (cellData) => {
|
|
42
|
-
if (cellData.columnKey !== 'description') {
|
|
43
|
-
return <TokenBodyCell tokenName={cellData.tokenName} />;
|
|
44
|
-
} else {
|
|
45
|
-
return cellData.tokenData.description;
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
function Story() {
|
|
50
|
-
const [filterText, setFilterText] = useState('');
|
|
51
|
-
const { theme } = useTheme();
|
|
52
|
-
const currentThemeChoices = useMemo(() => {
|
|
53
|
-
return merge(
|
|
54
|
-
{},
|
|
55
|
-
definition.choiceGroupsByTheme.default,
|
|
56
|
-
definition.choiceGroupsByTheme[theme]
|
|
57
|
-
);
|
|
58
|
-
}, [theme]);
|
|
59
|
-
const currentThemeDecisions = useMemo(
|
|
60
|
-
() =>
|
|
61
|
-
merge(
|
|
62
|
-
{},
|
|
63
|
-
definition.decisionGroupsByTheme.default,
|
|
64
|
-
definition.decisionGroupsByTheme[theme]
|
|
65
|
-
),
|
|
66
|
-
[theme]
|
|
67
|
-
);
|
|
68
|
-
|
|
69
|
-
const searchTextChangeHandler = useCallback((event) => {
|
|
70
|
-
setFilterText(event.target.value);
|
|
71
|
-
}, []);
|
|
72
|
-
|
|
73
|
-
return (
|
|
74
|
-
<Background>
|
|
75
|
-
<header>
|
|
76
|
-
<TextInput
|
|
77
|
-
value={filterText}
|
|
78
|
-
onChange={searchTextChangeHandler}
|
|
79
|
-
horizontalConstraint={13}
|
|
80
|
-
/>
|
|
81
|
-
<h2>Table of Contents</h2>
|
|
82
|
-
<ul>
|
|
83
|
-
<li>
|
|
84
|
-
<TokenGroupLinks
|
|
85
|
-
id="choices"
|
|
86
|
-
config={currentThemeChoices}
|
|
87
|
-
filterText={filterText}
|
|
88
|
-
>
|
|
89
|
-
Choices
|
|
90
|
-
</TokenGroupLinks>
|
|
91
|
-
</li>
|
|
92
|
-
<li>
|
|
93
|
-
<TokenGroupLinks id="states">States</TokenGroupLinks>
|
|
94
|
-
</li>
|
|
95
|
-
<li>
|
|
96
|
-
<TokenGroupLinks id="component-groups">
|
|
97
|
-
Component Groups
|
|
98
|
-
</TokenGroupLinks>
|
|
99
|
-
</li>
|
|
100
|
-
<li>
|
|
101
|
-
<TokenGroupLinks id="variants">Variants</TokenGroupLinks>
|
|
102
|
-
</li>
|
|
103
|
-
<li>
|
|
104
|
-
<TokenGroupLinks
|
|
105
|
-
id="decisions"
|
|
106
|
-
config={currentThemeDecisions}
|
|
107
|
-
filterText={filterText}
|
|
108
|
-
>
|
|
109
|
-
Decisions
|
|
110
|
-
</TokenGroupLinks>
|
|
111
|
-
</li>
|
|
112
|
-
</ul>
|
|
113
|
-
</header>
|
|
114
|
-
|
|
115
|
-
<DetailsGroupsContainer>
|
|
116
|
-
<MultiTokensGroupDetails
|
|
117
|
-
id="choices"
|
|
118
|
-
subtitle="This is the palette of values you may chose from when creating design tokens."
|
|
119
|
-
themeName={theme}
|
|
120
|
-
filterText={filterText}
|
|
121
|
-
columnsConfig={[{ key: 'token' }, { key: 'value' }]}
|
|
122
|
-
cellRenderer={(data) => {
|
|
123
|
-
if (data.columnKey === 'token') {
|
|
124
|
-
return <Token>{data.tokenName}</Token>;
|
|
125
|
-
} else {
|
|
126
|
-
const ChoiceSample = getSampleComponent(data.groupItemsPrefix);
|
|
127
|
-
return (
|
|
128
|
-
<>
|
|
129
|
-
<ChoiceSample value={data.tokenData} />
|
|
130
|
-
{data.tokenData}
|
|
131
|
-
</>
|
|
132
|
-
);
|
|
133
|
-
}
|
|
134
|
-
}}
|
|
135
|
-
tokensGroupData={currentThemeChoices}
|
|
136
|
-
/>
|
|
137
|
-
|
|
138
|
-
<SingleTokensGroupDetails
|
|
139
|
-
id="states"
|
|
140
|
-
columnsConfig={[{ key: 'state' }, { key: 'description' }]}
|
|
141
|
-
cellRenderer={BasicCellRenderer}
|
|
142
|
-
groupItems={definition.states}
|
|
143
|
-
themeName={theme}
|
|
144
|
-
filterText={filterText}
|
|
145
|
-
/>
|
|
146
|
-
|
|
147
|
-
<SingleTokensGroupDetails
|
|
148
|
-
id="component-groups"
|
|
149
|
-
title="Component Groups"
|
|
150
|
-
columnsConfig={[
|
|
151
|
-
{ key: 'component-group', label: 'Component Group' },
|
|
152
|
-
{ key: 'description' },
|
|
153
|
-
]}
|
|
154
|
-
cellRenderer={BasicCellRenderer}
|
|
155
|
-
groupItems={definition.componentGroups}
|
|
156
|
-
themeName={theme}
|
|
157
|
-
filterText={filterText}
|
|
158
|
-
/>
|
|
159
|
-
|
|
160
|
-
<SingleTokensGroupDetails
|
|
161
|
-
id="variants"
|
|
162
|
-
columnsConfig={[{ key: 'variant' }, { key: 'description' }]}
|
|
163
|
-
cellRenderer={BasicCellRenderer}
|
|
164
|
-
groupItems={definition.variants}
|
|
165
|
-
themeName={theme}
|
|
166
|
-
filterText={filterText}
|
|
167
|
-
/>
|
|
168
|
-
|
|
169
|
-
<MultiTokensGroupDetails
|
|
170
|
-
id="decisions"
|
|
171
|
-
subtitle="These are specific decisions where a choice gets applied to an element (optionally in a certain state)."
|
|
172
|
-
themeName={theme}
|
|
173
|
-
filterText={filterText}
|
|
174
|
-
columnsConfig={[
|
|
175
|
-
{ key: 'token' },
|
|
176
|
-
{ key: 'choice' },
|
|
177
|
-
{ key: 'value' },
|
|
178
|
-
]}
|
|
179
|
-
cellRenderer={(data) => {
|
|
180
|
-
switch (data.columnKey) {
|
|
181
|
-
case 'token':
|
|
182
|
-
return <Token>{data.tokenName}</Token>;
|
|
183
|
-
case 'choice':
|
|
184
|
-
return <Token>{data.tokenData.choice}</Token>;
|
|
185
|
-
case 'value':
|
|
186
|
-
const ChoiceSample = getSampleComponent(data.groupItemsPrefix);
|
|
187
|
-
const choiceValue = findChoiceValue(
|
|
188
|
-
currentThemeChoices,
|
|
189
|
-
data.tokenData.choice
|
|
190
|
-
);
|
|
191
|
-
if (choiceValue) {
|
|
192
|
-
return (
|
|
193
|
-
<>
|
|
194
|
-
<ChoiceSample value={choiceValue} />
|
|
195
|
-
{choiceValue}
|
|
196
|
-
</>
|
|
197
|
-
);
|
|
198
|
-
} else {
|
|
199
|
-
return <Token>---</Token>;
|
|
200
|
-
}
|
|
201
|
-
default:
|
|
202
|
-
return null;
|
|
203
|
-
}
|
|
204
|
-
}}
|
|
205
|
-
tokensGroupData={currentThemeDecisions}
|
|
206
|
-
/>
|
|
207
|
-
</DetailsGroupsContainer>
|
|
208
|
-
</Background>
|
|
209
|
-
);
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
storiesOf('Basics|Tokens', module)
|
|
213
|
-
.addParameters({
|
|
214
|
-
readme: {
|
|
215
|
-
// Show readme at the addons panel
|
|
216
|
-
sidebar: Readme,
|
|
217
|
-
},
|
|
218
|
-
})
|
|
219
|
-
.add('All Tokens', () => <Story />);
|