Skip to content

Commit

Permalink
Merge pull request #132 from mondaycom/moshe/chips_fixes
Browse files Browse the repository at this point in the history
Moshe/chips fixes
  • Loading branch information
MosheZemah authored May 26, 2021
2 parents d836ea9 + 289dc71 commit 93799a2
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 11 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "monday-ui-react-core",
"version": "0.3.31",
"version": "0.3.32",
"description": "Official monday.com UI resources for application development in React.js",
"main": "dist/main.js",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion src/components/Button/Button.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
.monday-style-button {
--loader-padding: 8px;
outline: none;
border: 1px solid transparent;
border: none;
height: auto;
font-family: Roboto, sans-serif;
border-radius: $border-radius-small;
Expand Down
8 changes: 5 additions & 3 deletions src/components/Chips/Chips.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@ const Chips = forwardRef(
}
}, [id, onDelete]);

const hasCloseButton = !readOnly && !disabled;

return (
<div
ref={mergedRef}
className={cx("chips--wrapper", className, { disabled })}
className={cx("chips--wrapper", className, { disabled, "with-close": hasCloseButton })}
id={id}
style={backgroundColorStyle}
>
Expand All @@ -56,14 +58,14 @@ const Chips = forwardRef(
ignoreFocusStyle
/>
) : null}
{!readOnly && !disabled && (
{hasCloseButton && (
<Icon
aria-label={`Remove ${label}`}
className="chip-icon close"
iconType={Icon.type.SVG}
clickable
icon={CloseSmall}
iconSize={iconSize}
iconSize={18}
onClick={onDeleteCallback}
/>
)}
Expand Down
24 changes: 23 additions & 1 deletion src/components/Chips/Chips.scss
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ $icon-margin: 4px;
align-items: center;
margin: 0 4px;
user-select: none;
animation: chips-enter 100ms;
animation-timing-function: cubic-bezier(0, 0, 0.35, 1);

&.with-close {
padding-right: 4px;
}

.chip-icon {
&.left {
Expand All @@ -26,9 +32,10 @@ $icon-margin: 4px;
@include focus-style();
cursor: pointer;
@include theme-prop(color, primary-text-color);
border-radius: 4px;

&:hover {
@include theme-prop(background-color, primary-background-hover-color);
@include theme-prop(background-color, primary-background-color);
}
}
}
Expand All @@ -47,3 +54,18 @@ $icon-margin: 4px;
@include ellipsis();
}
}

@keyframes chips-enter {
0% {
transform: scale(0.3);
opacity: 0;
}

70% {
opacity: 1;
}

100% {
transform: scale(1);
}
}
22 changes: 21 additions & 1 deletion src/components/Chips/__stories__/chips.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,21 @@ export const Sandbox = () => (
</div>
);

const randomProperty = function(obj) {
const keys = Object.keys(obj);
return obj[keys[(keys.length * Math.random()) << 0]];
};

const chipsPropsById = {
1: { key: "1", id: "1", label: "Label chip" },
2: { key: "2", id: "2", label: "Chip with left icon", leftIcon: "fa fa-star-o", color: Chips.colors.NEGATIVE },
3: { key: "3", id: "3", label: "Chip with right icon", rightIcon: "fa fa-info", color: Chips.colors.POSITIVE },
4: { key: "4", id: "4", label: "Disabled chip", leftIcon: "fa fa-star-o", rightIcon: "fa fa-info", disabled: true }
4: { key: "4", id: "4", label: "Disabled chip", leftIcon: "fa fa-star-o", rightIcon: "fa fa-info", disabled: true },
5: { key: "5", id: "5", label: "Label chip 5", color: randomProperty(Chips.colors) },
6: { key: "6", id: "6", label: "Label chip 6", color: randomProperty(Chips.colors) },
7: { key: "7", id: "7", label: "Label chip 7", color: randomProperty(Chips.colors) },
8: { key: "8", id: "8", label: "Label chip 8", color: randomProperty(Chips.colors) },
9: { key: "9", id: "9", label: "Label chip 9", color: randomProperty(Chips.colors) }
};

const ChipsWrapper = () => {
Expand All @@ -41,6 +51,13 @@ const ChipsWrapper = () => {
setChipsIds(["1", "2", "3", "4"]);
}, [setChipsIds]);

const onAdd = useCallback(() => {
const missingId = Object.keys(chipsPropsById).find(id => !chipsIds.includes(id));
if (missingId) {
setChipsIds(chipsIds.concat([missingId]));
}
}, [chipsIds, setChipsIds]);

return (
<div className="chips-wrapper">
{chipsIds.map(id => (
Expand All @@ -49,6 +66,9 @@ const ChipsWrapper = () => {
<Button className="reset-button" onClick={onReset} size={Button.sizes.SMALL} kind={Button.kinds.TERTIARY}>
Reset
</Button>
<Button className="add-button" onClick={onAdd} size={Button.sizes.SMALL} kind={Button.kinds.TERTIARY}>
Add
</Button>
</div>
);
};
Expand Down
8 changes: 7 additions & 1 deletion src/components/Chips/__stories__/chips.stories.scss
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.chips-wrapper {
display: flex;
flex-wrap: wrap;
height: 100px;
height: 140px;
border: 1px solid #c5c7d0;
width: 700px;
align-items: center;
Expand All @@ -12,4 +12,10 @@
position: absolute;
bottom: -40px;
}

.add-button {
position: absolute;
bottom: -40px;
left: 100px;
}
}
4 changes: 1 addition & 3 deletions src/styles/states.scss
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,7 @@

@mixin focus-style-css {
outline: none;
border: 1px solid;
@include theme-prop(border-color, primary-hover-color, true);
box-shadow: 0 0 0 3px hsla(209, 100%, 50%, 0.5);
box-shadow: 0 0 0 3px hsla(209, 100%, 50%, 0.5), 0px 0px 0px 1px var(--primary-hover-color) inset;
z-index: 11;
border-radius: 4px;
}

0 comments on commit 93799a2

Please sign in to comment.