Skip to content

Instantly share code, notes, and snippets.

@esmevane
Created December 16, 2018 15:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save esmevane/8a75cc697436d51e741fc241d29aba14 to your computer and use it in GitHub Desktop.
Save esmevane/8a75cc697436d51e741fc241d29aba14 to your computer and use it in GitHub Desktop.
[ Themes / Typescript ]: Hierarchical theme type & helper functions
// tslint:disable:object-literal-sort-keys
interface MinorHierarchy<T> {
one: T
two: T
three: T
four: T
}
export const createMinorHierarchy = <T>(
one: T,
two: T,
three: T,
four: T
): MinorHierarchy<T> => ({
one,
two,
three,
four,
})
interface MajorHierarchy<T> extends MinorHierarchy<T> {
five: T
six: T
seven: T
eight: T
nine: T
}
export const createMajorHierarchy = <T>(
one: T,
two: T,
three: T,
four: T,
five: T,
six: T,
seven: T,
eight: T,
nine: T
): MajorHierarchy<T> => ({
one,
two,
three,
four,
five,
six,
seven,
eight,
nine,
})
interface HierarchicalTheme {
margin: MajorHierarchy<string>
padding: MajorHierarchy<string>
width: MajorHierarchy<string>
height: MajorHierarchy<string>
opacity: MajorHierarchy<string>
border: {
radius: MinorHierarchy<string>
width: MinorHierarchy<string>
}
colors: {
neutral: MajorHierarchy<string>
primary: MajorHierarchy<string>
supporting: {
accent: MajorHierarchy<string>
success: MajorHierarchy<string>
destructive: MajorHierarchy<string>
warning: MajorHierarchy<string>
}
}
icons: {
size: MinorHierarchy<string>
}
font: {
serif: string
sans: string
weight: MajorHierarchy<string>
size: MajorHierarchy<string>
lineHeight: MajorHierarchy<string>
}
shadows: {
drop: MinorHierarchy<string>
inset: MinorHierarchy<string>
}
}
export const createHierarchy = (hierarchical: HierarchicalTheme) => hierarchical
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment