Source

adminjs-design-system/src/atoms/text.tsx

  1. import styled from 'styled-components'
  2. import {
  3. typography,
  4. TypographyProps,
  5. space,
  6. SpaceProps,
  7. variant,
  8. color,
  9. layout,
  10. LayoutProps,
  11. } from 'styled-system'
  12. import contentCSS from '../utils/content-styles'
  13. import { cssClass } from '../utils/css-class'
  14. import { ColorProps } from '../utils/color-props'
  15. const variants = variant({
  16. variants: {
  17. xs: {
  18. fontSize: 'xs',
  19. },
  20. sm: {
  21. fontSize: 'sm',
  22. },
  23. lg: {
  24. fontSize: 'lg',
  25. },
  26. },
  27. })
  28. /**
  29. * Prop Types of a Text component.
  30. * Apart from variant it extends all {@link ColorProps}, {@link SpaceProps} and
  31. * {@link TypographyProps}
  32. *
  33. * @memberof Text
  34. * @alias TextProps
  35. * @property {string} [...] Other props from {@link ColorProps}, {@link SpaceProps}
  36. * and {@link TypographyProps}
  37. */
  38. export type TextProps = TypographyProps & SpaceProps & ColorProps & LayoutProps & {
  39. /** Optional variant of a <Text /> component */
  40. variant?: 'xs' | 'sm' | 'lg';
  41. /** Define this if you want to render element as something other than div */
  42. as?: string;
  43. }
  44. /**
  45. * @classdesc
  46. *
  47. * <img src="components/text.png" />
  48. *
  49. * Use the Text component to control font size, weight, alignment, and color.
  50. * By default it is rendered as a `div` but you can change this to other (like `span`)
  51. * by using `as` prop,
  52. *
  53. * ### Usage
  54. *
  55. * ```javascript
  56. * import { Text, TextProps } from '@adminjs/design-system'
  57. * ```
  58. *
  59. * @component
  60. * @subcategory Atoms
  61. * @see TextProps
  62. * @see {@link https://storybook.adminjs.co/?path=/story/designsystem-atoms-text--default Storybook}
  63. * @hideconstructor
  64. * @example <caption>Lorem ipsum</caption>
  65. * return (
  66. * <Box>
  67. * <Text>
  68. * In publishing and graphic design,
  69. * Lorem ipsum is a <b>placeholder</b> text commonly used to demonstrate the
  70. * visual form of a document or a typeface without relying on meaningful
  71. * content.
  72. * </Text>
  73. * <Text mt="default" variant="sm">This text was from Wikipedia</Text>
  74. * </Box>
  75. * )
  76. * @section design-system
  77. */
  78. const Text = styled.div<TextProps>`
  79. ${contentCSS};
  80. ${typography};
  81. ${space};
  82. ${layout};
  83. ${color};
  84. ${variants};
  85. `
  86. Text.defaultProps = {
  87. className: cssClass('Text'),
  88. }
  89. export { Text }
  90. export default Text