From ff75b40bbd4059cdc89c73726b0f7c28f0b75963 Mon Sep 17 00:00:00 2001
From: Orr Gottlieb <60314759+orrgottlieb@users.noreply.github.com>
Date: Tue, 25 May 2021 10:40:56 +0300
Subject: [PATCH] Fix/orr/icon ref (#131)
* update button group and icons
* fix icon ref
* remove redundent useButton Props
* remove console.log
* some lint fixes
---
package.json | 4 +-
scripts/add-forward-ref-icons.js | 44 +++++++++++++++
src/components/ButtonGroup/ButtonGroup.jsx | 53 ++++++++++++++++---
src/components/ButtonGroup/ButtonGroup.scss | 28 +++++-----
.../__stories__/buttonGroup.stories.js | 3 ++
src/components/Chips/Chips.jsx | 19 +++----
src/components/Icon/Icon.jsx | 3 +-
src/components/Icon/Icons/components/API.js | 6 +--
.../Icon/Icons/components/Activity.js | 6 +--
src/components/Icon/Icons/components/Add.js | 6 +--
.../Icon/Icons/components/AddSmall.js | 6 +--
.../Icon/Icons/components/AddUpdate.js | 6 +--
src/components/Icon/Icons/components/Alert.js | 6 +--
.../Icon/Icons/components/Announcement.js | 6 +--
.../Icon/Icons/components/Archive.js | 6 +--
.../Icon/Icons/components/Attach.js | 6 +--
.../Icon/Icons/components/BlockQuote.js | 6 +--
src/components/Icon/Icons/components/Board.js | 6 +--
src/components/Icon/Icons/components/Bold.js | 6 +--
src/components/Icon/Icons/components/Bolt.js | 6 +--
.../Icon/Icons/components/Bookmark.js | 6 +--
.../Icon/Icons/components/Broadcast.js | 6 +--
src/components/Icon/Icons/components/Broom.js | 6 +--
.../Icon/Icons/components/Bullet.js | 6 +--
.../Icon/Icons/components/Bullets.js | 6 +--
.../Icon/Icons/components/Bulllet.js | 6 +--
.../Icon/Icons/components/Calendar.js | 6 +--
src/components/Icon/Icons/components/Chart.js | 6 +--
src/components/Icon/Icons/components/Check.js | 6 +--
.../Icon/Icons/components/CheckList.js | 6 +--
.../Icon/Icons/components/Checkbox.js | 6 +--
src/components/Icon/Icons/components/Close.js | 6 +--
.../Icon/Icons/components/CloseRound.js | 6 +--
.../Icon/Icons/components/CloseSmall.js | 6 +--
src/components/Icon/Icons/components/Code.js | 6 +--
.../Icon/Icons/components/Collapse.js | 6 +--
.../Icon/Icons/components/CollapseRound.js | 6 +--
.../Icon/Icons/components/Column.js | 6 +--
.../Icon/Icons/components/Comment.js | 6 +--
.../Icon/Icons/components/CreditCard.js | 6 +--
src/components/Icon/Icons/components/Cut.js | 6 +--
.../Icon/Icons/components/Dashboard.js | 6 +--
.../Icon/Icons/components/Delete.js | 6 +--
.../Icon/Icons/components/Divider.js | 6 +--
src/components/Icon/Icons/components/Doc.js | 6 +--
.../Icon/Icons/components/DoubleCheck.js | 6 +--
.../Icon/Icons/components/Download.js | 6 +--
src/components/Icon/Icons/components/Drag.js | 6 +--
.../Icons/components/DropdownChevronDown.js | 6 +--
.../Icons/components/DropdownChevronLeft.js | 6 +--
.../Icons/components/DropdownChevronRight.js | 6 +--
.../Icons/components/DropdownChevronUp.js | 6 +--
.../Icon/Icons/components/Duplicate.js | 6 +--
src/components/Icon/Icons/components/Edit.js | 6 +--
src/components/Icon/Icons/components/Email.js | 6 +--
src/components/Icon/Icons/components/Embed.js | 6 +--
src/components/Icon/Icons/components/Emoji.js | 6 +--
src/components/Icon/Icons/components/Enter.js | 6 +--
src/components/Icon/Icons/components/Event.js | 6 +--
.../Icon/Icons/components/ExternalPage.js | 6 +--
.../Icon/Icons/components/Favorite.js | 6 +--
.../Icon/Icons/components/Feedback.js | 6 +--
src/components/Icon/Icons/components/File.js | 6 +--
.../Icon/Icons/components/Filter.js | 6 +--
.../Icon/Icons/components/Fullscreen.js | 6 +--
.../Icon/Icons/components/FullscreenClose.js | 6 +--
src/components/Icon/Icons/components/Gif.js | 6 +--
src/components/Icon/Icons/components/Graph.js | 6 +--
src/components/Icon/Icons/components/Group.js | 6 +--
src/components/Icon/Icons/components/Guest.js | 6 +--
.../Icon/Icons/components/Health.js | 6 +--
src/components/Icon/Icons/components/Help.js | 6 +--
src/components/Icon/Icons/components/Hide.js | 6 +--
.../Icon/Icons/components/Highlight.js | 6 +--
.../Icons/components/HighlightColorBucket.js | 6 +--
src/components/Icon/Icons/components/Home.js | 6 +--
.../Icon/Icons/components/IPRestrictions.js | 6 +--
src/components/Icon/Icons/components/Image.js | 6 +--
src/components/Icon/Icons/components/Inbox.js | 6 +--
src/components/Icon/Icons/components/Info.js | 6 +--
.../Icon/Icons/components/Integrations.js | 6 +--
.../Icon/Icons/components/Invite.js | 6 +--
.../Icon/Icons/components/Italic.js | 6 +--
src/components/Icon/Icons/components/Item.js | 6 +--
.../Icon/Icons/components/Keyboard.js | 6 +--
src/components/Icon/Icons/components/Labs.js | 6 +--
src/components/Icon/Icons/components/Link.js | 6 +--
.../Icon/Icons/components/Location.js | 6 +--
.../Icon/Icons/components/Locked.js | 6 +--
.../Icon/Icons/components/Mention.js | 6 +--
src/components/Icon/Icons/components/Menu.js | 6 +--
.../Icon/Icons/components/Microphone.js | 6 +--
.../Icon/Icons/components/Mobile.js | 6 +--
.../Icons/components/MondayLogoOutline.js | 6 +--
src/components/Icon/Icons/components/Moon.js | 6 +--
.../Icon/Icons/components/MoreBelow.js | 6 +--
.../Icon/Icons/components/MoreBelowFilled.js | 6 +--
.../Icon/Icons/components/MoveArrowDown.js | 6 +--
.../Icon/Icons/components/MoveArrowLeft.js | 6 +--
.../Icon/Icons/components/MoveArrowRight.js | 6 +--
.../Icon/Icons/components/MoveArrowUp.js | 6 +--
.../Icon/Icons/components/MyWeek.js | 6 +--
.../Icons/components/NavigationChevronDown.js | 6 +--
.../Icons/components/NavigationChevronLeft.js | 6 +--
.../components/NavigationChevronRight.js | 6 +--
.../Icons/components/NavigationChevronUp.js | 6 +--
.../Icon/Icons/components/NewTab.js | 6 +--
.../Icon/Icons/components/NoColor.js | 6 +--
src/components/Icon/Icons/components/Note.js | 6 +--
.../Icon/Icons/components/Notifications.js | 6 +--
.../Icon/Icons/components/Numbers.js | 6 +--
src/components/Icon/Icons/components/Page.js | 6 +--
src/components/Icon/Icons/components/Paste.js | 6 +--
.../Icon/Icons/components/Person.js | 6 +--
src/components/Icon/Icons/components/Pin.js | 6 +--
src/components/Icon/Icons/components/Print.js | 6 +--
.../Icon/Icons/components/PushNotification.js | 6 +--
src/components/Icon/Icons/components/Quote.js | 6 +--
src/components/Icon/Icons/components/Redo.js | 6 +--
.../Icon/Icons/components/Remove.js | 6 +--
.../Icon/Icons/components/Replay.js | 6 +--
src/components/Icon/Icons/components/Retry.js | 6 +--
src/components/Icon/Icons/components/Robot.js | 6 +--
.../Icon/Icons/components/Search.js | 6 +--
.../Icon/Icons/components/Security.js | 6 +--
src/components/Icon/Icons/components/Send.js | 6 +--
.../Icon/Icons/components/Settings.js | 6 +--
.../Icon/Icons/components/SettingsKnobs.js | 6 +--
src/components/Icon/Icons/components/Share.js | 6 +--
src/components/Icon/Icons/components/Show.js | 6 +--
.../Icon/Icons/components/Shredder.js | 6 +--
src/components/Icon/Icons/components/Sort.js | 6 +--
.../Icon/Icons/components/StrikethroughS.js | 6 +--
.../Icon/Icons/components/StrikethroughT.js | 6 +--
src/components/Icon/Icons/components/Sun.js | 6 +--
.../Icon/Icons/components/Switch.js | 6 +--
src/components/Icon/Icons/components/Table.js | 6 +--
src/components/Icon/Icons/components/Team.js | 6 +--
src/components/Icon/Icons/components/Text.js | 6 +--
.../Icon/Icons/components/TextBig.js | 6 +--
.../Icon/Icons/components/TextHuge.js | 6 +--
.../Icon/Icons/components/TextSmall.js | 6 +--
.../Icon/Icons/components/Textcolor.js | 6 +--
.../Icon/Icons/components/ThumbsUp.js | 6 +--
src/components/Icon/Icons/components/Time.js | 6 +--
.../Icon/Icons/components/TurnInto.js | 6 +--
.../Icon/Icons/components/Underline.js | 6 +--
src/components/Icon/Icons/components/Undo.js | 6 +--
.../Icon/Icons/components/Unlocked.js | 6 +--
.../Icon/Icons/components/Update.js | 6 +--
.../Icon/Icons/components/Upgrade.js | 6 +--
.../Icon/Icons/components/Upload.js | 6 +--
.../Icon/Icons/components/Versioning.js | 6 +--
src/components/Icon/Icons/components/Video.js | 6 +--
src/components/Icon/Icons/components/Wand.js | 6 +--
src/components/Icon/Icons/components/Work.js | 6 +--
.../Icon/Icons/components/Workspace.js | 6 +--
src/components/MenuButton/MenuButton.jsx | 4 --
.../StepIndicator/StepIndicator.jsx | 6 +--
src/components/index.js | 2 +-
src/general-stories/colors/colors-helper.js | 1 -
src/published-components.js | 2 +-
162 files changed, 574 insertions(+), 495 deletions(-)
create mode 100644 scripts/add-forward-ref-icons.js
diff --git a/package.json b/package.json
index 89c85179a0..93bc33b78f 100644
--- a/package.json
+++ b/package.json
@@ -18,7 +18,9 @@
"deploy-storybook": "storybook-to-ghpages",
"link-local": "npm link && npm start",
"plop": "plop",
- "build-react-icons": "svg2react-icon --keep-colors node_modules/monday-ui-style/src/Icons src/components/Icon/Icons",
+ "build-react-icons-base": "svg2react-icon --keep-colors node_modules/monday-ui-style/src/Icons src/components/Icon/Icons",
+ "build-react-icons": "npm run build-react-icons-base && npm run add-ref-to-icons",
+ "add-ref-to-icons": "node ./scripts/add-forward-ref-icons.js",
"fix-lint": "prettier --write \"{,!(node_modules)/**/}*.{js,jsx}\"",
"eslint": "eslint ./src",
"eslint-fix": "eslint ./src --fix"
diff --git a/scripts/add-forward-ref-icons.js b/scripts/add-forward-ref-icons.js
new file mode 100644
index 0000000000..75d5f32e57
--- /dev/null
+++ b/scripts/add-forward-ref-icons.js
@@ -0,0 +1,44 @@
+var fs = require("fs");
+
+const startReplaceOrigin = "({size, ...props}) => (";
+const startReplaceReplaced = " React.forwardRef(({size, ...props}, ref) => (";
+const replaceRefOrigin = "{...props}>";
+const replaceRefReplaced = "{...props} ref={ref}>";
+const endReplaceOrigin = ");";
+const endReplaceReplaced = "));";
+
+function readFiles(dirname, onFileContent, onError) {
+ fs.readdir(dirname, function(err, filenames) {
+ if (err) {
+ onError(err);
+ return;
+ }
+ filenames.forEach(function(filename) {
+ fs.readFile(dirname + filename, "utf-8", function(err, content) {
+ if (err) {
+ onError(err);
+ return;
+ }
+ onFileContent(filename, content);
+ });
+ });
+ });
+}
+const dirName = "src/components/Icon/Icons/components/";
+readFiles(
+ dirName,
+ function(filename, content) {
+ console.log("optimizing:: ", filename);
+ const newContent = content
+ .replace(replaceRefOrigin, replaceRefReplaced)
+ .replace(startReplaceOrigin, startReplaceReplaced)
+ .replace(endReplaceOrigin, endReplaceReplaced);
+
+ fs.writeFile(`${dirName}/${filename}`, newContent, "utf8", function(err) {
+ if (err) return console.log(err);
+ });
+ },
+ function(err) {
+ throw err;
+ }
+);
diff --git a/src/components/ButtonGroup/ButtonGroup.jsx b/src/components/ButtonGroup/ButtonGroup.jsx
index 08654601ea..3796877fae 100644
--- a/src/components/ButtonGroup/ButtonGroup.jsx
+++ b/src/components/ButtonGroup/ButtonGroup.jsx
@@ -9,7 +9,25 @@ import { ButtonWrapper } from "./ButtonWrapper";
import "./ButtonGroup.scss";
const ButtonGroup = forwardRef(
- ({ componentClassName, options, name, disabled, value, onSelect, size, kind, groupAriaLabel, tooltipPosition, tooltipHideDelay, tooltipShowDelay, tooltipContainerSelector, tooltipMoveBy}, ref) => {
+ (
+ {
+ componentClassName,
+ options,
+ name,
+ disabled,
+ value,
+ onSelect,
+ size,
+ kind,
+ groupAriaLabel,
+ tooltipPosition,
+ tooltipHideDelay,
+ tooltipShowDelay,
+ tooltipContainerSelector,
+ tooltipMoveBy
+ },
+ ref
+ ) => {
const inputRef = useRef();
const [valueState, setValueState] = useState(value);
const prevValue = usePrevious(value);
@@ -33,7 +51,7 @@ const ButtonGroup = forwardRef(
}, [options, valueState]);
const Buttons = useMemo(() => {
- return options.map(option => {
+ return options.map((option, index) => {
const isSelected = option.value === valueState;
return (
onClick(option)}
rightIcon={option.icon}
leftIcon={option.leftIcon}
- disabled={disabled || option.disabled}
active={isSelected}
+ rightFlat={index !== options.length - 1}
+ leftFlat={index !== 0}
kind={Button.kinds.TERTIARY}
preventClickAnimation
ariaLabel={option.ariaLabel}
@@ -53,13 +72,28 @@ const ButtonGroup = forwardRef(
tooltipShowDelay={tooltipShowDelay}
tooltipContainerSelector={tooltipContainerSelector}
tooltipMoveBy={tooltipMoveBy}
- className={cx(`${baseClassName}__option-text`, { selected: isSelected, disabled })}
+ className={cx(`${baseClassName}__option-text`, {
+ selected: isSelected,
+ disabled,
+ "button-disabled": option.disabled
+ })}
>
{option.text}
);
});
- }, [options, disabled, onClick, size, valueState, tooltipPosition, tooltipHideDelay, tooltipShowDelay, tooltipContainerSelector, tooltipMoveBy]);
+ }, [
+ options,
+ disabled,
+ onClick,
+ size,
+ valueState,
+ tooltipPosition,
+ tooltipHideDelay,
+ tooltipShowDelay,
+ tooltipContainerSelector,
+ tooltipMoveBy
+ ]);
// Effects
useEffect(() => {
@@ -74,7 +108,12 @@ const ButtonGroup = forwardRef(
className={cx(baseClassName, componentClassName, `${baseClassName}--kind-${kind}`, { disabled })}
ref={mergedRef}
>
-
+
{Buttons}
{selectedOption && selectedOption.subText && (
@@ -118,4 +157,4 @@ ButtonGroup.propTypes = {
tooltipMoveBy: PropTypes.object
};
-export default ButtonGroup;
\ No newline at end of file
+export default ButtonGroup;
diff --git a/src/components/ButtonGroup/ButtonGroup.scss b/src/components/ButtonGroup/ButtonGroup.scss
index 6447ac3fd8..0a65a85406 100644
--- a/src/components/ButtonGroup/ButtonGroup.scss
+++ b/src/components/ButtonGroup/ButtonGroup.scss
@@ -2,7 +2,6 @@
@import "../../styles/themes.scss";
@import "../../styles/typography.scss";
-
.monday-style-button-group-component {
display: flex;
flex-direction: column;
@@ -17,29 +16,17 @@
justify-content: center;
.monday-style-button {
- border: 1px solid;
- border-radius: 0;
@include theme-prop(background-color, primary-background-color);
@include theme-prop(border-color, ui-border-color);
- margin-left: -1px;
-
- &:first-child {
- border-radius: $border-radius-small 0 0 $border-radius-small;
- margin-left: 0;
- }
- &:last-child {
- border-radius: 0 $border-radius-small $border-radius-small 0;
- }
-
&--color {
&-primary {
&-active {
+ z-index: 20;
&:hover {
@include theme-prop(background-color, primary-selected-color);
}
@include theme-prop(background-color, primary-selected-color);
@include theme-prop(border-color, primary-color);
- z-index: 10;
}
}
}
@@ -49,6 +36,7 @@
&:not(.disabled) {
@include theme-prop(color, primary-text-color);
&.selected {
+ z-index: 10;
@include theme-prop(color, primary-text-color);
}
}
@@ -69,4 +57,16 @@
&.disabled {
cursor: not-allowed;
}
+
+ .disabled {
+ cursor: not-allowed;
+ background-color: var(--disabled-background-color);
+ opacity: 0.5;
+ }
+
+ .button-disabled {
+ background-color: var(--disabled-background-color);
+ opacity: 0.5;
+ cursor: not-allowed;
+ }
}
diff --git a/src/components/ButtonGroup/__stories__/buttonGroup.stories.js b/src/components/ButtonGroup/__stories__/buttonGroup.stories.js
index beb1d9d528..d260b14648 100644
--- a/src/components/ButtonGroup/__stories__/buttonGroup.stories.js
+++ b/src/components/ButtonGroup/__stories__/buttonGroup.stories.js
@@ -4,6 +4,9 @@ import ButtonGroup from "../ButtonGroup";
import { StoryStateColumn, StoryStateRow } from "../../storybook-helpers";
import { FakeXMLHttpRequest } from "sinon";
import DescriptionLabel from "../../storybook-helpers/description-label/description-label";
+import TextSmall from "../../Icon/Icons/components/TextSmall";
+import Doc from "../../Icon/Icons/components/Doc";
+import { Bolt } from "../../Icon/Icons";
export const Sandbox = () => (
) : null}
{!readOnly && !disabled && (
-
-
-
+ iconType={Icon.type.SVG}
+ clickable
+ icon={CloseSmall}
+ iconSize={iconSize}
+ onClick={onDeleteCallback}
+ />
)}
);
diff --git a/src/components/Icon/Icon.jsx b/src/components/Icon/Icon.jsx
index 340bec1f84..9798c16632 100644
--- a/src/components/Icon/Icon.jsx
+++ b/src/components/Icon/Icon.jsx
@@ -38,10 +38,11 @@ const Icon = forwardRef(
return null;
}
- if (iconType === ICON_TYPES.SVG || typeof icon === "function") {
+ if (iconType === ICON_TYPES.SVG || typeof icon === "function" || typeof icon === "object") {
const IconComponent = icon;
return (
(
-