@tecsinapse/cortex-react 1.0.2 → 1.2.0
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/LICENSE.md +21 -0
- package/dist/cjs/components/Badge.js +27 -0
- package/dist/cjs/components/Button.js +11 -0
- package/dist/cjs/components/Card.js +19 -0
- package/dist/cjs/components/Hint.js +21 -0
- package/dist/cjs/components/Input.js +79 -0
- package/dist/cjs/components/Modal.js +25 -0
- package/dist/cjs/components/SearchInput.js +70 -0
- package/dist/cjs/components/Select.js +101 -0
- package/dist/cjs/components/Snackbar.js +18 -0
- package/dist/cjs/components/Table.js +53 -0
- package/dist/cjs/components/Tag.js +18 -0
- package/dist/cjs/components/TextArea.js +81 -0
- package/dist/cjs/components/Toggle.js +18 -0
- package/dist/cjs/hooks/useDebouncedState.js +16 -0
- package/dist/cjs/index.js +42 -0
- package/dist/esm/components/Badge.js +24 -0
- package/dist/esm/components/Button.js +9 -0
- package/dist/esm/components/Card.js +17 -0
- package/dist/esm/components/Hint.js +19 -0
- package/dist/esm/components/Input.js +72 -0
- package/dist/esm/components/Modal.js +23 -0
- package/dist/esm/components/SearchInput.js +68 -0
- package/dist/esm/components/Select.js +96 -0
- package/dist/esm/components/Snackbar.js +16 -0
- package/dist/esm/components/Table.js +44 -0
- package/dist/esm/components/Tag.js +16 -0
- package/dist/esm/components/TextArea.js +79 -0
- package/dist/esm/components/Toggle.js +16 -0
- package/dist/esm/hooks/useDebouncedState.js +14 -0
- package/dist/esm/index.js +12 -0
- package/dist/types/components/Badge.d.ts +12 -0
- package/dist/types/components/Button.d.ts +8 -0
- package/dist/types/components/Card.d.ts +6 -0
- package/dist/types/components/Hint.d.ts +14 -0
- package/dist/types/components/Input.d.ts +34 -0
- package/dist/types/components/Modal.d.ts +8 -0
- package/dist/types/components/SearchInput.d.ts +11 -0
- package/dist/types/components/Select.d.ts +28 -0
- package/dist/types/components/Snackbar.d.ts +9 -0
- package/dist/types/components/Table.d.ts +13 -0
- package/dist/types/components/Tag.d.ts +8 -0
- package/dist/types/components/TextArea.d.ts +24 -0
- package/dist/types/components/Toggle.d.ts +2 -0
- package/{src/components/index.ts → dist/types/components/index.d.ts} +1 -0
- package/dist/types/docs/badge-anchor.stories.d.ts +29 -0
- package/dist/types/docs/badge.stories.d.ts +27 -0
- package/dist/types/docs/button.stories.d.ts +30 -0
- package/dist/types/docs/card.stories.d.ts +10 -0
- package/dist/types/docs/hint.stories.d.ts +27 -0
- package/dist/types/docs/input-custom.stories.d.ts +33 -0
- package/dist/types/docs/input.stories.d.ts +33 -0
- package/dist/types/docs/modal.stories.d.ts +10 -0
- package/dist/types/docs/select-grouped.stories.d.ts +32 -0
- package/dist/types/docs/select.stories.d.ts +32 -0
- package/dist/types/docs/snackbar.stories.d.ts +21 -0
- package/dist/types/docs/table.stories.d.ts +10 -0
- package/dist/types/docs/tag.stories.d.ts +21 -0
- package/dist/types/docs/text-area.stories.d.ts +39 -0
- package/dist/types/docs/toggle.stories.d.ts +10 -0
- package/dist/types/docs/utils.d.ts +1 -0
- package/dist/types/hooks/useDebouncedState.d.ts +2 -0
- package/package.json +19 -14
- package/src/components/Badge.tsx +0 -45
- package/src/components/Button.tsx +0 -19
- package/src/components/Card.tsx +0 -18
- package/src/components/Hint.tsx +0 -31
- package/src/components/Input.tsx +0 -110
- package/src/components/Modal.tsx +0 -24
- package/src/components/SearchInput.tsx +0 -86
- package/src/components/Select.tsx +0 -170
- package/src/components/Snackbar.tsx +0 -26
- package/src/components/Tag.tsx +0 -19
- package/src/components/TextArea.tsx +0 -121
- package/src/components/Toggle.tsx +0 -25
- package/src/docs/badge-anchor.stories.tsx +0 -42
- package/src/docs/badge.stories.tsx +0 -31
- package/src/docs/button.stories.tsx +0 -37
- package/src/docs/card.stories.tsx +0 -29
- package/src/docs/hint.stories.tsx +0 -32
- package/src/docs/input-custom.stories.tsx +0 -45
- package/src/docs/input.stories.tsx +0 -40
- package/src/docs/modal.stories.tsx +0 -48
- package/src/docs/select-grouped.stories.tsx +0 -79
- package/src/docs/select.stories.tsx +0 -70
- package/src/docs/snackbar.stories.tsx +0 -31
- package/src/docs/tag.stories.tsx +0 -37
- package/src/docs/text-area.stories.tsx +0 -50
- package/src/docs/toggle.stories.tsx +0 -18
- package/src/docs/utils.ts +0 -8
- package/src/hooks/useDebouncedState.ts +0 -24
- /package/{src/hooks/index.ts → dist/types/hooks/index.d.ts} +0 -0
- /package/{src/index.ts → dist/types/index.d.ts} +0 -0
package/src/components/Input.tsx
DELETED
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import {
|
|
3
|
-
input,
|
|
4
|
-
InputBaseVariants,
|
|
5
|
-
inputBox,
|
|
6
|
-
labelStyle,
|
|
7
|
-
} from '@tecsinapse/cortex-core';
|
|
8
|
-
import { clsx } from 'clsx';
|
|
9
|
-
|
|
10
|
-
const getValidChildren = (children: React.ReactNode) => {
|
|
11
|
-
return React.Children.toArray(children).filter(el =>
|
|
12
|
-
React.isValidElement(el)
|
|
13
|
-
) as React.ReactElement[];
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
interface InputPropsBase {
|
|
17
|
-
variants?: InputBaseVariants;
|
|
18
|
-
label?: string;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export interface InputProps
|
|
22
|
-
extends React.InputHTMLAttributes<HTMLInputElement>,
|
|
23
|
-
InputPropsBase {}
|
|
24
|
-
|
|
25
|
-
export const Box = React.forwardRef<HTMLInputElement, InputProps>(
|
|
26
|
-
({ id, name, variants, label, placeholder, className, ...rest }, ref) => {
|
|
27
|
-
return (
|
|
28
|
-
<div className={'flex w-full flex-col'}>
|
|
29
|
-
<input
|
|
30
|
-
id={id ?? name}
|
|
31
|
-
name={name}
|
|
32
|
-
placeholder={placeholder ?? ' '}
|
|
33
|
-
className={clsx(inputBox(placeholder, label, className))}
|
|
34
|
-
{...rest}
|
|
35
|
-
ref={ref}
|
|
36
|
-
/>
|
|
37
|
-
<label
|
|
38
|
-
htmlFor={id ?? name}
|
|
39
|
-
className={labelStyle({ intent: variants?.intent, placeholder })}
|
|
40
|
-
>
|
|
41
|
-
{label}
|
|
42
|
-
</label>
|
|
43
|
-
</div>
|
|
44
|
-
);
|
|
45
|
-
}
|
|
46
|
-
);
|
|
47
|
-
|
|
48
|
-
type DivBaseProps = React.HTMLAttributes<HTMLDivElement>;
|
|
49
|
-
type InputFaceProps = DivBaseProps & Pick<InputPropsBase, 'variants'>;
|
|
50
|
-
|
|
51
|
-
export const Face = React.forwardRef<HTMLDivElement, InputFaceProps>(
|
|
52
|
-
({ children, variants, className, ...rest }, ref) => {
|
|
53
|
-
const clones = getValidChildren(children).map(el => {
|
|
54
|
-
return React.cloneElement(el, { ...el.props, variants });
|
|
55
|
-
});
|
|
56
|
-
return (
|
|
57
|
-
<div
|
|
58
|
-
{...rest}
|
|
59
|
-
className={clsx(input(variants), className)}
|
|
60
|
-
id={'input-face'}
|
|
61
|
-
ref={ref}
|
|
62
|
-
>
|
|
63
|
-
{clones}
|
|
64
|
-
</div>
|
|
65
|
-
);
|
|
66
|
-
}
|
|
67
|
-
);
|
|
68
|
-
|
|
69
|
-
export const Root = React.forwardRef<HTMLInputElement, InputProps>(
|
|
70
|
-
({ variants, className, ...rest }, ref) => {
|
|
71
|
-
return (
|
|
72
|
-
<Face variants={variants} className={className}>
|
|
73
|
-
<Box {...rest} ref={ref} />
|
|
74
|
-
</Face>
|
|
75
|
-
);
|
|
76
|
-
}
|
|
77
|
-
);
|
|
78
|
-
|
|
79
|
-
type InputElementsProps = DivBaseProps & {
|
|
80
|
-
children: React.ReactNode;
|
|
81
|
-
className?: string;
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
export const Left = React.forwardRef<HTMLDivElement, InputElementsProps>(
|
|
85
|
-
({ children, className, ...rest }, ref) => {
|
|
86
|
-
return (
|
|
87
|
-
<div className={clsx(className, 'mr-2.5')} {...rest} ref={ref}>
|
|
88
|
-
{children}
|
|
89
|
-
</div>
|
|
90
|
-
);
|
|
91
|
-
}
|
|
92
|
-
);
|
|
93
|
-
|
|
94
|
-
export const Right = React.forwardRef<HTMLDivElement, InputElementsProps>(
|
|
95
|
-
({ children, className, ...rest }, ref) => {
|
|
96
|
-
return (
|
|
97
|
-
<div className={clsx(className, 'ml-2.5')} {...rest} ref={ref}>
|
|
98
|
-
{children}
|
|
99
|
-
</div>
|
|
100
|
-
);
|
|
101
|
-
}
|
|
102
|
-
);
|
|
103
|
-
|
|
104
|
-
export const Input = {
|
|
105
|
-
Root,
|
|
106
|
-
Face,
|
|
107
|
-
Box,
|
|
108
|
-
Left,
|
|
109
|
-
Right,
|
|
110
|
-
};
|
package/src/components/Modal.tsx
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import React, { forwardRef, InputHTMLAttributes } from 'react'
|
|
2
|
-
import { modal, overlay } from '@tecsinapse/cortex-core'
|
|
3
|
-
|
|
4
|
-
interface ModalProps {
|
|
5
|
-
open: boolean
|
|
6
|
-
onClose: () => void
|
|
7
|
-
children: JSX.Element
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export const Modal = forwardRef<HTMLDivElement, ModalProps & InputHTMLAttributes<HTMLInputElement>>((props, ref) => {
|
|
11
|
-
const { open, onClose, children, className } = props
|
|
12
|
-
return (
|
|
13
|
-
<div
|
|
14
|
-
ref={ref}
|
|
15
|
-
{...props}
|
|
16
|
-
>
|
|
17
|
-
<div
|
|
18
|
-
className={overlay({ show: open })}
|
|
19
|
-
onClick={onClose}
|
|
20
|
-
></div>
|
|
21
|
-
<dialog className={modal({ open, className })}>{children}</dialog>
|
|
22
|
-
</div>
|
|
23
|
-
)
|
|
24
|
-
})
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
// import { Button, Input, searchInputVariants } from '@web/modules/core'
|
|
2
|
-
import React, { useEffect, useState } from 'react';
|
|
3
|
-
// import CircularLoading from './CircularLoading'
|
|
4
|
-
import { Input, Button } from './';
|
|
5
|
-
import { AiOutlineLoading } from 'react-icons/ai';
|
|
6
|
-
import { IoSearchOutline } from 'react-icons/io5';
|
|
7
|
-
import { useDebouncedState } from '../hooks';
|
|
8
|
-
|
|
9
|
-
interface SearchInputProps {
|
|
10
|
-
label?: string;
|
|
11
|
-
placeholder?: string;
|
|
12
|
-
isSubmitting?: boolean;
|
|
13
|
-
onChange?: (value: string) => void;
|
|
14
|
-
onClick?: (value: string) => void;
|
|
15
|
-
BOUNCE_TIMEOUT?: number;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
const inputFace = 'bg-white w-full';
|
|
19
|
-
const inputLeft = 'flex items-center';
|
|
20
|
-
const SearchInput = ({
|
|
21
|
-
label,
|
|
22
|
-
placeholder,
|
|
23
|
-
isSubmitting = false,
|
|
24
|
-
onChange,
|
|
25
|
-
onClick,
|
|
26
|
-
BOUNCE_TIMEOUT = 1000,
|
|
27
|
-
}: SearchInputProps) => {
|
|
28
|
-
const [bouncedText, setBouncedText] = useState<string>('');
|
|
29
|
-
const [searchInput, setSearchInput] = useDebouncedState<string>(
|
|
30
|
-
'',
|
|
31
|
-
setBouncedText,
|
|
32
|
-
BOUNCE_TIMEOUT
|
|
33
|
-
);
|
|
34
|
-
|
|
35
|
-
useEffect(() => {
|
|
36
|
-
if (onChange) {
|
|
37
|
-
onChange(bouncedText);
|
|
38
|
-
}
|
|
39
|
-
}, [bouncedText]);
|
|
40
|
-
|
|
41
|
-
const handleEnterKey = (e: React.KeyboardEvent) => {
|
|
42
|
-
if (e.key === 'Enter' && onClick && searchInput) {
|
|
43
|
-
onClick(searchInput);
|
|
44
|
-
}
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
return (
|
|
48
|
-
<div className="flex flex-row w-full space-x-mili">
|
|
49
|
-
<Input.Face variants={{ className: inputFace }}>
|
|
50
|
-
{!onClick && (
|
|
51
|
-
<Input.Left className={inputLeft}>
|
|
52
|
-
<IoSearchOutline />
|
|
53
|
-
</Input.Left>
|
|
54
|
-
)}
|
|
55
|
-
<Input.Box
|
|
56
|
-
placeholder={placeholder}
|
|
57
|
-
label={label}
|
|
58
|
-
onChange={e => setSearchInput(e.target.value)}
|
|
59
|
-
onKeyDown={handleEnterKey}
|
|
60
|
-
disabled={isSubmitting}
|
|
61
|
-
/>
|
|
62
|
-
</Input.Face>
|
|
63
|
-
{onClick && (
|
|
64
|
-
<Button
|
|
65
|
-
variants={{
|
|
66
|
-
intent: 'primary',
|
|
67
|
-
size: 'square',
|
|
68
|
-
className: 'h-11',
|
|
69
|
-
}}
|
|
70
|
-
onClick={() => onClick(searchInput)}
|
|
71
|
-
disabled={!searchInput || isSubmitting}
|
|
72
|
-
>
|
|
73
|
-
{isSubmitting ? (
|
|
74
|
-
<div className={'animate-spin'}>
|
|
75
|
-
<AiOutlineLoading />
|
|
76
|
-
</div>
|
|
77
|
-
) : (
|
|
78
|
-
<IoSearchOutline />
|
|
79
|
-
)}
|
|
80
|
-
</Button>
|
|
81
|
-
)}
|
|
82
|
-
</div>
|
|
83
|
-
);
|
|
84
|
-
};
|
|
85
|
-
|
|
86
|
-
export default SearchInput;
|
|
@@ -1,170 +0,0 @@
|
|
|
1
|
-
import { option as styleOption, selectVariants } from '@tecsinapse/cortex-core';
|
|
2
|
-
import React, {
|
|
3
|
-
useCallback,
|
|
4
|
-
useEffect,
|
|
5
|
-
useMemo,
|
|
6
|
-
useRef,
|
|
7
|
-
useState,
|
|
8
|
-
} from 'react';
|
|
9
|
-
import { Hint } from './Hint';
|
|
10
|
-
import { IoChevronDownOutline } from 'react-icons/io5';
|
|
11
|
-
import { IoIosCloseCircleOutline } from 'react-icons/io';
|
|
12
|
-
import SearchInput from './SearchInput';
|
|
13
|
-
|
|
14
|
-
interface CommonProps<T> {
|
|
15
|
-
label: string;
|
|
16
|
-
value: T | undefined;
|
|
17
|
-
onSelect: (value: T) => void;
|
|
18
|
-
keyExtractor: (value: T) => string;
|
|
19
|
-
labelExtractor: (value: T) => string;
|
|
20
|
-
onSearch?: (search: string) => void;
|
|
21
|
-
disabled?: boolean;
|
|
22
|
-
grouped?: boolean;
|
|
23
|
-
variant?: 'error' | 'default';
|
|
24
|
-
hint?: string;
|
|
25
|
-
placeholderSearchInput?: string;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
interface GroupedProps<T> {
|
|
29
|
-
options?: Map<string, T[]>;
|
|
30
|
-
groupedLabelExtractor: (value: string) => string;
|
|
31
|
-
grouped: true;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
interface DefaultProps<T> {
|
|
35
|
-
options?: T[];
|
|
36
|
-
groupedLabelExtractor?: never;
|
|
37
|
-
grouped?: never;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
type ConditionalProps<T> = GroupedProps<T> | DefaultProps<T>;
|
|
41
|
-
|
|
42
|
-
type SelectProps<T> = CommonProps<T> & ConditionalProps<T>;
|
|
43
|
-
|
|
44
|
-
const { button, dropdown, groupedTitle, containerGrouped, hintBody } =
|
|
45
|
-
selectVariants();
|
|
46
|
-
|
|
47
|
-
export const Select = <T,>(props: SelectProps<T>) => {
|
|
48
|
-
const {
|
|
49
|
-
label,
|
|
50
|
-
keyExtractor,
|
|
51
|
-
labelExtractor,
|
|
52
|
-
options,
|
|
53
|
-
value,
|
|
54
|
-
onSelect,
|
|
55
|
-
onSearch,
|
|
56
|
-
disabled,
|
|
57
|
-
grouped,
|
|
58
|
-
groupedLabelExtractor,
|
|
59
|
-
hint,
|
|
60
|
-
placeholderSearchInput,
|
|
61
|
-
variant = 'default',
|
|
62
|
-
} = props;
|
|
63
|
-
const [open, setOpen] = useState(false);
|
|
64
|
-
const placeholder = useMemo(
|
|
65
|
-
() => (value ? labelExtractor(value) : label),
|
|
66
|
-
[label, labelExtractor, value]
|
|
67
|
-
);
|
|
68
|
-
const ref = useRef<HTMLDivElement>(null);
|
|
69
|
-
|
|
70
|
-
const handleClickOutside = useCallback((event: any) => {
|
|
71
|
-
if (ref.current && !ref.current.contains(event.target)) {
|
|
72
|
-
setOpen(false);
|
|
73
|
-
}
|
|
74
|
-
}, []);
|
|
75
|
-
|
|
76
|
-
const handleSelect = useCallback(
|
|
77
|
-
(option: T) => {
|
|
78
|
-
onSelect(option);
|
|
79
|
-
setOpen(false);
|
|
80
|
-
},
|
|
81
|
-
[onSelect]
|
|
82
|
-
);
|
|
83
|
-
|
|
84
|
-
useEffect(() => {
|
|
85
|
-
document.addEventListener('click', handleClickOutside, true);
|
|
86
|
-
return () => {
|
|
87
|
-
document.removeEventListener('click', handleClickOutside, true);
|
|
88
|
-
};
|
|
89
|
-
}, [handleClickOutside]);
|
|
90
|
-
|
|
91
|
-
const Option = ({ option }: { option: T }) => (
|
|
92
|
-
<li
|
|
93
|
-
onClick={() => handleSelect(option)}
|
|
94
|
-
className={styleOption()}
|
|
95
|
-
role={'option'}
|
|
96
|
-
>
|
|
97
|
-
{labelExtractor(option)}
|
|
98
|
-
</li>
|
|
99
|
-
);
|
|
100
|
-
|
|
101
|
-
const GroupedOptions = ({ options }: { options?: Map<string, T[]> }) => (
|
|
102
|
-
<>
|
|
103
|
-
{[...(options ?? [])].map(([key, value]) => (
|
|
104
|
-
<div key={key} className={containerGrouped()}>
|
|
105
|
-
<span className={groupedTitle()}>{groupedLabelExtractor?.(key)}</span>
|
|
106
|
-
{value.map((option: T) => (
|
|
107
|
-
<Option option={option} key={keyExtractor(option)} />
|
|
108
|
-
))}
|
|
109
|
-
</div>
|
|
110
|
-
))}
|
|
111
|
-
</>
|
|
112
|
-
);
|
|
113
|
-
|
|
114
|
-
const DefaultOptions = ({ options }: { options?: T[] }) => (
|
|
115
|
-
<>
|
|
116
|
-
{(options ?? []).map(option => (
|
|
117
|
-
<Option option={option} key={keyExtractor(option)} />
|
|
118
|
-
))}
|
|
119
|
-
</>
|
|
120
|
-
);
|
|
121
|
-
|
|
122
|
-
return (
|
|
123
|
-
<div className="w-full relative bg-white" ref={ref}>
|
|
124
|
-
<button
|
|
125
|
-
className={button({ disabled, intent: variant })}
|
|
126
|
-
onClick={() => setOpen(prevState => !prevState)}
|
|
127
|
-
disabled={disabled}
|
|
128
|
-
>
|
|
129
|
-
<span>{placeholder}</span>
|
|
130
|
-
<IoChevronDownOutline />
|
|
131
|
-
</button>
|
|
132
|
-
<ul
|
|
133
|
-
role={'select'}
|
|
134
|
-
className={dropdown({
|
|
135
|
-
open,
|
|
136
|
-
})}
|
|
137
|
-
>
|
|
138
|
-
{onSearch ? (
|
|
139
|
-
<div className="m-mili">
|
|
140
|
-
<SearchInput
|
|
141
|
-
placeholder={placeholderSearchInput}
|
|
142
|
-
onChange={onSearch}
|
|
143
|
-
/>
|
|
144
|
-
</div>
|
|
145
|
-
) : (
|
|
146
|
-
<></>
|
|
147
|
-
)}
|
|
148
|
-
{grouped ? (
|
|
149
|
-
<GroupedOptions options={options} />
|
|
150
|
-
) : (
|
|
151
|
-
<DefaultOptions options={options} />
|
|
152
|
-
)}
|
|
153
|
-
</ul>
|
|
154
|
-
{hint && (
|
|
155
|
-
<Hint
|
|
156
|
-
variants={{
|
|
157
|
-
intent: variant,
|
|
158
|
-
}}
|
|
159
|
-
>
|
|
160
|
-
<div className={hintBody()}>
|
|
161
|
-
{variant === 'error' ? <IoIosCloseCircleOutline /> : <></>}
|
|
162
|
-
<span>{hint}</span>
|
|
163
|
-
</div>
|
|
164
|
-
</Hint>
|
|
165
|
-
)}
|
|
166
|
-
</div>
|
|
167
|
-
);
|
|
168
|
-
};
|
|
169
|
-
|
|
170
|
-
export default Select;
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import React, { forwardRef } from 'react'
|
|
2
|
-
import { snackbar, SnackbarVariants } from '@tecsinapse/cortex-core'
|
|
3
|
-
|
|
4
|
-
interface SnackbarProps {
|
|
5
|
-
variants?: SnackbarVariants
|
|
6
|
-
children: JSX.Element
|
|
7
|
-
show: boolean
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export const Snackbar = forwardRef<HTMLDivElement, SnackbarProps>((props, ref) => {
|
|
11
|
-
const { children, show, variants } = props
|
|
12
|
-
return (
|
|
13
|
-
<>
|
|
14
|
-
{show ? (
|
|
15
|
-
<div
|
|
16
|
-
className={snackbar(variants)}
|
|
17
|
-
ref={ref}
|
|
18
|
-
>
|
|
19
|
-
{children}
|
|
20
|
-
</div>
|
|
21
|
-
) : (
|
|
22
|
-
<></>
|
|
23
|
-
)}
|
|
24
|
-
</>
|
|
25
|
-
)
|
|
26
|
-
})
|
package/src/components/Tag.tsx
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import React, { forwardRef, HTMLProps } from 'react'
|
|
2
|
-
import { tag, TagVariants } from '@tecsinapse/cortex-core'
|
|
3
|
-
|
|
4
|
-
interface TagProps {
|
|
5
|
-
variants?: TagVariants
|
|
6
|
-
label: string
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export const Tag = forwardRef<HTMLDivElement, TagProps & HTMLProps<HTMLDivElement>>((props, ref) => {
|
|
10
|
-
const { label, variants } = props
|
|
11
|
-
return (
|
|
12
|
-
<div
|
|
13
|
-
className={tag(variants)}
|
|
14
|
-
ref={ref}
|
|
15
|
-
>
|
|
16
|
-
<p>{label}</p>
|
|
17
|
-
</div>
|
|
18
|
-
)
|
|
19
|
-
})
|
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import {
|
|
3
|
-
input,
|
|
4
|
-
InputBaseVariants,
|
|
5
|
-
inputBox,
|
|
6
|
-
labelStyle,
|
|
7
|
-
} from '@tecsinapse/cortex-core';
|
|
8
|
-
import { clsx } from 'clsx';
|
|
9
|
-
|
|
10
|
-
const getValidChildren = (children: React.ReactNode) => {
|
|
11
|
-
return React.Children.toArray(children).filter(el =>
|
|
12
|
-
React.isValidElement(el)
|
|
13
|
-
) as React.ReactElement[];
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
interface TextAreaPropsBase {
|
|
17
|
-
variants?: InputBaseVariants;
|
|
18
|
-
label?: string;
|
|
19
|
-
rows?: number;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
interface TextAreaProps
|
|
23
|
-
extends React.TextareaHTMLAttributes<HTMLTextAreaElement>,
|
|
24
|
-
TextAreaPropsBase {}
|
|
25
|
-
|
|
26
|
-
const Box = React.forwardRef<HTMLTextAreaElement, TextAreaProps>(
|
|
27
|
-
(
|
|
28
|
-
{ id, name, variants, label, placeholder, rows, className, ...rest },
|
|
29
|
-
ref
|
|
30
|
-
) => {
|
|
31
|
-
return (
|
|
32
|
-
<div className="flex w-full flex-col">
|
|
33
|
-
<textarea
|
|
34
|
-
ref={ref}
|
|
35
|
-
id={id ?? name}
|
|
36
|
-
name={name}
|
|
37
|
-
placeholder={placeholder ?? ' '}
|
|
38
|
-
className={clsx(
|
|
39
|
-
inputBox(placeholder, label, className),
|
|
40
|
-
'resize-none mt-mili'
|
|
41
|
-
)}
|
|
42
|
-
rows={rows}
|
|
43
|
-
{...rest}
|
|
44
|
-
/>
|
|
45
|
-
<label
|
|
46
|
-
htmlFor={id ?? name}
|
|
47
|
-
className={labelStyle({
|
|
48
|
-
intent: variants?.intent,
|
|
49
|
-
placeholder,
|
|
50
|
-
})}
|
|
51
|
-
>
|
|
52
|
-
{label}
|
|
53
|
-
</label>
|
|
54
|
-
</div>
|
|
55
|
-
);
|
|
56
|
-
}
|
|
57
|
-
);
|
|
58
|
-
|
|
59
|
-
type DivBaseProps = React.HTMLAttributes<HTMLDivElement>;
|
|
60
|
-
type TextAreaFaceProps = DivBaseProps & Pick<TextAreaPropsBase, 'variants'>;
|
|
61
|
-
|
|
62
|
-
const Face = React.forwardRef<HTMLDivElement, TextAreaFaceProps>(
|
|
63
|
-
({ children, variants, className, ...rest }, ref) => {
|
|
64
|
-
const clones = getValidChildren(children).map(el => {
|
|
65
|
-
return React.cloneElement(el, { ...el.props, variants });
|
|
66
|
-
});
|
|
67
|
-
return (
|
|
68
|
-
<div
|
|
69
|
-
ref={ref}
|
|
70
|
-
className={clsx(input(variants), className)}
|
|
71
|
-
id="textarea-face"
|
|
72
|
-
{...rest}
|
|
73
|
-
>
|
|
74
|
-
{clones}
|
|
75
|
-
</div>
|
|
76
|
-
);
|
|
77
|
-
}
|
|
78
|
-
);
|
|
79
|
-
|
|
80
|
-
const Root = React.forwardRef<HTMLTextAreaElement, TextAreaProps>(
|
|
81
|
-
({ variants, className, ...rest }, ref) => {
|
|
82
|
-
return (
|
|
83
|
-
<Face variants={variants} className={className}>
|
|
84
|
-
<Box ref={ref} {...rest} />
|
|
85
|
-
</Face>
|
|
86
|
-
);
|
|
87
|
-
}
|
|
88
|
-
);
|
|
89
|
-
|
|
90
|
-
type TextAreaElementsProps = DivBaseProps & {
|
|
91
|
-
children: React.ReactNode;
|
|
92
|
-
className?: string;
|
|
93
|
-
};
|
|
94
|
-
|
|
95
|
-
const Left = React.forwardRef<HTMLDivElement, TextAreaElementsProps>(
|
|
96
|
-
({ children, className, ...rest }, ref) => {
|
|
97
|
-
return (
|
|
98
|
-
<div className={clsx(className, 'mr-2.5')} {...rest} ref={ref}>
|
|
99
|
-
{children}
|
|
100
|
-
</div>
|
|
101
|
-
);
|
|
102
|
-
}
|
|
103
|
-
);
|
|
104
|
-
|
|
105
|
-
const Right = React.forwardRef<HTMLDivElement, TextAreaElementsProps>(
|
|
106
|
-
({ children, className, ...rest }, ref) => {
|
|
107
|
-
return (
|
|
108
|
-
<div className={clsx(className, 'ml-2.5')} {...rest} ref={ref}>
|
|
109
|
-
{children}
|
|
110
|
-
</div>
|
|
111
|
-
);
|
|
112
|
-
}
|
|
113
|
-
);
|
|
114
|
-
|
|
115
|
-
export const TextArea = {
|
|
116
|
-
Root,
|
|
117
|
-
Face,
|
|
118
|
-
Box,
|
|
119
|
-
Left,
|
|
120
|
-
Right,
|
|
121
|
-
};
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import React, { forwardRef, InputHTMLAttributes } from 'react';
|
|
2
|
-
import {
|
|
3
|
-
styleInputElement,
|
|
4
|
-
styleLabelElement,
|
|
5
|
-
toggle,
|
|
6
|
-
} from '@tecsinapse/cortex-core';
|
|
7
|
-
|
|
8
|
-
export const Toggle = forwardRef<
|
|
9
|
-
HTMLInputElement,
|
|
10
|
-
InputHTMLAttributes<HTMLInputElement>
|
|
11
|
-
>((props, ref) => {
|
|
12
|
-
return (
|
|
13
|
-
<div className={'flex flex-row items-center gap-x-centi'}>
|
|
14
|
-
<label className={styleLabelElement()}>
|
|
15
|
-
<input
|
|
16
|
-
type="checkbox"
|
|
17
|
-
className={styleInputElement()}
|
|
18
|
-
ref={ref}
|
|
19
|
-
{...props}
|
|
20
|
-
/>
|
|
21
|
-
<div className={toggle()} />
|
|
22
|
-
</label>
|
|
23
|
-
</div>
|
|
24
|
-
);
|
|
25
|
-
});
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { StoryFn } from '@storybook/react';
|
|
3
|
-
import { BadgeAnchor, Button } from '../index';
|
|
4
|
-
import { defaultIntents } from './utils';
|
|
5
|
-
|
|
6
|
-
export default {
|
|
7
|
-
title: 'Cortex-React/Badge/Anchor',
|
|
8
|
-
component: <div />,
|
|
9
|
-
args: {
|
|
10
|
-
value: 1,
|
|
11
|
-
intent: 'primary',
|
|
12
|
-
},
|
|
13
|
-
argTypes: {
|
|
14
|
-
intent: {
|
|
15
|
-
options: defaultIntents,
|
|
16
|
-
control: { type: 'select' },
|
|
17
|
-
},
|
|
18
|
-
value: {
|
|
19
|
-
control: { type: 'number' },
|
|
20
|
-
min: 1,
|
|
21
|
-
max: 9,
|
|
22
|
-
},
|
|
23
|
-
},
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
const Template: StoryFn = args => {
|
|
27
|
-
return (
|
|
28
|
-
<BadgeAnchor
|
|
29
|
-
variants={{ intent: args.intent, isAnchor: true }}
|
|
30
|
-
value={args.value}
|
|
31
|
-
>
|
|
32
|
-
<Button variants={{ variant: 'outline' }}>
|
|
33
|
-
<p>Button</p>
|
|
34
|
-
</Button>
|
|
35
|
-
</BadgeAnchor>
|
|
36
|
-
);
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
export const Base = {
|
|
40
|
-
render: Template,
|
|
41
|
-
args: {},
|
|
42
|
-
};
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { StoryFn } from '@storybook/react';
|
|
3
|
-
import { Badge } from '../index';
|
|
4
|
-
import { defaultIntents } from './utils';
|
|
5
|
-
|
|
6
|
-
export default {
|
|
7
|
-
title: 'Cortex-React/Badge',
|
|
8
|
-
component: <div />,
|
|
9
|
-
args: {
|
|
10
|
-
value: '1',
|
|
11
|
-
intent: 'primary',
|
|
12
|
-
},
|
|
13
|
-
argTypes: {
|
|
14
|
-
intent: {
|
|
15
|
-
options: defaultIntents,
|
|
16
|
-
control: { type: 'select' },
|
|
17
|
-
},
|
|
18
|
-
value: {
|
|
19
|
-
control: { type: 'text' },
|
|
20
|
-
},
|
|
21
|
-
},
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
const Template: StoryFn = args => {
|
|
25
|
-
return <Badge variants={{ intent: args.intent }} value={args.value ?? '2'} />;
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
export const Base = {
|
|
29
|
-
render: Template,
|
|
30
|
-
args: {},
|
|
31
|
-
};
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { StoryFn } from '@storybook/react';
|
|
3
|
-
import { Button } from '../index';
|
|
4
|
-
|
|
5
|
-
export default {
|
|
6
|
-
title: 'Cortex-React/Button',
|
|
7
|
-
component: <div />,
|
|
8
|
-
argTypes: {
|
|
9
|
-
intent: {
|
|
10
|
-
options: ['primary', 'secondary', 'success', 'info', 'warning', 'error'],
|
|
11
|
-
control: { type: 'select' },
|
|
12
|
-
},
|
|
13
|
-
variant: {
|
|
14
|
-
options: ['outline', 'text', 'filled'],
|
|
15
|
-
control: { type: 'select' },
|
|
16
|
-
},
|
|
17
|
-
size: {
|
|
18
|
-
options: ['small', 'default', 'circle', 'square'],
|
|
19
|
-
control: { type: 'select' },
|
|
20
|
-
},
|
|
21
|
-
},
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
const Template: StoryFn = args => {
|
|
25
|
-
return (
|
|
26
|
-
<Button
|
|
27
|
-
variants={{ intent: args.intent, variant: args.variant, size: args.size }}
|
|
28
|
-
>
|
|
29
|
-
<p>Button</p>
|
|
30
|
-
</Button>
|
|
31
|
-
);
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
export const Base = {
|
|
35
|
-
render: Template,
|
|
36
|
-
args: {},
|
|
37
|
-
};
|