From 46c112edfdcb40681a8997ec4f47b413a08fdd14 Mon Sep 17 00:00:00 2001 From: dan Date: Fri, 5 Apr 2024 15:09:35 +0100 Subject: Enforce that text is wrapped in , remaining cases (#3421) * Toggle.Button -> Toggle.ButtonWithText * Simplify Prompt.Cancel/Action * Move lines down for better diff * Remove ButtonWithText * Simplify types * Enforce Button/ButtonText nesting * Add suggested wrapper in linter error * Check ancestry too * Also check literals * Rm ts-ignore --- src/components/Button.tsx | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) (limited to 'src/components/Button.tsx') diff --git a/src/components/Button.tsx b/src/components/Button.tsx index 12b3fe4cb..33d777971 100644 --- a/src/components/Button.tsx +++ b/src/components/Button.tsx @@ -12,7 +12,6 @@ import { ViewStyle, } from 'react-native' import {LinearGradient} from 'expo-linear-gradient' -import {Trans} from '@lingui/macro' import {android, atoms as a, flatten, tokens, useTheme} from '#/alf' import {Props as SVGIconProps} from '#/components/icons/common' @@ -59,6 +58,10 @@ export type ButtonState = { export type ButtonContext = VariantProps & ButtonState +type NonTextElements = + | React.ReactElement + | Iterable + export type ButtonProps = Pick< PressableProps, 'disabled' | 'onPress' | 'testID' @@ -68,11 +71,9 @@ export type ButtonProps = Pick< testID?: string label: string style?: StyleProp - children: - | React.ReactNode - | string - | ((context: ButtonContext) => React.ReactNode | string) + children: NonTextElements | ((context: ButtonContext) => NonTextElements) } + export type ButtonTextProps = TextProps & VariantProps & {disabled?: boolean} const Context = React.createContext({ @@ -404,15 +405,7 @@ export function Button({ )} - {/* @ts-ignore */} - {typeof children === 'string' || children?.type === Trans ? ( - /* @ts-ignore */ - {children} - ) : typeof children === 'function' ? ( - children(context) - ) : ( - children - )} + {typeof children === 'function' ? children(context) : children} ) -- cgit 1.4.1