Skip to content

Commit

Permalink
feat(layout-grid): typescript (#498)
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt Goo committed Dec 28, 2018
1 parent af94a3a commit a25039e
Show file tree
Hide file tree
Showing 13 changed files with 209 additions and 191 deletions.
23 changes: 7 additions & 16 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

59 changes: 0 additions & 59 deletions packages/layout-grid/Cell.js

This file was deleted.

52 changes: 52 additions & 0 deletions packages/layout-grid/Cell.tsx
@@ -0,0 +1,52 @@
import * as React from 'react';
import * as classnames from 'classnames';

export type TwelveColumn = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12;
export type FourColumn = 1 | 2 | 3 | 4;
export type EightColumn = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8;
export type Alignment = 'bottom' | 'middle' | 'top';

export interface CellProps<T> extends React.HTMLProps<T> {
align?: Alignment,
className?: string,
columns?: TwelveColumn,
desktopColumns?: TwelveColumn,
order?: TwelveColumn,
phoneColumns?: FourColumn,
tabletColumns?: EightColumn,
tag?: string
};

const Cell: <T extends {} = HTMLDivElement>(props: CellProps<T>) => React.ReactElement<any> = ({
/* eslint-disable react/prop-types */
align,
children,
className = '',
columns,
desktopColumns,
order,
phoneColumns,
tabletColumns,
tag: Tag = 'div',
/* eslint-enable react/prop-types */
...otherProps
}) => {
const classes = classnames('mdc-layout-grid__cell', className, {
[`mdc-layout-grid__cell--align-${align}`]: !!align,
[`mdc-layout-grid__cell--order-${order}`]: !!order,
[`mdc-layout-grid__cell--span-${columns}`]: !!columns,
[`mdc-layout-grid__cell--span-${desktopColumns}-desktop`]: !!desktopColumns,
[`mdc-layout-grid__cell--span-${phoneColumns}-phone`]: !!phoneColumns,
[`mdc-layout-grid__cell--span-${tabletColumns}-tablet`]: !!tabletColumns,
});

return (
// https://github.com/Microsoft/TypeScript/issues/28892
// @ts-ignore
<Tag className={classes} {...otherProps}>
{children}
</Tag>
);
};

export default Cell;
40 changes: 0 additions & 40 deletions packages/layout-grid/Grid.js

This file was deleted.

35 changes: 35 additions & 0 deletions packages/layout-grid/Grid.tsx
@@ -0,0 +1,35 @@
import * as React from 'react';
import * as classnames from 'classnames';

export type Alignment = 'left' | 'right';
export interface GridProps<T> extends React.HTMLProps<T> {
align?: Alignment,
className?: string,
fixedColumnWidth?: boolean,
tag?: string
};

const Grid: <T extends {} = HTMLDivElement>(props: GridProps<T>) => React.ReactElement<any> = ({
/* eslint-disable react/prop-types */
align,
children,
className = '',
fixedColumnWidth = false,
tag: Tag = 'div',
/* eslint-enable react/prop-types */
...otherProps
}) => {
const classes = classnames('mdc-layout-grid', className, {
[`mdc-layout-grid--align-${align}`]: !!align,
'mdc-layout-grid--fixed-column-width': fixedColumnWidth,
});
return (
// https://github.com/Microsoft/TypeScript/issues/28892
// @ts-ignore
<Tag className={classes} {...otherProps}>
{children}
</Tag>
);
};

export default Grid;
31 changes: 0 additions & 31 deletions packages/layout-grid/Row.js

This file was deleted.

28 changes: 28 additions & 0 deletions packages/layout-grid/Row.tsx
@@ -0,0 +1,28 @@
import * as React from 'react';
import * as classnames from 'classnames';

export interface RowProps<T> extends React.HTMLProps<T> {
className?: string,
tag?: string
};

const Row: <T extends {} = HTMLDivElement>(props: RowProps<T>) => React.ReactElement<any> = ({
/* eslint-disable react/prop-types */
children = '',
className,
tag: Tag = 'div',
...otherProps
/* eslint-enable react/prop-types */
}) => {
const classes = classnames('mdc-layout-grid__inner', className);

return (
// https://github.com/Microsoft/TypeScript/issues/28892
// @ts-ignore
<Tag className={classes} {...otherProps}>
{children}
</Tag>
);
};

export default Row;
File renamed without changes.

0 comments on commit a25039e

Please sign in to comment.