Skip to content

Commit

Permalink
feat(card): typescript (#497)
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt Goo committed Dec 28, 2018
1 parent e3373bb commit c9665bc
Show file tree
Hide file tree
Showing 16 changed files with 331 additions and 380 deletions.
64 changes: 0 additions & 64 deletions packages/card/ActionButtons.js

This file was deleted.

57 changes: 57 additions & 0 deletions packages/card/ActionButtons.tsx
@@ -0,0 +1,57 @@
// The MIT License
//
// Copyright (c) 2018 Google, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

import * as React from 'react';
import * as classnames from 'classnames';

type ChildType = React.ReactElement<React.HTMLProps<HTMLButtonElement|HTMLAnchorElement>>;

export interface ActionButtonsProps extends React.HTMLProps<HTMLDivElement> {
className?: string;
children?: ChildType | ChildType[];
};

const addButtonClassToChildren = (children: ChildType | ChildType[]) => {
return React.Children.map((children as ChildType | ChildType[]), (item) => {
const className = classnames(
(item as ChildType).props.className,
'mdc-card__action',
'mdc-card__action--button'
);
const props = Object.assign({}, (item as ChildType).props, {className});
return React.cloneElement((item as ChildType), props);
});
};

const ActionButtons: React.FunctionComponent<ActionButtonsProps> = ({
className = '', children, ...otherProps // eslint-disable-line react/prop-types
}) => {
const classes = classnames('mdc-card__action-buttons', className);
if (!children) return null;
return (
<div className={classes} {...otherProps}>
{addButtonClassToChildren(children)}
</div>
);
};

export default ActionButtons;
63 changes: 28 additions & 35 deletions packages/card/ActionIcons.js → packages/card/ActionIcons.tsx
Expand Up @@ -20,45 +20,38 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

import React from 'react';
import classnames from 'classnames';
import PropTypes from 'prop-types';
import * as React from 'react';
import * as classnames from 'classnames';

export default class ActionIcons extends React.Component {
addIconClassToChildren = () => {
return React.Children.map(this.props.children, (item) => {
const className = classnames(
item.props.className, 'mdc-card__action', 'mdc-card__action--icon');
const props = Object.assign({}, item.props, {className});
return React.cloneElement(item, props);
});
};
type ChildType = React.ReactElement<React.HTMLProps<HTMLImageElement|HTMLOrSVGElement>>;

render() {
const {
className,
children, // eslint-disable-line no-unused-vars
...otherProps
} = this.props;
const classes = classnames('mdc-card__action-icons', className);
export interface ActionIconsProps extends React.HTMLProps<HTMLDivElement> {
className?: string;
children?: ChildType | ChildType[];
};

return (
<div
className={classes}
{...otherProps}
>
{this.addIconClassToChildren()}
</div>
const addIconClassToChildren = (children: ChildType | ChildType[]) => {
return React.Children.map((children as ChildType | ChildType[]), (item) => {
const className = classnames(
(item as ChildType).props.className,
'mdc-card__action',
'mdc-card__action--icon'
);
}
}

ActionIcons.propTypes = {
className: PropTypes.string,
children: PropTypes.node,
const props = Object.assign({}, (item as ChildType).props, {className});
return React.cloneElement((item as ChildType), props);
});
};

ActionIcons.defaultProps = {
className: '',
children: null,
const ActionIcons: React.FunctionComponent<ActionIconsProps> = ({
className = '', children, ...otherProps // eslint-disable-line react/prop-types
}) => {
const classes = classnames('mdc-card__action-icons', className);
if (!children) return null;
return (
<div className={classes} {...otherProps}>
{addIconClassToChildren(children)}
</div>
);
};

export default ActionIcons;
52 changes: 18 additions & 34 deletions packages/card/Actions.js → packages/card/Actions.tsx
Expand Up @@ -20,41 +20,25 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

import React from 'react';
import classnames from 'classnames';
import PropTypes from 'prop-types';
import * as React from 'react';
import * as classnames from 'classnames';

export default class Actions extends React.Component {
render() {
const {
className,
children,
fullBleed,
...otherProps
} = this.props;
const classes = classnames('mdc-card__actions', className, {
'mdc-card__actions--full-bleed': fullBleed,
});

return (
<div
className={classes}
{...otherProps}
>
{children}
</div>
);
}
}

Actions.propTypes = {
className: PropTypes.string,
children: PropTypes.node,
fullBleed: PropTypes.bool,
export interface ActionsProps extends React.HTMLProps<HTMLDivElement> {
className?: string;
fullBleed?: boolean;
};

Actions.defaultProps = {
className: '',
children: null,
fullBleed: false,
const Actions: React.FunctionComponent<ActionsProps> = ({
className = '', children, fullBleed = false, ...otherProps // eslint-disable-line react/prop-types
}) => {
const classes = classnames('mdc-card__actions', className, {
'mdc-card__actions--full-bleed': fullBleed,
});
return (
<div className={classes} {...otherProps}>
{children}
</div>
);
};

export default Actions;
96 changes: 0 additions & 96 deletions packages/card/Media.js

This file was deleted.

0 comments on commit c9665bc

Please sign in to comment.