Skip to content

Commit

Permalink
fix: loads of changes
Browse files Browse the repository at this point in the history
  • Loading branch information
The-Code-Monkey committed Jan 5, 2023
1 parent c07eea9 commit a8bcd71
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 36 deletions.
12 changes: 6 additions & 6 deletions packages/components/src/utils/theme-provider/create-theme.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import deepMerge from 'deepmerge';

import { ThemeModeEnum } from './enum';
import { ITheme } from './types';
import {ITheme} from "../../theme/utils";
import {ThemeModeEnum} from "../../theme/enum";

const arrayMerge = (_destination: unknown[], source: unknown[]) => source;

const getActiveMode = <V extends object>(
theme?: ITheme<V>,
parent?: ITheme<V>,
mode?: ThemeModeEnum
): ThemeModeEnum => {
mode?: string
): string => {
if (mode) return mode;
if (theme?.colors?.mode) return theme.colors.mode;
if (parent?.colors?.mode) return parent.colors.mode;
Expand All @@ -19,7 +19,7 @@ const getActiveMode = <V extends object>(

const applyMode = <V extends object>(
theme?: ITheme<V>,
mode?: ThemeModeEnum
mode?: string
): ITheme<V> => {
if (theme?.colors?.modes) {
const colors = { ...theme.colors };
Expand Down Expand Up @@ -56,7 +56,7 @@ const applyMode = <V extends object>(
};

const createTheme =
<V extends object>(theme?: ITheme<V>, mode?: ThemeModeEnum) =>
<V extends object>(theme?: ITheme<V>, mode?: string) =>
(parent): ITheme<V> => {
const activeMode = getActiveMode<V>(theme, parent, mode);
const themeWithAppliedMode = applyMode<V>(theme, activeMode);
Expand Down
8 changes: 0 additions & 8 deletions packages/components/src/utils/theme-provider/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1 @@
export { ThemeModeEnum } from './enum';
export { ThemeProvider } from './theme-provider';
export {
ITheme,
IntentsType,
ColorType,
IThemeColorsType,
ModeThemeType,
} from './types';
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { ReactNode } from 'react';
import { ThemeProvider as StyledThemeProvider } from 'styled-components';

import createTheme from './create-theme';
import { ThemeModeEnum } from './enum';
import { ITheme } from './types';
import {ThemeModeEnum} from "../../theme/enum";
import {ITheme} from "../../theme/utils";

interface Props<V> {
children: ReactNode;
Expand Down
2 changes: 1 addition & 1 deletion packages/theme/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"copy:theme": "cp -r ./src/theme ./dist/esm",
"copy:orchard": "cp ./orchard.theme.config.json ./dist/esm",
"copy:ts": "cp -r ./ts ./dist/esm",
"lint": "tcm lint src",
"lint": "tcm lint src ts",
"test": "yarn generate && yarn generate -b partial",
"prepare": "yarn build",
"size": "size-limit",
Expand Down
4 changes: 2 additions & 2 deletions packages/theme/ts/colors.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { IThemeColorsType, ModeThemeType, ThemeModeEnum } from '../utils';

import common from './dist/core';
import darkMode from './dist/dark-mode';
import intents from './dist/intents';
import lightMode from './dist/light-mode';
import neutrals from './dist/neutrals';
import { ThemeModeEnum } from './enum';
import { IThemeColorsType, ModeThemeType } from './utils';

const dark: ModeThemeType = {
mode: ThemeModeEnum.DARK,
Expand Down
File renamed without changes.
3 changes: 1 addition & 2 deletions packages/theme/ts/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { ITheme, IThemeColorsType, ModeThemeType } from '../utils';

import colors from './colors';
import variants from './defaultVariants';
import borders from './dist/borders';
Expand All @@ -20,6 +18,7 @@ import sizes from './dist/sizes';
import space from './dist/space';
import spacing from './dist/spacing';
import time from './dist/time';
import { ITheme, IThemeColorsType, ModeThemeType } from './utils';

const theme: ITheme<typeof variants> = {
colors: colors as IThemeColorsType & ModeThemeType,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { StandardProperties } from 'csstype';

import { ThemeModeEnum } from './enum';
type OptionalRecord<K extends string, T> = {
[P in K]?: T;
};

export type ColorType = Array<string> | Record<string, string>;

Expand All @@ -12,27 +14,14 @@ export type IntentsType = {
};

export type ModeThemeType = {
mode: ThemeModeEnum;
mode: string;
text: string;
highlight: string;
highlights: ColorType;
primary: ColorType;
neutrals: ColorType;
intents: IntentsType;
};

export type IThemeColorsType = {
mode?: ThemeModeEnum;
common: Record<string, string | ColorType>;
modes: {
[x in ThemeModeEnum]: ModeThemeType;
};
};

type OptionalRecord<K extends string, T> = {
[P in K]?: T;
};

export interface ITheme<V> {
colors?: ModeThemeType & IThemeColorsType;
variants?: V;
Expand All @@ -56,3 +45,11 @@ export interface ITheme<V> {
[x: string]: unknown;
defaultStyles?: OptionalRecord<string, unknown>;
}

export type IThemeColorsType = {
mode?: string;
common: Record<string, string | ColorType>;
modes: {
[x: string]: ModeThemeType;
};
};

0 comments on commit a8bcd71

Please sign in to comment.