UNPKG

@umbraco-ui/uui-ref

Version:

Umbraco UI ref component

237 lines (216 loc) 6.48 kB
import { LitElement, css } from 'lit'; import { defineElement } from '@umbraco-ui/uui-base/lib/registration'; import { property } from 'lit/decorators.js'; import { SelectOnlyMixin, SelectableMixin } from '@umbraco-ui/uui-base/lib/mixins'; import { UUIEvent } from '@umbraco-ui/uui-base/lib/events'; class UUIRefEvent extends UUIEvent { static { this.OPEN = "open"; } } var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __decorateClass = (decorators, target, key, kind) => { var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target; for (var i = decorators.length - 1, decorator; i >= 0; i--) if (decorator = decorators[i]) result = (kind ? decorator(target, key, result) : decorator(result)) || result; if (kind && result) __defProp(target, key, result); return result; }; let UUIRefElement = class extends SelectOnlyMixin( SelectableMixin(LitElement) ) { constructor() { super(...arguments); this.disabled = false; this.readonly = false; this.error = false; } handleOpenClick(e) { e.stopPropagation(); this.dispatchEvent(new UUIRefEvent(UUIRefEvent.OPEN)); } handleOpenKeydown(e) { if (e.key !== " " && e.key !== "Enter") return; e.preventDefault(); e.stopPropagation(); this.dispatchEvent(new UUIRefEvent(UUIRefEvent.OPEN)); } }; UUIRefElement.styles = [ css` :host { position: relative; display: flex; justify-content: space-between; align-items: center; width: 100%; font-size: var(--uui-font-size); box-sizing: border-box; border-radius: var(--uui-border-radius,3px); background-color: var(--uui-color-surface,#fff); --uui-card-before-opacity: 0; transition: --uui-card-before-opacity 120ms; } :host([selectable]:focus-visible) { outline-color: var(--uui-color-focus,#3879ff); outline-width: var(--uui-card-border-width); outline-style: solid; outline-offset: var(--uui-card-border-width); } :host([error]) { border: 1px solid var(--uui-color-invalid,#c31d4c); } :host([standalone]) { border: 1px solid var(--uui-color-border,#d8d7d9); } :host([selectable]) { cursor: pointer; } :host([selectable]) #select-border { position: absolute; z-index: 2; top: -2px; left: -2px; right: -2px; bottom: -2px; pointer-events: none; opacity: 0; transition: opacity 120ms; } :host([selectable]) #select-border::after { content: ''; position: absolute; width: 100%; height: 100%; box-sizing: border-box; border: 2px solid var(--uui-color-selected,#3544b1); border-radius: calc(var(--uui-border-radius,3px) + 2px); box-shadow: 0 0 4px 0 var(--uui-color-selected,#3544b1), inset 0 0 2px 0 var(--uui-color-selected,#3544b1); } :host([selected]) #select-border { opacity: 1; } :host([selectable]:not([selected]):hover) #select-border { opacity: 0.33; } :host([selectable][selected]:hover) #select-border { opacity: 0.8; } :host([selectable]:not([selected])) #open-part:hover + #select-border { opacity: 0; } :host([selectable][selected]) #open-part:hover + #select-border { opacity: 1; } :host([selectable]:not([selected]):hover) #select-border::after { animation: not-selected--hover 1.2s infinite; } @keyframes not-selected--hover { 0%, 100% { opacity: 0.66; } 50% { opacity: 1; } } :host([selectable][selected]:hover) #select-border::after { animation: selected--hover 1.4s infinite; } @keyframes selected--hover { 0%, 100% { opacity: 1; } 50% { opacity: 0.66; } } :host([selectable]) #open-part:hover + #select-border::after { animation: none; } :host([select-only]) *, :host([select-only]) ::slotted(*) { pointer-events: none; } button { font-size: inherit; font-family: inherit; border: 0; padding: 0; background-color: transparent; text-align: left; color: var(--uui-color-text,#060606); } a { text-decoration: none; color: inherit; } button:focus, a:focus { outline-offset: var(--uui-card-border-width); border-radius: var(--uui-border-radius,3px); outline: 2px solid var(--uui-color-focus,#3879ff); } slot[name='actions']::slotted(*) { --uui-button-height: calc(var(--uui-size-2,6px) * 4); } slot[name='actions']::slotted(*:first-child) { margin-right: var(--uui-size-2,6px); } slot[name='actions'] { display: flex; align-items: center; } #tag-container::slotted(*:first-child) { margin: calc(var(--uui-size-2,6px)); } #actions-container::slotted(*:first-child) { margin: calc(var(--uui-size-2,6px)); } #actions-container { opacity: 0; transition: opacity 120ms; } :host(:hover) #actions-container, :host(:focus) #actions-container, :host(:focus-within) #actions-container { opacity: 1; } :host([standalone]:not([disabled]):hover) { border-color: var(--uui-color-border-emphasis,#a1a1a1); } :host([disabled]) #open-part { cursor: default; } :host([standalone][disabled]) { border-color: var(--uui-color-disabled-standalone,rgb( 226, 226, 226 )); } slot[name='tag'] { display: flex; justify-content: flex-end; align-items: center; } ` ]; __decorateClass([ property({ type: Boolean, reflect: true }) ], UUIRefElement.prototype, "disabled", 2); __decorateClass([ property({ type: Boolean, reflect: true }) ], UUIRefElement.prototype, "readonly", 2); __decorateClass([ property({ type: Boolean, reflect: true }) ], UUIRefElement.prototype, "error", 2); UUIRefElement = __decorateClass([ defineElement("uui-ref") ], UUIRefElement); export { UUIRefElement, UUIRefEvent };