@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.
package/lib/checkbox.d.ts CHANGED
@@ -3,6 +3,7 @@ import { Theme } from '@rescui/ui-contexts';
3
3
  import type { CheckboxMode, CheckboxSize } from './parts/checkbox-control-inner';
4
4
  export declare type CheckboxProps = {
5
5
  className?: string;
6
+ id?: string;
6
7
  /** Checked state. `onChange` callback is required. */
7
8
  checked?: boolean;
8
9
  /** Node or text to show near the input */
@@ -17,6 +18,11 @@ export declare type CheckboxProps = {
17
18
  disabled?: boolean;
18
19
  /** Error state */
19
20
  error?: boolean | React.ReactNode;
21
+ /**
22
+ * If `true`, there will be reserved a space for a 1-line error message. Subsequent lines will be placed below normally.
23
+ * If `false`, there will be no reservation.
24
+ */
25
+ reserveErrorLine?: boolean;
20
26
  /** Value of the checkbox */
21
27
  value?: string;
22
28
  /** Change value callback. `event => ...` */
package/lib/checkbox.js CHANGED
@@ -4,9 +4,10 @@ import PropTypes from 'prop-types';
4
4
  import { MenuItem } from '@rescui/menu';
5
5
  import { useThemeWithUndefined } from '@rescui/ui-contexts';
6
6
  import cn from 'classnames';
7
- import WarningIcon from './_virtual/warning.js';
7
+ import { ErrorMessage } from '@rescui/form-field';
8
8
  import { GroupContext } from './parts/group-context.js';
9
9
  import CheckboxControl from './parts/checkbox-control.js';
10
+ import { useBackwardCompatibleId } from './parts/use-backward-compatible-id.js';
10
11
  import styles from './parts/checkbox.p.module.css.js';
11
12
  const THEME_STYLES = {
12
13
  light: styles.themeLight,
@@ -21,6 +22,7 @@ const Checkbox = /*#__PURE__*/React.forwardRef(function Checkbox(_ref, ref) {
21
22
  let {
22
23
  children,
23
24
  className,
25
+ id,
24
26
  disabled,
25
27
  mode = 'classic',
26
28
  size: propsSize = 'm',
@@ -32,6 +34,7 @@ const Checkbox = /*#__PURE__*/React.forwardRef(function Checkbox(_ref, ref) {
32
34
  // eslint-disable-next-line react/prop-types
33
35
  onClick,
34
36
  error,
37
+ reserveErrorLine = false,
35
38
  ...restProps
36
39
  } = _ref;
37
40
  const theme = useThemeWithUndefined(themeFromProps);
@@ -40,8 +43,12 @@ const Checkbox = /*#__PURE__*/React.forwardRef(function Checkbox(_ref, ref) {
40
43
  size: contextSize
41
44
  } = useContext(GroupContext);
42
45
  const size = !inGroup ? propsSize : contextSize || propsSize;
46
+ const uniqueId = `checkbox-list-${useBackwardCompatibleId()}`;
47
+ const errorId = `${id ? id : uniqueId}-error`;
43
48
  return /*#__PURE__*/React.createElement("div", {
44
49
  className: cn(className, styles.container, THEME_STYLES[theme], SIZE_STYLES[size]),
50
+ id: id,
51
+ "data-test": "checkbox__wrapper",
45
52
  "data-rs-internal": 'checkbox'
46
53
  }, /*#__PURE__*/React.createElement(MenuItem, {
47
54
  tag: 'label',
@@ -60,18 +67,16 @@ const Checkbox = /*#__PURE__*/React.forwardRef(function Checkbox(_ref, ref) {
60
67
  mode: mode,
61
68
  theme: theme,
62
69
  isError: Boolean(error),
70
+ errorId: errorId,
63
71
  notUseLabelTag: true,
64
72
  ...restProps
65
73
  })
66
- }, children), error && typeof error !== 'boolean' && /*#__PURE__*/React.createElement("div", {
74
+ }, children), /*#__PURE__*/React.createElement(ErrorMessage, {
75
+ id: errorId,
67
76
  className: styles.errorMessage,
68
- "data-test": "checkbox-error-message",
69
- "data-rs-internal": "checkbox__error-message"
70
- }, /*#__PURE__*/React.createElement(WarningIcon, {
71
- "data-rs-internal": "checkbox__error-icon",
72
- className: styles.errorIcon,
73
- "data-render-all-sizes": true
74
- }), /*#__PURE__*/React.createElement("span", null, error)));
77
+ "data-test": 'checkbox__error',
78
+ reserveLine: reserveErrorLine
79
+ }, error));
75
80
  });
76
81
  Checkbox.propTypes = {
77
82
  checked: PropTypes.bool,
@@ -87,6 +92,9 @@ Checkbox.propTypes = {
87
92
  onBlur: PropTypes.func,
88
93
  indeterminate: PropTypes.bool,
89
94
  mode: PropTypes.oneOf(['classic', 'rock']),
90
- size: PropTypes.oneOf(['s', 'm', 'l'])
95
+ size: PropTypes.oneOf(['s', 'm', 'l']),
96
+ className: PropTypes.string,
97
+ id: PropTypes.string,
98
+ reserveErrorLine: PropTypes.bool
91
99
  };
92
100
  export { Checkbox, Checkbox as default };