@commercetools-uikit/design-system 19.10.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.
@@ -22,7 +22,6 @@ var isEqual = require('lodash/isEqual');
22
22
  var hooks = require('@commercetools-uikit/hooks');
23
23
  var _Object$fromEntries = require('@babel/runtime-corejs3/core-js-stable/object/from-entries');
24
24
  var _mapInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/map');
25
- var _concatInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/concat');
26
25
  var kebabCase = require('lodash/kebabCase');
27
26
  var jsxRuntime = require('@emotion/react/jsx-runtime');
28
27
 
@@ -44,7 +43,6 @@ var merge__default = /*#__PURE__*/_interopDefault(merge);
44
43
  var isEqual__default = /*#__PURE__*/_interopDefault(isEqual);
45
44
  var _Object$fromEntries__default = /*#__PURE__*/_interopDefault(_Object$fromEntries);
46
45
  var _mapInstanceProperty__default = /*#__PURE__*/_interopDefault(_mapInstanceProperty);
47
- var _concatInstanceProperty__default = /*#__PURE__*/_interopDefault(_concatInstanceProperty);
48
46
  var kebabCase__default = /*#__PURE__*/_interopDefault(kebabCase);
49
47
 
50
48
  /*
@@ -523,7 +521,7 @@ function transformTokensToCssVarsValues(tokens) {
523
521
  let _ref2 = _slicedToArray(_ref, 2),
524
522
  key = _ref2[0],
525
523
  value = _ref2[1];
526
- return ["--".concat(kebabCase__default["default"](key)), value];
524
+ return [`--${kebabCase__default["default"](key)}`, value];
527
525
  }));
528
526
  }
529
527
 
@@ -548,11 +546,10 @@ function transformTokensToCssVarsReferences(tokens) {
548
546
  },
549
547
  includeDefaultValue = _ref3.includeDefaultValue;
550
548
  return _Object$fromEntries__default["default"](_mapInstanceProperty__default["default"](_context2 = _Object$entries__default["default"](tokens)).call(_context2, _ref4 => {
551
- var _context3;
552
549
  let _ref5 = _slicedToArray(_ref4, 2),
553
550
  key = _ref5[0],
554
551
  value = _ref5[1];
555
- return [key, _concatInstanceProperty__default["default"](_context3 = "var(--".concat(kebabCase__default["default"](key))).call(_context3, includeDefaultValue ? ', ' + value : '', ")")];
552
+ return [key, `var(--${kebabCase__default["default"](key)}${includeDefaultValue ? ', ' + value : ''})`];
556
553
  }));
557
554
  }
558
555
 
@@ -574,7 +571,7 @@ const applyTheme = _ref => {
574
571
  if (!target) return;
575
572
  const validTheme = _includesInstanceProperty__default["default"](allThemesNames).call(allThemesNames, newTheme || '') ? newTheme : 'default';
576
573
  if (newTheme && newTheme !== validTheme) {
577
- console.warn("ThemeProvider: the specified theme '".concat(newTheme, "' is not supported."));
574
+ console.warn(`ThemeProvider: the specified theme '${newTheme}' is not supported.`);
578
575
  }
579
576
  const vars = transformTokensToCssVarsValues(merge__default["default"]({}, themes.default, themes[validTheme], isObject__default["default"](themeOverrides) ? themeOverrides : {}));
580
577
  _forEachInstanceProperty__default["default"](_context = _Object$entries__default["default"](vars)).call(_context, _ref2 => {
@@ -640,11 +637,10 @@ const useTheme = function () {
640
637
  // If we use 'useLayoutEffect' here, we would be trying to read the
641
638
  // data attribute before it gets set from the effect in the ThemeProvider
642
639
  react.useEffect(() => {
643
- var _parentSelectorRef$cu;
644
640
  // We need to read the current theme after the provider is rendered
645
641
  // to have the actual selected theme (calculated client-side) in the
646
642
  // hook local state
647
- const nextTheme = (_parentSelectorRef$cu = parentSelectorRef.current()) === null || _parentSelectorRef$cu === void 0 ? void 0 : _parentSelectorRef$cu.dataset.theme;
643
+ const nextTheme = parentSelectorRef.current()?.dataset.theme;
648
644
  if (nextTheme) {
649
645
  setTheme(nextTheme);
650
646
  }
@@ -665,7 +661,7 @@ const withThemeContext = WrappedComponent => {
665
661
  };
666
662
 
667
663
  // NOTE: This string will be replaced on build time with the package version.
668
- var version = "19.10.0";
664
+ var version = "19.11.0";
669
665
 
670
666
  exports.ThemeProvider = ThemeProvider;
671
667
  exports.customProperties = designTokens$1;
@@ -22,7 +22,6 @@ var isEqual = require('lodash/isEqual');
22
22
  var hooks = require('@commercetools-uikit/hooks');
23
23
  var _Object$fromEntries = require('@babel/runtime-corejs3/core-js-stable/object/from-entries');
24
24
  var _mapInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/map');
25
- var _concatInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/concat');
26
25
  var kebabCase = require('lodash/kebabCase');
27
26
  var jsxRuntime = require('@emotion/react/jsx-runtime');
28
27
 
@@ -44,7 +43,6 @@ var merge__default = /*#__PURE__*/_interopDefault(merge);
44
43
  var isEqual__default = /*#__PURE__*/_interopDefault(isEqual);
