genStyleUtils.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import { useContext } from 'react';
  2. import { genStyleUtils } from '@ant-design/cssinjs-utils';
  3. import { ConfigContext, defaultIconPrefixCls } from '../../config-provider/context';
  4. import { genCommonStyle, genIconStyle, genLinkStyle } from '../../style';
  5. import useLocalToken, { unitless } from '../useToken';
  6. export const {
  7. genStyleHooks,
  8. genComponentStyleHook,
  9. genSubStyleComponent
  10. } = genStyleUtils({
  11. usePrefix: () => {
  12. const {
  13. getPrefixCls,
  14. iconPrefixCls
  15. } = useContext(ConfigContext);
  16. const rootPrefixCls = getPrefixCls();
  17. return {
  18. rootPrefixCls,
  19. iconPrefixCls
  20. };
  21. },
  22. useToken: () => {
  23. const [theme, realToken, hashId, token, cssVar] = useLocalToken();
  24. return {
  25. theme,
  26. realToken,
  27. hashId,
  28. token,
  29. cssVar
  30. };
  31. },
  32. useCSP: () => {
  33. const {
  34. csp
  35. } = useContext(ConfigContext);
  36. return csp !== null && csp !== void 0 ? csp : {};
  37. },
  38. getResetStyles: (token, config) => {
  39. var _a;
  40. const linkStyle = genLinkStyle(token);
  41. return [linkStyle, {
  42. '&': linkStyle
  43. }, genIconStyle((_a = config === null || config === void 0 ? void 0 : config.prefix.iconPrefixCls) !== null && _a !== void 0 ? _a : defaultIconPrefixCls)];
  44. },
  45. getCommonStyle: genCommonStyle,
  46. getCompUnitless: () => unitless
  47. });