# Facet

facet buttons.

## CSS

Include the SCSS in your application

```scss
// Pick ONE of the brands below to include
@import '@springernature/facet/default';
@import '@springernature/facet/nature';

// Include this with your other components
@import '@springernature/facet/facet';
@import '@springernature/facet/facet-expander';
```

## Example usage

```html
<div class="c-facet" data-facet>
    <!-- example of checkbox input -->
    <div class="c-facet__container">
        <fieldset class="c-facet__item">
            <legend>
                <span class="c-facet__label">Subject</span>
                <span class="u-hide u-js-show">
                    <button type="button" class="c-facet__button c-facet__button--border" data-facet-expander data-facet-target="#subject-target">
                        <svg class="c-facet__icon" role="img" aria-hidden="true" focusable="false" viewBox="0 0 16 16" xmlns="http://www.w3.org/2000/svg">...</svg>
                    </button>
                </span>
            </legend>

            <div id="subject-target" data-test="subject-target" class="c-facet-expander u-js-hide">
                <ul class="c-facet-expander__list">
                    <li class="c-facet-expander__list-item">
                        <input type="checkbox" name="subject" id="subject-1" value="1"/>
                        <label class="c-facet-expander__link" for="subject-1">
                            <span>Subject 1</span>
                        </label>
                    </li>
                </ul>
            </div>
        </fieldset>

        <!-- example of radio input -->
        <fieldset class="c-facet__item">
            <legend>
                <span class="c-facet__label">Date</span>
                <span class="u-hide u-js-show">
                <button type="button" class="c-facet__button c-facet__button--border" data-facet-expander data-facet-target="#date-target">
                    <svg class="c-facet__icon" role="img" aria-hidden="true" focusable="false" viewBox="0 0 16 16" xmlns="http://www.w3.org/2000/svg">...</svg>
                </button>
            </span>
            </legend>

            <div id="date-target" class="c-facet-expander u-js-hide">
                <ul class="c-facet-expander__list">
                    <li class="c-facet-expander__list-item">
                        <input name="date_range" id="date-range-1" value="1" type="radio"/>
                        <label class="c-facet-expander__link" for="date-range-1">
                            <span>Date 1</span>
                        </label>
                    </li>
                </ul>
            </div>
        </fieldset>
    </div>
</div>
```

### Enhanced facet

The enhanced facet makes use of [expander](https://github.com/springernature/elements/blob/master/themes/springernature/js/README.md#expander)
and [makeArray](https://github.com/springernature/elements/blob/master/themes/springernature/js/README.md##makearray) from the `theme`.

`id` in expander container should match `href` in trigger for enhanced-facet to find and append to facet item.

Updates button text to indicate what is selected or how many items are selected after form submit.

Adds additional form controls to apply and clear selections in the expander.

## Polyfills

This module uses `Element.closest()`.
