open-vault/ui/app/components/confirm-action.js
Noelle Daley eed91ba84d
Add storybook (#6496)
* add storybook

* add storybook files

* add ToggleButton and AlertBanner stories

* add knobs addon

* add notes addon

* add ToggleButton and AlertsBanner notes

* move panel to right

* add ICon

* create story blueprint

* add header to blueprint

* upgrade to storybook 5.0.1

* add confirm-action stories

* move addon panel to bottom

* update ConfirmAction

* add jsdoc comments to alert banner component

* add AlertInline

* set showPanel to true in blueprint

* include newly generated markdown for stories

* adjust code example for toggle button

* add json-to-markdown to package.json

* update AuthForm

* add Storybook readme

* add AlertPopup

* add story markdown custom template

* make storybook dependencies optional

* center all stories

* use message-types helper to dynamically render alerts

* hide panel

* nest alert stories

* move icons into table

* separate homelink into multiple stories

* add homelink with nav example

* remove see links from alert-banner

* add script to autogenerate markdown from component and add it to stories

* add viewport addon and remove centered addon

* update README to include markdown generation

* remove @see links from jsdoc comments

* update README to include jsdoc example

* update alert banner md

* get rid of trailing ######

* update jsdoc and regenerate notes files

* update i-con md

* Update ui/scripts/gen-story-md.js

Co-Authored-By: noelledaley <noelledaley@users.noreply.github.com>

* Update ui/scripts/gen-story-md.js

Co-Authored-By: noelledaley <noelledaley@users.noreply.github.com>

* add storybook docs to vault ui readme

* add jsdoc comments to component blueprint, automatically import md file in story blueprint

* add template template to component blueprint override

* apply basic theme to storybook

* remove comment

* make sure all stories are using auto generated md

* storybook: show optional props in brackets

* storybook: 🔪 HomeLink

* storybook: show AuthConfigForm stories with knobs
2019-04-03 14:06:20 -07:00

80 lines
2.7 KiB
JavaScript

import Component from '@ember/component';
import hbs from 'htmlbars-inline-precompile';
/**
* @module ConfirmAction
* `ConfirmAction` is a button followed by a confirmation message and button used to prevent users from performing actions they do not intend to.
*
* @example
* ```js
* <ConfirmAction
* @onConfirmAction={{ () => { console.log('Action!') } }}
* @confirmMessage="Are you sure you want to delete this config?">
* Delete
* </ConfirmAction>
* ```
*
* @property {Func} onConfirmAction=null - The action to take upon confirming.
* @property {String} [confirmMessage=Are you sure you want to do this?] - The message to display upon confirming.
* @property {String} [confirmButtonText=Delete] - The confirm button text.
* @property {String} [cancelButtonText=Cancel] - The cancel button text.
* @property {String} [disabledMessage=Complete the form to complete this action] - The message to display when the button is disabled.
*
*/
export default Component.extend({
tagName: 'span',
classNames: ['confirm-action'],
layout: hbs`
{{#if showConfirm ~}}
<span class={{containerClasses}}>
<span class={{concat 'confirm-action-text ' messageClasses}}>{{if disabled disabledMessage confirmMessage}}</span>
<button {{action 'onConfirm'}} disabled={{disabled}} class={{confirmButtonClasses}} type="button" data-test-confirm-button=true>{{confirmButtonText}}</button>
<button {{action 'toggleConfirm'}} type="button" class={{cancelButtonClasses}} data-test-confirm-cancel-button=true>{{cancelButtonText}}</button>
</span>
{{else}}
<button
class={{buttonClasses}}
type="button"
disabled={{disabled}}
data-test-confirm-action-trigger=true
{{action 'toggleConfirm'}}
>
{{yield}}
</button>
{{~/if}}
`,
disabled: false,
disabledMessage: 'Complete the form to complete this action',
showConfirm: false,
messageClasses: 'is-size-8 has-text-grey',
confirmButtonClasses: 'is-danger is-outlined button',
containerClasses: '',
buttonClasses: 'button',
buttonText: 'Delete',
confirmMessage: 'Are you sure you want to do this?',
confirmButtonText: 'Delete',
cancelButtonClasses: 'button',
cancelButtonText: 'Cancel',
// the action to take when we confirm
onConfirmAction: null,
actions: {
toggleConfirm() {
this.toggleProperty('showConfirm');
},
onConfirm() {
const confirmAction = this.get('onConfirmAction');
if (typeof confirmAction !== 'function') {
throw new Error('confirm-action components expects `onConfirmAction` attr to be a function');
} else {
confirmAction();
this.toggleProperty('showConfirm');
}
},
},
});