@oliasoft-open-source/react-ui-library 4.6.6 → 4.6.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/global.css +50 -49
- package/dist/index.js +29 -29
- package/dist/index.js.map +1 -1
- package/dist/storybook/assets/{Color-6VNJS4EI-BrOcbA6h.js → Color-6VNJS4EI-hQgbfk1_.js} +1 -1
- package/dist/storybook/assets/{DocsRenderer-NNNQARDV-tJI6VTjP.js → DocsRenderer-NNNQARDV-qVZ0Szzp.js} +1 -1
- package/dist/storybook/assets/{WithTooltip-V3YHNWJZ-YRJYbhNd.js → WithTooltip-V3YHNWJZ-EVkXusH9.js} +1 -1
- package/dist/storybook/assets/{accordion.stories-nYKTmoeA.js → accordion.stories-Je6TgVbI.js} +1 -1
- package/dist/storybook/assets/{buttons-and-links-VKKWJKFr.js → buttons-and-links-Htqi06fE.js} +1 -1
- package/dist/storybook/assets/{casing-loads.stories-oh3l5Q7X.js → casing-loads.stories-rv-r7qUR.js} +1 -1
- package/dist/storybook/assets/cell.stories-ntUcZ9Z2.js +245 -0
- package/dist/storybook/assets/{chunk-HLWAVYOI-83EByc66.js → chunk-HLWAVYOI-XUXGp0n7.js} +1 -1
- package/dist/storybook/assets/{color-ugWGhOJm.js → color-l-jFB8qa.js} +1 -1
- package/dist/storybook/assets/{file-input.stories-8w1taUk6.js → file-input.stories-lKF1ABXX.js} +1 -1
- package/dist/storybook/assets/{footer.stories-tB9ZiuYm.js → footer.stories-txHcy_rz.js} +1 -1
- package/dist/storybook/assets/{form.stories-b8fSf1KV.js → form.stories-AikCzsZc.js} +1 -1
- package/dist/storybook/assets/{formation.stories-4zFgtvwa.js → formation.stories-WYUKooZj.js} +1 -1
- package/dist/storybook/assets/{formatter-SWP5E3XI-umUJAuhQ.js → formatter-SWP5E3XI-2jpDZ32o.js} +1 -1
- package/dist/storybook/assets/{iframe-LJjp0O19.js → iframe-afwDQcyf.js} +2 -2
- package/dist/storybook/assets/{index-hMEOtd8c.js → index-WQN43Pdc.js} +5 -5
- package/dist/storybook/assets/{input-validation-5TXTtQCt.js → input-validation-1C25NF0D.js} +1 -1
- package/dist/storybook/assets/{inputs-rK_va801.js → inputs-dvl3Vxzi.js} +1 -1
- package/dist/storybook/assets/{layout-forms-4SDauXUc.js → layout-forms-aQDJspiu.js} +1 -1
- package/dist/storybook/assets/{layout-general-4b2v8KKO.js → layout-general-glx7j38t.js} +1 -1
- package/dist/storybook/assets/{padding-and-spacing-0ADtQv-B.js → padding-and-spacing-nDPUVOhE.js} +1 -1
- package/dist/storybook/assets/{preview-Jj3eWAFT.js → preview-8iAUReLe.js} +1 -1
- package/dist/storybook/assets/{preview-ZGYBin_R.js → preview-NgqKh_bR.js} +2 -2
- package/dist/storybook/assets/{row.stories-p0ssjvtr.js → row.stories-s3mq4p3b.js} +1 -1
- package/dist/storybook/assets/{syntaxhighlighter-B5GMVT5T-yVSKFRoH.js → syntaxhighlighter-B5GMVT5T-sSZfeghu.js} +1 -1
- package/dist/storybook/assets/table-5HZEOUW_.js +1 -0
- package/dist/storybook/assets/{table.stories-wdVWlpz1.js → table.stories-wP0SdJzJ.js} +1 -1
- package/dist/storybook/assets/{textarea-gwm6gdQO.js → textarea-TSoWqDT8.js} +1 -1
- package/dist/storybook/assets/{textarea.stories-eOTtHmL4.js → textarea.stories-w6XYooLd.js} +1 -1
- package/dist/storybook/assets/{title.stories-9QWP9XVr.js → title.stories-CDtRZqWr.js} +1 -1
- package/dist/storybook/assets/{unit-table.stories-ZHWCQMuq.js → unit-table.stories-M8TmG1IT.js} +1 -1
- package/dist/storybook/iframe.html +1 -1
- package/dist/storybook/index.json +1 -1
- package/dist/storybook/project.json +1 -1
- package/dist/storybook/stories.json +1 -1
- package/package.json +1 -1
- package/dist/storybook/assets/cell.stories-dk65sciA.js +0 -212
- package/dist/storybook/assets/table-033R9jUC.js +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{j as n}from"./jsx-runtime-FsUICBgo.js";import{r as S}from"./index-RfLt4OUa.js";import{f as B}from"./immer.esm-bD7SSJ7T.js";import{l as oe}from"./lodash-Bmg8FrMx.js";import{G as se}from"./grid-u1mZpaML.js";import{T as V}from"./text-6KQ6ntOV.js";import{T as A}from"./table-033R9jUC.js";import{C as sn}from"./card-0r8RRVk-.js";import{I as ae}from"./input-2BhbKV-j.js";import{F as re}from"./field-FZX0Z7IB.js";import{H as ln}from"./heading-jZsIIJF0.js";import{t as ne,v as on,w as cn,x as dn,y as un,z as pn,A as gn,B as mn}from"./table.stories-data-NfE_v-gH.js";import"./styled-components.browser.esm-qIipjd6c.js";import"./tslib.es6-OIsz3r9a.js";import"./index-VW3EWkuE.js";import"./index.es-VXFRDikp.js";import"./inheritsLoose-8sb_A2v4.js";import"./redux-F5dueAP3.js";import"./objectSpread2-93s0nBry.js";import"./tiny-invariant-R4kOKlvx.js";import"./index-miLrID2P.js";import"./memoize-one.esm-hqe5SRxC.js";import"./objectWithoutPropertiesLoose-9Q1jwsKS.js";import"./actions-mOcj9IlF.js";import"./common-types-U65vzrrz.js";import"./disabled-context-urNQThQz.js";import"./button-shH4xakS.js";import"./spinner-R8Il4aRe.js";import"./icon-8EQazuuW.js";import"./index-4QtD-hFu.js";import"./tooltip-HEHiU__l.js";import"./types-VB5zD18b.js";import"./types-5uVBABF4.js";import"./badge-23Ty_zBt.js";import"./pagination-tnyyuMkB.js";import"./select-DZdWUrCW.js";import"./assertThisInitialized-4q6YPdh3.js";import"./select.input-zP5tW20f.js";import"./input-group-R8LoqKRn.js";import"./input-group-addon-BHVsW9mL.js";import"./number-input-CMhEMmUd.js";import"./index-qZmQ7nA9.js";import"./index-cCpkwrS5.js";import"./check-box-2gxosI3y.js";import"./help-icon-SKky6KLV.js";import"./slider-MN9iDCsS.js";import"./index-ugi_ZH6T.js";import"./popover-cad2llTa.js";import"./label-uCFEME1p.js";import"./flex-RYZsoWEN.js";const ut={title:"Basic/Table",component:A,args:{table:{...ne}}},I=g=>n.jsx(A,{...g}),K=I.bind({}),_=I.bind({});_.args={table:{...ne,fixedWidth:"400px"}};const M=I.bind({});M.args={table:{...ne,fixedWidth:"auto"}};const O=I.bind({});O.args={table:on};O.parameters={docs:{description:{story:"Use sparingly when certain columns cannot be below a certain width. Unless the Table is auto width, set one column to `auto` to use remaining space."}}};const L=I.bind({});L.args={table:cn};const U=I.bind({});U.args={table:dn};U.parameters={docs:{description:{story:"This is only required when you need to override `columnAlignment` in header cells (i.e. they have different alignment)"}}};const Q=I.bind({});Q.args={table:un};const E=I.bind({});E.args={table:pn};E.decorators=[g=>n.jsx("div",{style:{position:"absolute",inset:0,padding:"var(--padding)"},children:n.jsx(g,{})})];const N=I.bind({});N.args={table:gn};N.parameters={docs:{description:{story:"If a `maxHeight` is set, the table should only fill that height if it needs to."}}};const G=I.bind({});G.args={table:mn};const q=()=>n.jsx(sn,{heading:n.jsx(ln,{children:"Card heading"}),padding:!1,children:n.jsx(A,{table:{...ne,bordered:!1}})});q.parameters={docs:{source:{type:"dynamic"}}};const z=()=>{const g=["Section","Width","Height"];let u=["","m","m"],r=[...Array(175).keys()].map((s,t)=>[t,t*2,t*2]);const T=(s,t,i)=>s==="m"&&t==="ft"?i*3.28084:s==="ft"&&t==="m"?i/3.28084:i,o=(s,t,i,p)=>{r[t][i]=s.target.value,p()},C=s=>{r=r.concat([["","",""]]),s()},k=(s,t)=>{r=r.filter((i,p)=>p!==s),t()},d=(s,t,i)=>{const p=u[t],y=s.target.value;u=u.map((R,h)=>h===t?y:R),r=r.map(R=>R.map((h,b)=>b===t?T(p,y,h):h)),i()},m=()=>{const s=[{label:"10 / page",value:10},{label:"20 / page",value:20},{label:"50 / page",value:50},{label:"Show all",value:0}],[t,i]=S.useState(10),[p,y]=S.useState(1),[R,h]=S.useState(!1),b=()=>{h(!R)},W=()=>{const e=Math.ceil(r.length/t);y(e)},D=(p-1)*t,a=t===0?r.length-1:D+t,c={headers:[{cells:g.map(e=>({value:e})),actions:[{primary:!0,label:"Add",icon:"add",onClick:()=>{C(b),W()}}]},{cells:[{},{options:[{label:"m",value:"m"},{label:"ft",value:"ft"}],value:u[1],type:"Select",native:!0,onChange:e=>d(e,1,b)},{options:[{label:"m",value:"m"},{label:"ft",value:"ft"}],value:u[2],type:"Select",native:!0,onChange:e=>d(e,2,b)}]}],rows:r.slice(D,a).map((e,l)=>{const P=D+l;return{cells:[...Array(3).keys()].map((f,w)=>({value:e[w],type:"Input",onChange:x=>o(x,P,w,b)})),actions:[{label:"Delete",icon:"minus",onClick:()=>k(P,b)}]}}),footer:{pagination:{rowCount:r.length,selectedPage:p,rowsPerPage:{onChange:e=>{const{value:l}=e.target;i(Number(l))},options:s,value:t},onSelectPage:e=>y(e),small:!0}}};return n.jsx(A,{table:c})};return n.jsx(m,{})},J=()=>{const g=["Section","Width","Height"];let u=[...Array(175).keys()].map((T,o)=>({Section:o,Width:o*2,Height:o*2}));const r=()=>{const T=[{label:"10 / page",value:10},{label:"20 / page",value:20},{label:"50 / page",value:50},{label:"Show all",value:0}],[o,C]=S.useState(10),[k,d]=S.useState(1),[m,s]=S.useState({}),[t,i]=S.useState({});S.useEffect(()=>{d(1)},[m,t]);const p=(k-1)*o,y=o===0?u.length-1:p+o,R=(e,l,P)=>e.filter(f=>Object.keys(l).every(w=>l[w]===""?!0:f[w].toString().includes(l[w]))).sort((f,w)=>Object.entries(P).map(([x,F])=>{switch(F){case"up":return f[x]-w[x];case"down":return w[x]-f[x];default:return 0}}).reduce((x,F)=>x||F,0)),h=(e,l,P,f,w)=>{const x=e.map(v=>{const j=Object.keys(f).includes(v)?f[v]:"",H=`${v[0].toUpperCase()}${v.slice(1)}`;return{key:v,value:H,hasSort:!0,sort:j,onSort:()=>{const $=j===""?"up":j==="up"?"down":"";w({...f,[v]:$})}}}),F=e.map(v=>{const j=Object.keys(l).includes(v)?l[v]:"";return{key:v,value:j,type:"Input",placeholder:"Filter",onChange:H=>P({...l,[v]:H.target.value})}});return{dataSortCells:x,dataFilterCells:F}},{dataSortCells:b,dataFilterCells:W}=h(g,m,s,t,i),D=R(u,m,t),a=[...D.slice(p,y).map(e=>({cells:Object.entries(e).map(([P,f])=>({key:P,value:f,type:"Input",disabled:!0}))}))],c={headers:[{cells:b},{cells:W}],rows:a,footer:{pagination:{rowCount:D.length,selectedPage:k,rowsPerPage:{onChange:e=>{const{value:l}=e.target;C(Number(l))},options:T,value:o},onSelectPage:e=>d(e),small:!0}}};return n.jsx(A,{table:c})};return n.jsx(r,{})},X=()=>{const g={tea:3.6,coffee:3.2,orange:4.1},u=[{label:"Tea",value:"tea"},{label:"Coffee",value:"coffee"},{label:"Orange juice",value:"orange"}],r={cells:[{type:"Select",options:u,value:{value:"tea"}},{type:"Input"},{type:"Static"}]},T=[...Array(15).keys()].map((a,c)=>({cells:[{type:"Select",options:u,value:{value:"tea"}},{type:"Input",value:c+1},{type:"Static"}]})),[o,C]=S.useState(T),k=[{label:"10 / page",value:10},{label:"20 / page",value:20},{label:"50 / page",value:50},{label:"Show all",value:0}],[d,m]=S.useState(10),[s,t]=S.useState(1),i=(s-1)*d,p=d===0?o.length-1:i+d,y=({newRow:a}={})=>{const c=B(o,e=>{e.push(a??r)});C(c)},R=({rowIndex:a})=>{const c=B(o,e=>{delete e[a]}).filter(e=>e);C(c)},h=({rowIndex:a,value:c})=>{const e=B(o,l=>{l[a].cells[0].value.value=c});C(e)},b=({rowIndex:a,value:c})=>{const e=B(o,l=>{l[a].cells[1].value=c});C(e)},W=({value:a})=>{const c=Number(a);return!oe.isNaN(c)&&oe.isInteger(c)&&c>0},D=o.slice(i,p).map((a,c)=>{const e=i+c;return o.length-1,{...a,cells:a==null?void 0:a.cells.map((l,P)=>{var v,j,H,$,le;const f=(H=(j=(v=a==null?void 0:a.cells)==null?void 0:v[0])==null?void 0:j.value)==null?void 0:H.value,w=Number((le=($=a==null?void 0:a.cells)==null?void 0:$[1])==null?void 0:le.value),x=g==null?void 0:g[f],F=x&&W({value:w})?(x*w).toFixed(2):null;if(P===0)return{...l,onChange:te=>h({rowIndex:e,value:te.target.value})};if(P===1)return{...l,onChange:te=>b({rowIndex:e,value:te.target.value}),error:W({value:l.value})?null:"Must be valid whole number"};if(P===2)return{...l,value:F}}),actions:[{label:"Delete",icon:"minus",onClick:()=>R({rowIndex:e})}]}});return n.jsx(A,{table:{defaultEmptyRow:r,onAddRow:y,columnAlignment:["left","right","right"],headers:[{cells:[{value:"Drink"},{value:"Quantity"},{value:"Total Price (£)"}],actions:[{primary:!0,icon:"plus",label:"Add",onClick:()=>y()}]}],rows:D,footer:{pagination:{rowCount:o.length,selectedPage:s,rowsPerPage:{onChange:a=>{const{value:c}=a.target;m(Number(c))},options:k,value:d},onSelectPage:a=>t(a),small:!0}}}})},Y=()=>{const g=["Section","Width","Height"];let u=Array.from(Array(10),(d,m)=>[m,m*2,m*2]);const[r,T]=S.useState({pastedValues:"",rowIndex:0,cellIndex:0}),o=(d,m,s,t)=>{u[m][s]=Number(d.target.value),t()},C=(d,m,s,t)=>{var p;let i=((p=d==null?void 0:d.clipboardData)==null?void 0:p.getData("text"))??"";return T({rowIndex:m,cellIndex:s,pastedValues:i}),t(),{pastedData:r}},k=()=>{const[d,m]=S.useState(!1),s=()=>{m(!d)},t={headers:[{cells:g.map(i=>({value:i}))}],rows:u.map((i,p)=>{const y=p;return{cells:[...Array(3).keys()].map((R,h)=>({value:i[h],type:"Input",onChange:b=>o(b,y,h,s),onPaste:b=>C(b,y,h,s)}))}})};return n.jsxs(n.Fragment,{children:[n.jsx(A,{table:t}),n.jsx(re,{label:"Pasted Data",children:n.jsx(ae,{value:r.pastedValues})}),n.jsx(re,{label:"At Row",children:n.jsx(ae,{value:r.rowIndex})}),n.jsx(re,{label:"At Cell Index",children:n.jsx(ae,{value:r.cellIndex})})]})};return n.jsx(k,{})},Z=()=>{const g={fixedWidth:"auto",name:"Table title",actions:[{icon:"download",tooltip:"Download"}],columnAlignment:[...Array(10)].map((u,r)=>"right"),headers:[{cells:[...Array(10)].map((u,r)=>({value:"Heading"}))},{cells:[...Array(10)].map((u,r)=>({options:[{label:"m",value:"m"},{label:"ft",value:"ft"}],type:"Select",searchable:!1,value:{label:"m",value:"m"},autoLayerWidth:!0}))}],rows:[...Array(10)].map((u,r)=>({cells:[...Array(10)].map((T,o)=>({value:123.45})),actions:[{icon:"help",tooltip:n.jsxs(se,{children:[n.jsx(V,{bold:!0,children:"Title goes here lorem ipsum"}),n.jsx(V,{children:"Label: 123.45m"}),n.jsx(V,{children:"Another label: 123.45m"}),n.jsx(V,{children:"Label: 123.45m"})]})}]}))};return n.jsx(A,{table:g})},ee=()=>{const g={fixedWidth:"auto",name:"Table title",actions:[{icon:"download",tooltip:"Download"}],headers:[{cells:[{value:"Label"},{value:"Value",colSpan:2}]}],rows:[{cells:[{value:"Country",style:{fontWeight:"bold"},width:"120px"},{value:"Norway",colSpan:2}],actions:[{icon:"help",tooltip:n.jsxs(se,{children:[n.jsx(V,{bold:!0,children:"Title goes here"}),n.jsx(V,{children:"Details go here"})]})}]},{cells:[{value:"Depth",style:{fontWeight:"bold"}},{value:123,width:"80px"},{options:[{label:"m",value:"m"},{label:"ft",value:"ft"}],value:{label:"m",value:"m"},type:"Select",width:"80px"}],actions:[{icon:"help",tooltip:n.jsxs(se,{children:[n.jsx(V,{bold:!0,children:"Title goes here"}),n.jsx(V,{children:"Details go here"})]})}]}]};return n.jsx(A,{table:g})};var ie,ce,de;K.parameters={...K.parameters,docs:{...(ie=K.parameters)==null?void 0:ie.docs,source:{originalSource:`args => {
|
|
1
|
+
import{j as n}from"./jsx-runtime-FsUICBgo.js";import{r as S}from"./index-RfLt4OUa.js";import{f as B}from"./immer.esm-bD7SSJ7T.js";import{l as oe}from"./lodash-Bmg8FrMx.js";import{G as se}from"./grid-u1mZpaML.js";import{T as V}from"./text-6KQ6ntOV.js";import{T as A}from"./table-5HZEOUW_.js";import{C as sn}from"./card-0r8RRVk-.js";import{I as ae}from"./input-2BhbKV-j.js";import{F as re}from"./field-FZX0Z7IB.js";import{H as ln}from"./heading-jZsIIJF0.js";import{t as ne,v as on,w as cn,x as dn,y as un,z as pn,A as gn,B as mn}from"./table.stories-data-NfE_v-gH.js";import"./styled-components.browser.esm-qIipjd6c.js";import"./tslib.es6-OIsz3r9a.js";import"./index-VW3EWkuE.js";import"./index.es-VXFRDikp.js";import"./inheritsLoose-8sb_A2v4.js";import"./redux-F5dueAP3.js";import"./objectSpread2-93s0nBry.js";import"./tiny-invariant-R4kOKlvx.js";import"./index-miLrID2P.js";import"./memoize-one.esm-hqe5SRxC.js";import"./objectWithoutPropertiesLoose-9Q1jwsKS.js";import"./actions-mOcj9IlF.js";import"./common-types-U65vzrrz.js";import"./disabled-context-urNQThQz.js";import"./button-shH4xakS.js";import"./spinner-R8Il4aRe.js";import"./icon-8EQazuuW.js";import"./index-4QtD-hFu.js";import"./tooltip-HEHiU__l.js";import"./types-VB5zD18b.js";import"./types-5uVBABF4.js";import"./badge-23Ty_zBt.js";import"./pagination-tnyyuMkB.js";import"./select-DZdWUrCW.js";import"./assertThisInitialized-4q6YPdh3.js";import"./select.input-zP5tW20f.js";import"./input-group-R8LoqKRn.js";import"./input-group-addon-BHVsW9mL.js";import"./number-input-CMhEMmUd.js";import"./index-qZmQ7nA9.js";import"./index-cCpkwrS5.js";import"./check-box-2gxosI3y.js";import"./help-icon-SKky6KLV.js";import"./slider-MN9iDCsS.js";import"./index-ugi_ZH6T.js";import"./popover-cad2llTa.js";import"./label-uCFEME1p.js";import"./flex-RYZsoWEN.js";const ut={title:"Basic/Table",component:A,args:{table:{...ne}}},I=g=>n.jsx(A,{...g}),K=I.bind({}),_=I.bind({});_.args={table:{...ne,fixedWidth:"400px"}};const M=I.bind({});M.args={table:{...ne,fixedWidth:"auto"}};const O=I.bind({});O.args={table:on};O.parameters={docs:{description:{story:"Use sparingly when certain columns cannot be below a certain width. Unless the Table is auto width, set one column to `auto` to use remaining space."}}};const L=I.bind({});L.args={table:cn};const U=I.bind({});U.args={table:dn};U.parameters={docs:{description:{story:"This is only required when you need to override `columnAlignment` in header cells (i.e. they have different alignment)"}}};const Q=I.bind({});Q.args={table:un};const E=I.bind({});E.args={table:pn};E.decorators=[g=>n.jsx("div",{style:{position:"absolute",inset:0,padding:"var(--padding)"},children:n.jsx(g,{})})];const N=I.bind({});N.args={table:gn};N.parameters={docs:{description:{story:"If a `maxHeight` is set, the table should only fill that height if it needs to."}}};const G=I.bind({});G.args={table:mn};const q=()=>n.jsx(sn,{heading:n.jsx(ln,{children:"Card heading"}),padding:!1,children:n.jsx(A,{table:{...ne,bordered:!1}})});q.parameters={docs:{source:{type:"dynamic"}}};const z=()=>{const g=["Section","Width","Height"];let u=["","m","m"],r=[...Array(175).keys()].map((s,t)=>[t,t*2,t*2]);const T=(s,t,i)=>s==="m"&&t==="ft"?i*3.28084:s==="ft"&&t==="m"?i/3.28084:i,o=(s,t,i,p)=>{r[t][i]=s.target.value,p()},C=s=>{r=r.concat([["","",""]]),s()},k=(s,t)=>{r=r.filter((i,p)=>p!==s),t()},d=(s,t,i)=>{const p=u[t],y=s.target.value;u=u.map((R,h)=>h===t?y:R),r=r.map(R=>R.map((h,b)=>b===t?T(p,y,h):h)),i()},m=()=>{const s=[{label:"10 / page",value:10},{label:"20 / page",value:20},{label:"50 / page",value:50},{label:"Show all",value:0}],[t,i]=S.useState(10),[p,y]=S.useState(1),[R,h]=S.useState(!1),b=()=>{h(!R)},W=()=>{const e=Math.ceil(r.length/t);y(e)},D=(p-1)*t,a=t===0?r.length-1:D+t,c={headers:[{cells:g.map(e=>({value:e})),actions:[{primary:!0,label:"Add",icon:"add",onClick:()=>{C(b),W()}}]},{cells:[{},{options:[{label:"m",value:"m"},{label:"ft",value:"ft"}],value:u[1],type:"Select",native:!0,onChange:e=>d(e,1,b)},{options:[{label:"m",value:"m"},{label:"ft",value:"ft"}],value:u[2],type:"Select",native:!0,onChange:e=>d(e,2,b)}]}],rows:r.slice(D,a).map((e,l)=>{const P=D+l;return{cells:[...Array(3).keys()].map((f,w)=>({value:e[w],type:"Input",onChange:x=>o(x,P,w,b)})),actions:[{label:"Delete",icon:"minus",onClick:()=>k(P,b)}]}}),footer:{pagination:{rowCount:r.length,selectedPage:p,rowsPerPage:{onChange:e=>{const{value:l}=e.target;i(Number(l))},options:s,value:t},onSelectPage:e=>y(e),small:!0}}};return n.jsx(A,{table:c})};return n.jsx(m,{})},J=()=>{const g=["Section","Width","Height"];let u=[...Array(175).keys()].map((T,o)=>({Section:o,Width:o*2,Height:o*2}));const r=()=>{const T=[{label:"10 / page",value:10},{label:"20 / page",value:20},{label:"50 / page",value:50},{label:"Show all",value:0}],[o,C]=S.useState(10),[k,d]=S.useState(1),[m,s]=S.useState({}),[t,i]=S.useState({});S.useEffect(()=>{d(1)},[m,t]);const p=(k-1)*o,y=o===0?u.length-1:p+o,R=(e,l,P)=>e.filter(f=>Object.keys(l).every(w=>l[w]===""?!0:f[w].toString().includes(l[w]))).sort((f,w)=>Object.entries(P).map(([x,F])=>{switch(F){case"up":return f[x]-w[x];case"down":return w[x]-f[x];default:return 0}}).reduce((x,F)=>x||F,0)),h=(e,l,P,f,w)=>{const x=e.map(v=>{const j=Object.keys(f).includes(v)?f[v]:"",H=`${v[0].toUpperCase()}${v.slice(1)}`;return{key:v,value:H,hasSort:!0,sort:j,onSort:()=>{const $=j===""?"up":j==="up"?"down":"";w({...f,[v]:$})}}}),F=e.map(v=>{const j=Object.keys(l).includes(v)?l[v]:"";return{key:v,value:j,type:"Input",placeholder:"Filter",onChange:H=>P({...l,[v]:H.target.value})}});return{dataSortCells:x,dataFilterCells:F}},{dataSortCells:b,dataFilterCells:W}=h(g,m,s,t,i),D=R(u,m,t),a=[...D.slice(p,y).map(e=>({cells:Object.entries(e).map(([P,f])=>({key:P,value:f,type:"Input",disabled:!0}))}))],c={headers:[{cells:b},{cells:W}],rows:a,footer:{pagination:{rowCount:D.length,selectedPage:k,rowsPerPage:{onChange:e=>{const{value:l}=e.target;C(Number(l))},options:T,value:o},onSelectPage:e=>d(e),small:!0}}};return n.jsx(A,{table:c})};return n.jsx(r,{})},X=()=>{const g={tea:3.6,coffee:3.2,orange:4.1},u=[{label:"Tea",value:"tea"},{label:"Coffee",value:"coffee"},{label:"Orange juice",value:"orange"}],r={cells:[{type:"Select",options:u,value:{value:"tea"}},{type:"Input"},{type:"Static"}]},T=[...Array(15).keys()].map((a,c)=>({cells:[{type:"Select",options:u,value:{value:"tea"}},{type:"Input",value:c+1},{type:"Static"}]})),[o,C]=S.useState(T),k=[{label:"10 / page",value:10},{label:"20 / page",value:20},{label:"50 / page",value:50},{label:"Show all",value:0}],[d,m]=S.useState(10),[s,t]=S.useState(1),i=(s-1)*d,p=d===0?o.length-1:i+d,y=({newRow:a}={})=>{const c=B(o,e=>{e.push(a??r)});C(c)},R=({rowIndex:a})=>{const c=B(o,e=>{delete e[a]}).filter(e=>e);C(c)},h=({rowIndex:a,value:c})=>{const e=B(o,l=>{l[a].cells[0].value.value=c});C(e)},b=({rowIndex:a,value:c})=>{const e=B(o,l=>{l[a].cells[1].value=c});C(e)},W=({value:a})=>{const c=Number(a);return!oe.isNaN(c)&&oe.isInteger(c)&&c>0},D=o.slice(i,p).map((a,c)=>{const e=i+c;return o.length-1,{...a,cells:a==null?void 0:a.cells.map((l,P)=>{var v,j,H,$,le;const f=(H=(j=(v=a==null?void 0:a.cells)==null?void 0:v[0])==null?void 0:j.value)==null?void 0:H.value,w=Number((le=($=a==null?void 0:a.cells)==null?void 0:$[1])==null?void 0:le.value),x=g==null?void 0:g[f],F=x&&W({value:w})?(x*w).toFixed(2):null;if(P===0)return{...l,onChange:te=>h({rowIndex:e,value:te.target.value})};if(P===1)return{...l,onChange:te=>b({rowIndex:e,value:te.target.value}),error:W({value:l.value})?null:"Must be valid whole number"};if(P===2)return{...l,value:F}}),actions:[{label:"Delete",icon:"minus",onClick:()=>R({rowIndex:e})}]}});return n.jsx(A,{table:{defaultEmptyRow:r,onAddRow:y,columnAlignment:["left","right","right"],headers:[{cells:[{value:"Drink"},{value:"Quantity"},{value:"Total Price (£)"}],actions:[{primary:!0,icon:"plus",label:"Add",onClick:()=>y()}]}],rows:D,footer:{pagination:{rowCount:o.length,selectedPage:s,rowsPerPage:{onChange:a=>{const{value:c}=a.target;m(Number(c))},options:k,value:d},onSelectPage:a=>t(a),small:!0}}}})},Y=()=>{const g=["Section","Width","Height"];let u=Array.from(Array(10),(d,m)=>[m,m*2,m*2]);const[r,T]=S.useState({pastedValues:"",rowIndex:0,cellIndex:0}),o=(d,m,s,t)=>{u[m][s]=Number(d.target.value),t()},C=(d,m,s,t)=>{var p;let i=((p=d==null?void 0:d.clipboardData)==null?void 0:p.getData("text"))??"";return T({rowIndex:m,cellIndex:s,pastedValues:i}),t(),{pastedData:r}},k=()=>{const[d,m]=S.useState(!1),s=()=>{m(!d)},t={headers:[{cells:g.map(i=>({value:i}))}],rows:u.map((i,p)=>{const y=p;return{cells:[...Array(3).keys()].map((R,h)=>({value:i[h],type:"Input",onChange:b=>o(b,y,h,s),onPaste:b=>C(b,y,h,s)}))}})};return n.jsxs(n.Fragment,{children:[n.jsx(A,{table:t}),n.jsx(re,{label:"Pasted Data",children:n.jsx(ae,{value:r.pastedValues})}),n.jsx(re,{label:"At Row",children:n.jsx(ae,{value:r.rowIndex})}),n.jsx(re,{label:"At Cell Index",children:n.jsx(ae,{value:r.cellIndex})})]})};return n.jsx(k,{})},Z=()=>{const g={fixedWidth:"auto",name:"Table title",actions:[{icon:"download",tooltip:"Download"}],columnAlignment:[...Array(10)].map((u,r)=>"right"),headers:[{cells:[...Array(10)].map((u,r)=>({value:"Heading"}))},{cells:[...Array(10)].map((u,r)=>({options:[{label:"m",value:"m"},{label:"ft",value:"ft"}],type:"Select",searchable:!1,value:{label:"m",value:"m"},autoLayerWidth:!0}))}],rows:[...Array(10)].map((u,r)=>({cells:[...Array(10)].map((T,o)=>({value:123.45})),actions:[{icon:"help",tooltip:n.jsxs(se,{children:[n.jsx(V,{bold:!0,children:"Title goes here lorem ipsum"}),n.jsx(V,{children:"Label: 123.45m"}),n.jsx(V,{children:"Another label: 123.45m"}),n.jsx(V,{children:"Label: 123.45m"})]})}]}))};return n.jsx(A,{table:g})},ee=()=>{const g={fixedWidth:"auto",name:"Table title",actions:[{icon:"download",tooltip:"Download"}],headers:[{cells:[{value:"Label"},{value:"Value",colSpan:2}]}],rows:[{cells:[{value:"Country",style:{fontWeight:"bold"},width:"120px"},{value:"Norway",colSpan:2}],actions:[{icon:"help",tooltip:n.jsxs(se,{children:[n.jsx(V,{bold:!0,children:"Title goes here"}),n.jsx(V,{children:"Details go here"})]})}]},{cells:[{value:"Depth",style:{fontWeight:"bold"}},{value:123,width:"80px"},{options:[{label:"m",value:"m"},{label:"ft",value:"ft"}],value:{label:"m",value:"m"},type:"Select",width:"80px"}],actions:[{icon:"help",tooltip:n.jsxs(se,{children:[n.jsx(V,{bold:!0,children:"Title goes here"}),n.jsx(V,{children:"Details go here"})]})}]}]};return n.jsx(A,{table:g})};var ie,ce,de;K.parameters={...K.parameters,docs:{...(ie=K.parameters)==null?void 0:ie.docs,source:{originalSource:`args => {
|
|
2
2
|
return <Table
|
|
3
3
|
// eslint-disable-next-line react/jsx-props-no-spreading
|
|
4
4
|
{...args} />;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{j as o}from"./jsx-runtime-FsUICBgo.js";import{r as V}from"./index-RfLt4OUa.js";import{c as h}from"./index-VW3EWkuE.js";import{i as l}from"./types-5uVBABF4.js";import{D as z}from"./disabled-context-urNQThQz.js";import{T as k}from"./tooltip-HEHiU__l.js";const I="_inputInTable_66zck_1",N="_inputHover_66zck_13",R="_inputFocus_66zck_18",C="_inputError_66zck_25",S="_inputWarning_66zck_26",A="_inputDisabled_66zck_61",F="_hideScrollbars_66zck_67",H="_textarea_66zck_77",W="_small_66zck_116",w="_error_66zck_121",D="_warning_66zck_138",P="_monospace_66zck_155",t={inputInTable:I,inputHover:N,inputFocus:R,inputError:C,inputWarning:S,inputDisabled:A,hideScrollbars:F,textarea:H,small:W,error:w,warning:D,monospace:P},i=({name:r,value:u="",placeholder:s="",cols:d,rows:c,disabled:m=!1,onChange:p=()=>{},onKeyPress:f=()=>{},onFocus:v=()=>{},onBlur:_=()=>{},tabIndex:b=0,error:e=null,warning:a=null,tooltip:n=null,maxTooltipWidth:y,resize:x,monospace:g=!1,testId:E})=>{const T=V.useContext(z),q=o.jsx("textarea",{className:h(t.textarea,e?t.error:"",a?t.warning:"",g?t.monospace:""),name:r,value:u,placeholder:s,cols:d,rows:c,onChange:p,disabled:m||T,onKeyPress:f,onFocus:v,onBlur:_,tabIndex:b,style:{resize:x},"data-testid":E});return o.jsx(k,{error:!!e,warning:!!a,text:n||e||a,enabled:n&&l(n)||e&&l(e)||a&&l(a)||!1,maxWidth:y,placement:"bottom-center",children:q})};try{i.displayName="TextArea",i.__docgenInfo={description:"",displayName:"TextArea",props:{name:{defaultValue:null,description:"",name:"name",required:!1,type:{name:"string"}},value:{defaultValue:{value:""},description:"",name:"value",required:!1,type:{name:"TStringOrNumber"}},placeholder:{defaultValue:{value:""},description:"",name:"placeholder",required:!1,type:{name:"string"}},cols:{defaultValue:null,description:"",name:"cols",required:!1,type:{name:"number"}},rows:{defaultValue:null,description:"",name:"rows",required:!1,type:{name:"number"}},disabled:{defaultValue:{value:"false"},description:"",name:"disabled",required:!1,type:{name:"boolean"}},onChange:{defaultValue:{value:"() => {}"},description:"",name:"onChange",required:!1,type:{name:"((evt: ChangeEvent<HTMLTextAreaElement>) => void)"}},onKeyPress:{defaultValue:{value:"() => {}"},description:"",name:"onKeyPress",required:!1,type:{name:"((evt: KeyboardEvent<HTMLTextAreaElement>) => void)"}},onFocus:{defaultValue:{value:"() => {}"},description:"",name:"onFocus",required:!1,type:{name:"((evt: FocusEvent<HTMLTextAreaElement, Element>) => void)"}},onBlur:{defaultValue:{value:"() => {}"},description:"",name:"onBlur",required:!1,type:{name:"((evt: FocusEvent<HTMLTextAreaElement, Element>) => void)"}},tabIndex:{defaultValue:{value:"0"},description:"",name:"tabIndex",required:!1,type:{name:"number"}},error:{defaultValue:{value:"null"},description:"",name:"error",required:!1,type:{name:"string | number | boolean | ReactElement<any, string | JSXElementConstructor<any>> | Iterable<ReactNode> | ReactPortal | null"}},warning:{defaultValue:{value:"null"},description:"",name:"warning",required:!1,type:{name:"string | number | boolean | ReactElement<any, string | JSXElementConstructor<any>> | Iterable<ReactNode> | ReactPortal | null"}},tooltip:{defaultValue:{value:"null"},description:"",name:"tooltip",required:!1,type:{name:"string | number | boolean | ReactElement<any, string | JSXElementConstructor<any>> | Iterable<ReactNode> | ReactPortal | null"}},maxTooltipWidth:{defaultValue:null,description:"",name:"maxTooltipWidth",required:!1,type:{name:"TStringOrNumber"}},resize:{defaultValue:null,description:"",name:"resize",required:!1,type:{name:"enum",value:[{value:'"
|
|
1
|
+
import{j as o}from"./jsx-runtime-FsUICBgo.js";import{r as V}from"./index-RfLt4OUa.js";import{c as h}from"./index-VW3EWkuE.js";import{i as l}from"./types-5uVBABF4.js";import{D as z}from"./disabled-context-urNQThQz.js";import{T as k}from"./tooltip-HEHiU__l.js";const I="_inputInTable_66zck_1",N="_inputHover_66zck_13",R="_inputFocus_66zck_18",C="_inputError_66zck_25",S="_inputWarning_66zck_26",A="_inputDisabled_66zck_61",F="_hideScrollbars_66zck_67",H="_textarea_66zck_77",W="_small_66zck_116",w="_error_66zck_121",D="_warning_66zck_138",P="_monospace_66zck_155",t={inputInTable:I,inputHover:N,inputFocus:R,inputError:C,inputWarning:S,inputDisabled:A,hideScrollbars:F,textarea:H,small:W,error:w,warning:D,monospace:P},i=({name:r,value:u="",placeholder:s="",cols:d,rows:c,disabled:m=!1,onChange:p=()=>{},onKeyPress:f=()=>{},onFocus:v=()=>{},onBlur:_=()=>{},tabIndex:b=0,error:e=null,warning:a=null,tooltip:n=null,maxTooltipWidth:y,resize:x,monospace:g=!1,testId:E})=>{const T=V.useContext(z),q=o.jsx("textarea",{className:h(t.textarea,e?t.error:"",a?t.warning:"",g?t.monospace:""),name:r,value:u,placeholder:s,cols:d,rows:c,onChange:p,disabled:m||T,onKeyPress:f,onFocus:v,onBlur:_,tabIndex:b,style:{resize:x},"data-testid":E});return o.jsx(k,{error:!!e,warning:!!a,text:n||e||a,enabled:n&&l(n)||e&&l(e)||a&&l(a)||!1,maxWidth:y,placement:"bottom-center",children:q})};try{i.displayName="TextArea",i.__docgenInfo={description:"",displayName:"TextArea",props:{name:{defaultValue:null,description:"",name:"name",required:!1,type:{name:"string"}},value:{defaultValue:{value:""},description:"",name:"value",required:!1,type:{name:"TStringOrNumber"}},placeholder:{defaultValue:{value:""},description:"",name:"placeholder",required:!1,type:{name:"string"}},cols:{defaultValue:null,description:"",name:"cols",required:!1,type:{name:"number"}},rows:{defaultValue:null,description:"",name:"rows",required:!1,type:{name:"number"}},disabled:{defaultValue:{value:"false"},description:"",name:"disabled",required:!1,type:{name:"boolean"}},onChange:{defaultValue:{value:"() => {}"},description:"",name:"onChange",required:!1,type:{name:"((evt: ChangeEvent<HTMLTextAreaElement>) => void)"}},onKeyPress:{defaultValue:{value:"() => {}"},description:"",name:"onKeyPress",required:!1,type:{name:"((evt: KeyboardEvent<HTMLTextAreaElement>) => void)"}},onFocus:{defaultValue:{value:"() => {}"},description:"",name:"onFocus",required:!1,type:{name:"((evt: FocusEvent<HTMLTextAreaElement, Element>) => void)"}},onBlur:{defaultValue:{value:"() => {}"},description:"",name:"onBlur",required:!1,type:{name:"((evt: FocusEvent<HTMLTextAreaElement, Element>) => void)"}},tabIndex:{defaultValue:{value:"0"},description:"",name:"tabIndex",required:!1,type:{name:"number"}},error:{defaultValue:{value:"null"},description:"",name:"error",required:!1,type:{name:"string | number | boolean | ReactElement<any, string | JSXElementConstructor<any>> | Iterable<ReactNode> | ReactPortal | null"}},warning:{defaultValue:{value:"null"},description:"",name:"warning",required:!1,type:{name:"string | number | boolean | ReactElement<any, string | JSXElementConstructor<any>> | Iterable<ReactNode> | ReactPortal | null"}},tooltip:{defaultValue:{value:"null"},description:"",name:"tooltip",required:!1,type:{name:"string | number | boolean | ReactElement<any, string | JSXElementConstructor<any>> | Iterable<ReactNode> | ReactPortal | null"}},maxTooltipWidth:{defaultValue:null,description:"",name:"maxTooltipWidth",required:!1,type:{name:"TStringOrNumber"}},resize:{defaultValue:null,description:"",name:"resize",required:!1,type:{name:"enum",value:[{value:'"-moz-initial"'},{value:'"inherit"'},{value:'"initial"'},{value:'"revert"'},{value:'"revert-layer"'},{value:'"unset"'},{value:'"inline"'},{value:'"block"'},{value:'"both"'},{value:'"horizontal"'},{value:'"none"'},{value:'"vertical"'}]}},monospace:{defaultValue:{value:"false"},description:"",name:"monospace",required:!1,type:{name:"boolean"}},testId:{defaultValue:null,description:"",name:"testId",required:!1,type:{name:"string"}}}}}catch{}export{i as T};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{j as u}from"./jsx-runtime-FsUICBgo.js";import{T as s}from"./textarea-
|
|
1
|
+
import{j as u}from"./jsx-runtime-FsUICBgo.js";import{T as s}from"./textarea-TSoWqDT8.js";import"./index-RfLt4OUa.js";import"./index-VW3EWkuE.js";import"./types-5uVBABF4.js";import"./lodash-Bmg8FrMx.js";import"./disabled-context-urNQThQz.js";import"./tooltip-HEHiU__l.js";import"./index-miLrID2P.js";const{useArgs:g}=__STORYBOOK_MODULE_ADDONS__,C={title:"Forms/TextArea",component:s,args:{disabled:!1}},c=n=>{const[i,o]=g(),m=p=>{o({value:p.target.value})};return u.jsx(s,{...n,onChange:m})},e=c.bind({});var t,r,a;e.parameters={...e.parameters,docs:{...(t=e.parameters)==null?void 0:t.docs,source:{originalSource:`args => {
|
|
2
2
|
const [_, updateArgs] = useArgs();
|
|
3
3
|
const handleChange = (evt: ChangeEvent<HTMLTextAreaElement>) => {
|
|
4
4
|
updateArgs({
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{j as D}from"./jsx-runtime-FsUICBgo.js";import{T as X}from"./table-
|
|
1
|
+
import{j as D}from"./jsx-runtime-FsUICBgo.js";import{T as X}from"./table-5HZEOUW_.js";import{t as G,C as O,s as W,D as k,E as q,F as z,G as K,H as M,I as P,J as Q}from"./table.stories-data-NfE_v-gH.js";import"./index-RfLt4OUa.js";import"./index-VW3EWkuE.js";import"./index.es-VXFRDikp.js";import"./inheritsLoose-8sb_A2v4.js";import"./redux-F5dueAP3.js";import"./objectSpread2-93s0nBry.js";import"./tiny-invariant-R4kOKlvx.js";import"./index-miLrID2P.js";import"./memoize-one.esm-hqe5SRxC.js";import"./objectWithoutPropertiesLoose-9Q1jwsKS.js";import"./lodash-Bmg8FrMx.js";import"./actions-mOcj9IlF.js";import"./common-types-U65vzrrz.js";import"./disabled-context-urNQThQz.js";import"./button-shH4xakS.js";import"./spinner-R8Il4aRe.js";import"./icon-8EQazuuW.js";import"./tslib.es6-OIsz3r9a.js";import"./index-4QtD-hFu.js";import"./tooltip-HEHiU__l.js";import"./types-VB5zD18b.js";import"./types-5uVBABF4.js";import"./badge-23Ty_zBt.js";import"./heading-jZsIIJF0.js";import"./help-icon-SKky6KLV.js";import"./pagination-tnyyuMkB.js";import"./select-DZdWUrCW.js";import"./assertThisInitialized-4q6YPdh3.js";import"./text-6KQ6ntOV.js";import"./select.input-zP5tW20f.js";import"./input-2BhbKV-j.js";import"./input-group-R8LoqKRn.js";import"./input-group-addon-BHVsW9mL.js";import"./number-input-CMhEMmUd.js";import"./index-qZmQ7nA9.js";import"./index-cCpkwrS5.js";import"./check-box-2gxosI3y.js";import"./slider-MN9iDCsS.js";import"./index-ugi_ZH6T.js";import"./popover-cad2llTa.js";import"./flex-RYZsoWEN.js";const Gr={title:"Basic/Table/Title & Header",component:X,args:{table:{...G}}},r=B=>D.jsx(X,{...B}),e=r.bind({});e.args={table:O};const s=r.bind({});s.args={table:W};const a=r.bind({});a.args={table:k};const t=r.bind({});t.args={table:q};const o=r.bind({});o.args={table:z};const n=r.bind({});n.args={table:K};const i=r.bind({});i.args={table:M};const p=r.bind({});p.args={table:P};const l=r.bind({});l.args={table:Q};var m,c,d;e.parameters={...e.parameters,docs:{...(m=e.parameters)==null?void 0:m.docs,source:{originalSource:`args => {
|
|
2
2
|
return <Table
|
|
3
3
|
// eslint-disable-next-line react/jsx-props-no-spreading
|
|
4
4
|
{...args} />;
|
package/dist/storybook/assets/{unit-table.stories-ZHWCQMuq.js → unit-table.stories-M8TmG1IT.js}
RENAMED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{j as n}from"./jsx-runtime-FsUICBgo.js";import{r as v}from"./index-RfLt4OUa.js";import{f as Q}from"./immer.esm-bD7SSJ7T.js";import{d as b}from"./index-qZmQ7nA9.js";import{G as Z}from"./grid-u1mZpaML.js";import{C as L}from"./card-0r8RRVk-.js";import{F as V}from"./field-FZX0Z7IB.js";import{H as E}from"./heading-jZsIIJF0.js";import{S as H}from"./select-DZdWUrCW.js";import{T as F}from"./toggle-M_66MP8X.js";import{l as ee}from"./lodash-Bmg8FrMx.js";import{u as te}from"./use-previous-VKMmnaK7.js";import{T as ne,C as P}from"./table-
|
|
1
|
+
import{j as n}from"./jsx-runtime-FsUICBgo.js";import{r as v}from"./index-RfLt4OUa.js";import{f as Q}from"./immer.esm-bD7SSJ7T.js";import{d as b}from"./index-qZmQ7nA9.js";import{G as Z}from"./grid-u1mZpaML.js";import{C as L}from"./card-0r8RRVk-.js";import{F as V}from"./field-FZX0Z7IB.js";import{H as E}from"./heading-jZsIIJF0.js";import{S as H}from"./select-DZdWUrCW.js";import{T as F}from"./toggle-M_66MP8X.js";import{l as ee}from"./lodash-Bmg8FrMx.js";import{u as te}from"./use-previous-VKMmnaK7.js";import{T as ne,C as P}from"./table-5HZEOUW_.js";import"./index-cCpkwrS5.js";import"./styled-components.browser.esm-qIipjd6c.js";import"./tslib.es6-OIsz3r9a.js";import"./index-VW3EWkuE.js";import"./label-uCFEME1p.js";import"./common-types-U65vzrrz.js";import"./help-icon-SKky6KLV.js";import"./tooltip-HEHiU__l.js";import"./index-miLrID2P.js";import"./icon-8EQazuuW.js";import"./objectWithoutPropertiesLoose-9Q1jwsKS.js";import"./inheritsLoose-8sb_A2v4.js";import"./index-4QtD-hFu.js";import"./disabled-context-urNQThQz.js";import"./types-5uVBABF4.js";import"./assertThisInitialized-4q6YPdh3.js";import"./memoize-one.esm-hqe5SRxC.js";import"./types-VB5zD18b.js";import"./text-6KQ6ntOV.js";import"./actions-mOcj9IlF.js";import"./button-shH4xakS.js";import"./spinner-R8Il4aRe.js";import"./badge-23Ty_zBt.js";import"./select.input-zP5tW20f.js";import"./index.es-VXFRDikp.js";import"./redux-F5dueAP3.js";import"./objectSpread2-93s0nBry.js";import"./tiny-invariant-R4kOKlvx.js";import"./pagination-tnyyuMkB.js";import"./input-2BhbKV-j.js";import"./input-group-R8LoqKRn.js";import"./input-group-addon-BHVsW9mL.js";import"./number-input-CMhEMmUd.js";import"./check-box-2gxosI3y.js";import"./slider-MN9iDCsS.js";import"./index-ugi_ZH6T.js";import"./popover-cad2llTa.js";const ae=o=>o.reduce(({preferredUnits:i,storageUnits:r},{unitKey:s,preferredUnit:a,storageUnit:g})=>(i[s]=a,r[s]=g,{preferredUnits:i,storageUnits:r}),{preferredUnits:{},storageUnits:{}}),re=({headers:o,rows:i,selectedUnits:r,storageUnits:s,onChangeUnit:a,convertBackToStorageUnit:g,enableCosmeticRounding:c,enableDisplayRounding:f})=>{const u=o?o.map(m=>({...m,cells:m.cells.map(p=>{var t;if(p.type===P.AUTO_UNIT){const{testId:C,unitKey:d}=p;return{value:r[d],type:P.SELECT,options:(t=b.getUnitsForQuantity(d))==null?void 0:t.map(h=>({label:b.label(h),value:h})),native:p.native,onChange:h=>a({unitKey:d,value:h.target.value}),testId:C}}return p})})):[],l=i?i.map((m,p)=>({...m,cells:m.cells.map((t,C)=>{if("autoUnit"in t&&(t!=null&&t.autoUnit)&&(typeof(t==null?void 0:t.value)=="string"||typeof(t==null?void 0:t.value)=="number")){const{unitKey:d,value:h,formatDisplayValue:U}=t,x=f&&"roundDisplayValue"in t?t==null?void 0:t.roundDisplayValue:null,e=r[d],T=s[d],y=e!==T,S=y?b.convertAndGetValue(h,e,T):t.value,R=b.isScientificStringNum(h),w=c&&(y||!R)?b.roundToPrecision(S,14):S,_=U?U(w):w;return{...t,value:_,enableCosmeticRounding:c,enableDisplayRounding:f,roundDisplayValue:x,onChange:j=>{const{value:W}=j.target,I=s[d],D=r[d],J=D!==I,K=g?I:D,$=J?b.convertAndGetValue(W,K,D):W;if("onChange"in t){const{onChange:X}=t,Y={...j,target:{...j.target,value:String($),rowIndex:p,cellIndex:C,unit:K}};X(Y)}}}}return t})})):[];return{convertedHeaders:u,convertedRows:l}},B=({table:o,unitConfig:i,convertBackToStorageUnit:r=!0,enableCosmeticRounding:s=!0,enableDisplayRounding:a=!0})=>{const{rows:g,headers:c,...f}=o,{storageUnits:u,preferredUnits:l}=ae(i),m=te(l),[p,t]=v.useState(l),C=({unitKey:e,value:T})=>t({...p,[e]:T}),d=e=>re({headers:c,rows:g,selectedUnits:e,storageUnits:u,onChangeUnit:C,convertBackToStorageUnit:r,enableCosmeticRounding:s,enableDisplayRounding:a}),h=d(p),[U,x]=v.useState(h);return v.useEffect(()=>{!ee.isEqual(l,m)&&(t(l),x(d(l)))},[i]),v.useEffect(()=>{x(d(p))},[o,p]),n.jsx(ne,{table:{...f,headers:U.convertedHeaders,rows:U.convertedRows}})};try{B.displayName="UnitTable",B.__docgenInfo={description:"",displayName:"UnitTable",props:{table:{defaultValue:null,description:"",name:"table",required:!0,type:{name:"IUnitTable"}},unitConfig:{defaultValue:null,description:"",name:"unitConfig",required:!0,type:{name:"IUnitConfigItem[]"}},convertBackToStorageUnit:{defaultValue:{value:"true"},description:"",name:"convertBackToStorageUnit",required:!1,type:{name:"boolean"}},enableCosmeticRounding:{defaultValue:{value:"true"},description:"",name:"enableCosmeticRounding",required:!1,type:{name:"boolean"}},enableDisplayRounding:{defaultValue:{value:"true"},description:"",name:"enableDisplayRounding",required:!1,type:{name:"boolean"}},onListReorder:{defaultValue:null,description:"",name:"onListReorder",required:!1,type:{name:"((obj: { from: number; to: number; }) => void)"}}}}}catch{}const dt={title:"Basic/UnitTable",args:{}},oe=!0,ie=!0,le=!0,se=!1,z="m",M="C",ue=3,de=(o,i,r)=>{const s=[i,i,r],a=[...Array(o)].map((g,c)=>{const f=c,u=c+1.25,l=4+c*.25;return[String(f),String(u),String(l)]});return[s,...a]},ce=de(ue,z,M),pe=({reduxTable:o,value:i,unit:r,rowIndex:s,cellIndex:a})=>Q(o,g=>{const c=g[0][a],f=(u,l)=>l===0;return g.forEach((u,l)=>{if(f(u,l)){u[a]=r;return}if(l===s+1){u[a]=String(i);return}const m=b.convertAndGetValue(u[a],r,c);u[a]=String(m)}),g}),ge=({reduxTable:o,value:i,rowIndex:r,cellIndex:s})=>Q(o,a=>{a[r+1][s]=i}),k=()=>{var U,x;const[o,i]=v.useState(z),[r,s]=v.useState(M),[a,g]=v.useState(ce),[c,f]=v.useState(oe),[u,l]=v.useState(le),[m,p]=v.useState(ie),[t,C]=v.useState(se),d=e=>{const{rowIndex:T,cellIndex:y,value:S,unit:R}=e.target,w=t?pe({reduxTable:a,value:S,unit:R,rowIndex:T,cellIndex:y}):ge({reduxTable:a,value:S,rowIndex:T,cellIndex:y});g(w)},h=a.reduce((e,T,y)=>(y===0?e.headers=[{cells:[{value:"From"},{value:"To"},{value:"Temperature"}]},{cells:[{type:"AutoUnit",unitKey:"length"},{type:"AutoUnit",unitKey:"length"},{type:"AutoUnit",unitKey:"temperature",testId:"table-unit-selector-3"}]}]:e.rows=e.rows.concat({cells:T.map((S,R)=>{const w=y===1&&R===1;return{value:S,type:w?"Text":"NumberInput",unitKey:R===2?"temperature":"length",onChange:d,roundDisplayValue:y===3&&R===2?D=>b.roundByMagnitude(D,2):null,formatDisplayValue:w?D=>`T* ${D}`:null,autoUnit:!0}})}),e),{headers:[],rows:[]});return n.jsxs(Z,{columns:"1fr 1fr",gap:!0,children:[n.jsxs(L,{heading:n.jsx(E,{children:"Settings"}),children:[n.jsx(V,{label:"Convert back to storage unit:",labelLeft:!0,labelWidth:200,children:n.jsx(F,{checked:c,onChange:e=>f(e.target.checked)})}),n.jsx(V,{label:"Enable display rounding:",labelLeft:!0,labelWidth:200,children:n.jsx(F,{checked:u,onChange:e=>l(e.target.checked)})}),n.jsx(V,{label:"Enable cosmetic rounding:",labelLeft:!0,labelWidth:200,children:n.jsx(F,{checked:m,onChange:e=>p(e.target.checked)})}),n.jsx(V,{label:"Convert whole table:",labelLeft:!0,labelWidth:200,children:n.jsx(F,{checked:t,onChange:e=>C(e.target.checked)})})]}),n.jsxs(L,{heading:n.jsx(E,{children:"Unit template"}),children:[n.jsx(V,{label:"Length unit:",labelLeft:!0,labelWidth:120,children:n.jsx(H,{options:(U=b.getUnitsForQuantity("length"))==null?void 0:U.map(e=>({value:e,label:b.label(e)})),value:{value:o},onChange:e=>i(e.target.value),width:"100px"})}),n.jsx(V,{label:"Temperature unit:",labelLeft:!0,labelWidth:120,children:n.jsx(H,{options:(x=b.getUnitsForQuantity("temperature"))==null?void 0:x.map(e=>({value:e,label:b.label(e)})),value:{value:r},onChange:e=>s(e.target.value),width:"100px"})})]}),n.jsx(L,{heading:n.jsx(E,{children:"Storage State (Redux)"}),children:n.jsx("pre",{children:n.jsx("code",{children:JSON.stringify(a,null,2)})})}),n.jsx(L,{heading:n.jsx(E,{children:"UnitTable"}),children:n.jsx(B,{table:h,unitConfig:[{unitKey:"length",storageUnit:a[0][0],preferredUnit:o},{unitKey:"temperature",storageUnit:a[0][2],preferredUnit:r}],convertBackToStorageUnit:c,enableDisplayRounding:u,enableCosmeticRounding:m})})]})};var A,N,q,G,O;k.parameters={...k.parameters,docs:{...(A=k.parameters)==null?void 0:A.docs,source:{originalSource:`() => {
|
|
2
2
|
const [preferredLengthUnit, setPreferredLengthUnit] = useState(initialLengthUnit);
|
|
3
3
|
const [preferredTemperatureUnit, setPreferredTemperatureUnit] = useState(initialTemperatureUnit);
|
|
4
4
|
const [reduxTable, setReduxTable] = useState<TTable>(initialTable);
|