lnked/react-starter

View on GitHub
src/components/button/index.tsx

Summary

Maintainability
B
6 hrs
Test Coverage
import * as React from 'react'
import * as css from './styles.scss'

import { Classes } from 'helpers'

export type P = {
  type?: string;
  size?: 'small' | 'normal' | 'large';
  label?: string;
  icon?: boolean;
  info?: boolean;
  danger?: boolean;
  normal?: boolean;
  success?: boolean;
  primary?: boolean;
  warning?: boolean;
  circle?: boolean;
  loading?: boolean;
  disabled?: boolean;
  className?: string;
  children?: JSX.Element[] | JSX.Element | string;
  handleClick?: () => void | boolean;
}

const cx = Classes.bind(css)

export default function Button ({ type, size = 'small', circle, label, loading, children, handleClick, ...rest }: P) {
  const {
    info,
    danger,
    normal,
    success,
    primary,
    warning,
  } = rest

  return (
    <button
      type={type}
      onClick={handleClick}
      className={cx(css.button, {
        info,
        normal,
        circle,
        danger,
        success,
        primary,
        warning,
        loading,
      },
      [ `size-${size}` ])}>
      {label || children}
    </button>
  )
}