useVariants.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334
  1. "use strict";
  2. var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
  3. Object.defineProperty(exports, "__esModule", {
  4. value: true
  5. });
  6. exports.default = void 0;
  7. var React = _interopRequireWildcard(require("react"));
  8. var _context = require("../context");
  9. var _configProvider = require("../../config-provider");
  10. /**
  11. * Compatible for legacy `bordered` prop.
  12. */
  13. const useVariant = (component, variant, legacyBordered = undefined) => {
  14. var _a, _b;
  15. const {
  16. variant: configVariant,
  17. [component]: componentConfig
  18. } = React.useContext(_configProvider.ConfigContext);
  19. const ctxVariant = React.useContext(_context.VariantContext);
  20. const configComponentVariant = componentConfig === null || componentConfig === void 0 ? void 0 : componentConfig.variant;
  21. let mergedVariant;
  22. if (typeof variant !== 'undefined') {
  23. mergedVariant = variant;
  24. } else if (legacyBordered === false) {
  25. mergedVariant = 'borderless';
  26. } else {
  27. // form variant > component global variant > global variant
  28. mergedVariant = (_b = (_a = ctxVariant !== null && ctxVariant !== void 0 ? ctxVariant : configComponentVariant) !== null && _a !== void 0 ? _a : configVariant) !== null && _b !== void 0 ? _b : 'outlined';
  29. }
  30. const enableVariantCls = _configProvider.Variants.includes(mergedVariant);
  31. return [mergedVariant, enableVariantCls];
  32. };
  33. var _default = exports.default = useVariant;