@true-engineering/true-react-common-ui-kit 4.0.0-alpha40 → 4.0.0-alpha42

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": "4.0.0-alpha40",
3
+ "version": "4.0.0-alpha42",
4
4
  "description": "True Engineering React UI Kit with theming support",
5
5
  "author": "True Engineering (https://trueengineering.ru)",
6
6
  "keywords": [
@@ -1,7 +1,10 @@
1
1
  import { useState, FC } from 'react';
2
2
  import type { Meta, StoryObj } from '@storybook/react';
3
+ import { IExtendableProps } from '../../types';
3
4
  import { Checkbox as CheckboxComponent, ICheckboxProps } from './Checkbox';
4
5
 
6
+ const CHECKBOX_SIZES = ['micro'] as const;
7
+
5
8
  const CheckboxComponentWithData: FC<ICheckboxProps<string>> = (props) => {
6
9
  const [isChecked, setIsChecked] = useState(false);
7
10
  const [isSemiChecked, setIsSemiChecked] = useState(false);
@@ -23,6 +26,7 @@ const CheckboxComponentWithData: FC<ICheckboxProps<string>> = (props) => {
23
26
  value={undefined}
24
27
  isChecked={isSemiChecked}
25
28
  onSelect={({ isSelected }) => setIsSemiChecked(isSelected)}
29
+ {...props}
26
30
  >
27
31
  Is Semi Checked
28
32
  </CheckboxComponent>
@@ -36,6 +40,7 @@ const meta: Meta<typeof CheckboxComponentWithData> = {
36
40
  args: {
37
41
  value: 'value',
38
42
  labelPosition: 'right',
43
+ size: undefined,
39
44
  isInvalid: false,
40
45
  isDisabled: false,
41
46
  isReadonly: false,
@@ -45,8 +50,16 @@ const meta: Meta<typeof CheckboxComponentWithData> = {
45
50
  exclude: ['data', 'tweakStyles', 'testId', 'onSelect'],
46
51
  },
47
52
  },
53
+ argTypes: {
54
+ size: { options: [undefined, ...CHECKBOX_SIZES], control: 'inline-radio' },
55
+ },
48
56
  };
49
57
 
58
+ declare module './types' {
59
+ // eslint-disable-next-line @typescript-eslint/no-empty-interface
60
+ export interface ICheckboxSizes extends IExtendableProps<typeof CHECKBOX_SIZES> {}
61
+ }
62
+
50
63
  export default meta;
51
64
 
52
65
  type Story = StoryObj<typeof CheckboxComponent>;
@@ -1,4 +1,5 @@
1
1
  import { createThemedStyles, ITweakStyles } from '../../theme';
2
+ import { ICheckboxSizes } from './types';
2
3
 
3
4
  export const useStyles = createThemedStyles('Checkbox', {
4
5
  root: {
@@ -46,4 +47,4 @@ export const useStyles = createThemedStyles('Checkbox', {
46
47
  },
47
48
  });
48
49
 
49
- export type ICheckboxStyles = ITweakStyles<typeof useStyles>;
50
+ export type ICheckboxStyles = ITweakStyles<typeof useStyles, ICheckboxSizes>;
@@ -1,18 +1,20 @@
1
1
  import { ReactNode, ChangeEvent, KeyboardEvent } from 'react';
2
2
  import clsx from 'clsx';
3
3
  import {
4
- addDataTestId,
5
4
  getSelectKeyHandler,
5
+ isNotEmpty,
6
6
  isReactNodeNotEmpty,
7
+ addDataAttributes,
7
8
  } from '@true-engineering/true-react-platform-helpers';
8
- import { addDataAttributes } from '../../helpers';
9
9
  import { ICommonProps } from '../../types';
10
10
  import { Icon } from '../Icon';
11
+ import { ICheckboxSize } from './types';
11
12
  import { useStyles, ICheckboxStyles } from './Checkbox.styles';
12
13
 
13
14
  export interface ICheckboxProps<V> extends ICommonProps<ICheckboxStyles> {
14
15
  value?: V;
15
16
  children?: ReactNode;
17
+ size?: ICheckboxSize;
16
18
  /** @default false */
17
19
  isChecked?: boolean;
18
20
  /** @default false */
@@ -34,6 +36,7 @@ export interface ICheckboxProps<V> extends ICommonProps<ICheckboxStyles> {
34
36
  export function Checkbox<V>({
35
37
  value,
36
38
  children,
39
+ size,
37
40
  isChecked = false,
38
41
  isSemiChecked = false,
39
42
  isInvalid = false,
@@ -55,14 +58,13 @@ export function Checkbox<V>({
55
58
 
56
59
  return (
57
60
  <label
58
- className={clsx(classes.root, {
61
+ className={clsx(classes.root, isNotEmpty(size) && classes[size], {
59
62
  [classes.checked]: isSelected,
60
63
  [classes.invalid]: isInvalid,
61
64
  [classes.disabled]: isDisabled,
62
65
  [classes.labelPositionLeft]: labelPosition === 'left',
63
66
  })}
64
- {...addDataTestId(testId)}
65
- {...addDataAttributes(data)}
67
+ {...addDataAttributes(data, testId)}
66
68
  >
67
69
  <input
68
70
  className={classes.input}
@@ -0,0 +1,4 @@
1
+ // eslint-disable-next-line @typescript-eslint/no-empty-interface
2
+ export interface ICheckboxSizes {}
3
+
4
+ export type ICheckboxSize = keyof ICheckboxSizes;