UNPKG

wired-elements

Version:

Collection of hand-drawn sketchy web components

104 lines (103 loc) 3.36 kB
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __metadata = (this && this.__metadata) || function (k, v) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); }; import { WiredBase, BaseCSS } from './wired-base'; import { ellipse } from './wired-lib'; import { css, html } from 'lit'; import { customElement, property, query } from 'lit/decorators.js'; let WiredIconButton = class WiredIconButton extends WiredBase { constructor() { super(...arguments); this.disabled = false; } static get styles() { return [ BaseCSS, css ` :host { display: inline-block; font-size: 14px; } path { transition: transform 0.05s ease; } button { position: relative; user-select: none; border: none; background: none; font-family: inherit; font-size: inherit; cursor: pointer; letter-spacing: 1.25px; text-transform: uppercase; text-align: center; padding: 10px; color: inherit; outline: none; border-radius: 50%; } button[disabled] { opacity: 0.6 !important; background: rgba(0, 0, 0, 0.07); cursor: default; pointer-events: none; } button:active path { transform: scale(0.97) translate(1.5%, 1.5%); } button:focus path { stroke-width: 1.5; } button::-moz-focus-inner { border: 0; } button ::slotted(*) { position: relative; font-size: var(--wired-icon-size, 24px); } ` ]; } render() { return html ` <button ?disabled="${this.disabled}"> <slot @slotchange="${this.wiredRender}"></slot> <div id="overlay"> <svg></svg> </div> </button> `; } canvasSize() { if (this.button) { const size = this.button.getBoundingClientRect(); return [size.width, size.height]; } return this.lastSize; } draw(svg, size) { const min = Math.min(size[0], size[1]); svg.setAttribute('width', `${min}`); svg.setAttribute('height', `${min}`); ellipse(svg, min / 2, min / 2, min, min, this.seed); } }; __decorate([ property({ type: Boolean, reflect: true }), __metadata("design:type", Object) ], WiredIconButton.prototype, "disabled", void 0); __decorate([ query('button'), __metadata("design:type", HTMLButtonElement) ], WiredIconButton.prototype, "button", void 0); WiredIconButton = __decorate([ customElement('wired-icon-button') ], WiredIconButton); export { WiredIconButton };