|
| 1 | +import type * as React from 'react'; |
| 2 | +import type * as CSS from 'csstype'; |
| 3 | + |
| 4 | +export type Variant = |
| 5 | + | 'h1' |
| 6 | + | 'h2' |
| 7 | + | 'h3' |
| 8 | + | 'h4' |
| 9 | + | 'h5' |
| 10 | + | 'h6' |
| 11 | + | 'subtitle1' |
| 12 | + | 'subtitle2' |
| 13 | + | 'body1' |
| 14 | + | 'body2' |
| 15 | + | 'caption' |
| 16 | + | 'button' |
| 17 | + | 'overline'; |
| 18 | + |
| 19 | +export interface FontStyle |
| 20 | + extends Required<{ |
| 21 | + fontFamily: React.CSSProperties['fontFamily']; |
| 22 | + fontSize: number; |
| 23 | + fontWeightLight: React.CSSProperties['fontWeight']; |
| 24 | + fontWeightRegular: React.CSSProperties['fontWeight']; |
| 25 | + fontWeightMedium: React.CSSProperties['fontWeight']; |
| 26 | + fontWeightBold: React.CSSProperties['fontWeight']; |
| 27 | + htmlFontSize: number; |
| 28 | + }> {} |
| 29 | + |
| 30 | +export type NormalCssProperties = CSS.Properties<number | string>; |
| 31 | +export type Fontface = CSS.AtRule.FontFace & { fallbacks?: CSS.AtRule.FontFace[] }; |
| 32 | + |
| 33 | +/** |
| 34 | + * Allows the user to augment the properties available |
| 35 | + */ |
| 36 | +export interface BaseCSSProperties extends NormalCssProperties { |
| 37 | + '@font-face'?: Fontface | Fontface[]; |
| 38 | +} |
| 39 | + |
| 40 | +export interface CSSProperties extends BaseCSSProperties { |
| 41 | + // Allow pseudo selectors and media queries |
| 42 | + // `unknown` is used since TS does not allow assigning an interface without |
| 43 | + // an index signature to one with an index signature. This is to allow type safe |
| 44 | + // module augmentation. |
| 45 | + // Technically we want any key not typed in `BaseCSSProperties` to be of type |
| 46 | + // `CSSProperties` but this doesn't work. The index signature needs to cover |
| 47 | + // BaseCSSProperties as well. Usually you would use `BaseCSSProperties[keyof BaseCSSProperties]` |
| 48 | + // but this would not allow assigning React.CSSProperties to CSSProperties |
| 49 | + [k: string]: unknown | CSSProperties; |
| 50 | +} |
| 51 | + |
| 52 | + |
| 53 | +// TODO: which one should actually be allowed to be subject to module augmentation? |
| 54 | +// current type vs interface decision is kept for historical reasons until we |
| 55 | +// made a decision |
| 56 | +export type TypographyStyle = CSSProperties; |
| 57 | + |
| 58 | +export interface TypographyUtils { |
| 59 | + pxToRem: (px: number) => string; |
| 60 | +} |
| 61 | + |
| 62 | +export interface Typography extends Record<Variant, TypographyStyle>, FontStyle, TypographyUtils {} |
| 63 | + |
| 64 | + |
0 commit comments