@commercetools-uikit/design-system 15.15.0 → 15.15.1
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/dist/commercetools-uikit-design-system.cjs.d.ts +1 -0
- package/dist/commercetools-uikit-design-system.cjs.d.ts.map +1 -0
- package/dist/commercetools-uikit-design-system.cjs.dev.js +41 -45
- package/dist/commercetools-uikit-design-system.cjs.prod.js +41 -45
- package/dist/commercetools-uikit-design-system.esm.js +41 -45
- package/package.json +2 -2
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"commercetools-uikit-design-system.cjs.d.ts","sourceRoot":"","sources":["./declarations/src/index.d.ts"],"names":[],"mappings":"AAAA"}
|
|
@@ -52,7 +52,7 @@ var kebabCase__default = /*#__PURE__*/_interopDefault(kebabCase);
|
|
|
52
52
|
This file is created by the 'scripts/generate-design-tokens.js' script.
|
|
53
53
|
The variables should be updated in 'materials/internals/definition.yaml'.
|
|
54
54
|
*/
|
|
55
|
-
|
|
55
|
+
const themes = {
|
|
56
56
|
default: {
|
|
57
57
|
colorPrimary: '#00b39e',
|
|
58
58
|
colorPrimary25: 'hsl(172.9608938547486, 100%, 25%)',
|
|
@@ -838,7 +838,7 @@ var themes = {
|
|
|
838
838
|
shadowForTagWhenHovered: 'none'
|
|
839
839
|
}
|
|
840
840
|
};
|
|
841
|
-
|
|
841
|
+
const designTokens = {
|
|
842
842
|
colorPrimary: 'var(--color-primary, #00b39e)',
|
|
843
843
|
colorPrimary25: 'var(--color-primary-25, hsl(172.9608938547486, 100%, 25%))',
|
|
844
844
|
colorPrimary40: 'var(--color-primary-40, hsl(172.9608938547486, 100%, 40%))',
|
|
@@ -1340,8 +1340,8 @@ var designTokens$1 = designTokens;
|
|
|
1340
1340
|
function transformTokensToCssVarsValues(tokens) {
|
|
1341
1341
|
var _context;
|
|
1342
1342
|
|
|
1343
|
-
return _Object$fromEntries__default["default"](_mapInstanceProperty__default["default"](_context = _Object$entries__default["default"](tokens)).call(_context,
|
|
1344
|
-
|
|
1343
|
+
return _Object$fromEntries__default["default"](_mapInstanceProperty__default["default"](_context = _Object$entries__default["default"](tokens)).call(_context, _ref => {
|
|
1344
|
+
let _ref2 = _slicedToArray(_ref, 2),
|
|
1345
1345
|
key = _ref2[0],
|
|
1346
1346
|
value = _ref2[1];
|
|
1347
1347
|
|
|
@@ -1367,15 +1367,15 @@ function transformTokensToCssVarsValues(tokens) {
|
|
|
1367
1367
|
function transformTokensToCssVarsReferences(tokens) {
|
|
1368
1368
|
var _context2;
|
|
1369
1369
|
|
|
1370
|
-
|
|
1370
|
+
let _ref3 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
|
|
1371
1371
|
includeDefaultValue: true
|
|
1372
1372
|
},
|
|
1373
1373
|
includeDefaultValue = _ref3.includeDefaultValue;
|
|
1374
1374
|
|
|
1375
|
-
return _Object$fromEntries__default["default"](_mapInstanceProperty__default["default"](_context2 = _Object$entries__default["default"](tokens)).call(_context2,
|
|
1375
|
+
return _Object$fromEntries__default["default"](_mapInstanceProperty__default["default"](_context2 = _Object$entries__default["default"](tokens)).call(_context2, _ref4 => {
|
|
1376
1376
|
var _context3;
|
|
1377
1377
|
|
|
1378
|
-
|
|
1378
|
+
let _ref5 = _slicedToArray(_ref4, 2),
|
|
1379
1379
|
key = _ref5[0],
|
|
1380
1380
|
value = _ref5[1];
|
|
1381
1381
|
|
|
@@ -1387,35 +1387,33 @@ function ownKeys(object, enumerableOnly) { var keys = _Object$keys__default["def
|
|
|
1387
1387
|
|
|
1388
1388
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var _context2, _context3; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty__default["default"](_context2 = ownKeys(Object(source), !0)).call(_context2, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors__default["default"] ? _Object$defineProperties__default["default"](target, _Object$getOwnPropertyDescriptors__default["default"](source)) : _forEachInstanceProperty__default["default"](_context3 = ownKeys(Object(source))).call(_context3, function (key) { _Object$defineProperty__default["default"](target, key, _Object$getOwnPropertyDescriptor__default["default"](source, key)); }); } return target; }
|
|
1389
1389
|
|
|
1390
|
-
|
|
1390
|
+
const allThemesNames = _Object$keys__default["default"](themes);
|
|
1391
1391
|
|
|
1392
1392
|
// used to cover SSR builds (for instance in Gatsby)
|
|
1393
|
-
|
|
1393
|
+
const isBrowser = typeof window !== 'undefined';
|
|
1394
1394
|
|
|
1395
|
-
|
|
1396
|
-
return isBrowser ? document.querySelector(':root') : null;
|
|
1397
|
-
};
|
|
1395
|
+
const defaultParentSelector = () => isBrowser ? document.querySelector(':root') : null;
|
|
1398
1396
|
|
|
1399
|
-
|
|
1397
|
+
const applyTheme = _ref => {
|
|
1400
1398
|
var _context;
|
|
1401
1399
|
|
|
1402
|
-
|
|
1400
|
+
let newTheme = _ref.newTheme,
|
|
1403
1401
|
_ref$parentSelector = _ref.parentSelector,
|
|
1404
1402
|
parentSelector = _ref$parentSelector === void 0 ? defaultParentSelector : _ref$parentSelector,
|
|
1405
1403
|
themeOverrides = _ref.themeOverrides;
|
|
1406
|
-
|
|
1404
|
+
const target = parentSelector(); // With no target we can't change themes
|
|
1407
1405
|
|
|
1408
1406
|
if (!target) return;
|
|
1409
|
-
|
|
1407
|
+
const validTheme = _includesInstanceProperty__default["default"](allThemesNames).call(allThemesNames, newTheme || '') ? newTheme : 'default';
|
|
1410
1408
|
|
|
1411
1409
|
if (newTheme && newTheme !== validTheme) {
|
|
1412
1410
|
console.warn("ThemeProvider: the specified theme '".concat(newTheme, "' is not supported."));
|
|
1413
1411
|
}
|
|
1414
1412
|
|
|
1415
|
-
|
|
1413
|
+
const vars = transformTokensToCssVarsValues(merge__default["default"]({}, themes.default, themes[validTheme], isObject__default["default"](themeOverrides) ? themeOverrides : {}));
|
|
1416
1414
|
|
|
1417
|
-
_forEachInstanceProperty__default["default"](_context = _Object$entries__default["default"](vars)).call(_context,
|
|
1418
|
-
|
|
1415
|
+
_forEachInstanceProperty__default["default"](_context = _Object$entries__default["default"](vars)).call(_context, _ref2 => {
|
|
1416
|
+
let _ref3 = _slicedToArray(_ref2, 2),
|
|
1419
1417
|
key = _ref3[0],
|
|
1420
1418
|
value = _ref3[1];
|
|
1421
1419
|
|
|
@@ -1425,11 +1423,11 @@ var applyTheme = function applyTheme(_ref) {
|
|
|
1425
1423
|
target.setAttribute('data-theme', validTheme);
|
|
1426
1424
|
};
|
|
1427
1425
|
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
react.useLayoutEffect(
|
|
1426
|
+
const ThemeProvider = props => {
|
|
1427
|
+
const parentSelectorRef = react.useRef(props.parentSelector);
|
|
1428
|
+
const themeNameRef = react.useRef();
|
|
1429
|
+
const themeOverridesRef = react.useRef();
|
|
1430
|
+
react.useLayoutEffect(() => {
|
|
1433
1431
|
// We want to make sure we don't really apply the change when the props
|
|
1434
1432
|
// provided include a new object with the same theme overrides
|
|
1435
1433
|
// (eg: users providing an inline object as prop to the ThemeProvider)
|
|
@@ -1456,20 +1454,20 @@ ThemeProvider.defaultProps = {
|
|
|
1456
1454
|
theme: 'default'
|
|
1457
1455
|
};
|
|
1458
1456
|
|
|
1459
|
-
|
|
1460
|
-
|
|
1457
|
+
const useTheme = function () {
|
|
1458
|
+
let parentSelector = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : defaultParentSelector;
|
|
1461
1459
|
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1460
|
+
const _useState = react.useState('default'),
|
|
1461
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
1462
|
+
theme = _useState2[0],
|
|
1463
|
+
setTheme = _useState2[1];
|
|
1466
1464
|
|
|
1467
|
-
|
|
1468
|
-
|
|
1465
|
+
const parentSelectorRef = react.useRef(parentSelector);
|
|
1466
|
+
const mutationChangeCallback = react.useCallback(mutationList => {
|
|
1469
1467
|
// We expect only a single element in the mutation list as we configured the
|
|
1470
1468
|
// observer to only listen to `data-theme` changes.
|
|
1471
|
-
|
|
1472
|
-
|
|
1469
|
+
const _mutationList = _slicedToArray(mutationList, 1),
|
|
1470
|
+
mutationEvent = _mutationList[0];
|
|
1473
1471
|
|
|
1474
1472
|
setTheme(mutationEvent.target.dataset.theme);
|
|
1475
1473
|
}, []);
|
|
@@ -1478,41 +1476,39 @@ var useTheme = function useTheme() {
|
|
|
1478
1476
|
attributeFilter: ['data-theme']
|
|
1479
1477
|
});
|
|
1480
1478
|
|
|
1481
|
-
|
|
1482
|
-
return theme === 'default' ? defaultThemeValue : newThemeValue;
|
|
1483
|
-
}; // If we use 'useLayoutEffect' here, we would be trying to read the
|
|
1479
|
+
const themedValue = (defaultThemeValue, newThemeValue) => theme === 'default' ? defaultThemeValue : newThemeValue; // If we use 'useLayoutEffect' here, we would be trying to read the
|
|
1484
1480
|
// data attribute before it gets set from the effect in the ThemeProvider
|
|
1485
1481
|
|
|
1486
1482
|
|
|
1487
|
-
react.useEffect(
|
|
1483
|
+
react.useEffect(() => {
|
|
1488
1484
|
var _parentSelectorRef$cu;
|
|
1489
1485
|
|
|
1490
1486
|
// We need to read the current theme after the provider is rendered
|
|
1491
1487
|
// to have the actual selected theme (calculated client-side) in the
|
|
1492
1488
|
// hook local state
|
|
1493
|
-
|
|
1489
|
+
const nextTheme = (_parentSelectorRef$cu = parentSelectorRef.current()) === null || _parentSelectorRef$cu === void 0 ? void 0 : _parentSelectorRef$cu.dataset.theme;
|
|
1494
1490
|
|
|
1495
1491
|
if (nextTheme) {
|
|
1496
1492
|
setTheme(nextTheme);
|
|
1497
1493
|
}
|
|
1498
1494
|
}, []);
|
|
1499
1495
|
return {
|
|
1500
|
-
theme
|
|
1501
|
-
themedValue
|
|
1496
|
+
theme,
|
|
1497
|
+
themedValue,
|
|
1502
1498
|
isNewTheme: theme === 'test'
|
|
1503
1499
|
};
|
|
1504
1500
|
};
|
|
1505
1501
|
|
|
1506
|
-
|
|
1502
|
+
const withThemeContext = WrappedComponent => {
|
|
1507
1503
|
// eslint-disable-next-line react/display-name
|
|
1508
|
-
return
|
|
1509
|
-
|
|
1504
|
+
return props => {
|
|
1505
|
+
const themeUtilties = useTheme();
|
|
1510
1506
|
return jsxRuntime.jsx(WrappedComponent, _objectSpread(_objectSpread({}, props), themeUtilties));
|
|
1511
1507
|
};
|
|
1512
1508
|
};
|
|
1513
1509
|
|
|
1514
1510
|
// NOTE: This string will be replaced on build time with the package version.
|
|
1515
|
-
var version = "15.15.
|
|
1511
|
+
var version = "15.15.1";
|
|
1516
1512
|
|
|
1517
1513
|
exports.ThemeProvider = ThemeProvider;
|
|
1518
1514
|
exports.customProperties = designTokens$1;
|
|
@@ -52,7 +52,7 @@ var kebabCase__default = /*#__PURE__*/_interopDefault(kebabCase);
|
|
|
52
52
|
This file is created by the 'scripts/generate-design-tokens.js' script.
|
|
53
53
|
The variables should be updated in 'materials/internals/definition.yaml'.
|
|
54
54
|
*/
|
|
55
|
-
|
|
55
|
+
const themes = {
|
|
56
56
|
default: {
|
|
57
57
|
colorPrimary: '#00b39e',
|
|
58
58
|
colorPrimary25: 'hsl(172.9608938547486, 100%, 25%)',
|
|
@@ -838,7 +838,7 @@ var themes = {
|
|
|
838
838
|
shadowForTagWhenHovered: 'none'
|
|
839
839
|
}
|
|
840
840
|
};
|
|
841
|
-
|
|
841
|
+
const designTokens = {
|
|
842
842
|
colorPrimary: 'var(--color-primary, #00b39e)',
|
|
843
843
|
colorPrimary25: 'var(--color-primary-25, hsl(172.9608938547486, 100%, 25%))',
|
|
844
844
|
colorPrimary40: 'var(--color-primary-40, hsl(172.9608938547486, 100%, 40%))',
|
|
@@ -1340,8 +1340,8 @@ var designTokens$1 = designTokens;
|
|
|
1340
1340
|
function transformTokensToCssVarsValues(tokens) {
|
|
1341
1341
|
var _context;
|
|
1342
1342
|
|
|
1343
|
-
return _Object$fromEntries__default["default"](_mapInstanceProperty__default["default"](_context = _Object$entries__default["default"](tokens)).call(_context,
|
|
1344
|
-
|
|
1343
|
+
return _Object$fromEntries__default["default"](_mapInstanceProperty__default["default"](_context = _Object$entries__default["default"](tokens)).call(_context, _ref => {
|
|
1344
|
+
let _ref2 = _slicedToArray(_ref, 2),
|
|
1345
1345
|
key = _ref2[0],
|
|
1346
1346
|
value = _ref2[1];
|
|
1347
1347
|
|
|
@@ -1367,15 +1367,15 @@ function transformTokensToCssVarsValues(tokens) {
|
|
|
1367
1367
|
function transformTokensToCssVarsReferences(tokens) {
|
|
1368
1368
|
var _context2;
|
|
1369
1369
|
|
|
1370
|
-
|
|
1370
|
+
let _ref3 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
|
|
1371
1371
|
includeDefaultValue: true
|
|
1372
1372
|
},
|
|
1373
1373
|
includeDefaultValue = _ref3.includeDefaultValue;
|
|
1374
1374
|
|
|
1375
|
-
return _Object$fromEntries__default["default"](_mapInstanceProperty__default["default"](_context2 = _Object$entries__default["default"](tokens)).call(_context2,
|
|
1375
|
+
return _Object$fromEntries__default["default"](_mapInstanceProperty__default["default"](_context2 = _Object$entries__default["default"](tokens)).call(_context2, _ref4 => {
|
|
1376
1376
|
var _context3;
|
|
1377
1377
|
|
|
1378
|
-
|
|
1378
|
+
let _ref5 = _slicedToArray(_ref4, 2),
|
|
1379
1379
|
key = _ref5[0],
|
|
1380
1380
|
value = _ref5[1];
|
|
1381
1381
|
|
|
@@ -1387,35 +1387,33 @@ function ownKeys(object, enumerableOnly) { var keys = _Object$keys__default["def
|
|
|
1387
1387
|
|
|
1388
1388
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var _context2, _context3; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty__default["default"](_context2 = ownKeys(Object(source), !0)).call(_context2, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors__default["default"] ? _Object$defineProperties__default["default"](target, _Object$getOwnPropertyDescriptors__default["default"](source)) : _forEachInstanceProperty__default["default"](_context3 = ownKeys(Object(source))).call(_context3, function (key) { _Object$defineProperty__default["default"](target, key, _Object$getOwnPropertyDescriptor__default["default"](source, key)); }); } return target; }
|
|
1389
1389
|
|
|
1390
|
-
|
|
1390
|
+
const allThemesNames = _Object$keys__default["default"](themes);
|
|
1391
1391
|
|
|
1392
1392
|
// used to cover SSR builds (for instance in Gatsby)
|
|
1393
|
-
|
|
1393
|
+
const isBrowser = typeof window !== 'undefined';
|
|
1394
1394
|
|
|
1395
|
-
|
|
1396
|
-
return isBrowser ? document.querySelector(':root') : null;
|
|
1397
|
-
};
|
|
1395
|
+
const defaultParentSelector = () => isBrowser ? document.querySelector(':root') : null;
|
|
1398
1396
|
|
|
1399
|
-
|
|
1397
|
+
const applyTheme = _ref => {
|
|
1400
1398
|
var _context;
|
|
1401
1399
|
|
|
1402
|
-
|
|
1400
|
+
let newTheme = _ref.newTheme,
|
|
1403
1401
|
_ref$parentSelector = _ref.parentSelector,
|
|
1404
1402
|
parentSelector = _ref$parentSelector === void 0 ? defaultParentSelector : _ref$parentSelector,
|
|
1405
1403
|
themeOverrides = _ref.themeOverrides;
|
|
1406
|
-
|
|
1404
|
+
const target = parentSelector(); // With no target we can't change themes
|
|
1407
1405
|
|
|
1408
1406
|
if (!target) return;
|
|
1409
|
-
|
|
1407
|
+
const validTheme = _includesInstanceProperty__default["default"](allThemesNames).call(allThemesNames, newTheme || '') ? newTheme : 'default';
|
|
1410
1408
|
|
|
1411
1409
|
if (newTheme && newTheme !== validTheme) {
|
|
1412
1410
|
console.warn("ThemeProvider: the specified theme '".concat(newTheme, "' is not supported."));
|
|
1413
1411
|
}
|
|
1414
1412
|
|
|
1415
|
-
|
|
1413
|
+
const vars = transformTokensToCssVarsValues(merge__default["default"]({}, themes.default, themes[validTheme], isObject__default["default"](themeOverrides) ? themeOverrides : {}));
|
|
1416
1414
|
|
|
1417
|
-
_forEachInstanceProperty__default["default"](_context = _Object$entries__default["default"](vars)).call(_context,
|
|
1418
|
-
|
|
1415
|
+
_forEachInstanceProperty__default["default"](_context = _Object$entries__default["default"](vars)).call(_context, _ref2 => {
|
|
1416
|
+
let _ref3 = _slicedToArray(_ref2, 2),
|
|
1419
1417
|
key = _ref3[0],
|
|
1420
1418
|
value = _ref3[1];
|
|
1421
1419
|
|
|
@@ -1425,11 +1423,11 @@ var applyTheme = function applyTheme(_ref) {
|
|
|
1425
1423
|
target.setAttribute('data-theme', validTheme);
|
|
1426
1424
|
};
|
|
1427
1425
|
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
react.useLayoutEffect(
|
|
1426
|
+
const ThemeProvider = props => {
|
|
1427
|
+
const parentSelectorRef = react.useRef(props.parentSelector);
|
|
1428
|
+
const themeNameRef = react.useRef();
|
|
1429
|
+
const themeOverridesRef = react.useRef();
|
|
1430
|
+
react.useLayoutEffect(() => {
|
|
1433
1431
|
// We want to make sure we don't really apply the change when the props
|
|
1434
1432
|
// provided include a new object with the same theme overrides
|
|
1435
1433
|
// (eg: users providing an inline object as prop to the ThemeProvider)
|
|
@@ -1456,20 +1454,20 @@ ThemeProvider.defaultProps = {
|
|
|
1456
1454
|
theme: 'default'
|
|
1457
1455
|
};
|
|
1458
1456
|
|
|
1459
|
-
|
|
1460
|
-
|
|
1457
|
+
const useTheme = function () {
|
|
1458
|
+
let parentSelector = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : defaultParentSelector;
|
|
1461
1459
|
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1460
|
+
const _useState = react.useState('default'),
|
|
1461
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
1462
|
+
theme = _useState2[0],
|
|
1463
|
+
setTheme = _useState2[1];
|
|
1466
1464
|
|
|
1467
|
-
|
|
1468
|
-
|
|
1465
|
+
const parentSelectorRef = react.useRef(parentSelector);
|
|
1466
|
+
const mutationChangeCallback = react.useCallback(mutationList => {
|
|
1469
1467
|
// We expect only a single element in the mutation list as we configured the
|
|
1470
1468
|
// observer to only listen to `data-theme` changes.
|
|
1471
|
-
|
|
1472
|
-
|
|
1469
|
+
const _mutationList = _slicedToArray(mutationList, 1),
|
|
1470
|
+
mutationEvent = _mutationList[0];
|
|
1473
1471
|
|
|
1474
1472
|
setTheme(mutationEvent.target.dataset.theme);
|
|
1475
1473
|
}, []);
|
|
@@ -1478,41 +1476,39 @@ var useTheme = function useTheme() {
|
|
|
1478
1476
|
attributeFilter: ['data-theme']
|
|
1479
1477
|
});
|
|
1480
1478
|
|
|
1481
|
-
|
|
1482
|
-
return theme === 'default' ? defaultThemeValue : newThemeValue;
|
|
1483
|
-
}; // If we use 'useLayoutEffect' here, we would be trying to read the
|
|
1479
|
+
const themedValue = (defaultThemeValue, newThemeValue) => theme === 'default' ? defaultThemeValue : newThemeValue; // If we use 'useLayoutEffect' here, we would be trying to read the
|
|
1484
1480
|
// data attribute before it gets set from the effect in the ThemeProvider
|
|
1485
1481
|
|
|
1486
1482
|
|
|
1487
|
-
react.useEffect(
|
|
1483
|
+
react.useEffect(() => {
|
|
1488
1484
|
var _parentSelectorRef$cu;
|
|
1489
1485
|
|
|
1490
1486
|
// We need to read the current theme after the provider is rendered
|
|
1491
1487
|
// to have the actual selected theme (calculated client-side) in the
|
|
1492
1488
|
// hook local state
|
|
1493
|
-
|
|
1489
|
+
const nextTheme = (_parentSelectorRef$cu = parentSelectorRef.current()) === null || _parentSelectorRef$cu === void 0 ? void 0 : _parentSelectorRef$cu.dataset.theme;
|
|
1494
1490
|
|
|
1495
1491
|
if (nextTheme) {
|
|
1496
1492
|
setTheme(nextTheme);
|
|
1497
1493
|
}
|
|
1498
1494
|
}, []);
|
|
1499
1495
|
return {
|
|
1500
|
-
theme
|
|
1501
|
-
themedValue
|
|
1496
|
+
theme,
|
|
1497
|
+
themedValue,
|
|
1502
1498
|
isNewTheme: theme === 'test'
|
|
1503
1499
|
};
|
|
1504
1500
|
};
|
|
1505
1501
|
|
|
1506
|
-
|
|
1502
|
+
const withThemeContext = WrappedComponent => {
|
|
1507
1503
|
// eslint-disable-next-line react/display-name
|
|
1508
|
-
return
|
|
1509
|
-
|
|
1504
|
+
return props => {
|
|
1505
|
+
const themeUtilties = useTheme();
|
|
1510
1506
|
return jsxRuntime.jsx(WrappedComponent, _objectSpread(_objectSpread({}, props), themeUtilties));
|
|
1511
1507
|
};
|
|
1512
1508
|
};
|
|
1513
1509
|
|
|
1514
1510
|
// NOTE: This string will be replaced on build time with the package version.
|
|
1515
|
-
var version = "15.15.
|
|
1511
|
+
var version = "15.15.1";
|
|
1516
1512
|
|
|
1517
1513
|
exports.ThemeProvider = ThemeProvider;
|
|
1518
1514
|
exports.customProperties = designTokens$1;
|
|
@@ -27,7 +27,7 @@ import { jsx } from '@emotion/react/jsx-runtime';
|
|
|
27
27
|
This file is created by the 'scripts/generate-design-tokens.js' script.
|
|
28
28
|
The variables should be updated in 'materials/internals/definition.yaml'.
|
|
29
29
|
*/
|
|
30
|
-
|
|
30
|
+
const themes = {
|
|
31
31
|
default: {
|
|
32
32
|
colorPrimary: '#00b39e',
|
|
33
33
|
colorPrimary25: 'hsl(172.9608938547486, 100%, 25%)',
|
|
@@ -813,7 +813,7 @@ var themes = {
|
|
|
813
813
|
shadowForTagWhenHovered: 'none'
|
|
814
814
|
}
|
|
815
815
|
};
|
|
816
|
-
|
|
816
|
+
const designTokens = {
|
|
817
817
|
colorPrimary: 'var(--color-primary, #00b39e)',
|
|
818
818
|
colorPrimary25: 'var(--color-primary-25, hsl(172.9608938547486, 100%, 25%))',
|
|
819
819
|
colorPrimary40: 'var(--color-primary-40, hsl(172.9608938547486, 100%, 40%))',
|
|
@@ -1315,8 +1315,8 @@ var designTokens$1 = designTokens;
|
|
|
1315
1315
|
function transformTokensToCssVarsValues(tokens) {
|
|
1316
1316
|
var _context;
|
|
1317
1317
|
|
|
1318
|
-
return _Object$fromEntries(_mapInstanceProperty(_context = _Object$entries(tokens)).call(_context,
|
|
1319
|
-
|
|
1318
|
+
return _Object$fromEntries(_mapInstanceProperty(_context = _Object$entries(tokens)).call(_context, _ref => {
|
|
1319
|
+
let _ref2 = _slicedToArray(_ref, 2),
|
|
1320
1320
|
key = _ref2[0],
|
|
1321
1321
|
value = _ref2[1];
|
|
1322
1322
|
|
|
@@ -1342,15 +1342,15 @@ function transformTokensToCssVarsValues(tokens) {
|
|
|
1342
1342
|
function transformTokensToCssVarsReferences(tokens) {
|
|
1343
1343
|
var _context2;
|
|
1344
1344
|
|
|
1345
|
-
|
|
1345
|
+
let _ref3 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
|
|
1346
1346
|
includeDefaultValue: true
|
|
1347
1347
|
},
|
|
1348
1348
|
includeDefaultValue = _ref3.includeDefaultValue;
|
|
1349
1349
|
|
|
1350
|
-
return _Object$fromEntries(_mapInstanceProperty(_context2 = _Object$entries(tokens)).call(_context2,
|
|
1350
|
+
return _Object$fromEntries(_mapInstanceProperty(_context2 = _Object$entries(tokens)).call(_context2, _ref4 => {
|
|
1351
1351
|
var _context3;
|
|
1352
1352
|
|
|
1353
|
-
|
|
1353
|
+
let _ref5 = _slicedToArray(_ref4, 2),
|
|
1354
1354
|
key = _ref5[0],
|
|
1355
1355
|
value = _ref5[1];
|
|
1356
1356
|
|
|
@@ -1362,35 +1362,33 @@ function ownKeys(object, enumerableOnly) { var keys = _Object$keys(object); if (
|
|
|
1362
1362
|
|
|
1363
1363
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var _context2, _context3; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty(_context2 = ownKeys(Object(source), !0)).call(_context2, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)) : _forEachInstanceProperty(_context3 = ownKeys(Object(source))).call(_context3, function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
1364
1364
|
|
|
1365
|
-
|
|
1365
|
+
const allThemesNames = _Object$keys(themes);
|
|
1366
1366
|
|
|
1367
1367
|
// used to cover SSR builds (for instance in Gatsby)
|
|
1368
|
-
|
|
1368
|
+
const isBrowser = typeof window !== 'undefined';
|
|
1369
1369
|
|
|
1370
|
-
|
|
1371
|
-
return isBrowser ? document.querySelector(':root') : null;
|
|
1372
|
-
};
|
|
1370
|
+
const defaultParentSelector = () => isBrowser ? document.querySelector(':root') : null;
|
|
1373
1371
|
|
|
1374
|
-
|
|
1372
|
+
const applyTheme = _ref => {
|
|
1375
1373
|
var _context;
|
|
1376
1374
|
|
|
1377
|
-
|
|
1375
|
+
let newTheme = _ref.newTheme,
|
|
1378
1376
|
_ref$parentSelector = _ref.parentSelector,
|
|
1379
1377
|
parentSelector = _ref$parentSelector === void 0 ? defaultParentSelector : _ref$parentSelector,
|
|
1380
1378
|
themeOverrides = _ref.themeOverrides;
|
|
1381
|
-
|
|
1379
|
+
const target = parentSelector(); // With no target we can't change themes
|
|
1382
1380
|
|
|
1383
1381
|
if (!target) return;
|
|
1384
|
-
|
|
1382
|
+
const validTheme = _includesInstanceProperty(allThemesNames).call(allThemesNames, newTheme || '') ? newTheme : 'default';
|
|
1385
1383
|
|
|
1386
1384
|
if (newTheme && newTheme !== validTheme) {
|
|
1387
1385
|
console.warn("ThemeProvider: the specified theme '".concat(newTheme, "' is not supported."));
|
|
1388
1386
|
}
|
|
1389
1387
|
|
|
1390
|
-
|
|
1388
|
+
const vars = transformTokensToCssVarsValues(merge({}, themes.default, themes[validTheme], isObject(themeOverrides) ? themeOverrides : {}));
|
|
1391
1389
|
|
|
1392
|
-
_forEachInstanceProperty(_context = _Object$entries(vars)).call(_context,
|
|
1393
|
-
|
|
1390
|
+
_forEachInstanceProperty(_context = _Object$entries(vars)).call(_context, _ref2 => {
|
|
1391
|
+
let _ref3 = _slicedToArray(_ref2, 2),
|
|
1394
1392
|
key = _ref3[0],
|
|
1395
1393
|
value = _ref3[1];
|
|
1396
1394
|
|
|
@@ -1400,11 +1398,11 @@ var applyTheme = function applyTheme(_ref) {
|
|
|
1400
1398
|
target.setAttribute('data-theme', validTheme);
|
|
1401
1399
|
};
|
|
1402
1400
|
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
useLayoutEffect(
|
|
1401
|
+
const ThemeProvider = props => {
|
|
1402
|
+
const parentSelectorRef = useRef(props.parentSelector);
|
|
1403
|
+
const themeNameRef = useRef();
|
|
1404
|
+
const themeOverridesRef = useRef();
|
|
1405
|
+
useLayoutEffect(() => {
|
|
1408
1406
|
// We want to make sure we don't really apply the change when the props
|
|
1409
1407
|
// provided include a new object with the same theme overrides
|
|
1410
1408
|
// (eg: users providing an inline object as prop to the ThemeProvider)
|
|
@@ -1431,20 +1429,20 @@ ThemeProvider.defaultProps = {
|
|
|
1431
1429
|
theme: 'default'
|
|
1432
1430
|
};
|
|
1433
1431
|
|
|
1434
|
-
|
|
1435
|
-
|
|
1432
|
+
const useTheme = function () {
|
|
1433
|
+
let parentSelector = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : defaultParentSelector;
|
|
1436
1434
|
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1435
|
+
const _useState = useState('default'),
|
|
1436
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
1437
|
+
theme = _useState2[0],
|
|
1438
|
+
setTheme = _useState2[1];
|
|
1441
1439
|
|
|
1442
|
-
|
|
1443
|
-
|
|
1440
|
+
const parentSelectorRef = useRef(parentSelector);
|
|
1441
|
+
const mutationChangeCallback = useCallback(mutationList => {
|
|
1444
1442
|
// We expect only a single element in the mutation list as we configured the
|
|
1445
1443
|
// observer to only listen to `data-theme` changes.
|
|
1446
|
-
|
|
1447
|
-
|
|
1444
|
+
const _mutationList = _slicedToArray(mutationList, 1),
|
|
1445
|
+
mutationEvent = _mutationList[0];
|
|
1448
1446
|
|
|
1449
1447
|
setTheme(mutationEvent.target.dataset.theme);
|
|
1450
1448
|
}, []);
|
|
@@ -1453,40 +1451,38 @@ var useTheme = function useTheme() {
|
|
|
1453
1451
|
attributeFilter: ['data-theme']
|
|
1454
1452
|
});
|
|
1455
1453
|
|
|
1456
|
-
|
|
1457
|
-
return theme === 'default' ? defaultThemeValue : newThemeValue;
|
|
1458
|
-
}; // If we use 'useLayoutEffect' here, we would be trying to read the
|
|
1454
|
+
const themedValue = (defaultThemeValue, newThemeValue) => theme === 'default' ? defaultThemeValue : newThemeValue; // If we use 'useLayoutEffect' here, we would be trying to read the
|
|
1459
1455
|
// data attribute before it gets set from the effect in the ThemeProvider
|
|
1460
1456
|
|
|
1461
1457
|
|
|
1462
|
-
useEffect(
|
|
1458
|
+
useEffect(() => {
|
|
1463
1459
|
var _parentSelectorRef$cu;
|
|
1464
1460
|
|
|
1465
1461
|
// We need to read the current theme after the provider is rendered
|
|
1466
1462
|
// to have the actual selected theme (calculated client-side) in the
|
|
1467
1463
|
// hook local state
|
|
1468
|
-
|
|
1464
|
+
const nextTheme = (_parentSelectorRef$cu = parentSelectorRef.current()) === null || _parentSelectorRef$cu === void 0 ? void 0 : _parentSelectorRef$cu.dataset.theme;
|
|
1469
1465
|
|
|
1470
1466
|
if (nextTheme) {
|
|
1471
1467
|
setTheme(nextTheme);
|
|
1472
1468
|
}
|
|
1473
1469
|
}, []);
|
|
1474
1470
|
return {
|
|
1475
|
-
theme
|
|
1476
|
-
themedValue
|
|
1471
|
+
theme,
|
|
1472
|
+
themedValue,
|
|
1477
1473
|
isNewTheme: theme === 'test'
|
|
1478
1474
|
};
|
|
1479
1475
|
};
|
|
1480
1476
|
|
|
1481
|
-
|
|
1477
|
+
const withThemeContext = WrappedComponent => {
|
|
1482
1478
|
// eslint-disable-next-line react/display-name
|
|
1483
|
-
return
|
|
1484
|
-
|
|
1479
|
+
return props => {
|
|
1480
|
+
const themeUtilties = useTheme();
|
|
1485
1481
|
return jsx(WrappedComponent, _objectSpread(_objectSpread({}, props), themeUtilties));
|
|
1486
1482
|
};
|
|
1487
1483
|
};
|
|
1488
1484
|
|
|
1489
1485
|
// NOTE: This string will be replaced on build time with the package version.
|
|
1490
|
-
var version = "15.15.
|
|
1486
|
+
var version = "15.15.1";
|
|
1491
1487
|
|
|
1492
1488
|
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": "15.15.
|
|
4
|
+
"version": "15.15.1",
|
|
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": "15.15.
|
|
28
|
+
"@commercetools-uikit/hooks": "15.15.1",
|
|
29
29
|
"@emotion/react": "^11.10.5",
|
|
30
30
|
"lodash": "4.17.21",
|
|
31
31
|
"prop-types": "15.8.1",
|