Skip to content

Commit

Permalink
[WIP] Bug Fixed: createTypography TypographyOptions type is invalid (#…
Browse files Browse the repository at this point in the history
…9364)

Make TypographyOptions = DeepPartial<Typography>
  • Loading branch information
Andrei Goncharov authored and pelotom committed Dec 2, 2017
1 parent 40d4142 commit bbc75dc
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/index.d.ts
Expand Up @@ -48,6 +48,11 @@ type Diff<T extends string, U extends string> = (
/** @internal */
export type Omit<T, K extends keyof T> = Pick<T, Diff<keyof T, K>>;

/** @internal */
export type DeepPartial<T> = {
[P in keyof T]?: DeepPartial<T[P]>;
}

export namespace PropTypes {
type Alignment = 'inherit' | 'left' | 'center' | 'right' | 'justify';
type Color = 'inherit' | 'primary' | 'accent' | 'default';
Expand Down
3 changes: 2 additions & 1 deletion src/styles/createTypography.d.ts
@@ -1,5 +1,6 @@
import * as React from 'react';
import { Palette } from './createPalette';
import { DeepPartial } from '..'

export type TextStyle =
| 'display1'
Expand Down Expand Up @@ -36,7 +37,7 @@ export interface TypographyStyle {

export type Typography = { [type in Style]: TypographyStyle } & FontStyle;

export type TypographyOptions = Partial<FontStyle> & Partial<Typography>;
export type TypographyOptions = DeepPartial<Typography>;

export default function createTypography(
palette: Palette,
Expand Down
6 changes: 6 additions & 0 deletions src/styles/createTypography.spec.js
Expand Up @@ -34,4 +34,10 @@ describe('createTypography', () => {
const typography = createTypography(palette, { htmlFontSize: 10 });
assert.strictEqual(typography.display4.fontSize, '11.2rem');
});

it('should create a typography with custom display4', () => {
const customFontSize = '18px';
const typography = createTypography(palette, { display4: { fontSize: customFontSize } });
assert.strictEqual(typography.display4.fontSize, customFontSize);
});
});
9 changes: 9 additions & 0 deletions test/typescript/styles.spec.tsx
Expand Up @@ -94,6 +94,15 @@ const customTheme = createMuiTheme({
},
});

const customThemeTypographyPartial = createMuiTheme({
typography: {
display4: {
fontSize: '18px'
},
fontSize: 18
},
});

function OverridesTheme() {
return (
<MuiThemeProvider theme={theme}>
Expand Down

0 comments on commit bbc75dc

Please sign in to comment.