@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.19 kB
JavaScript
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react/jsx-runtime"),t=require("react"),a=require("@mui/material/Typography"),i=require("@mui/material/RadioGroup"),s=require("@mui/material/FormControlLabel"),r=require("@mui/material/Radio"),l=require("@mui/material/Stack"),o=require("@mui/material/TextField"),n=require("@mui/material/Checkbox"),c=require("@mui/icons-material/InfoOutlined"),d=require("@mui/material/Tooltip"),u=require("@mui/material/Divider"),m=require("../NumberFormatter.context.js"),h=require("../../Dialog/Dialog.container.js"),p=require("../../locales/index.js"),f=require("../locale.json.js");function N(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var b=N(a),x=N(i),g=N(s),j=N(r),v=N(l),$=N(o),C=N(n),T=N(c),w=N(d),y=N(u);const F="NexusNumberFormatterDialog";exports.NumberFormatterDialog=a=>{const{open:i,onClose:s,title:r,sx:l}=a,{options:o,setOptions:n}=m.useNumberFormatterContext(),[c,d]=t.useState("scientific"!==o.notation?"standard":"scientific"),[u,N]=t.useState(o.decimalPlaces),[P,q]=t.useState(o.showTrailingZeros),[D,k]=t.useState("auto"===o.notation),[I,S]=t.useState(o.scientificThresholds?.above),[B,R]=t.useState(o.scientificThresholds?.below),Z=p.useTranslate(f.default),A=new Intl.NumberFormat(void 0,{notation:"standard",maximumFractionDigits:Number.isNaN(u??NaN)?20:u,minimumFractionDigits:Number.isNaN(u??NaN)?0:u}),W=new Intl.NumberFormat(void 0,{notation:"scientific",maximumFractionDigits:Number.isNaN(u??NaN)?20:u,minimumFractionDigits:Number.isNaN(u??NaN)?0:u}),G=t.useCallback((()=>{d("scientific"!==o.notation?"standard":"scientific"),N(o.decimalPlaces),q(o.showTrailingZeros),k("auto"===o.notation),S(o.scientificThresholds?.above),R(o.scientificThresholds?.below)}),[o]),O=t.useCallback((()=>c!==("scientific"!==o.notation?"standard":"scientific")||(!(u===o.decimalPlaces||void 0===o.decimalPlaces&&Number.isNaN(u??NaN))||(P!==o.showTrailingZeros||(D!==("auto"===o.notation)||(I!==o.scientificThresholds?.above||B!==o.scientificThresholds?.below))))),[o,c,u,P,D,I,B]);return e.jsx(h.Dialog,{className:`${F}-root`,"data-testid":`${F}-root`,title:r??Z("Numerical Format"),open:i,onClose:(e,t)=>{s?.(e,t),G()},leftActions:[{children:Z("Reset"),onClick:()=>{G()},disabled:!O(),className:`${F}-resetButton`,"data-testid":`${F}-resetButton`}],rightActions:[{children:Z("Cancel"),color:"primary",onClick:e=>{s?.(e,"escapeKeyDown"),G()},className:`${F}-cancelButton`,"data-testid":`${F}-cancelButton`},{children:Z("Apply"),color:"primary",variant:"contained",onClick:e=>{s?.(e,"escapeKeyDown"),n({notation:D?"auto":c,decimalPlaces:u,showTrailingZeros:P,scientificThresholds:{above:I,below:B}})},disabled:!O(),className:`${F}-applyButton`,"data-testid":`${F}-applyButton`}],PaperProps:{sx:[{"&.MuiPaper-root":{width:500,minHeight:340,maxWidth:"100%"}},...Array.isArray(l)?l:[l]]},children:e.jsxs(v.default,{children:[e.jsxs(x.default,{className:`${F}-radioGroup`,"data-testid":`${F}-radioGroup`,row:!0,value:c,onChange:e=>d(e.target.value),sx:{mb:4},children:[e.jsx(g.default,{value:"standard",control:e.jsx(j.default,{className:`${F}-standardRadio`,inputProps:{"data-testid":`${F}-standardRadio`}}),label:Z("Decimal")}),e.jsx(g.default,{value:"scientific",control:e.jsx(j.default,{className:`${F}-scientificRadio`,inputProps:{"data-testid":`${F}-scientificRadio`}}),label:Z("Scientific")})]}),e.jsx($.default,{className:`${F}-decimalInput`,fullWidth:!0,label:Z("Decimal Places"),value:Number.isNaN(u??NaN)?"":u,onChange:e=>{N(parseInt(e.target.value,10))},type:"number",slotProps:{htmlInput:{max:20,min:0,step:1,"data-testid":`${F}-decimalInput`}}}),e.jsxs(v.default,{direction:"row",justifyContent:"space-between",alignItems:"center",sx:{mt:1},children:[e.jsx(b.default,{variant:"caption",children:`${Z("Sample")}: ${("scientific"===c?W:A).format("standard"===c?1.23456789:123456789)}`}),e.jsx(g.default,{control:e.jsx(C.default,{className:`${F}-trailingZeroCheckbox`,checked:Boolean(P),onChange:(e,t)=>q(t),inputProps:{"data-testid":`${F}-trailingZeroCheckbox`}}),label:e.jsx(b.default,{variant:"body2",children:Z("Include trailing zeros")})})]}),"standard"===c&&e.jsxs(e.Fragment,{children:[e.jsx(y.default,{sx:{mt:4,mb:4}}),e.jsx(g.default,{control:e.jsx(C.default,{className:`${F}-thresholdCheckbox`,checked:D,onChange:(e,t)=>k(t),inputProps:{"data-testid":`${F}-thresholdCheckbox`}}),label:e.jsxs(v.default,{spacing:2,direction:"row",alignItems:"center",children:[e.jsx(b.default,{variant:"body2",children:Z("Set thresholds")}),e.jsx(w.default,{disableInteractive:!0,title:Z("ThresholdTooltip"),children:e.jsx(T.default,{color:"action",fontSize:"small"})})]})}),D&&e.jsxs(e.Fragment,{children:[e.jsx($.default,{sx:{mt:4},className:`${F}-upperThreshold`,fullWidth:!0,label:Z("Upper threshold"),value:I,onChange:e=>S(parseFloat(e.target.value)),type:"number",slotProps:{htmlInput:{min:0,step:1e3,"data-testid":`${F}-upperThreshold`}}}),e.jsx($.default,{sx:{mt:4},className:`${F}-lowerThreshold`,fullWidth:!0,label:Z("Lower threshold"),value:B,onChange:e=>R(parseFloat(e.target.value)),type:"number",slotProps:{htmlInput:{min:0,step:1e-6,"data-testid":`${F}-lowerThreshold`}}})]})]})]})})};