spectrum_picker.ts 801 B

123456789101112131415161718192021222324
  1. /**
  2. * Wrapper for the new ngReact <color-picker> directive for backward compatibility.
  3. * Allows remaining <spectrum-picker> untouched in outdated plugins.
  4. * Technically, it's just a wrapper for react component with two-way data binding support.
  5. */
  6. import coreModule from '../core_module';
  7. /** @ngInject */
  8. export function spectrumPicker() {
  9. return {
  10. restrict: 'E',
  11. require: 'ngModel',
  12. scope: true,
  13. replace: true,
  14. template: '<color-picker color="ngModel.$viewValue" on-change="onColorChange"></color-picker>',
  15. link: (scope: any, element: any, attrs: any, ngModel: any) => {
  16. scope.ngModel = ngModel;
  17. scope.onColorChange = (color: string) => {
  18. ngModel.$setViewValue(color);
  19. };
  20. },
  21. };
  22. }
  23. coreModule.directive('spectrumPicker', spectrumPicker);