diff --git a/src/components/RadioButton/RadioButton.tsx b/src/components/RadioButton/RadioButton.tsx index c50923c3..8eb0e7a6 100644 --- a/src/components/RadioButton/RadioButton.tsx +++ b/src/components/RadioButton/RadioButton.tsx @@ -5,10 +5,12 @@ import { View, type ViewProps, } from 'react-native' -import Animated, { LinearTransition } from 'react-native-reanimated' +import Animated from 'react-native-reanimated' import { StyleSheet } from 'react-native-unistyles' +const AnimatedPressable = Animated.createAnimatedComponent(Pressable) + export interface RadioButtonProps extends AccessibilityProps, Pick { /** Обработчик нажатия на кнопку */ @@ -50,13 +52,8 @@ export const RadioButton = memo( return ( - {!disabled && state === 'danger' && ( - - )} - + ( onPressOut={onPressOut} {...rest} > - - + + ) } ) -const radioStyles = StyleSheet.create(({ theme }) => ({ +const radioStyles = StyleSheet.create(({ theme, border }) => ({ container: { width: theme.Form.RadioButton.radiobuttonWidth, height: theme.Form.RadioButton.radiobuttonHeight, - borderRadius: theme.Form.RadioButton.radiobuttonWidth, + borderRadius: border.Radius['rounded-full'], + borderWidth: 1, alignItems: 'center', justifyContent: 'center', - margin: theme.General.focusShadowWidth, + transitionProperty: ['borderColor', 'backgroundColor'], + transitionDuration: 100, variants: { checked: { true: { borderColor: theme.Form.RadioButton.radiobuttonActiveBorderColor, backgroundColor: theme.Form.RadioButton.radiobuttonActiveBorderColor, - borderWidth: 5, }, false: { borderColor: theme.Form.InputText.inputBorderColor, - borderWidth: 1, backgroundColor: theme.Form.InputText.inputBg, }, }, - pressed: { - true: { borderColor: theme.Form.InputText.inputHoverBorderColor }, - false: {}, - }, - state: { - danger: { borderColor: theme.Form.InputText.inputErrorBorderColor }, - }, + pressed: { true: {}, false: {} }, disabled: { true: { borderColor: theme.Form.InputText.inputBorderColor, backgroundColor: theme.Button.Disabled.disabledButtonBg, opacity: 0.6, - borderWidth: 1, }, false: {}, }, + state: { danger: {}, default: {} }, }, compoundVariants: [ { @@ -116,27 +107,28 @@ const radioStyles = StyleSheet.create(({ theme }) => ({ pressed: 'true', styles: { borderColor: theme.Form.RadioButton.radiobuttonActiveHoverBorderColor, - backgroundColor: - theme.Form.RadioButton.radiobuttonActiveHoverBorderColor, - borderWidth: 5, + backgroundColor: theme.Form.RadioButton.radiobuttonActiveHoverBg, }, }, { - state: 'danger', checked: 'true', + disabled: 'true', styles: { - borderColor: theme.Form.InputText.inputErrorBorderColor, + borderColor: theme.Form.RadioButton.radiobuttonActiveBorderColor, backgroundColor: theme.Form.RadioButton.radiobuttonActiveBorderColor, - borderWidth: 1, }, }, { - checked: 'true', - disabled: 'true', + state: 'danger', + disabled: 'false', + checked: 'false', + styles: { borderColor: theme.Form.InputText.inputErrorBorderColor }, + }, + { + checked: 'false', + pressed: 'true', styles: { - borderColor: theme.Form.RadioButton.radiobuttonActiveBorderColor, - backgroundColor: theme.Form.RadioButton.radiobuttonActiveBorderColor, - borderWidth: 5, + borderColor: theme.Form.RadioButton.radiobuttonActiveHoverBorderColor, }, }, ], @@ -144,31 +136,29 @@ const radioStyles = StyleSheet.create(({ theme }) => ({ center: { width: theme.Form.RadioButton.radiobuttonIconSize, height: theme.Form.RadioButton.radiobuttonIconSize, - borderRadius: theme.Form.RadioButton.radiobuttonIconSize, + borderRadius: border.Radius['rounded-full'], backgroundColor: theme.Form.InputText.inputBg, - variants: { - checked: { true: {}, false: {} }, - disabled: { true: {}, false: {} }, - }, - compoundVariants: [ - { - disabled: 'true', - checked: 'false', - styles: { backgroundColor: 'transparent' }, - }, - ], + transitionProperty: ['opacity'], + transitionDuration: 100, + variants: { checked: { false: { opacity: 0 }, true: { opacity: 1 } } }, }, outline: { position: 'absolute', + top: -theme.General.focusShadowWidth, + left: -theme.General.focusShadowWidth, width: theme.Form.RadioButton.radiobuttonWidth + theme.General.focusShadowWidth * 2, height: theme.Form.RadioButton.radiobuttonHeight + theme.General.focusShadowWidth * 2, - borderRadius: - theme.Form.RadioButton.radiobuttonHeight + - theme.General.focusShadowWidth * 2, + borderRadius: border.Radius['rounded-full'], backgroundColor: theme.General.focusOutlineErrorColor, + transitionProperty: 'opacity', + transitionDuration: 100, + variants: { + state: { danger: { opacity: 1 }, default: { opacity: 0 } }, + disabled: { true: { opacity: 0 } }, + }, }, })) diff --git a/src/components/RadioButton/__tests__/__snapshots__/RadioButton.test.tsx.snap b/src/components/RadioButton/__tests__/__snapshots__/RadioButton.test.tsx.snap index 86e144d6..cb279583 100644 --- a/src/components/RadioButton/__tests__/__snapshots__/RadioButton.test.tsx.snap +++ b/src/components/RadioButton/__tests__/__snapshots__/RadioButton.test.tsx.snap @@ -17,27 +17,28 @@ exports[`RadioButton snapshots checked = false, disabled = false, state = danger jestInlineStyle={ { "backgroundColor": "#fff0f0", - "borderRadius": 28, + "borderRadius": 100, "height": 28, + "left": -3.5, + "opacity": 1, "position": "absolute", + "top": -3.5, + "transitionDuration": 100, + "transitionProperty": "opacity", "width": 28, } } - layout={ - LinearTransition { - "build": [Function], - "durationV": 100, - "randomizeDelay": false, - "reduceMotionV": "system", - } - } + pointerEvents="none" style={ [ { "backgroundColor": "#fff0f0", - "borderRadius": 28, + "borderRadius": 100, "height": 28, + "left": -3.5, + "opacity": 1, "position": "absolute", + "top": -3.5, "width": 28, }, ] @@ -64,6 +65,33 @@ exports[`RadioButton snapshots checked = false, disabled = false, state = danger accessible={true} collapsable={false} focusable={true} + jestAnimatedProps={ + { + "value": {}, + } + } + jestAnimatedStyle={ + { + "value": {}, + } + } + jestInlineStyle={ + { + "alignItems": "center", + "backgroundColor": "#ffffff", + "borderColor": "#db3424", + "borderRadius": 100, + "borderWidth": 1, + "height": 21, + "justifyContent": "center", + "transitionDuration": 100, + "transitionProperty": [ + "borderColor", + "backgroundColor", + ], + "width": 21, + } + } onBlur={[Function]} onClick={[Function]} onFocus={[Function]} @@ -74,29 +102,57 @@ exports[`RadioButton snapshots checked = false, disabled = false, state = danger onResponderTerminationRequest={[Function]} onStartShouldSetResponder={[Function]} style={ - { - "alignItems": "center", - "backgroundColor": "#ffffff", - "borderColor": "#db3424", - "borderRadius": 21, - "borderWidth": 1, - "height": 21, - "justifyContent": "center", - "margin": 3.5, - "width": 21, - } + [ + { + "alignItems": "center", + "backgroundColor": "#ffffff", + "borderColor": "#db3424", + "borderRadius": 100, + "borderWidth": 1, + "height": 21, + "justifyContent": "center", + "width": 21, + }, + ] } testID="RadioButton_Pressable" > @@ -104,6 +160,46 @@ exports[`RadioButton snapshots checked = false, disabled = false, state = danger exports[`RadioButton snapshots checked = false, disabled = false, state = default 1`] = ` + @@ -165,6 +316,48 @@ exports[`RadioButton snapshots checked = false, disabled = false, state = defaul exports[`RadioButton snapshots checked = false, disabled = true, state = default 1`] = ` + @@ -242,27 +491,28 @@ exports[`RadioButton snapshots checked = true, disabled = false, state = danger jestInlineStyle={ { "backgroundColor": "#fff0f0", - "borderRadius": 28, + "borderRadius": 100, "height": 28, + "left": -3.5, + "opacity": 1, "position": "absolute", + "top": -3.5, + "transitionDuration": 100, + "transitionProperty": "opacity", "width": 28, } } - layout={ - LinearTransition { - "build": [Function], - "durationV": 100, - "randomizeDelay": false, - "reduceMotionV": "system", - } - } + pointerEvents="none" style={ [ { "backgroundColor": "#fff0f0", - "borderRadius": 28, + "borderRadius": 100, "height": 28, + "left": -3.5, + "opacity": 1, "position": "absolute", + "top": -3.5, "width": 28, }, ] @@ -289,6 +539,33 @@ exports[`RadioButton snapshots checked = true, disabled = false, state = danger accessible={true} collapsable={false} focusable={true} + jestAnimatedProps={ + { + "value": {}, + } + } + jestAnimatedStyle={ + { + "value": {}, + } + } + jestInlineStyle={ + { + "alignItems": "center", + "backgroundColor": "#2b2e33", + "borderColor": "#2b2e33", + "borderRadius": 100, + "borderWidth": 1, + "height": 21, + "justifyContent": "center", + "transitionDuration": 100, + "transitionProperty": [ + "borderColor", + "backgroundColor", + ], + "width": 21, + } + } onBlur={[Function]} onClick={[Function]} onFocus={[Function]} @@ -299,29 +576,57 @@ exports[`RadioButton snapshots checked = true, disabled = false, state = danger onResponderTerminationRequest={[Function]} onStartShouldSetResponder={[Function]} style={ - { - "alignItems": "center", - "backgroundColor": "#2b2e33", - "borderColor": "#db3424", - "borderRadius": 21, - "borderWidth": 1, - "height": 21, - "justifyContent": "center", - "margin": 3.5, - "width": 21, - } + [ + { + "alignItems": "center", + "backgroundColor": "#2b2e33", + "borderColor": "#2b2e33", + "borderRadius": 100, + "borderWidth": 1, + "height": 21, + "justifyContent": "center", + "width": 21, + }, + ] } testID="RadioButton_Pressable" > @@ -329,6 +634,46 @@ exports[`RadioButton snapshots checked = true, disabled = false, state = danger exports[`RadioButton snapshots checked = true, disabled = false, state = default 1`] = ` + @@ -390,6 +790,48 @@ exports[`RadioButton snapshots checked = true, disabled = false, state = default exports[`RadioButton snapshots checked = true, disabled = true, state = default 1`] = ` + @@ -452,6 +950,46 @@ exports[`RadioButton snapshots checked = true, disabled = true, state = default exports[`RadioButton snapshots default 1`] = ` +