logo polydile dile-components

dile-radio-group

Web Components to create a customizable radio buttons interface.

There are two components in this package:

Installation

npm i @dile/dile-radio-group

Usage

Import the components.

import '@dile/dile-radio-group/dile-radio-group.js';
import '@dile/dile-radio-group/dile-radio.js';

Use the components.

<dile-radio-group name="interested" label="Are you interested in this subject?">
  <dile-radio label="Yes" value="yes"></dile-radio>
  <dile-radio label="Some interested" value="some"></dile-radio>
  <dile-radio label="Not at all" value="not"></dile-radio>
</dile-radio-group>

Properties

For dile-radio-group component

For dile-radio component

Custom events

dile-radio-group custom events

dile-radio custom events

CSS Custom Properties

Custom propertyDescriptionDefault
--dile-input-label-font-sizeFont size for the label1em
--dile-input-label-colorColor for the label text#59e
--dile-input-label-font-weightLabel text font weightnormal
--dile-input-label-margin-bottomLabel marging bottom4px
--dile-radio-disabled-icon-colorColor for the icon when it is disabled#ccc
--dile-radio-space-between-label-and-iconSeparation label on radios0.4rem
--dile-radio-icon-sizeRadio icon size1.2rem
--dile-radio-icon-colorRadio icon color#303030
--dile-radio-label-font-sizeRadio label text size1rem
--dile-radio-label-colorRadio label text color#303030
--dile-radio-selected-icon-colorRadio icon color--dile-radio-icon-color or #303030
--dile-radio-selected-label-colorRadio label selected text color--dile-radio-label-color or #303030

dile-radio-group demos

Default dile-radio-group

class MyComponent extends LitElement {

  render() {
    return html`
      <dile-radio-group id="group" name="interested" label="Are you interested in this subject?">
        <dile-radio label="Yes" value="yes"></dile-radio>
        <dile-radio label="Some interested" value="some"></dile-radio>
        <dile-radio label="Not at all" value="not"></dile-radio>
      </dile-radio-group>
      <p id="message">Select one value</p>
    `
  }
  firstUpdated() {
    this.shadowRoot.getElementById('group').addEventListener('dile-radio-group-changed', (e) => {
      this.shadowRoot.getElementById('message').innerText = 'Element ' + e.detail.name + ' has value: ' + e.detail.value;
    });
  }
}
customElements.define('my-component', MyComponent);
export const JsStory = () => html`<my-component></my-component>`;

Value initialized

<dile-radio-group value="red" name="favorite-color" label="Select your favorite color">
  <dile-radio label="Yellow" value="yellow"></dile-radio>
  <dile-radio label="Red" value="red"></dile-radio>
  <dile-radio label="Green" value="Green"></dile-radio>
</dile-radio-group>

Disabled radio buttons

<dile-radio-group name="transport" label="Prefered transport" disabled>
  <dile-radio label="Car" value="car"></dile-radio>
  <dile-radio label="Bus" value="bus"></dile-radio>
</dile-radio-group>

Styled radio buttons

<style>
.styled {
  --dile-input-label-color: #114611;
  --dile-input-label-font-weight: bold;
  --dile-radio-icon-color: #20e073; 
  --dile-radio-selected-icon-color: #0c758c; 
  --dile-radio-label-font-size: 1.2rem;
  --dile-radio-icon-size: 28px;
  --dile-radio-label-color: #288ea5;
  --dile-radio-selected-label-color: #184a2e;
}
.styled dile-radio {
  margin: 0.4rem 0;
}
</style>
<dile-radio-group name="transport" label="Prefered transport" class="styled">
  <dile-radio label="Car" value="car"></dile-radio>
  <dile-radio label="Bus" value="bus"></dile-radio>
  <dile-radio label="Train" value="train"></dile-radio>
</dile-radio-group>