From 30a0ebff77d7ea806a5c4d1a32398d1916d02544 Mon Sep 17 00:00:00 2001 From: Batyr Kanzitdinov Date: Mon, 29 Aug 2022 22:36:08 +0200 Subject: [PATCH] `utils` added --- src/utils/designSystem.tsx | 32 ++++++++++++----------- src/utils/types.d.ts | 52 -------------------------------------- src/utils/types/api.ts | 4 +++ src/utils/types/enums.ts | 39 ++++++++++++++++++++++++++++ src/utils/types/index.d.ts | 29 +++++++++++++++++++++ 5 files changed, 89 insertions(+), 67 deletions(-) delete mode 100644 src/utils/types.d.ts create mode 100644 src/utils/types/api.ts create mode 100644 src/utils/types/enums.ts create mode 100644 src/utils/types/index.d.ts diff --git a/src/utils/designSystem.tsx b/src/utils/designSystem.tsx index dd336e7..2f0584a 100644 --- a/src/utils/designSystem.tsx +++ b/src/utils/designSystem.tsx @@ -1,27 +1,29 @@ import {Color} from 'react-native-navigation'; import {Colors, Typography} from 'react-native-ui-lib'; import {stores} from '../stores'; +import {Appearance} from './types/enums'; -const colors: DesignSystemColors = { +const colors = { primary: '#5383b8', // blue secondary: '#469c57', // green accent: '#fed330', // yellow - blackish: Colors.rgba(20, 20, 20, 1), - blackish2: Colors.rgba(50, 50, 50, 1), - whitish: Colors.rgba(250, 250, 250, 1), - whitish2: Colors.rgba(230, 230, 230, 1), + _black: Colors.rgba(20, 20, 20, 1), + _black2: Colors.rgba(50, 50, 50, 1), + _white: Colors.rgba(250, 250, 250, 1), + _white2: Colors.rgba(230, 230, 230, 1), }; -const themes: Record = { +const themes: Record = { + system: {} as any, light: { - textColor: colors.blackish, - bgColor: colors.whitish, - bg2Color: colors.whitish2, + textColor: colors._black, + bgColor: colors._white, + bg2Color: colors._white2, }, dark: { - textColor: colors.whitish, - bgColor: colors.blackish, - bg2Color: colors.blackish2, + textColor: colors._white, + bgColor: colors._black, + bg2Color: colors._black2, }, }; @@ -29,7 +31,7 @@ const themes: Record = { export const configureDesignSystem = async (): PVoid => { const {ui} = stores; - if (ui.isSystemAppearance) { + if (ui.isAppearanceSystem) { Colors.loadColors(colors); Colors.loadSchemes(themes); } else { @@ -45,7 +47,7 @@ export const configureDesignSystem = async (): PVoid => { export const getThemeColor = (c: keyof ThemeColors): Color => { const {ui} = stores; - if (ui.isSystemAppearance) { + if (ui.isAppearanceSystem) { return { dark: themes.dark[c], light: themes.light[c], @@ -58,7 +60,7 @@ export const getThemeColor = (c: keyof ThemeColors): Color => { export const getThemeStatusBarStyle = (): StatusBarStyle => { const {ui} = stores; - if (ui.isSystemAppearance) { + if (ui.isAppearanceSystem) { return undefined; } else { switch (ui.appearance) { diff --git a/src/utils/types.d.ts b/src/utils/types.d.ts deleted file mode 100644 index ffa3cff..0000000 --- a/src/utils/types.d.ts +++ /dev/null @@ -1,52 +0,0 @@ -interface IService { - init: () => PVoid; -} -type Services = Record; - -interface IStore { - hydrate?: () => PVoid; -} -type Stores = Record; - -type PVoid = Promise; -type AnyObj = Record; -type PureFunc = () => void; - -type DesignSystemColors = Record; -type AppearanceMode = 'light' | 'dark'; -type StatusBarStyle = 'light' | 'dark' | undefined; -type ThemeColors = { - textColor: string; - bgColor: string; - bg2Color: string; -}; - -type Language = 'en' | 'ru'; - -// SERVICES -type AppType = 'one_screen' | 'three_tabs'; - -// STORES -type UIAppearance = 'System' | 'Light' | 'Dark'; -type UILanguage = 'System' | 'English' | 'Russian'; - -// SCREENS -// Props -type ExampleScreenProps = { - value?: number; -}; - -// Settings -type AppearanceAction = { - name: UIAppearance; -}; - -type LanguageAction = { - name: UILanguage; -}; - -// API -// Responses -type CounterGetResponse = { - value: number; -}; diff --git a/src/utils/types/api.ts b/src/utils/types/api.ts new file mode 100644 index 0000000..e8251b7 --- /dev/null +++ b/src/utils/types/api.ts @@ -0,0 +1,4 @@ +// Responses +export type CounterGetResponse = { + value: number; +}; diff --git a/src/utils/types/enums.ts b/src/utils/types/enums.ts new file mode 100644 index 0000000..79c81df --- /dev/null +++ b/src/utils/types/enums.ts @@ -0,0 +1,39 @@ +const _languages = { + system: 'System', + en: 'EN', + ru: 'RU', +} as const; +export type Language = keyof typeof _languages; +export type LanguageUI = typeof _languages[Language]; +export const languageToUI: Record = { + system: 'System', + en: 'EN', + ru: 'RU', +}; +export const languageUIToInternal: Record = { + System: 'system', + EN: 'en', + RU: 'ru', +}; +export const languages: Language[] = ['system', 'en', 'ru']; +export const languagesUI: LanguageUI[] = ['System', 'EN', 'RU']; + +const _appearances = { + system: 'System', + light: 'Light', + dark: 'Dark', +} as const; +export type Appearance = keyof typeof _appearances; +export type AppearanceUI = typeof _appearances[Appearance]; +export const appearanceToUI: Record = { + system: 'System', + light: 'Light', + dark: 'Dark', +}; +export const appearanceUIToInternal: Record = { + System: 'system', + Light: 'light', + Dark: 'dark', +}; +export const appearances: Appearance[] = ['system', 'light', 'dark']; +export const appearancesUI: AppearanceUI[] = ['System', 'Light', 'Dark']; diff --git a/src/utils/types/index.d.ts b/src/utils/types/index.d.ts new file mode 100644 index 0000000..2e6f42d --- /dev/null +++ b/src/utils/types/index.d.ts @@ -0,0 +1,29 @@ +// `stores` layer +interface IStore { + hydrate?: () => PVoid; +} +type Stores = Record; + +type StoreDefaultKeys = 'set' | 'setMany' | 'hydrate'; +type StoreKeysOf = keyof Omit; + +// `services` layer +interface IService { + init: () => PVoid; +} +type Services = Record; + +// System +type PVoid = Promise; +type AnyObj = Record; +type PureFunc = () => void; +type PureFuncAsync = () => PVoid; +type PureFuncArg = (value?: T) => void; + +// Design system +type StatusBarStyle = 'light' | 'dark' | undefined; +type ThemeColors = { + textColor: string; + bgColor: string; + bg2Color: string; +};