react-native-molecules 0.5.0-beta.27 → 0.5.0-beta.29
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/components/ActivityIndicator/ActivityIndicator.tsx +1 -1
- package/components/Button/utils.ts +1 -1
- package/components/Checkbox/Checkbox.tsx +124 -88
- package/components/Checkbox/CheckboxBase.ios.tsx +2 -4
- package/components/Checkbox/CheckboxBase.tsx +3 -10
- package/components/Checkbox/context.tsx +14 -0
- package/components/Checkbox/index.tsx +11 -4
- package/components/Checkbox/types.ts +63 -29
- package/components/Checkbox/utils.ts +25 -83
- package/components/IconButton/IconButton.tsx +16 -17
- package/components/IconButton/types.ts +8 -0
- package/components/IconButton/utils.ts +25 -0
- package/components/Menu/Menu.tsx +31 -20
- package/components/Menu/index.tsx +2 -1
- package/components/Radio/Radio.tsx +188 -0
- package/components/Radio/RadioBase.ios.tsx +69 -0
- package/components/{RadioButton/RadioButtonAndroid.tsx → Radio/RadioBase.tsx} +27 -63
- package/components/Radio/context.tsx +23 -0
- package/components/Radio/index.tsx +20 -0
- package/components/Radio/types.ts +101 -0
- package/components/Radio/utils.ts +115 -0
- package/package.json +1 -1
- package/components/RadioButton/RadioButton.tsx +0 -138
- package/components/RadioButton/RadioButtonGroup.tsx +0 -97
- package/components/RadioButton/RadioButtonIOS.tsx +0 -92
- package/components/RadioButton/RadioButtonItem.tsx +0 -232
- package/components/RadioButton/index.ts +0 -22
- package/components/RadioButton/utils.ts +0 -165
|
@@ -1,232 +0,0 @@
|
|
|
1
|
-
import { forwardRef, memo, useCallback, useContext, useMemo } from 'react';
|
|
2
|
-
import { type StyleProp, StyleSheet, type TextStyle, View, type ViewStyle } from 'react-native';
|
|
3
|
-
|
|
4
|
-
import { resolveStateVariant } from '../../utils';
|
|
5
|
-
import { Text } from '../Text';
|
|
6
|
-
import { TouchableRipple } from '../TouchableRipple';
|
|
7
|
-
import RadioButton from './RadioButton';
|
|
8
|
-
import { RadioButtonContext } from './RadioButtonGroup';
|
|
9
|
-
import { handlePress, isChecked, radioButtonItemStyles } from './utils';
|
|
10
|
-
|
|
11
|
-
export type Props = {
|
|
12
|
-
/**
|
|
13
|
-
* Value of the radio button.
|
|
14
|
-
*/
|
|
15
|
-
value: string;
|
|
16
|
-
/**
|
|
17
|
-
* Label to be displayed on the item.
|
|
18
|
-
*/
|
|
19
|
-
label: string;
|
|
20
|
-
/**
|
|
21
|
-
* Whether radio is disabled.
|
|
22
|
-
*/
|
|
23
|
-
disabled?: boolean;
|
|
24
|
-
/**
|
|
25
|
-
* Function to execute on press.
|
|
26
|
-
*/
|
|
27
|
-
onPress?: () => void;
|
|
28
|
-
/**
|
|
29
|
-
* Accessibility label for the touchable. This is read by the screen reader when the user taps the touchable.
|
|
30
|
-
*/
|
|
31
|
-
accessibilityLabel?: string;
|
|
32
|
-
/**
|
|
33
|
-
* Custom color for unchecked radio.
|
|
34
|
-
*/
|
|
35
|
-
uncheckedColor?: string;
|
|
36
|
-
/**
|
|
37
|
-
* Custom color for radio.
|
|
38
|
-
*/
|
|
39
|
-
color?: string;
|
|
40
|
-
/**
|
|
41
|
-
* Status of radio button.
|
|
42
|
-
*/
|
|
43
|
-
status?: 'checked' | 'unchecked';
|
|
44
|
-
/**
|
|
45
|
-
* Additional styles for container View.
|
|
46
|
-
*/
|
|
47
|
-
style?: StyleProp<ViewStyle>;
|
|
48
|
-
/**
|
|
49
|
-
* TouchableRipple style
|
|
50
|
-
*/
|
|
51
|
-
rippleContainerStyle?: StyleProp<ViewStyle>;
|
|
52
|
-
/**
|
|
53
|
-
* Style that is passed to Label element.
|
|
54
|
-
*/
|
|
55
|
-
labelStyle?: StyleProp<TextStyle>;
|
|
56
|
-
/**
|
|
57
|
-
* Style that is passed to Container element.
|
|
58
|
-
*/
|
|
59
|
-
containerStyle?: StyleProp<ViewStyle>;
|
|
60
|
-
/**
|
|
61
|
-
* testID to be used on tests.
|
|
62
|
-
*/
|
|
63
|
-
testID?: string;
|
|
64
|
-
/**
|
|
65
|
-
* Radio button control position.
|
|
66
|
-
*/
|
|
67
|
-
position?: 'leading' | 'trailing';
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* RadioButton.Item allows you to press the whole row (item) instead of only the RadioButton.
|
|
72
|
-
*
|
|
73
|
-
* <div class="screenshots">
|
|
74
|
-
* <figure>
|
|
75
|
-
* <img class="medium" src="screenshots/radio-item.ios.png" />
|
|
76
|
-
* <figcaption>Pressed</figcaption>
|
|
77
|
-
* </figure>
|
|
78
|
-
* </div>
|
|
79
|
-
*
|
|
80
|
-
* ## Usage
|
|
81
|
-
* ```js
|
|
82
|
-
* import * as React from 'react';
|
|
83
|
-
* import { RadioButton } from 'react-native-paper';
|
|
84
|
-
*
|
|
85
|
-
* const MyComponent = () => {
|
|
86
|
-
* const [value, setValue] = React.useState('first');
|
|
87
|
-
*
|
|
88
|
-
* return (
|
|
89
|
-
* <RadioButton.Group onValueChange={value => setValue(value)} value={value}>
|
|
90
|
-
* <RadioButton.Item label="First item" value="first" />
|
|
91
|
-
* <RadioButton.Item label="Second item" value="second" />
|
|
92
|
-
* </RadioButton.Group>
|
|
93
|
-
* );
|
|
94
|
-
* };
|
|
95
|
-
*
|
|
96
|
-
* export default MyComponent;
|
|
97
|
-
*```
|
|
98
|
-
*/
|
|
99
|
-
const RadioButtonItem = (
|
|
100
|
-
{
|
|
101
|
-
value,
|
|
102
|
-
label,
|
|
103
|
-
style: styleProp,
|
|
104
|
-
labelStyle,
|
|
105
|
-
onPress,
|
|
106
|
-
disabled,
|
|
107
|
-
color,
|
|
108
|
-
uncheckedColor,
|
|
109
|
-
status,
|
|
110
|
-
accessibilityLabel = label,
|
|
111
|
-
testID,
|
|
112
|
-
position = 'trailing',
|
|
113
|
-
containerStyle,
|
|
114
|
-
rippleContainerStyle,
|
|
115
|
-
}: Props,
|
|
116
|
-
ref: any,
|
|
117
|
-
) => {
|
|
118
|
-
const context = useContext(RadioButtonContext);
|
|
119
|
-
|
|
120
|
-
const checked = useMemo(
|
|
121
|
-
() =>
|
|
122
|
-
isChecked({
|
|
123
|
-
contextValue: context?.value,
|
|
124
|
-
status,
|
|
125
|
-
value,
|
|
126
|
-
}) === 'checked',
|
|
127
|
-
[context?.value, status, value],
|
|
128
|
-
);
|
|
129
|
-
|
|
130
|
-
const state = resolveStateVariant({
|
|
131
|
-
disabled: !!disabled,
|
|
132
|
-
checked,
|
|
133
|
-
});
|
|
134
|
-
|
|
135
|
-
radioButtonItemStyles.useVariants({
|
|
136
|
-
state: state as any,
|
|
137
|
-
});
|
|
138
|
-
|
|
139
|
-
// const componentStyles = useComponentStyles('RadioButton_Item', styleProp, {
|
|
140
|
-
// state: resolveStateVariant({
|
|
141
|
-
// disabled: !!disabled,
|
|
142
|
-
// checked,
|
|
143
|
-
// }),
|
|
144
|
-
// });
|
|
145
|
-
|
|
146
|
-
const isLeading = position === 'leading';
|
|
147
|
-
|
|
148
|
-
const { containerStyles, labelStyles, accessibilityState, radioButtonProps } = useMemo(() => {
|
|
149
|
-
return {
|
|
150
|
-
containerStyles: [radioButtonItemStyles.root, styles.container, containerStyle],
|
|
151
|
-
labelStyles: [
|
|
152
|
-
styles.label,
|
|
153
|
-
radioButtonItemStyles.label,
|
|
154
|
-
{
|
|
155
|
-
textAlign: isLeading ? 'right' : 'left',
|
|
156
|
-
},
|
|
157
|
-
labelStyle,
|
|
158
|
-
] as StyleProp<TextStyle>,
|
|
159
|
-
accessibilityState: {
|
|
160
|
-
checked,
|
|
161
|
-
disabled,
|
|
162
|
-
},
|
|
163
|
-
radioButtonProps: {
|
|
164
|
-
value,
|
|
165
|
-
disabled,
|
|
166
|
-
status,
|
|
167
|
-
color,
|
|
168
|
-
uncheckedColor,
|
|
169
|
-
checked,
|
|
170
|
-
style: styleProp,
|
|
171
|
-
},
|
|
172
|
-
};
|
|
173
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
174
|
-
}, [
|
|
175
|
-
checked,
|
|
176
|
-
color,
|
|
177
|
-
containerStyle,
|
|
178
|
-
disabled,
|
|
179
|
-
isLeading,
|
|
180
|
-
labelStyle,
|
|
181
|
-
status,
|
|
182
|
-
styleProp,
|
|
183
|
-
uncheckedColor,
|
|
184
|
-
value,
|
|
185
|
-
state,
|
|
186
|
-
]);
|
|
187
|
-
|
|
188
|
-
const onRadioPress = useCallback(
|
|
189
|
-
() =>
|
|
190
|
-
handlePress({
|
|
191
|
-
onPress: onPress,
|
|
192
|
-
onValueChange: context?.onValueChange,
|
|
193
|
-
value,
|
|
194
|
-
}),
|
|
195
|
-
[onPress, context?.onValueChange, value],
|
|
196
|
-
);
|
|
197
|
-
|
|
198
|
-
return (
|
|
199
|
-
<TouchableRipple
|
|
200
|
-
ref={ref}
|
|
201
|
-
onPress={onRadioPress}
|
|
202
|
-
accessibilityLabel={accessibilityLabel}
|
|
203
|
-
accessibilityRole="radio"
|
|
204
|
-
accessibilityState={accessibilityState}
|
|
205
|
-
testID={testID}
|
|
206
|
-
disabled={disabled}
|
|
207
|
-
style={rippleContainerStyle}>
|
|
208
|
-
<View style={containerStyles} pointerEvents="none">
|
|
209
|
-
{isLeading && <RadioButton {...radioButtonProps} />}
|
|
210
|
-
<Text style={labelStyles}>{label}</Text>
|
|
211
|
-
{!isLeading && <RadioButton {...radioButtonProps} />}
|
|
212
|
-
</View>
|
|
213
|
-
</TouchableRipple>
|
|
214
|
-
);
|
|
215
|
-
};
|
|
216
|
-
|
|
217
|
-
const styles = StyleSheet.create({
|
|
218
|
-
container: {
|
|
219
|
-
flexDirection: 'row',
|
|
220
|
-
alignItems: 'center',
|
|
221
|
-
justifyContent: 'space-between',
|
|
222
|
-
},
|
|
223
|
-
label: {
|
|
224
|
-
flexShrink: 1,
|
|
225
|
-
flexGrow: 1,
|
|
226
|
-
fontSize: 16,
|
|
227
|
-
},
|
|
228
|
-
});
|
|
229
|
-
|
|
230
|
-
RadioButtonItem.displayName = 'RadioButton_Item';
|
|
231
|
-
|
|
232
|
-
export default memo(forwardRef(RadioButtonItem));
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { getRegisteredComponentWithFallback } from '../../core';
|
|
2
|
-
import RadioButtonComponent from './RadioButton';
|
|
3
|
-
import RadioButtonGroup from './RadioButtonGroup';
|
|
4
|
-
import RadioButtonItem from './RadioButtonItem';
|
|
5
|
-
|
|
6
|
-
const RadioButtonDefault = Object.assign(
|
|
7
|
-
// @component ./RadioButton.tsx
|
|
8
|
-
RadioButtonComponent,
|
|
9
|
-
{
|
|
10
|
-
// @component ./RadioButtonGroup.tsx
|
|
11
|
-
Group: RadioButtonGroup,
|
|
12
|
-
// @component ./RadioButtonItem.tsx
|
|
13
|
-
Item: RadioButtonItem,
|
|
14
|
-
},
|
|
15
|
-
);
|
|
16
|
-
|
|
17
|
-
export const RadioButton = getRegisteredComponentWithFallback('RadioButton', RadioButtonDefault);
|
|
18
|
-
|
|
19
|
-
export type { Props as RadioButtonProps } from './RadioButton';
|
|
20
|
-
export type { Props as RadioButtonGroupProps } from './RadioButtonGroup';
|
|
21
|
-
export type { Props as RadioButtonItemProps } from './RadioButtonItem';
|
|
22
|
-
export { radioButtonItemStyles, radioButtonStyles } from './utils';
|
|
@@ -1,165 +0,0 @@
|
|
|
1
|
-
import { StyleSheet } from 'react-native-unistyles';
|
|
2
|
-
|
|
3
|
-
import { getRegisteredComponentStylesWithFallback } from '../../core';
|
|
4
|
-
|
|
5
|
-
// type States = 'disabled' | 'checked' | 'hovered' | 'checkedAndHovered';
|
|
6
|
-
|
|
7
|
-
export const DEFAULT_ICON_SIZE = 24;
|
|
8
|
-
export const ANIMATION_DURATION = 100;
|
|
9
|
-
|
|
10
|
-
const radioButtonStylesDefault = StyleSheet.create(theme => ({
|
|
11
|
-
root: {
|
|
12
|
-
// color: theme.colors.onSurfaceVariant,
|
|
13
|
-
// uncheckedColor: theme.colors.onSurfaceVariant,
|
|
14
|
-
// variants: {
|
|
15
|
-
// state: {
|
|
16
|
-
// checked: {
|
|
17
|
-
// color: theme.colors.primary,
|
|
18
|
-
// },
|
|
19
|
-
// disabled: {
|
|
20
|
-
// color: theme.colors.onSurfaceDisabled,
|
|
21
|
-
// uncheckedColor: theme.colors.onSurfaceDisabled,
|
|
22
|
-
// },
|
|
23
|
-
// },
|
|
24
|
-
// },
|
|
25
|
-
},
|
|
26
|
-
|
|
27
|
-
container: {
|
|
28
|
-
borderRadius: theme.shapes.corner.full as unknown as number,
|
|
29
|
-
},
|
|
30
|
-
radioContainer: {
|
|
31
|
-
alignItems: 'center',
|
|
32
|
-
justifyContent: 'center',
|
|
33
|
-
},
|
|
34
|
-
radio: {
|
|
35
|
-
height: 20,
|
|
36
|
-
width: 20,
|
|
37
|
-
borderRadius: 10,
|
|
38
|
-
margin: 8,
|
|
39
|
-
borderColor: theme.colors.onSurfaceVariant,
|
|
40
|
-
|
|
41
|
-
variants: {
|
|
42
|
-
state: {
|
|
43
|
-
checked: {
|
|
44
|
-
borderColor: theme.colors.primary,
|
|
45
|
-
},
|
|
46
|
-
disabled: {
|
|
47
|
-
borderColor: theme.colors.onSurfaceDisabled,
|
|
48
|
-
},
|
|
49
|
-
},
|
|
50
|
-
},
|
|
51
|
-
},
|
|
52
|
-
dot: {
|
|
53
|
-
height: 10,
|
|
54
|
-
width: 10,
|
|
55
|
-
borderRadius: 5,
|
|
56
|
-
backgroundColor: theme.colors.onSurfaceVariant,
|
|
57
|
-
|
|
58
|
-
variants: {
|
|
59
|
-
state: {
|
|
60
|
-
checked: {
|
|
61
|
-
backgroundColor: theme.colors.primary,
|
|
62
|
-
},
|
|
63
|
-
disabled: {
|
|
64
|
-
backgroundColor: theme.colors.onSurfaceDisabled,
|
|
65
|
-
},
|
|
66
|
-
},
|
|
67
|
-
},
|
|
68
|
-
},
|
|
69
|
-
icon: {
|
|
70
|
-
backgroundColor: theme.colors.onSurfaceVariant,
|
|
71
|
-
|
|
72
|
-
variants: {
|
|
73
|
-
state: {
|
|
74
|
-
checked: {
|
|
75
|
-
backgroundColor: theme.colors.primary,
|
|
76
|
-
},
|
|
77
|
-
disabled: {
|
|
78
|
-
backgroundColor: theme.colors.onSurfaceDisabled,
|
|
79
|
-
},
|
|
80
|
-
},
|
|
81
|
-
},
|
|
82
|
-
},
|
|
83
|
-
stateLayer: {
|
|
84
|
-
variants: {
|
|
85
|
-
state: {
|
|
86
|
-
hovered: {
|
|
87
|
-
backgroundColor: theme.colors.stateLayer.hover.onSurface,
|
|
88
|
-
},
|
|
89
|
-
|
|
90
|
-
checkedAndHovered: {
|
|
91
|
-
backgroundColor: theme.colors.stateLayer.hover.primary,
|
|
92
|
-
},
|
|
93
|
-
},
|
|
94
|
-
},
|
|
95
|
-
},
|
|
96
|
-
}));
|
|
97
|
-
|
|
98
|
-
const radioButtonItemStylesDefault = StyleSheet.create(theme => ({
|
|
99
|
-
root: {
|
|
100
|
-
paddingVertical: theme.spacings['2'],
|
|
101
|
-
paddingHorizontal: theme.spacings['4'],
|
|
102
|
-
|
|
103
|
-
variants: {
|
|
104
|
-
state: {
|
|
105
|
-
checked: {},
|
|
106
|
-
disabled: {},
|
|
107
|
-
},
|
|
108
|
-
},
|
|
109
|
-
},
|
|
110
|
-
label: {
|
|
111
|
-
color: theme.colors.onSurface,
|
|
112
|
-
|
|
113
|
-
variants: {
|
|
114
|
-
state: {
|
|
115
|
-
checked: {},
|
|
116
|
-
disabled: {
|
|
117
|
-
color: theme.colors.onSurfaceDisabled,
|
|
118
|
-
},
|
|
119
|
-
},
|
|
120
|
-
},
|
|
121
|
-
},
|
|
122
|
-
}));
|
|
123
|
-
|
|
124
|
-
export const radioButtonStyles = getRegisteredComponentStylesWithFallback(
|
|
125
|
-
'RadioButton',
|
|
126
|
-
radioButtonStylesDefault,
|
|
127
|
-
);
|
|
128
|
-
export const radioButtonItemStyles = getRegisteredComponentStylesWithFallback(
|
|
129
|
-
'RadioButton_Item',
|
|
130
|
-
radioButtonItemStylesDefault,
|
|
131
|
-
);
|
|
132
|
-
|
|
133
|
-
export const handlePress = ({
|
|
134
|
-
onPress,
|
|
135
|
-
value,
|
|
136
|
-
onValueChange,
|
|
137
|
-
}: {
|
|
138
|
-
onPress?: () => void;
|
|
139
|
-
value: string;
|
|
140
|
-
onValueChange?: (value: string) => void;
|
|
141
|
-
}) => {
|
|
142
|
-
if (onPress && onValueChange) {
|
|
143
|
-
console.warn(
|
|
144
|
-
`onPress in the scope of RadioButtonGroup will not be executed, use onValueChange instead`,
|
|
145
|
-
);
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
onValueChange ? onValueChange(value) : onPress?.();
|
|
149
|
-
};
|
|
150
|
-
|
|
151
|
-
export const isChecked = ({
|
|
152
|
-
value,
|
|
153
|
-
status,
|
|
154
|
-
contextValue,
|
|
155
|
-
}: {
|
|
156
|
-
value: string;
|
|
157
|
-
status?: 'checked' | 'unchecked';
|
|
158
|
-
contextValue?: string;
|
|
159
|
-
}) => {
|
|
160
|
-
if (contextValue !== undefined && contextValue !== null) {
|
|
161
|
-
return contextValue === value ? 'checked' : 'unchecked';
|
|
162
|
-
} else {
|
|
163
|
-
return status;
|
|
164
|
-
}
|
|
165
|
-
};
|