react-native-molecules 0.5.0-beta.29 → 0.5.0-beta.30

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.
@@ -10,13 +10,13 @@ import type { CheckboxLabelProps, CheckboxProps, CheckboxRowProps } from './type
10
10
  import { checkboxRowStyles } from './utils';
11
11
 
12
12
  /**
13
- * The checkbox control (the box). Use inside a CheckboxRow, or standalone with `value`/`onValueChange`.
13
+ * The checkbox control (the box). Use inside a CheckboxRow, or standalone with `value`/`onChange`.
14
14
  */
15
15
  const Checkbox = (
16
16
  {
17
17
  value: valueProp,
18
18
  defaultValue,
19
- onValueChange,
19
+ onChange: onChangeProp,
20
20
  indeterminate,
21
21
  disabled: disabledProp,
22
22
  size: sizeProp,
@@ -30,7 +30,7 @@ const Checkbox = (
30
30
  const [value, setValue] = useControlledValue({
31
31
  value: valueProp,
32
32
  defaultValue,
33
- onChange: onValueChange,
33
+ onChange: onChangeProp,
34
34
  disabled: disabledProp,
35
35
  });
36
36
 
@@ -114,7 +114,7 @@ export const CheckboxRow = memo(
114
114
  {
115
115
  value: valueProp,
116
116
  defaultValue,
117
- onValueChange,
117
+ onChange,
118
118
  indeterminate,
119
119
  disabled,
120
120
  size,
@@ -129,7 +129,7 @@ export const CheckboxRow = memo(
129
129
  const [value, setValue] = useControlledValue({
130
130
  value: valueProp,
131
131
  defaultValue,
132
- onChange: onValueChange,
132
+ onChange,
133
133
  disabled,
134
134
  });
135
135
 
@@ -137,8 +137,8 @@ export const CheckboxRow = memo(
137
137
 
138
138
  const onToggle = useCallback(() => {
139
139
  if (disabled) return;
140
- setValue(!checked);
141
- }, [disabled, setValue, checked]);
140
+ setValue(indeterminate ? true : !checked);
141
+ }, [disabled, setValue, checked, indeterminate]);
142
142
 
143
143
  const contextValue = useMemo(
144
144
  () => ({ checked, onToggle, disabled, indeterminate, size, labelId }),
@@ -45,8 +45,8 @@ const CheckboxIOS = (
45
45
  }, [checked, colorProp, indeterminate, style, state, size, checkedColor]);
46
46
 
47
47
  const onChange = useCallback(() => {
48
- onChangeProp?.(!checked);
49
- }, [checked, onChangeProp]);
48
+ onChangeProp?.(indeterminate ? true : !checked);
49
+ }, [checked, indeterminate, onChangeProp]);
50
50
 
51
51
  const icon = indeterminate ? 'minus' : 'check';
52
52
 
@@ -57,7 +57,7 @@ const CheckboxIOS = (
57
57
  onPress={onChange}
58
58
  disabled={disabled}
59
59
  accessibilityRole="checkbox"
60
- accessibilityState={{ disabled, checked }}
60
+ accessibilityState={{ disabled, checked: indeterminate ? false : checked }}
61
61
  accessibilityLiveRegion="polite"
62
62
  style={rippleContainerStyles}
63
63
  testID={testID}
@@ -54,8 +54,8 @@ const CheckboxAndroid = (
54
54
  }, [checked, colorProp, uncheckedColorProp, style, size, state]);
55
55
 
56
56
  const onChange = useCallback(() => {
57
- onChangeProp?.(!checked);
58
- }, [checked, onChangeProp]);
57
+ onChangeProp?.(indeterminate ? true : !checked);
58
+ }, [checked, indeterminate, onChangeProp]);
59
59
 
60
60
  const icon = indeterminate
61
61
  ? 'minus-box'
@@ -63,7 +63,10 @@ const CheckboxAndroid = (
63
63
  ? 'checkbox-marked'
64
64
  : 'checkbox-blank-outline';
65
65
 
66
- const accessibilityState = useMemo(() => ({ disabled, checked }), [checked, disabled]);
66
+ const accessibilityState = useMemo(
67
+ () => ({ disabled, checked: indeterminate ? false : checked }),
68
+ [checked, disabled, indeterminate],
69
+ );
67
70
 
68
71
  return (
69
72
  <TouchableRipple
@@ -53,7 +53,7 @@ export type CheckboxBaseProps = Omit<TouchableRippleProps, 'children'> & {
53
53
  };
54
54
 
55
55
  /**
56
- * The checkbox control (the box). Use inside a CheckboxRow, or standalone with `value`/`onValueChange`.
56
+ * The checkbox control (the box). Use inside a CheckboxRow, or standalone with `value`/`onChange`.
57
57
  */
58
58
  export type CheckboxProps = Omit<CheckboxBaseProps, 'value' | 'onChange'> & {
59
59
  /**
@@ -67,7 +67,7 @@ export type CheckboxProps = Omit<CheckboxBaseProps, 'value' | 'onChange'> & {
67
67
  /**
68
68
  * Called when the checked state changes.
69
69
  */
70
- onValueChange?: (newValue: boolean) => void;
70
+ onChange?: (newValue: boolean) => void;
71
71
  };
72
72
 
73
73
  export type CheckboxRowProps = ViewProps & {
@@ -82,7 +82,7 @@ export type CheckboxRowProps = ViewProps & {
82
82
  /**
83
83
  * Called when the checked state changes.
84
84
  */
85
- onValueChange?: (newValue: boolean) => void;
85
+ onChange?: (newValue: boolean) => void;
86
86
  /**
87
87
  * Whether the checkbox is in the indeterminate state.
88
88
  */
@@ -39,7 +39,7 @@ const Radio = (
39
39
  if (item) {
40
40
  item.onSelect();
41
41
  } else if (value !== undefined) {
42
- group?.onValueChange(value);
42
+ group?.onChange(value);
43
43
  }
44
44
  }, [disabled, item, group, value]);
45
45
 
@@ -119,7 +119,7 @@ export const RadioRow = memo(
119
119
 
120
120
  const onSelect = useCallback(() => {
121
121
  if (disabled) return;
122
- group?.onValueChange(value);
122
+ group?.onChange(value);
123
123
  }, [disabled, group, value]);
124
124
 
125
125
  const contextValue = useMemo(
@@ -144,7 +144,7 @@ RadioRow.displayName = 'Radio_Row';
144
144
  * Controls a group of radios, holding the selected value.
145
145
  *
146
146
  * ```tsx
147
- * <RadioGroup value={value} onValueChange={setValue}>
147
+ * <RadioGroup value={value} onChange={setValue}>
148
148
  * <RadioRow value="first">
149
149
  * <Radio />
150
150
  * <Radio.Label>First option</Radio.Label>
@@ -156,21 +156,21 @@ export const RadioGroup = memo(
156
156
  ({
157
157
  value: valueProp,
158
158
  defaultValue,
159
- onValueChange: onChange,
159
+ onChange,
160
160
  disabled,
161
161
  size,
162
162
  children,
163
163
  ...rest
164
164
  }: RadioGroupProps) => {
165
- const [value, onValueChange] = useControlledValue({
165
+ const [value, setValue] = useControlledValue({
166
166
  value: valueProp,
167
167
  defaultValue,
168
168
  onChange,
169
169
  });
170
170
 
171
171
  const contextValue = useMemo(
172
- () => ({ value, onValueChange, disabled, size }),
173
- [value, onValueChange, disabled, size],
172
+ () => ({ value, onChange: setValue, disabled, size }),
173
+ [value, setValue, disabled, size],
174
174
  );
175
175
 
176
176
  return (
@@ -4,7 +4,7 @@ import type { Size } from './types';
4
4
 
5
5
  export type RadioGroupContextType = {
6
6
  value?: string;
7
- onValueChange: (value: string) => void;
7
+ onChange: (value: string) => void;
8
8
  disabled?: boolean;
9
9
  size?: Size;
10
10
  };
@@ -18,7 +18,7 @@ export type RadioGroupProps = ViewProps & {
18
18
  /**
19
19
  * Called when the selected value changes.
20
20
  */
21
- onValueChange?: (value: string) => void;
21
+ onChange?: (value: string) => void;
22
22
  /**
23
23
  * Disables every radio in the group.
24
24
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-molecules",
3
- "version": "0.5.0-beta.29",
3
+ "version": "0.5.0-beta.30",
4
4
  "author": "Thet Aung <thetaung.dev@gmail.com>",
5
5
  "license": "MIT",
6
6
  "main": "index.ts",