Skip to content

Commit

Permalink
Integrate button icon variations into button_icon.js. Integrate butto…
Browse files Browse the repository at this point in the history
…n variations inbot button.js.

- Rename classes prop to className.
  • Loading branch information
cjcenizal committed Mar 28, 2017
1 parent 68e14a2 commit efa0a26
Show file tree
Hide file tree
Showing 9 changed files with 84 additions and 130 deletions.
20 changes: 0 additions & 20 deletions ui_framework/components/button/basic_button.js

This file was deleted.

63 changes: 55 additions & 8 deletions ui_framework/components/button/button.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, {
Component,
PropTypes,
} from 'react';

Expand Down Expand Up @@ -28,7 +29,7 @@ const KuiButton = props => {
props.onClick(props.data);
}

const classes = classNames('kuiButton', props.classes, {
const className = classNames('kuiButton', props.className, {
'kuiButton--iconText': props.icon || props.iconRight,
});

Expand All @@ -42,19 +43,34 @@ const KuiButton = props => {
);
}

const elementType = props.isSubmit ? 'input' : props.href ? 'a' : 'button';
const elementType =
props.isSubmit
? 'input'
: props.href
? 'a'
: 'button';

const children =
props.isSubmit
? null
: (
<span>
{props.icon}
{wrappedChildren}
{props.iconRight}
</span>
);

return React.createElement(elementType, {
'data-test-subj': props.testSubject,
className: classes,
className,
href: props.href,
target: props.target,
type: props.isSubmit ? 'submit' : null,
disabled: props.isDisabled,
onClick,
value: props.isSubmit ? props.children : null,
children: props.isSubmit ? null : [props.icon, wrappedChildren, props.iconRight],
});
}, children);
};

