Typography.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. "use client";
  2. var __rest = this && this.__rest || function (s, e) {
  3. var t = {};
  4. for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
  5. if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
  6. if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
  7. }
  8. return t;
  9. };
  10. import * as React from 'react';
  11. import classNames from 'classnames';
  12. import { composeRef } from "rc-util/es/ref";
  13. import { devUseWarning } from '../_util/warning';
  14. import { useComponentConfig } from '../config-provider/context';
  15. import useStyle from './style';
  16. const Typography = /*#__PURE__*/React.forwardRef((props, ref) => {
  17. const {
  18. prefixCls: customizePrefixCls,
  19. component: Component = 'article',
  20. className,
  21. rootClassName,
  22. setContentRef,
  23. children,
  24. direction: typographyDirection,
  25. style
  26. } = props,
  27. restProps = __rest(props, ["prefixCls", "component", "className", "rootClassName", "setContentRef", "children", "direction", "style"]);
  28. const {
  29. getPrefixCls,
  30. direction: contextDirection,
  31. className: contextClassName,
  32. style: contextStyle
  33. } = useComponentConfig('typography');
  34. const direction = typographyDirection !== null && typographyDirection !== void 0 ? typographyDirection : contextDirection;
  35. const mergedRef = setContentRef ? composeRef(ref, setContentRef) : ref;
  36. const prefixCls = getPrefixCls('typography', customizePrefixCls);
  37. if (process.env.NODE_ENV !== 'production') {
  38. const warning = devUseWarning('Typography');
  39. warning.deprecated(!setContentRef, 'setContentRef', 'ref');
  40. }
  41. // Style
  42. const [wrapCSSVar, hashId, cssVarCls] = useStyle(prefixCls);
  43. const componentClassName = classNames(prefixCls, contextClassName, {
  44. [`${prefixCls}-rtl`]: direction === 'rtl'
  45. }, className, rootClassName, hashId, cssVarCls);
  46. const mergedStyle = Object.assign(Object.assign({}, contextStyle), style);
  47. return wrapCSSVar(
  48. /*#__PURE__*/
  49. // @ts-expect-error: Expression produces a union type that is too complex to represent.
  50. React.createElement(Component, Object.assign({
  51. className: componentClassName,
  52. style: mergedStyle,
  53. ref: mergedRef
  54. }, restProps), children));
  55. });
  56. if (process.env.NODE_ENV !== 'production') {
  57. Typography.displayName = 'Typography';
  58. }
  59. export default Typography;