-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create Button React components in UI Framework.
- Loading branch information
Showing
31 changed files
with
577 additions
and
208 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import React from 'react'; | ||
import classNames from 'classnames'; | ||
|
||
import { KuiButton } from './button'; | ||
|
||
const KuiBasicButton = props => { | ||
const classes = classNames('kuiButton--basic', props.classes); | ||
|
||
const extendedProps = Object.assign({}, props, { | ||
classes, | ||
}); | ||
|
||
return ( | ||
<KuiButton {...extendedProps} /> | ||
); | ||
}; | ||
|
||
KuiBasicButton.propTypes = Object.assign({}, KuiButton.propTypes); | ||
|
||
export { KuiBasicButton }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import React, { | ||
PropTypes, | ||
} from 'react'; | ||
|
||
import classNames from 'classnames'; | ||
import keyMirror from 'keymirror'; | ||
|
||
const KuiButton = props => { | ||
if (props.isSubmit) { | ||
// input is a void element tag and can't have children. | ||
if (typeof props.children !== 'string' || props.icon || props.rightIcon) { | ||
throw new Error( | ||
`KuiButton with isSubmit prop set to true can only accept string children, and can't | ||
display icons. This is because input is a void element and can't contain children.` | ||
); | ||
} | ||
} | ||
|
||
function onClick() { | ||
// onClick is optional, so exit early if it doesn't exist. | ||
if (!props.onClick) { | ||
return; | ||
} | ||
// Don't even trigger the onClick handler if we're disabled. | ||
if (props.isDisabled) { | ||
return; | ||
} | ||
props.onClick(props.data); | ||
} | ||
|
||
const classes = classNames('kuiButton', props.classes, { | ||
'kuiButton--iconText': props.icon || props.iconRight, | ||
}); | ||
|
||
let wrappedChildren; | ||
|
||
if (props.children) { | ||
// We need to wrap the text so that the icon's :first-child etc. seudo-selectors get applied | ||
// correctly. | ||
wrappedChildren = ( | ||
<span>{props.children}</span> | ||
); | ||
} | ||
|
||
const elementType = props.isSubmit ? 'input' : props.href ? 'a' : 'button'; | ||
|
||
return React.createElement(elementType, { | ||
'data-test-subj': props.testSubject, | ||
className: classes, | ||
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], | ||
}); | ||
}; | ||
|
||
KuiButton.propTypes = { | ||
testSubject: PropTypes.string, | ||
data: PropTypes.any, | ||
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([ | ||
PropTypes.string, | ||
PropTypes.array, | ||
PropTypes.object, | ||
]), | ||
}; | ||
|
||
export { KuiButton }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import React, { | ||
PropTypes, | ||
} from 'react'; | ||
|
||
import classNames from 'classnames'; | ||
|
||
const KuiButtonGroup = props => { | ||
const classes = classNames('kuiButtonGroup', { | ||
'kuiButtonGroup--united': props.isUnited, | ||
}); | ||
|
||
return ( | ||
<div className={classes}> | ||
{props.children} | ||
</div> | ||
); | ||
}; | ||
|
||
KuiButtonGroup.propTypes = { | ||
children: PropTypes.node, | ||
isUnited: PropTypes.bool, | ||
}; | ||
|
||
export { KuiButtonGroup }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import React, { | ||
PropTypes, | ||
} from 'react'; | ||
|
||
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, | ||
); | ||
|
||
return ( | ||
<span className={iconClasses} /> | ||
); | ||
}; | ||
|
||
KuiButtonIcon.TYPE = keyMirror({ | ||
CREATE: null, | ||
DELETE: null, | ||
PREVIOUS: null, | ||
NEXT: null, | ||
}); | ||
|
||
KuiButtonIcon.propTypes = { | ||
type: PropTypes.string, | ||
classes: PropTypes.string, | ||
}; | ||
|
||
export { KuiButtonIcon }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import React from 'react'; | ||
import classNames from 'classnames'; | ||
|
||
import { KuiButton } from './button'; | ||
|
||
const KuiDangerButton = props => { | ||
const classes = classNames('kuiButton--danger', props.classes); | ||
|
||
const extendedProps = Object.assign({}, props, { | ||
classes, | ||
}); | ||
|
||
return ( | ||
<KuiButton {...extendedProps} /> | ||
); | ||
}; | ||
|
||
KuiDangerButton.propTypes = Object.assign({}, KuiButton.propTypes); | ||
|
||
export { KuiDangerButton }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import React from 'react'; | ||
import classNames from 'classnames'; | ||
|
||
import { KuiButton } from './button'; | ||
|
||
const KuiHollowButton = props => { | ||
const classes = classNames('kuiButton--hollow', props.classes); | ||
|
||
const extendedProps = Object.assign({}, props, { | ||
classes, | ||
}); | ||
|
||
return ( | ||
<KuiButton {...extendedProps} /> | ||
); | ||
}; | ||
|
||
KuiHollowButton.propTypes = Object.assign({}, KuiButton.propTypes); | ||
|
||
export { KuiHollowButton }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export { KuiBasicButton } from './basic_button'; | ||
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'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import React from 'react'; | ||
import classNames from 'classnames'; | ||
|
||
import { KuiButton } from './button'; | ||
|
||
const KuiPrimaryButton = props => { | ||
const classes = classNames('kuiButton--primary', props.classes); | ||
|
||
const extendedProps = Object.assign({}, props, { | ||
classes, | ||
}); | ||
|
||
return ( | ||
<KuiButton {...extendedProps} /> | ||
); | ||
}; | ||
|
||
KuiPrimaryButton.propTypes = Object.assign({}, KuiButton.propTypes); | ||
|
||
export { KuiPrimaryButton }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './button'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import React from 'react'; | ||
|
||
import { | ||
KuiBasicButton, | ||
} from '../../../../components'; | ||
|
||
export default () => ( | ||
<div> | ||
<KuiBasicButton> | ||
Basic button | ||
</KuiBasicButton> | ||
|
||
<br /> | ||
|
||
<KuiBasicButton isDisabled> | ||
Basic button, disabled | ||
</KuiBasicButton> | ||
</div> | ||
); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import React from 'react'; | ||
|
||
import { | ||
KuiDangerButton, | ||
} from '../../../../components'; | ||
|
||
export default () => ( | ||
<div> | ||
<KuiDangerButton> | ||
Danger button | ||
</KuiDangerButton> | ||
|
||
<br /> | ||
|
||
<KuiDangerButton isDisabled> | ||
Danger button, disabled | ||
</KuiDangerButton> | ||
</div> | ||
|
||
); |
Oops, something went wrong.