Theme.js 674 B

12345678910111213141516171819
  1. import warning from '../../warning';
  2. let uuid = 0;
  3. /**
  4. * Theme with algorithms to derive tokens from design tokens.
  5. * Use `createTheme` first which will help to manage the theme instance cache.
  6. */
  7. export default class Theme {
  8. constructor(derivatives) {
  9. this.derivatives = Array.isArray(derivatives) ? derivatives : [derivatives];
  10. this.id = uuid;
  11. if (derivatives.length === 0) {
  12. warning(derivatives.length > 0, '[Ant Design Vue CSS-in-JS] Theme should have at least one derivative function.');
  13. }
  14. uuid += 1;
  15. }
  16. getDerivativeToken(token) {
  17. return this.derivatives.reduce((result, derivative) => derivative(token, result), undefined);
  18. }
  19. }