mithril-ui-form-rating-plugin
TypeScript icon, indicating that this package has built-in type declarations

0.7.4 • Public • Published

A rating plugin for Mithril-ui-form

Mithril-ui-form is a declarative framwork to create forms using the front-end Mithril framework and mithril-materialized components using the materialize-css design theme.

A simple rating control, i.e. a horizontal list of radio buttons, with optional labels for each item.

Include rating control

import { ratingPlugin } from "mithril-ui-form-rating-plugin";

...

registerPlugin("rating", ratingPlugin);

Optional CSS style

Please include the following CSS style to make it look good.

.muf-rating {
  width: 100%;
  padding: 0.5rem 0;
  display: flex;
  justify-content: flex-start;
  align-items: flex-end;
}
.muf-rating > .label {
  width: 50%;
}
.muf-rating > .radios {
  width: 50%;
  display: flex;
  justify-content: space-evenly;
  align-items: flex-end;
}
.muf-rating > .radios > label {
  display: inline-block;
  padding: 0 0.1rem 1rem 0.1rem;
  text-align: center;
}
.muf-rating > .radios > label > input[type='radio'] {
  opacity: 1; /* only needed when using materialize-css */
}

Example usage

Example

{ 
  "id": "my_rating", 
  "type": "rating",
  "label": "What do you think of this plugin?",
  "description": "_Please, be honest!_",
  "min": 0,
  "max": 5,
  "ratings": {
    "0": "extremely<br>bad",
    "5": "super<br>good"
  }
},

Or you can use the alternative syntax, so it is easier to switch between options and select. Just make sure that the options's id property is a number (or a number converted to a string, e.g. "42").

{
    "id": "hasIndDiff",
    "label": "Has individual differences?",
    "type": "rating",
    "options": [
      {
        "id": 1,
        "label": "None"
      },
      {
        "id": 2,
        "label": "Unknown"
      },
      {
        "id": 3,
        "label": "Yes"
      }
    ],
    "className": "col s12"
  },

Package Sidebar

Install

npm i mithril-ui-form-rating-plugin

Weekly Downloads

5

Version

0.7.4

License

MIT

Unpacked Size

41.9 kB

Total Files

12

Last publish

Collaborators

  • erikvullings