@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.
@@ -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,8 @@
1
+ export const defaultIntents = [
2
+ 'primary',
3
+ 'secondary',
4
+ 'success',
5
+ 'info',
6
+ 'warning',
7
+ 'error',
8
+ ];
@@ -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';