diff --git a/ui/src/shared/components/ConfirmButton.js b/ui/src/shared/components/ConfirmButton.js new file mode 100644 index 0000000000..e21ec19eaa --- /dev/null +++ b/ui/src/shared/components/ConfirmButton.js @@ -0,0 +1,74 @@ +import React, {Component, PropTypes} from 'react' + +import OnClickOutside from 'shared/components/OnClickOutside' + +class ConfirmButton extends Component { + constructor(props) { + super(props) + + this.state = { + expanded: false, + } + } + + handleButtonClick = () => { + if (this.props.disabled) { + return + } + this.setState({expanded: !this.state.expanded}) + } + + handleConfirmClick = () => { + this.setState({expanded: false}) + this.props.confirmAction() + } + + handleClickOutside() { + this.setState({expanded: false}) + } + + render() { + const {text, confirmText, type, size, square, icon, disabled} = this.props + const {expanded} = this.state + + const classname = `confirm-button btn ${type} ${size}${square + ? ' btn-square' + : ''}${disabled ? ' disabled' : ''}${expanded ? ' expanded' : ''}` + + return ( +
+ {icon && } + {text && text} +
+
+ {confirmText} +
+
+
+ ) + } +} + +const {bool, func, string} = PropTypes + +ConfirmButton.defaultProps = { + confirmText: 'Confirm', + type: 'btn-default', + size: 'btn-sm', + square: true, +} +ConfirmButton.propTypes = { + text: string, + confirmText: string, + confirmAction: func.isRequired, + type: string, + size: string, + square: bool, + icon: string, + disabled: bool, +} + +export default OnClickOutside(ConfirmButton) diff --git a/ui/src/style/chronograf.scss b/ui/src/style/chronograf.scss index 5a377d739c..4e83cface2 100644 --- a/ui/src/style/chronograf.scss +++ b/ui/src/style/chronograf.scss @@ -28,9 +28,10 @@ // Components @import 'components/ceo-display-options'; -@import 'components/confirm-buttons'; @import 'components/code-mirror-theme'; @import 'components/color-dropdown'; +@import 'components/confirm-button'; +@import 'components/confirm-buttons'; @import 'components/custom-time-range'; @import 'components/dygraphs'; @import 'components/fancy-scrollbars'; diff --git a/ui/src/style/components/confirm-button.scss b/ui/src/style/components/confirm-button.scss new file mode 100644 index 0000000000..4cca85ea05 --- /dev/null +++ b/ui/src/style/components/confirm-button.scss @@ -0,0 +1,57 @@ +/* + Confirm Button + ---------------------------------------------------------------------------- + This button requires a second click to confirm the action +*/ + +.confirm-button { + .confirm-button--tooltip { + visibility: hidden; + transition: all; + position: absolute; + top: calc(100% + 8px); + left: 50%; + transform: translateX(-50%); + } +} +.confirm-button--confirmation { + border-radius: 3px; + background-color: $c-curacao; + opacity: 0; + padding: 0 7px; + color: $g20-white; + font-size: 13px; + font-weight: 600; + text-align: center; + transition: + opacity 0.25s ease, + background-color 0.25s ease; + + &:after { + content: ''; + border: 8px solid transparent; + border-bottom-color: $c-curacao; + position: absolute; + bottom: 100%; + left: 50%; + transform: translateX(-50%); + transition: border-color 0.25s ease; + z-index: 100; + } + + &:hover { + background-color: $c-dreamsicle; + cursor: pointer; + } + &:hover:after { + border-bottom-color: $c-dreamsicle; + } +} +.confirm-button.expanded { + .confirm-button--tooltip { + visibility: visible; + } + .confirm-button--confirmation { + opacity: 1; + } +}