src/Label.ts

   1/**

   2 * # Label Widget

   3 * Shows a text label

   4 * 

   5 * ### Profile

   6 * invoked as `m(Label, {text:});`

   7 * 

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

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

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

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

  12 * 

  13 * ### Example

  14 * 

  15 * 'script.js'> 

  16 * m.mount(root, {view: () => m(hsWidget.Label, {

  17 *      css: '.myLabel'

  18 *      style: 'text-align: right;',

  19 *      text: 'This is a label'

  20 * })});

  21 * 

  22 * 'style.css'>

  23 * .myLabel {  

  24 *    background-color: white; 

  25 *    margin: 5px;

  26 * }

  27 * 

  28 * 

  29 * 

  30 */

  31

  32/** */

  33import { m, Vnode }     from 'hslayout';

  34

  35/**

  36 * # Label 

  37 * A text label

  38 * 

  39 * ### Profile

  40 * invoked as `m(Label, {text:});`

  41 * 

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

  43 * - `text?: string` the label text; 

  44 */

  45export class Label {

  46    view(node: Vnode): Vnode { 

  47        const css = node.attrs.css || '';

  48        const style = node.attrs.style || '';

  49        const text  = node.attrs.text || 'unspecified';

  50        return m(`.hs-label ${css}`, { style:style }, m.trust(text)); 

  51    }

  52}

  53

  54