UNPKG

@dracoui/ember

Version:

Draco Design System for Ember

3 lines (2 loc) 2.9 kB
import{_ as t,b as o,a as e}from"../../../../_rollupPluginBabelHelpers-CLoDr8uC.js";import r from"truncate";import{assert as s}from"@ember/debug";import{action as i}from"@ember/object";import{tracked as n}from"@glimmer/tracking";import c from"../../button/index.js";import{DracoCopySnippetStatusValues as a}from"./types.js";import{DracoButtonColorValues as p}from"../../button/types.js";import{precompileTemplate as u}from"@ember/template-compilation";import{setComponentTemplate as l}from"@ember/component";var m,h,y,d=u('<Draco::Button\n @size={{this.size}}\n @color={{this.color}}\n title={{@textToCopy}}\n class={{this.classNames}}\n @isFullWidth={{this.isFullWidth}}\n aria-label={{concat "copy " @textToCopy}}\n {{draco-clipboard\n text=@textToCopy\n onSuccess=this.onSuccess\n onError=this.onError}}\n ...attributes\n>\n <span class="draco-copy-snippet__text">\n {{this.textToShow}}\n </span>\n\n <Draco::Icon\n @size={{14}}\n @name={{this.icon}}\n class="draco-copy-snippet__icon draco-copy-snippet__icon--{{this._status}}"\n />\n</Draco::Button>');const b=p.Tertiary,f=a.Idle,g=Object.values(p).filter((t=>[p.Primary,p.Secondary,p.Tertiary].includes(t)));let _=(h=t((m=class extends c{constructor(...t){super(...t),o(this,"componentName","Draco::Copy::Snippet"),e(this,"_timer",h,this),e(this,"_status",y,this)}get textToShow(){const{textToCopy:t=""}=this.args,o="string"==typeof t?t:t.toString();return this.isTruncated?r(o,14):o}get icon(){const t={[a.Error]:"lucide:clipboard-x",[a.Idle]:"lucide:clipboard-copy",[a.Success]:"lucide:clipboard-check"};return t[this._status]??t[f]}get color(){const t=this.args.color||this.args.variant||this.args.type||b;return s(`@color for "${this.componentName}" must be one of the following: ${g.join(", ")}; received: ${t}`,g.includes(t)),t}get isTruncated(){return this.args.isTruncated??!0}get classNames(){const t=["draco-copy-snippet"];return t.push(`draco-copy-snippet--status-${this._status}`),this.isTruncated&&t.push("draco-copy-snippet--truncated"),t.join(" ")}onSuccess(t){this._status=a.Success,this.resetStatusDelayed();const{onSuccess:o}=this.args;"function"==typeof o&&o(t)}onError(t){this._status=a.Error,this.resetStatusDelayed();const{onError:o}=this.args;"function"==typeof o&&o(t)}resetStatusDelayed(){clearTimeout(this._timer),this._timer=setTimeout((()=>{this._status=f}),1500)}}).prototype,"_timer",[n],{configurable:!0,enumerable:!0,writable:!0,initializer:null}),y=t(m.prototype,"_status",[n],{configurable:!0,enumerable:!0,writable:!0,initializer:function(){return f}}),t(m.prototype,"onSuccess",[i],Object.getOwnPropertyDescriptor(m.prototype,"onSuccess"),m.prototype),t(m.prototype,"onError",[i],Object.getOwnPropertyDescriptor(m.prototype,"onError"),m.prototype),m);l(d,_);export{g as AVAILABLE_COLORS,b as DEFAULT_COLOR,f as DEFAULT_STATUS,_ as default}; //# sourceMappingURL=index.js.map