diff options
Diffstat (limited to 'src/components')
-rw-r--r-- | src/components/Prompt.tsx | 20 | ||||
-rw-r--r-- | src/components/forms/ToggleButton.tsx | 124 | ||||
-rw-r--r-- | src/components/moderation/LabelPreference.tsx | 6 |
3 files changed, 78 insertions, 72 deletions
diff --git a/src/components/Prompt.tsx b/src/components/Prompt.tsx index 000d2a3cd..3344b051b 100644 --- a/src/components/Prompt.tsx +++ b/src/components/Prompt.tsx @@ -91,15 +91,13 @@ export function Actions({children}: React.PropsWithChildren<{}>) { } export function Cancel({ - children, cta, -}: React.PropsWithChildren<{ +}: { /** - * Optional i18n string, used in lieu of `children` for simple buttons. If - * undefined (and `children` is undefined), it will default to "Cancel". + * Optional i18n string. If undefined, it will default to "Cancel". */ cta?: string -}>) { +}) { const {_} = useLingui() const {gtMobile} = useBreakpoints() const {close} = Dialog.useDialogContext() @@ -114,27 +112,25 @@ export function Cancel({ size={gtMobile ? 'small' : 'medium'} label={cta || _(msg`Cancel`)} onPress={onPress}> - {children ? children : <ButtonText>{cta || _(msg`Cancel`)}</ButtonText>} + <ButtonText>{cta || _(msg`Cancel`)}</ButtonText> </Button> ) } export function Action({ - children, onPress, color = 'primary', cta, testID, -}: React.PropsWithChildren<{ +}: { onPress: () => void color?: ButtonColor /** - * Optional i18n string, used in lieu of `children` for simple buttons. If - * undefined (and `children` is undefined), it will default to "Confirm". + * Optional i18n string. If undefined, it will default to "Confirm". */ cta?: string testID?: string -}>) { +}) { const {_} = useLingui() const {gtMobile} = useBreakpoints() const {close} = Dialog.useDialogContext() @@ -151,7 +147,7 @@ export function Action({ label={cta || _(msg`Confirm`)} onPress={handleOnPress} testID={testID}> - {children ? children : <ButtonText>{cta || _(msg`Confirm`)}</ButtonText>} + <ButtonText>{cta || _(msg`Confirm`)}</ButtonText> </Button> ) } diff --git a/src/components/forms/ToggleButton.tsx b/src/components/forms/ToggleButton.tsx index 9cdaaaa9d..752842638 100644 --- a/src/components/forms/ToggleButton.tsx +++ b/src/components/forms/ToggleButton.tsx @@ -1,16 +1,15 @@ import React from 'react' -import {View, AccessibilityProps, TextStyle, ViewStyle} from 'react-native' - -import {atoms as a, useTheme, native} from '#/alf' -import {Text} from '#/components/Typography' +import {AccessibilityProps, TextStyle, View, ViewStyle} from 'react-native' +import {atoms as a, native, useTheme} from '#/alf' import * as Toggle from '#/components/forms/Toggle' +import {Text} from '#/components/Typography' -export type ItemProps = Omit<Toggle.ItemProps, 'style' | 'role' | 'children'> & - AccessibilityProps & - React.PropsWithChildren<{ +type ItemProps = Omit<Toggle.ItemProps, 'style' | 'role' | 'children'> & + AccessibilityProps & { + children: React.ReactElement testID?: string - }> + } export type GroupProps = Omit<Toggle.GroupProps, 'style' | 'type'> & { multiple?: boolean @@ -47,49 +46,42 @@ function ButtonInner({children}: React.PropsWithChildren<{}>) { const t = useTheme() const state = Toggle.useItemContext() - const {baseStyles, hoverStyles, activeStyles, textStyles} = - React.useMemo(() => { - const base: ViewStyle[] = [] - const hover: ViewStyle[] = [] - const active: ViewStyle[] = [] - const text: TextStyle[] = [] + const {baseStyles, hoverStyles, activeStyles} = React.useMemo(() => { + const base: ViewStyle[] = [] + const hover: ViewStyle[] = [] + const active: ViewStyle[] = [] - hover.push( - t.name === 'light' ? t.atoms.bg_contrast_100 : t.atoms.bg_contrast_25, - ) + hover.push( + t.name === 'light' ? t.atoms.bg_contrast_100 : t.atoms.bg_contrast_25, + ) - if (state.selected) { - active.push({ - backgroundColor: t.palette.contrast_800, - }) - text.push(t.atoms.text_inverted) - hover.push({ - backgroundColor: t.palette.contrast_800, - }) - - if (state.disabled) { - active.push({ - backgroundColor: t.palette.contrast_500, - }) - } - } + if (state.selected) { + active.push({ + backgroundColor: t.palette.contrast_800, + }) + hover.push({ + backgroundColor: t.palette.contrast_800, + }) if (state.disabled) { - base.push({ - backgroundColor: t.palette.contrast_100, - }) - text.push({ - opacity: 0.5, + active.push({ + backgroundColor: t.palette.contrast_500, }) } + } - return { - baseStyles: base, - hoverStyles: hover, - activeStyles: active, - textStyles: text, - } - }, [t, state]) + if (state.disabled) { + base.push({ + backgroundColor: t.palette.contrast_100, + }) + } + + return { + baseStyles: base, + hoverStyles: hover, + activeStyles: active, + } + }, [t, state]) return ( <View @@ -110,19 +102,37 @@ function ButtonInner({children}: React.PropsWithChildren<{}>) { activeStyles, (state.hovered || state.pressed) && hoverStyles, ]}> - {typeof children === 'string' ? ( - <Text - style={[ - a.text_center, - a.font_bold, - t.atoms.text_contrast_medium, - textStyles, - ]}> - {children} - </Text> - ) : ( - children - )} + {children} </View> ) } + +export function ButtonText({children}: {children: React.ReactNode}) { + const t = useTheme() + const state = Toggle.useItemContext() + + const textStyles = React.useMemo(() => { + const text: TextStyle[] = [] + if (state.selected) { + text.push(t.atoms.text_inverted) + } + if (state.disabled) { + text.push({ + opacity: 0.5, + }) + } + return text + }, [t, state]) + + return ( + <Text + style={[ + a.text_center, + a.font_bold, + t.atoms.text_contrast_medium, + textStyles, + ]}> + {children} + </Text> + ) +} diff --git a/src/components/moderation/LabelPreference.tsx b/src/components/moderation/LabelPreference.tsx index 990e73622..619164303 100644 --- a/src/components/moderation/LabelPreference.tsx +++ b/src/components/moderation/LabelPreference.tsx @@ -84,17 +84,17 @@ export function Buttons({ onChange={onChange}> {ignoreLabel && ( <ToggleButton.Button name="ignore" label={ignoreLabel}> - {ignoreLabel} + <ToggleButton.ButtonText>{ignoreLabel}</ToggleButton.ButtonText> </ToggleButton.Button> )} {warnLabel && ( <ToggleButton.Button name="warn" label={warnLabel}> - {warnLabel} + <ToggleButton.ButtonText>{warnLabel}</ToggleButton.ButtonText> </ToggleButton.Button> )} {hideLabel && ( <ToggleButton.Button name="hide" label={hideLabel}> - {hideLabel} + <ToggleButton.ButtonText>{hideLabel}</ToggleButton.ButtonText> </ToggleButton.Button> )} </ToggleButton.Group> |