Skip to content

Commit

Permalink
don't be an idiot, Burke.
Browse files Browse the repository at this point in the history
  • Loading branch information
zburke committed May 14, 2024
1 parent 3b87183 commit fb3aa29
Showing 1 changed file with 28 additions and 18 deletions.
46 changes: 28 additions & 18 deletions lib/Button/Button.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,43 +36,53 @@ const Button = React.forwardRef((
buttonStyle = 'default',
type = 'button',
...rest
},
ref) => {
}, ref) => {
const props = { buttonStyle, type, ...rest };

function getStyle() {
const buttonBuiltIn = [];
if (/\s/.test(buttonStyle)) {
const csslist = buttonStyle.split(/\s+/);
if (/\s/.test(props.buttonStyle)) {
const csslist = props.buttonStyle.split(/\s+/);
csslist.forEach((classname) => { buttonBuiltIn.push(css[classname]); });
} else {
buttonBuiltIn.push(css[buttonStyle]);
buttonBuiltIn.push(css[props.buttonStyle]);
}
return className(
css.button,
buttonBuiltIn,
{ [`${css.marginBottom0}`]: marginBottom0 },
{ [`${css.marginBottom0}`]: bottomMargin0 },
{ [`${css.paddingSide0}`]: paddingSide0 },
{ [`${css.fullWidth}`]: fullWidth },
{ [`${css[`align-${align}`]}`]: align },
buttonClass,
{ [`${css.marginBottom0}`]: props.marginBottom0 },
{ [`${css.marginBottom0}`]: props.bottomMargin0 },
{ [`${css.paddingSide0}`]: props.paddingSide0 },
{ [`${css.fullWidth}`]: props.fullWidth },
{ [`${css[`align-${props.align}`]}`]: props.align },
props.buttonClass,
);
}

function handleAnchorClick(e) {
if (e && !allowAnchorClick) e.preventDefault();
if (onClick) {
onClick(e);
if (e && !props.allowAnchorClick) e.preventDefault();
if (props.onClick) {
props.onClick(e);
}
}

const inputCustom = omitProps(rest, [
const inputCustom = omitProps(props, [
'buttonClass',
'buttonStyle',
'bottomMargin0',
'marginBottom0',
'paddingSide0',
'align',
'hollow',
'fullWidth',
'bsRole',
'bsClass',
'onClick',
'allowAnchorClick',
'buttonRef',
'type',
'to',
]);
const { children, onClick, to, buttonRef } = props;

const sharedProps = {
...inputCustom,
Expand All @@ -97,11 +107,11 @@ const Button = React.forwardRef((

// Render a regular anchor tag
// if the "href" prop is provided
if (href) {
if (props.href) {
return (
<a
role="button"
href={href}
href={props.href}
{...sharedProps}
onClick={handleAnchorClick}
ref={buttonRef || ref}
Expand Down

0 comments on commit fb3aa29

Please sign in to comment.