Filter | jaspr_daisyui_components
jaspr_daisyui_components
pub.dev ↗

Filter

Filter is a group of radio buttons. Choosing one of the options will hide the others and shows a reset button next to the chosen option.

Class name Type Description
filter Component For a HTML <form> or a <div> element that includes radio buttons for filtering items
filter-reset Part An alternative to the reset button if you can't use a HTML form

Filter using HTML form, radio buttons and reset button

A HTML form for filtering items
<form class="filter">
  <input class="btn btn-square" type="reset" value="×" />
  <input class="btn" type="radio" name="frameworks" aria-label="Svelte" />
  <input class="btn" type="radio" name="frameworks" aria-label="Vue" />
  <input class="btn" type="radio" name="frameworks" aria-label="React" />
</form>
Filter(
  [
    input(classes: 'btn btn-square', type: InputType.reset, value: '×'),
    input(
      classes: 'btn',
      type: InputType.radio,
      name: 'frameworks',
      attributes: {'aria-label': 'Svelte'},
    ),
    input(
      classes: 'btn',
      type: InputType.radio,
      name: 'frameworks',
      attributes: {'aria-label': 'Vue'},
    ),
    input(
      classes: 'btn',
      type: InputType.radio,
      name: 'frameworks',
      attributes: {'aria-label': 'React'},
    ),
  ],
);

Filter without HTML form

Use this if you can't use a HTML form for some reason
<div class="filter">
  <input class="btn filter-reset" type="radio" name="metaframeworks" aria-label="All" />
  <input class="btn" type="radio" name="metaframeworks" aria-label="Sveltekit" />
  <input class="btn" type="radio" name="metaframeworks" aria-label="Nuxt" />
  <input class="btn" type="radio" name="metaframeworks" aria-label="Next.js" />
</div>
div(
  [
    FilterReset(
      const [],
      classes: 'btn',
      type: 'radio',
      name: 'metaframeworks',
      attributes: {'aria-label': 'All'},
    ),
    input(
      classes: 'btn',
      type: InputType.radio,
      name: 'metaframeworks',
      attributes: {'aria-label': 'Sveltekit'},
    ),
    input(
      classes: 'btn',
      type: InputType.radio,
      name: 'metaframeworks',
      attributes: {'aria-label': 'Nuxt'},
    ),
    input(
      classes: 'btn',
      type: InputType.radio,
      name: 'metaframeworks',
      attributes: {'aria-label': 'Next.js'},
    ),
  ],
  classes: 'filter',
);

Filter using HTML form, checkboxes, and a reset button

For having multiple choices, use checkboxes.
<form class="filter">
  <input class="btn" type="checkbox" name="frameworks" aria-label="Svelte" />
  <input class="btn" type="checkbox" name="frameworks" aria-label="Vue" />
  <input class="btn" type="checkbox" name="frameworks" aria-label="React" />
  <input class="btn btn-square" type="reset" value="×" />
</form>
Filter(
  [
    input(
      classes: 'btn',
      type: InputType.checkbox,
      name: 'frameworks',
      attributes: {'aria-label': 'Svelte'},
    ),
    input(
      classes: 'btn',
      type: InputType.checkbox,
      name: 'frameworks',
      attributes: {'aria-label': 'Vue'},
    ),
    input(
      classes: 'btn',
      type: InputType.checkbox,
      name: 'frameworks',
      attributes: {'aria-label': 'React'},
    ),
    input(classes: 'btn btn-square', type: InputType.reset, value: '×'),
  ],
);