@true-engineering/true-react-common-ui-kit 3.8.0 → 3.9.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/README.md +16 -0
- package/dist/components/Checkbox/Checkbox.d.ts +2 -2
- package/dist/components/NewMoreMenu/NewMoreMenu.d.ts +1 -1
- package/dist/components/NewMoreMenu/NewMoreMenu.styles.d.ts +3 -1
- package/dist/components/ScrollIntoViewIfNeeded/ScrollIntoViewIfNeeded.d.ts +1 -1
- package/dist/components/Select/Select.d.ts +4 -4
- package/dist/components/Select/components/SelectList/SelectList.d.ts +5 -6
- package/dist/components/Select/components/SelectListItem/SelectListItem.d.ts +2 -2
- package/dist/components/WithPopup/WithPopup.d.ts +2 -0
- package/dist/components/WithPopup/WithPopup.styles.d.ts +1 -1
- package/dist/true-react-common-ui-kit.js +59 -32
- package/dist/true-react-common-ui-kit.js.map +1 -1
- package/dist/true-react-common-ui-kit.umd.cjs +59 -32
- package/dist/true-react-common-ui-kit.umd.cjs.map +1 -1
- package/package.json +1 -1
- package/src/components/Checkbox/Checkbox.tsx +88 -85
- package/src/components/NewMoreMenu/NewMoreMenu.stories.tsx +1 -0
- package/src/components/NewMoreMenu/NewMoreMenu.styles.ts +5 -5
- package/src/components/NewMoreMenu/NewMoreMenu.tsx +18 -2
- package/src/components/Select/Select.tsx +609 -580
- package/src/components/Select/components/SelectList/SelectList.tsx +156 -157
- package/src/components/Select/components/SelectListItem/SelectListItem.tsx +72 -68
- package/src/components/WithPopup/WithPopup.stories.tsx +1 -0
- package/src/components/WithPopup/WithPopup.styles.ts +4 -0
- package/src/components/WithPopup/WithPopup.tsx +13 -2
package/package.json
CHANGED
|
@@ -1,85 +1,88 @@
|
|
|
1
|
-
import { useEffect, useState, ReactNode } from 'react';
|
|
2
|
-
import clsx from 'clsx';
|
|
3
|
-
import {
|
|
4
|
-
addDataTestId,
|
|
5
|
-
getSelectKeyHandler,
|
|
6
|
-
isReactNodeNotEmpty,
|
|
7
|
-
} from '@true-engineering/true-react-platform-helpers';
|
|
8
|
-
import { addDataAttributes } from '../../helpers';
|
|
9
|
-
import { ICommonProps } from '../../types';
|
|
10
|
-
import { Icon } from '../Icon';
|
|
11
|
-
import { useStyles, ICheckboxStyles } from './Checkbox.styles';
|
|
12
|
-
|
|
13
|
-
export interface ICheckboxProps<V> extends ICommonProps<ICheckboxStyles> {
|
|
14
|
-
children?: ReactNode;
|
|
15
|
-
isChecked: boolean | undefined;
|
|
16
|
-
/** @default false */
|
|
17
|
-
isSemiChecked?: boolean;
|
|
18
|
-
/** @default false */
|
|
19
|
-
isDisabled?: boolean;
|
|
20
|
-
/** @default false */
|
|
21
|
-
isReadonly?: boolean;
|
|
22
|
-
/** @default false */
|
|
23
|
-
isInvalid?: boolean;
|
|
24
|
-
value: V;
|
|
25
|
-
/** @default 'right' */
|
|
26
|
-
labelPosition?: 'right' | 'left';
|
|
27
|
-
onSelect: (
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
{
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
}
|
|
1
|
+
import { useEffect, useState, ReactNode, ChangeEvent, KeyboardEvent } from 'react';
|
|
2
|
+
import clsx from 'clsx';
|
|
3
|
+
import {
|
|
4
|
+
addDataTestId,
|
|
5
|
+
getSelectKeyHandler,
|
|
6
|
+
isReactNodeNotEmpty,
|
|
7
|
+
} from '@true-engineering/true-react-platform-helpers';
|
|
8
|
+
import { addDataAttributes } from '../../helpers';
|
|
9
|
+
import { ICommonProps } from '../../types';
|
|
10
|
+
import { Icon } from '../Icon';
|
|
11
|
+
import { useStyles, ICheckboxStyles } from './Checkbox.styles';
|
|
12
|
+
|
|
13
|
+
export interface ICheckboxProps<V> extends ICommonProps<ICheckboxStyles> {
|
|
14
|
+
children?: ReactNode;
|
|
15
|
+
isChecked: boolean | undefined;
|
|
16
|
+
/** @default false */
|
|
17
|
+
isSemiChecked?: boolean;
|
|
18
|
+
/** @default false */
|
|
19
|
+
isDisabled?: boolean;
|
|
20
|
+
/** @default false */
|
|
21
|
+
isReadonly?: boolean;
|
|
22
|
+
/** @default false */
|
|
23
|
+
isInvalid?: boolean;
|
|
24
|
+
value: V;
|
|
25
|
+
/** @default 'right' */
|
|
26
|
+
labelPosition?: 'right' | 'left';
|
|
27
|
+
onSelect: (
|
|
28
|
+
value: { value: V; isSelected: boolean },
|
|
29
|
+
event: ChangeEvent<HTMLInputElement> | KeyboardEvent,
|
|
30
|
+
) => void;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function Checkbox<V>({
|
|
34
|
+
children,
|
|
35
|
+
isDisabled = false,
|
|
36
|
+
isReadonly = false,
|
|
37
|
+
isChecked = false,
|
|
38
|
+
value,
|
|
39
|
+
data,
|
|
40
|
+
testId,
|
|
41
|
+
isSemiChecked = false,
|
|
42
|
+
labelPosition = 'right',
|
|
43
|
+
tweakStyles,
|
|
44
|
+
onSelect,
|
|
45
|
+
}: ICheckboxProps<V>): JSX.Element {
|
|
46
|
+
const classes = useStyles({ theme: tweakStyles });
|
|
47
|
+
|
|
48
|
+
const [isSelected, setIsSelected] = useState(false);
|
|
49
|
+
|
|
50
|
+
const hasAction = !isDisabled && !isReadonly;
|
|
51
|
+
|
|
52
|
+
const onToggle = (event: ChangeEvent<HTMLInputElement> | KeyboardEvent) => {
|
|
53
|
+
const isSelectedNext = !isSelected;
|
|
54
|
+
onSelect({ value, isSelected: isSelectedNext }, event);
|
|
55
|
+
setIsSelected(isSelectedNext);
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
useEffect(() => {
|
|
59
|
+
setIsSelected(isChecked);
|
|
60
|
+
}, [isChecked]);
|
|
61
|
+
|
|
62
|
+
return (
|
|
63
|
+
<label
|
|
64
|
+
className={clsx(classes.root, {
|
|
65
|
+
[classes.disabled]: isDisabled,
|
|
66
|
+
[classes.labelPositionLeft]: labelPosition === 'left',
|
|
67
|
+
})}
|
|
68
|
+
{...addDataTestId(testId)}
|
|
69
|
+
{...addDataAttributes(data)}
|
|
70
|
+
>
|
|
71
|
+
<input
|
|
72
|
+
type="checkbox"
|
|
73
|
+
className={classes.input}
|
|
74
|
+
checked={isSelected}
|
|
75
|
+
disabled={isDisabled}
|
|
76
|
+
readOnly={isReadonly}
|
|
77
|
+
{...(hasAction && {
|
|
78
|
+
onChange: onToggle,
|
|
79
|
+
onKeyDown: getSelectKeyHandler(onToggle),
|
|
80
|
+
})}
|
|
81
|
+
/>
|
|
82
|
+
<div className={clsx(classes.check, isSelected && classes.checked)}>
|
|
83
|
+
<Icon type={isSemiChecked ? 'minus' : 'check'} />
|
|
84
|
+
</div>
|
|
85
|
+
{isReactNodeNotEmpty(children) && <div className={classes.children}>{children}</div>}
|
|
86
|
+
</label>
|
|
87
|
+
);
|
|
88
|
+
}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { colors, ITweakStyles, createThemedStyles } from '../../theme';
|
|
2
2
|
import { IListStyles } from '../List';
|
|
3
|
+
import { IWithPopupStyles } from '../WithPopup';
|
|
3
4
|
|
|
4
5
|
export const useStyles = createThemedStyles('NewMoreMenu', {
|
|
5
|
-
root: {},
|
|
6
|
-
|
|
7
6
|
hasCircle: {},
|
|
8
7
|
|
|
9
8
|
button: {
|
|
@@ -31,8 +30,9 @@ export const useStyles = createThemedStyles('NewMoreMenu', {
|
|
|
31
30
|
disabled: {
|
|
32
31
|
cursor: 'default',
|
|
33
32
|
},
|
|
34
|
-
|
|
35
|
-
menu: {},
|
|
36
33
|
});
|
|
37
34
|
|
|
38
|
-
export type INewMoreMenuStyles = ITweakStyles<
|
|
35
|
+
export type INewMoreMenuStyles = ITweakStyles<
|
|
36
|
+
typeof useStyles,
|
|
37
|
+
{ tweakList: IListStyles; tweakWithPopup: IWithPopupStyles }
|
|
38
|
+
>;
|
|
@@ -2,6 +2,7 @@ import { FC } from 'react';
|
|
|
2
2
|
import clsx from 'clsx';
|
|
3
3
|
import { addDataTestId, isArrayNotEmpty } from '@true-engineering/true-react-platform-helpers';
|
|
4
4
|
import { addDataAttributes } from '../../helpers';
|
|
5
|
+
import { useTweakStyles } from '../../hooks';
|
|
5
6
|
import { ICommonProps } from '../../types';
|
|
6
7
|
import { Icon } from '../Icon';
|
|
7
8
|
import { IListItem, List } from '../List';
|
|
@@ -9,7 +10,7 @@ import { IWithPopupProps, WithPopup } from '../WithPopup';
|
|
|
9
10
|
import { useStyles, INewMoreMenuStyles } from './NewMoreMenu.styles';
|
|
10
11
|
|
|
11
12
|
export interface INewMoreMenuProps
|
|
12
|
-
extends Pick<IWithPopupProps, 'middlewares' | 'shouldRenderInBody'>,
|
|
13
|
+
extends Pick<IWithPopupProps, 'middlewares' | 'shouldHideOnScroll' | 'shouldRenderInBody'>,
|
|
13
14
|
ICommonProps<INewMoreMenuStyles> {
|
|
14
15
|
items: IListItem[];
|
|
15
16
|
/** @default false */
|
|
@@ -28,19 +29,34 @@ export const NewMoreMenu: FC<INewMoreMenuProps> = ({
|
|
|
28
29
|
testId,
|
|
29
30
|
placement,
|
|
30
31
|
middlewares,
|
|
32
|
+
shouldHideOnScroll,
|
|
31
33
|
shouldRenderInBody,
|
|
32
34
|
tweakStyles,
|
|
33
35
|
}) => {
|
|
34
36
|
const classes = useStyles({ theme: tweakStyles });
|
|
35
37
|
|
|
38
|
+
const tweakWithPopupStyles = useTweakStyles({
|
|
39
|
+
tweakStyles,
|
|
40
|
+
className: 'tweakWithPopup',
|
|
41
|
+
currentComponentName: 'NewMoreMenu',
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
const tweakListStyles = useTweakStyles({
|
|
45
|
+
tweakStyles,
|
|
46
|
+
className: 'tweakList',
|
|
47
|
+
currentComponentName: 'NewMoreMenu',
|
|
48
|
+
});
|
|
49
|
+
|
|
36
50
|
const isButtonDisabled = isDisabled || !isArrayNotEmpty(items);
|
|
37
51
|
|
|
38
52
|
return (
|
|
39
53
|
<WithPopup
|
|
40
54
|
placement={placement}
|
|
41
55
|
middlewares={middlewares}
|
|
56
|
+
shouldHideOnScroll={shouldHideOnScroll}
|
|
42
57
|
shouldRenderInBody={shouldRenderInBody}
|
|
43
58
|
isDisabled={isButtonDisabled}
|
|
59
|
+
tweakStyles={tweakWithPopupStyles}
|
|
44
60
|
trigger={({ isActive }) => (
|
|
45
61
|
<button
|
|
46
62
|
className={clsx(classes.button, {
|
|
@@ -58,7 +74,7 @@ export const NewMoreMenu: FC<INewMoreMenuProps> = ({
|
|
|
58
74
|
</button>
|
|
59
75
|
)}
|
|
60
76
|
>
|
|
61
|
-
{({ onClose }) => <List items={items} onClick={onClose} />}
|
|
77
|
+
{({ onClose }) => <List items={items} tweakStyles={tweakListStyles} onClick={onClose} />}
|
|
62
78
|
</WithPopup>
|
|
63
79
|
);
|
|
64
80
|
};
|