@tecsinapse/cortex-react 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -0
- package/package.json +33 -0
- package/src/components/Badge.tsx +45 -0
- package/src/components/Button.tsx +19 -0
- package/src/components/Card.tsx +18 -0
- package/src/components/Hint.tsx +31 -0
- package/src/components/Input.tsx +110 -0
- package/src/components/Modal.tsx +24 -0
- package/src/components/SearchInput.tsx +86 -0
- package/src/components/Select.tsx +170 -0
- package/src/components/Snackbar.tsx +26 -0
- package/src/components/Tag.tsx +19 -0
- package/src/components/TextArea.tsx +121 -0
- package/src/components/Toggle.tsx +25 -0
- package/src/components/index.ts +11 -0
- package/src/docs/badge-anchor.stories.tsx +42 -0
- package/src/docs/badge.stories.tsx +31 -0
- package/src/docs/button.stories.tsx +37 -0
- package/src/docs/card.stories.tsx +29 -0
- package/src/docs/hint.stories.tsx +32 -0
- package/src/docs/input-custom.stories.tsx +45 -0
- package/src/docs/input.stories.tsx +40 -0
- package/src/docs/modal.stories.tsx +48 -0
- package/src/docs/select-grouped.stories.tsx +79 -0
- package/src/docs/select.stories.tsx +70 -0
- package/src/docs/snackbar.stories.tsx +31 -0
- package/src/docs/tag.stories.tsx +37 -0
- package/src/docs/text-area.stories.tsx +50 -0
- package/src/docs/toggle.stories.tsx +18 -0
- package/src/docs/utils.ts +8 -0
- package/src/hooks/index.ts +1 -0
- package/src/hooks/useDebouncedState.ts +24 -0
- package/src/index.ts +1 -0
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import React, { useState } from 'react';
|
|
2
|
+
import { StoryFn } from '@storybook/react';
|
|
3
|
+
import { TextArea } from '../index';
|
|
4
|
+
|
|
5
|
+
export default {
|
|
6
|
+
title: 'Cortex-React/TextArea',
|
|
7
|
+
component: <div />,
|
|
8
|
+
args: {
|
|
9
|
+
rows: 6,
|
|
10
|
+
intent: 'default',
|
|
11
|
+
label: 'Label',
|
|
12
|
+
placeholder: 'placeholder',
|
|
13
|
+
},
|
|
14
|
+
argTypes: {
|
|
15
|
+
intent: {
|
|
16
|
+
options: ['default', 'success', 'warning', 'error'],
|
|
17
|
+
control: { type: 'select' },
|
|
18
|
+
},
|
|
19
|
+
rows: {
|
|
20
|
+
control: { type: 'number' },
|
|
21
|
+
},
|
|
22
|
+
label: {
|
|
23
|
+
control: { type: 'text' },
|
|
24
|
+
},
|
|
25
|
+
placeholder: {
|
|
26
|
+
control: { type: 'text' },
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
const Template: StoryFn = args => {
|
|
32
|
+
const [value, setValue] = useState('');
|
|
33
|
+
return (
|
|
34
|
+
<div className={'w-[300px]'}>
|
|
35
|
+
<TextArea.Root
|
|
36
|
+
placeholder={args.placeholder}
|
|
37
|
+
label={args.label}
|
|
38
|
+
variants={{ intent: args.intent }}
|
|
39
|
+
rows={args.rows}
|
|
40
|
+
value={value}
|
|
41
|
+
onChange={e => setValue(e.currentTarget.value)}
|
|
42
|
+
/>
|
|
43
|
+
</div>
|
|
44
|
+
);
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
export const Base = {
|
|
48
|
+
render: Template,
|
|
49
|
+
args: {},
|
|
50
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import React, { useState } from 'react';
|
|
2
|
+
import { StoryFn } from '@storybook/react';
|
|
3
|
+
import { Toggle } from '../index';
|
|
4
|
+
|
|
5
|
+
export default {
|
|
6
|
+
title: 'Cortex-React/Toggle',
|
|
7
|
+
component: <div />,
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
const Template: StoryFn = () => {
|
|
11
|
+
const [checked, setChecked] = useState(false);
|
|
12
|
+
return <Toggle checked={checked} onClick={() => setChecked(!checked)} />;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export const Base = {
|
|
16
|
+
render: Template,
|
|
17
|
+
args: {},
|
|
18
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './useDebouncedState';
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Dispatch, SetStateAction, useEffect, useRef, useState } from 'react';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @param initialState
|
|
5
|
+
* @param timeoutCallback callback to be called after bouncing ends. Should be memoized.
|
|
6
|
+
* @param timeoutMs
|
|
7
|
+
*/
|
|
8
|
+
export function useDebouncedState<S>(
|
|
9
|
+
initialState: S | (() => S),
|
|
10
|
+
timeoutCallback?: (state: S) => void,
|
|
11
|
+
timeoutMs = 166
|
|
12
|
+
): [S, Dispatch<SetStateAction<S>>] {
|
|
13
|
+
const timeoutId = useRef<NodeJS.Timeout>();
|
|
14
|
+
|
|
15
|
+
const [state, setState] = useState<S>(initialState);
|
|
16
|
+
|
|
17
|
+
useEffect(() => {
|
|
18
|
+
if (timeoutId.current) clearTimeout(timeoutId.current);
|
|
19
|
+
if (timeoutCallback)
|
|
20
|
+
timeoutId.current = setTimeout(() => timeoutCallback(state), timeoutMs);
|
|
21
|
+
}, [state]);
|
|
22
|
+
|
|
23
|
+
return [state, setState];
|
|
24
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './components';
|