UNPKG

@esri/calcite-components

Version:

Web Components for Esri's Calcite Design System.

5 lines (4 loc) 3.06 kB
/*! All material copyright ESRI, All Rights Reserved, unless otherwise specified. See https://github.com/Esri/calcite-design-system/blob/dev/LICENSE.md for details. v3.2.1 */ import{a as C,r as m}from"./TGDV7BPX.js";import"./YSI7ZYDZ.js";import{a as y}from"./YXZ62PQO.js";import{d as z}from"./3ADX47DD.js";import"./NNVH7JUI.js";import{E as S,F as a,R as k,c as f,d as $,e as h,h as t}from"./BJZTU5BQ.js";var l={swatch:"swatch",noColorSwatch:"swatch--no-color",checker:"checker"},x={borderLight:"rgba(0, 0, 0, 0.3)",borderDark:"rgba(255, 255, 255, 0.15)"},b=4,i={squareSize:b,size:b*2},q=f`:host{position:relative;display:inline-flex}:host([scale=s]){block-size:1.25rem;inline-size:1.25rem}:host([scale=m]){block-size:1.5rem;inline-size:1.5rem}:host([scale=l]){block-size:2rem;inline-size:2rem}.swatch{overflow:hidden;block-size:inherit;inline-size:inherit}.swatch rect{transition-property:all;transition-duration:.15s;transition-timing-function:cubic-bezier(.4,0,.2,1)}.swatch--no-color rect{fill:var(--calcite-color-foreground-1)}.swatch--no-color line{stroke:var(--calcite-color-status-danger)}.checker{fill:#cacaca}:host([hidden]){display:none}[hidden]{display:none}`,w=class extends S{constructor(){super(...arguments),this.active=!1,this.scale="m"}static{this.properties={active:[7,{},{reflect:!0,type:Boolean}],color:1,scale:[3,{},{reflect:!0}]}}static{this.styles=q}load(){this.handleColorChange(this.color)}willUpdate(e){e.has("color")&&this.handleColorChange(this.color)}handleColorChange(e){this.internalColor=e?C(e):null}render(){let e=!this.internalColor,c={[l.swatch]:!0,[l.noColorSwatch]:e};return $`<svg class=${a(c)} xmlns=http://www.w3.org/2000/svg>${this.renderSwatch()}</svg>`}renderSwatch(){let{active:e,el:c,internalColor:s}=this,o=e?"100%":"0",n=z(c)==="light"?x.borderLight:x.borderDark,d=!s,r={height:"100%",rx:o,stroke:n,strokeWidth:"2",width:"100%"};if(d)return h`<clipPath id=shape><rect height=100% rx=${o??t} width=100% /></clipPath>${this.renderSwatchRect({clipPath:`inset(0 round ${o})`,...r})}<line clip-path=url(#shape) stroke-width=3 x1=100% x2=0 y1=0 y2=100% />`;let p=s.alpha(),v=m(s),g=m(s,p<1);return h`<title>${g}</title><defs><pattern height=${i.size} id=checker patternUnits=userSpaceOnUse width=${i.size} x=0 y=0><rect class=${a(l.checker)} height=${i.squareSize} width=${i.squareSize} x=0 y=0 /><rect class=${a(l.checker)} height=${i.squareSize} width=${i.squareSize} x=${i.squareSize} y=${i.squareSize} /></pattern></defs>${this.renderSwatchRect({fill:"url(#checker)",rx:r.rx,height:r.height,width:r.width})}${this.renderSwatchRect({clipPath:p<1?"polygon(100% 0, 0 0, 0 100%)":`inset(0 round ${o})`,fill:v,...r})}${p<1?this.renderSwatchRect({clipPath:"polygon(100% 0, 100% 100%, 0 100%)",fill:g,key:"opacity-fill",...r}):null}`}renderSwatchRect({clipPath:e,fill:c,height:s,key:o,rx:u,stroke:n,strokeWidth:d,width:r}){return y(o,h`<rect clip-path=${e??t} fill=${c??t} height=${s??t} rx=${u??t} stroke=${n??t} stroke-width=${d??t} width=${r??t} />`)}};k("calcite-color-picker-swatch",w);export{w as ColorPickerSwatch};