kopia lustrzana https://github.com/shoelace-style/shoelace
tidy up color picker
rodzic
3bd3bdd086
commit
c50b57d96b
|
@ -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
|
||||||
|
|
||||||
|
|
|
@ -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',
|
||||||
|
@ -387,8 +388,13 @@ export default class SlColorPicker extends LitElement {
|
||||||
|
|
||||||
handleDropdownShow(event: CustomEvent) {
|
handleDropdownShow(event: CustomEvent) {
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
|
|
||||||
|
if (this.disabled) {
|
||||||
|
event.preventDefault();
|
||||||
|
} else {
|
||||||
this.slShow.emit();
|
this.slShow.emit();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
handleDropdownAfterShow(event: CustomEvent) {
|
handleDropdownAfterShow(event: CustomEvent) {
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
|
@ -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}
|
||||||
|
|
Ładowanie…
Reference in New Issue