From 6e5fe64e8b8a3fa622b95cfc50a9a3e913f91969 Mon Sep 17 00:00:00 2001 From: Cory LaViska Date: Tue, 26 Oct 2021 09:35:07 -0400 Subject: [PATCH] add eye dropper --- .../color-picker/color-picker.styles.ts | 5 +- src/components/color-picker/color-picker.ts | 49 ++++++++++++++++--- src/components/icon/library.system.ts | 5 ++ 3 files changed, 51 insertions(+), 8 deletions(-) diff --git a/src/components/color-picker/color-picker.styles.ts b/src/components/color-picker/color-picker.styles.ts index c147832f5..ee302109d 100644 --- a/src/components/color-picker/color-picker.styles.ts +++ b/src/components/color-picker/color-picker.styles.ts @@ -191,11 +191,14 @@ export default css` flex: 1 1 auto; } + .color-picker__user-input sl-button-group { + margin-left: var(--sl-spacing-small); + } + .color-picker__user-input sl-button { min-width: 3.25rem; max-width: 3.25rem; font-size: 1rem; - margin-left: var(--sl-spacing-small); } .color-picker__swatches { diff --git a/src/components/color-picker/color-picker.ts b/src/components/color-picker/color-picker.ts index 24208b326..c99445c7c 100644 --- a/src/components/color-picker/color-picker.ts +++ b/src/components/color-picker/color-picker.ts @@ -13,15 +13,19 @@ import color from 'color'; import styles from './color-picker.styles'; import '../button/button'; +import '../button-group/button-group'; import '../dropdown/dropdown'; import '../icon/icon'; import '../input/input'; +const hasEyeDropper = 'EyeDropper' in window; + /** * @since 2.0 * @status stable * * @dependency sl-button + * @dependency sl-button-group * @dependency sl-dropdown * @dependency sl-input * @@ -570,6 +574,22 @@ export default class SlColorPicker extends LitElement { this.previewButton.classList.remove('color-picker__preview-color--copied'); } + handleEyeDropper() { + if (!hasEyeDropper) { + return; + } + + // @ts-ignore + const eyeDropper = new EyeDropper(); + + eyeDropper + .open() + .then((colorSelectionResult: any) => this.setColor(colorSelectionResult.sRGBHex)) + .catch(() => { + // The user canceled, do nothing + }); + } + @watch('format') handleFormatChange() { this.syncValues(); @@ -606,6 +626,7 @@ export default class SlColorPicker extends LitElement { const x = this.saturation; const y = 100 - this.lightness; + // TODO - i18n for format, copy, and eye dropper buttons const colorPicker = html`
- ${!this.noFormatToggle - ? html` - - ${this.setLetterCase(this.format)} - - ` - : ''} + + ${!this.noFormatToggle + ? html` + + ${this.setLetterCase(this.format)} + + ` + : ''} + ${hasEyeDropper + ? html` + + + + ` + : ''} +
${this.swatches diff --git a/src/components/icon/library.system.ts b/src/components/icon/library.system.ts index 008e4cb98..0de597c84 100644 --- a/src/components/icon/library.system.ts +++ b/src/components/icon/library.system.ts @@ -41,6 +41,11 @@ const icons = { `, + eyedropper: ` + + + + `, 'grip-vertical': `