ui-kit
Version:
user interface kit
94 lines (80 loc) • 3.52 kB
text/jade
:doc
Shows menu immediately when rendered
UIConfirm
{String} cancelLabel - Label for cancel button
{String} [cancelKeybinding='esc'] - Keyboard key that will trigger cancel, can be set to a falsey value
{String} confirmLabel - Label for confirm button
{String} [confirmKeybinding='enter'] - Keyboard key that will trigger confirm, can be set to a falsey value
{String} [message] - Optional String, but puts buttons at the bottom of the menu
{String} [position] Inherits Flyout:position
{Function} [onCancelClick] - Called when cancel, or close button (if shown) is clicked
{Function} [onConfirmClick] - Called when confirm is clicked
{Function} [onHide] - Called any time this menu hides (including onConfirmClick)
{String} [type='delete'] - Types supported are delete or confirm
import {attachKeybindings, removeKeybindings} from '../../utils/keybinding.js'
import Flyout from '../../controls/flyout'
import './index.ess'
var classFn = this.composeClasses('UIConfirm', {'type-@':props.type, 'has-message': !!props.message})
Flyout(
className=classFn()
hideMenuKeybinding=props.cancelKeybinding
onShow=this.onShow
onHide=this.onHide
onKeybindingPress=this.onKeybindingPress
onWindowClickHide=this.onCancelClick
position=props.position
scrollToMenu=props.scrollToMenu
scrollToMenuOptions=props.scrollToOptions
showMenuOnLoad)
block menu(actions)
if (props.message)
div(className=classFn('UIConfirm-message'))
=props.message
div(className=classFn('UIConfirm-button-container'))
button(className=(classFn('UIConfirm-button', {'confirm': true})) autoFocus onClick=this.onConfirmClick.bind(null, actions.hide))
div(className=(classFn('UIConfirm-button-content')))
div(className=(classFn('UIConfirm-button-label')))
= props.confirmLabel
button(className=(classFn('UIConfirm-button', {'cancel': true})) onClick=this.onCancelClick.bind(null, actions.hide))
div(className=(classFn('UIConfirm-button-content')))
div(className=(classFn('UIConfirm-button-label')))
= props.cancelLabel
div(className=(classFn('UIConfirm-close-icon')) onClick=this.onCancelClick.bind(null, actions.hide))
:module
export var mixins = [require('../../mixins/compose-classes')]
export function getDefaultProps() {
return {
cancelKeybinding: 'esc',
cancelLabel: 'cancel',
confirmKeybinding: 'enter',
confirmLabel: 'confirm',
type: 'delete'
}
}
export function componentWillUnmount () {
removeKeybindings(this.props.confirmKeybinding, this.onEnterPress);
}
export function onCancelClick (hideDropdown) {
if (hideDropdown) hideDropdown();
if (this.props.onCancelClick) this.props.onCancelClick();
}
export function onConfirmClick (hideDropdown) {
if (hideDropdown) hideDropdown();
if (this.props.onConfirmClick) this.props.onConfirmClick();
}
export function onShow () {
if (!this.props.confirmKeybinding) return;
setTimeout(() => {
attachKeybindings(this.props.confirmKeybinding, this.onEnterPress);
}, 200);
}
export function onHide () {
if (this.props.onHide) this.props.onHide();
removeKeybindings(this.props.confirmKeybinding, this.onEnterPress);
}
export function onEnterPress () {
this.onConfirmClick();
}
export function onKeybindingPress (action) {
if (action === 'hide') this.onCancelClick();
}