tidy up color picker

pull/411/head
Cory LaViska 2021-03-30 08:44:41 -04:00
rodzic 3bd3bdd086
commit c50b57d96b
2 zmienionych plików z 15 dodań i 8 usunięć

Wyświetl plik

@ -9,6 +9,7 @@ _During the beta period, these restrictions may be relaxed in the event of a mis
## Next ## Next
- Fixed a bug where toggling `open` on `sl-drawer` would skip the transition - Fixed a bug where toggling `open` on `sl-drawer` would skip the transition
- Fixed a bug where `sl-color-picker` could be opened when disabled
- Renamed `components.json` to `metadata.json` - Renamed `components.json` to `metadata.json`
- Updated to the prerelease versions of LitElement and lit-html - Updated to the prerelease versions of LitElement and lit-html

Wyświetl plik

@ -1,6 +1,7 @@
import { LitElement, html, unsafeCSS } from 'lit'; import { LitElement, html, unsafeCSS } from 'lit';
import { customElement, property, query, state } from 'lit/decorators'; import { customElement, property, query, state } from 'lit/decorators';
import { classMap } from 'lit-html/directives/class-map'; import { classMap } from 'lit-html/directives/class-map';
import { ifDefined } from 'lit-html/directives/if-defined';
import { styleMap } from 'lit-html/directives/style-map'; import { styleMap } from 'lit-html/directives/style-map';
import { event, EventEmitter, watch } from '../../internal/decorators'; import { event, EventEmitter, watch } from '../../internal/decorators';
import styles from 'sass:./color-picker.scss'; import styles from 'sass:./color-picker.scss';
@ -96,7 +97,7 @@ export default class SlColorPicker extends LitElement {
* An array of predefined color swatches to display. Can include any format the color picker can parse, including * An array of predefined color swatches to display. Can include any format the color picker can parse, including
* HEX(A), RGB(A), HSL(A), and CSS color names. * HEX(A), RGB(A), HSL(A), and CSS color names.
*/ */
@property() swatches = [ @property({ attribute: false }) swatches = [
'#d0021b', '#d0021b',
'#f5a623', '#f5a623',
'#f8e71c', '#f8e71c',
@ -127,7 +128,7 @@ export default class SlColorPicker extends LitElement {
/** Emitted when the color picker closes. Calling `event.preventDefault()` will prevent it from being closed. */ /** Emitted when the color picker closes. Calling `event.preventDefault()` will prevent it from being closed. */
@event('sl-hide') slHide: EventEmitter<void>; @event('sl-hide') slHide: EventEmitter<void>;
/** Emitted after the color picker closes and all transitions are complete. */ /** Emitted after the color picker closes and all transitions are complete. */
@event('sl-after-hide') slAfterHide: EventEmitter<void>; @event('sl-after-hide') slAfterHide: EventEmitter<void>;
connectedCallback() { connectedCallback() {
@ -387,7 +388,12 @@ export default class SlColorPicker extends LitElement {
handleDropdownShow(event: CustomEvent) { handleDropdownShow(event: CustomEvent) {
event.stopPropagation(); event.stopPropagation();
this.slShow.emit();
if (this.disabled) {
event.preventDefault();
} else {
this.slShow.emit();
}
} }
handleDropdownAfterShow(event: CustomEvent) { handleDropdownAfterShow(event: CustomEvent) {
@ -646,7 +652,7 @@ export default class SlColorPicker extends LitElement {
aria-valuetext=${`hsl(${Math.round(this.hue)}, ${Math.round(this.saturation)}%, ${Math.round( aria-valuetext=${`hsl(${Math.round(this.hue)}, ${Math.round(this.saturation)}%, ${Math.round(
this.lightness this.lightness
)}%)`} )}%)`}
tabindex=${this.disabled ? null : '0'} tabindex=${ifDefined(this.disabled ? undefined : '0')}
@keydown=${this.handleGridKeyDown} @keydown=${this.handleGridKeyDown}
></span> ></span>
</div> </div>
@ -671,7 +677,7 @@ export default class SlColorPicker extends LitElement {
aria-valuemin="0" aria-valuemin="0"
aria-valuemax="360" aria-valuemax="360"
aria-valuenow=${Math.round(this.hue)} aria-valuenow=${Math.round(this.hue)}
tabindex=${this.disabled ? null : 0} tabindex=${ifDefined(this.disabled ? undefined : '0')}
@keydown=${this.handleHueKeyDown} @keydown=${this.handleHueKeyDown}
></span> ></span>
</div> </div>
@ -706,7 +712,7 @@ export default class SlColorPicker extends LitElement {
aria-valuemin="0" aria-valuemin="0"
aria-valuemax="100" aria-valuemax="100"
aria-valuenow=${Math.round(this.alpha)} aria-valuenow=${Math.round(this.alpha)}
tabindex=${this.disabled ? null : '0'} tabindex=${ifDefined(this.disabled ? undefined : '0')}
@keydown=${this.handleAlphaKeyDown} @keydown=${this.handleAlphaKeyDown}
></span> ></span>
</div> </div>
@ -767,7 +773,7 @@ export default class SlColorPicker extends LitElement {
<div <div
part="swatch" part="swatch"
class="color-picker__swatch color-picker__transparent-bg" class="color-picker__swatch color-picker__transparent-bg"
tabindex=${this.disabled ? null : '0'} tabindex=${ifDefined(this.disabled ? undefined : '0')}
role="button" role="button"
aria-label=${swatch} aria-label=${swatch}
@click=${() => !this.disabled && this.setColor(swatch)} @click=${() => !this.disabled && this.setColor(swatch)}
@ -795,7 +801,7 @@ export default class SlColorPicker extends LitElement {
class="color-dropdown" class="color-dropdown"
aria-disabled=${this.disabled ? 'true' : 'false'} aria-disabled=${this.disabled ? 'true' : 'false'}
.containing-element=${this} .containing-element=${this}
hoist=${this.hoist} ?hoist=${this.hoist}
@sl-show=${this.handleDropdownShow} @sl-show=${this.handleDropdownShow}
@sl-after-show=${this.handleDropdownAfterShow} @sl-after-show=${this.handleDropdownAfterShow}
@sl-hide=${this.handleDropdownHide} @sl-hide=${this.handleDropdownHide}