@rescui/checkbox 0.9.5-RUI-286-Fix-tooltip-stacking-f4145b01.1 → 0.10.1

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.
@@ -30,6 +30,7 @@ export declare type CheckboxControlProps = {
30
30
  notUseLabelTag?: boolean;
31
31
  size?: CheckboxSize;
32
32
  mode?: CheckboxMode;
33
+ errorId?: string;
33
34
  };
34
35
  declare const CheckboxControlInner: React.ForwardRefExoticComponent<CheckboxControlProps & React.RefAttributes<HTMLInputElement>>;
35
36
  export default CheckboxControlInner;
@@ -22,11 +22,11 @@ const DEFAULT_MODE = 'classic';
22
22
  const CheckboxControlInner = /*#__PURE__*/React.forwardRef(function CheckboxControlInner(_ref, ref) {
23
23
  let {
24
24
  className,
25
- // eslint-disable-next-line @typescript-eslint/ban-ts-ignore, react/prop-types
26
- // @ts-ignore
25
+ // @ts-expect-error: omit children from restProps
27
26
  children,
28
27
  theme: themeFromProps,
29
28
  isError,
29
+ errorId,
30
30
  disabled,
31
31
  size = DEFAULT_SIZE,
32
32
  mode = DEFAULT_MODE,
@@ -46,7 +46,9 @@ const CheckboxControlInner = /*#__PURE__*/React.forwardRef(function CheckboxCont
46
46
  ref: ref,
47
47
  className: styles.input,
48
48
  type: "checkbox",
49
- disabled: disabled
49
+ disabled: disabled,
50
+ "aria-errormessage": isError ? errorId : undefined,
51
+ "aria-invalid": Boolean(isError)
50
52
  }), /*#__PURE__*/React.createElement("span", {
51
53
  className: cn(styles.icon, isError && styles.iconError),
52
54
  "data-test": 'checkbox-icon'
@@ -69,6 +71,7 @@ CheckboxControlInner.propTypes = {
69
71
  indeterminate: PropTypes.bool,
70
72
  notUseLabelTag: PropTypes.bool,
71
73
  size: PropTypes.oneOf(['s', 'm', 'l']),
72
- mode: PropTypes.oneOf(['classic', 'rock'])
74
+ mode: PropTypes.oneOf(['classic', 'rock']),
75
+ errorId: PropTypes.string
73
76
  };
74
77
  export { CheckboxControlInner as default };
@@ -10,6 +10,7 @@ const CheckboxControl = /*#__PURE__*/React.forwardRef(function CheckboxControl(p
10
10
  handleCheckboxChange,
11
11
  value: groupValue,
12
12
  isError,
13
+ errorId,
13
14
  theme,
14
15
  size,
15
16
  mode,
@@ -29,6 +30,7 @@ const CheckboxControl = /*#__PURE__*/React.forwardRef(function CheckboxControl(p
29
30
  onChange,
30
31
  checked,
31
32
  isError: propsIsError,
33
+ errorId: propsErrorId,
32
34
  disabled: propsDisabled,
33
35
  theme: propsTheme,
34
36
  size: propsSize,
@@ -37,6 +39,7 @@ const CheckboxControl = /*#__PURE__*/React.forwardRef(function CheckboxControl(p
37
39
  } = props;
38
40
  return /*#__PURE__*/React.createElement(CheckboxControlInner, {
39
41
  isError: isError || propsIsError,
42
+ errorId: errorId || propsErrorId,
40
43
  value: value,
41
44
  onChange: handleCheckboxChange,
42
45
  checked: _includesInstanceProperty(groupValue).call(groupValue, value),
@@ -3,13 +3,23 @@ import { Theme } from '@rescui/ui-contexts';
3
3
  import CSS from 'csstype';
4
4
  export declare type CheckboxListProps = {
5
5
  className?: string;
6
+ id?: string;
6
7
  style?: CSS.Properties;
7
8
  mode?: 'classic' | 'rock';
8
9
  size?: 's' | 'm' | 'l';
9
10
  onChange?: (val: string[]) => void;
10
11
  value?: string[];
11
12
  defaultValue?: string[];
12
- error?: boolean | React.ReactNode;
13
+ label?: React.ReactNode;
14
+ note?: React.ReactNode;
15
+ /** Error flag or message */
16
+ error?: React.ReactNode;
17
+ /**
18
+ * If `true`, there will be reserved a space for a 1-line error message. Subsequent lines will be placed below normally.
19
+ * If `false`, there will be no reservation.
20
+ */
21
+ reserveErrorLine?: boolean;
22
+ boldLabel?: boolean;
13
23
  theme?: Theme;
14
24
  disabled?: boolean;
15
25
  children?: React.ReactNode;
@@ -4,18 +4,19 @@ import PropTypes from 'prop-types';
4
4
  import { Menu } from '@rescui/menu';
5
5
  import cn from 'classnames';
6
6
  import { useThemeWithUndefined } from '@rescui/ui-contexts';
7
- import WarningIcon from '../_virtual/warning.js';
8
- import styles from './checkbox.p.module.css.js';
7
+ import { ErrorMessage, shouldRenderErrorMessage } from '@rescui/form-field';
8
+ import styles from './checkbox-list.p.module.css.js';
9
9
  import CheckboxManager from './checkbox-manager.js';
10
+ import { useBackwardCompatibleId } from './use-backward-compatible-id.js';
10
11
  const THEME_STYLES = {
11
12
  light: styles.themeLight,
12
13
  dark: styles.themeDark
13
14
  };
14
15
  const SIZE_STYLES = {
15
- s: styles.listSizeS,
16
- m: styles.listSizeM,
17
- l: styles.listSizeL
18
- };
16
+ s: styles.sizeS,
17
+ m: styles.sizeM,
18
+ l: styles.sizeL
19
+ }; // eslint-disable-next-line complexity
19
20
 
20
21
  const CheckboxList = _ref => {
21
22
  let {
@@ -27,13 +28,20 @@ const CheckboxList = _ref => {
27
28
  onChange,
28
29
  value,
29
30
  defaultValue,
31
+ label,
32
+ note,
30
33
  error,
34
+ reserveErrorLine = false,
31
35
  className,
32
- // eslint-disable-next-line react/prop-types
36
+ id,
33
37
  style,
38
+ boldLabel = true,
34
39
  ...restProps
35
40
  } = _ref;
36
41
  const theme = useThemeWithUndefined(themeFromProps);
42
+ const uniqueId = `checkbox-list-${useBackwardCompatibleId()}`;
43
+ const errorId = `${id ? id : uniqueId}-error`;
44
+ const hasFooter = Boolean(note) || shouldRenderErrorMessage(error, reserveErrorLine);
37
45
  return /*#__PURE__*/React.createElement(CheckboxManager, {
38
46
  theme: theme,
39
47
  defaultValue: defaultValue,
@@ -45,18 +53,18 @@ const CheckboxList = _ref => {
45
53
  disabled: disabled,
46
54
  size: size,
47
55
  mode: mode
48
- }, /*#__PURE__*/React.createElement("div", {
49
- className: cn(className, styles.container, THEME_STYLES[theme], SIZE_STYLES[size] || styles.listSizeM),
50
- style: style
51
- }, error && typeof error !== 'boolean' && /*#__PURE__*/React.createElement("div", {
52
- className: cn(styles.errorMessage, styles.list),
53
- "data-test": "checkbox-error-message",
54
- "data-rs-internal": "checkbox-list__error-message"
55
- }, /*#__PURE__*/React.createElement(WarningIcon, {
56
- "data-rs-internal": "checkbox-list__error-icon",
57
- className: styles.errorIcon,
58
- "data-render-all-sizes": true
59
- }), /*#__PURE__*/React.createElement("span", null, error)), /*#__PURE__*/React.createElement(Menu, {
56
+ }, /*#__PURE__*/React.createElement("fieldset", {
57
+ className: cn(className, styles.container, THEME_STYLES[theme], SIZE_STYLES[size] || styles.sizeM, Boolean(error) && styles.error, disabled && styles.disabled),
58
+ id: id,
59
+ style: style,
60
+ "aria-errormessage": error ? errorId : undefined,
61
+ "aria-invalid": Boolean(error),
62
+ "data-test": "checkbox-list"
63
+ }, label && /*#__PURE__*/React.createElement("legend", {
64
+ className: styles.label,
65
+ "data-test": 'checkbox-list__label',
66
+ "data-rs-internal": boldLabel ? 'checkbox-list__bold-label' : 'checkbox-list__label'
67
+ }, label), /*#__PURE__*/React.createElement(Menu, {
60
68
  tag: 'div',
61
69
  itemTag: null,
62
70
  size: size,
@@ -64,8 +72,20 @@ const CheckboxList = _ref => {
64
72
  disabled: disabled,
65
73
  "data-rs-internal": 'checkbox__menu',
66
74
  theme: theme,
75
+ className: styles.inner,
67
76
  ...restProps
68
- }, children)));
77
+ }, children), hasFooter && /*#__PURE__*/React.createElement("div", {
78
+ className: styles.footer
79
+ }, /*#__PURE__*/React.createElement(ErrorMessage, {
80
+ id: errorId,
81
+ className: styles.errorMessage,
82
+ "data-test": 'checkbox-list__error',
83
+ reserveLine: reserveErrorLine
84
+ }, error), note && /*#__PURE__*/React.createElement("div", {
85
+ className: styles.note,
86
+ "data-test": 'checkbox-list__note',
87
+ "data-rs-internal": "checkbox-list__note"
88
+ }, note))));
69
89
  };
70
90
 
71
91
  CheckboxList.propTypes = {
@@ -74,8 +94,15 @@ CheckboxList.propTypes = {
74
94
  onChange: PropTypes.func,
75
95
  value: PropTypes.array,
76
96
  defaultValue: PropTypes.array,
77
- error: PropTypes.oneOfType([PropTypes.bool, PropTypes.node]),
97
+ error: ErrorMessage.propTypes.children,
98
+ style: PropTypes.object,
78
99
  theme: PropTypes.oneOf(['light', 'dark']),
79
- disabled: PropTypes.bool
100
+ disabled: PropTypes.bool,
101
+ className: PropTypes.string,
102
+ id: PropTypes.string,
103
+ reserveErrorLine: PropTypes.bool,
104
+ label: PropTypes.node,
105
+ note: PropTypes.node,
106
+ boldLabel: PropTypes.bool
80
107
  };
81
108
  export { CheckboxList as default };
@@ -0,0 +1,16 @@
1
+ var styles = {
2
+ "themeLight": "_themeLight_1txuou8_6",
3
+ "themeDark": "_themeDark_1txuou8_9",
4
+ "container": "_container_1txuou8_13",
5
+ "sizeS": "_sizeS_1txuou8_18",
6
+ "sizeM": "_sizeM_1txuou8_21",
7
+ "sizeL": "_sizeL_1txuou8_24",
8
+ "inner": "_inner_1txuou8_28",
9
+ "label": "_label_1txuou8_32",
10
+ "disabled": "_disabled_1txuou8_39",
11
+ "footer": "_footer_1txuou8_44",
12
+ "errorMessage": "_errorMessage_1txuou8_49",
13
+ "error": "_error_1txuou8_49",
14
+ "note": "_note_1txuou8_58"
15
+ };
16
+ export { styles as default };
@@ -1,31 +1,25 @@
1
1
  var styles = {
2
- "themeLight": "_themeLight_1yjjktt_8",
3
- "themeDark": "_themeDark_1yjjktt_11",
4
- "container": "_container_1yjjktt_15",
5
- "listSizeS": "_listSizeS_1yjjktt_20",
6
- "listSizeM": "_listSizeM_1yjjktt_23",
7
- "listSizeL": "_listSizeL_1yjjktt_26",
8
- "checkboxSizeS": "_checkboxSizeS_1yjjktt_30",
9
- "checkboxSizeM": "_checkboxSizeM_1yjjktt_33",
10
- "checkboxSizeL": "_checkboxSizeL_1yjjktt_36",
11
- "sizeS": "_sizeS_1yjjktt_40",
12
- "sizeM": "_sizeM_1yjjktt_43",
13
- "sizeL": "_sizeL_1yjjktt_46",
14
- "classic": "_classic_1yjjktt_50",
15
- "rock": "_rock_1yjjktt_53",
16
- "checkbox": "_checkbox_1yjjktt_30",
17
- "errorMessage": "_errorMessage_1yjjktt_79",
18
- "list": "_list_1yjjktt_20",
19
- "errorIcon": "_errorIcon_1yjjktt_93",
20
- "input": "_input_1yjjktt_99",
21
- "icon": "_icon_1yjjktt_110",
22
- "enabled": "_enabled_1yjjktt_126",
23
- "indeterminate": "_indeterminate_1yjjktt_130",
24
- "disabled": "_disabled_1yjjktt_138",
25
- "error": "_error_1yjjktt_79",
26
- "checkmark": "_checkmark_1yjjktt_194",
27
- "markS": "_markS_1yjjktt_219",
28
- "markM": "_markM_1yjjktt_222",
29
- "markL": "_markL_1yjjktt_225"
2
+ "themeLight": "_themeLight_d1mcrn_8",
3
+ "themeDark": "_themeDark_d1mcrn_11",
4
+ "checkboxSizeS": "_checkboxSizeS_d1mcrn_15",
5
+ "checkboxSizeM": "_checkboxSizeM_d1mcrn_18",
6
+ "checkboxSizeL": "_checkboxSizeL_d1mcrn_21",
7
+ "sizeS": "_sizeS_d1mcrn_25",
8
+ "sizeM": "_sizeM_d1mcrn_28",
9
+ "sizeL": "_sizeL_d1mcrn_31",
10
+ "classic": "_classic_d1mcrn_35",
11
+ "rock": "_rock_d1mcrn_38",
12
+ "checkbox": "_checkbox_d1mcrn_15",
13
+ "input": "_input_d1mcrn_65",
14
+ "icon": "_icon_d1mcrn_76",
15
+ "enabled": "_enabled_d1mcrn_92",
16
+ "indeterminate": "_indeterminate_d1mcrn_96",
17
+ "disabled": "_disabled_d1mcrn_104",
18
+ "error": "_error_d1mcrn_133",
19
+ "checkmark": "_checkmark_d1mcrn_160",
20
+ "markS": "_markS_d1mcrn_185",
21
+ "markM": "_markM_d1mcrn_188",
22
+ "markL": "_markL_d1mcrn_191",
23
+ "errorMessage": "_errorMessage_d1mcrn_195"
30
24
  };
31
25
  export { styles as default };
@@ -8,6 +8,7 @@ export declare type GroupContextValue = {
8
8
  inGroup: boolean;
9
9
  handleCheckboxChange?: React.ChangeEventHandler<HTMLInputElement>;
10
10
  isError?: boolean;
11
+ errorId?: string;
11
12
  theme?: Theme;
12
13
  size?: CheckboxSize;
13
14
  mode?: 'classic' | 'rock';
@@ -0,0 +1,4 @@
1
+ export declare const useBackwardCompatibleId: {
2
+ (): string | number;
3
+ counter: number;
4
+ };
@@ -0,0 +1,14 @@
1
+ import React, { useRef } from 'react';
2
+
3
+ const useBackwardCompatibleId = () => {
4
+ const id = useRef(null);
5
+
6
+ if (id.current === null) {
7
+ id.current = useBackwardCompatibleId.counter++;
8
+ }
9
+
10
+ return (React.useId ? React.useId : () => id.current)();
11
+ };
12
+
13
+ useBackwardCompatibleId.counter = 0;
14
+ export { useBackwardCompatibleId };