KuiButton.propTypes = {
Expand All @@ -63,18 +79,49 @@ KuiButton.propTypes = {
icon: PropTypes.node,
iconRight: PropTypes.node,
children: PropTypes.node,
type: PropTypes.string,
isSubmit: PropTypes.bool,
href: PropTypes.string,
target: PropTypes.string,
onClick: PropTypes.func,
isDisabled: PropTypes.bool,
hasIcon: PropTypes.bool,
classes: PropTypes.oneOfType([
className: PropTypes.oneOfType([
PropTypes.string,
PropTypes.array,
PropTypes.object,
]),
};

export { KuiButton };
function createButtonVariation(hardCodedProps) {
const ButtonVariation = props => {
return React.createElement(KuiButton, Object.assign({}, props, hardCodedProps));
};

ButtonVariation.propTypes = Object.assign({}, KuiButton.propTypes);

return ButtonVariation;
}

const KuiBasicButton = createButtonVariation({
className: 'kuiButton--basic',
});

const KuiHollowButton = createButtonVariation({
className: 'kuiButton--hollow',
});

const KuiDangerButton = createButtonVariation({
className: 'kuiButton--danger',
});

const KuiPrimaryButton = createButtonVariation({
className: 'kuiButton--primary',
});

export {
KuiButton,
KuiBasicButton,
KuiHollowButton,
KuiDangerButton,
KuiPrimaryButton,
};
43 changes: 14 additions & 29 deletions ui_framework/components/button/button_icon.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,44 +6,29 @@ import classNames from 'classnames';
import keyMirror from 'keymirror';

const KuiButtonIcon = props => {
const typeToIconClassMap = {
[KuiButtonIcon.TYPE.CREATE]: 'fa-plus',
[KuiButtonIcon.TYPE.DELETE]: 'fa-trash',
[KuiButtonIcon.TYPE.PREVIOUS]: 'fa-chevron-left',
[KuiButtonIcon.TYPE.NEXT]: 'fa-chevron-right',
};

let iconType;

if (props.type) {
iconType = typeToIconClassMap[props.type];

if (iconType === undefined) {
throw new Error(`KuiButtonIcon type not defined: ${props.type}`);
}
}

const iconClasses = classNames(
'kuiButton__icon kuiIcon',
iconType,
props.classes,
props.className,
);

return (
<span className={iconClasses} />
);
};

KuiButtonIcon.TYPE = keyMirror({
CREATE: null,
DELETE: null,
PREVIOUS: null,
NEXT: null,
});

KuiButtonIcon.propTypes = {
type: PropTypes.string,
classes: PropTypes.string,
className: PropTypes.string,
};

export { KuiButtonIcon };
const KuiCreateButtonIcon = () => <KuiButtonIcon className="fa-plus" />;
const KuiDeleteButtonIcon = () => <KuiButtonIcon className="fa-trash" />;
const KuiPreviousButtonIcon = () => <KuiButtonIcon className="fa-chevron-left" />;
const KuiNextButtonIcon = () => <KuiButtonIcon className="fa-chevron-right" />;

export {
KuiButtonIcon,
KuiCreateButtonIcon,
KuiDeleteButtonIcon,
KuiPreviousButtonIcon,
KuiNextButtonIcon,
};
20 changes: 0 additions & 20 deletions ui_framework/components/button/danger_button.js

This file was deleted.

20 changes: 0 additions & 20 deletions ui_framework/components/button/hollow_button.js

This file was deleted.

7 changes: 2 additions & 5 deletions ui_framework/components/button/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
export { KuiBasicButton } from './basic_button';
export * from './button';
export * from './button_icon';
export { KuiButtonGroup } from './button_group';
export { KuiButtonIcon } from './button_icon';
export { KuiDangerButton } from './danger_button';
export { KuiHollowButton } from './hollow_button';
export { KuiPrimaryButton } from './primary_button';
20 changes: 0 additions & 20 deletions ui_framework/components/button/primary_button.js

This file was deleted.

7 changes: 4 additions & 3 deletions ui_framework/doc_site/src/views/button/button_group_united.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import React from 'react';
import {
KuiBasicButton,
KuiButtonGroup,
KuiButtonIcon,
KuiNextButtonIcon,
KuiPreviousButtonIcon,
} from '../../../../components';

export default () => (
Expand All @@ -23,8 +24,8 @@ export default () => (
<br />

<KuiButtonGroup isUnited>
<KuiBasicButton icon={<KuiButtonIcon type={KuiButtonIcon.TYPE.PREVIOUS} />}/>
<KuiBasicButton iconRight={<KuiButtonIcon type={KuiButtonIcon.TYPE.NEXT} />}/>
<KuiBasicButton icon={<KuiPreviousButtonIcon />}/>
<KuiBasicButton iconRight={<KuiNextButtonIcon />}/>
</KuiButtonGroup>
</div>
);
14 changes: 9 additions & 5 deletions ui_framework/doc_site/src/views/button/button_with_icon.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,40 @@ import React from 'react';
import {
KuiBasicButton,
KuiButtonIcon,
KuiCreateButtonIcon,
KuiDangerButton,
KuiDeleteButtonIcon,
KuiNextButtonIcon,
KuiPreviousButtonIcon,
KuiPrimaryButton,
} from '../../../../components';

export default () => (
<div>
<KuiPrimaryButton icon={<KuiButtonIcon type={KuiButtonIcon.TYPE.CREATE} />}>
<KuiPrimaryButton icon={<KuiCreateButtonIcon />}>
Create
</KuiPrimaryButton>

<br />

<KuiDangerButton icon={<KuiButtonIcon type={KuiButtonIcon.TYPE.DELETE} />}>
<KuiDangerButton icon={<KuiDeleteButtonIcon />}>
Delete
</KuiDangerButton>

<br />

<KuiBasicButton icon={<KuiButtonIcon type={KuiButtonIcon.TYPE.PREVIOUS} />}>
<KuiBasicButton icon={<KuiPreviousButtonIcon />}>
Previous
</KuiBasicButton>

<br />

<KuiBasicButton iconRight={<KuiButtonIcon type={KuiButtonIcon.TYPE.NEXT} />}>
<KuiBasicButton iconRight={<KuiNextButtonIcon />}>
Next
</KuiBasicButton>

<br />

<KuiBasicButton icon={<KuiButtonIcon classes="fa-plane" />}/>
<KuiBasicButton icon={<KuiButtonIcon className="fa-plane" />}/>
</div>
);

0 comments on commit efa0a26

Please sign in to comment.