@iqmo/browser
Version:
Browser Stlite
4 lines (3 loc) • 19 kB
JavaScript
import{c0 as w,ci as ge,c1 as O,r as c,z as ye,j as m,bY as ve,c4 as we,b_ as Oe,bH as Re,b4 as re,F as oe,cE as ne,bZ as ke}from"./index-C9lG8Cnd.js";import{a as je}from"./useBasicWidgetState-C76uodSh.js";var ie={vertical:"vertical",horizontal:"horizontal"};function ae(e,t){var o=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(n){return Object.getOwnPropertyDescriptor(e,n).enumerable})),o.push.apply(o,r)}return o}function C(e){for(var t=1;t<arguments.length;t++){var o=arguments[t]!=null?arguments[t]:{};t%2?ae(Object(o),!0).forEach(function(r){R(e,r,o[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(o)):ae(Object(o)).forEach(function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(o,r))})}return e}function R(e,t,o){return t in e?Object.defineProperty(e,t,{value:o,enumerable:!0,configurable:!0,writable:!0}):e[t]=o,e}var x=0,E=1,I=2;function T(e){return e.$isActive?I:e.$isHovered?E:x}function Se(e){var t=e.$theme.colors,o=e.$disabled,r=e.$checked,n=e.$isFocusVisible,i=e.$error;if(o)return t.tickFillDisabled;if(r)if(i)switch(T(e)){case x:return t.tickFillErrorSelected;case E:return t.tickFillErrorSelectedHover;case I:return t.tickFillErrorSelectedHoverActive}else switch(T(e)){case x:return t.tickFillSelected;case E:return t.tickFillSelectedHover;case I:return t.tickFillSelectedHoverActive}else return n?t.borderSelected:i?t.tickBorderError:t.tickBorder;return null}function Fe(e){var t=e.$theme.colors;if(e.$disabled)return t.tickMarkFillDisabled;if(e.$checked)return t.tickMarkFill;if(e.$error)switch(T(e)){case x:return t.tickFillError;case E:return t.tickFillErrorHover;case I:return t.tickFillErrorHoverActive}else switch(T(e)){case x:return t.tickFill;case E:return t.tickFillHover;case I:return t.tickFillActive}}function Me(e){var t=e.$labelPlacement,o=t===void 0?"":t,r=e.$theme,n;switch(o){case"top":n="Bottom";break;case"bottom":n="Top";break;case"left":n=r.direction==="rtl"?"Left":"Right";break;default:case"right":n=r.direction==="rtl"?"Right":"Left";break}var i=r.sizing,a=i.scale300;return R({},"padding".concat(n),a)}function $e(e){var t=e.$disabled,o=e.$theme,r=o.colors;return t?r.contentSecondary:r.contentPrimary}var _=w("div",function(e){var t=e.$disabled,o=e.$align;return{display:"flex",flexWrap:"wrap",flexDirection:o==="horizontal"?"row":"column",alignItems:o==="horizontal"?"center":"flex-start",cursor:t?"not-allowed":"pointer","-webkit-tap-highlight-color":"transparent"}});_.displayName="RadioGroupRoot",_.displayName="RadioGroupRoot";var N=w("label",function(e){var t,o=e.$disabled,r=e.$hasDescription,n=e.$labelPlacement,i=e.$theme,a=e.$align,s=i.sizing,u=a==="horizontal",f=i.direction==="rtl"?"Left":"Right";return t={flexDirection:n==="top"||n==="bottom"?"column":"row",display:"flex",alignItems:"center",cursor:o?"not-allowed":"pointer",marginTop:s.scale200},R(t,"margin".concat(f),u?s.scale200:null),R(t,"marginBottom",r&&!u?null:s.scale200),t});N.displayName="Root",N.displayName="Root";var U=w("div",function(e){var t=e.$theme,o=t.animation,r=t.sizing;return{backgroundColor:Fe(e),borderTopLeftRadius:"50%",borderTopRightRadius:"50%",borderBottomRightRadius:"50%",borderBottomLeftRadius:"50%",height:e.$checked?r.scale200:r.scale550,transitionDuration:o.timing200,transitionTimingFunction:o.easeOutCurve,width:e.$checked?r.scale200:r.scale550}});U.displayName="RadioMarkInner",U.displayName="RadioMarkInner";var q=w("div",function(e){var t=e.$theme,o=t.animation,r=t.sizing;return{alignItems:"center",backgroundColor:Se(e),borderTopLeftRadius:"50%",borderTopRightRadius:"50%",borderBottomRightRadius:"50%",borderBottomLeftRadius:"50%",boxShadow:e.$isFocusVisible&&e.$checked?"0 0 0 3px ".concat(e.$theme.colors.accent):"none",display:"flex",height:r.scale700,justifyContent:"center",marginTop:r.scale0,marginRight:r.scale0,marginBottom:r.scale0,marginLeft:r.scale0,outline:"none",verticalAlign:"middle",width:r.scale700,flexShrink:0,transitionDuration:o.timing200,transitionTimingFunction:o.easeOutCurve}});q.displayName="RadioMarkOuter",q.displayName="RadioMarkOuter";var G=w("div",function(e){var t=e.$theme.typography;return C(C({verticalAlign:"middle"},Me(e)),{},{color:$e(e)},t.LabelMedium)});G.displayName="Label",G.displayName="Label";var W=w("input",{width:0,height:0,marginTop:0,marginRight:0,marginBottom:0,marginLeft:0,paddingTop:0,paddingRight:0,paddingBottom:0,paddingLeft:0,clip:"rect(0 0 0 0)",position:"absolute"});W.displayName="Input",W.displayName="Input";var X=w("div",function(e){var t,o=e.$theme,r=e.$align,n=r==="horizontal",i=o.direction==="rtl"?"Right":"Left",a=o.direction==="rtl"?"Left":"Right";return C(C({},o.typography.ParagraphSmall),{},(t={color:o.colors.contentSecondary,cursor:"auto"},R(t,"margin".concat(i),r==="horizontal"?null:o.sizing.scale900),R(t,"margin".concat(a),n?o.sizing.scale200:null),R(t,"maxWidth","240px"),t))});X.displayName="Description",X.displayName="Description";function Y(e){"@babel/helpers - typeof";return Y=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(t){return typeof t}:function(t){return t&&typeof Symbol=="function"&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},Y(e)}function Z(){return Z=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var o=arguments[t];for(var r in o)Object.prototype.hasOwnProperty.call(o,r)&&(e[r]=o[r])}return e},Z.apply(this,arguments)}function Pe(e,t){return Le(e)||Ie(e,t)||Ee(e,t)||xe()}function xe(){throw new TypeError(`Invalid attempt to destructure non-iterable instance.
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function Ee(e,t){if(e){if(typeof e=="string")return se(e,t);var o=Object.prototype.toString.call(e).slice(8,-1);if(o==="Object"&&e.constructor&&(o=e.constructor.name),o==="Map"||o==="Set")return Array.from(e);if(o==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(o))return se(e,t)}}function se(e,t){(t==null||t>e.length)&&(t=e.length);for(var o=0,r=new Array(t);o<t;o++)r[o]=e[o];return r}function Ie(e,t){var o=e==null?null:typeof Symbol<"u"&&e[Symbol.iterator]||e["@@iterator"];if(o!=null){var r=[],n=!0,i=!1,a,s;try{for(o=o.call(e);!(n=(a=o.next()).done)&&(r.push(a.value),!(t&&r.length===t));n=!0);}catch(u){i=!0,s=u}finally{try{!n&&o.return!=null&&o.return()}finally{if(i)throw s}}return r}}function Le(e){if(Array.isArray(e))return e}function Ce(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function Te(e,t){for(var o=0;o<t.length;o++){var r=t[o];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function Ae(e,t,o){return t&&Te(e.prototype,t),Object.defineProperty(e,"prototype",{writable:!1}),e}function Be(e,t){if(typeof t!="function"&&t!==null)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&J(e,t)}function J(e,t){return J=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(o,r){return o.__proto__=r,o},J(e,t)}function De(e){var t=He();return function(){var o=B(e),r;if(t){var n=B(this).constructor;r=Reflect.construct(o,arguments,n)}else r=o.apply(this,arguments);return ze(this,r)}}function ze(e,t){if(t&&(Y(t)==="object"||typeof t=="function"))return t;if(t!==void 0)throw new TypeError("Derived constructors may only return object or undefined");return A(e)}function A(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 B(e){return B=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},B(e)}function D(e,t,o){return t in e?Object.defineProperty(e,t,{value:o,enumerable:!0,configurable:!0,writable:!0}):e[t]=o,e}var le=function(e){Be(o,e);var t=De(o);function o(){var r;Ce(this,o);for(var n=arguments.length,i=new Array(n),a=0;a<n;a++)i[a]=arguments[a];return r=t.call.apply(t,[this].concat(i)),D(A(r),"state",{isFocusVisible:!1,focusedRadioIndex:-1}),D(A(r),"handleFocus",function(s,u){ge(s)&&r.setState({isFocusVisible:!0}),r.setState({focusedRadioIndex:u}),r.props.onFocus&&r.props.onFocus(s)}),D(A(r),"handleBlur",function(s,u){r.state.isFocusVisible!==!1&&r.setState({isFocusVisible:!1}),r.setState({focusedRadioIndex:-1}),r.props.onBlur&&r.props.onBlur(s)}),r}return Ae(o,[{key:"render",value:function(){var r=this,n=this.props.overrides,i=n===void 0?{}:n,a=O(i.RadioGroupRoot,_),s=Pe(a,2),u=s[0],f=s[1];return c.createElement(u,Z({id:this.props.id,role:"radiogroup","aria-describedby":this.props["aria-describedby"],"aria-errormessage":this.props["aria-errormessage"],"aria-invalid":this.props.error||null,"aria-label":this.props["aria-label"],"aria-labelledby":this.props["aria-labelledby"],$align:this.props.align,$disabled:this.props.disabled,$error:this.props.error,$required:this.props.required},f),c.Children.map(this.props.children,function(p,b){if(!c.isValidElement(p))return null;var l=r.props.value===p.props.value;return c.cloneElement(p,{align:r.props.align,autoFocus:r.props.autoFocus,checked:l,disabled:r.props.disabled||p.props.disabled,error:r.props.error,isFocused:r.state.focusedRadioIndex===b,isFocusVisible:r.state.isFocusVisible,tabIndex:b===0&&!r.props.value||l?"0":"-1",labelPlacement:r.props.labelPlacement,name:r.props.name,onBlur:function(d){return r.handleBlur(d,b)},onFocus:function(d){return r.handleFocus(d,b)},onChange:r.props.onChange,onMouseEnter:r.props.onMouseEnter,onMouseLeave:r.props.onMouseLeave})}))}}]),o}(c.Component);D(le,"defaultProps",{name:"",value:"",disabled:!1,autoFocus:!1,labelPlacement:"right",align:"vertical",error:!1,required:!1,onChange:function(){},onMouseEnter:function(){},onMouseLeave:function(){},onFocus:function(){},onBlur:function(){},overrides:{}});function K(e){"@babel/helpers - typeof";return K=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(t){return typeof t}:function(t){return t&&typeof Symbol=="function"&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},K(e)}function v(){return v=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var o=arguments[t];for(var r in o)Object.prototype.hasOwnProperty.call(o,r)&&(e[r]=o[r])}return e},v.apply(this,arguments)}function S(e,t){return Ue(e)||Ne(e,t)||_e(e,t)||Ve()}function Ve(){throw new TypeError(`Invalid attempt to destructure non-iterable instance.
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function _e(e,t){if(e){if(typeof e=="string")return ce(e,t);var o=Object.prototype.toString.call(e).slice(8,-1);if(o==="Object"&&e.constructor&&(o=e.constructor.name),o==="Map"||o==="Set")return Array.from(e);if(o==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(o))return ce(e,t)}}function ce(e,t){(t==null||t>e.length)&&(t=e.length);for(var o=0,r=new Array(t);o<t;o++)r[o]=e[o];return r}function Ne(e,t){var o=e==null?null:typeof Symbol<"u"&&e[Symbol.iterator]||e["@@iterator"];if(o!=null){var r=[],n=!0,i=!1,a,s;try{for(o=o.call(e);!(n=(a=o.next()).done)&&(r.push(a.value),!(t&&r.length===t));n=!0);}catch(u){i=!0,s=u}finally{try{!n&&o.return!=null&&o.return()}finally{if(i)throw s}}return r}}function Ue(e){if(Array.isArray(e))return e}function qe(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function Ge(e,t){for(var o=0;o<t.length;o++){var r=t[o];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function We(e,t,o){return t&&Ge(e.prototype,t),Object.defineProperty(e,"prototype",{writable:!1}),e}function Xe(e,t){if(typeof t!="function"&&t!==null)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&Q(e,t)}function Q(e,t){return Q=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(o,r){return o.__proto__=r,o},Q(e,t)}function Ye(e){var t=Je();return function(){var o=z(e),r;if(t){var n=z(this).constructor;r=Reflect.construct(o,arguments,n)}else r=o.apply(this,arguments);return Ze(this,r)}}function Ze(e,t){if(t&&(K(t)==="object"||typeof t=="function"))return t;if(t!==void 0)throw new TypeError("Derived constructors may only return object or undefined");return F(e)}function F(e){if(e===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function Je(){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 z(e){return z=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},z(e)}function M(e,t,o){return t in e?Object.defineProperty(e,t,{value:o,enumerable:!0,configurable:!0,writable:!0}):e[t]=o,e}function Ke(e){return e==="top"||e==="left"}function Qe(e){return e==="bottom"||e==="right"}var et=function(e){return e.stopPropagation()},ue=function(e){Xe(o,e);var t=Ye(o);function o(){var r;qe(this,o);for(var n=arguments.length,i=new Array(n),a=0;a<n;a++)i[a]=arguments[a];return r=t.call.apply(t,[this].concat(i)),M(F(r),"state",{isActive:!1,isHovered:!1}),M(F(r),"onMouseEnter",function(s){r.setState({isHovered:!0}),r.props.onMouseEnter&&r.props.onMouseEnter(s)}),M(F(r),"onMouseLeave",function(s){r.setState({isHovered:!1}),r.props.onMouseLeave&&r.props.onMouseLeave(s)}),M(F(r),"onMouseDown",function(s){r.setState({isActive:!0}),r.props.onMouseDown&&r.props.onMouseDown(s)}),M(F(r),"onMouseUp",function(s){r.setState({isActive:!1}),r.props.onMouseUp&&r.props.onMouseUp(s)}),r}return We(o,[{key:"componentDidMount",value:function(){var r;this.props.autoFocus&&(r=this.props.inputRef)!==null&&r!==void 0&&r.current&&this.props.inputRef.current.focus()}},{key:"render",value:function(){var r=this.props.overrides,n=r===void 0?{}:r,i=O(n.Root,N),a=S(i,2),s=a[0],u=a[1],f=O(n.Label,G),p=S(f,2),b=p[0],l=p[1],d=O(n.Input,W),$=S(d,2),H=$[0],k=$[1],V=O(n.Description,X),P=S(V,2),L=P[0],g=P[1],y=O(n.RadioMarkInner,U),h=S(y,2),pe=h[0],de=h[1],fe=O(n.RadioMarkOuter,q),ee=S(fe,2),be=ee[0],he=ee[1],j={$align:this.props.align,$checked:this.props.checked,$disabled:this.props.disabled,$hasDescription:!!this.props.description,$isActive:this.state.isActive,$error:this.props.error,$isFocused:this.props.isFocused,$isFocusVisible:this.props.isFocused&&this.props.isFocusVisible,$isHovered:this.state.isHovered,$labelPlacement:this.props.labelPlacement,$required:this.props.required,$value:this.props.value},te=c.createElement(b,v({},j,l),this.props.containsInteractiveElement?c.createElement("div",{onClick:function(me){return me.preventDefault()}},this.props.children):this.props.children);return c.createElement(c.Fragment,null,c.createElement(s,v({"data-baseweb":"radio",onMouseEnter:this.onMouseEnter,onMouseLeave:this.onMouseLeave,onMouseDown:this.onMouseDown,onMouseUp:this.onMouseUp},j,u),Ke(this.props.labelPlacement)&&te,c.createElement(be,v({},j,he),c.createElement(pe,v({},j,de))),c.createElement(H,v({"aria-invalid":this.props.error||null,checked:this.props.checked,disabled:this.props.disabled,name:this.props.name,onBlur:this.props.onBlur,onFocus:this.props.onFocus,onClick:et,onChange:this.props.onChange,ref:this.props.inputRef,required:this.props.required,tabIndex:this.props.tabIndex,type:"radio",value:this.props.value},j,k)),Qe(this.props.labelPlacement)&&te),!!this.props.description&&c.createElement(L,v({},j,g),this.props.description))}}]),o}(c.Component);M(ue,"defaultProps",{overrides:{},containsInteractiveElement:!1,checked:!1,disabled:!1,autoFocus:!1,inputRef:c.createRef(),align:"vertical",error:!1,onChange:function(){},onMouseEnter:function(){},onMouseLeave:function(){},onMouseDown:function(){},onMouseUp:function(){},onFocus:function(){},onBlur:function(){}});function tt(e){const t=parseFloat(e.sizes.checkbox),o=parseFloat(e.spacing.threeXS),r=oe(t.toString()),n=Math.round(r*.375);let i=Math.round(oe((t-o).toString()));return i>=r&&(i-=1),[ne(n,"px"),ne(i,"px")]}function rt({disabled:e,horizontal:t,value:o,onChange:r,options:n,captions:i,label:a,labelVisibility:s,help:u}){const[f,p]=c.useState(o??null);c.useEffect(()=>{o!==f&&p(o??null)},[o]);const b=c.useCallback(g=>{const y=parseInt(g.target.value,10);p(y),r(y)},[r]),l=ye(),d=i.length>0,$=n.length>0,H=$?n:["No options to select."],k=e||!$,V=g=>g==""&&t&&d?" ":g,[P,L]=tt(l);return m.jsxs("div",{className:"stRadio","data-testid":"stRadio",children:[m.jsx(ve,{label:a,disabled:k,labelVisibility:s,children:u&&m.jsx(we,{children:m.jsx(Oe,{content:u,placement:Re.TOP_RIGHT})})}),m.jsx(le,{onChange:b,value:f!==null?f.toString():void 0,disabled:k,align:t?ie.horizontal:ie.vertical,"aria-label":a,"data-testid":"stRadioGroup",overrides:{RadioGroupRoot:{style:{gap:d?l.spacing.sm:l.spacing.none,minHeight:l.sizes.minElementHeight}}},children:H.map((g,y)=>m.jsxs(ue,{value:y.toString(),overrides:{Root:{style:({$isFocusVisible:h})=>({marginBottom:l.spacing.none,marginTop:l.spacing.none,marginRight:d?l.spacing.sm:l.spacing.lg,paddingLeft:l.spacing.none,alignItems:"start",paddingRight:l.spacing.threeXS,backgroundColor:h?l.colors.darkenedBgMix25:""})},RadioMarkOuter:{style:({$checked:h})=>({width:l.sizes.checkbox,height:l.sizes.checkbox,marginTop:"0.35rem",marginRight:l.spacing.none,marginLeft:l.spacing.none,backgroundColor:h&&!k?l.colors.primary:l.colors.fadedText40})},RadioMarkInner:{style:({$checked:h})=>({height:h?P:L,width:h?P:L})},Label:{style:{color:k?l.colors.fadedText40:l.colors.bodyText,position:"relative",top:l.spacing.px}}},children:[m.jsx(re,{source:g,allowHTML:!1,isLabel:!0,largerLabel:!0}),d&&m.jsx(re,{source:V(i[y]),allowHTML:!1,isCaption:!0,isLabel:!0})]},y))})]})}const ot=c.memo(rt);function nt({disabled:e,element:t,widgetMgr:o,fragmentId:r}){const[n,i]=je({getStateFromWidgetMgr:it,getDefaultStateFromProto:at,getCurrStateFromProto:st,updateWidgetMgrState:lt,element:t,widgetMgr:o,fragmentId:r}),a=c.useCallback(d=>{i({value:d,fromUi:!0})},[i]),{horizontal:s,options:u,captions:f,label:p,labelVisibility:b,help:l}=t;return m.jsx(ot,{label:p,onChange:a,options:u,captions:f,disabled:e,horizontal:s,labelVisibility:ke(b==null?void 0:b.value),value:n??null,help:l})}function it(e,t){return e.getIntValue(t)}function at(e){return e.default??null}function st(e){return e.value??null}function lt(e,t,o,r){t.setIntValue(e,o.value??null,{fromUi:o.fromUi},r)}const ct=c.memo(nt);export{ct as default};