@iqmo/browser
Version:
Browser Stlite
2 lines (1 loc) • 2.82 kB
JavaScript
import{r as f,z as T,C as y,j as c,cf as L,cg as w,bZ as C,b4 as S,c4 as $,b_ as R,bH as W,H as v,ch as B}from"./index-C9lG8Cnd.js";import{a as H}from"./useBasicWidgetState-C76uodSh.js";import{S as j,L as X,a as p}from"./checkbox-CWQIXh9J.js";function M({element:e,disabled:a,widgetMgr:s,fragmentId:n}){var g;const[x,h]=H({getStateFromWidgetMgr:V,getDefaultStateFromProto:F,getCurrStateFromProto:I,updateWidgetMgrState:P,element:e,widgetMgr:s,fragmentId:n}),k=f.useCallback(i=>{h({value:i.target.checked,fromUi:!0})},[h]),t=T(),{colors:o,spacing:b,sizes:r}=t,m=y(t),u=a?o.fadedText40:o.bodyText;return c.jsx(L,{className:"row-widget stCheckbox","data-testid":"stCheckbox",children:c.jsx(j,{checked:x,disabled:a,onChange:k,"aria-label":e.label,checkmarkType:e.type===B.StyleType.TOGGLE?p.toggle:p.default,labelPlacement:X.right,overrides:{Root:{style:({$isFocusVisible:i})=>({marginBottom:b.none,marginTop:b.none,backgroundColor:i?o.darkenedBgMix25:"",display:"flex",alignItems:"start"})},Toggle:{style:({$checked:i})=>{let d=m?o.bgColor:o.bodyText;return a&&(d=m?o.gray70:o.gray90),{width:`calc(${r.checkbox} - ${t.spacing.twoXS})`,height:`calc(${r.checkbox} - ${t.spacing.twoXS})`,transform:i?`translateX(${r.checkbox})`:"",backgroundColor:d,boxShadow:""}}},ToggleTrack:{style:({$checked:i,$isHovered:d})=>{let l=o.fadedText40;return d&&!a&&(l=o.fadedText20),i&&!a&&(l=o.primary),{marginRight:0,marginLeft:0,marginBottom:0,marginTop:t.spacing.twoXS,paddingLeft:t.spacing.threeXS,paddingRight:t.spacing.threeXS,width:`calc(2 * ${r.checkbox})`,minWidth:`calc(2 * ${r.checkbox})`,height:r.checkbox,minHeight:r.checkbox,borderBottomLeftRadius:t.radii.full,borderTopLeftRadius:t.radii.full,borderBottomRightRadius:t.radii.full,borderTopRightRadius:t.radii.full,backgroundColor:l}}},Checkmark:{style:({$isFocusVisible:i,$checked:d})=>{const l=d&&!a?o.primary:o.fadedText40;return{outline:0,width:r.checkbox,height:r.checkbox,marginTop:t.spacing.twoXS,marginLeft:0,marginBottom:0,boxShadow:i&&d?`0 0 0 0.2rem ${v(o.primary,.5)}`:"",borderLeftWidth:r.borderWidth,borderRightWidth:r.borderWidth,borderTopWidth:r.borderWidth,borderBottomWidth:r.borderWidth,borderLeftColor:l,borderRightColor:l,borderTopColor:l,borderBottomColor:l}}},Label:{style:{lineHeight:t.lineHeights.small,paddingLeft:t.spacing.sm,position:"relative",color:u}}},children:c.jsxs(w,{visibility:C((g=e.labelVisibility)==null?void 0:g.value),"data-testid":"stWidgetLabel",children:[c.jsx(S,{source:e.label,allowHTML:!1,isLabel:!0,largerLabel:!0}),e.help&&c.jsx($,{color:u,children:c.jsx(R,{content:e.help,placement:W.TOP_RIGHT})})]})})})}function V(e,a){return e.getBoolValue(a)}function F(e){return e.default??null}function I(e){return e.value??null}function P(e,a,s,n){a.setBoolValue(e,s.value,{fromUi:s.fromUi},n)}const G=f.memo(M);export{G as default};