@nexusui/components
Version:
These are custom components specially-developed for NexusUI applications. They will make your life easier by giving you out-of-the-box implementations for various high-level UI elements that you can drop directly into your application.
2 lines (1 loc) • 5.78 kB
JavaScript
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react/jsx-runtime"),t=require("react"),a=require("react-draggable"),r=require("lodash/uniqueId"),i=require("@mui/material/Popover"),s=require("@mui/material/Box"),l=require("@mui/material/Typography"),o=require("@mui/material/RadioGroup"),n=require("@mui/material/FormControlLabel"),u=require("@mui/material/Radio"),d=require("@mui/material/Stack"),c=require("@mui/material/TextField"),m=require("@mui/material/Checkbox"),h=require("@mui/icons-material/InfoOutlined"),f=require("@mui/material/Tooltip"),p=require("@mui/material/Menu"),x=require("@mui/material/Button"),b=require("@mui/material/Divider"),N=require("../NumberFormatter.context.js"),g=require("../../locales/index.js"),j=require("../locale.json.js");function v(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var $=v(t),w=v(a),P=v(r),q=v(s),T=v(l),C=v(o),S=v(n),y=v(u),I=v(d),F=v(c),M=v(m),k=v(h),D=v(f),R=v(p),z=v(x),Z=v(b);const B=$.default.forwardRef(((t,a)=>{const{handle:r,...s}=t;return e.jsx(w.default,{handle:`#${r}`,children:e.jsx(q.default,{children:e.jsx(i.PopoverPaper,{ref:a,...s})})})})),L="NexusNumberFormatterMenu",W=e=>e.stopPropagation();exports.NumberFormatterMenu=a=>{const{slotProps:r,MenuListProps:i,draggable:s,...l}=a,[o]=t.useState((()=>P.default(`${L}-draggable`))),n=r?.paper?.sx,{options:u,setOptions:d}=N.useNumberFormatterContext(),c=t.useRef(u),[m,h]=t.useState("scientific"!==u.notation?"standard":"scientific"),[f,p]=t.useState(u.decimalPlaces),[x,b]=t.useState(u.showTrailingZeros),[v,$]=t.useState("auto"===u.notation),[w,q]=t.useState(u.scientificThresholds?.above),[G,O]=t.useState(u.scientificThresholds?.below),A=g.useTranslate(j.default),E=t.useCallback((()=>{h("scientific"!==c.current.notation?"standard":"scientific"),p(c.current.decimalPlaces),b(c.current.showTrailingZeros),$("auto"===c.current.notation),q(c.current.scientificThresholds?.above),O(c.current.scientificThresholds?.below)}),[]),_=t.useCallback((()=>m!==("scientific"!==c.current.notation?"standard":"scientific")||(!(f===c.current.decimalPlaces||void 0===c.current.decimalPlaces&&Number.isNaN(f??NaN))||(x!==c.current.showTrailingZeros||(v!==("auto"===c.current.notation)||(w!==c.current.scientificThresholds?.above||G!==c.current.scientificThresholds?.below))))),[m,f,x,v,w,G]);return t.useEffect((()=>{d({notation:v?"auto":m,decimalPlaces:f,showTrailingZeros:x,scientificThresholds:{above:w,below:G}})}),[m,f,x,v,w,G,d]),t.useEffect((()=>{a.open||(c.current=u)}),[a.open,u]),e.jsx(R.default,{autoFocus:!1,className:`${L}-root`,"data-testid":`${L}-root`,MenuListProps:{disablePadding:!0,...i},slots:s?{paper:B}:{},slotProps:{...r,paper:{...r?.paper,handle:s?o:void 0,sx:[{width:330,maxWidth:"100%",minHeight:230},...n?Array.isArray(n)?n:[n]:[]]}},...l,children:e.jsxs(I.default,{sx:{p:4,cursor:s?"move":void 0,alignItems:"flex-start"},id:s?o:void 0,"data-testid":s?`${L}-draggable`:void 0,children:[e.jsxs(I.default,{className:`${L}-header`,"data-testid":`${L}-header`,direction:"row",alignItems:"center",justifyContent:"space-between",alignSelf:"stretch",children:[e.jsx(T.default,{className:`${L}-title`,"data-testid":`${L}-title`,variant:"subtitle2",children:A("Numerical Format")}),e.jsx(z.default,{className:`${L}-resetButton`,"data-testid":`${L}-resetButton`,onClick:()=>{E()},disabled:!_(),onMouseDown:W,children:A("Reset")})]}),e.jsxs(C.default,{className:`${L}-radioGroup`,"data-testid":`${L}-radioGroup`,row:!0,value:m,onChange:e=>h(e.target.value),onMouseDown:W,sx:{mt:2,mb:4},children:[e.jsx(S.default,{value:"standard",control:e.jsx(y.default,{size:"small",className:`${L}-standardRadio`,inputProps:{"data-testid":`${L}-standardRadio`}}),label:A("Decimal")}),e.jsx(S.default,{value:"scientific",control:e.jsx(y.default,{size:"small",className:`${L}-scientificRadio`,inputProps:{"data-testid":`${L}-scientificRadio`}}),label:A("Scientific")})]}),"scientific"===m&&e.jsx(T.default,{sx:{mt:-2,mb:6},variant:"caption",color:"textSecondary",children:A("ScientificDescription")}),e.jsx(F.default,{className:`${L}-decimalInput`,fullWidth:!0,label:A("Decimal Places"),value:Number.isNaN(f??NaN)?"":f,onChange:e=>{p(parseInt(e.target.value,10))},type:"number",slotProps:{htmlInput:{max:20,min:0,step:1,"data-testid":`${L}-decimalInput`}},onMouseDown:W}),e.jsx(S.default,{sx:{mt:2},control:e.jsx(M.default,{size:"small",className:`${L}-trailingZeroCheckbox`,checked:Boolean(x),onChange:(e,t)=>b(t),inputProps:{"data-testid":`${L}-trailingZeroCheckbox`}}),label:e.jsx(T.default,{variant:"body2",children:A("Include trailing zeros")})}),"standard"===m&&e.jsxs(e.Fragment,{children:[e.jsx(Z.default,{sx:{mt:4,mb:4,alignSelf:"stretch"}}),e.jsx(S.default,{control:e.jsx(M.default,{size:"small",className:`${L}-thresholdCheckbox`,checked:v,onChange:(e,t)=>$(t),inputProps:{"data-testid":`${L}-thresholdCheckbox`},onMouseDown:W}),label:e.jsxs(I.default,{spacing:2,direction:"row",alignItems:"center",children:[e.jsx(T.default,{variant:"body2",children:A("Set thresholds")}),e.jsx(D.default,{disableInteractive:!0,title:A("ThresholdTooltip"),children:e.jsx(k.default,{color:"action",fontSize:"small"})})]})}),v&&e.jsxs(e.Fragment,{children:[e.jsx(F.default,{sx:{mt:4},className:`${L}-upperThreshold`,fullWidth:!0,label:A("Upper threshold"),value:Number.isNaN(w??NaN)?"":w,onChange:e=>q(parseFloat(e.target.value)),type:"number",slotProps:{htmlInput:{min:0,step:1e3,"data-testid":`${L}-upperThreshold`}},onMouseDown:W}),e.jsx(F.default,{sx:{mt:4},className:`${L}-lowerThreshold`,fullWidth:!0,label:A("Lower threshold"),value:Number.isNaN(G??NaN)?"":G,onChange:e=>O(parseFloat(e.target.value)),type:"number",slotProps:{htmlInput:{min:0,step:1e-6,"data-testid":`${L}-lowerThreshold`}},onMouseDown:W})]})]})]})})};