Add disable prop in IconButton and MenuItem
authorAjay Bura <ajbura@gmail.com>
Fri, 24 Dec 2021 09:35:56 +0000 (15:05 +0530)
committerAjay Bura <ajbura@gmail.com>
Fri, 24 Dec 2021 09:35:56 +0000 (15:05 +0530)
Signed-off-by: Ajay Bura <ajbura@gmail.com>
src/app/atoms/button/IconButton.jsx
src/app/atoms/context-menu/ContextMenu.jsx
src/app/atoms/context-menu/ContextMenu.scss

index 67b8a653cc296461576a85084d84c93f0e0ae13e..061808c135ef14163f2e1a703f0ee885c4a9dacf 100644 (file)
@@ -9,7 +9,8 @@ import Text from '../text/Text';
 
 const IconButton = React.forwardRef(({
   variant, size, type,
-  tooltip, tooltipPlacement, src, onClick, tabIndex,
+  tooltip, tooltipPlacement, src,
+  onClick, tabIndex, disabled,
 }, ref) => {
   const btn = (
     <button
@@ -20,6 +21,7 @@ const IconButton = React.forwardRef(({
       // eslint-disable-next-line react/button-has-type
       type={type}
       tabIndex={tabIndex}
+      disabled={disabled}
     >
       <RawIcon size={size} src={src} />
     </button>
@@ -43,6 +45,7 @@ IconButton.defaultProps = {
   tooltipPlacement: 'top',
   onClick: null,
   tabIndex: 0,
+  disabled: false,
 };
 
 IconButton.propTypes = {
@@ -54,6 +57,7 @@ IconButton.propTypes = {
   src: PropTypes.string.isRequired,
   onClick: PropTypes.func,
   tabIndex: PropTypes.number,
+  disabled: PropTypes.bool,
 };
 
 export default IconButton;
index 3c914c342dbf872d13d60fe6e24f31969d81a3cc..99dd9e6e420ee749bea069ada6151f19274ae6e0 100644 (file)
@@ -71,7 +71,8 @@ MenuHeader.propTypes = {
 };
 
 function MenuItem({
-  variant, iconSrc, type, onClick, children,
+  variant, iconSrc, type,
+  onClick, children, disabled,
 }) {
   return (
     <div className="context-menu__item">
@@ -80,6 +81,7 @@ function MenuItem({
         iconSrc={iconSrc}
         type={type}
         onClick={onClick}
+        disabled={disabled}
       >
         { children }
       </Button>
@@ -91,6 +93,7 @@ MenuItem.defaultProps = {
   variant: 'surface',
   iconSrc: 'none',
   type: 'button',
+  disabled: false,
 };
 
 MenuItem.propTypes = {
@@ -98,7 +101,8 @@ MenuItem.propTypes = {
   iconSrc: PropTypes.string,
   type: PropTypes.oneOf(['button', 'submit']),
   onClick: PropTypes.func.isRequired,
-  children: PropTypes.string.isRequired,
+  children: PropTypes.node.isRequired,
+  disabled: PropTypes.bool,
 };
 
 function MenuBorder() {
index 50e3d91a0782245d609688d84c4ba62d117f5083..2df9f0a44dc68b6439ef033fc30800b661b24385 100644 (file)
@@ -1,3 +1,4 @@
+@use '../../partials/flex';
 @use '../../partials/text';
 @use '../../partials/dir';
 
@@ -25,7 +26,7 @@
 
 .context-menu__header {
   height: 34px;
-  padding: 0 var(--sp-tight);
+  padding: 0 var(--sp-normal);
   margin-bottom: var(--sp-ultra-tight);
   display: flex;
   align-items: center;
   }
 
   &:not(:first-child) {
-    margin-top: var(--sp-normal);
+    margin-top: var(--sp-extra-tight);
     border-top: 1px solid var(--bg-surface-border);
   }
 }
 
 .context-menu__item {
+  display: flex;
   button[class^="btn"] {
-    width: 100%;
+    @extend .cp-fx__item-one;
     justify-content: flex-start;
     border-radius: 0;
     box-shadow: none;
     white-space: nowrap;
+    padding: var(--sp-extra-tight) var(--sp-normal);
+
+    & > .ic-raw {
+      @include dir.side(margin, 0, var(--sp-tight));
+    }
 
+    // if item doesn't have icon
     .text:first-child {
       @include dir.side(
         margin,
-        calc(var(--ic-small) + var(--sp-ultra-tight)),
-        var(--sp-extra-tight)
+        calc(var(--ic-small) + var(--sp-tight)),
+        0
       );
     }
   }
   .btn-surface:focus {
     background-color: var(--bg-surface-hover);
   }
+  .btn-positive:focus {
+    background-color: var(--bg-positive-hover);
+  }
   .btn-caution:focus {
     background-color: var(--bg-caution-hover);
   }