npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

coherent-gameface-radio-button

v3.3.1

Published

A component for Coherent Labs Gameface.

Downloads

92

Readme

The radio-button is part of the Gameface custom components suite.

Installation

npm i coherent-gameface-radio-button

Usage with UMD:

<script src="./node_modules/coherent-gameface-radio-button/dist/coherent-gameface-radio-button.production.min.js"></script>
  • add the radio-button group and button custom Elements to your html:
<gameface-radio-group>
	<radio-button slot="radio-button"></radio-button>
	<radio-button slot="radio-button"></radio-button>
</gameface-radio-group>

Configuration and usage is explained further down the document.

Usage with JavaScript:

If you wish to import the GamefaceRadioGroup using JavaScript you can remove the script tag and import it like this:

import { GamefaceRadioGroup } from 'coherent-gameface-radio-button';

or simply

import 'coherent-gameface-radio-button';

Note that this approach requires a module bundler like Webpack or Rollup to resolve the modules from the node_modules folder.

Add the Styles

<link rel="stylesheet" href="coherent-gameface-components-theme.css">
<link rel="stylesheet" href="style.css">

To overwrite the default styles, simply create new rules for the class names that you wish to change and include them after the default styles.

Load the HTML file in Gameface to see the radio-button. You can also see an example in the demo folder of the component.

Configuration and Usage

Radio Group Attributes

The gameface-radio-group element support the following attributes:

|Attribute |Type |Default | Description | |---|---|---|---| |value | String |N/A | The value of the selected radio button | |disabled | Boolean |false | Whether the whole group is disabled or not | |value | String | 'on' | The value that will be returned from the .value getter | |name | String | '' | The name of the component|

Radio Button Attributes

You can customize the radio button using the following attributes:

|Attribute |Type |Default | Description | |---|---|---|---| |checked | Boolean |false | Whether the component is checked or not | |disabled | Boolean |false | Whether the component is disabled or not | |controls-disabled | Boolean HTML Attribute |false | If present - hides the controls of the buttons, making it possible to add your custom | |value | String | 'on' | The value that will be returned from the .value getter | |name | String | '' | The name of the component|

Initial Setup

You can configure the <radio-button>'s initial state declaratively by setting the attributes in the HTML:

<gameface-radio-group>
	<radio-button slot="radio-button" disabled>Tab Targeting</radio-button>
	<radio-button slot="radio-button" checked value="yes" name="subtitles">Action Combat</radio-button>
</gameface-radio-group>

Updating the Attributes

You can update the attributes using JavaScript or the DOM APIs.

With JavaScript:

document.querySelector('gameface-radio-group').allButtons[0].<attribute> = <value>;

Where
<attribute> ::= disabled | checked | value | name
<value> ::= true | false | string

Custom Buttons

You can add different styles for the radio buttons. Put the custom elements in the radio-button-content slot:

<gameface-radio-group class="custom-buttons">
    <radio-button slot="radio-button" checked>
        <div slot="radio-button-content" class="inner-button"><span>OFF</span></div>
    </radio-button>
    <radio-button slot="radio-button">
        <div slot="radio-button-content" class="inner-button"><span>ON</span></div>
    </radio-button>
</gameface-radio-group>

You can put HTML elements or other components in the radio-button-content slot.

Add the controls-disabled attribute to the <radio-button> element to hide the default radio button style:

<gameface-radio-group class="custom-buttons">
    <radio-button checked controls-disabled>
        <div slot="radio-button-content">OFF</div>
    </radio-button>
    <radio-button controls-disabled>
        <div slot="radio-button-content">ON</div>
    </radio-button>
</gameface-radio-group>

Usage

On top of using the radioButton.checked and radioButton.checked you can get one of the <gameface-radio-group> Elements and call radioGroup.allButtons which will return an Array of all <radio-button> Elements.

When a radio-button has a checked attribute, this will be the initially checked button.

Mouse focusing works as well as keyboard navigation and focusing using the arrow keys and Enter or Space keys.

To select a <radio-button> using code, you can do the following:

const radioGroup = document.querySelector('gameface-radio-group');
radioGroup.value = {{SOME_RADIO_BUTTON_VALUE}};

If the value you've set doesn't match any of the available radio button values it will return a warning.

Checking Previous or Next Button

You can select adjacent <radio-button> elements using the <gameface-radio-group> methods: checkPrev() and checkNext().

If there are one or more following elements with the disabled attribute, the methods will check the next available one.

To select the previous or next available <radio-button>, you can do the following:

const radioGroup = document.querySelector('gameface-radio-group');
radioGroup.checkNext();
//or
radioGroup.checkPrev();

If there are no available elements to select, the currently checked one will remain selected.