All files / typography index.tsx

100% Statements 5/5
83.33% Branches 5/6
100% Functions 1/1
100% Lines 5/5

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56        4x                                                       4x                 3x 3x             3x            
import * as React from 'react';
import cx from 'classnames';
import { TypographyStyle, TypographyWeight } from '../types';
 
const TAG_MAP = {
  [TypographyStyle.H1]: 'h1',
  [TypographyStyle.H2]: 'h2',
  [TypographyStyle.H3]: 'h3',
  [TypographyStyle.H4]: 'h4',
  [TypographyStyle.P1]: 'span',
  [TypographyStyle.P2]: 'span',
  [TypographyStyle.LABEL1]: 'label',
  [TypographyStyle.LABEL2]: 'label',
};
 
export interface ITypography {
  /** Optional passed classname. */
  className?: string;
  /** Content specified as children. */
  children: React.ReactNode;
  /** Make text display block */
  isBlock?: boolean;
  /** Passed inline styles */
  style?: object;
  /** Custom html Tag */
  tag?: string;
  /** Type option from set types */
  type?: TypographyStyle;
  /** Specified weight of typography */
  weight?: TypographyWeight;
}
 
export const Typography: React.FC<ITypography> = ({
  isBlock = false,
  children,
  className,
  tag,
  type = TypographyStyle.P1,
  style,
  weight,
}) => {
  const ElementTag = (tag || TAG_MAP[type]) as any;
  const combinedClass = cx({
    [className || '']: !!className,
    [`panda-typography--${type}`]: true,
    [`panda-typography--weight-${weight}`]: !!weight,
    'panda-typography--display-block': isBlock,
  });
 
  return (
    <ElementTag className={combinedClass} style={style}>
      {children}
    </ElementTag>
  );
};