diff --git a/template/src/components/kit/card/Card.tsx b/template/src/components/kit/card/Card.tsx deleted file mode 100644 index 15fcf20..0000000 --- a/template/src/components/kit/card/Card.tsx +++ /dev/null @@ -1,50 +0,0 @@ -import { ForwardedRef, createRef, forwardRef } from 'react'; -import { StyleProp, View, ViewStyle } from 'react-native'; -import { Flex, FlexProps } from '../flex'; -import { Padding } from '../shared/types'; -import { Squishable } from '../squishable'; -import { - ColorSchemeValue, - useColorSchemeValue, -} from '~/hooks/use-color-scheme-value'; - -export type CardProps = FlexProps & { - outlined?: boolean; - padding?: Padding; - color?: ColorSchemeValue; - style?: StyleProp; - radius?: number; -}; - -export type CardComponent = ( - props: CardProps -) => React.ReactElement | null; - -export const Card = forwardRef( - ( - { outlined = false, color, style, radius = 32, ...props }: CardProps, - ref?: ForwardedRef - ) => { - const backgroundColor = useColorSchemeValue(color ?? ['#fff', '#15171E']); - const borderColor = useColorSchemeValue(color ?? ['#E8E3E0', '#434A60']); - - return ( - - ); - } -); - -const ref = createRef(); - console.log('derp')} />; diff --git a/template/src/components/kit/card/index.ts b/template/src/components/kit/card/index.ts deleted file mode 100644 index ca0b060..0000000 --- a/template/src/components/kit/card/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './Card'; diff --git a/template/src/components/kit/flex/Flex.tsx b/template/src/components/kit/flex/Flex.tsx index 6488d2a..bc008a4 100644 --- a/template/src/components/kit/flex/Flex.tsx +++ b/template/src/components/kit/flex/Flex.tsx @@ -1,4 +1,3 @@ -import { ForwardedRef, forwardRef } from 'react'; import { FlexStyle, StyleProp, @@ -6,58 +5,89 @@ import { View, ViewStyle, } from 'react-native'; -import { Padding, PolymorphicComponentProps } from '../shared/types'; -import { getPaddingStyle } from '../shared/utils'; -import { GapContext, useGap } from './GapContext'; +import { + ComponentWithViewStyle, + Padding, + PolymorphicComponentProps, + Radius, +} from '../shared/types'; +import { getPaddingStyle, getRadiusStyle } from '../shared/utils'; import { FlexGap } from './types'; import { getFlexDirection, getGapStyle } from './utils'; -export type FlexProps = PolymorphicComponentProps< - C, - { - row?: boolean; - reverse?: boolean; - gap?: FlexGap; - padding?: Padding; - align?: FlexStyle['alignItems']; - alignSelf?: FlexStyle['alignSelf']; - justify?: FlexStyle['justifyContent']; - grow?: number | boolean; - shrink?: number | boolean; - basis?: FlexStyle['flexBasis']; - wrap?: boolean; - absolute?: boolean; - zIndex?: ViewStyle['zIndex']; - top?: ViewStyle['top']; - left?: ViewStyle['left']; - bottom?: ViewStyle['bottom']; - right?: ViewStyle['right']; - width?: ViewStyle['width']; - height?: ViewStyle['height']; - fill?: boolean; - } ->; - -export type FlexComponent = ( - props: FlexProps -) => React.ReactElement | null; +export type FlexProps = + PolymorphicComponentProps< + C, + { + row?: boolean; + reverse?: boolean; + gap?: FlexGap; + padding?: Padding; + align?: FlexStyle['alignItems']; + alignSelf?: FlexStyle['alignSelf']; + justify?: FlexStyle['justifyContent']; + grow?: number | boolean; + shrink?: number | boolean; + basis?: FlexStyle['flexBasis']; + wrap?: boolean; + absolute?: boolean; + zIndex?: number; + top?: FlexStyle['top']; + left?: FlexStyle['left']; + bottom?: FlexStyle['bottom']; + right?: FlexStyle['right']; + width?: FlexStyle['width']; + height?: FlexStyle['height']; + fill?: boolean; + radius?: Radius; + background?: ViewStyle['backgroundColor']; + style?: StyleProp; + } + >; -export const Flex = forwardRef( - ( +export const Flex = ({ + as, + row = false, + reverse = false, + gap, + padding, + align = 'stretch', + alignSelf = 'auto', + justify = 'flex-start', + grow = 0, + shrink = 0, + basis = 'auto', + wrap = false, + absolute = false, + zIndex, + top, + left, + bottom, + right, + width, + height, + fill = false, + radius, + background, + style, + forwardedRef, + ...props +}: FlexProps) => { + const Comp = as || View; + const finalStyle: StyleProp = [ + getPaddingStyle(padding), + getGapStyle(gap), + getRadiusStyle(radius), { - as, - row = false, - reverse = false, - gap, - padding, - align = 'stretch', - alignSelf = 'auto', - justify = 'flex-start', - grow = 0, - shrink = 0, - basis = 'auto', - wrap = false, - absolute = false, + flexGrow: Number(grow), + flexShrink: Number(shrink), + flexBasis: basis, + alignItems: align, + alignSelf, + justifyContent: justify, + flexDirection: getFlexDirection(row, reverse), + flexWrap: wrap ? 'wrap' : 'nowrap', + position: absolute ? 'absolute' : 'relative', zIndex, top, left, @@ -65,44 +95,11 @@ export const Flex = forwardRef( right, width, height, - fill = false, - style, - ...props - }: FlexProps, - ref?: ForwardedRef - ) => { - const Comp = as || View; - const inheritedGap = useGap(); - const finalGap = typeof gap === 'number' ? gap : inheritedGap; - const finalStyle: StyleProp = [ - getPaddingStyle(padding), - getGapStyle(finalGap), - { - flexGrow: Number(grow), - flexShrink: Number(shrink), - flexBasis: basis, - alignItems: align, - alignSelf, - justifyContent: justify, - flexDirection: getFlexDirection(row, reverse), - flexWrap: wrap ? 'wrap' : 'nowrap', - position: absolute ? 'absolute' : 'relative', - zIndex, - top, - left, - bottom, - right, - width, - height, - }, - fill ? StyleSheet.absoluteFill : null, - style, - ]; + backgroundColor: background, + }, + fill ? StyleSheet.absoluteFill : null, + style, + ]; - return ( - - - - ); - } -); + return ; +}; diff --git a/template/src/components/kit/flex/GapContext.tsx b/template/src/components/kit/flex/GapContext.tsx deleted file mode 100644 index 419478f..0000000 --- a/template/src/components/kit/flex/GapContext.tsx +++ /dev/null @@ -1,8 +0,0 @@ -import { createContext, useContext } from 'react'; -import { FlexGap } from './types'; - -export const GapContext = createContext(0); - -export function useGap() { - return useContext(GapContext); -} diff --git a/template/src/components/kit/flex/index.ts b/template/src/components/kit/flex/index.ts index 04e5a76..f1c9f0b 100644 --- a/template/src/components/kit/flex/index.ts +++ b/template/src/components/kit/flex/index.ts @@ -1,4 +1,3 @@ export * from './Flex'; -export * from './GapContext'; export * from './types'; export * from './utils'; diff --git a/template/src/components/kit/index.ts b/template/src/components/kit/index.ts index 7f966ca..bde1b6b 100644 --- a/template/src/components/kit/index.ts +++ b/template/src/components/kit/index.ts @@ -1,7 +1,6 @@ export * from './activity-indicator'; export * from './bottom-sheet'; export * from './button'; -export * from './card'; export * from './date-time'; export * from './flex'; export * from './icon'; diff --git a/template/src/components/kit/shared/types.ts b/template/src/components/kit/shared/types.ts index 556f97f..e2cf0df 100644 --- a/template/src/components/kit/shared/types.ts +++ b/template/src/components/kit/shared/types.ts @@ -1,28 +1,47 @@ +import { StyleProp, ViewStyle } from 'react-native'; + export type Padding = | number | [vertical: number, horizontal: number] | [top: number, horizontal: number, bottom: number] | [top: number, right: number, bottom: number, left: number]; +export type Radius = + | number + | [topLeftAndBottomRight: number, topRightAndBottomLeft: number] + | [topLeft: number, topRightAndBottomLeft: number, bottomRight: number] + | [ + topLeft: number, + topRight: number, + bottomRight: number, + bottomLeft: number + ]; + export type Size = number | [number, number]; export type AsProp = { as?: C; }; +export type ForwardedRefProp = { + forwardedRef?: PolymorphicRef; +}; + export type PropsToOmit = keyof (AsProp & P); export type PolymorphicComponentProps< - C extends React.ElementType, - Props = {} + C extends ComponentWithViewStyle, + Props extends { style?: Style } = {}, + Style extends StyleProp = StyleProp > = Props & AsProp & + ForwardedRefProp & Omit, PropsToOmit>; -export type PolymorphicComponentPropsWithRef< - C extends React.ElementType, - Props = {} -> = PolymorphicComponentProps & { ref?: PolymorphicRef }; +export type ComponentWithViewStyle< + Props extends { style?: Style } = {}, + Style extends StyleProp = StyleProp +> = React.JSXElementConstructor; export type PolymorphicRef = React.ComponentPropsWithRef['ref']; diff --git a/template/src/components/kit/shared/utils.ts b/template/src/components/kit/shared/utils.ts index 35d3150..0ca7e23 100644 --- a/template/src/components/kit/shared/utils.ts +++ b/template/src/components/kit/shared/utils.ts @@ -1,5 +1,5 @@ import { ViewStyle } from 'react-native'; -import { Padding, Size } from './types'; +import { Padding, Radius, Size } from './types'; export function getPaddingStyle(padding?: Padding): ViewStyle | null { if (padding === undefined) { @@ -24,6 +24,44 @@ export function getPaddingStyle(padding?: Padding): ViewStyle | null { return { paddingTop, paddingRight, paddingBottom, paddingLeft }; } +export function getRadiusStyle(radius?: Radius): ViewStyle | null { + if (radius === undefined) { + return null; + } + + if (typeof radius === 'number') { + return { borderRadius: radius }; + } + + if (radius.length === 2) { + const [topLeftAndBottomRight, topRightAndBottomLeft] = radius; + return { + borderTopLeftRadius: topLeftAndBottomRight, + borderTopRightRadius: topRightAndBottomLeft, + borderBottomRightRadius: topLeftAndBottomRight, + borderBottomLeftRadius: topRightAndBottomLeft, + }; + } + + if (radius.length === 3) { + const [topLeft, topRightAndBottomLeft, bottomRight] = radius; + return { + borderTopLeftRadius: topLeft, + borderTopRightRadius: topRightAndBottomLeft, + borderBottomRightRadius: bottomRight, + borderBottomLeftRadius: topRightAndBottomLeft, + }; + } + + const [topLeft, topRight, bottomRight, bottomLeft] = radius; + return { + borderTopLeftRadius: topLeft, + borderTopRightRadius: topRight, + borderBottomRightRadius: bottomRight, + borderBottomLeftRadius: bottomLeft, + }; +} + export function getSizeStyle( size?: Size ): Pick | null { diff --git a/template/src/screens/SecretConfig.tsx b/template/src/screens/SecretConfig.tsx index 8e923fd..c39c5de 100644 --- a/template/src/screens/SecretConfig.tsx +++ b/template/src/screens/SecretConfig.tsx @@ -67,7 +67,7 @@ export function SecretConfigScreen({ navigation }: SecretConfigScreenProps) { return ( @@ -114,7 +114,7 @@ export function SecretConfigScreen({ navigation }: SecretConfigScreenProps) { row gap={8} padding={[15, 20, insets.bottom + 15]} - backgroundColor="#eee" + background="#eee" style={styles.footer} >