All files / button/components buttonPlain.tsx

50% Statements 2/4
0% Branches 0/11
0% Functions 0/1
50% Lines 2/4

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 57 58 59 60 61 62 63 64                                                  2x             2x                                                              
import * as React from 'react';
import cx from 'classnames';
 
import { TypographyStyle, ThemeStyle } from '../../types';
import { Typography } from '../../typography';
import { Icon, ADD_GLYPH, IGlyph } from '../../icon';
 
/**
 * Button component without background styling.
 */
export interface IButtonPlainProps {
  /** Optional passed classnames */
  className?: string;
  /** Indicates use of default Icon */
  hasDefaultIcon?: boolean;
  /** Glyph for svg */
  icon?: IGlyph;
  /** Sizing for Glyph */
  iconSize?: { height: number; width: number };
  /** On click action for the button. */
  onClick: () => void;
  /** Theme style for button colors */
  theme?: ThemeStyle;
}
 
const PLAIN_THEME = {
  [ThemeStyle.black]: 'panda-btn-plain--theme-black',
  [ThemeStyle.blue]: 'panda-btn-plain--theme-blue',
  [ThemeStyle.red]: 'panda-btn-plain--theme-red',
  [ThemeStyle.white]: 'panda-btn-plain--theme-white',
};
 
export const ButtonPlain: React.FC<IButtonPlainProps> = ({
  className,
  children,
  hasDefaultIcon,
  icon,
  iconSize,
  onClick,
  theme = ThemeStyle.blue,
}) => {
  const combinedClass = cx({
    'panda-btn-plain': true,
    'hover-cursor': true,
    [className || '']: !!className,
    [PLAIN_THEME[theme]]: true,
  });
 
  return (
    <button className={combinedClass} onClick={onClick}>
      {icon || hasDefaultIcon ? (
        <Icon
          icon={hasDefaultIcon ? ADD_GLYPH : icon!}
          size={iconSize || { width: 15, height: 15 }}
        >
          {children}
        </Icon>
      ) : (
        <Typography type={TypographyStyle.P1}>{children}</Typography>
      )}
    </button>
  );
};