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

Commit 73add93

Browse files
태재영Matt Goo
태재영
authored and
Matt Goo
committed
chore(card): define CSS_CLASSES (#839)
1 parent cbf6cc5 commit 73add93

File tree

7 files changed

+68
-15
lines changed

7 files changed

+68
-15
lines changed

packages/card/ActionButtons.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
import React from 'react';
2424
import classnames from 'classnames';
2525

26+
import {CSS_CLASSES} from './constant';
27+
2628
type ChildType = React.ReactElement<React.HTMLProps<HTMLButtonElement|HTMLAnchorElement>>;
2729

2830
export interface ActionButtonsProps extends React.HTMLProps<HTMLDivElement> {
@@ -34,8 +36,8 @@ const addButtonClassToChildren = (children: ChildType | ChildType[]) => {
3436
return React.Children.map((children as ChildType | ChildType[]), (item) => {
3537
const className = classnames(
3638
(item as ChildType).props.className,
37-
'mdc-card__action',
38-
'mdc-card__action--button'
39+
CSS_CLASSES.ACTION,
40+
CSS_CLASSES.ACTION_BUTTON,
3941
);
4042
const props = Object.assign({}, (item as ChildType).props, {className});
4143
return React.cloneElement((item as ChildType), props);
@@ -45,7 +47,7 @@ const addButtonClassToChildren = (children: ChildType | ChildType[]) => {
4547
const ActionButtons: React.FunctionComponent<ActionButtonsProps> = ({
4648
className = '', children, ...otherProps // eslint-disable-line react/prop-types
4749
}) => {
48-
const classes = classnames('mdc-card__action-buttons', className);
50+
const classes = classnames(CSS_CLASSES.ACTION_BUTTONS, className);
4951
if (!children) return null;
5052
return (
5153
<div className={classes} {...otherProps}>

packages/card/ActionIcons.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
import React from 'react';
2424
import classnames from 'classnames';
2525

26+
import {CSS_CLASSES} from './constant';
27+
2628
type ChildType = React.ReactElement<React.HTMLProps<HTMLImageElement|HTMLOrSVGElement>>;
2729

2830
export interface ActionIconsProps extends React.HTMLProps<HTMLDivElement> {
@@ -34,8 +36,8 @@ const addIconClassToChildren = (children: ChildType | ChildType[]) => {
3436
return React.Children.map((children as ChildType | ChildType[]), (item) => {
3537
const className = classnames(
3638
(item as ChildType).props.className,
37-
'mdc-card__action',
38-
'mdc-card__action--icon'
39+
CSS_CLASSES.ACTION,
40+
CSS_CLASSES.ACTION_ICON,
3941
);
4042
const props = Object.assign({}, (item as ChildType).props, {className});
4143
return React.cloneElement((item as ChildType), props);
@@ -45,7 +47,7 @@ const addIconClassToChildren = (children: ChildType | ChildType[]) => {
4547
const ActionIcons: React.FunctionComponent<ActionIconsProps> = ({
4648
className = '', children, ...otherProps // eslint-disable-line react/prop-types
4749
}) => {
48-
const classes = classnames('mdc-card__action-icons', className);
50+
const classes = classnames(CSS_CLASSES.ACTION_ICONS, className);
4951
if (!children) return null;
5052
return (
5153
<div className={classes} {...otherProps}>

packages/card/Actions.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
import React from 'react';
2424
import classnames from 'classnames';
2525

26+
import {CSS_CLASSES} from './constant';
27+
2628
export interface ActionsProps extends React.HTMLProps<HTMLDivElement> {
2729
className?: string;
2830
fullBleed?: boolean;
@@ -31,8 +33,8 @@ export interface ActionsProps extends React.HTMLProps<HTMLDivElement> {
3133
const Actions: React.FunctionComponent<ActionsProps> = ({
3234
className = '', children, fullBleed = false, ...otherProps // eslint-disable-line react/prop-types
3335
}) => {
34-
const classes = classnames('mdc-card__actions', className, {
35-
'mdc-card__actions--full-bleed': fullBleed,
36+
const classes = classnames(CSS_CLASSES.ACTIONS, className, {
37+
[CSS_CLASSES.ACTIONS_FULL_BLEED]: fullBleed,
3638
});
3739
return (
3840
<div className={classes} {...otherProps}>

packages/card/Media.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
import React from 'react';
2424
import classnames from 'classnames';
2525

26+
import {CSS_CLASSES} from './constant';
27+
2628
export interface MediaProps extends React.HTMLProps<HTMLDivElement> {
2729
className?: string;
2830
square?: boolean;
@@ -48,7 +50,7 @@ const renderChildren: (mediaChildren: MediaChildren) => React.ReactElement<HTMLD
4850
if (!children) {
4951
return;
5052
}
51-
const classes = classnames('mdc-card__media-content', contentClassName);
53+
const classes = classnames(CSS_CLASSES.MEDIA_CONTENT, contentClassName);
5254
return <div className={classes}>{children}</div>;
5355
};
5456

@@ -71,9 +73,9 @@ const Media: React.FunctionComponent<MediaProps> = ({
7173
/* eslint-enable react/prop-types */
7274
...otherProps
7375
}) => {
74-
const classes = classnames('mdc-card__media', className, {
75-
'mdc-card__media--square': square,
76-
'mdc-card__media--16-9': wide,
76+
const classes = classnames(CSS_CLASSES.MEDIA, className, {
77+
[CSS_CLASSES.MEDIA_SQUARE]: square,
78+
[CSS_CLASSES.MEDIA_16_9]: wide,
7779
});
7880

7981
return (

packages/card/PrimaryContent.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ import React from 'react';
2424
import classnames from 'classnames';
2525
import {withRipple, InjectedProps} from '@material/react-ripple';
2626

27+
import {CSS_CLASSES} from './constant';
28+
2729
export interface PrimaryContentBaseProps extends React.HTMLProps<HTMLDivElement>, InjectedProps<HTMLDivElement>{
2830
className: string;
2931
unbounded?: boolean;
@@ -38,7 +40,7 @@ export const PrimaryContentBase: React.FunctionComponent<PrimaryContentBaseProps
3840
/* eslint-enable react/prop-types */
3941
...otherProps
4042
}) => {
41-
const classes = classnames('mdc-card__primary-action', className);
43+
const classes = classnames(CSS_CLASSES.PRIMARY_ACTION, className);
4244

4345
return (
4446
<div className={classes} ref={initRipple} {...otherProps}>

packages/card/constant.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// The MIT License
2+
//
3+
// Copyright (c) 2019 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+
const CSS_CLASSES = {
24+
ROOT: 'mdc-card',
25+
OUTLINED: 'mdc-card--outlined',
26+
PRIMARY_ACTION: 'mdc-card__primary-action',
27+
MEDIA: 'mdc-card__media',
28+
MEDIA_SQUARE: 'mdc-card__media--square',
29+
MEDIA_16_9: 'mdc-card__media--16-9',
30+
MEDIA_CONTENT: 'mdc-card__media-content',
31+
ACTIONS: 'mdc-card__actions',
32+
ACTIONS_FULL_BLEED: 'mdc-card__actions--full-bleed',
33+
ACTION_BUTTONS: 'mdc-card__action-buttons',
34+
ACTION_ICONS: 'mdc-card__action-icons',
35+
ACTION: 'mdc-card__action',
36+
ACTION_BUTTON: 'mdc-card__action--button',
37+
ACTION_ICON: 'mdc-card__action--icon',
38+
};
39+
40+
export {CSS_CLASSES};

packages/card/index.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,15 @@
2222

2323
import React from 'react';
2424
import classnames from 'classnames';
25+
2526
import ActionButtons from './ActionButtons';
2627
import ActionIcons from './ActionIcons';
2728
import Actions from './Actions';
2829
import PrimaryContent from './PrimaryContent';
2930
import Media from './Media';
3031

32+
import {CSS_CLASSES} from './constant';
33+
3134
export interface CardProps extends React.HTMLProps<HTMLDivElement> {
3235
className?: string,
3336
outlined?: boolean
@@ -36,8 +39,8 @@ export interface CardProps extends React.HTMLProps<HTMLDivElement> {
3639
const Card: React.FunctionComponent<CardProps> = ({
3740
children, className = '', outlined = false, ...otherProps // eslint-disable-line react/prop-types
3841
}) => {
39-
const classes = classnames('mdc-card', className, {
40-
'mdc-card--outlined': outlined,
42+
const classes = classnames(CSS_CLASSES.ROOT, className, {
43+
[CSS_CLASSES.OUTLINED]: outlined,
4144
});
4245
return (
4346
<div className={classes} {...otherProps}>

0 commit comments

Comments
 (0)