src/Button.ts

   1/**

   2 * # Button Widget

   3 * A simple button widget

   4 * 

   5 * ### Profile

   6 * invoked as `m(Button, {name:, onclick:});`

   7 * 

   8 * ### Attributes (node.attrs):

   9 * - `onclick:() => void` function to execute when button is clicked

  10 * - `name: string` name to show as button text

  11 * - `css: string` css class to assign to button tag

  12 * - `style: string` style string to apply to button tag

  13 * 

  14 * ### Example

  15 * 

  16 * 'script.js'>

  17 * let clicked = 0;

  18 * 

  19 * m.mount(root, {view: () => m('.hs-white', [

  20 *    m('h4''Please click:'),

  21 *    m(hsWidget.Button, { desc: {

  22 *        name: 'click me',

  23 *        clicked: () => clicked++

  24 *    }}),

  25 * ])});

  26 * 

  27 * 

  28 * 

  29 */

  30

  31/** */

  32import { Vnode }     from 'hslayout';

  33import { ToggleButton } from './ToggleButton';

  34

  35/**

  36 * # Button Widget

  37 * A simple button widget

  38 * 

  39 * ### Profile

  40 * invoked as `m(Button, {name:, onclick:});`

  41 * 

  42 * ### Attributes (node.attrs):

  43 * attribtues as defined in {@link ToggleButton.ToggleButton `ToggleButton`}, 

  44 * except for `items`, which are replaced by 

  45 * - `name: string` name to show as button text (in lieu of `items`)

  46 * - `clicked:() => void` function to execute when button is clicked

  47 */

  48export class Button extends ToggleButton {

  49    oninit(node: Vnode) {

  50        node.attrs.desc.items = [node.attrs.desc.name || 'button'];

  51        super.oninit(node);

  52        ToggleButton.ensureSelected(node);

  53    }

  54}

  55

  56