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

@ngheadlessui/radio

v0.0.3

Published

Radio Groups give you the same functionality as native HTML radio inputs, without any of the styling. They're perfect for building out custom UIs for selectors.

Downloads

2

Readme

ui-radio

Radio Groups give you the same functionality as native HTML radio inputs, without any of the styling. They're perfect for building out custom UIs for selectors.

Demo


Installation

# npm
npm install @ngheadlessui/radio

# Yarn
yarn add @ngheadlessui/radio

# import the lib into module you want to use it in
import { UiRadioModule } from '@ngheadlessui/radio';

Basic Example

Radio Groups are built using the headless-tab-group, and headlessRadioOption components.

Clicking an option will select it, and when the Radio Group is focused, the arrow keys will change the selected option.

<headless-radio-group>
  <!-- You can use the headlessRadioOption as a component -->
  <headlessRadioOption>Option 1</headlessRadioOption>
  <headlessRadioOption>Option 2</headlessRadioOption>
  <headlessRadioOption>Option 3</headlessRadioOption>

  <!--or as a directive -->
  <div headlessRadioOption>Option 1</div>
  <div headlessRadioOption>Option 2</div>
  <div headlessRadioOption>Option 3</div>
</headless-radio-group>

Styling the checked radio item

This is a headless component so there are no styles included by default. Instead, the components expose useful information via bound classes that you can use to apply styles yourself.

To style the checked Radio, use the selected class checked-headless-radio, which tells you which radio is currently checked. For flexiblity.

.checked-headless-radio {
  @apply bg-sky-900 bg-opacity-75 text-white;
}

Disabling a radio item

To disable a radio, use the disabled input property on the headlessRadioOption component. Disabled radio items cannot be selected with the mouse.

<headless-tab-group>
  <headless-radio-group>
    <!-- You can use the headlessRadioOption as a component -->
    <headlessRadioOption [disabled]="true">Option 1</headlessRadioOption>
    <headlessRadioOption>Option 2</headlessRadioOption>
    <headlessRadioOption>Option 3</headlessRadioOption>

    <!--or as a directive -->
    <ng-container *ngFor="let plan of plans">
      <div headlessRadioOption [disabled]="plan.name === 'monthly'">
        {{ plan.name }}
      </div>
    </ng-container>
  </headless-radio-group>
</headless-tab-group>

To style disabled radio, use the disabled class disabled-headless-radio, which tells you whether or not that radio option is currently disabled.

.disabled-headless-radio {
  @apply text-red-300 bg-yellow-700 hover:bg-white/[0.12] hover:text-white;
}

Specifying the default checked radio

To select a radio is checked by default, use the checkedOptionIndex="number" property on the headless-tab-group component.

<headless-radio-group [checkedOptionIndex]="1">
  <headlessRadioOption>Option 1</headlessRadioOption>
  <headlessRadioOption>Option 2</headlessRadioOption>
  <headlessRadioOption>Option 3</headlessRadioOption>
</headless-radio-group>

Listening for changes

To run a function whenever the checked radio changes, listen to emissions from the (changeRadio) EventEmitter on the headless-radio-group component. (changeRadio) emits the index ($event) of the checked radio.

<headless-radio-group (changeRadio)="listenToChangeInRadio($event)">
  <headlessRadioOption>Option 1</headlessRadioOption>
  <headlessRadioOption>Option 2</headlessRadioOption>
  <headlessRadioOption>Option 3</headlessRadioOption>
</headless-radio-group>

Component APIs

headless-radio-group

The main Radio Group component.

| Props | Default | Description | | ------------------ | ------- | --------------------------------------------------------------------------------- | | checkedOptionIndex | 0 | Number The index of checked radio | | (changeRadio) | | EventEmitter This is fired when there is a change in checked radio |

headlessRadioOption

The Radio component.

| Props | Default | Description | | -------- | --------- | ---------------------------------------------------------------------------------- | | id | undefined | String unique identifier of the radio option | | disabled | false | Boolean Whether or not selected of the Rasio option is currently disabled. |