<div class="checkbox-list js-checkbox-list">
    <div class="checkbox-list__toggle js-toggle">
    </div>
    <div class="checkbox-list__list js-list-container">
    </div>
</div>
<div class="checkbox-list js-checkbox-list">
    <div class="checkbox-list__toggle js-toggle">
        {{placeholder}}
    </div>
    <div class="checkbox-list__list js-list-container">
        {{#each options}}
            <div class="checkbox-list__item">
                <label for="{{value}}" class="js-checkbox-item">
                    <input type="checkbox" id="{{value}}" value="{{value}}" data-label="{{label}}">
                    <span>{{label}}</span>
                </label>
            </div>
        {{/each}}
    </div>
</div>
/* No context defined for this component. */
  • Content:
    import './checkbox-list.scss';
    export default class CheckboxList {
        constructor(module, onSelect) {
            this.module = module;
            this.listContainer = module.querySelector('.js-list-container');
            this.toggle = this.module.querySelector('.js-toggle');
            this.onSelect = onSelect;
            this.addListeners();
        }
        addListeners() {
            this.toggle.addEventListener('click', () => {
                const activeList = document.querySelector('.js-list-container.active');
                if (activeList && activeList !== this.listContainer) {
                    activeList.classList.remove('active');
                }
                this.listContainer.classList.toggle('active');
            });
            this.module.querySelectorAll('.js-checkbox-item > input').forEach((item) => {
                item.addEventListener('change', () => {
                    if (this.onSelect) {
                        this.onSelect(item);
                    }
                    this.setActiveToggle();
                });
            });
            this.module.addEventListener('click', (e) => {
                e.stopPropagation();
            });
            document.addEventListener('click', () => {
                this.hide();
            });
        }
        removeItem(value) {
            const activeOption = this.module.querySelector(`.js-checkbox-item > input[value='${value}']`);
            if (activeOption) {
                activeOption.checked = false;
            }
            this.setActiveToggle();
        }
        removeAllItems() {
            this.module.querySelectorAll('.js-checkbox-item > input:checked').forEach((item) => {
                const checkbox = item;
                checkbox.checked = false;
            });
            this.setActiveToggle();
        }
        setActiveToggle() {
            if (this.module.querySelector('.js-checkbox-item > input:checked')) {
                this.toggle.classList.add('active');
            } else {
                this.toggle.classList.remove('active');
            }
        }
        setActiveOption(value) {
            const option = this.module.querySelector(`.js-checkbox-item > input[value='${value}']`);
            if (option) {
                option.checked = true;
            }
            this.setActiveToggle();
        }
        getLabelByValue(value) {
            const option = this.module.querySelector(`.js-checkbox-item > input[value='${value}']`);
            if (option) {
                return option.dataset.label;
            }
            return value;
        }
        hide() {
            if (this.listContainer.classList.contains('active')) {
                this.listContainer.classList.remove('active');
            }
        }
    }
    
  • URL: /components/raw/checkbox-list/checkbox-list.js
  • Filesystem Path: src/patterns/03-components/filters/checkbox-list/checkbox-list.js
  • Size: 2.5 KB
  • Content:
    @import 'src/core/scss/01-settings/_import';
    @import 'src/core/scss/02-tools/_import';
    $cb-box-shadow: rgba(17, 19, 23, .2);
    $cb-option-shadow: rgba(0, 0, 0, .4);
    .checkbox-list {
        position: relative;
        &__toggle {
            @extend %medium-card-description;
            @extend %spacer-xs;
            align-items: center;
            background-color: map-get($colors, 'white');
            border: 1px solid map-get($colors, 'limeade');
            border-radius: 4px;
            color: map-get($colors, 'woodsmoke');
            cursor: pointer;
            display: flex;
            height: rem(43);
            justify-content: space-between;
            padding: rem(10);
            &::after {
                background-image: url('/img/ui/icons/chevron-right-green-light.svg');
                background-size: rem(15) rem(20);
                content: '';
                display: inline-block;
                height: rem(20);
                transform: rotate(90deg);
                width: rem(15);
            }
            &.active {
                background-color: map-get($colors, 'deep-sea');
                box-shadow: inset 0 0 18px $cb-option-shadow;
                color: map-get($colors, 'white');
                &::after {
                    background-image: url('/img/ui/icons/chevron-down-white.svg');
                    transform: none;
                }
            }
        }
        &__list {
            background-color: map-get($colors, 'white');
            border-radius: 5px;
            box-shadow: 0 4px 4px $cb-box-shadow;
            display: none;
            margin-top: rem(19);
            max-height: 330px;
            overflow-y: auto;
            position: absolute;
            top: 100%;
            width: 100%;
            z-index: 1;
            &.active {
                display: block;
            }
        }
        &__item {
            border-bottom: 1px solid map-get($colors, 'gallery');
            display: flex;
            & > label {
                @extend %medium-card-description;
                align-items: center;
                color: map-get($colors, 'boulder');
                cursor: pointer;
                display: flex;
                margin-bottom: 0;
                padding: rem(15);
                & > span {
                    margin-left: rem(10);
                }
            }
            &:hover {
                background-color: map-get($colors, 'alabaster');
                & > label {
                    color: map-get($colors, 'woodsmoke');
                }
            }
        }
    }
    
  • URL: /components/raw/checkbox-list/checkbox-list.scss
  • Filesystem Path: src/patterns/03-components/filters/checkbox-list/checkbox-list.scss
  • Size: 2.3 KB

There are no notes for this item.