color-picker.js 940 B

1234567891011121314151617181920212223242526272829303132333435
  1. import Picker from './picker';
  2. class ColorPicker extends Picker {
  3. constructor(select, label) {
  4. super(select);
  5. this.label.innerHTML = label;
  6. this.container.classList.add('ql-color-picker');
  7. Array.from(this.container.querySelectorAll('.ql-picker-item'))
  8. .slice(0, 7)
  9. .forEach(item => {
  10. item.classList.add('ql-primary');
  11. });
  12. }
  13. buildItem(option) {
  14. const item = super.buildItem(option);
  15. item.style.backgroundColor = option.getAttribute('value') || '';
  16. return item;
  17. }
  18. selectItem(item, trigger) {
  19. super.selectItem(item, trigger);
  20. const colorLabel = this.label.querySelector('.ql-color-label');
  21. const value = item ? item.getAttribute('data-value') || '' : '';
  22. if (colorLabel) {
  23. if (colorLabel.tagName === 'line') {
  24. colorLabel.style.stroke = value;
  25. } else {
  26. colorLabel.style.fill = value;
  27. }
  28. }
  29. }
  30. }
  31. export default ColorPicker;