Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeScript theme definition #8

Open
djgrant opened this issue Nov 27, 2019 · 4 comments
Open

TypeScript theme definition #8

djgrant opened this issue Nov 27, 2019 · 4 comments

Comments

@djgrant
Copy link

djgrant commented Nov 27, 2019

Would this be a good place to keep a TS definition for theme objects? This would be helpful when implementing a spec-compliant library and improve dev experience of existing libraries.

@crswll
Copy link

crswll commented Feb 6, 2020

I hacked this up real quick for a side project I'm working on. It has some extra that's not standard so delete away!

interface ThemeUiSpec {
  borders?: { [name: string]: number }
  borderStyles?: { [name: string]: number }
  borderWidths?: { [name: string]: number }
  colors?:
    | { [name: string]: string }
    | { "modes"?: { [name: string]: string } }
  fonts?: { [name: string]: string }
  fontSizes?: { [name: string]: number }
  fontWeights?: { [name: string]: number }
  letterSpacings?: { [name: string]: number }
  lineHeights?: { [name: string]: number }
  radii?: { [name: string]: number }
  space?: { [name: string]: number }
  sizes?: { [name: string]: number }
  transitionDurations?: { [name: string]: number }
  transitionTiming?: {
    [name: string]: {
      "x1": number,
      "y1": number,
      "x2": number,
      "y2": number,
    }
  }
  zIndices?: { [name: string]: number }
}

@cyrilchapon
Copy link

An important question regarding this :

Can a value be an alias of another value ?

I mean :

colors: {
  red: '#F33',
  primary: 'red' <== what does it do ?
}

@jxnblk
Copy link
Member

jxnblk commented May 8, 2020

@cyrilchapon currently values in the theme scales cannot self-reference, so 'red' would be the CSS color keyword and not the value defined on the line above in your example ('#F33') – to make theme objects completely JSON-serializable in the future, we might want some mechanism to do that, but it doesn't currently work that way

@Sheldonfrith
Copy link

Sheldonfrith commented Mar 5, 2021

@crswll very helpful, thanks! I am modifying it slightly for my use. I am using the 'styled-system' library, and I think the following interface is closer to what that library specifically uses (although I haven't tested it yet, and the library unfortunately isn't written in ts).

type ArrayStringNumber = (string|number)[];
type ObjStringNumber = {[key:string]: number | string};
type ArrayOrObjStringNumber = ArrayStringNumber|ObjStringNumber;
export type SimpleColors = {[key:string]:string};
export type NestedColors = {[key:string]:{[key:string]:string}};
export type Colors = SimpleColors|NestedColors;
export interface Theme {
    breakpoints: {[key: string]: number}|number[]
    borders?: ArrayOrObjStringNumber
    borderStyles?: { [key: string]: string }
    borderWidths?: ArrayOrObjStringNumber
    colors?: Colors
    fonts?: { [key: string]: string }
    fontSizes?: ArrayOrObjStringNumber
    fontWeights?: { [key: string]: number }|number[]
    letterSpacings?: ArrayOrObjStringNumber
    lineHeights?: ArrayOrObjStringNumber
    radii?: ArrayOrObjStringNumber
    space?: ArrayOrObjStringNumber
    sizes?: ArrayOrObjStringNumber
    transitionDurations?: { [key: string]: number }
    transitionTiming?: {
      [key: string]: {
        "x1": number,
        "y1": number,
        "x2": number,
        "y2": number,
      }
    }
    zIndices?: { [key: string]: number }
  }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants