Theme.js 1.2 KB

123456789101112131415161718192021222324252627282930313233
  1. import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
  2. import _createClass from "@babel/runtime/helpers/esm/createClass";
  3. import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
  4. import { warning } from "rc-util/es/warning";
  5. var uuid = 0;
  6. /**
  7. * Theme with algorithms to derive tokens from design tokens.
  8. * Use `createTheme` first which will help to manage the theme instance cache.
  9. */
  10. var Theme = /*#__PURE__*/function () {
  11. function Theme(derivatives) {
  12. _classCallCheck(this, Theme);
  13. _defineProperty(this, "derivatives", void 0);
  14. _defineProperty(this, "id", void 0);
  15. this.derivatives = Array.isArray(derivatives) ? derivatives : [derivatives];
  16. this.id = uuid;
  17. if (derivatives.length === 0) {
  18. warning(derivatives.length > 0, '[Ant Design CSS-in-JS] Theme should have at least one derivative function.');
  19. }
  20. uuid += 1;
  21. }
  22. _createClass(Theme, [{
  23. key: "getDerivativeToken",
  24. value: function getDerivativeToken(token) {
  25. return this.derivatives.reduce(function (result, derivative) {
  26. return derivative(token, result);
  27. }, undefined);
  28. }
  29. }]);
  30. return Theme;
  31. }();
  32. export { Theme as default };