|
| 1 | +import type { ReactNode } from 'react'; |
| 2 | +import type { |
| 3 | + ViewStyle, |
| 4 | + TextStyle, |
| 5 | + ViewProps, |
| 6 | + TextProps, |
| 7 | + TextInputProps, |
| 8 | + PressableProps, |
| 9 | +} from 'react-native'; |
| 10 | +import type themeType from './theme'; |
| 11 | + |
| 12 | +export type spacingType<T extends themeType> = T['spacing']; |
| 13 | +export type radiusType<T extends themeType> = keyof T['borderRadius']; |
| 14 | +export type colorType<T extends themeType> = keyof T['colors']; |
| 15 | +export type zIndicesType<T extends themeType> = keyof T['zIndices']; |
| 16 | +export type fontSizesType<T extends themeType> = keyof T['fontSizes']; |
| 17 | +export type fontFamilyType<T extends themeType> = keyof T['fonts']; |
| 18 | +export type lineHeightType<T extends themeType> = keyof T['lineHeights']; |
| 19 | +export type fontWeightType<T extends themeType> = keyof T['fontWeights']; |
| 20 | +export type fontLetterSpacingType< |
| 21 | + T extends themeType |
| 22 | +> = keyof T['letterSpacings']; |
| 23 | +export type iconSizesType<T extends themeType> = keyof T['iconSizes']; |
| 24 | +export type shadowType<T extends themeType> = keyof T['shadows']; |
| 25 | + |
| 26 | +export type borderRadiusType<T extends themeType> = { |
| 27 | + borderRadius?: radiusType<T>; |
| 28 | + borderBottomEndRadius?: radiusType<T>; |
| 29 | + borderBottomLeftRadius?: radiusType<T>; |
| 30 | + borderBottomRightRadius?: radiusType<T>; |
| 31 | + borderBottomStartRadius?: radiusType<T>; |
| 32 | + borderTopEndRadius?: radiusType<T>; |
| 33 | + borderTopLeftRadius?: radiusType<T>; |
| 34 | + borderTopRightRadius?: radiusType<T>; |
| 35 | + borderTopStartRadius?: radiusType<T>; |
| 36 | +}; |
| 37 | + |
| 38 | +export type borderRadiusPropsType<T extends themeType> = keyof borderRadiusType< |
| 39 | + T |
| 40 | +>; |
| 41 | + |
| 42 | +export type colorValueType<T extends themeType> = { |
| 43 | + backgroundColor?: colorType<T>; |
| 44 | + color?: colorType<T>; |
| 45 | + borderColor?: colorType<T>; |
| 46 | + borderRightColor?: colorType<T>; |
| 47 | + borderLeftColor?: colorType<T>; |
| 48 | + borderTopColor?: colorType<T>; |
| 49 | + borderBottomColor?: colorType<T>; |
| 50 | +}; |
| 51 | + |
| 52 | +export type colorValuePropsType<T extends themeType> = keyof colorValueType<T>; |
| 53 | + |
| 54 | +export type spacingValueType<T extends themeType> = { |
| 55 | + margin?: spacingType<T> | number; |
| 56 | + marginBottom?: spacingType<T> | number; |
| 57 | + marginEnd?: spacingType<T> | number; |
| 58 | + marginHorizontal?: spacingType<T> | number; |
| 59 | + marginVertical?: spacingType<T> | number; |
| 60 | + marginLeft?: spacingType<T> | number; |
| 61 | + marginRight?: spacingType<T> | number; |
| 62 | + marginStart?: spacingType<T> | number; |
| 63 | + marginTop?: spacingType<T> | number; |
| 64 | + padding?: spacingType<T> | number; |
| 65 | + paddingBottom?: spacingType<T> | number; |
| 66 | + paddingEnd?: spacingType<T> | number; |
| 67 | + paddingHorizontal?: spacingType<T> | number; |
| 68 | + paddingVertical?: spacingType<T> | number; |
| 69 | + paddingLeft?: spacingType<T> | number; |
| 70 | + paddingRight?: spacingType<T> | number; |
| 71 | + paddingStart?: spacingType<T> | number; |
| 72 | + paddingTop?: spacingType<T> | number; |
| 73 | +}; |
| 74 | + |
| 75 | +export type spacingValuePropsType<T extends themeType> = keyof spacingValueType< |
| 76 | + T |
| 77 | +>; |
| 78 | + |
| 79 | +export type zIndexValueType<T extends themeType> = { |
| 80 | + zIndex?: zIndicesType<T>; |
| 81 | +}; |
| 82 | + |
| 83 | +export type zIndexPropsType<T extends themeType> = keyof zIndexValueType<T>; |
| 84 | + |
| 85 | +export type fontStyleValueType<T extends themeType> = { |
| 86 | + fontSize?: fontSizesType<T>; |
| 87 | + fontFamily?: fontFamilyType<T>; |
| 88 | + lineHeight?: lineHeightType<T>; |
| 89 | + letterSpacing?: fontLetterSpacingType<T>; |
| 90 | + fontWeight?: fontWeightType<T>; |
| 91 | +}; |
| 92 | + |
| 93 | +export type fontStyleValuePropsType< |
| 94 | + T extends themeType |
| 95 | +> = keyof fontStyleValueType<T>; |
| 96 | + |
| 97 | +export type shadowStyleKeys = |
| 98 | + | 'elevation' |
| 99 | + | 'shadowColor' |
| 100 | + | 'shadowOffset' |
| 101 | + | 'shadowOpacity' |
| 102 | + | 'shadowRadius'; |
| 103 | + |
| 104 | +export type omittedViewTypes<T extends themeType> = |
| 105 | + | borderRadiusPropsType<T> |
| 106 | + | colorValuePropsType<T> |
| 107 | + | spacingValuePropsType<T> |
| 108 | + | zIndexPropsType<T> |
| 109 | + | shadowStyleKeys; |
| 110 | + |
| 111 | +export type shadowValueType<T extends themeType> = { |
| 112 | + shadow?: shadowType<T>; |
| 113 | +}; |
| 114 | + |
| 115 | +export type nonThemableViewStyles<T extends themeType> = Omit< |
| 116 | + ViewStyle, |
| 117 | + omittedViewTypes<T> |
| 118 | +>; |
| 119 | + |
| 120 | +export type omittedTextTypes<T extends themeType> = |
| 121 | + | fontStyleValuePropsType<T> |
| 122 | + | omittedViewTypes<T>; |
| 123 | + |
| 124 | +export type nonThemableTextStyles<T extends themeType> = Omit< |
| 125 | + TextStyle, |
| 126 | + omittedTextTypes<T> |
| 127 | +>; |
| 128 | + |
| 129 | +export interface CommonThemableTypes<T extends themeType> |
| 130 | + extends borderRadiusType<T>, |
| 131 | + colorValueType<T>, |
| 132 | + zIndexValueType<T>, |
| 133 | + spacingValueType<T>, |
| 134 | + shadowValueType<T> {} |
| 135 | + |
| 136 | +export interface ThemableViewStyle<T extends themeType> |
| 137 | + extends nonThemableViewStyles<T>, |
| 138 | + CommonThemableTypes<T> { |
| 139 | + children?: ReactNode; |
| 140 | +} |
| 141 | + |
| 142 | +export interface ThemableTextStyle<T extends themeType> |
| 143 | + extends nonThemableTextStyles<T>, |
| 144 | + CommonThemableTypes<T>, |
| 145 | + fontStyleValueType<T> { |
| 146 | + children?: ReactNode; |
| 147 | +} |
| 148 | + |
| 149 | +export interface ThemeableTextInputStyle<T extends themeType> |
| 150 | + extends ThemableTextStyle<T> { |
| 151 | + placeholderTextColor?: colorType<T>; |
| 152 | +} |
| 153 | + |
| 154 | +export interface BoxProps<T extends themeType> extends ThemableViewStyle<T> { |
| 155 | + view?: ViewProps; |
| 156 | +} |
| 157 | + |
| 158 | +export interface RowProps<T extends themeType> extends ThemableViewStyle<T> { |
| 159 | + spacing?: spacingType<T>; |
| 160 | + view?: ViewProps; |
| 161 | +} |
| 162 | + |
| 163 | +export interface TextBlockProps<T extends themeType> |
| 164 | + extends ThemableTextStyle<T> { |
| 165 | + text?: TextProps; |
| 166 | +} |
| 167 | + |
| 168 | +export type ThemedInputProps = Omit< |
| 169 | + TextInputProps, |
| 170 | + 'placeholderTextColor' | 'underlineColorAndroid' |
| 171 | +>; |
| 172 | + |
| 173 | +export interface InputProps<T extends themeType> |
| 174 | + extends ThemeableTextInputStyle<T> { |
| 175 | + textInput?: ThemedInputProps; |
| 176 | + underlineColorAndroid?: colorType<T>; |
| 177 | +} |
| 178 | + |
| 179 | +export type NonThemablePressableProps = Omit< |
| 180 | + PressableProps, |
| 181 | + 'style' | 'children' |
| 182 | +>; |
| 183 | + |
| 184 | +export interface TouchableProps<T extends themeType> |
| 185 | + extends ThemableViewStyle<T> { |
| 186 | + press?: NonThemablePressableProps; |
| 187 | + inactiveStyle?: ThemableViewStyle<T>; |
| 188 | + pressedStyle?: ThemableViewStyle<T>; |
| 189 | + pressedChildren?: ReactNode; |
| 190 | + inactiveChildren?: ReactNode; |
| 191 | +} |
0 commit comments