narsenico / a-color-picker

A color picker for web app
MIT License
107 stars 21 forks source link

Property 'on' does not exist on type 'ACPController[]'. #22

Open peiris opened 5 years ago

peiris commented 5 years ago

I'm trying to integrate this with a StencilJs component. I have the below code.

componentDidLoad() {
    AColorPicker.from('.kp-color-generator__form__color-chip', {
      color: this.defaultColorHex,
      palette: 'PALETTE_MATERIAL_CHROME'
    }).on('change', (picker) => {
      this.defaultColorHex = picker.color;
    });
  }

But Stencil build fails with a warning as below, with a highlight for .on(

TypeScript: src/components/kp-color-generator/kp-color-generator.tsx:24:8
           Property 'on' does not exist on type 'ACPController[]'.

     L23:    palette: 'PALETTE_MATERIAL_CHROME'
     L24:  }).on('change', (picker) => {
     L25:    this.defaultColorHex = picker.color;
narsenico commented 5 years ago

Hi @peiris try to use .createPicker instead of .from. The method .from returns an array of ACPController and for some reason Stencil doesn't recognize on/off. Instead .createPicker returns just one ACPController instance.