diff --git a/docs/docusaurus.config.js b/docs/docusaurus.config.js index 1dec1bb6ec..bc75f57c94 100644 --- a/docs/docusaurus.config.js +++ b/docs/docusaurus.config.js @@ -92,8 +92,6 @@ const config = { }, Checkbox: { Checkbox: 'Checkbox/Checkbox', - CheckboxAndroid: 'Checkbox/CheckboxAndroid', - CheckboxIOS: 'Checkbox/CheckboxIOS', CheckboxItem: 'Checkbox/CheckboxItem', }, Chip: { diff --git a/example/src/Examples/CheckboxItemExample.tsx b/example/src/Examples/CheckboxItemExample.tsx index acafd709b7..7e7c0751b8 100644 --- a/example/src/Examples/CheckboxItemExample.tsx +++ b/example/src/Examples/CheckboxItemExample.tsx @@ -7,8 +7,6 @@ import ScreenWrapper from '../ScreenWrapper'; const CheckboxExample = () => { const [checkedDefault, setCheckedDefault] = React.useState(true); - const [checkedAndroid, setCheckedAndroid] = React.useState(true); - const [checkedIOS, setCheckedIOS] = React.useState(true); const [checkedLeadingControl, setCheckedLeadingControl] = React.useState(true); const [checkedDisabled, setCheckedDisabled] = React.useState(true); @@ -17,27 +15,14 @@ const CheckboxExample = () => { return ( setCheckedDefault(!checkedDefault)} /> - setCheckedAndroid(!checkedAndroid)} - /> - setCheckedIOS(!checkedIOS)} - /> setCheckedLeadingControl(!checkedLeadingControl)} - mode="ios" position="leading" /> & { /** * Status of checkbox. */ @@ -22,11 +29,11 @@ export type Props = { /** * Custom color for unchecked checkbox. */ - uncheckedColor?: string; + uncheckedColor?: ColorValue; /** * Custom color for checkbox. */ - color?: string; + color?: ColorValue; /** * Whether the checkbox is in an error state. When true, the outline * (unchecked) and container (checked / indeterminate) use @@ -44,6 +51,8 @@ export type Props = { testID?: string; }; +const ANIMATION_DURATION = 100; + /** * Checkboxes allow the selection of multiple options from a set. * @@ -68,15 +77,131 @@ export type Props = { * export default MyComponent; * ``` */ -const Checkbox = ({ theme: themeOverrides, ...props }: Props) => { +const Checkbox = ({ + status, + theme: themeOverrides, + disabled, + onPress, + testID, + error, + ...rest +}: Props) => { const theme = useInternalTheme(themeOverrides); - return Platform.OS === 'ios' ? ( - - ) : ( - + const { current: scaleAnim } = React.useRef( + new Animated.Value(1) + ); + const isFirstRendering = React.useRef(true); + + const { + animation: { scale }, + } = theme; + + React.useEffect(() => { + // Do not run animation on very first rendering + if (isFirstRendering.current) { + isFirstRendering.current = false; + return; + } + + const checked = status === 'checked'; + + Animated.sequence([ + Animated.timing(scaleAnim, { + toValue: 0.85, + duration: checked ? ANIMATION_DURATION * scale : 0, + useNativeDriver: false, + }), + Animated.timing(scaleAnim, { + toValue: 1, + duration: checked + ? ANIMATION_DURATION * scale + : ANIMATION_DURATION * scale * 1.75, + useNativeDriver: false, + }), + ]).start(); + }, [status, scaleAnim, scale]); + + const checked = status === 'checked'; + const indeterminate = status === 'indeterminate'; + + const { selectionControlColor, selectionControlOpacity } = + getSelectionControlColor({ + theme, + disabled, + checked, + customColor: rest.color, + customUncheckedColor: rest.uncheckedColor, + error, + }); + + const borderWidth = scaleAnim.interpolate({ + inputRange: [0.8, 1], + outputRange: [7, 0], + }); + + const icon = indeterminate + ? 'minus-box' + : checked + ? 'checkbox-marked' + : 'checkbox-blank-outline'; + + return ( + + + + + + + + ); }; +const styles = StyleSheet.create({ + container: { + borderRadius: 18, + width: 36, + height: 36, + padding: 6, + }, + fillContainer: { + alignItems: 'center', + justifyContent: 'center', + }, + fill: { + height: 14, + width: 14, + }, +}); + export default Checkbox; // @component-docs ignore-next-line diff --git a/src/components/Checkbox/CheckboxAndroid.tsx b/src/components/Checkbox/CheckboxAndroid.tsx deleted file mode 100644 index d73bdf57c5..0000000000 --- a/src/components/Checkbox/CheckboxAndroid.tsx +++ /dev/null @@ -1,194 +0,0 @@ -import * as React from 'react'; -import { - Animated, - ColorValue, - GestureResponderEvent, - StyleSheet, - View, -} from 'react-native'; - -import { getAndroidSelectionControlColor } from './utils'; -import { useInternalTheme } from '../../core/theming'; -import type { $RemoveChildren, ThemeProp } from '../../types'; -import MaterialCommunityIcon from '../MaterialCommunityIcon'; -import TouchableRipple from '../TouchableRipple/TouchableRipple'; - -export type Props = $RemoveChildren & { - /** - * Status of checkbox. - */ - status: 'checked' | 'unchecked' | 'indeterminate'; - /** - * Whether checkbox is disabled. - */ - disabled?: boolean; - /** - * Function to execute on press. - */ - onPress?: (e: GestureResponderEvent) => void; - /** - * Custom color for unchecked checkbox. - */ - uncheckedColor?: ColorValue; - /** - * Custom color for checkbox. - */ - color?: ColorValue; - /** - * Whether the checkbox is in an error state. When true, the outline - * (unchecked) and container (checked / indeterminate) use - * `theme.colors.error`. `disabled` and explicit `color`/`uncheckedColor` - * overrides take precedence. - */ - error?: boolean; - /** - * @optional - */ - theme?: ThemeProp; - /** - * testID to be used on tests. - */ - testID?: string; -}; - -// From https://material.io/design/motion/speed.html#duration -const ANIMATION_DURATION = 100; - -/** - * Checkboxes allow the selection of multiple options from a set. - * This component follows platform guidelines for Android, but can be used - * on any platform. - * - * @extends TouchableRipple props https://callstack.github.io/react-native-paper/docs/components/TouchableRipple - */ -const CheckboxAndroid = ({ - status, - theme: themeOverrides, - disabled, - onPress, - testID, - error, - ...rest -}: Props) => { - const theme = useInternalTheme(themeOverrides); - const { current: scaleAnim } = React.useRef( - new Animated.Value(1) - ); - const isFirstRendering = React.useRef(true); - - const { - animation: { scale }, - } = theme; - - React.useEffect(() => { - // Do not run animation on very first rendering - if (isFirstRendering.current) { - isFirstRendering.current = false; - return; - } - - const checked = status === 'checked'; - - Animated.sequence([ - Animated.timing(scaleAnim, { - toValue: 0.85, - duration: checked ? ANIMATION_DURATION * scale : 0, - useNativeDriver: false, - }), - Animated.timing(scaleAnim, { - toValue: 1, - duration: checked - ? ANIMATION_DURATION * scale - : ANIMATION_DURATION * scale * 1.75, - useNativeDriver: false, - }), - ]).start(); - }, [status, scaleAnim, scale]); - - const checked = status === 'checked'; - const indeterminate = status === 'indeterminate'; - - const { selectionControlColor, selectionControlOpacity } = - getAndroidSelectionControlColor({ - theme, - disabled, - checked, - customColor: rest.color, - customUncheckedColor: rest.uncheckedColor, - error, - }); - - const borderWidth = scaleAnim.interpolate({ - inputRange: [0.8, 1], - outputRange: [7, 0], - }); - - const icon = indeterminate - ? 'minus-box' - : checked - ? 'checkbox-marked' - : 'checkbox-blank-outline'; - - return ( - - - - - - - - - ); -}; - -CheckboxAndroid.displayName = 'Checkbox.Android'; - -const styles = StyleSheet.create({ - container: { - borderRadius: 18, - width: 36, - height: 36, - padding: 6, - }, - fillContainer: { - alignItems: 'center', - justifyContent: 'center', - }, - fill: { - height: 14, - width: 14, - }, -}); - -export default CheckboxAndroid; - -// @component-docs ignore-next-line -export { CheckboxAndroid }; diff --git a/src/components/Checkbox/CheckboxIOS.tsx b/src/components/Checkbox/CheckboxIOS.tsx deleted file mode 100644 index 5830359372..0000000000 --- a/src/components/Checkbox/CheckboxIOS.tsx +++ /dev/null @@ -1,116 +0,0 @@ -import * as React from 'react'; -import { - ColorValue, - GestureResponderEvent, - StyleSheet, - View, -} from 'react-native'; - -import { getSelectionControlIOSColor } from './utils'; -import { useInternalTheme } from '../../core/theming'; -import type { $RemoveChildren, ThemeProp } from '../../types'; -import MaterialCommunityIcon from '../MaterialCommunityIcon'; -import TouchableRipple from '../TouchableRipple/TouchableRipple'; - -export type Props = $RemoveChildren & { - /** - * Status of checkbox. - */ - status: 'checked' | 'unchecked' | 'indeterminate'; - /** - * Whether checkbox is disabled. - */ - disabled?: boolean; - /** - * Function to execute on press. - */ - onPress?: (e: GestureResponderEvent) => void; - /** - * Custom color for checkbox. - */ - color?: ColorValue; - /** - * Whether the checkbox is in an error state. When true, the checked / - * indeterminate icon uses `theme.colors.error`. `disabled` and explicit - * `color` overrides take precedence. - */ - error?: boolean; - /** - * @optional - */ - theme?: ThemeProp; - /** - * testID to be used on tests. - */ - testID?: string; -}; - -/** - * Checkboxes allow the selection of multiple options from a set. - * This component follows platform guidelines for iOS, but can be used - * on any platform. - * - * @extends TouchableRipple props https://callstack.github.io/react-native-paper/docs/components/TouchableRipple - */ -const CheckboxIOS = ({ - status, - disabled, - onPress, - theme: themeOverrides, - testID, - error, - ...rest -}: Props) => { - const theme = useInternalTheme(themeOverrides); - const checked = status === 'checked'; - const indeterminate = status === 'indeterminate'; - - const { checkedColor } = getSelectionControlIOSColor({ - theme, - disabled, - customColor: rest.color, - error, - }); - - const icon = indeterminate ? 'minus' : 'check'; - const opacity = indeterminate || checked ? 1 : 0; - - return ( - - - - - - ); -}; - -CheckboxIOS.displayName = 'Checkbox.IOS'; - -const styles = StyleSheet.create({ - container: { - borderRadius: 18, - padding: 6, - }, -}); - -export default CheckboxIOS; - -// @component-docs ignore-next-line -export { CheckboxIOS }; diff --git a/src/components/Checkbox/CheckboxItem.tsx b/src/components/Checkbox/CheckboxItem.tsx index 9037137e7a..c0935ffb7a 100644 --- a/src/components/Checkbox/CheckboxItem.tsx +++ b/src/components/Checkbox/CheckboxItem.tsx @@ -10,8 +10,6 @@ import { } from 'react-native'; import Checkbox from './Checkbox'; -import CheckboxAndroid from './CheckboxAndroid'; -import CheckboxIOS from './CheckboxIOS'; import { useInternalTheme } from '../../core/theming'; import { tokens } from '../../theme/tokens'; import type { ThemeProp, TypescaleKey } from '../../types'; @@ -99,11 +97,6 @@ export type Props = { * Checkbox control position. */ position?: 'leading' | 'trailing'; - /** - * Whether `` or `` should be used. - * Left undefined `` will be used. - */ - mode?: 'android' | 'ios'; /** * Sets additional distance outside of element in which a press can be detected. */ @@ -138,7 +131,6 @@ const CheckboxItem = ({ labelStyle, theme: themeOverrides, testID, - mode, position = 'trailing', accessibilityLabel = label, disabled, @@ -151,15 +143,7 @@ const CheckboxItem = ({ const theme = useInternalTheme(themeOverrides); const checkboxProps = { ...props, status, theme, disabled }; const isLeading = position === 'leading'; - let checkbox; - - if (mode === 'android') { - checkbox = ; - } else if (mode === 'ios') { - checkbox = ; - } else { - checkbox = ; - } + const checkbox = ; const textColor = theme.colors.onSurface; const textAlign = isLeading ? 'right' : 'left'; diff --git a/src/components/Checkbox/index.ts b/src/components/Checkbox/index.ts index 54a65538c8..32274f97d9 100644 --- a/src/components/Checkbox/index.ts +++ b/src/components/Checkbox/index.ts @@ -1,6 +1,4 @@ import CheckboxComponent from './Checkbox'; -import CheckboxAndroid from './CheckboxAndroid'; -import CheckboxIOS from './CheckboxIOS'; import CheckboxItem from './CheckboxItem'; const Checkbox = Object.assign( @@ -9,10 +7,6 @@ const Checkbox = Object.assign( { // @component ./CheckboxItem.tsx Item: CheckboxItem, - // @component ./CheckboxAndroid.tsx - Android: CheckboxAndroid, - // @component ./CheckboxIOS.tsx - IOS: CheckboxIOS, } ); diff --git a/src/components/Checkbox/utils.ts b/src/components/Checkbox/utils.ts index 87362df00c..1314193174 100644 --- a/src/components/Checkbox/utils.ts +++ b/src/components/Checkbox/utils.ts @@ -5,7 +5,7 @@ import type { InternalTheme } from '../../types'; const { stateOpacity } = tokens.md.ref; -const getAndroidCheckedColor = ({ +const getCheckedColor = ({ theme, customColor, error, @@ -25,7 +25,7 @@ const getAndroidCheckedColor = ({ return theme.colors.primary; }; -const getAndroidUncheckedColor = ({ +const getUncheckedColor = ({ theme, customUncheckedColor, error, @@ -45,7 +45,7 @@ const getAndroidUncheckedColor = ({ return theme.colors.onSurfaceVariant; }; -const getAndroidControlColor = ({ +const getControlColor = ({ theme, checked, disabled, @@ -68,7 +68,7 @@ const getAndroidControlColor = ({ return uncheckedColor; }; -export const getAndroidSelectionControlColor = ({ +export const getSelectionControlColor = ({ theme, disabled, checked, @@ -83,8 +83,8 @@ export const getAndroidSelectionControlColor = ({ customUncheckedColor?: ColorValue; error?: boolean; }) => { - const checkedColor = getAndroidCheckedColor({ theme, customColor, error }); - const uncheckedColor = getAndroidUncheckedColor({ + const checkedColor = getCheckedColor({ theme, customColor, error }); + const uncheckedColor = getUncheckedColor({ theme, customUncheckedColor, error, @@ -94,7 +94,7 @@ export const getAndroidSelectionControlColor = ({ : stateOpacity.enabled; return { - selectionControlColor: getAndroidControlColor({ + selectionControlColor: getControlColor({ theme, disabled, checked, @@ -104,56 +104,3 @@ export const getAndroidSelectionControlColor = ({ selectionControlOpacity, }; }; - -const getIOSCheckedColor = ({ - theme, - disabled, - customColor, - error, -}: { - theme: InternalTheme; - customColor?: ColorValue; - disabled?: boolean; - error?: boolean; -}) => { - if (disabled) { - return theme.colors.primary; - } - - if (customColor) { - return customColor; - } - - if (error) { - return theme.colors.error; - } - - return theme.colors.primary; -}; - -export const getSelectionControlIOSColor = ({ - theme, - disabled, - customColor, - error, -}: { - theme: InternalTheme; - disabled?: boolean; - customColor?: ColorValue; - error?: boolean; -}) => { - const checkedColor = getIOSCheckedColor({ - theme, - disabled, - customColor, - error, - }); - const checkedColorOpacity = disabled - ? stateOpacity.disabled - : stateOpacity.enabled; - - return { - checkedColor, - checkedColorOpacity, - }; -}; diff --git a/src/components/RadioButton/RadioButtonAndroid.tsx b/src/components/RadioButton/RadioButtonAndroid.tsx index 4b68455101..cb1757726b 100644 --- a/src/components/RadioButton/RadioButtonAndroid.tsx +++ b/src/components/RadioButton/RadioButtonAndroid.tsx @@ -5,7 +5,7 @@ import { RadioButtonContext, RadioButtonContextType } from './RadioButtonGroup'; import { handlePress, isChecked } from './utils'; import { useInternalTheme } from '../../core/theming'; import type { $RemoveChildren, ThemeProp } from '../../types'; -import { getAndroidSelectionControlColor } from '../Checkbox/utils'; +import { getSelectionControlColor } from '../Checkbox/utils'; import TouchableRipple from '../TouchableRipple/TouchableRipple'; export type Props = $RemoveChildren & { @@ -110,7 +110,7 @@ const RadioButtonAndroid = ({ value, }) === 'checked'; - const { selectionControlColor } = getAndroidSelectionControlColor({ + const { selectionControlColor } = getSelectionControlColor({ theme, disabled, checked, diff --git a/src/components/RadioButton/RadioButtonIOS.tsx b/src/components/RadioButton/RadioButtonIOS.tsx index defd7cb932..d5d8df7090 100644 --- a/src/components/RadioButton/RadioButtonIOS.tsx +++ b/src/components/RadioButton/RadioButtonIOS.tsx @@ -3,9 +3,9 @@ import { GestureResponderEvent, StyleSheet, View } from 'react-native'; import { RadioButtonContext, RadioButtonContextType } from './RadioButtonGroup'; import { handlePress, isChecked } from './utils'; +import { getSelectionControlIOSColor } from './utils'; import { useInternalTheme } from '../../core/theming'; import type { $RemoveChildren, ThemeProp } from '../../types'; -import { getSelectionControlIOSColor } from '../Checkbox/utils'; import MaterialCommunityIcon from '../MaterialCommunityIcon'; import TouchableRipple from '../TouchableRipple/TouchableRipple'; diff --git a/src/components/RadioButton/utils.ts b/src/components/RadioButton/utils.ts index 18eca2a0d7..9cd776ad8d 100644 --- a/src/components/RadioButton/utils.ts +++ b/src/components/RadioButton/utils.ts @@ -1,4 +1,9 @@ -import type { GestureResponderEvent } from 'react-native'; +import type { ColorValue, GestureResponderEvent } from 'react-native'; + +import { tokens } from '../../theme/tokens'; +import type { InternalTheme } from '../../types'; + +const { stateOpacity } = tokens.md.ref; export const handlePress = ({ onPress, @@ -35,3 +40,56 @@ export const isChecked = ({ return status; } }; + +const getIOSCheckedColor = ({ + theme, + disabled, + customColor, + error, +}: { + theme: InternalTheme; + customColor?: ColorValue; + disabled?: boolean; + error?: boolean; +}) => { + if (disabled) { + return theme.colors.primary; + } + + if (customColor) { + return customColor; + } + + if (error) { + return theme.colors.error; + } + + return theme.colors.primary; +}; + +export const getSelectionControlIOSColor = ({ + theme, + disabled, + customColor, + error, +}: { + theme: InternalTheme; + disabled?: boolean; + customColor?: ColorValue; + error?: boolean; +}) => { + const checkedColor = getIOSCheckedColor({ + theme, + disabled, + customColor, + error, + }); + const checkedColorOpacity = disabled + ? stateOpacity.disabled + : stateOpacity.enabled; + + return { + checkedColor, + checkedColorOpacity, + }; +}; diff --git a/src/components/__tests__/Checkbox/CheckboxItem.test.tsx b/src/components/__tests__/Checkbox/CheckboxItem.test.tsx index 28546d16e5..7018d01c38 100644 --- a/src/components/__tests__/Checkbox/CheckboxItem.test.tsx +++ b/src/components/__tests__/Checkbox/CheckboxItem.test.tsx @@ -1,5 +1,4 @@ import * as React from 'react'; -import { Platform } from 'react-native'; import { act, fireEvent } from '@testing-library/react-native'; @@ -14,31 +13,11 @@ it('renders unchecked', () => { expect(tree).toMatchSnapshot(); }); -it('can render the iOS checkbox on different platforms', () => { - Platform.OS = 'android'; - const tree = render( - - ).toJSON(); - - expect(tree).toMatchSnapshot(); -}); - -it('can render the Android checkbox on different platforms', () => { - Platform.OS = 'ios'; - const tree = render( - - ).toJSON(); - - expect(tree).toMatchSnapshot(); -}); - it('can render leading checkbox control', () => { - Platform.OS = 'ios'; const tree = render( ).toJSON(); diff --git a/src/components/__tests__/Checkbox/__snapshots__/Checkbox.test.tsx.snap b/src/components/__tests__/Checkbox/__snapshots__/Checkbox.test.tsx.snap index 9e6deed50f..f1a7834ac6 100644 --- a/src/components/__tests__/Checkbox/__snapshots__/Checkbox.test.tsx.snap +++ b/src/components/__tests__/Checkbox/__snapshots__/Checkbox.test.tsx.snap @@ -40,16 +40,24 @@ exports[`renders Checkbox with custom testID 1`] = ` }, { "borderRadius": 18, + "height": 36, "padding": 6, + "width": 36, }, ] } testID="custom:testID" > @@ -81,8 +89,37 @@ exports[`renders Checkbox with custom testID 1`] = ` ] } > - check + checkbox-marked + + + `; @@ -128,15 +165,23 @@ exports[`renders checked Checkbox with color 1`] = ` }, { "borderRadius": 18, + "height": 36, "padding": 6, + "width": 36, }, ] } > @@ -168,8 +213,37 @@ exports[`renders checked Checkbox with color 1`] = ` ] } > - check + checkbox-marked + + + `; @@ -214,15 +288,23 @@ exports[`renders checked Checkbox with onPress 1`] = ` }, { "borderRadius": 18, + "height": 36, "padding": 6, + "width": 36, }, ] } > @@ -254,8 +336,37 @@ exports[`renders checked Checkbox with onPress 1`] = ` ] } > - check + checkbox-marked + + + `; @@ -300,15 +411,23 @@ exports[`renders indeterminate Checkbox 1`] = ` }, { "borderRadius": 18, + "height": 36, "padding": 6, + "width": 36, }, ] } > @@ -321,7 +440,7 @@ exports[`renders indeterminate Checkbox 1`] = ` style={ [ { - "color": "rgba(103, 80, 164, 1)", + "color": "rgba(73, 69, 79, 1)", "fontSize": 24, }, [ @@ -340,8 +459,37 @@ exports[`renders indeterminate Checkbox 1`] = ` ] } > - minus + minus-box + + + `; @@ -387,15 +535,23 @@ exports[`renders indeterminate Checkbox with color 1`] = ` }, { "borderRadius": 18, + "height": 36, "padding": 6, + "width": 36, }, ] } > @@ -408,7 +564,7 @@ exports[`renders indeterminate Checkbox with color 1`] = ` style={ [ { - "color": "red", + "color": "rgba(73, 69, 79, 1)", "fontSize": 24, }, [ @@ -427,8 +583,37 @@ exports[`renders indeterminate Checkbox with color 1`] = ` ] } > - minus + minus-box + + + `; @@ -474,15 +659,23 @@ exports[`renders unchecked Checkbox with color 1`] = ` }, { "borderRadius": 18, + "height": 36, "padding": 6, + "width": 36, }, ] } > @@ -514,8 +707,37 @@ exports[`renders unchecked Checkbox with color 1`] = ` ] } > - check + checkbox-marked + + + `; @@ -560,15 +782,23 @@ exports[`renders unchecked Checkbox with onPress 1`] = ` }, { "borderRadius": 18, + "height": 36, "padding": 6, + "width": 36, }, ] } > @@ -581,7 +811,7 @@ exports[`renders unchecked Checkbox with onPress 1`] = ` style={ [ { - "color": "rgba(103, 80, 164, 1)", + "color": "rgba(73, 69, 79, 1)", "fontSize": 24, }, [ @@ -600,8 +830,37 @@ exports[`renders unchecked Checkbox with onPress 1`] = ` ] } > - check + checkbox-blank-outline + + + `; diff --git a/src/components/__tests__/Checkbox/__snapshots__/CheckboxItem.test.tsx.snap b/src/components/__tests__/Checkbox/__snapshots__/CheckboxItem.test.tsx.snap index 2615640570..8f8faef29b 100644 --- a/src/components/__tests__/Checkbox/__snapshots__/CheckboxItem.test.tsx.snap +++ b/src/components/__tests__/Checkbox/__snapshots__/CheckboxItem.test.tsx.snap @@ -56,225 +56,6 @@ exports[`can render leading checkbox control 1`] = ` ] } > - - - - check - - - - - Default with leading control - - - -`; - -exports[`can render the Android checkbox on different platforms 1`] = ` - - - - iOS Checkbox - - - -`; - -exports[`can render the iOS checkbox on different platforms 1`] = ` - - - iOS Checkbox + Default with leading control - - - - check - - - `; @@ -713,15 +351,23 @@ exports[`renders unchecked 1`] = ` }, { "borderRadius": 18, + "height": 36, "padding": 6, + "width": 36, }, ] } > @@ -734,7 +380,7 @@ exports[`renders unchecked 1`] = ` style={ [ { - "color": "rgba(103, 80, 164, 1)", + "color": "rgba(73, 69, 79, 1)", "fontSize": 24, }, [ @@ -753,8 +399,37 @@ exports[`renders unchecked 1`] = ` ] } > - check + checkbox-blank-outline + + + diff --git a/src/components/__tests__/Checkbox/utils.test.tsx b/src/components/__tests__/Checkbox/utils.test.tsx index 2aa20fd688..118fe1690f 100644 --- a/src/components/__tests__/Checkbox/utils.test.tsx +++ b/src/components/__tests__/Checkbox/utils.test.tsx @@ -1,15 +1,12 @@ import { getTheme } from '../../../core/theming'; import { tokens } from '../../../theme/tokens'; -import { - getAndroidSelectionControlColor, - getSelectionControlIOSColor, -} from '../../Checkbox/utils'; +import { getSelectionControlColor } from '../../Checkbox/utils'; const { stateOpacity } = tokens.md.ref; -describe('getAndroidSelectionControlColor - checkbox color', () => { +describe('getSelectionControlColor - checkbox color', () => { it('should return correct disabled color, for theme version 3', () => { expect( - getAndroidSelectionControlColor({ + getSelectionControlColor({ theme: getTheme(), disabled: true, checked: false, @@ -22,7 +19,7 @@ describe('getAndroidSelectionControlColor - checkbox color', () => { it('should return custom color, checked', () => { expect( - getAndroidSelectionControlColor({ + getSelectionControlColor({ theme: getTheme(), checked: true, customColor: 'purple', @@ -34,7 +31,7 @@ describe('getAndroidSelectionControlColor - checkbox color', () => { it('should return theme color, for theme version 3, checked', () => { expect( - getAndroidSelectionControlColor({ + getSelectionControlColor({ theme: getTheme(), checked: true, }) @@ -45,7 +42,7 @@ describe('getAndroidSelectionControlColor - checkbox color', () => { it('should return custom color, unchecked', () => { expect( - getAndroidSelectionControlColor({ + getSelectionControlColor({ theme: getTheme(), checked: false, customUncheckedColor: 'purple', @@ -57,7 +54,7 @@ describe('getAndroidSelectionControlColor - checkbox color', () => { it('should return theme color, for theme version 3, unchecked', () => { expect( - getAndroidSelectionControlColor({ + getSelectionControlColor({ theme: getTheme(), checked: false, }) @@ -68,7 +65,7 @@ describe('getAndroidSelectionControlColor - checkbox color', () => { it('should return theme color, unchecked, dark mode', () => { expect( - getAndroidSelectionControlColor({ + getSelectionControlColor({ theme: getTheme(true), checked: false, }) @@ -79,7 +76,7 @@ describe('getAndroidSelectionControlColor - checkbox color', () => { it('should return theme color, unchecked, light mode', () => { expect( - getAndroidSelectionControlColor({ + getSelectionControlColor({ theme: getTheme(false), checked: false, }) @@ -90,7 +87,7 @@ describe('getAndroidSelectionControlColor - checkbox color', () => { it('should return error color, checked, when error is true', () => { expect( - getAndroidSelectionControlColor({ + getSelectionControlColor({ theme: getTheme(), checked: true, error: true, @@ -102,7 +99,7 @@ describe('getAndroidSelectionControlColor - checkbox color', () => { it('should return error color, unchecked, when error is true', () => { expect( - getAndroidSelectionControlColor({ + getSelectionControlColor({ theme: getTheme(), checked: false, error: true, @@ -114,7 +111,7 @@ describe('getAndroidSelectionControlColor - checkbox color', () => { it('should return error color, checked, dark mode, when error is true', () => { expect( - getAndroidSelectionControlColor({ + getSelectionControlColor({ theme: getTheme(true), checked: true, error: true, @@ -126,7 +123,7 @@ describe('getAndroidSelectionControlColor - checkbox color', () => { it('should return disabled color when both disabled and error are true (disabled wins)', () => { expect( - getAndroidSelectionControlColor({ + getSelectionControlColor({ theme: getTheme(), disabled: true, checked: true, @@ -140,7 +137,7 @@ describe('getAndroidSelectionControlColor - checkbox color', () => { it('should return custom color when both customColor and error are true, checked (customColor wins)', () => { expect( - getAndroidSelectionControlColor({ + getSelectionControlColor({ theme: getTheme(), checked: true, customColor: 'purple', @@ -153,7 +150,7 @@ describe('getAndroidSelectionControlColor - checkbox color', () => { it('should return custom unchecked color when both customUncheckedColor and error are true, unchecked (customUncheckedColor wins)', () => { expect( - getAndroidSelectionControlColor({ + getSelectionControlColor({ theme: getTheme(), checked: false, customUncheckedColor: 'purple', @@ -164,85 +161,3 @@ describe('getAndroidSelectionControlColor - checkbox color', () => { }); }); }); - -describe('getSelectionControlIOSColor - checked color', () => { - it('should return correct disabled color, for theme version 3', () => { - expect( - getSelectionControlIOSColor({ - theme: getTheme(), - disabled: true, - }) - ).toMatchObject({ - checkedColor: getTheme().colors.primary, - checkedColorOpacity: stateOpacity.disabled, - }); - }); - - it('should return custom color, checked', () => { - expect( - getSelectionControlIOSColor({ - theme: getTheme(), - customColor: 'purple', - }) - ).toMatchObject({ - checkedColor: 'purple', - }); - }); - - it('should return theme color, for theme version 3, checked', () => { - expect( - getSelectionControlIOSColor({ - theme: getTheme(), - }) - ).toMatchObject({ - checkedColor: getTheme().colors.primary, - }); - }); - - it('should return error color when error is true', () => { - expect( - getSelectionControlIOSColor({ - theme: getTheme(), - error: true, - }) - ).toMatchObject({ - checkedColor: getTheme().colors.error, - }); - }); - - it('should return error color, dark mode, when error is true', () => { - expect( - getSelectionControlIOSColor({ - theme: getTheme(true), - error: true, - }) - ).toMatchObject({ - checkedColor: getTheme(true).colors.error, - }); - }); - - it('should return disabled color when both disabled and error are true (disabled wins)', () => { - expect( - getSelectionControlIOSColor({ - theme: getTheme(), - disabled: true, - error: true, - }) - ).toMatchObject({ - checkedColor: getTheme().colors.primary, - checkedColorOpacity: stateOpacity.disabled, - }); - }); - - it('should return custom color when both customColor and error are true (customColor wins)', () => { - expect( - getSelectionControlIOSColor({ - theme: getTheme(), - customColor: 'purple', - error: true, - }) - ).toMatchObject({ - checkedColor: 'purple', - }); - }); -}); diff --git a/src/components/__tests__/RadioButton/utils.test.tsx b/src/components/__tests__/RadioButton/utils.test.tsx new file mode 100644 index 0000000000..929d0f7a2c --- /dev/null +++ b/src/components/__tests__/RadioButton/utils.test.tsx @@ -0,0 +1,87 @@ +import { getTheme } from '../../../core/theming'; +import { tokens } from '../../../theme/tokens'; +import { getSelectionControlIOSColor } from '../../RadioButton/utils'; + +const { stateOpacity } = tokens.md.ref; + +describe('getSelectionControlIOSColor - checked color', () => { + it('should return correct disabled color, for theme version 3', () => { + expect( + getSelectionControlIOSColor({ + theme: getTheme(), + disabled: true, + }) + ).toMatchObject({ + checkedColor: getTheme().colors.primary, + checkedColorOpacity: stateOpacity.disabled, + }); + }); + + it('should return custom color, checked', () => { + expect( + getSelectionControlIOSColor({ + theme: getTheme(), + customColor: 'purple', + }) + ).toMatchObject({ + checkedColor: 'purple', + }); + }); + + it('should return theme color, for theme version 3, checked', () => { + expect( + getSelectionControlIOSColor({ + theme: getTheme(), + }) + ).toMatchObject({ + checkedColor: getTheme().colors.primary, + }); + }); + + it('should return error color when error is true', () => { + expect( + getSelectionControlIOSColor({ + theme: getTheme(), + error: true, + }) + ).toMatchObject({ + checkedColor: getTheme().colors.error, + }); + }); + + it('should return error color, dark mode, when error is true', () => { + expect( + getSelectionControlIOSColor({ + theme: getTheme(true), + error: true, + }) + ).toMatchObject({ + checkedColor: getTheme(true).colors.error, + }); + }); + + it('should return disabled color when both disabled and error are true (disabled wins)', () => { + expect( + getSelectionControlIOSColor({ + theme: getTheme(), + disabled: true, + error: true, + }) + ).toMatchObject({ + checkedColor: getTheme().colors.primary, + checkedColorOpacity: stateOpacity.disabled, + }); + }); + + it('should return custom color when both customColor and error are true (customColor wins)', () => { + expect( + getSelectionControlIOSColor({ + theme: getTheme(), + customColor: 'purple', + error: true, + }) + ).toMatchObject({ + checkedColor: 'purple', + }); + }); +}); diff --git a/src/index.tsx b/src/index.tsx index 1430e797c4..b5ecadea41 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -81,8 +81,6 @@ export type { Props as CardContentProps } from './components/Card/CardContent'; export type { Props as CardCoverProps } from './components/Card/CardCover'; export type { Props as CardTitleProps } from './components/Card/CardTitle'; export type { Props as CheckboxProps } from './components/Checkbox/Checkbox'; -export type { Props as CheckboxAndroidProps } from './components/Checkbox/CheckboxAndroid'; -export type { Props as CheckboxIOSProps } from './components/Checkbox/CheckboxIOS'; export type { Props as CheckboxItemProps } from './components/Checkbox/CheckboxItem'; export type { Props as ChipProps } from './components/Chip/Chip'; export type { Props as DataTableProps } from './components/DataTable/DataTable';