Added className prop to button comp
authorunknown <ajbura@gmail.com>
Thu, 2 Sep 2021 13:45:28 +0000 (19:15 +0530)
committerunknown <ajbura@gmail.com>
Thu, 2 Sep 2021 13:45:28 +0000 (19:15 +0530)
src/app/atoms/button/Button.jsx

index b6e4a0fb13ff9689f34e797e21f73436b2e71c3d..bfe06f66320922f009eea5144ef80032a1248955 100644 (file)
@@ -7,26 +7,29 @@ import RawIcon from '../system-icons/RawIcon';
 import { blurOnBubbling } from './script';
 
 function Button({
-  id, variant, iconSrc, type, onClick, children, disabled,
+  id, className, variant, iconSrc,
+  type, onClick, children, disabled,
 }) {
   const iconClass = (iconSrc === null) ? '' : `btn-${variant}--icon`;
   return (
     <button
       id={id === '' ? undefined : id}
-      className={`btn-${variant} ${iconClass} noselect`}
+      className={`${className ? `${className} ` : ''}btn-${variant} ${iconClass} noselect`}
       onMouseUp={(e) => blurOnBubbling(e, `.btn-${variant}`)}
       onClick={onClick}
       type={type === 'button' ? 'button' : 'submit'}
       disabled={disabled}
     >
       {iconSrc !== null && <RawIcon size="small" src={iconSrc} />}
-      <Text variant="b1">{ children }</Text>
+      {typeof children === 'string' && <Text variant="b1">{ children }</Text>}
+      {typeof children !== 'string' && children }
     </button>
   );
 }
 
 Button.defaultProps = {
   id: '',
+  className: null,
   variant: 'surface',
   iconSrc: null,
   type: 'button',
@@ -36,6 +39,7 @@ Button.defaultProps = {
 
 Button.propTypes = {
   id: PropTypes.string,
+  className: PropTypes.string,
   variant: PropTypes.oneOf(['surface', 'primary', 'caution', 'danger']),
   iconSrc: PropTypes.string,
   type: PropTypes.oneOf(['button', 'submit']),