@bodynarf/react.components 1.1.1 → 1.1.6
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/{src/components → components}/anchor/anchor.scss +0 -0
- package/components/anchor/components/anchorWithIcon/index.d.ts +5 -0
- package/components/anchor/components/anchorWithIcon/index.d.ts.map +1 -0
- package/components/anchor/components/anchorWithIcon/index.js +16 -0
- package/components/anchor/components/simpleAnchor/index.d.ts +5 -0
- package/components/anchor/components/simpleAnchor/index.d.ts.map +1 -0
- package/components/anchor/components/simpleAnchor/index.js +5 -0
- package/components/anchor/index.d.ts +24 -0
- package/components/anchor/index.d.ts.map +1 -0
- package/components/anchor/index.js +18 -0
- package/{src/components/anchor/types.ts → components/anchor/types.d.ts} +3 -9
- package/components/anchor/types.d.ts.map +1 -0
- package/components/anchor/types.js +1 -0
- package/{src/components → components}/button/button.scss +0 -0
- package/components/button/components/buttonWithIcon/index.d.ts +5 -0
- package/components/button/components/buttonWithIcon/index.d.ts.map +1 -0
- package/components/button/components/buttonWithIcon/index.js +19 -0
- package/components/button/components/simpleButton/index.d.ts +5 -0
- package/components/button/components/simpleButton/index.d.ts.map +1 -0
- package/components/button/components/simpleButton/index.js +5 -0
- package/components/button/index.d.ts +34 -0
- package/components/button/index.d.ts.map +1 -0
- package/components/button/index.js +29 -0
- package/components/button/types.d.ts +20 -0
- package/components/button/types.d.ts.map +1 -0
- package/components/button/types.js +1 -0
- package/components/dropdown/components/dropdownItem/index.d.ts +15 -0
- package/components/dropdown/components/dropdownItem/index.d.ts.map +1 -0
- package/components/dropdown/components/dropdownItem/index.js +6 -0
- package/components/dropdown/components/dropdownLabel/index.d.ts +16 -0
- package/components/dropdown/components/dropdownLabel/index.d.ts.map +1 -0
- package/components/dropdown/components/dropdownLabel/index.js +20 -0
- package/{src/components → components}/dropdown/dropdown.scss +0 -0
- package/components/dropdown/index.d.ts +31 -0
- package/components/dropdown/index.d.ts.map +1 -0
- package/components/dropdown/index.js +55 -0
- package/{src/components/dropdown/types.ts → components/dropdown/types.d.ts} +3 -4
- package/components/dropdown/types.d.ts.map +1 -0
- package/components/dropdown/types.js +1 -0
- package/{src/components → components}/icon/icon.scss +0 -0
- package/components/icon/index.d.ts +18 -0
- package/components/icon/index.d.ts.map +1 -0
- package/components/icon/index.js +15 -0
- package/components/primitives/date/index.d.ts +11 -0
- package/components/primitives/date/index.d.ts.map +1 -0
- package/components/primitives/date/index.js +31 -0
- package/components/primitives/index.d.ts +5 -0
- package/components/primitives/index.d.ts.map +1 -0
- package/components/primitives/index.js +4 -0
- package/components/primitives/multiline/components/multilineWithLabel/index.d.ts +6 -0
- package/components/primitives/multiline/components/multilineWithLabel/index.d.ts.map +1 -0
- package/components/primitives/multiline/components/multilineWithLabel/index.js +29 -0
- package/components/primitives/multiline/components/multilineWithoutLabel/index.d.ts +6 -0
- package/components/primitives/multiline/components/multilineWithoutLabel/index.d.ts.map +1 -0
- package/components/primitives/multiline/components/multilineWithoutLabel/index.js +25 -0
- package/components/primitives/multiline/index.d.ts +13 -0
- package/components/primitives/multiline/index.d.ts.map +1 -0
- package/components/primitives/multiline/index.js +14 -0
- package/components/primitives/text/components/textWithLabel/index.d.ts +6 -0
- package/components/primitives/text/components/textWithLabel/index.d.ts.map +1 -0
- package/components/primitives/text/components/textWithLabel/index.js +28 -0
- package/components/primitives/text/components/textWithoutLabel/index.d.ts +6 -0
- package/components/primitives/text/components/textWithoutLabel/index.d.ts.map +1 -0
- package/components/primitives/text/components/textWithoutLabel/index.js +24 -0
- package/components/primitives/text/index.d.ts +8 -0
- package/components/primitives/text/index.d.ts.map +1 -0
- package/components/primitives/text/index.js +14 -0
- package/{src/components/primitives/types.ts → components/primitives/types.d.ts} +5 -32
- package/components/primitives/types.d.ts.map +1 -0
- package/components/primitives/types.js +1 -0
- package/components/search/index.d.ts +31 -0
- package/components/search/index.d.ts.map +1 -0
- package/components/search/index.js +41 -0
- package/{src/components → components}/search/search.scss +0 -0
- package/{src/components/types.ts → components/types.d.ts} +5 -16
- package/components/types.d.ts.map +1 -0
- package/components/types.js +1 -0
- package/hooks/index.d.ts +2 -0
- package/hooks/index.d.ts.map +1 -0
- package/hooks/index.js +1 -0
- package/hooks/useComponentOutsideClick.d.ts +11 -0
- package/hooks/useComponentOutsideClick.d.ts.map +1 -0
- package/hooks/useComponentOutsideClick.js +32 -0
- package/index.d.ts +10 -0
- package/index.d.ts.map +1 -0
- package/index.js +9 -0
- package/package.json +10 -21
- package/.github/ISSUE_TEMPLATE/bug_report.md +0 -25
- package/anchor.ts +0 -10
- package/button.ts +0 -11
- package/date.ts +0 -7
- package/dropdown.ts +0 -9
- package/hooks.ts +0 -5
- package/icon.ts +0 -7
- package/index.html +0 -13
- package/index.ts +0 -14
- package/multiline.ts +0 -7
- package/search.ts +0 -7
- package/src/components/anchor/components/anchorWithIcon/anchorWithIcon.tsx +0 -45
- package/src/components/anchor/components/simpleAnchor/simpleAnchor.tsx +0 -16
- package/src/components/anchor/index.tsx +0 -64
- package/src/components/button/components/buttonWithIcon/buttonWithIcon.tsx +0 -47
- package/src/components/button/components/simpleButton/simpleButton.tsx +0 -16
- package/src/components/button/index.tsx +0 -83
- package/src/components/button/types.ts +0 -40
- package/src/components/dropdown/components/dropdownItem/dropdownItem.tsx +0 -30
- package/src/components/dropdown/components/dropdownLabel/dropdownLabel.tsx +0 -60
- package/src/components/dropdown/index.tsx +0 -141
- package/src/components/icon/index.tsx +0 -34
- package/src/components/primitives/date/index.tsx +0 -103
- package/src/components/primitives/multiline/components/multilineWithLabel/index.tsx +0 -93
- package/src/components/primitives/multiline/components/multilineWithoutLabel/index.tsx +0 -51
- package/src/components/primitives/multiline/index.tsx +0 -28
- package/src/components/primitives/text/components/textWithLabel/index.tsx +0 -92
- package/src/components/primitives/text/components/textWithoutLabel/index.tsx +0 -49
- package/src/components/primitives/text/index.tsx +0 -21
- package/src/components/search/index.tsx +0 -127
- package/src/hooks/useComponentOutsideClick.ts +0 -48
- package/src/main.tsx +0 -9
- package/text.ts +0 -7
- package/tsconfig.json +0 -39
- package/tsconfig.node.json +0 -8
- package/vite.config.ts +0 -14
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
import { ChangeEvent, useCallback } from 'react';
|
|
2
|
-
|
|
3
|
-
import { generateGuid } from '@bodynarf/utils/guid';
|
|
4
|
-
import { getClassName } from '@bodynarf/utils/component';
|
|
5
|
-
import { isStringEmpty } from '@bodynarf/utils/common';
|
|
6
|
-
|
|
7
|
-
import { BaseInputElementProps, InputLabel } from '../types';
|
|
8
|
-
|
|
9
|
-
/** Date input conponent props type */
|
|
10
|
-
export type DateProps = Omit<BaseInputElementProps<Date | undefined>, 'placeholder'> & {
|
|
11
|
-
/** Label configuration */
|
|
12
|
-
label: InputLabel;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
/** Date input component */
|
|
16
|
-
const DatePicker = (props: DateProps): JSX.Element => {
|
|
17
|
-
const onValueChange = useCallback(
|
|
18
|
-
(event: ChangeEvent<HTMLInputElement>) =>
|
|
19
|
-
props.onValueChange(
|
|
20
|
-
isStringEmpty(event.target.value)
|
|
21
|
-
? undefined
|
|
22
|
-
: new Date(event.target.value)
|
|
23
|
-
),
|
|
24
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
25
|
-
[props.onValueChange]
|
|
26
|
-
);
|
|
27
|
-
|
|
28
|
-
const id = props.name || generateGuid();
|
|
29
|
-
|
|
30
|
-
const size = `is-${(props.size || 'normal')}`;
|
|
31
|
-
|
|
32
|
-
const className = getClassName([
|
|
33
|
-
props.className,
|
|
34
|
-
size,
|
|
35
|
-
props.rounded === true ? 'is-rounded' : '',
|
|
36
|
-
"input",
|
|
37
|
-
]);
|
|
38
|
-
|
|
39
|
-
const inputContainerClassName = getClassName([
|
|
40
|
-
"control",
|
|
41
|
-
props.loading === true ? 'is-loading' : '',
|
|
42
|
-
(props.style || 'default') === 'default' ? '' : `is-${props.style}`
|
|
43
|
-
]);
|
|
44
|
-
|
|
45
|
-
const label = props.label;
|
|
46
|
-
const defaultValue = props.defaultValue?.toISOString().split("T")[0];
|
|
47
|
-
|
|
48
|
-
if (label.horizontal === true) {
|
|
49
|
-
return (
|
|
50
|
-
<div className="app-input field is-horizontal">
|
|
51
|
-
<div className={`field-label ${size}`}>
|
|
52
|
-
<label
|
|
53
|
-
className="label"
|
|
54
|
-
htmlFor={id}
|
|
55
|
-
>
|
|
56
|
-
{label.caption}
|
|
57
|
-
</label>
|
|
58
|
-
</div>
|
|
59
|
-
<div className="field-body">
|
|
60
|
-
<div className="field">
|
|
61
|
-
<div className={inputContainerClassName}>
|
|
62
|
-
<input
|
|
63
|
-
type="date"
|
|
64
|
-
className={className}
|
|
65
|
-
readOnly={props.readonly}
|
|
66
|
-
disabled={props.disabled}
|
|
67
|
-
defaultValue={defaultValue}
|
|
68
|
-
onChange={onValueChange}
|
|
69
|
-
name={id}
|
|
70
|
-
id={id}
|
|
71
|
-
/>
|
|
72
|
-
</div>
|
|
73
|
-
</div>
|
|
74
|
-
</div>
|
|
75
|
-
</div>
|
|
76
|
-
);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
return (
|
|
80
|
-
<div className="app-input field">
|
|
81
|
-
<label
|
|
82
|
-
className={`label ${size}`}
|
|
83
|
-
htmlFor={id}
|
|
84
|
-
>
|
|
85
|
-
{label.caption}
|
|
86
|
-
</label>
|
|
87
|
-
<div className={inputContainerClassName}>
|
|
88
|
-
<input
|
|
89
|
-
type="date"
|
|
90
|
-
className={className}
|
|
91
|
-
readOnly={props.readonly}
|
|
92
|
-
disabled={props.disabled}
|
|
93
|
-
defaultValue={props.defaultValue?.toLocaleDateString()}
|
|
94
|
-
onChange={onValueChange}
|
|
95
|
-
name={id}
|
|
96
|
-
id={id}
|
|
97
|
-
/>
|
|
98
|
-
</div>
|
|
99
|
-
</div>
|
|
100
|
-
);
|
|
101
|
-
};
|
|
102
|
-
|
|
103
|
-
export default DatePicker;
|
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
import { ChangeEvent, useCallback } from 'react';
|
|
2
|
-
|
|
3
|
-
import { generateGuid } from '@bodynarf/utils/guid';
|
|
4
|
-
import { getClassName } from '@bodynarf/utils/component';
|
|
5
|
-
|
|
6
|
-
import { MultilineProps } from '../..';
|
|
7
|
-
|
|
8
|
-
/** Multiline textual input component with describing label */
|
|
9
|
-
const MultilineWithLabel = (props: MultilineProps): JSX.Element => {
|
|
10
|
-
const onValueChange = useCallback(
|
|
11
|
-
(event: ChangeEvent<HTMLTextAreaElement>) => props.onValueChange(event.target.value),
|
|
12
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
13
|
-
[props.onValueChange]
|
|
14
|
-
);
|
|
15
|
-
|
|
16
|
-
const id = props.name || generateGuid();
|
|
17
|
-
|
|
18
|
-
const size = `is-${(props.size || 'normal')}`;
|
|
19
|
-
|
|
20
|
-
const className = getClassName([
|
|
21
|
-
props.className,
|
|
22
|
-
size,
|
|
23
|
-
props.rounded === true ? 'is-rounded' : '',
|
|
24
|
-
"textarea",
|
|
25
|
-
props.fixed === true ? 'has-fixed-size': '',
|
|
26
|
-
]);
|
|
27
|
-
|
|
28
|
-
const inputContainerClassName = getClassName([
|
|
29
|
-
"control",
|
|
30
|
-
props.loading === true ? 'is-loading' : '',
|
|
31
|
-
(props.style || 'default') === 'default' ? '' : `is-${props.style}`
|
|
32
|
-
]);
|
|
33
|
-
|
|
34
|
-
const label = props.label!;
|
|
35
|
-
|
|
36
|
-
if (label.horizontal === true) {
|
|
37
|
-
return (
|
|
38
|
-
<div className="app-input field is-horizontal">
|
|
39
|
-
<div className={`field-label ${size}`}>
|
|
40
|
-
<label
|
|
41
|
-
className="label"
|
|
42
|
-
htmlFor={id}
|
|
43
|
-
>
|
|
44
|
-
{label.caption}
|
|
45
|
-
</label>
|
|
46
|
-
</div>
|
|
47
|
-
<div className="field-body">
|
|
48
|
-
<div className="field">
|
|
49
|
-
<div className={inputContainerClassName}>
|
|
50
|
-
<textarea
|
|
51
|
-
className={className}
|
|
52
|
-
placeholder={props.placeholder}
|
|
53
|
-
readOnly={props.readonly}
|
|
54
|
-
disabled={props.disabled}
|
|
55
|
-
defaultValue={props.defaultValue}
|
|
56
|
-
onChange={onValueChange}
|
|
57
|
-
name={id}
|
|
58
|
-
id={id}
|
|
59
|
-
rows={props.rows}
|
|
60
|
-
/>
|
|
61
|
-
</div>
|
|
62
|
-
</div>
|
|
63
|
-
</div>
|
|
64
|
-
</div>
|
|
65
|
-
);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
return (
|
|
69
|
-
<div className="app-input field">
|
|
70
|
-
<label
|
|
71
|
-
className={`label ${size}`}
|
|
72
|
-
htmlFor={id}
|
|
73
|
-
>
|
|
74
|
-
{label.caption}
|
|
75
|
-
</label>
|
|
76
|
-
<div className={inputContainerClassName}>
|
|
77
|
-
<textarea
|
|
78
|
-
className={className}
|
|
79
|
-
placeholder={props.placeholder}
|
|
80
|
-
readOnly={props.readonly}
|
|
81
|
-
disabled={props.disabled}
|
|
82
|
-
defaultValue={props.defaultValue}
|
|
83
|
-
onChange={onValueChange}
|
|
84
|
-
name={id}
|
|
85
|
-
id={id}
|
|
86
|
-
rows={props.rows}
|
|
87
|
-
/>
|
|
88
|
-
</div>
|
|
89
|
-
</div>
|
|
90
|
-
);
|
|
91
|
-
};
|
|
92
|
-
|
|
93
|
-
export default MultilineWithLabel;
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { ChangeEvent, useCallback } from 'react';
|
|
2
|
-
|
|
3
|
-
import { generateGuid } from '@bodynarf/utils/guid';
|
|
4
|
-
import { getClassName } from '@bodynarf/utils/component';
|
|
5
|
-
|
|
6
|
-
import { MultilineProps } from '../..';
|
|
7
|
-
|
|
8
|
-
/** Multiline textual input component without describing label*/
|
|
9
|
-
const MultilineWithoutLabel = (props: MultilineProps): JSX.Element => {
|
|
10
|
-
const onValueChange = useCallback(
|
|
11
|
-
(event: ChangeEvent<HTMLTextAreaElement>) => props.onValueChange(event.target.value),
|
|
12
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
13
|
-
[props.onValueChange]
|
|
14
|
-
);
|
|
15
|
-
|
|
16
|
-
const id = props.name || generateGuid();
|
|
17
|
-
|
|
18
|
-
const size = `is-${(props.size || 'normal')}`;
|
|
19
|
-
|
|
20
|
-
const className = getClassName([
|
|
21
|
-
props.className,
|
|
22
|
-
size,
|
|
23
|
-
props.rounded === true ? 'is-rounded' : '',
|
|
24
|
-
"textarea",
|
|
25
|
-
props.fixed === true ? 'has-fixed-size': '',
|
|
26
|
-
]);
|
|
27
|
-
|
|
28
|
-
const inputContainerClassName = getClassName([
|
|
29
|
-
"control",
|
|
30
|
-
props.loading === true ? 'is-loading' : '',
|
|
31
|
-
(props.style || 'default') === 'default' ? '' : `is-${props.style}`
|
|
32
|
-
]);
|
|
33
|
-
|
|
34
|
-
return (
|
|
35
|
-
<div className="field">
|
|
36
|
-
<div className={inputContainerClassName}>
|
|
37
|
-
<textarea
|
|
38
|
-
className={className}
|
|
39
|
-
placeholder={props.placeholder}
|
|
40
|
-
defaultValue={props.defaultValue}
|
|
41
|
-
onChange={onValueChange}
|
|
42
|
-
id={id}
|
|
43
|
-
name={id}
|
|
44
|
-
rows={props.rows}
|
|
45
|
-
/>
|
|
46
|
-
</div>
|
|
47
|
-
</div>
|
|
48
|
-
);
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
export default MultilineWithoutLabel;
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { isNullOrUndefined } from '@bodynarf/utils/common';
|
|
2
|
-
|
|
3
|
-
import { BaseInputElementProps } from '../types';
|
|
4
|
-
|
|
5
|
-
import MultilineWithoutLabel from './components/multilineWithoutLabel';
|
|
6
|
-
import MultilineWithLabel from './components/multilineWithLabel';
|
|
7
|
-
|
|
8
|
-
/** Multiline textual input conponent props type */
|
|
9
|
-
export type MultilineProps = BaseInputElementProps<string> & {
|
|
10
|
-
/** Is input should be resizable */
|
|
11
|
-
fixed?: boolean;
|
|
12
|
-
|
|
13
|
-
/** Number of initial rows count */
|
|
14
|
-
rows?: number;
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
/** Multiline textual input component */
|
|
18
|
-
const Multiline = (props: MultilineProps): JSX.Element => {
|
|
19
|
-
if (isNullOrUndefined(props.label)) {
|
|
20
|
-
return (<MultilineWithoutLabel {...props} />);
|
|
21
|
-
}
|
|
22
|
-
else {
|
|
23
|
-
return (<MultilineWithLabel {...props} />);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
export default Multiline;
|
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
import { ChangeEvent, useCallback } from 'react';
|
|
2
|
-
|
|
3
|
-
import { generateGuid } from '@bodynarf/utils/guid';
|
|
4
|
-
import { getClassName } from '@bodynarf/utils/component';
|
|
5
|
-
|
|
6
|
-
import { TextProps } from '../..';
|
|
7
|
-
|
|
8
|
-
/** Textual input with describing label */
|
|
9
|
-
const TextWithLabel = (props: TextProps): JSX.Element => {
|
|
10
|
-
const onValueChange = useCallback(
|
|
11
|
-
(event: ChangeEvent<HTMLInputElement>) => props.onValueChange(event.target.value),
|
|
12
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
13
|
-
[props.onValueChange]
|
|
14
|
-
);
|
|
15
|
-
|
|
16
|
-
const id = props.name || generateGuid();
|
|
17
|
-
|
|
18
|
-
const size = `is-${(props.size || 'normal')}`;
|
|
19
|
-
|
|
20
|
-
const className = getClassName([
|
|
21
|
-
props.className,
|
|
22
|
-
size,
|
|
23
|
-
props.rounded === true ? 'is-rounded' : '',
|
|
24
|
-
"input",
|
|
25
|
-
]);
|
|
26
|
-
|
|
27
|
-
const inputContainerClassName = getClassName([
|
|
28
|
-
"control",
|
|
29
|
-
props.loading === true ? 'is-loading' : '',
|
|
30
|
-
(props.style || 'default') === 'default' ? '' : `is-${props.style}`
|
|
31
|
-
]);
|
|
32
|
-
|
|
33
|
-
const label = props.label!;
|
|
34
|
-
|
|
35
|
-
if (label.horizontal === true) {
|
|
36
|
-
return (
|
|
37
|
-
<div className="app-input field is-horizontal">
|
|
38
|
-
<div className={`field-label ${size}`}>
|
|
39
|
-
<label
|
|
40
|
-
className="label"
|
|
41
|
-
htmlFor={id}
|
|
42
|
-
>
|
|
43
|
-
{label.caption}
|
|
44
|
-
</label>
|
|
45
|
-
</div>
|
|
46
|
-
<div className="field-body">
|
|
47
|
-
<div className="field">
|
|
48
|
-
<div className={inputContainerClassName}>
|
|
49
|
-
<input
|
|
50
|
-
className={className}
|
|
51
|
-
type="text"
|
|
52
|
-
placeholder={props.placeholder}
|
|
53
|
-
readOnly={props.readonly}
|
|
54
|
-
disabled={props.disabled}
|
|
55
|
-
defaultValue={props.defaultValue}
|
|
56
|
-
onChange={onValueChange}
|
|
57
|
-
name={id}
|
|
58
|
-
id={id}
|
|
59
|
-
/>
|
|
60
|
-
</div>
|
|
61
|
-
</div>
|
|
62
|
-
</div>
|
|
63
|
-
</div>
|
|
64
|
-
);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
return (
|
|
68
|
-
<div className="app-input field">
|
|
69
|
-
<label
|
|
70
|
-
className={`label ${size}`}
|
|
71
|
-
htmlFor={id}
|
|
72
|
-
>
|
|
73
|
-
{label.caption}
|
|
74
|
-
</label>
|
|
75
|
-
<div className={inputContainerClassName}>
|
|
76
|
-
<input
|
|
77
|
-
className={className}
|
|
78
|
-
type="text"
|
|
79
|
-
placeholder={props.placeholder}
|
|
80
|
-
readOnly={props.readonly}
|
|
81
|
-
disabled={props.disabled}
|
|
82
|
-
defaultValue={props.defaultValue}
|
|
83
|
-
onChange={onValueChange}
|
|
84
|
-
name={id}
|
|
85
|
-
id={id}
|
|
86
|
-
/>
|
|
87
|
-
</div>
|
|
88
|
-
</div>
|
|
89
|
-
);
|
|
90
|
-
};
|
|
91
|
-
|
|
92
|
-
export default TextWithLabel;
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import { ChangeEvent, useCallback } from 'react';
|
|
2
|
-
|
|
3
|
-
import { generateGuid } from '@bodynarf/utils/guid';
|
|
4
|
-
import { getClassName } from '@bodynarf/utils/component';
|
|
5
|
-
|
|
6
|
-
import { TextProps } from '../..';
|
|
7
|
-
|
|
8
|
-
/** Textual input without describing label */
|
|
9
|
-
const TextWithoutLabel = (props: TextProps): JSX.Element => {
|
|
10
|
-
const onValueChange = useCallback(
|
|
11
|
-
(event: ChangeEvent<HTMLInputElement>) => props.onValueChange(event.target.value),
|
|
12
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
13
|
-
[props.onValueChange]
|
|
14
|
-
);
|
|
15
|
-
|
|
16
|
-
const className = getClassName([
|
|
17
|
-
props.className,
|
|
18
|
-
`is-${(props.size || 'normal')}`,
|
|
19
|
-
props.rounded === true ? 'is-rounded' : '',
|
|
20
|
-
"input",
|
|
21
|
-
]);
|
|
22
|
-
|
|
23
|
-
const containerClassName = getClassName([
|
|
24
|
-
"app-input",
|
|
25
|
-
"control",
|
|
26
|
-
props.loading === true ? 'is-loading' : '',
|
|
27
|
-
(props.style || 'default') === 'default' ? '' : `is-${props.style}`
|
|
28
|
-
]);
|
|
29
|
-
|
|
30
|
-
const id = props.name || generateGuid();
|
|
31
|
-
|
|
32
|
-
return (
|
|
33
|
-
<div className={containerClassName}>
|
|
34
|
-
<input
|
|
35
|
-
className={className}
|
|
36
|
-
type="text"
|
|
37
|
-
placeholder={props.placeholder}
|
|
38
|
-
readOnly={props.readonly}
|
|
39
|
-
disabled={props.disabled}
|
|
40
|
-
defaultValue={props.defaultValue}
|
|
41
|
-
onChange={onValueChange}
|
|
42
|
-
name={id}
|
|
43
|
-
id={id}
|
|
44
|
-
/>
|
|
45
|
-
</div>
|
|
46
|
-
);
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
export default TextWithoutLabel;
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { isNullOrUndefined } from '@bodynarf/utils/common';
|
|
2
|
-
|
|
3
|
-
import { BaseInputElementProps } from '../types';
|
|
4
|
-
|
|
5
|
-
import TextWithLabel from './components/textWithLabel';
|
|
6
|
-
import TextWithoutLabel from './components/textWithoutLabel';
|
|
7
|
-
|
|
8
|
-
/** Text input conponent props type */
|
|
9
|
-
export type TextProps = BaseInputElementProps<string>;
|
|
10
|
-
|
|
11
|
-
/** Textual input component */
|
|
12
|
-
const Text = (props: TextProps): JSX.Element => {
|
|
13
|
-
if (isNullOrUndefined(props.label)) {
|
|
14
|
-
return (<TextWithoutLabel {...props}/>);
|
|
15
|
-
}
|
|
16
|
-
else {
|
|
17
|
-
return (<TextWithLabel {...props}/>);
|
|
18
|
-
}
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
export default Text;
|
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
import { ChangeEvent, useCallback, useState } from 'react';
|
|
2
|
-
|
|
3
|
-
import './search.scss';
|
|
4
|
-
|
|
5
|
-
import { generateGuid } from '@bodynarf/utils/guid';
|
|
6
|
-
import { isNullOrUndefined } from '@bodynarf/utils/common';
|
|
7
|
-
|
|
8
|
-
import Button from 'src/components/button';
|
|
9
|
-
|
|
10
|
-
export type SearchProps = {
|
|
11
|
-
/** Search caption */
|
|
12
|
-
caption: string;
|
|
13
|
-
|
|
14
|
-
/** Search handler */
|
|
15
|
-
onSearch: (searchPattern: string) => void;
|
|
16
|
-
|
|
17
|
-
/** Initial search value */
|
|
18
|
-
defaultValue?: string;
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Search type: by typing, starts from minimum characters to search
|
|
22
|
-
* or by clicking on button next to search bar.
|
|
23
|
-
* Default is byTyping
|
|
24
|
-
*/
|
|
25
|
-
searchType?: 'byTyping' | 'byButton';
|
|
26
|
-
|
|
27
|
-
/** Control name. If empty - will be replaced by random guid */
|
|
28
|
-
name?: string;
|
|
29
|
-
|
|
30
|
-
/** Minimum amount of characters to search */
|
|
31
|
-
minCharsToSearch?: number;
|
|
32
|
-
|
|
33
|
-
/** Size of search bar */
|
|
34
|
-
size?: 'small' | 'normal' | 'medium' | 'large';
|
|
35
|
-
|
|
36
|
-
/** Should search bar be rounded */
|
|
37
|
-
rounded?: boolean;
|
|
38
|
-
|
|
39
|
-
/** Is search bar disabled */
|
|
40
|
-
disabled?: boolean;
|
|
41
|
-
|
|
42
|
-
/** Should loading icon be displayed in search bar*/
|
|
43
|
-
isLoading?: boolean;
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
/** Search component */
|
|
47
|
-
export default function Search(props: SearchProps): JSX.Element {
|
|
48
|
-
const [name] = useState<string>(props.name || generateGuid());
|
|
49
|
-
const [searchValue, setSearchValue] = useState<string>(props.defaultValue || '');
|
|
50
|
-
|
|
51
|
-
const searchType = props.searchType || 'byTyping';
|
|
52
|
-
|
|
53
|
-
const onChange = useCallback(
|
|
54
|
-
(event: ChangeEvent<HTMLInputElement>) => {
|
|
55
|
-
const elementValue: string = event.target.value;
|
|
56
|
-
|
|
57
|
-
if (searchType === 'byTyping') {
|
|
58
|
-
const minCharsToSearch: number =
|
|
59
|
-
isNullOrUndefined(props.minCharsToSearch)
|
|
60
|
-
? 3
|
|
61
|
-
: props.minCharsToSearch as number;
|
|
62
|
-
|
|
63
|
-
if (elementValue.length >= minCharsToSearch) {
|
|
64
|
-
props.onSearch(elementValue);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
setSearchValue(elementValue);
|
|
69
|
-
}, [props, searchType]);
|
|
70
|
-
|
|
71
|
-
const onSearchButtonClick = useCallback(
|
|
72
|
-
() => {
|
|
73
|
-
props.onSearch(searchValue);
|
|
74
|
-
}, [props, searchValue]);
|
|
75
|
-
|
|
76
|
-
const className: string = 'app-search control'
|
|
77
|
-
+ ` is-${(props.size || 'normal')}`
|
|
78
|
-
+ (props.isLoading === true ? ' is-loading' : '')
|
|
79
|
-
+ (searchType === 'byButton' ? ' is-expanded': '')
|
|
80
|
-
;
|
|
81
|
-
|
|
82
|
-
const inputClassName: string = 'input is-unselectable'
|
|
83
|
-
+ ` is-${(props.size || 'normal')}`
|
|
84
|
-
+ (props.rounded === true ? ' is-rounded' : '')
|
|
85
|
-
;
|
|
86
|
-
|
|
87
|
-
if (searchType === 'byButton') {
|
|
88
|
-
return (
|
|
89
|
-
<div className="field has-addons">
|
|
90
|
-
<div className={className}>
|
|
91
|
-
<input
|
|
92
|
-
type='search'
|
|
93
|
-
name={name}
|
|
94
|
-
defaultValue={searchValue}
|
|
95
|
-
className={inputClassName}
|
|
96
|
-
disabled={props.disabled}
|
|
97
|
-
onChange={onChange}
|
|
98
|
-
placeholder={props.caption}
|
|
99
|
-
/>
|
|
100
|
-
</div>
|
|
101
|
-
<div className="control">
|
|
102
|
-
<Button
|
|
103
|
-
caption="Search"
|
|
104
|
-
type="info"
|
|
105
|
-
onClick={onSearchButtonClick}
|
|
106
|
-
isLoading={props.isLoading}
|
|
107
|
-
/>
|
|
108
|
-
</div>
|
|
109
|
-
</div>
|
|
110
|
-
);
|
|
111
|
-
}
|
|
112
|
-
else {
|
|
113
|
-
return (
|
|
114
|
-
<div className={className}>
|
|
115
|
-
<input
|
|
116
|
-
type='search'
|
|
117
|
-
name={name}
|
|
118
|
-
defaultValue={searchValue}
|
|
119
|
-
className={inputClassName}
|
|
120
|
-
disabled={props.disabled}
|
|
121
|
-
onChange={onChange}
|
|
122
|
-
placeholder={props.caption}
|
|
123
|
-
/>
|
|
124
|
-
</div>
|
|
125
|
-
);
|
|
126
|
-
}
|
|
127
|
-
}
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { DependencyList, useCallback, useEffect } from "react";
|
|
2
|
-
|
|
3
|
-
import { isNull, isNullOrUndefined } from "@bodynarf/utils/common";
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Subscribe to component outside click
|
|
7
|
-
* @param selector Component root selector
|
|
8
|
-
* @param clickHandleCondition Condition to handle document click
|
|
9
|
-
* @param clickHandleChange Handler of outside component click
|
|
10
|
-
* @param clickListenCondition Condition to start listening document clicks
|
|
11
|
-
* @param dependencies Additional dependencies to update hook
|
|
12
|
-
*/
|
|
13
|
-
export const useComponentOutsideClick = (
|
|
14
|
-
selector: string,
|
|
15
|
-
clickHandleCondition: boolean,
|
|
16
|
-
clickHandleChange: () => void,
|
|
17
|
-
clickListenCondition?: boolean,
|
|
18
|
-
dependencies?: DependencyList
|
|
19
|
-
): void => {
|
|
20
|
-
const onDocumentClick = useCallback(
|
|
21
|
-
(event: MouseEvent): void => {
|
|
22
|
-
if (clickHandleCondition) {
|
|
23
|
-
const target: HTMLElement = event.target as HTMLElement;
|
|
24
|
-
|
|
25
|
-
if (isNullOrUndefined(target)) {
|
|
26
|
-
return;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
const relatedComponent: Element | null =
|
|
30
|
-
target.closest(selector);
|
|
31
|
-
|
|
32
|
-
if (isNull(relatedComponent)) {
|
|
33
|
-
clickHandleChange();
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
37
|
-
}, [clickHandleCondition, selector, clickHandleChange, dependencies]);
|
|
38
|
-
|
|
39
|
-
useEffect(() => {
|
|
40
|
-
if (isNullOrUndefined(clickListenCondition) || clickListenCondition === true) {
|
|
41
|
-
document.addEventListener('click', onDocumentClick);
|
|
42
|
-
|
|
43
|
-
return (): void => document.removeEventListener('click', onDocumentClick);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
return () => { };
|
|
47
|
-
}, [clickListenCondition, onDocumentClick]);
|
|
48
|
-
};
|
package/src/main.tsx
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { createRoot } from "react-dom/client";
|
|
2
|
-
|
|
3
|
-
import "bootstrap-icons/font/bootstrap-icons.css";
|
|
4
|
-
import "bulma/bulma.sass";
|
|
5
|
-
|
|
6
|
-
const container = document.getElementById("root");
|
|
7
|
-
|
|
8
|
-
const root = createRoot(container!); // createRoot(container!) if you use TypeScript
|
|
9
|
-
root.render(<div> Components </div>);
|
package/text.ts
DELETED
package/tsconfig.json
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"target": "ESNext",
|
|
4
|
-
"useDefineForClassFields": true,
|
|
5
|
-
"lib": [
|
|
6
|
-
"DOM",
|
|
7
|
-
"DOM.Iterable",
|
|
8
|
-
"ESNext"
|
|
9
|
-
],
|
|
10
|
-
"allowJs": false,
|
|
11
|
-
"skipLibCheck": false,
|
|
12
|
-
"esModuleInterop": false,
|
|
13
|
-
"allowSyntheticDefaultImports": true,
|
|
14
|
-
"strict": true,
|
|
15
|
-
"noImplicitAny": true,
|
|
16
|
-
"noImplicitThis": true,
|
|
17
|
-
"alwaysStrict": true,
|
|
18
|
-
"forceConsistentCasingInFileNames": true,
|
|
19
|
-
"module": "ESNext",
|
|
20
|
-
"moduleResolution": "Node",
|
|
21
|
-
"resolveJsonModule": true,
|
|
22
|
-
"noEmit": true,
|
|
23
|
-
"jsx": "react-jsx",
|
|
24
|
-
"downlevelIteration": true,
|
|
25
|
-
"noUnusedLocals": true,
|
|
26
|
-
"noUnusedParameters": true,
|
|
27
|
-
"noImplicitReturns": true,
|
|
28
|
-
"baseUrl": "./",
|
|
29
|
-
},
|
|
30
|
-
"include": [
|
|
31
|
-
"src",
|
|
32
|
-
"./"
|
|
33
|
-
],
|
|
34
|
-
"references": [
|
|
35
|
-
{
|
|
36
|
-
"path": "./tsconfig.node.json"
|
|
37
|
-
}
|
|
38
|
-
],
|
|
39
|
-
}
|