pebble / clay

Pebble Config Framework
MIT License
120 stars 29 forks source link

Allow items to be in multiple groups #159

Open dmorgan81 opened 6 years ago

dmorgan81 commented 6 years ago

If items are in multiple groups interesting custom function possibilities are opened up. For example, a section could have a toggle that shows/hides all other items in that section. With multiple groups attaching that behavior to all special toggles becomes something like this:

Clay.getItemsByGroup('section-toggle').forEach(function(toggle) {
    var groups = toggle.config.groups;
    if (!groups) return;
    groups = groups.filter(function(group) { return group !== 'section-toggle'; });
    toggle.on('change', function() {
        var enabled = this.get();
        groups.forEach(function(group) {
            Clay.getItemsByGroup(group)
                .filter(function(item) { return item !== toggle; })
                .forEach(function(item) {
                    if (enabled) item.show();
                    else item.hide();
            });
        });
    }).trigger('change');
});

Resolves #160