color-picker.js 922 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. [].slice.call(this.container.querySelectorAll('.ql-picker-item'), 0, 7).forEach(function(item) {
  8. item.classList.add('ql-primary');
  9. });
  10. }
  11. buildItem(option) {
  12. let item = super.buildItem(option);
  13. item.style.backgroundColor = option.getAttribute('value') || '';
  14. return item;
  15. }
  16. selectItem(item, trigger) {
  17. super.selectItem(item, trigger);
  18. let colorLabel = this.label.querySelector('.ql-color-label');
  19. let value = item ? item.getAttribute('data-value') || '' : '';
  20. if (colorLabel) {
  21. if (colorLabel.tagName === 'line') {
  22. colorLabel.style.stroke = value;
  23. } else {
  24. colorLabel.style.fill = value;
  25. }
  26. }
  27. }
  28. }
  29. export default ColorPicker;