Skip to content

Commit

Permalink
Merge pull request #70 from MacPaw/feat/prefilled-and-disabled-tag-input
Browse files Browse the repository at this point in the history
feat: add disabled state for tag input component
  • Loading branch information
kulia26 authored Aug 1, 2022
2 parents bdace38 + 69d6247 commit 87e1736
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 26 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@macpaw/macpaw-ui",
"version": "4.1.0",
"version": "4.2.0",
"main": "lib/ui.js",
"scripts": {
"dev": "next -p 1234",
Expand Down
68 changes: 50 additions & 18 deletions pages/tag-input.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export const BasicTagInput = () => {
const [values, setValues] = useState([{ id:1, value:'Tag 1' }]);
return (
<div style={{ width: 300 }}>
<TagInput
<TagInput
id="BasicTagInput"
tags={values}
label="Tags"
Expand All @@ -23,7 +23,7 @@ export const BasicTagInput = () => {
```
const [values, setValues] = useState([{ id:1, value:'Tag 1' }]);
<TagInput
<TagInput
id="BasicTagInput"
tags={values}
label="Tags"
Expand All @@ -38,7 +38,7 @@ export const MaxHeightTagInput = () => {
const [values, setValues] = useState([{ id:1, value:'Tag 1' }]);
return (
<div style={{ width: 300 }}>
<TagInput
<TagInput
id="MaxHeightTagInput"
tags={values}
label="Tags"
Expand All @@ -55,7 +55,7 @@ export const MaxHeightTagInput = () => {
```
const [values, setValues] = useState([{ id:1, value:'Tag 1' }]);
<TagInput
<TagInput
id="MaxHeightTagInput"
tags={values}
label="Tags"
Expand All @@ -77,7 +77,7 @@ export const KeyCodeTagInput = () => {
const removeKeyCodes = ['Delete', 'Backspace', 'Escape'];
return (
<div style={{ width: 300 }}>
<TagInput
<TagInput
id="KeyCodeTagInput"
tags={values}
label="Tags"
Expand All @@ -97,7 +97,7 @@ const [values, setValues] = useState([{ id:1, value:'Tag 1' }]);
const addKeyCodes = ['Enter', 'Space', 'Comma'];
const removeKeyCodes = ['Delete', 'Backspace', 'Escape'];
<TagInput
<TagInput
id="KeyCodeTagInput"
tags={values}
label="Tags"
Expand All @@ -115,7 +115,7 @@ export const ReadOnlyTagInput = () => {
const [values, setValues] = useState([{ id:1, value:'Tag 1' }]);
return (
<div style={{ width: 300 }}>
<TagInput
<TagInput
id="ReadOnlyTagInput"
tags={values}
label="Read only tags"
Expand All @@ -130,21 +130,53 @@ export const ReadOnlyTagInput = () => {
```
const [values, setValues] = useState([{ id:1, value:'Tag 1' }]);
<TagInput
<TagInput
id="ReadOnlyTagInput"
tags={values}
label="Read only tags"
isReadOnly
/>
```

## Disabled tag input

export const DisabledTagInput = () => {
const [values, setValues] = useState([{ id:1, value:'Tag 1' }]);
return (
<div style={{ width: 300 }}>
<TagInput
id="ReadOnlyTagInput"
tags={values}
label="Disabled input field"
disabled
isReadOnly
/>
</div>
)
}

<DisabledTagInput />

```
const [values, setValues] = useState([{ id:1, value:'Tag 1' }]);
<TagInput
id="ReadOnlyTagInput"
tags={values}
label="Disabled input field"
disabled
isReadOnly
/>
```

## With unique values

export const UniqueTagInput = () => {
const [values, setValues] = useState([{ id:1, value:'Tag 1' }]);
return (
<div style={{ width: 300 }}>
<TagInput
<TagInput
id="UniqueTagInput"
tags={values}
label="Unique tags"
Expand All @@ -161,7 +193,7 @@ export const UniqueTagInput = () => {
```
const [values, setValues] = useState([{ id:1, value:'Tag 1' }]);
<TagInput
<TagInput
id="UniqueTagInput"
tags={values}
label="Unique tags"
Expand All @@ -177,7 +209,7 @@ export const FormattedTagInput = () => {
const [values, setValues] = useState([{ id:1, value:'Tag 1' }]);
return (
<div style={{ width: 300 }}>
<TagInput
<TagInput
id="FormattedTagInput"
tags={values}
label="Hash tags"
Expand All @@ -194,7 +226,7 @@ export const FormattedTagInput = () => {
```
const [values, setValues] = useState([{ id:1, value:'Tag 1' }]);
<TagInput
<TagInput
id="FormattedTagInput"
tags={values}
label="Hash tags"
Expand Down Expand Up @@ -226,10 +258,10 @@ export const TagInputWithValidation = () => {
setValues(nextValues);
const hasWrongValues = nextValues.some(({color})=>color === 'warning');
if(error && !hasWrongValues) setError('');
}
}
return (
<div style={{ width: 300 }}>
<TagInput
<TagInput
id="TagInputWithValidation"
tags={values}
error={error}
Expand Down Expand Up @@ -265,13 +297,13 @@ const onChangeInput = () => setError('');
const handleChange = (nextValues) => {
setValues(nextValues);
const hasWrongValues = nextValues.some(({color})=>color === 'warning');
if(error && !hasWrongValues) setError('');
}
}
<TagInput
<TagInput
id="TagInputWithValidation"
tags={values}
error={error}
Expand Down
2 changes: 1 addition & 1 deletion src/Input/Input.scss
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
font-size: 16px;
font-family: 'Montserrat', 'Helvetica Neue', sans-serif;
line-height: 1.2;
border: 2px solid rgba(111, 114, 121, .16);
border: 2px solid var(--color-black-04);
background: var(--color-white);
transition: border-color 200ms cubic-bezier(0.25, 0.1, 0.25, 1);

Expand Down
31 changes: 27 additions & 4 deletions src/TagInput/TagInput.scss
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

&-label {
display: block;

&:hover + .tagList {
border-color: var(--color-black)
}
Expand All @@ -21,7 +21,30 @@
.tag-input-label,
.tagList {
cursor: inherit;
pointer-events: none;
}
.tagList:hover {
border-color: var(--color-black-04);
}
.tag-input-label {
&:hover + .tagList {
border-color: var(--color-black-04);
}
}
}

&.-disabled {
cursor: not-allowed;
.tagList {
border: 2px solid transparent;
background: var(--color-black-08);
}
.tagList:hover {
border-color: transparent;
}
.tag-input-label {
&:hover + .tagList {
border-color: transparent;
}
}
}

Expand All @@ -32,7 +55,7 @@
padding: 8px 10px;
cursor: text;
transition: border-color 200ms cubic-bezier(.25, .1, .25, 1);
border: 2px solid rgba(111, 114, 121, .16);
border: 2px solid var(--color-black-04);
border-radius: 8px;
flex-wrap: wrap;

Expand All @@ -53,7 +76,7 @@
padding: 4px 8px 5px;
box-sizing: border-box;
background-color: transparent;

&:focus {
outline: none;
}
Expand Down
3 changes: 3 additions & 0 deletions src/TagInput/TagInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export interface TagInput {
removeKeyCodes?: string[];
maxHeight?: string | number;
isReadOnly?: boolean;
disabled?: boolean;
isUnique?: boolean;
isHandleClipboard?: boolean;
onChange: (nextTags: TagInputListItem[]) => void;
Expand All @@ -49,6 +50,7 @@ const TagInput: React.FC<React.PropsWithChildren<TagInput>> = ({
removeKeyCodes = [],
maxHeight,
isReadOnly,
disabled,
isUnique,
isHandleClipboard,
onChange,
Expand All @@ -63,6 +65,7 @@ const TagInput: React.FC<React.PropsWithChildren<TagInput>> = ({
const tagInputClassNames = cx('tag-input', className, {
'-readonly': isReadOnly,
'-error': showError,
'-disabled': disabled,
});

const checkIsUniqueTag = (tag: string, list: TagInputListItem[]) => {
Expand Down

0 comments on commit 87e1736

Please sign in to comment.