UNPKG

@boxyhq/react-ui

Version:

React UI components from BoxyHQ

3 lines (2 loc) 14.2 kB
"use strict";const t=require("./index-CS5SeY3J.cjs"),g=require("react");async function T(e){const n=await e.text();try{return n.length?JSON.parse(n):""}catch{return n}}async function z(e,n){try{const s=await fetch(e,n);if(s.status===204)return;const i=s.headers.get("jackson-pagetoken"),a=await T(s);if(!s.ok)throw new A(s.status,a.error.message);return i&&typeof a=="object"?{data:a,pageToken:i}:a}catch(s){return{error:{message:s.message||"Something went wrong"}}}}class A extends Error{constructor(n,s){super(s),this.status=n}}function D(e){function n(){const{type:i,id:a,label:l,value:r,classNames:x,handleInputChange:m,...d}=e;return d}function s(){var i,a,l;return{container:t.cssClassAssembler((i=e.classNames)==null?void 0:i.container,t.styles.container),input:t.cssClassAssembler((a=e.classNames)==null?void 0:a.input,t.styles.input),label:t.cssClassAssembler((l=e.classNames)==null?void 0:l.label,t.styles.label)}}return t.jsxRuntimeExports.jsxs("div",{className:s().container,children:[t.jsxRuntimeExports.jsx("label",{htmlFor:e.id,className:s().label,children:e.label}),t.jsxRuntimeExports.jsx(t.Spacer,{y:2}),t.jsxRuntimeExports.jsx("input",{type:e.type||"text",id:e.id,value:e.value,className:s().input,onChange:i=>typeof e.handleInputChange=="function"&&e.handleInputChange(i),...n()})]})}const $="_container_1jz5a_4",I="_input_1jz5a_1",M="_label_1jz5a_1",B="_toolbar_1jz5a_9",b={container:$,input:I,label:M,toolbar:B};function L(e){const[n,s]=g.useState(()=>!1);function i(){s(!n)}function a(r){e.handleChange(r)}function l(){var r;return{input:t.cssClassAssembler((r=e.classNames)==null?void 0:r.input,b.input)}}return t.jsxRuntimeExports.jsxs("div",{className:b.container,children:[t.jsxRuntimeExports.jsxs("div",{className:b.toolbar,children:[t.jsxRuntimeExports.jsx("label",{htmlFor:e.id,className:b.label,children:e.label}),t.jsxRuntimeExports.jsxs("div",{children:[t.jsxRuntimeExports.jsx(t.IconButton,{handleClick:i,label:n?"Hide secret":"Show secret",icon:n?"EyeSlashIcon":"EyeIcon"}),t.jsxRuntimeExports.jsx(t.Spacer,{x:.5}),t.jsxRuntimeExports.jsx(t.CopyToClipboardButton,{text:e.value||"",successCallback:e.copyDoneCallback})]})]}),t.jsxRuntimeExports.jsx(t.Spacer,{y:2}),t.jsxRuntimeExports.jsx("input",{type:n?"text":"password",placeholder:e.placeholder,value:e.value||"",id:e.id,required:e.required,maxLength:e.maxLength,readOnly:e.readOnly,onChange:r=>a(r),className:l().input})]})}const q="_label_u7c4s_9",O="_div_u7c4s_17",V="_select_u7c4s_49",E={label:q,div:O,"div--disabled":"_div--disabled_u7c4s_43",select:V};function H(e){var i;function n(){return e.id?e.id:e.label.replace(/ /g,"")}function s(){var a,l;return{div:E.div+(e.disabled?` ${E["div--disabled"]}`:""),select:t.cssClassAssembler((a=e.classNames)==null?void 0:a.select,E.select),label:t.cssClassAssembler((l=e.classNames)==null?void 0:l.label,E.label)}}return t.jsxRuntimeExports.jsxs(t.jsxRuntimeExports.Fragment,{children:[t.jsxRuntimeExports.jsx("label",{htmlFor:n(),className:s().label,children:e.label}),t.jsxRuntimeExports.jsx(t.Spacer,{y:2}),t.jsxRuntimeExports.jsxs("div",{className:s().div,children:[t.jsxRuntimeExports.jsx("select",{id:n(),name:e.name,className:s().select,disabled:e.disabled??!1,value:e.selectedValue,onChange:a=>e.handleChange(a),children:(i=e.options)==null?void 0:i.map(a=>t.jsxRuntimeExports.jsx("option",{value:a.value,children:a.text},a.value))}),t.jsxRuntimeExports.jsx("span",{})]})]})}const Q="_label_15znz_3",G="_checkbox_15znz_12",S={label:Q,checkbox:G};function U(e){function n(){return e.id?e.id:e.label.replace(/ /g,"")}return t.jsxRuntimeExports.jsxs("label",{className:S.label,children:[t.jsxRuntimeExports.jsx("input",{type:"checkbox",id:n(),name:e.name,checked:e.checked,onChange:s=>e.handleChange(s),className:S.checkbox}),e.label]})}const J="_container_569d7_1",K={container:J};function W(e){return t.jsxRuntimeExports.jsxs("div",{className:K.container,children:[t.jsxRuntimeExports.jsx("div",{"aria-hidden":!e.isBusy,children:t.jsxRuntimeExports.jsx(t.Spinner,{})}),t.jsxRuntimeExports.jsx("div",{"aria-busy":e.isBusy,children:e.children})]})}const X="_ul_1yjqg_1",Y={ul:X},F=g.createContext({offset:0});function Z(e){const[n,s]=g.useState(()=>0);function i(){return n===0&&e.currentPageItemsCount<e.itemsPerPage}function a(){return n===0}function l(){return e.currentPageItemsCount<e.itemsPerPage}function r(){const j=n-e.itemsPerPage;s(j),typeof e.handlePageChange=="function"&&e.handlePageChange({offset:j}),typeof e.reFetch=="function"&&e.reFetch({offset:j,limit:e.itemsPerPage,pageToken:e.pageTokenMap[j-e.itemsPerPage]})}function x(){const u=n,j=u+e.itemsPerPage;s(j),typeof e.handlePageChange=="function"&&e.handlePageChange({offset:j}),typeof e.reFetch=="function"&&e.reFetch({offset:j,limit:e.itemsPerPage,pageToken:e.pageTokenMap[u]})}function m(){const u=new URLSearchParams(window.location.search).get("offset");return u&&Number.isFinite(+u)?Math.abs(+u):null}function d(){const u=m();typeof u=="number"?(s(u),typeof e.reFetch=="function"&&e.reFetch({offset:u,limit:e.itemsPerPage})):(typeof e.handlePageChange=="function"&&e.handlePageChange({offset:0}),typeof e.reFetch=="function"&&e.reFetch({offset:0,limit:e.itemsPerPage}))}return g.useEffect(()=>{window.addEventListener("popstate",d),d()},[]),g.useEffect(()=>()=>{window.removeEventListener("popstate",d)},[]),t.jsxRuntimeExports.jsx(F.Provider,{value:{offset:n},children:t.jsxRuntimeExports.jsxs(t.jsxRuntimeExports.Fragment,{children:[e.children,i()?null:t.jsxRuntimeExports.jsx("nav",{"aria-label":"Pagination Navigation",children:t.jsxRuntimeExports.jsxs("ul",{className:Y.ul,children:[t.jsxRuntimeExports.jsx("li",{children:t.jsxRuntimeExports.jsx(t.Button,{name:"Prev",variant:"outline",icon:"LeftArrowIcon","aria-label":"Goto Previous Page",handleClick:r,disabled:a()})}),t.jsxRuntimeExports.jsx("li",{children:t.jsxRuntimeExports.jsx(t.Button,{name:"Next",variant:"outline",icon:"RightArrowIcon","aria-label":"Goto Next Page",handleClick:x,disabled:l()})})]})})]})})}const p="_container_1uf8j_1",ee="_svg_1uf8j_12",te="_description_1uf8j_17",R={container:p,svg:ee,description:te};function C(e){function n(){return{container:R.container+(e.className?` ${e.className}`:"")}}function s(){return e.variant||"info"}return t.jsxRuntimeExports.jsxs("div",{className:n().container,children:[s()==="info"?t.jsxRuntimeExports.jsx(t.InfoIcon,{svgAttrs:{class:R.svg}}):t.jsxRuntimeExports.jsx(t.jsxRuntimeExports.Fragment,{children:t.jsxRuntimeExports.jsx(t.ExclamationTriangle,{svgAttrs:{class:R.svg}})}),t.jsxRuntimeExports.jsx("h4",{children:e.title}),e.description?t.jsxRuntimeExports.jsx("p",{className:R.description,children:e.description}):null]})}const ne="_table_z2c6r_2",se="_caption_z2c6r_13",ae="_thead_z2c6r_24",ie="_td_z2c6r_32",le="_th_z2c6r_24",ce="_tr_z2c6r_41",oe="_iconSpan_z2c6r_59",re="_noMoreResults_z2c6r_64",h={table:ne,caption:se,thead:ae,td:ie,th:le,tr:ce,iconSpan:oe,noMoreResults:re},ue="_badge_huzc5_3",xe="_info_huzc5_12",me="_success_huzc5_16",de="_warning_huzc5_20",v={"sr-only":"_sr-only_huzc5_1",badge:ue,info:xe,success:me,warning:de};function y(e){function n(){return" "+(e.variant?v[e.variant]:v.info)}return t.jsxRuntimeExports.jsx("span",{className:`${v.badge}${n()}`,"aria-label":e.ariaLabel||e.badgeText,children:e.badgeText})}function je(e){var N;function n(c,o){return()=>c.handleClick(o)}function s(){const c=e.col;let o="-";return i()?o=e.rowData[c]:a()&&(o=e.rowData[c.name]),o}function i(){return typeof e.col=="string"}function a(){return typeof e.col=="object"&&"name"in e.col}function l(){return e.col==="actions"||typeof e.col=="object"&&e.col.name==="actions"}function r(){var o,f,P;const c=e.col;return typeof((o=c.badge)==null?void 0:o.shouldDisplayBadge)=="function"?c.badge.shouldDisplayBadge(e.rowData):!!((f=c.badge)!=null&&f.position||(P=c.badge)!=null&&P.badgeText)}function x(){var o;return(o=e.col.badge)==null?void 0:o.position}function m(){var o;const c=e.col;return((o=c.badge)==null?void 0:o.badgeText)||e.rowData[c.name]}function d(){var o;return(o=e.col.badge)==null?void 0:o.ariaLabel}function u(){var o,f;const c=e.col;return typeof((o=c.badge)==null?void 0:o.variantSelector)=="function"?c.badge.variantSelector(e.rowData):(f=c.badge)==null?void 0:f.variant}function j(){return s()===void 0||s()===""||s()===null}return t.jsxRuntimeExports.jsxs(t.jsxRuntimeExports.Fragment,{children:[l()?t.jsxRuntimeExports.jsx(t.jsxRuntimeExports.Fragment,{children:(N=e.actions)==null?void 0:N.map((c,o)=>{var f;return t.jsxRuntimeExports.jsx("span",{className:(f=e.classNames)==null?void 0:f.iconSpan,children:t.jsxRuntimeExports.jsx(t.IconButton,{label:c.label,handleClick:n(c,e.rowData),icon:c.icon})},o)})}):null,i()?t.jsxRuntimeExports.jsx(t.jsxRuntimeExports.Fragment,{children:s()}):null,a()?t.jsxRuntimeExports.jsx(t.jsxRuntimeExports.Fragment,{children:r()?t.jsxRuntimeExports.jsx(t.jsxRuntimeExports.Fragment,{children:t.jsxRuntimeExports.jsxs(t.jsxRuntimeExports.Fragment,{children:[x()==="surround"?t.jsxRuntimeExports.jsx(y,{badgeText:m(),ariaLabel:d(),variant:u()}):null,x()==="left"?t.jsxRuntimeExports.jsxs(t.jsxRuntimeExports.Fragment,{children:[t.jsxRuntimeExports.jsx(y,{badgeText:m(),ariaLabel:d(),variant:u()}),j()?null:t.jsxRuntimeExports.jsx(t.Spacer,{x:2}),s()]}):null,x()==="right"?t.jsxRuntimeExports.jsxs(t.jsxRuntimeExports.Fragment,{children:[s(),j()?null:t.jsxRuntimeExports.jsx(t.Spacer,{x:2}),t.jsxRuntimeExports.jsx(y,{badgeText:m(),ariaLabel:d(),variant:u()})]}):null]})}):t.jsxRuntimeExports.jsx(t.jsxRuntimeExports.Fragment,{children:s()})}):null]})}function k(e){var i,a;function n(){var l,r,x,m,d,u,j;return{table:t.cssClassAssembler((l=e.classNames)==null?void 0:l.table,h.table),caption:t.cssClassAssembler((r=e.classNames)==null?void 0:r.caption,h.caption),thead:t.cssClassAssembler((x=e.classNames)==null?void 0:x.thead,h.thead),tr:t.cssClassAssembler((m=e.classNames)==null?void 0:m.tr,h.tr),th:t.cssClassAssembler((d=e.classNames)==null?void 0:d.th,h.th),td:t.cssClassAssembler((u=e.classNames)==null?void 0:u.td,h.td),iconSpan:t.cssClassAssembler((j=e.classNames)==null?void 0:j.iconSpan,h.iconSpan)}}function s(l){return typeof l=="string"?l:l.name}return t.jsxRuntimeExports.jsxs("table",{className:n().table,children:[e.tableCaption?t.jsxRuntimeExports.jsx("caption",{className:n().caption,children:e.tableCaption}):null,t.jsxRuntimeExports.jsx("thead",{className:n().thead,children:t.jsxRuntimeExports.jsx("tr",{className:n().tr,children:(i=e.cols)==null?void 0:i.map(l=>t.jsxRuntimeExports.jsx("th",{scope:"col",className:n().th,children:s(l)},s(l)))})}),t.jsxRuntimeExports.jsxs("tbody",{children:[e.noMoreResults?t.jsxRuntimeExports.jsx("tr",{children:t.jsxRuntimeExports.jsx("td",{colSpan:e.cols.length,className:h.noMoreResults,children:"No more results found"})}):null,e.noMoreResults?null:t.jsxRuntimeExports.jsx(t.jsxRuntimeExports.Fragment,{children:(a=e.data)==null?void 0:a.map((l,r)=>{var x;return t.jsxRuntimeExports.jsx("tr",{className:n().tr,children:(x=e.cols)==null?void 0:x.map((m,d)=>t.jsxRuntimeExports.jsx("td",{className:n().td,children:t.jsxRuntimeExports.jsx(je,{col:m,rowData:l,actions:e.actions,classNames:n()})},d))},r)})})]})]})}function he(e){function n(){return e.data.length===0&&i.offset===0}function s(){return e.data.length===0&&i.offset>0}const i=g.useContext(F);return t.jsxRuntimeExports.jsx(t.jsxRuntimeExports.Fragment,{children:n()?t.jsxRuntimeExports.jsx(t.jsxRuntimeExports.Fragment,{children:t.jsxRuntimeExports.jsxs(t.jsxRuntimeExports.Fragment,{children:[e.showErrorComponent?t.jsxRuntimeExports.jsx(C,{variant:"error",title:e.errorMessage}):null,e.showErrorComponent?null:t.jsxRuntimeExports.jsx(C,{title:e.emptyStateMessage})]})}):t.jsxRuntimeExports.jsx(t.jsxRuntimeExports.Fragment,{children:t.jsxRuntimeExports.jsx("div",{className:h.tableContainer,children:t.jsxRuntimeExports.jsx(k,{cols:e.cols,data:e.data,actions:e.actions,noMoreResults:s(),...e.tableProps})})})})}function fe(e){var n;return t.jsxRuntimeExports.jsx(t.jsxRuntimeExports.Fragment,{children:((n=e.data)==null?void 0:n.length)>0?t.jsxRuntimeExports.jsx(t.jsxRuntimeExports.Fragment,{children:t.jsxRuntimeExports.jsx("div",{className:h.tableContainer,children:t.jsxRuntimeExports.jsx(k,{cols:e.cols,data:e.data,actions:e.actions,...e.tableProps})})}):t.jsxRuntimeExports.jsx(t.jsxRuntimeExports.Fragment,{children:t.jsxRuntimeExports.jsxs(t.jsxRuntimeExports.Fragment,{children:[e.showErrorComponent?t.jsxRuntimeExports.jsx(C,{variant:"error",title:e.errorMessage}):null,e.showErrorComponent?null:t.jsxRuntimeExports.jsx(C,{title:e.emptyStateMessage})]})})})}const ge="_toggle_1uxfk_4",be="_display_1uxfk_12",Ee="_input_1uxfk_60",_={"sr-only":"_sr-only_1uxfk_1",toggle:ge,display:be,input:Ee};function Re(e){return t.jsxRuntimeExports.jsxs("label",{className:_.toggle,children:[e.label,t.jsxRuntimeExports.jsx("input",{type:"checkbox",className:`${_.input} ${_["sr-only"]}`,onChange:n=>e.handleChange(n),checked:e.checked,disabled:e.disabled}),t.jsxRuntimeExports.jsx("span",{className:_.display})]})}const _e="_confirmationDiv_sqflu_1",Ce="_buttonsDiv_sqflu_7",w={confirmationDiv:_e,buttonsDiv:Ce};function ve(e){var s,i,a,l,r,x;const n=g.useRef(null);return g.useEffect(()=>{var m;(m=n.current)==null||m.focus()},[]),t.jsxRuntimeExports.jsxs("div",{className:w.confirmationDiv,children:[t.jsxRuntimeExports.jsx("h6",{children:e.promptMessage}),t.jsxRuntimeExports.jsxs("div",{className:w.buttonsDiv,children:[t.jsxRuntimeExports.jsx(t.Button,{type:"button",name:((s=e.buttonNames)==null?void 0:s.ctoa)||"Confirm",variant:e.ctoaVariant,handleClick:e.confirmationCallback,classNames:(a=(i=e.classNames)==null?void 0:i.button)==null?void 0:a.ctoa}),t.jsxRuntimeExports.jsx(t.Button,{type:"button",variant:"outline",name:((l=e.buttonNames)==null?void 0:l.cancel)||"Cancel",handleClick:e.cancelCallback,classNames:(x=(r=e.classNames)==null?void 0:r.button)==null?void 0:x.cancel,buttonRef:n})]})]})}exports.Checkbox=U;exports.ConfirmationPrompt=ve;exports.InputField=D;exports.LoadingContainer=W;exports.NonPaginatedTable=fe;exports.Paginate=Z;exports.PaginatedTable=he;exports.SecretInputFormControl=L;exports.Select=H;exports.ToggleSwitch=Re;exports.sendHTTPRequest=z; //# sourceMappingURL=index-DleagIor.cjs.map