@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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@true-engineering/true-react-common-ui-kit",
3
- "version": "3.8.0",
3
+ "version": "3.9.0",
4
4
  "description": "True Engineering React UI Kit with theming support",
5
5
  "author": "True Engineering (https://trueengineering.ru)",
6
6
  "keywords": [
@@ -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: (value: { value: V; isSelected: boolean }) => void;
28
- }
29
-
30
- export function Checkbox<V>({
31
- children,
32
- isDisabled = false,
33
- isReadonly = false,
34
- isChecked = false,
35
- value,
36
- data,
37
- testId,
38
- isSemiChecked = false,
39
- labelPosition = 'right',
40
- tweakStyles,
41
- onSelect,
42
- }: ICheckboxProps<V>): JSX.Element {
43
- const classes = useStyles({ theme: tweakStyles });
44
-
45
- const [isSelected, setIsSelected] = useState(false);
46
-
47
- const hasAction = !isDisabled && !isReadonly;
48
-
49
- const onToggle = () => {
50
- const isSelectedNext = !isSelected;
51
- onSelect({ value, isSelected: isSelectedNext });
52
- setIsSelected(isSelectedNext);
53
- };
54
-
55
- useEffect(() => {
56
- setIsSelected(isChecked);
57
- }, [isChecked]);
58
-
59
- return (
60
- <label
61
- className={clsx(classes.root, {
62
- [classes.disabled]: isDisabled,
63
- [classes.labelPositionLeft]: labelPosition === 'left',
64
- })}
65
- {...addDataTestId(testId)}
66
- {...addDataAttributes(data)}
67
- >
68
- <input
69
- type="checkbox"
70
- className={classes.input}
71
- checked={isSelected}
72
- disabled={isDisabled}
73
- readOnly={isReadonly}
74
- {...(hasAction && {
75
- onChange: onToggle,
76
- onKeyDown: getSelectKeyHandler(onToggle),
77
- })}
78
- />
79
- <div className={clsx(classes.check, isSelected && classes.checked)}>
80
- <Icon type={isSemiChecked ? 'minus' : 'check'} />
81
- </div>
82
- {isReactNodeNotEmpty(children) && <div className={classes.children}>{children}</div>}
83
- </label>
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
+ }
@@ -63,6 +63,7 @@ Default.args = {
63
63
  hasDefaultStateBackground: true,
64
64
  placement: 'bottom-end',
65
65
  shouldRenderInBody: false,
66
+ shouldHideOnScroll: false,
66
67
  };
67
68
 
68
69
  Default.parameters = {
@@ -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<typeof useStyles, { tweakList: IListStyles }>;
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
  };