icon-picker.js 710 B

123456789101112131415161718192021222324
  1. import Picker from './picker';
  2. class IconPicker extends Picker {
  3. constructor(select, icons) {
  4. super(select);
  5. this.container.classList.add('ql-icon-picker');
  6. Array.from(this.container.querySelectorAll('.ql-picker-item')).forEach(
  7. item => {
  8. item.innerHTML = icons[item.getAttribute('data-value') || ''];
  9. },
  10. );
  11. this.defaultItem = this.container.querySelector('.ql-selected');
  12. this.selectItem(this.defaultItem);
  13. }
  14. selectItem(target, trigger) {
  15. super.selectItem(target, trigger);
  16. const item = target || this.defaultItem;
  17. if (this.label.innerHTML === item.innerHTML) return;
  18. this.label.innerHTML = item.innerHTML;
  19. }
  20. }
  21. export default IconPicker;