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

add possibility to override Button Height #44

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions lib/Button.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ export default class Button extends Component {
overrides: PropTypes.shape({
textColor: PropTypes.string,
backgroundColor: PropTypes.string,
rippleColor: PropTypes.string
rippleColor: PropTypes.string,
height: PropTypes.number,
}),
disabled: PropTypes.bool,
raised: PropTypes.bool,
Expand All @@ -24,7 +25,7 @@ export default class Button extends Component {
theme: 'light',
primary: PRIMARY,
disabled: false,
raised: false
raised: false,
};

constructor(props) {
Expand Down Expand Up @@ -152,15 +153,19 @@ export default class Button extends Component {
})();

const buttonStyle = (() => {
const heightStyle = (overrides && overrides.height) ? { height: overrides.height } : null;

if (raised) {
buttonStyleMap[shape][theme][type] = Object.assign(buttonStyleMap[shape][theme][type], heightStyle);

if (disabled || !(overrides && overrides.backgroundColor)) {
return buttonStyleMap[shape][theme][type];
}

return Object.assign(buttonStyleMap[shape][theme][type], { backgroundColor: getColor(overrides.backgroundColor) });
return Object.assign(buttonStyleMap[shape][theme][type], { backgroundColor: getColor(overrides.backgroundColor), height: overrides.height });
}

return null;
return heightStyle;
})();

const rippleColor = (() => {
Expand All @@ -177,7 +182,8 @@ export default class Button extends Component {
style={[
styles.button,
buttonStyle, {
backgroundColor: buttonStyle && buttonStyle.backgroundColor
backgroundColor: buttonStyle && buttonStyle.backgroundColor,
height: buttonStyle && buttonStyle.height,
}
]}
>
Expand All @@ -199,6 +205,7 @@ export default class Button extends Component {
styles.button,
buttonStyle, {
backgroundColor: buttonStyle && buttonStyle.backgroundColor,
height: buttonStyle && buttonStyle.height,
}, raised && !isCompatible('elevation') && {
borderWidth: 1,
borderColor: 'rgba(0,0,0,.12)'
Expand All @@ -224,6 +231,7 @@ export default class Button extends Component {
styles.button,
buttonStyle, {
backgroundColor: buttonStyle && buttonStyle.backgroundColor,
height: buttonStyle && buttonStyle.height,
elevation: raised ? elevation : 0
}]}
>
Expand All @@ -250,4 +258,4 @@ const styles = {
position: 'relative',
top: 2
}
};
};