Skip to content
This repository was archived by the owner on Jul 29, 2025. It is now read-only.

Commit c9665bc

Browse files
author
Matt Goo
committed
feat(card): typescript (#497)
1 parent e3373bb commit c9665bc

16 files changed

+331
-380
lines changed

packages/card/ActionButtons.js

Lines changed: 0 additions & 64 deletions
This file was deleted.

packages/card/ActionButtons.tsx

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// The MIT License
2+
//
3+
// Copyright (c) 2018 Google, Inc.
4+
//
5+
// Permission is hereby granted, free of charge, to any person obtaining a copy
6+
// of this software and associated documentation files (the "Software"), to deal
7+
// in the Software without restriction, including without limitation the rights
8+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
// copies of the Software, and to permit persons to whom the Software is
10+
// furnished to do so, subject to the following conditions:
11+
//
12+
// The above copyright notice and this permission notice shall be included in
13+
// all copies or substantial portions of the Software.
14+
//
15+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
// THE SOFTWARE.
22+
23+
import * as React from 'react';
24+
import * as classnames from 'classnames';
25+
26+
type ChildType = React.ReactElement<React.HTMLProps<HTMLButtonElement|HTMLAnchorElement>>;
27+
28+
export interface ActionButtonsProps extends React.HTMLProps<HTMLDivElement> {
29+
className?: string;
30+
children?: ChildType | ChildType[];
31+
};
32+
33+
const addButtonClassToChildren = (children: ChildType | ChildType[]) => {
34+
return React.Children.map((children as ChildType | ChildType[]), (item) => {
35+
const className = classnames(
36+
(item as ChildType).props.className,
37+
'mdc-card__action',
38+
'mdc-card__action--button'
39+
);
40+
const props = Object.assign({}, (item as ChildType).props, {className});
41+
return React.cloneElement((item as ChildType), props);
42+
});
43+
};
44+
45+
const ActionButtons: React.FunctionComponent<ActionButtonsProps> = ({
46+
className = '', children, ...otherProps // eslint-disable-line react/prop-types
47+
}) => {
48+
const classes = classnames('mdc-card__action-buttons', className);
49+
if (!children) return null;
50+
return (
51+
<div className={classes} {...otherProps}>
52+
{addButtonClassToChildren(children)}
53+
</div>
54+
);
55+
};
56+
57+
export default ActionButtons;

packages/card/ActionIcons.js renamed to packages/card/ActionIcons.tsx

Lines changed: 28 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -20,45 +20,38 @@
2020
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2121
// THE SOFTWARE.
2222

23-
import React from 'react';
24-
import classnames from 'classnames';
25-
import PropTypes from 'prop-types';
23+
import * as React from 'react';
24+
import * as classnames from 'classnames';
2625

27-
export default class ActionIcons extends React.Component {
28-
addIconClassToChildren = () => {
29-
return React.Children.map(this.props.children, (item) => {
30-
const className = classnames(
31-
item.props.className, 'mdc-card__action', 'mdc-card__action--icon');
32-
const props = Object.assign({}, item.props, {className});
33-
return React.cloneElement(item, props);
34-
});
35-
};
26+
type ChildType = React.ReactElement<React.HTMLProps<HTMLImageElement|HTMLOrSVGElement>>;
3627

37-
render() {
38-
const {
39-
className,
40-
children, // eslint-disable-line no-unused-vars
41-
...otherProps
42-
} = this.props;
43-
const classes = classnames('mdc-card__action-icons', className);
28+
export interface ActionIconsProps extends React.HTMLProps<HTMLDivElement> {
29+
className?: string;
30+
children?: ChildType | ChildType[];
31+
};
4432

45-
return (
46-
<div
47-
className={classes}
48-
{...otherProps}
49-
>
50-
{this.addIconClassToChildren()}
51-
</div>
33+
const addIconClassToChildren = (children: ChildType | ChildType[]) => {
34+
return React.Children.map((children as ChildType | ChildType[]), (item) => {
35+
const className = classnames(
36+
(item as ChildType).props.className,
37+
'mdc-card__action',
38+
'mdc-card__action--icon'
5239
);
53-
}
54-
}
55-
56-
ActionIcons.propTypes = {
57-
className: PropTypes.string,
58-
children: PropTypes.node,
40+
const props = Object.assign({}, (item as ChildType).props, {className});
41+
return React.cloneElement((item as ChildType), props);
42+
});
5943
};
6044

61-
ActionIcons.defaultProps = {
62-
className: '',
63-
children: null,
45+
const ActionIcons: React.FunctionComponent<ActionIconsProps> = ({
46+
className = '', children, ...otherProps // eslint-disable-line react/prop-types
47+
}) => {
48+
const classes = classnames('mdc-card__action-icons', className);
49+
if (!children) return null;
50+
return (
51+
<div className={classes} {...otherProps}>
52+
{addIconClassToChildren(children)}
53+
</div>
54+
);
6455
};
56+
57+
export default ActionIcons;

packages/card/Actions.js renamed to packages/card/Actions.tsx

Lines changed: 18 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -20,41 +20,25 @@
2020
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2121
// THE SOFTWARE.
2222

23-
import React from 'react';
24-
import classnames from 'classnames';
25-
import PropTypes from 'prop-types';
23+
import * as React from 'react';
24+
import * as classnames from 'classnames';
2625

27-
export default class Actions extends React.Component {
28-
render() {
29-
const {
30-
className,
31-
children,
32-
fullBleed,
33-
...otherProps
34-
} = this.props;
35-
const classes = classnames('mdc-card__actions', className, {
36-
'mdc-card__actions--full-bleed': fullBleed,
37-
});
38-
39-
return (
40-
<div
41-
className={classes}
42-
{...otherProps}
43-
>
44-
{children}
45-
</div>
46-
);
47-
}
48-
}
49-
50-
Actions.propTypes = {
51-
className: PropTypes.string,
52-
children: PropTypes.node,
53-
fullBleed: PropTypes.bool,
26+
export interface ActionsProps extends React.HTMLProps<HTMLDivElement> {
27+
className?: string;
28+
fullBleed?: boolean;
5429
};
5530

56-
Actions.defaultProps = {
57-
className: '',
58-
children: null,
59-
fullBleed: false,
31+
const Actions: React.FunctionComponent<ActionsProps> = ({
32+
className = '', children, fullBleed = false, ...otherProps // eslint-disable-line react/prop-types
33+
}) => {
34+
const classes = classnames('mdc-card__actions', className, {
35+
'mdc-card__actions--full-bleed': fullBleed,
36+
});
37+
return (
38+
<div className={classes} {...otherProps}>
39+
{children}
40+
</div>
41+
);
6042
};
43+
44+
export default Actions;

packages/card/Media.js

Lines changed: 0 additions & 96 deletions
This file was deleted.

0 commit comments

Comments
 (0)