Skip to content

Commit 308cebe

Browse files
[Improvement] - Added Disabled mode (#8) (#9)
* [Improvement] - Added Disabled mode (#8) * Added Disable mode * Removed unnecesary style option for the tag * Changing a little the storybook to Show Disabled Mode * chore: 🧹 housekeeping Co-authored-by: Julmer Olivero Ocando <jolivero.03@gmail.com>
1 parent 205d4a1 commit 308cebe

File tree

9 files changed

+3757
-2740
lines changed

9 files changed

+3757
-2740
lines changed

.github/workflows/main.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ jobs:
88
- name: Begin CI...
99
uses: actions/checkout@v2
1010

11-
- name: Use Node 12
11+
- name: Use Node 16
1212
uses: actions/setup-node@v1
1313
with:
14-
node-version: 12.x
14+
node-version: 16.x
1515

1616
- name: Use cached node_modules
1717
uses: actions/cache@v1

.nvmrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
12
1+
16

.storybook/main.js

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,12 @@
11
module.exports = {
2-
stories: ['../stories/**/*.stories.(ts|tsx)'],
3-
addons: ['@storybook/addon-actions', '@storybook/addon-links', '@storybook/addon-docs'],
4-
webpackFinal: async (config) => {
5-
config.module.rules.push({
6-
test: /\.(ts|tsx)$/,
7-
use: [
8-
{
9-
loader: require.resolve('ts-loader'),
10-
options: {
11-
transpileOnly: true,
12-
},
13-
},
14-
{
15-
loader: require.resolve('react-docgen-typescript-loader'),
16-
},
17-
],
18-
});
19-
20-
config.resolve.extensions.push('.ts', '.tsx');
21-
22-
return config;
23-
},
24-
};
2+
"stories": [
3+
"../stories/**/*.stories.mdx",
4+
"../stories/**/*.stories.@(js|jsx|ts|tsx)"
5+
],
6+
"addons": [
7+
"@storybook/addon-links",
8+
"@storybook/addon-essentials",
9+
"@storybook/addon-interactions"
10+
],
11+
"framework": "@storybook/react"
12+
}

.storybook/preview.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
export const parameters = {
2+
actions: { argTypesRegex: "^on[A-Z].*" },
3+
controls: {
4+
matchers: {
5+
color: /(background|color)$/i,
6+
date: /Date$/,
7+
},
8+
},
9+
}

package.json

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -16,36 +16,37 @@
1616
"build": "tsdx build && filesize",
1717
"lint": "tsdx lint",
1818
"prepare": "tsdx build && filesize",
19-
"storybook": "start-storybook -p 6006",
20-
"build-storybook": "build-storybook"
19+
"storybook": "export NODE_OPTIONS=--openssl-legacy-provider; start-storybook -p 6006",
20+
"build-storybook": "export NODE_OPTIONS=--openssl-legacy-provider; build-storybook"
2121
},
2222
"peerDependencies": {
2323
"react": ">=16"
2424
},
2525
"dependencies": {
26-
"goober": "^2.0.18"
26+
"goober": "^2.1.10"
2727
},
2828
"devDependencies": {
29-
"@ampproject/filesize": "^4.2.0",
30-
"@babel/core": "^7.12.10",
31-
"@storybook/addon-actions": "^6.1.11",
32-
"@storybook/addon-docs": "^6.1.11",
33-
"@storybook/addon-info": "^5.3.21",
34-
"@storybook/addon-links": "^6.1.11",
35-
"@storybook/addons": "^6.1.11",
36-
"@storybook/react": "^6.1.11",
37-
"@types/react": "^17.0.0",
38-
"@types/react-dom": "^17.0.0",
39-
"babel-loader": "^8.2.2",
40-
"husky": "^4.3.6",
41-
"react": "^17.0.1",
29+
"@ampproject/filesize": "^4.3.0",
30+
"@babel/core": "^7.18.9",
31+
"@storybook/addon-actions": "^6.5.9",
32+
"@storybook/addon-essentials": "^6.5.9",
33+
"@storybook/addon-interactions": "^6.5.9",
34+
"@storybook/addon-links": "^6.5.9",
35+
"@storybook/builder-webpack4": "^6.5.9",
36+
"@storybook/manager-webpack4": "^6.5.9",
37+
"@storybook/react": "^6.5.9",
38+
"@storybook/testing-library": "^0.0.13",
39+
"@types/react": "^18.0.15",
40+
"@types/react-dom": "^18.0.6",
41+
"babel-loader": "^8.2.5",
42+
"react": "^18.2.0",
4243
"react-docgen-typescript-loader": "^3.7.2",
43-
"react-dom": "^17.0.1",
44-
"react-is": "^17.0.1",
45-
"ts-loader": "^8.0.12",
44+
"react-dom": "^18.2.0",
45+
"react-is": "^18.2.0",
46+
"ts-loader": "^9.3.1",
4647
"tsdx": "^0.14.1",
47-
"tslib": "^2.0.3",
48-
"typescript": "^4.1.3"
48+
"tslib": "^2.4.0",
49+
"typescript": "^4.7.4"
4950
},
5051
"prettier": {
5152
"printWidth": 80,

src/index.tsx

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,21 @@ export interface TagsInputProps {
1313
seprators?: string[];
1414
onExisting?: (tag: string) => void;
1515
onRemoved?: (tag: string) => void;
16+
disabled?: boolean;
1617
}
1718

1819
// initialize goober once
1920
setup(React.createElement);
2021

2122
const RTIContainer = css({
22-
"--rtiBg": "#fff",
23-
"--rtiBorder": "#ccc",
24-
"--rtiMain": "#3182ce",
25-
"--rtiRadius": "0.375rem",
26-
"--rtiS": "0.5rem",
27-
"--rtiTag": "#edf2f7",
28-
"--rtiTagRemove": "#e53e3e",
23+
"--rti-bg": "#fff",
24+
"--rti-border": "#ccc",
25+
"--rti-main": "#3182ce",
26+
"--rti-radius": "0.375rem",
27+
"--rti-s": "0.5rem",
28+
"--rti-tag": "#edf2f7",
29+
"--rti-tag-remove": "#e53e3e",
30+
"--rti-tag-padding": "0.15rem 0.25rem",
2931

3032
"*": {
3133
boxSizing: "border-box",
@@ -67,6 +69,7 @@ export const TagsInput = ({
6769
seprators,
6870
onExisting,
6971
onRemoved,
72+
disabled,
7073
}: TagsInputProps) => {
7174
const [tags, setTags] = useState(value || []);
7275

@@ -102,7 +105,7 @@ export const TagsInput = ({
102105
return (
103106
<div aria-labelledby={name} className={cc("rti--container", RTIContainer)}>
104107
{tags.map(tag => (
105-
<Tag key={tag} text={tag} remove={onTagRemove} />
108+
<Tag key={tag} text={tag} remove={onTagRemove} disabled={disabled} />
106109
))}
107110

108111
<input
@@ -112,6 +115,7 @@ export const TagsInput = ({
112115
placeholder={placeHolder}
113116
onKeyDown={handleOnKeyUp}
114117
onBlur={onBlur}
118+
disabled={disabled}
115119
/>
116120
</div>
117121
);

src/tag.tsx

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import cc from "./classnames";
55
interface TagProps {
66
text: string;
77
remove: any;
8+
disabled?: boolean;
89
}
910

1011
const tagStyles = css({
@@ -13,7 +14,7 @@ const tagStyles = css({
1314
borderRadius: "var(--rti-radius)",
1415
display: "inline-flex",
1516
justifyContent: "center",
16-
paddingLeft: "var(--rti-s)",
17+
padding: "var(--rti-tag-padding)",
1718

1819
button: {
1920
background: "none",
@@ -29,7 +30,7 @@ const tagStyles = css({
2930
},
3031
});
3132

32-
export default function Tag({ text, remove }: TagProps) {
33+
export default function Tag({ text, remove, disabled }: TagProps) {
3334
const handleOnRemove = e => {
3435
e.stopPropagation();
3536
remove(text);
@@ -38,13 +39,15 @@ export default function Tag({ text, remove }: TagProps) {
3839
return (
3940
<span className={cc("rti--tag", tagStyles)}>
4041
<span>{text}</span>
41-
<button
42-
type="button"
43-
onClick={handleOnRemove}
44-
aria-label={`remove ${text}`}
45-
>
46-
&#10005;
47-
</button>
42+
{!disabled && (
43+
<button
44+
type="button"
45+
onClick={handleOnRemove}
46+
aria-label={`remove ${text}`}
47+
>
48+
&#10005;
49+
</button>
50+
)}
4851
</span>
4952
);
5053
}

stories/tags-input.stories.tsx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ export default {
66
title: "Tags Input",
77
};
88

9-
export const Default = () => {
9+
export const Page = () => {
1010
const [selected, setSelected] = useState(["papaya"]);
11+
const [disabled, setDisabled] = useState(false);
1112

1213
return (
1314
<div>
@@ -18,7 +19,17 @@ export const Default = () => {
1819
onChange={setSelected}
1920
name="fruits"
2021
placeHolder="enter fruits"
22+
disabled={disabled}
2123
/>
24+
<div style={{ margin: "2rem 0", display: "flex", flexFlow: "row" }}>
25+
<button
26+
onClick={() => setDisabled(!disabled)}
27+
style={{ marginRight: "2rem" }}
28+
>
29+
Toggle Disable
30+
</button>
31+
<pre>Disable: {JSON.stringify(disabled)}</pre>
32+
</div>
2233
</div>
2334
);
2435
};

0 commit comments

Comments
 (0)