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

Commit cbf6cc5

Browse files
태재영Matt Goo
authored andcommitted
feat(button): define CSS_CLASSES (#838)
1 parent 41a919d commit cbf6cc5

File tree

2 files changed

+42
-9
lines changed

2 files changed

+42
-9
lines changed

packages/button/constant.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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-button',
25+
ICON: 'mdc-button__icon',
26+
LABEL: 'mdc-button__label',
27+
DENSE: 'mdc-button--dense',
28+
RAISED: 'mdc-button--raised',
29+
OUTLINED: 'mdc-button--outlined',
30+
UNELEVATED: 'mdc-button--unelevated',
31+
};
32+
33+
export {CSS_CLASSES};

packages/button/index.tsx

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

27-
const BUTTON_CLASS_NAME = 'mdc-button__icon';
27+
import {CSS_CLASSES} from './constant';
2828

2929
type ButtonTypes = HTMLAnchorElement | HTMLButtonElement;
3030

@@ -63,11 +63,11 @@ export const Button = <T extends ButtonTypes>(
6363
}: ButtonProps<T>
6464
) => {
6565
const props = {
66-
className: classnames('mdc-button', className, {
67-
'mdc-button--raised': raised,
68-
'mdc-button--unelevated': unelevated,
69-
'mdc-button--outlined': outlined,
70-
'mdc-button--dense': dense,
66+
className: classnames(CSS_CLASSES.ROOT, className, {
67+
[CSS_CLASSES.RAISED]: raised,
68+
[CSS_CLASSES.UNELEVATED]: unelevated,
69+
[CSS_CLASSES.OUTLINED]: outlined,
70+
[CSS_CLASSES.DENSE]: dense,
7171
}),
7272
ref: initRipple,
7373
disabled,
@@ -78,7 +78,7 @@ export const Button = <T extends ButtonTypes>(
7878
return (
7979
<a {...props as React.HTMLProps<HTMLAnchorElement>} href={href}>
8080
{!trailingIcon ? renderIcon(icon) : null}
81-
<span className='mdc-button__label'>
81+
<span className={CSS_CLASSES.LABEL}>
8282
{children}
8383
</span>
8484
{trailingIcon ? renderIcon(trailingIcon) : null}
@@ -89,7 +89,7 @@ export const Button = <T extends ButtonTypes>(
8989
return (
9090
<button {...props as React.HTMLProps<HTMLButtonElement>}>
9191
{!trailingIcon ? renderIcon(icon) : null}
92-
<span className='mdc-button__label'>
92+
<span className={CSS_CLASSES.LABEL}>
9393
{children}
9494
</span>
9595
{trailingIcon ? renderIcon(trailingIcon) : null}
@@ -100,7 +100,7 @@ export const Button = <T extends ButtonTypes>(
100100
const renderIcon = (icon?: React.ReactElement<React.HTMLProps<HTMLOrSVGElement>>) => (
101101
icon ?
102102
React.cloneElement(icon, {
103-
className: classnames(BUTTON_CLASS_NAME, icon.props.className),
103+
className: classnames(CSS_CLASSES.ICON, icon.props.className),
104104
}) :
105105
null
106106
);

0 commit comments

Comments
 (0)