45
44
  var _Object$fromEntries__default = /*#__PURE__*/_interopDefault(_Object$fromEntries);
46
45
  var _mapInstanceProperty__default = /*#__PURE__*/_interopDefault(_mapInstanceProperty);
47
- var _concatInstanceProperty__default = /*#__PURE__*/_interopDefault(_concatInstanceProperty);
48
46
  var kebabCase__default = /*#__PURE__*/_interopDefault(kebabCase);
49
47
 
50
48
  /*
@@ -523,7 +521,7 @@ function transformTokensToCssVarsValues(tokens) {
523
521
  let _ref2 = _slicedToArray(_ref, 2),
524
522
  key = _ref2[0],
525
523
  value = _ref2[1];
526
- return ["--".concat(kebabCase__default["default"](key)), value];
524
+ return [`--${kebabCase__default["default"](key)}`, value];
527
525
  }));
528
526
  }
529
527
 
@@ -548,11 +546,10 @@ function transformTokensToCssVarsReferences(tokens) {
548
546
  },
549
547
  includeDefaultValue = _ref3.includeDefaultValue;
550
548
  return _Object$fromEntries__default["default"](_mapInstanceProperty__default["default"](_context2 = _Object$entries__default["default"](tokens)).call(_context2, _ref4 => {
551
- var _context3;
552
549
  let _ref5 = _slicedToArray(_ref4, 2),
553
550
  key = _ref5[0],
554
551
  value = _ref5[1];
555
- return [key, _concatInstanceProperty__default["default"](_context3 = "var(--".concat(kebabCase__default["default"](key))).call(_context3, includeDefaultValue ? ', ' + value : '', ")")];
552
+ return [key, `var(--${kebabCase__default["default"](key)}${includeDefaultValue ? ', ' + value : ''})`];
556
553
  }));
557
554
  }
558
555
 
@@ -574,7 +571,7 @@ const applyTheme = _ref => {
574
571
  if (!target) return;
575
572
  const validTheme = _includesInstanceProperty__default["default"](allThemesNames).call(allThemesNames, newTheme || '') ? newTheme : 'default';
576
573
  if (newTheme && newTheme !== validTheme) {
577
- console.warn("ThemeProvider: the specified theme '".concat(newTheme, "' is not supported."));
574
+ console.warn(`ThemeProvider: the specified theme '${newTheme}' is not supported.`);
578
575
  }
579
576
  const vars = transformTokensToCssVarsValues(merge__default["default"]({}, themes.default, themes[validTheme], isObject__default["default"](themeOverrides) ? themeOverrides : {}));
580
577
  _forEachInstanceProperty__default["default"](_context = _Object$entries__default["default"](vars)).call(_context, _ref2 => {
@@ -640,11 +637,10 @@ const useTheme = function () {
640
637
  // If we use 'useLayoutEffect' here, we would be trying to read the
641
638
  // data attribute before it gets set from the effect in the ThemeProvider
642
639
  react.useEffect(() => {
643
- var _parentSelectorRef$cu;
644
640
  // We need to read the current theme after the provider is rendered
645
641
  // to have the actual selected theme (calculated client-side) in the
646
642
  // hook local state
647
- const nextTheme = (_parentSelectorRef$cu = parentSelectorRef.current()) === null || _parentSelectorRef$cu === void 0 ? void 0 : _parentSelectorRef$cu.dataset.theme;
643
+ const nextTheme = parentSelectorRef.current()?.dataset.theme;
648
644
  if (nextTheme) {
649
645
  setTheme(nextTheme);
650
646
  }
@@ -665,7 +661,7 @@ const withThemeContext = WrappedComponent => {
665
661
  };
666
662
 
667
663
  // NOTE: This string will be replaced on build time with the package version.
668
- var version = "19.10.0";
664
+ var version = "19.11.0";
669
665
 
670
666
  exports.ThemeProvider = ThemeProvider;
671
667
  exports.customProperties = designTokens$1;
@@ -18,7 +18,6 @@ import isEqual from 'lodash/isEqual';
18
18
  import { useMutationObserver } from '@commercetools-uikit/hooks';
19
19
  import _Object$fromEntries from '@babel/runtime-corejs3/core-js-stable/object/from-entries';
20
20
  import _mapInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/map';
21
- import _concatInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/concat';
22
21
  import kebabCase from 'lodash/kebabCase';
23
22
  import { jsx } from '@emotion/react/jsx-runtime';
24
23
 
@@ -498,7 +497,7 @@ function transformTokensToCssVarsValues(tokens) {
498
497
  let _ref2 = _slicedToArray(_ref, 2),
499
498
  key = _ref2[0],
500
499
  value = _ref2[1];
501
- return ["--".concat(kebabCase(key)), value];
500
+ return [`--${kebabCase(key)}`, value];
502
501
  }));
503
502
  }
504
503
 
@@ -523,11 +522,10 @@ function transformTokensToCssVarsReferences(tokens) {
523
522
  },
524
523
  includeDefaultValue = _ref3.includeDefaultValue;
525
524
  return _Object$fromEntries(_mapInstanceProperty(_context2 = _Object$entries(tokens)).call(_context2, _ref4 => {
526
- var _context3;
527
525
  let _ref5 = _slicedToArray(_ref4, 2),
528
526
  key = _ref5[0],
529
527
  value = _ref5[1];
530
- return [key, _concatInstanceProperty(_context3 = "var(--".concat(kebabCase(key))).call(_context3, includeDefaultValue ? ', ' + value : '', ")")];
528
+ return [key, `var(--${kebabCase(key)}${includeDefaultValue ? ', ' + value : ''})`];
531
529
  }));
532
530
  }
533
531
 
@@ -549,7 +547,7 @@ const applyTheme = _ref => {
549
547
  if (!target) return;
550
548
  const validTheme = _includesInstanceProperty(allThemesNames).call(allThemesNames, newTheme || '') ? newTheme : 'default';
551
549
  if (newTheme && newTheme !== validTheme) {
552
- console.warn("ThemeProvider: the specified theme '".concat(newTheme, "' is not supported."));
550
+ console.warn(`ThemeProvider: the specified theme '${newTheme}' is not supported.`);
553
551
  }
554
552
  const vars = transformTokensToCssVarsValues(merge({}, themes.default, themes[validTheme], isObject(themeOverrides) ? themeOverrides : {}));
555
553
  _forEachInstanceProperty(_context = _Object$entries(vars)).call(_context, _ref2 => {
@@ -615,11 +613,10 @@ const useTheme = function () {
615
613
  // If we use 'useLayoutEffect' here, we would be trying to read the
616
614
  // data attribute before it gets set from the effect in the ThemeProvider
617
615
  useEffect(() => {
618
- var _parentSelectorRef$cu;
619
616
  // We need to read the current theme after the provider is rendered
620
617
  // to have the actual selected theme (calculated client-side) in the
621
618
  // hook local state
622
- const nextTheme = (_parentSelectorRef$cu = parentSelectorRef.current()) === null || _parentSelectorRef$cu === void 0 ? void 0 : _parentSelectorRef$cu.dataset.theme;
619
+ const nextTheme = parentSelectorRef.current()?.dataset.theme;
623
620
  if (nextTheme) {
624
621
  setTheme(nextTheme);
625
622
  }
@@ -640,6 +637,6 @@ const withThemeContext = WrappedComponent => {
640
637
  };
641
638
 
642
639
  // NOTE: This string will be replaced on build time with the package version.
643
- var version = "19.10.0";
640
+ var version = "19.11.0";
644
641
 
645
642
  export { ThemeProvider, designTokens$1 as customProperties, designTokens$1 as designTokens, themes, transformTokensToCssVarsReferences, transformTokensToCssVarsValues, useTheme, version, withThemeContext };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@commercetools-uikit/design-system",
3
3
  "description": "Core package of the commercetools design system.",
4
- "version": "19.10.0",
4
+ "version": "19.12.0",
5
5
  "bugs": "https://github.com/commercetools/ui-kit/issues",
6
6
  "repository": {
7
7
  "type": "git",
@@ -25,7 +25,7 @@
25
25
  "dependencies": {
26
26
  "@babel/runtime": "^7.20.13",
27
27
  "@babel/runtime-corejs3": "^7.20.13",
28
- "@commercetools-uikit/hooks": "19.10.0",
28
+ "@commercetools-uikit/hooks": "19.12.0",
29
29
  "@emotion/react": "^11.10.5",
30
30
  "lodash": "4.17.21",
31
31
  "prop-types": "15.8.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
- &nbsp;{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
- &nbsp;{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 />);