Skip to content
This repository was archived by the owner on Mar 4, 2020. It is now read-only.

Commit e5ef249

Browse files
kuzhelovlevithomason
authored andcommitted
fix(Button): icon colors and layout (#135)
* fix layuot and icon color of Button * fix color stylings of Button * fix children API * align content to center * remove unused 'content' prop from styles * fix color applied for hover state * fix child API * use site variable to initialize default color * changelog
1 parent dc95292 commit e5ef249

4 files changed

Lines changed: 65 additions & 51 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
2929

3030
### Fixes
3131
- Adjust layout and rendered HTML of Input @kuzhelov ([#127](https://github.com/stardust-ui/react/pull/127))
32+
- Fix Button component's layout and icon color @kuzhelov ([#135](https://github.com/stardust-ui/react/pull/135))
3233

3334
<!--------------------------------[ v0.4.0 ]------------------------------- -->
3435
## [v0.4.0](https://github.com/stardust-ui/react/tree/v0.4.0) (2018-08-29)

src/components/Button/Button.tsx

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,13 @@ class Button extends UIComponent<Extendable<IButtonProps>, any> {
116116
accessibility: ButtonBehavior as Accessibility,
117117
}
118118

119-
public renderComponent({ ElementType, classes, accessibility, rest }): React.ReactNode {
119+
public renderComponent({
120+
ElementType,
121+
classes,
122+
accessibility,
123+
variables,
124+
rest,
125+
}): React.ReactNode {
120126
const { children, content, disabled, iconPosition } = this.props
121127
const hasChildren = childrenExist(children)
122128

@@ -129,20 +135,27 @@ class Button extends UIComponent<Extendable<IButtonProps>, any> {
129135
{...rest}
130136
>
131137
{hasChildren && children}
132-
{!hasChildren && iconPosition !== 'after' && this.renderIcon()}
133-
{!hasChildren && content}
134-
{!hasChildren && iconPosition === 'after' && this.renderIcon()}
138+
{!hasChildren && iconPosition !== 'after' && this.renderIcon(variables)}
139+
{!hasChildren && content && <span className={classes.content}>{content}</span>}
140+
{!hasChildren && iconPosition === 'after' && this.renderIcon(variables)}
135141
</ElementType>
136142
)
137143
}
138144

139-
public renderIcon = () => {
145+
public renderIcon = variables => {
140146
const { disabled, icon, iconPosition, content, type } = this.props
141147

142148
return Icon.create(icon, {
143149
defaultProps: {
144150
xSpacing: !content ? 'none' : iconPosition === 'after' ? 'before' : 'after',
145-
variables: { color: type === 'primary' && !disabled ? 'white' : undefined },
151+
variables: {
152+
color:
153+
type === 'primary'
154+
? variables.typePrimaryColor
155+
: type === 'secondary'
156+
? variables.typeSecondaryColor
157+
: variables.color,
158+
},
146159
},
147160
})
148161
}

src/themes/teams/components/Button/buttonStyles.ts

Lines changed: 43 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@ import { disabledStyle, truncateStyle } from '../../../../styles/customCSS'
44

55
const buttonStyles: IComponentPartStylesInput = {
66
root: ({ props, variables }: { props: any; variables: any }): ICSSInJSStyle => {
7-
const { circular, disabled, fluid, icon, iconPosition, type } = props
7+
const { circular, disabled, fluid, type } = props
88
const primary = type === 'primary'
99
const secondary = type === 'secondary'
1010

1111
const {
1212
height,
1313
minWidth,
1414
maxWidth,
15+
color,
1516
backgroundColor,
1617
backgroundColorHover,
1718
circularRadius,
@@ -30,28 +31,43 @@ const buttonStyles: IComponentPartStylesInput = {
3031
height,
3132
minWidth,
3233
maxWidth,
34+
color,
3335
backgroundColor,
34-
display: 'inline-block',
36+
display: 'inline-flex',
37+
justifyContent: 'center',
38+
alignItems: 'center',
3539
position: 'relative',
3640
padding: `0 ${pxToRem(paddingLeftRightValue)}`,
3741
margin: `0 ${pxToRem(8)} 0 0`,
3842
verticalAlign: 'middle',
3943
borderRadius: pxToRem(2),
40-
borderWidth: 0,
4144

42-
...truncateStyle,
45+
borderWidth: `${secondary ? (circular ? 1 : 2) : 0}px`,
46+
cursor: 'pointer',
47+
':hover': {
48+
backgroundColor: backgroundColorHover,
49+
},
4350

44-
...(icon &&
45-
(iconPosition
46-
? {
47-
display: 'inline-flex',
48-
alignItems: 'center',
49-
justifyContent: 'center',
50-
}
51-
: {
52-
minWidth: height,
53-
padding: 0,
54-
})),
51+
...(primary && {
52+
color: typePrimaryColor,
53+
backgroundColor: typePrimaryBackgroundColor,
54+
borderColor: typePrimaryBorderColor,
55+
':hover': {
56+
color: typePrimaryColor,
57+
backgroundColor: typePrimaryBackgroundColorHover,
58+
},
59+
}),
60+
61+
...(secondary && {
62+
color: typeSecondaryColor,
63+
backgroundColor: typeSecondaryBackgroundColor,
64+
borderColor: typeSecondaryBorderColor,
65+
':hover': {
66+
color: typeSecondaryColor,
67+
borderColor: 'transparent',
68+
backgroundColor: typeSecondaryBackgroundColorHover,
69+
},
70+
}),
5571

5672
...(circular && {
5773
minWidth: height,
@@ -64,38 +80,20 @@ const buttonStyles: IComponentPartStylesInput = {
6480
maxWidth: '100%',
6581
}),
6682

67-
...(disabled
68-
? disabledStyle
69-
: {
70-
borderWidth: `${secondary ? (circular ? 1 : 2) : 0}px`,
71-
cursor: 'pointer',
72-
':hover': {
73-
backgroundColor: backgroundColorHover,
74-
},
75-
76-
...(primary && {
77-
color: typePrimaryColor,
78-
backgroundColor: typePrimaryBackgroundColor,
79-
borderColor: typePrimaryBorderColor,
80-
':hover': {
81-
color: typePrimaryColor,
82-
backgroundColor: typePrimaryBackgroundColorHover,
83-
},
84-
}),
85-
86-
...(secondary && {
87-
color: typeSecondaryColor,
88-
backgroundColor: typeSecondaryBackgroundColor,
89-
borderColor: typeSecondaryBorderColor,
90-
':hover': {
91-
color: typeSecondaryColor,
92-
borderColor: 'transparent',
93-
backgroundColor: typeSecondaryBackgroundColorHover,
94-
},
95-
}),
96-
}),
83+
...(disabled && {
84+
...disabledStyle,
85+
':hover': {
86+
borderColor: undefined,
87+
backgroundColor: undefined,
88+
},
89+
}),
9790
}
9891
},
92+
93+
content: ({ props }) => ({
94+
overflow: 'hidden',
95+
...(typeof props.content === 'string' && truncateStyle),
96+
}),
9997
}
10098

10199
export default buttonStyles

src/themes/teams/components/Button/buttonVariables.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export interface IButtonVariables {
66
height: string
77
minWidth: string
88
maxWidth: string
9+
color: string
910
backgroundColor: string
1011
backgroundColorHover: string
1112
circularRadius: string
@@ -25,6 +26,7 @@ export default (siteVars: any): IButtonVariables => {
2526
height: pxToRem(32),
2627
minWidth: pxToRem(96),
2728
maxWidth: pxToRem(280),
29+
color: siteVars.black,
2830
backgroundColor: siteVars.gray08,
2931
backgroundColorHover: siteVars.gray06,
3032
circularRadius: pxToRem(999),

0 commit comments

Comments
 (0)