@cerberus-design/react
Version:
The Cerberus Design React component library.
1 lines • 2.1 kB
Source Map (JSON)
{"version":3,"sources":["../../../../src/components/text/index.ts","../../../../src/components/text/text.tsx"],"sourcesContent":["export * from './text'\n","import {\n Em,\n H1,\n H2,\n H3,\n H4,\n H5,\n H6,\n P,\n Small,\n Span,\n Strong,\n type PProps,\n} from 'styled-system/jsx'\n\n/**\n * This module exports a component for rendering text utilizing the styled-system JSX utility.\n * @module @cerberus/react/Text\n */\n\nexport type Headings = 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6'\nexport type TextElements = 'p' | 'strong' | 'em' | 'small' | 'span'\n\n// For some reason we have to use the HTMLParagraphElement type here\n// or else TS will fail for non-style props like 'id' or 'className'\nexport interface TextProps extends PProps {\n /**\n * The element to render as. Defaults to 'p'.\n */\n as?: TextElements | Headings\n}\n\n/**\n * A component for rendering text utilizing the styled-system JSX utility.\n * @definition [Text docs](https://cerberus.digitalu.design/react/text)\n * @example\n * ```tsx\n * <Text as=\"h1\" color=\"page.text.100\" textStyle={{\n * base: 'heading-md',\n * md: 'heading-lg',\n * }}>\n * Hello, world!\n * </Text>\n */\nexport function Text(props: TextProps) {\n const { as = 'p', ...pandaJSXProps } = props\n\n const cache = {\n h1: H1,\n h2: H2,\n h3: H3,\n h4: H4,\n h5: H5,\n h6: H6,\n strong: Strong,\n em: Em,\n small: Small,\n span: Span,\n p: P,\n }\n\n if (as in cache) {\n const Component = cache[as as keyof typeof cache]\n return <Component {...pandaJSXProps} />\n }\n\n return <P {...pandaJSXProps} />\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,iBAaO;AAkDI;AAnBJ,SAAS,KAAK,OAAkB;AACrC,QAAM,EAAE,KAAK,KAAK,GAAG,cAAc,IAAI;AAEvC,QAAM,QAAQ;AAAA,IACZ,IAAI;AAAA,IACJ,IAAI;AAAA,IACJ,IAAI;AAAA,IACJ,IAAI;AAAA,IACJ,IAAI;AAAA,IACJ,IAAI;AAAA,IACJ,QAAQ;AAAA,IACR,IAAI;AAAA,IACJ,OAAO;AAAA,IACP,MAAM;AAAA,IACN,GAAG;AAAA,EACL;AAEA,MAAI,MAAM,OAAO;AACf,UAAM,YAAY,MAAM,EAAwB;AAChD,WAAO,4CAAC,aAAW,GAAG,eAAe;AAAA,EACvC;AAEA,SAAO,4CAAC,gBAAG,GAAG,eAAe;AAC/B;","names":[]}