Skip to content

Commit

Permalink
utils added
Browse files Browse the repository at this point in the history
  • Loading branch information
kanzitelli committed Aug 29, 2022
1 parent fc9dcb9 commit 30a0ebf
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 67 deletions.
32 changes: 17 additions & 15 deletions src/utils/designSystem.tsx
Original file line number Diff line number Diff line change
@@ -1,35 +1,37 @@
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<AppearanceMode, ThemeColors> = {
const themes: Record<Appearance, ThemeColors> = {
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,
},
};

// for more information - https://wix.github.io/react-native-ui-lib/foundation/style
export const configureDesignSystem = async (): PVoid => {
const {ui} = stores;

if (ui.isSystemAppearance) {
if (ui.isAppearanceSystem) {
Colors.loadColors(colors);
Colors.loadSchemes(themes);
} else {
Expand All @@ -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],
Expand All @@ -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) {
Expand Down
52 changes: 0 additions & 52 deletions src/utils/types.d.ts

This file was deleted.

4 changes: 4 additions & 0 deletions src/utils/types/api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// Responses
export type CounterGetResponse = {
value: number;
};
39 changes: 39 additions & 0 deletions src/utils/types/enums.ts
Original file line number Diff line number Diff line change
@@ -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<Language, LanguageUI> = {
system: 'System',
en: 'EN',
ru: 'RU',
};
export const languageUIToInternal: Record<LanguageUI, Language> = {
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<Appearance, AppearanceUI> = {
system: 'System',
light: 'Light',
dark: 'Dark',
};
export const appearanceUIToInternal: Record<AppearanceUI, Appearance> = {
System: 'system',
Light: 'light',
Dark: 'dark',
};
export const appearances: Appearance[] = ['system', 'light', 'dark'];
export const appearancesUI: AppearanceUI[] = ['System', 'Light', 'Dark'];
29 changes: 29 additions & 0 deletions src/utils/types/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// `stores` layer
interface IStore {
hydrate?: () => PVoid;
}
type Stores = Record<string, IStore>;

type StoreDefaultKeys = 'set' | 'setMany' | 'hydrate';
type StoreKeysOf<S> = keyof Omit<S, StoreDefaultKeys>;

// `services` layer
interface IService {
init: () => PVoid;
}
type Services = Record<string, IService>;

// System
type PVoid = Promise<void>;
type AnyObj = Record<string, unknown>;
type PureFunc = () => void;
type PureFuncAsync = () => PVoid;
type PureFuncArg<T> = (value?: T) => void;

// Design system
type StatusBarStyle = 'light' | 'dark' | undefined;
type ThemeColors = {
textColor: string;
bgColor: string;
bg2Color: string;
};

0 comments on commit 30a0ebf

Please sign in to comment.