-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
15 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,17 @@ | ||
import Color from 'color' | ||
import deepmerge from 'deepmerge' | ||
|
||
import { ThemeTokens } from './core/token.h' | ||
import { Shape, ThemeTokens } from './core/token.h' | ||
|
||
export function theme(shape1: ThemeTokens, shape2: ThemeTokens = {}): ThemeTokens { | ||
return deepmerge(shape1, shape2) | ||
} | ||
type Primitives = Shape<string | number> | ||
type ThemeFn = (primitives: Primitives) => ThemeTokens | ||
|
||
export function color(inputColor: string, options: { h?: number; s?: number; l?: number }): string { | ||
return Color(inputColor) | ||
// @ts-ignore | ||
.hsl(options.h, options.s, options.l) | ||
.hex() | ||
// TODO: theme args must be fn or plain shape. | ||
export function withTokens(theme1: ThemeFn, theme2?: ThemeFn) { | ||
return (primitives1: Primitives = {}) => (primitives2: Primitives = {}) => { | ||
const composedPrimitives = deepmerge(primitives1, primitives2) | ||
if (theme2 === undefined) { | ||
return theme1(composedPrimitives) | ||
} | ||
return deepmerge(theme1(composedPrimitives), theme2(composedPrimitives)) | ||
} | ||
} |