@iqmo/browser
Version:
Browser Stlite
10 lines (9 loc) • 11.2 kB
JavaScript
import{c0 as h,ci as ie,cj as m,r as s,ck as v}from"./index-C9lG8Cnd.js";var w=Object.freeze({default:"default",toggle:"toggle",toggle_round:"toggle"}),ne=Object.freeze({top:"top",right:"right",bottom:"bottom",left:"left"});function _(e,o){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var t=Object.getOwnPropertySymbols(e);o&&(t=t.filter(function(l){return Object.getOwnPropertyDescriptor(e,l).enumerable})),r.push.apply(r,t)}return r}function S(e){for(var o=1;o<arguments.length;o++){var r=arguments[o]!=null?arguments[o]:{};o%2?_(Object(r),!0).forEach(function(t){U(e,t,r[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):_(Object(r)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))})}return e}function U(e,o,r){return o in e?Object.defineProperty(e,o,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[o]=r,e}function ae(e){var o=e.$disabled,r=e.$checked,t=e.$error,l=e.$isIndeterminate,i=e.$theme,n=e.$isFocusVisible,a=i.colors;return o?a.tickFillDisabled:r||l?"transparent":t?a.borderNegative:n?a.borderSelected:a.tickBorder}function ce(e){var o=e.$labelPlacement,r=o===void 0?"":o,t=e.$theme,l=t.sizing,i=l.scale300,n;switch(r){case"top":n="Bottom";break;case"bottom":n="Top";break;case"left":n="Right";break;default:case"right":n="Left";break}return t.direction==="rtl"&&n==="Left"?n="Right":t.direction==="rtl"&&n==="Right"&&(n="Left"),U({},"padding".concat(n),i)}function le(e){var o=e.$disabled,r=e.$checked,t=e.$isIndeterminate,l=e.$error,i=e.$isHovered,n=e.$isActive,a=e.$theme,c=a.colors;return o?r||t?c.tickFillDisabled:c.tickFill:l&&(t||r)?n?c.tickFillErrorSelectedHoverActive:i?c.tickFillErrorSelectedHover:c.tickFillErrorSelected:l?n?c.tickFillErrorHoverActive:i?c.tickFillErrorHover:c.tickFillError:t||r?n?c.tickFillSelectedHoverActive:i?c.tickFillSelectedHover:c.tickFillSelected:n?c.tickFillActive:i?c.tickFillHover:c.tickFill}function se(e){var o=e.$disabled,r=e.$theme,t=r.colors;return o?t.contentSecondary:t.contentPrimary}var L=h("label",function(e){var o=e.$disabled,r=e.$labelPlacement;return{flexDirection:r==="top"||r==="bottom"?"column":"row",display:"flex",alignItems:r==="top"||r==="bottom"?"center":"flex-start",cursor:o?"not-allowed":"pointer",userSelect:"none"}});L.displayName="Root",L.displayName="Root";var j=h("span",function(e){var o=e.$checked,r=e.$disabled,t=e.$error,l=e.$isIndeterminate,i=e.$theme,n=e.$isFocusVisible,a=i.sizing,c=i.animation,y=r?i.colors.tickMarkFillDisabled:t?i.colors.tickMarkFillError:i.colors.tickMarkFill,k=encodeURIComponent(`
<svg width="14" height="4" viewBox="0 0 14 4" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M14 0.5H0V3.5H14V0.5Z" fill="`.concat(y,`"/>
</svg>
`)),$=encodeURIComponent(`
<svg width="17" height="13" viewBox="0 0 17 13" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M6.50002 12.6L0.400024 6.60002L2.60002 4.40002L6.50002 8.40002L13.9 0.900024L16.1 3.10002L6.50002 12.6Z" fill="`.concat(y,`"/>
</svg>
`)),b=i.borders.checkboxBorderRadius,f=ae(e);return{flex:"0 0 auto",transitionDuration:c.timing200,transitionTimingFunction:c.easeOutCurve,transitionProperty:"background-image, border-color, background-color",width:a.scale700,height:a.scale700,left:"4px",top:"4px",boxSizing:"border-box",borderLeftStyle:"solid",borderRightStyle:"solid",borderTopStyle:"solid",borderBottomStyle:"solid",borderLeftWidth:"3px",borderRightWidth:"3px",borderTopWidth:"3px",borderBottomWidth:"3px",borderLeftColor:f,borderRightColor:f,borderTopColor:f,borderBottomColor:f,borderTopLeftRadius:b,borderTopRightRadius:b,borderBottomRightRadius:b,borderBottomLeftRadius:b,outline:n&&o?"3px solid ".concat(i.colors.accent):"none",display:"inline-block",verticalAlign:"middle",backgroundImage:l?"url('data:image/svg+xml,".concat(k,"');"):o?"url('data:image/svg+xml,".concat($,"');"):null,backgroundColor:le(e),backgroundRepeat:"no-repeat",backgroundPosition:"center",backgroundSize:"contain",marginTop:i.sizing.scale0,marginBottom:i.sizing.scale0,marginLeft:i.sizing.scale0,marginRight:i.sizing.scale0}});j.displayName="Checkmark",j.displayName="Checkmark";var P=h("div",function(e){var o=e.$theme,r=o.typography;return S(S(S({verticalAlign:"middle"},ce(e)),{},{color:se(e)},r.LabelMedium),{},{lineHeight:"24px"})});P.displayName="Label",P.displayName="Label";var T=h("input",{opacity:0,width:0,height:0,overflow:"hidden",margin:0,padding:0,position:"absolute"});T.displayName="Input",T.displayName="Input";var E=h("div",function(e){var o=e.$theme.colors.toggleFill;return e.$disabled?o=e.$theme.colors.toggleFillDisabled:e.$checked&&e.$error?o=e.$theme.colors.tickFillErrorSelected:e.$checked&&(o=e.$theme.colors.toggleFillChecked),{backgroundColor:o,borderTopLeftRadius:"50%",borderTopRightRadius:"50%",borderBottomRightRadius:"50%",borderBottomLeftRadius:"50%",boxShadow:e.$isFocusVisible?"0 0 0 3px ".concat(e.$theme.colors.accent):e.$isHovered&&!e.$disabled?e.$theme.lighting.shadow500:e.$theme.lighting.shadow400,outline:"none",height:e.$theme.sizing.scale700,width:e.$theme.sizing.scale700,transform:e.$checked?"translateX(".concat(e.$theme.direction==="rtl"?"-100%":"100%",")"):null,transition:"transform ".concat(e.$theme.animation.timing200)}});E.displayName="Toggle",E.displayName="Toggle";var M=h("div",function(e){var o=e.$theme.colors.toggleTrackFill;return e.$disabled?o=e.$theme.colors.toggleTrackFillDisabled:e.$error&&e.$checked&&(o=e.$theme.colors.tickFillError),{alignItems:"center",backgroundColor:o,borderTopLeftRadius:"7px",borderTopRightRadius:"7px",borderBottomRightRadius:"7px",borderBottomLeftRadius:"7px",display:"flex",height:e.$theme.sizing.scale550,marginTop:e.$theme.sizing.scale200,marginBottom:e.$theme.sizing.scale100,marginLeft:e.$theme.sizing.scale200,marginRight:e.$theme.sizing.scale100,width:e.$theme.sizing.scale1000}});M.displayName="ToggleTrack",M.displayName="ToggleTrack";function B(e){"@babel/helpers - typeof";return B=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(o){return typeof o}:function(o){return o&&typeof Symbol=="function"&&o.constructor===Symbol&&o!==Symbol.prototype?"symbol":typeof o},B(e)}function u(){return u=Object.assign?Object.assign.bind():function(e){for(var o=1;o<arguments.length;o++){var r=arguments[o];for(var t in r)Object.prototype.hasOwnProperty.call(r,t)&&(e[t]=r[t])}return e},u.apply(this,arguments)}function ue(e,o){if(!(e instanceof o))throw new TypeError("Cannot call a class as a function")}function de(e,o){for(var r=0;r<o.length;r++){var t=o[r];t.enumerable=t.enumerable||!1,t.configurable=!0,"value"in t&&(t.writable=!0),Object.defineProperty(e,t.key,t)}}function pe(e,o,r){return o&&de(e.prototype,o),Object.defineProperty(e,"prototype",{writable:!1}),e}function be(e,o){if(typeof o!="function"&&o!==null)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(o&&o.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),o&&C(e,o)}function C(e,o){return C=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(r,t){return r.__proto__=t,r},C(e,o)}function fe(e){var o=he();return function(){var r=F(e),t;if(o){var l=F(this).constructor;t=Reflect.construct(r,arguments,l)}else t=r.apply(this,arguments);return ge(this,t)}}function ge(e,o){if(o&&(B(o)==="object"||typeof o=="function"))return o;if(o!==void 0)throw new TypeError("Derived constructors may only return object or undefined");return d(e)}function d(e){if(e===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function he(){if(typeof Reflect>"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function F(e){return F=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(o){return o.__proto__||Object.getPrototypeOf(o)},F(e)}function p(e,o,r){return o in e?Object.defineProperty(e,o,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[o]=r,e}var me=function(e){return e.stopPropagation()},q=function(e){be(r,e);var o=fe(r);function r(){var t;ue(this,r);for(var l=arguments.length,i=new Array(l),n=0;n<l;n++)i[n]=arguments[n];return t=o.call.apply(o,[this].concat(i)),p(d(t),"state",{isFocused:t.props.autoFocus||!1,isFocusVisible:!1,isHovered:!1,isActive:!1}),p(d(t),"onMouseEnter",function(a){t.setState({isHovered:!0}),t.props.onMouseEnter(a)}),p(d(t),"onMouseLeave",function(a){t.setState({isHovered:!1,isActive:!1}),t.props.onMouseLeave(a)}),p(d(t),"onMouseDown",function(a){t.setState({isActive:!0}),t.props.onMouseDown(a)}),p(d(t),"onMouseUp",function(a){t.setState({isActive:!1}),t.props.onMouseUp(a)}),p(d(t),"onFocus",function(a){t.setState({isFocused:!0}),t.props.onFocus(a),ie(a)&&t.setState({isFocusVisible:!0})}),p(d(t),"onBlur",function(a){t.setState({isFocused:!1}),t.props.onBlur(a),t.state.isFocusVisible!==!1&&t.setState({isFocusVisible:!1})}),t}return pe(r,[{key:"componentDidMount",value:function(){var t=this.props,l=t.autoFocus,i=t.inputRef;l&&i.current&&i.current.focus()}},{key:"render",value:function(){var t=this.props,l=t.overrides,i=l===void 0?{}:l,n=t.onChange,a=t.labelPlacement,c=a===void 0?this.props.checkmarkType===w.toggle?"left":"right":a,y=t.inputRef,k=t.isIndeterminate,$=t.error,b=t.disabled,f=t.value,W=t.name,Z=t.type,R=t.checked,O=t.children,x=t.required,X=t.title,D=i.Root,z=i.Checkmark,H=i.Label,I=i.Input,A=i.Toggle,N=i.ToggleTrack,G=m(D)||L,J=m(z)||j,K=m(H)||P,Q=m(I)||T,Y=m(A)||E,ee=m(N)||M,te={onChange:n,onFocus:this.onFocus,onBlur:this.onBlur},oe={onMouseEnter:this.onMouseEnter,onMouseLeave:this.onMouseLeave,onMouseDown:this.onMouseDown,onMouseUp:this.onMouseUp},g={$isFocused:this.state.isFocused,$isFocusVisible:this.state.isFocusVisible,$isHovered:this.state.isHovered,$isActive:this.state.isActive,$error:$,$checked:R,$isIndeterminate:k,$required:x,$disabled:b,$value:f},V=O&&s.createElement(K,u({$labelPlacement:c},g,v(H)),this.props.containsInteractiveElement?s.createElement("div",{onClick:function(re){return re.preventDefault()}},O):O);return s.createElement(G,u({"data-baseweb":"checkbox",title:X||null,$labelPlacement:c},g,oe,v(D)),(c==="top"||c==="left")&&V,this.props.checkmarkType===w.toggle?s.createElement(ee,u({},g,v(N)),s.createElement(Y,u({},g,v(A)))):s.createElement(J,u({},g,v(z))),s.createElement(Q,u({value:f,name:W,checked:R,required:x,"aria-label":this.props["aria-label"]||this.props.ariaLabel,"aria-checked":k?"mixed":R,"aria-describedby":this.props["aria-describedby"],"aria-errormessage":this.props["aria-errormessage"],"aria-invalid":$||null,"aria-required":x||null,disabled:b,type:Z,ref:y,onClick:me},g,te,v(I))),(c==="bottom"||c==="right")&&V)}}]),r}(s.Component);p(q,"defaultProps",{overrides:{},checked:!1,containsInteractiveElement:!1,disabled:!1,autoFocus:!1,isIndeterminate:!1,inputRef:s.createRef(),error:!1,type:"checkbox",checkmarkType:w.default,onChange:function(){},onMouseEnter:function(){},onMouseLeave:function(){},onMouseDown:function(){},onMouseUp:function(){},onFocus:function(){},onBlur:function(){}});export{ne as L,q as S,w as a};