freemium-survey-components 0.2.0 → 0.5.1

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/README.md CHANGED
@@ -1,4 +1,6 @@
1
- # Freemium-survey-components [npm](https://www.npmjs.com/package/freemium-survey-components)
1
+ # [Freemium-survey-components](https://www.npmjs.com/package/freemium-survey-components)
2
+
3
+ ⚠️: **Not ready for public usage yet!**
2
4
 
3
5
  Freemium-survey-components is a react package that renders the survey collection form given the survey object from the survey-serv platform service.
4
6
 
@@ -52,7 +54,7 @@ Of the below components the parent app would only need to interact with the Surv
52
54
  ## Using SURVEY
53
55
 
54
56
  ```sh
55
- import Survey from 'freemium-survey-components'
57
+ import {Survey} from 'freemium-survey-components'
56
58
  ...
57
59
  <Survey survey={surveyObjectFromDb} onSubmit ={(data : surveyFormData) => {....}/>
58
60
  ```
package/lib/index.cjs.js CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e,n=require("react"),t=(e=n)&&"object"==typeof e&&"default"in e?e.default:e;function r(e,n){void 0===n&&(n={});var t=n.insertAt;if(e&&"undefined"!=typeof document){var r=document.head||document.getElementsByTagName("head")[0],o=document.createElement("style");o.type="text/css","top"===t&&r.firstChild?r.insertBefore(o,r.firstChild):r.appendChild(o),o.styleSheet?o.styleSheet.cssText=e:o.appendChild(document.createTextNode(e))}}r(".container {\n margin: 0 auto;\n width: 100%;\n}\n.title {\n color: var(--brand-color);\n font-weight: 600;\n}\n\n.footer {\n margin-top: 20px;\n border-top: 1px solid var(--default-background-color);\n border-top: 1px solid var(--background-color, var(--default-background-color));\n padding-top: 20px;\n display: flex;\n justify-content: center;\n font-size: 12px;\n}\n\n.widget span {\n color: #aaa;\n font-size: 12px;\n}\n.widget button {\n display: inline-block;\n font-size: 16px;\n white-space: nowrap;\n vertical-align: middle;\n background: none;\n border: none;\n box-shadow: none;\n cursor: pointer;\n text-align: center;\n font-weight: 500;\n border-radius: 4px;\n margin: 0;\n outline: none;\n margin-left: -1px;\n width: 40px;\n height: 40px;\n transform: scale(1);\n transition: background 0.2s ease-in, color 0.2s ease-in,\n border-color 0.2s ease-in, transform 0.2s cubic-bezier(0.5, 2, 0.5, 0.75);\n}\n.widget button:hover {\n color: white;\n transform: scale(1.15);\n z-index: 2;\n position: relative;\n}\n.widget button.active {\n color: white;\n transform: scale(1.15);\n z-index: 2;\n position: relative;\n}\n\n.choices {\n width: 100%;\n display: flex;\n justify-content: space-between;\n}\n\n.choice.active,\n.choice:hover:nth-child(1) {\n background: #eb5b56;\n}\n.choice.active,\n.choice:hover:nth-child(2) {\n background: #fb8774;\n}\n.choice.active,\n.choice:hover:nth-child(3) {\n background: #f58f6b;\n}\n.choice.active,\n.choice:hover:nth-child(4) {\n background: #f6996a;\n}\n.choice.active,\n.choice:hover:nth-child(5) {\n background: #eab268;\n}\n.choice.active,\n.choice:hover:nth-child(6) {\n background: #cebb69;\n}\n.choice.active,\n.choice:hover:nth-child(7) {\n background: #bdc46c;\n}\n.choice.active,\n.choice:hover:nth-child(8) {\n background: #a4cd72;\n}\n.choice.active,\n.choice:hover:nth-child(9) {\n background: #77c955;\n}\n.choice.active,\n.choice:hover:nth-child(10) {\n background: #37c248;\n}\n\n.widget.highlighted button.active,\n.widget.highlighted button:hover {\n background: var(--brand-color) !important;\n}\n.widget .rounded button {\n border-radius: 100%;\n}\n.widget .boxed button {\n border-radius: 0;\n}\n.widget {\n padding: 35px 0;\n box-sizing: border-box;\n position: relative;\n padding-bottom: 30px;\n}\n.widget .button-container {\n display: flex;\n justify-content: space-between;\n background: var(--default-background-color);\n background: var(--background-color, var(--default-background-color));\n}\n.widget .positive-text,\n.widget .negative-text {\n position: absolute;\n color: var(--color-elephant-500);\n}\n.widget .positive-text {\n right: 0px;\n bottom: 5px;\n text-align: right;\n}\n.widget .negative-text {\n left: 0;\n bottom: 5px;\n text-align: left;\n}\n@media (max-width: 550px) {\n .widget .button-container {\n background: transparent;\n }\n .widget .choices {\n flex-wrap: wrap;\n justify-content: center;\n grid-gap: 16px;\n gap: 16px;\n background: transparent;\n }\n .widget button {\n border-radius: 50%;\n background: #ebeff3;\n }\n}\n");const o=e=>{const{type_info:{linear_scale:{button_shape:r,button_style:o},score_presets:{start:a,end:i},validation:{min:l},footer_text:c}}=e,d=e=>{switch(e){case e<4:return"detractor";case e<7:return"passive";default:return"promoter"}},s=n.useRef(Array.from({length:10},((e,n)=>n+l)));return t.createElement("div",{className:"container"},t.createElement("div",{className:`widget ${r} ${o}`},t.createElement("div",{className:"button-container"},t.createElement("span",{className:"negative-text"},a),t.createElement("div",{className:"choices"},s.current.map((n=>t.createElement("button",{onClick:t=>{e.onChangeHandler(n)},className:`choice ${d(n)} ${e.npsValue===n&&"active"}`},n)))),t.createElement("span",{className:"positive-text"},i))),t.createElement("div",{className:"footer"},c))},a=(e,n)=>(e.defaultProps=n,e);r(".input-container,\n.textarea-container {\n display: flex;\n flex-direction: column;\n width: 100%;\n border-radius: 4px;\n position: relative;\n}\nlabel.input-label {\n display: inline-block;\n padding-bottom: 8px;\n padding-left: 2px;\n font-size: 12px;\n font-weight: 400;\n}\nlabel.required::after {\n content: '*';\n position: relative;\n top: 2px;\n font-weight: 500;\n font-size: 0.85rem;\n padding-left: 3px;\n color: var(--default-error-highlight-color);\n color: var(--error-highlight-color,var(--default-error-highlight-color));\n}\n\n.input-basic {\n width: 100%;\n display: flex;\n align-items: center;\n border-radius: var(--default-border-radius);\n border-radius: var(--border-radius,var(--default-border-radius));\n border: 1px solid var(--default-input-border-color));\n border: 1px solid var(--input-border-color,var(--default-input-border-color)));\n transition: border-color 0.2s linear;\n background: #fff;\n}\n.textarea-container .input-basic {\n flex-direction: column;\n align-items: unset;\n}\n.input-basic.error {\n border: 1px solid var(--default-error-highlight-color);\n border: 1px solid var(--error-highlight-color,var(--default-error-highlight-color));\n}\n.input-basic.error:hover {\n border: 1px solid var(--default-error-highlight-color);\n border: 1px solid var(--error-highlight-color,var(--default-error-highlight-color));\n}\n.input-basic.error[focus-within] {\n box-shadow: none;\n}\n.input-basic.error:focus-within {\n box-shadow: none;\n}\n.input-basic:hover {\n border-color: var(--default-input-hover-border-color));\n border-color: var(--input-hover-border-color,var(--default-input-hover-border-color)));\n transition: 0.2s linear;\n}\n.input-basic[focus-within] {\n border: 1px solid transparent;\n box-shadow: 0 0 0 2px\n var(--default-input-highlight-color);\n box-shadow: 0 0 0 2px\n var(--input-highlight-color, var(--default-input-highlight-color));\n}\n.input-basic:focus-within {\n border: 1px solid transparent;\n box-shadow: 0 0 0 2px\n var(--default-input-highlight-color);\n box-shadow: 0 0 0 2px\n var(--input-highlight-color, var(--default-input-highlight-color));\n}\n.end-max-length {\n padding: 0 8px;\n font-size: 0.85rem;\n}\n.textarea-container .end-max-length {\n padding: 8px;\n align-self: flex-end;\n}\nspan.input-error {\n display: block;\n padding-left: 2px;\n padding-top: 4px;\n font-size: 0.9rem;\n color: var(--default-error-highlight-color);\n color: var(--error-highlight-color,var(--default-error-highlight-color));\n}\ninput[type='text'] {\n padding: 4px 12px;\n flex: 1;\n border: unset;\n height: 32px;\n font-size: 1rem;\n /* line-height: ${typography.input.text.lineHeight}; */\n font-weight: 500;\n border-radius: 4px;\n}\ninput[type='text'],\ntextarea {\n outline: none;\n border: none;\n}\ninput[type='text']::-moz-placeholder {\n color: var(--input-placeholder-color);\n}\ninput[type='text']:-ms-input-placeholder {\n color: var(--input-placeholder-color);\n}\ninput[type='text']::placeholder {\n color: var(--input-placeholder-color);\n}\ntextarea {\n min-height: 116px;\n padding: 4px 12px;\n flex: 1;\n border: unset;\n resize: none;\n font-size: 1rem;\n /* line-height: ${typography.input.text.lineHeight}; */\n font-weight: 500;\n border-radius: 4px;\n}\ntextarea::-moz-placeholder {\n color: var(--input-placeholder-color);\n}\ntextarea:-ms-input-placeholder {\n color: var(--input-placeholder-color);\n}\ntextarea::placeholder {\n color: var(--input-placeholder-color);\n}\n");const i={isRequired:!1,showCount:!1,isErrored:!1,inline:!1,spellCheck:!1,autoFocus:!1},l=n.forwardRef(((e,n)=>{const{inputStyle:r,style:o,className:a,showCount:i,isErrored:l,startLabel:c,isRequired:d,errorText:s,endLabel:u,maxLength:p,...h}=e;return console.log(e.value),t.createElement("div",{className:"input-container",style:o},e.label&&t.createElement("label",{className:"input-label "+(d?"required":"")},e.label),t.createElement("div",null,c&&t.createElement("div",{className:"start-label"},c),t.createElement("div",{className:`input-basic ${l?"error":""}${a||""}`},t.createElement("input",Object.assign({type:"text",autoComplete:"off"},h,{ref:n,style:r})),i&&p>0&&t.createElement("div",{className:"end-max-length"},`${e.value&&e.value.length||0}/${e.maxLength}`)),u&&t.createElement("div",{className:"end-label"},u)),l&&s&&t.createElement("span",{className:"input-error"},e.errorText))})),c=n.forwardRef(((e,n)=>{const{inputStyle:r,style:o,className:a,showCount:i,maxLength:l,isErrored:c,startLabel:d,isRequired:s,...u}=e;return console.log(e.value),t.createElement(t.Fragment,null,t.createElement("div",{className:"textarea-container",style:o},e.label&&t.createElement("label",{className:"input-label "+(s?"required":"")},e.label),d&&t.createElement("div",{className:"start-label"},d),t.createElement("div",{className:`input-basic ${c?"error":""} ${a||""}`},t.createElement("textarea",Object.assign({autoComplete:"off"},u,{ref:n,style:r})),i&&l&&l>0&&t.createElement("div",{className:"end-max-length"},`${e.value&&e.value.length||0}/${e.maxLength}`)),e.endLabel&&t.createElement("div",{className:"end-label"},e.endLabel)),e.isErrored&&e.errorText&&t.createElement("span",{className:"input-error"},e.errorText))})),d=a(l,i),s=a(c,i);r(".checkbox-group {\n display: flex;\n align-items: center;\n grid-gap: 12px;\n gap: 12px;\n flex-direction: column;\n white-space: nowrap;\n flex-wrap: wrap;\n}\n.icon-container {\n display: inline-block;\n flex: 0 0 12px;\n width: 12px;\n height: 12px;\n min-width: 12px;\n min-height: 12px;\n color: inherit;\n position: absolute;\n left: 1px;\n top: 2px;\n}\n.tick-icon {\n position: absolute;\n top: 0;\n right: 0;\n bottom: 0;\n left: 0;\n height: 100%;\n width: 100%;\n color: inherit;\n fill: currentColor;\n}\ninput[type='checkbox'] {\n clip: rect(0px 0px 0px 0px);\n width: 0px;\n height: 0px;\n}\ninput[type='checkbox']:focus ~ .checkbox {\n /* box-shadow: ${pseudo.focus} 0px 0px 0px 2px; */\n box-shadow: var(--default-input-highlight-color)\n 0px 0px 0px 2px;\n box-shadow: var(--input-highlight-color, var(--default-input-highlight-color))\n 0px 0px 0px 2px;\n border-color: transparent;\n}\n.checkbox-label {\n display: flex;\n align-items: center;\n -webkit-user-select: none;\n -moz-user-select: none;\n -ms-user-select: none;\n user-select: none;\n opacity: 1;\n cursor: pointer;\n font-size: 1rem;\n font-weight: 500;\n padding: 16px;\n min-width: 200px;\n border: 1px solid #ebeff3;\n box-shadow: 0px 2px 5px rgb(18 52 77 / 10%);\n border-radius: 4px;\n}\n.checkbox-label.disabled {\n opacity: 0.5;\n cursor: 'not-allowed';\n}\n.checkbox {\n transition: background-color ease-in 0.2s;\n min-width: 14px;\n min-height: 14px;\n border-radius: 2px;\n position: relative;\n margin-right: 10px;\n background-color: #fff;\n border: 1px solid;\n border-color: var(--default-input-highlight-color)\n ;\n border-color: var(\n --input-highlight-color,\n var(--default-input-highlight-color)\n );\n}\n.checkbox:hover {\n border-color: var(--default-input-highlight-color)\n ;\n border-color: var(\n --input-highlight-color,\n var(--default-input-highlight-color)\n );\n box-shadow: var(--default-background-color) 0px 0px\n 0px 5px;\n box-shadow: var(--background-color, var(--default-background-color)) 0px 0px\n 0px 5px;\n}\ninput[type='checkbox']:checked ~ .checkbox {\n background-color: var(--default-input-highlight-color)\n ;\n background-color: var(\n --input-highlight-color,\n var(--default-input-highlight-color)\n );\n border-color: var(--default-input-highlight-color)\n ;\n border-color: var(\n --input-highlight-color,\n var(--default-input-highlight-color)\n );\n}\ninput[type='checkbox']:checked ~ .checkbox:hover {\n border-color: var(--default-input-highlight-color)\n ;\n border-color: var(\n --input-highlight-color,\n var(--default-input-highlight-color)\n );\n}\ninput[type='checkbox']:disabled ~ .checkbox:hover {\n box-shadow: unset;\n border-color: unset;\n}\n");const u=()=>t.createElement("svg",{id:"tick",className:"tick-icon",xmlns:"http://www.w3.org/2000/svg","aria-labelledby":"title",viewBox:"0 0 10 10"},t.createElement("path",{d:"M3 5.87c-.18666814.00267463-.36667109-.06932655-.5-.2L.21 3.41c-.1786328-.17863279-.24839684-.43899577-.1830127-.6830127.06538414-.24401694.25598306-.43461586.5-.5C.77100423 2.16160316 1.0313672 2.23136721 1.21 2.41L3 4.18 6.8.33c.27679776-.27455556.72320224-.27455556 1 0 .13696438.13025306.21450026.31098915.21450026.5S7.93696438 1.19974694 7.8 1.33L3.45 5.67c-.12082534.11896945-.28072735.19003701-.45.2Z",fill:"#fff",fillRule:"evenodd"})),p=({values:e,options:n,onChangeHandler:r})=>t.createElement("div",{className:"checkbox-group"},n.map(((n,o)=>t.createElement(h,{key:n.id,checked:e?.includes(n.id),name:n.name??n.id,id:n.id,autoFocus:0===o,onChange:(t,o)=>{if(o)r([...e||[],n.id]);else{const t=e.indexOf(n.id);t>-1&&e.splice(t,1),r([...e])}}},n.label)))),h=a(n.forwardRef(((e,n)=>t.createElement("label",{className:`checkbox-label ${e.disabled&&"disabled"}`},t.createElement("input",{ref:n,id:e.id,type:"checkbox",name:e.name,readOnly:e.readOnly,disabled:e.disabled,"aria-disabled":e.disabled,value:e.value,checked:e.checked,autoFocus:e.autoFocus,onChange:e.readOnly?()=>{}:n=>e.onChange(n,n.target.checked)}),t.createElement("div",{className:"checkbox"},e.checked&&t.createElement("div",{className:"icon-container"},t.createElement(u,null)," ")),t.createElement("div",null,e.children)))),{checked:!1});r(".radio-group {\n display: flex;\n align-items: center;\n grid-gap: 12px;\n gap: 12px;\n white-space: nowrap;\n flex-direction: column;\n}\n\n.radio {\n background-color: #fff;\n border: 1px solid;\n border-color: var(--default-input-border-color));\n border-color: var(--input-border-color,var(--default-input-border-color)));\n transition: background-color ease-in 0.2s;\n width: 18px;\n height: 18px;\n border-radius: 50%;\n position: relative;\n margin-right: 12px;\n}\n.radio:before {\n left: 3px;\n top: 3px;\n content: '';\n position: absolute;\n width: 10px;\n height: 10px;\n border-radius: 50%;\n transition: all ease-in 0.2s;\n background-color: #fff;\n}\n.radio-label {\n display: flex;\n align-items: center;\n -webkit-user-select: none;\n -moz-user-select: none;\n -ms-user-select: none;\n user-select: none;\n cursor: pointer;\n font-size: 1rem;\n font-weight: 500;\n padding: 16px;\n min-width: 200px;\n border: 1px solid #ebeff3;\n box-shadow: 0px 2px 5px rgb(18 52 77 / 10%);\n border-radius: 4px;\n}\ninput[type='radio'] {\n clip: rect(0, 0, 0, 0);\n position: absolute;\n}\ninput[type='radio']:focus ~ .radio {\n /* box-shadow: ${pseudo.focus} 0px 0px 0px 3px; */\n box-shadow: var(--default-input-highlight-color)\n 0px 0px 0px 3px;\n box-shadow: var(--input-highlight-color, var(--default-input-highlight-color))\n 0px 0px 0px 3px;\n border-color: transparent;\n}\n\ninput[type='radio']:checked ~ .radio:before {\n background-color: var(--default-input-highlight-color)\n ;\n background-color: var(\n --input-highlight-color,\n var(--default-input-highlight-color)\n );\n}\n.radio-container:hover .radio {\n border-color: var(--default-input-highlight-color)\n ;\n border-color: var(\n --input-highlight-color,\n var(--default-input-highlight-color)\n );\n box-shadow: var(--default-background-color) 0px 0px 0px 5px;\n box-shadow: var(--background-color,var(--default-background-color)) 0px 0px 0px 5px;\n}\n");const b=({name:e,options:n,value:r,onChangeHandler:o})=>t.createElement("div",{className:"radio-group"},n.map((n=>t.createElement(g,{key:n.id,value:n.id,name:e,onChange:e=>{o(e.currentTarget.value)},checked:r===n.id},n.label)))),g=a(n.forwardRef(((e,n)=>t.createElement("label",{className:"radio-label"},t.createElement("input",{ref:n,type:"radio",name:e.name,value:e.value,checked:e.checked,onClick:e.onChange,autoFocus:!0}),t.createElement("div",{className:"radio"}),t.createElement("div",null,e.children)))),{checked:!1});r(".progressbar-container {\n width: 100%;\n height: 6px;\n position: fixed;\n top: 0;\n left: 0;\n z-index: 1;\n}\n.progressbar {\n transition: transform 0.25s linear;\n transform-origin: left;\n height: 100%;\n background-color: var(--brand-color);\n}\n");const x=e=>{const{totalSteps:n,completedSteps:r}=e;return t.createElement("div",{className:"progressbar-container"},t.createElement("div",{className:"progressbar",style:{width:(r>0?100/n:0)+"%",transform:`scaleX(${r})`}}))};r(".action-button {\n width: auto;\n display: block;\n margin: 0;\n padding: 8px 16px;\n cursor: pointer;\n line-height: 1.5;\n text-align: center;\n font-weight: 500;\n letter-spacing: 0.3px;\n border-radius: 4px;\n white-space: nowrap;\n -webkit-user-select: none;\n -moz-user-select: none;\n -ms-user-select: none;\n user-select: none;\n color: #fff;\n background: var(--primary-button-color);\n border: 1px solid var(--primary-button-color);\n border-radius: 4px;\n min-width: 200px;\n}\n@media (max-width: 550px) {\n .action-button {\n min-width: 120px;\n }\n}\n\n.action-button:not([disabled]):hover {\n background: var(--primary-button-hover-color);\n /* background-color: ${hover}; */\n}\n\n.action-button:not([disabled]):active {\n}\n\n.action-button[disabled] {\n cursor: not-allowed;\n}\n\nbutton:focus:not(:active) {\n border: 1px solid transparent;\n /* box-shadow: 0 0 0 2px ${pseudo.focus}; */\n}\n");const m=()=>t.createElement(t.Fragment,null,"..."),f=e=>{const{inline:n=!1,children:r,disabled:o,className:a="",htmlType:i,type:l="primary",onClick:c,size:d,overrideStyleClassName:s="",loading:u=!1,...p}=e;return t.createElement("button",Object.assign({style:n?{display:"inline-block"}:{},disabled:o,className:`action-button ${a} ${s}`,type:i,onClick:c},p),u?t.createElement(m,null):r)},v=({question:e,formValues:n,onChangeHandler:r})=>{switch(e.type_info.question_type){case"RANGE":return t.createElement(o,{type_info:e.type_info,onChangeHandler:r,npsValue:n[e.name]});case"CHECKBOX":return t.createElement(p,{values:n[e.name],options:e.type_info.choices,onChangeHandler:r});case"CHECKBOX":return t.createElement(b,{name:e.name,onChangeHandler:r,options:e.type_info.choices,value:n[e.name]});case"MESSAGE":return t.createElement("div",{className:"responsive-text-field"},t.createElement(d,{autoFocus:!0,label:"",maxLength:300,showCount:!0,isRequired:e.is_required,value:n[e.name]||"",onChange:e=>r(e.target.value)}),t.createElement(s,{autoFocus:!0,label:"",maxLength:300,showCount:!0,isRequired:e.is_required,value:n[e.name]||"",onChange:e=>r(e.target.value)}));case"PARAGRAPH":return t.createElement(s,{autoFocus:!0,label:"",isRequired:e.is_required,value:n[e.name]||"",onChange:e=>r(e.target.value)});default:return console.error(`Question type ${e.type_info.question_type} not found`),null}};r(":root {\n --default-primary-button-color: #d72d30;\n --default-primary-button-hover-color: #f1171b;\n --default-brand-color: #264966;\n --default-input-highlight-color: #2c5cc5;\n --default-input-border-color: #92a2b1;\n --default-input-hover-border-color: #264966;\n --default-input-placeholder-color: #92a2b1;\n --default-border-radius: 4px;\n --default-background-color: #ebeff3;\n --default-error-highlight-color: #d72d30;\n}\n.question-container {\n display: flex;\n flex-direction: column;\n text-align: center;\n max-width: 700px;\n margin: 0 auto;\n align-items: center;\n background: #ffffff;\n border-radius: 4px;\n transition: transform 400ms ease 0ms, opacity 200ms ease 0ms;\n box-shadow: 0px 2px 16px rgba(18, 52, 77, 0.1);\n margin-bottom: 40px;\n padding: 20px;\n grid-gap: 28px;\n gap: 28px;\n}\n.question-text {\n font-size: 1.1rem;\n line-height: 1.5;\n}\n\n.action-buttons {\n display: flex;\n justify-content: space-between;\n width: 100%;\n align-items: center;\n}\n.skip-button {\n cursor: pointer;\n background: transparent;\n border: none;\n min-width: 40px;\n padding: 4px 12px;\n border-radius: 4px;\n}\n\n.next-button {\n margin: 0 auto;\n}\n.submit {\n padding-bottom: 40px;\n display: flex;\n justify-content: center;\n}\n.responsive-text-field {\n width: 100%;\n}\n.responsive-text-field .textarea-container {\n display: none;\n}\n\n@media (max-width: 550px) {\n .responsive-text-field .input-container {\n display: none;\n }\n .responsive-text-field .textarea-container {\n display: flex;\n }\n}\n");const w=["RANGE","NPS","RADIO"],k=()=>t.createElement("div",{className:"question-container",style:{gap:"16px"}},t.createElement("h4",null,"Thank you for taking our survey!."),t.createElement("p",null," Your response is very important to us."));exports.BUTTON_SIZE_VARIANTS={LARGE:"large",MINI:"mini",NORMAL:"normal"},exports.Button=f,exports.CheckboxGroup=p,exports.Input=d,exports.NPS=o,exports.ProgressBar=x,exports.Radio=g,exports.RadioGroup=b,exports.Survey=({survey:e,onSubmit:r})=>{const{meta:{blocks:o},question_details:{questions:a}}=e,[i,l]=n.useState({}),[c,d]=n.useState(!1),[s,u]=n.useState([]),p=n.useRef(null),h=n.useRef(null),b=n.useRef(null),g=n.useRef(0),m=n.useRef(!1),y=n.useRef([]);n.useEffect((()=>{o&&!p.current&&o.length>0&&N(o[0])}),[o]),n.useEffect((()=>{b.current?.scrollIntoView({block:"center",behavior:"smooth"}),y.current=s}),[s]),n.useEffect((()=>{Object.keys(i).length>0&&h.current&&(w.includes(h.current.type_info.question_type)||m.current)&&!E()&&C()}),[i]);const E=()=>g.current===o.length-1||"end"===p.current.branchOption,N=e=>{let n={};if(e.is_based_on_score){const t=a[0].type_info.choices[i?.[a[0].name]]?.dependent_question_names,r=e.question_names.find((e=>t?.includes(e)));n=a.find((e=>e.name===r))}else n=a.find((n=>n.name===e.question_names[0]));p.current=e,h.current=n;y.current.find((e=>e.question.name===n.name))||u([...y.current,{...e,question:n}])},q=(e,n,t)=>{if(t)if(null!=i[e.question.name]&&e.name!==s[s.length-1].name){const[t,r]=(e=>{const n=s.findIndex((n=>n.name===e.name)),t=s.slice(0,n+1),r=t.reduce(((e,n)=>(e[n.question.name]=i[n.question.name],e)),{});return g.current=o.findIndex((n=>n.name===e.name)),[t,r]})(e);l({...r,...null!=n&&{[e.question.name]:n}}),y.current=t}else l({...i,...null!=n&&{[e.question.name]:n}});else l({...i,...null!=n&&{[e.question.name]:n}})},C=()=>{E()?d(!0):(p.current.nextBlock?g.current=o.findIndex((e=>e.name===p.current.nextBlock)):g.current+=1,N(o[g.current]))},_=e=>{const n=s.findIndex((n=>n.name===e.name)),t=[...s];t.splice(n,1),y.current=t,C()};return p.current&&h.current?c?t.createElement(k,null):t.createElement(t.Fragment,null,t.createElement(x,{totalSteps:o.length,completedSteps:g.current}),s.map(((e,n)=>{return t.createElement("div",{className:"question-container",ref:b,id:e.title,key:e.title},t.createElement("div",{className:"question-text"},e.question.text),t.createElement(v,{question:e.question,formValues:i,onChangeHandler:n=>{m.current=!1,g.current=o.findIndex((n=>n.name===e.name)),p.current=e,h.current=e.question,q(e,n,w.includes(e.question.type_info.question_type)&&!E())}}),t.createElement("div",{className:"action-buttons"},(r=e.question,r.name===h.current.name&&!w.includes(r.type_info.question_type)&&!E()&&t.createElement(f,{onClick:()=>{m.current=!0,q(e,null,!0)},className:"next-button"},"Next")),((e,n)=>!e.required&&n.name===h.current.name)(e,e.question)&&t.createElement("button",{className:"skip-button",onClick:_},"Skip")));var r})),E()&&t.createElement("div",{className:"submit"},t.createElement(f,{onClick:()=>{d(!0),r(i)}},"Submit Survey"))):null},exports.TextArea=s;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var n,e=require("react"),t=(n=e)&&"object"==typeof n&&"default"in n?n.default:n;function r(n,e){void 0===e&&(e={});var t=e.insertAt;if(n&&"undefined"!=typeof document){var r=document.head||document.getElementsByTagName("head")[0],o=document.createElement("style");o.type="text/css","top"===t&&r.firstChild?r.insertBefore(o,r.firstChild):r.appendChild(o),o.styleSheet?o.styleSheet.cssText=n:o.appendChild(document.createTextNode(n))}}r(".nps-container {\n margin: 0 auto;\n width: 100%;\n display: flex;\n flex-direction: column;\n grid-gap: 52px;\n gap: 52px;\n}\n.nps-container .footer {\n border-top: 1px solid var(--default-background-color);\n border-top: 1px solid var(--background-color, var(--default-background-color));\n padding-top: 20px;\n display: flex;\n justify-content: center;\n font-size: 0.75rem;\n}\n.nps-container .widget {\n position: relative;\n}\n.nps-container .widget .button-container {\n display: flex;\n justify-content: space-between;\n background: var(--default-background-color);\n background: var(--background-color, var(--default-background-color));\n}\n.nps-container .widget .positive-text {\n position: absolute;\n color: var(--color-elephant-500);\n bottom: -28px;\n right: 0px;\n text-align: right;\n}\n.nps-container .widget .negative-text {\n position: absolute;\n color: var(--color-elephant-500);\n bottom: -28px;\n left: 0;\n text-align: left;\n}\n.nps-container .widget span {\n color: #aaa;\n font-size: 0.75rem;\n}\n.nps-container .widget button {\n display: inline-block;\n font-size: 1rem;\n white-space: nowrap;\n vertical-align: middle;\n background: none;\n border: none;\n box-shadow: none;\n cursor: pointer;\n text-align: center;\n font-weight: 400;\n border-radius: 4px;\n margin: 0;\n outline: none;\n margin-left: -1px;\n width: 40px;\n height: 40px;\n transform: scale(1);\n transition: background 0.2s ease-in, color 0.2s ease-in, border-color 0.2s ease-in, transform 0.2s cubic-bezier(0.5, 2, 0.5, 0.75);\n}\n.nps-container .widget button:hover {\n color: white;\n transform: scale(1.15);\n z-index: 2;\n position: relative;\n}\n.nps-container .widget button.active {\n color: white;\n transform: scale(1.15);\n z-index: 2;\n position: relative;\n}\n.nps-container .widget.highlighted button:hover, .nps-container .widget.highlighted button.active {\n background: var(--default-brand-color) !important;\n background: var(--brand-color, var(--default-brand-color)) !important;\n}\n.nps-container .widget.rounded button {\n border-radius: 50%;\n}\n.nps-container .widget.rounded.boxed button {\n border-radius: 0;\n}\n.nps-container .choices {\n width: 100%;\n display: flex;\n justify-content: space-between;\n}\n.nps-container .choice:nth-child(1).active, .nps-container .choice:nth-child(1):hover {\n background: #eb5b56;\n}\n.nps-container .choice:nth-child(2).active, .nps-container .choice:nth-child(2):hover {\n background: #fb8774;\n}\n.nps-container .choice:nth-child(3).active, .nps-container .choice:nth-child(3):hover {\n background: #f58f6b;\n}\n.nps-container .choice:nth-child(4).active, .nps-container .choice:nth-child(4):hover {\n background: #f6996a;\n}\n.nps-container .choice:nth-child(5).active, .nps-container .choice:nth-child(5):hover {\n background: #eab268;\n}\n.nps-container .choice:nth-child(6).active, .nps-container .choice:nth-child(6):hover {\n background: #cebb69;\n}\n.nps-container .choice:nth-child(7).active, .nps-container .choice:nth-child(7):hover {\n background: #bdc46c;\n}\n.nps-container .choice:nth-child(8).active, .nps-container .choice:nth-child(8):hover {\n background: #a4cd72;\n}\n.nps-container .choice:nth-child(9).active, .nps-container .choice:nth-child(9):hover {\n background: #77c955;\n}\n.nps-container .choice:nth-child(9).active, .nps-container .choice:nth-child(9):hover {\n background: #37c248;\n}\n\n@media (max-width: 550px) {\n .nps-container .widget .button-container {\n background: transparent;\n }\n .nps-container .widget .choices {\n flex-wrap: wrap;\n justify-content: center;\n grid-gap: 16px;\n gap: 16px;\n background: transparent;\n }\n .nps-container .widget button {\n border-radius: 50%;\n background: #ebeff3;\n }\n}");const o=n=>{const{type_info:{linear_scale:{button_shape:r,button_style:o},score_presets:{start:a,end:i},validation:{min:l},footer_text:c}}=n,s=n=>{switch(n){case n<4:return"detractor";case n<7:return"passive";default:return"promoter"}},d=e.useRef(Array.from({length:10},((n,e)=>e+l)));return t.createElement("div",{className:"nps-container"},t.createElement("div",{className:`widget ${r} ${o}`},t.createElement("div",{className:"button-container"},t.createElement("span",{className:"negative-text"},a),t.createElement("div",{className:"choices"},d.current.map((e=>t.createElement("button",{key:e,onClick:t=>{n.onChangeHandler(e)},className:`choice ${s(e)} ${n.npsValue===e&&"active"}`},e)))),t.createElement("span",{className:"positive-text"},i))),t.createElement("div",{className:"footer"},c))},a=(n,e)=>(n.defaultProps=e,n);r(".input-container,\n.textarea-container {\n display: flex;\n flex-direction: column;\n width: 100%;\n border-radius: 4px;\n position: relative;\n}\nlabel.input-label {\n display: inline-block;\n padding-bottom: 8px;\n padding-left: 2px;\n font-size: 0.75rem;\n font-weight: 400;\n}\nlabel.required::after {\n content: '*';\n position: relative;\n top: 2px;\n font-weight: 500;\n font-size: 0.85rem;\n padding-left: 3px;\n color: var(--default-error-highlight-color);\n color: var(--error-highlight-color, var(--default-error-highlight-color));\n}\n\n.input-basic {\n width: 100%;\n display: flex;\n align-items: center;\n border-radius: var(--default-border-radius);\n border-radius: var(--border-radius, var(--default-border-radius));\n border: 1px solid var(--default-input-border-color);\n border: 1px solid var(--input-border-color, var(--default-input-border-color));\n transition: border-color 0.2s linear;\n background: #fff;\n}\n.textarea-container .input-basic {\n flex-direction: column;\n align-items: unset;\n}\n.input-basic.error {\n border: 1px solid\n var(--default-error-highlight-color);\n border: 1px solid\n var(--error-highlight-color, var(--default-error-highlight-color));\n}\n.input-basic.error:hover {\n border: 1px solid\n var(--default-error-highlight-color);\n border: 1px solid\n var(--error-highlight-color, var(--default-error-highlight-color));\n}\n.input-basic.error[focus-within] {\n box-shadow: none;\n}\n.input-basic.error:focus-within {\n box-shadow: none;\n}\n.input-basic:hover {\n border-color: var(--default-input-hover-border-color)\n ;\n border-color: var(\n --input-hover-border-color,\n var(--default-input-hover-border-color)\n );\n transition: 0.2s linear;\n}\n.input-basic[focus-within] {\n border: 1px solid transparent;\n box-shadow: 0 0 0 2px\n var(--default-input-highlight-color);\n box-shadow: 0 0 0 2px\n var(--input-highlight-color, var(--default-input-highlight-color));\n}\n.input-basic:focus-within {\n border: 1px solid transparent;\n box-shadow: 0 0 0 2px\n var(--default-input-highlight-color);\n box-shadow: 0 0 0 2px\n var(--input-highlight-color, var(--default-input-highlight-color));\n}\n.end-max-length {\n padding: 0 8px;\n font-size: 0.85rem;\n}\n.textarea-container .end-max-length {\n padding: 8px;\n align-self: flex-end;\n}\nspan.input-error {\n display: block;\n padding-left: 2px;\n padding-top: 4px;\n font-size: 0.9rem;\n color: var(--default-error-highlight-color);\n color: var(--error-highlight-color, var(--default-error-highlight-color));\n}\ninput[type='text'] {\n padding: 4px 12px;\n flex: 1;\n border: unset;\n height: 32px;\n font-size: 1rem;\n /* line-height: ${typography.input.text.lineHeight}; */\n border-radius: 4px;\n}\ninput[type='text'],\ntextarea {\n outline: none;\n border: none;\n}\ninput[type='text']::-moz-placeholder {\n color: var(--default-input-placeholder-color);\n color: var(--input-placeholder-color, var(--default-input-placeholder-color));\n}\ninput[type='text']:-ms-input-placeholder {\n color: var(--default-input-placeholder-color);\n color: var(--input-placeholder-color, var(--default-input-placeholder-color));\n}\ninput[type='text']::placeholder {\n color: var(--default-input-placeholder-color);\n color: var(--input-placeholder-color, var(--default-input-placeholder-color));\n}\ntextarea {\n min-height: 116px;\n padding: 4px 12px;\n flex: 1;\n border: unset;\n resize: none;\n font-size: 1rem;\n /* line-height: ${typography.input.text.lineHeight}; */\n border-radius: 4px;\n}\ntextarea::-moz-placeholder {\n color: var(--input-placeholder-color);\n}\ntextarea:-ms-input-placeholder {\n color: var(--input-placeholder-color);\n}\ntextarea::placeholder {\n color: var(--input-placeholder-color);\n}\n");const i={isRequired:!1,showCount:!1,isErrored:!1,inline:!1,spellCheck:!1,autoFocus:!1},l=e.forwardRef(((n,e)=>{const{inputStyle:r,style:o,className:a,showCount:i,isErrored:l,startLabel:c,isRequired:s,errorText:d,endLabel:u,maxLength:p,...h}=n;return console.log(n.value),t.createElement("div",{className:"input-container",style:o},n.label&&t.createElement("label",{className:"input-label "+(s?"required":"")},n.label),t.createElement("div",null,c&&t.createElement("div",{className:"start-label"},c),t.createElement("div",{className:`input-basic ${l?"error":""}${a||""}`},t.createElement("input",Object.assign({type:"text",autoComplete:"off"},h,{ref:e,style:r})),i&&p>0&&t.createElement("div",{className:"end-max-length"},`${n.value&&n.value.length||0}/${n.maxLength}`)),u&&t.createElement("div",{className:"end-label"},u)),l&&d&&t.createElement("span",{className:"input-error"},n.errorText))})),c=e.forwardRef(((n,e)=>{const{inputStyle:r,style:o,className:a,showCount:i,maxLength:l,isErrored:c,startLabel:s,isRequired:d,...u}=n;return console.log(n.value),t.createElement(t.Fragment,null,t.createElement("div",{className:"textarea-container",style:o},n.label&&t.createElement("label",{className:"input-label "+(d?"required":"")},n.label),s&&t.createElement("div",{className:"start-label"},s),t.createElement("div",{className:`input-basic ${c?"error":""} ${a||""}`},t.createElement("textarea",Object.assign({autoComplete:"off"},u,{ref:e,style:r})),i&&l&&l>0&&t.createElement("div",{className:"end-max-length"},`${n.value&&n.value.length||0}/${n.maxLength}`)),n.endLabel&&t.createElement("div",{className:"end-label"},n.endLabel)),n.isErrored&&n.errorText&&t.createElement("span",{className:"input-error"},n.errorText))})),s=a(l,i),d=a(c,i);r(".checkbox-group {\n display: flex;\n grid-gap: 12px;\n gap: 12px;\n flex-direction: column;\n white-space: nowrap;\n flex-wrap: wrap;\n}\n.icon-container {\n display: inline-block;\n flex: 0 0 12px;\n width: 12px;\n height: 12px;\n min-width: 12px;\n min-height: 12px;\n color: inherit;\n position: absolute;\n left: 1px;\n top: 2px;\n}\n.tick-icon {\n position: absolute;\n top: 0;\n right: 0;\n bottom: 0;\n left: 0;\n height: 100%;\n width: 100%;\n color: inherit;\n fill: currentColor;\n}\ninput[type='checkbox'] {\n position: absolute;\n clip: rect(0px 0px 0px 0px);\n width: 0px;\n height: 0px;\n}\ninput[type='checkbox']:focus ~ .checkbox {\n /* box-shadow: ${pseudo.focus} 0px 0px 0px 2px; */\n box-shadow: var(--default-input-highlight-color)\n 0px 0px 0px 2px;\n box-shadow: var(--input-highlight-color, var(--default-input-highlight-color))\n 0px 0px 0px 2px;\n border-color: transparent;\n}\n.checkbox-label {\n display: flex;\n align-items: center;\n -webkit-user-select: none;\n -moz-user-select: none;\n -ms-user-select: none;\n user-select: none;\n opacity: 1;\n cursor: pointer;\n font-size: 1rem;\n padding: 16px 24px;\n min-width: 200px;\n border: 1px solid #ebeff3;\n box-shadow: 0px 2px 5px rgb(18 52 77 / 6%);\n border-radius: 4px;\n white-space: pre-wrap;\n}\n.checkbox-label.disabled {\n opacity: 0.5;\n cursor: 'not-allowed';\n}\n.checkbox {\n transition: background-color ease-in 0.2s;\n min-width: 14px;\n min-height: 14px;\n min-height: 14px;\n max-height: 14px;\n border-radius: 2px;\n position: relative;\n margin-right: 10px;\n background-color: #fff;\n border: 1px solid;\n border-color: var(--default-input-highlight-color)\n ;\n border-color: var(\n --input-highlight-color,\n var(--default-input-highlight-color)\n );\n}\n.checkbox:hover {\n border-color: var(--default-input-highlight-color)\n ;\n border-color: var(\n --input-highlight-color,\n var(--default-input-highlight-color)\n );\n box-shadow: var(--default-background-color) 0px 0px\n 0px 5px;\n box-shadow: var(--background-color, var(--default-background-color)) 0px 0px\n 0px 5px;\n}\ninput[type='checkbox']:checked ~ .checkbox {\n background-color: var(--default-input-highlight-color)\n ;\n background-color: var(\n --input-highlight-color,\n var(--default-input-highlight-color)\n );\n border-color: var(--default-input-highlight-color)\n ;\n border-color: var(\n --input-highlight-color,\n var(--default-input-highlight-color)\n );\n}\ninput[type='checkbox']:checked ~ .checkbox:hover {\n border-color: var(--default-input-highlight-color)\n ;\n border-color: var(\n --input-highlight-color,\n var(--default-input-highlight-color)\n );\n}\ninput[type='checkbox']:disabled ~ .checkbox:hover {\n box-shadow: unset;\n border-color: unset;\n}\n");const u=()=>t.createElement("svg",{id:"tick",className:"tick-icon",xmlns:"http://www.w3.org/2000/svg","aria-labelledby":"title",viewBox:"0 0 10 10"},t.createElement("path",{d:"M3 5.87c-.18666814.00267463-.36667109-.06932655-.5-.2L.21 3.41c-.1786328-.17863279-.24839684-.43899577-.1830127-.6830127.06538414-.24401694.25598306-.43461586.5-.5C.77100423 2.16160316 1.0313672 2.23136721 1.21 2.41L3 4.18 6.8.33c.27679776-.27455556.72320224-.27455556 1 0 .13696438.13025306.21450026.31098915.21450026.5S7.93696438 1.19974694 7.8 1.33L3.45 5.67c-.12082534.11896945-.28072735.19003701-.45.2Z",fill:"#fff",fillRule:"evenodd"})),p=({values:n,options:e,onChangeHandler:r})=>t.createElement("div",{className:"checkbox-group"},e.map(((e,o)=>t.createElement(h,{key:e.id,checked:n?.includes(e.id),name:e.name??e.id,id:e.id,autoFocus:0===o,onChange:(t,o)=>{if(o)r([...n||[],e.id]);else{const t=n.indexOf(e.id);t>-1&&n.splice(t,1),r([...n])}}},e.label)))),h=a(e.forwardRef(((n,e)=>t.createElement("label",{className:`checkbox-label ${n.disabled&&"disabled"}`},t.createElement("input",{ref:e,id:n.id,type:"checkbox",name:n.name,readOnly:n.readOnly,disabled:n.disabled,"aria-disabled":n.disabled,value:n.value,checked:n.checked,autoFocus:n.autoFocus,onChange:n.readOnly?()=>{}:e=>n.onChange(e,e.target.checked)}),t.createElement("div",{className:"checkbox"},n.checked&&t.createElement("div",{className:"icon-container"},t.createElement(u,null)," ")),t.createElement("div",null,n.children)))),{checked:!1});r(".radio-group {\n display: flex;\n grid-gap: 12px;\n gap: 12px;\n white-space: nowrap;\n flex-direction: column;\n}\n\n.radio {\n background-color: #fff;\n border: 1px solid;\n border-color: var(--default-input-border-color);\n border-color: var(--input-border-color, var(--default-input-border-color));\n transition: background-color ease-in 0.2s;\n min-width: 18px;\n max-width: 18px;\n min-height: 18px;\n max-height: 18px;\n border-radius: 50%;\n position: relative;\n margin-right: 12px;\n}\n.radio:before {\n left: 3px;\n top: 3px;\n content: '';\n position: absolute;\n width: 10px;\n height: 10px;\n border-radius: 50%;\n transition: all ease-in 0.2s;\n background-color: #fff;\n}\n.radio-label {\n display: flex;\n align-items: center;\n -webkit-user-select: none;\n -moz-user-select: none;\n -ms-user-select: none;\n user-select: none;\n cursor: pointer;\n font-size: 1rem;\n font-weight: 400;\n padding: 16px 24px;\n min-width: 200px;\n border: 1px solid #ebeff3;\n box-shadow: 0px 2px 5px rgb(18 52 77 / 6%);\n border-radius: 4px;\n white-space: pre-wrap;\n}\ninput[type='radio'] {\n position: absolute;\n clip: rect(0, 0, 0, 0);\n width: 0px;\n height: 0px;\n}\ninput[type='radio']:focus ~ .radio {\n /* box-shadow: ${pseudo.focus} 0px 0px 0px 3px; */\n box-shadow: var(--default-input-highlight-color)\n 0px 0px 0px 3px;\n box-shadow: var(--input-highlight-color, var(--default-input-highlight-color))\n 0px 0px 0px 3px;\n border-color: transparent;\n}\n\ninput[type='radio']:checked ~ .radio:before {\n background-color: var(--default-input-highlight-color)\n ;\n background-color: var(\n --input-highlight-color,\n var(--default-input-highlight-color)\n );\n}\n.radio-container:hover .radio {\n border-color: var(--default-input-highlight-color)\n ;\n border-color: var(\n --input-highlight-color,\n var(--default-input-highlight-color)\n );\n box-shadow: var(--default-background-color) 0px 0px\n 0px 5px;\n box-shadow: var(--background-color, var(--default-background-color)) 0px 0px\n 0px 5px;\n}\n");const b=({name:n,options:e,value:r,onChangeHandler:o})=>t.createElement("div",{className:"radio-group"},e.map(((e,a)=>t.createElement(g,{key:e.id,value:e.id,name:n,onChange:n=>{o(n.currentTarget.value)},autoFocus:0===a,checked:r===e.id},e.label)))),g=a(e.forwardRef(((n,e)=>t.createElement("label",{className:"radio-label"},t.createElement("input",{ref:e,type:"radio",name:n.name,value:n.value,checked:n.checked,onChange:n.onChange,autoFocus:n.autoFocus}),t.createElement("div",{className:"radio"}),t.createElement("div",null,n.children)))),{checked:!1,autoFocus:!1});r(".progressbar-container {\n width: 100%;\n height: 6px;\n position: fixed;\n top: 0;\n left: 0;\n z-index: 1;\n}\n.progressbar {\n transition: transform 0.25s linear;\n transform-origin: left;\n height: 100%;\n background-color: var(--default-brand-color);\n background-color: var(--brand-color, var(--default-brand-color));\n}\n");const x=n=>{const{totalSteps:e,completedSteps:r}=n;return t.createElement("div",{className:"progressbar-container"},t.createElement("div",{className:"progressbar",style:{width:(r>0?100/e:0)+"%",transform:`scaleX(${r})`}}))};r(".action-button {\n width: auto;\n display: block;\n margin: 0;\n padding: 8px 16px;\n cursor: pointer;\n line-height: 1.5;\n text-align: center;\n font-weight: 500;\n letter-spacing: 0.3px;\n border-radius: 4px;\n white-space: nowrap;\n -webkit-user-select: none;\n -moz-user-select: none;\n -ms-user-select: none;\n user-select: none;\n color: #fff;\n background: var(--default-primary-button-color);\n background: var(--primary-button-color, var(--default-primary-button-color));\n border: 1px solid var(--default-primary-button-color);\n border: 1px solid var(--primary-button-color, var(--default-primary-button-color));\n border-radius: 4px;\n min-width: 200px;\n}\n\n@media (max-width: 550px) {\n .action-button {\n min-width: 120px;\n }\n}\n.action-button:not([disabled]):hover {\n background: var(--default-primary-button-color);\n background: var(--primary-button-hover-color, var(--default-primary-button-color));\n}\n\n.action-button[disabled] {\n cursor: not-allowed;\n}\n\nbutton:focus:not(:active) {\n border: 1px solid transparent;\n /* box-shadow: 0 0 0 2px ${pseudo.focus}; */\n}");const m=()=>t.createElement(t.Fragment,null,"..."),f=n=>{const{inline:e=!1,children:r,disabled:o,className:a="",htmlType:i,type:l="primary",onClick:c,size:s,overrideStyleClassName:d="",loading:u=!1,...p}=n;return t.createElement("button",Object.assign({style:e?{display:"inline-block"}:{},disabled:o,className:`action-button ${a} ${d}`,type:i,onClick:c},p),u?t.createElement(m,null):r)},v=({question:n,formValues:e,onChangeHandler:r})=>{switch(n.type_info.question_type){case"RANGE":return t.createElement(o,{type_info:n.type_info,onChangeHandler:r,npsValue:e[n.name]});case"CHECKBOX":case"DROPDOWN":return t.createElement(p,{values:e[n.name],options:n.type_info.choices,onChangeHandler:r});case"RADIO":case"MULTICHOICE":return t.createElement(b,{name:n.name,onChangeHandler:r,options:n.type_info.choices,value:e[n.name]});case"INPUT":return t.createElement("div",{className:"responsive-text-field"},t.createElement(s,{autoFocus:!0,label:"",maxLength:300,showCount:!0,isRequired:n.is_required,value:e[n.name]||"",onChange:n=>r(n.target.value)}),t.createElement(d,{autoFocus:!0,label:"",maxLength:300,showCount:!0,isRequired:n.is_required,value:e[n.name]||"",onChange:n=>r(n.target.value)}));case"PARAGRAPH":return t.createElement(d,{autoFocus:!0,label:"",isRequired:n.is_required,value:e[n.name]||"",onChange:n=>r(n.target.value)});case"MESSAGE":return t.createElement("div",{className:"message-container"},n.type_info?.meta?.value);default:return console.error(`Question type ${n.type_info.question_type} not found`),null}};r(":root {\n --default-primary-button-color: rgb(0, 0, 0, 1);\n --default-primary-button-hover-color: #f1171b;\n --default-brand-color: #264966;\n --default-input-highlight-color: #2c5cc5;\n --default-input-border-color: #92a2b1;\n --default-input-hover-border-color: #264966;\n --default-input-placeholder-color: #92a2b1;\n --default-border-radius: 4px;\n --default-background-color: #ebeff3;\n --default-error-highlight-color: #d72d30;\n}\n\n.question-container {\n display: flex;\n flex-direction: column;\n text-align: center;\n max-width: 700px;\n margin: 0 auto;\n align-items: center;\n background: #ffffff;\n border-radius: 4px;\n transition: transform 400ms ease 0ms, opacity 200ms ease 0ms;\n box-shadow: 0px 2px 16px rgba(18, 52, 77, 0.1);\n margin-bottom: 52px;\n padding: 28px;\n grid-gap: 36px;\n gap: 36px;\n}\n\n.question-text {\n font-size: 1rem;\n line-height: 1.5;\n}\n\n.action-buttons {\n display: flex;\n justify-content: space-between;\n width: 100%;\n align-items: center;\n}\n\n.skip-button {\n cursor: pointer;\n background: transparent;\n border: none;\n min-width: 40px;\n padding: 4px 12px;\n border-radius: 4px;\n}\n\n.next-button {\n margin: 0 auto;\n}\n\n.submit {\n padding-bottom: 40px;\n display: flex;\n justify-content: center;\n}\n\n.responsive-text-field {\n width: 100%;\n}\n\n.responsive-text-field .textarea-container {\n display: none;\n}\n\n@media (max-width: 550px) {\n .responsive-text-field .input-container {\n display: none;\n }\n\n .responsive-text-field .textarea-container {\n display: flex;\n }\n}");const y=["RANGE","NPS","RADIO"],w=()=>t.createElement("div",{className:"question-container",style:{gap:"16px"}},t.createElement("h4",null,"Thank you for taking our survey!."),t.createElement("p",null," Your response is very important to us."));exports.BUTTON_SIZE_VARIANTS={LARGE:"large",MINI:"mini",NORMAL:"normal"},exports.Button=f,exports.CheckboxGroup=p,exports.Input=s,exports.NPS=o,exports.ProgressBar=x,exports.Radio=g,exports.RadioGroup=b,exports.Survey=({survey:n,onSubmit:r})=>{const{meta:{blocks:o},question_details:{questions:a}}=n,[i,l]=e.useState({}),[c,s]=e.useState(!1),[d,u]=e.useState([]),p=e.useRef(null),h=e.useRef(null),b=e.useRef(null),g=e.useRef(0),m=e.useRef(!1),k=e.useRef([]);e.useEffect((()=>{o&&!p.current&&o.length>0&&N(o[0])}),[o]),e.useEffect((()=>{b.current?.scrollIntoView({block:"center",behavior:"smooth"}),k.current=d}),[d]),e.useEffect((()=>{Object.keys(i).length>0&&h.current&&(y.includes(h.current.type_info.question_type)||m.current)&&!E()&&C()}),[i]);const E=()=>g.current===o.length-1||"end"===p.current.branchOption,N=n=>{let e={};if(n.is_based_on_score){const t=a[0].type_info.choices[i?.[a[0].name]]?.dependent_question_names,r=n.question_names.find((n=>t?.includes(n)));e=a.find((n=>n.name===r))}else e=a.find((e=>e.name===n.question_names[0]));p.current=n,h.current=e;k.current.find((n=>n.question.name===e.name))||u([...k.current,{...n,question:e}])},q=(n,e,t)=>{if(t)if(null!=i[n.question.name]&&n.name!==d[d.length-1].name){const[t,r]=(n=>{const e=d.findIndex((e=>e.name===n.name)),t=d.slice(0,e+1),r=t.reduce(((n,e)=>(n[e.question.name]=i[e.question.name],n)),{});return g.current=o.findIndex((e=>e.name===n.name)),[t,r]})(n);l({...r,...null!=e&&{[n.question.name]:e}}),k.current=t}else l({...i,...null!=e&&{[n.question.name]:e}});else l({...i,...null!=e&&{[n.question.name]:e}})},C=()=>{E()?s(!0):(p.current.nextBlock?g.current=o.findIndex((n=>n.name===p.current.nextBlock)):g.current+=1,N(o[g.current]))},_=n=>{const e=d.findIndex((e=>e.name===n.name)),t=[...d];t.splice(e,1),k.current=t,C()},R=(n,e)=>e.name===h.current.name&&!y.includes(e.type_info.question_type)&&!E(),S=(n,e)=>!n.required&&e.name===h.current.name;return p.current&&h.current?c?t.createElement(w,null):t.createElement(t.Fragment,null,t.createElement(x,{totalSteps:o.length,completedSteps:g.current}),d.map(((n,e)=>t.createElement("div",{className:"question-container",ref:b,id:n.title,key:n.title},t.createElement("div",{className:"question-text"},n.question.text),t.createElement(v,{question:n.question,formValues:i,onChangeHandler:e=>{m.current=!1,g.current=o.findIndex((e=>e.name===n.name)),p.current=n,h.current=n.question,q(n,e,y.includes(n.question.type_info.question_type)&&!E())}}),R(0,n.question)||S(n,n.question)?t.createElement("div",{className:"action-buttons"},R(0,n.question)&&t.createElement(f,{onClick:()=>{m.current=!0,q(n,null,!0)},className:"next-button"},"Next"),S(n,n.question)&&t.createElement("button",{className:"skip-button",onClick:_},"Skip")):null))),E()&&t.createElement("div",{className:"submit"},t.createElement(f,{onClick:()=>{s(!0),r(i)}},"Submit Survey"))):null},exports.TextArea=d;
package/lib/index.esm.js CHANGED
@@ -1 +1 @@
1
- import e,{useRef as n,forwardRef as t,useState as r,useEffect as o}from"react";function a(e,n){void 0===n&&(n={});var t=n.insertAt;if(e&&"undefined"!=typeof document){var r=document.head||document.getElementsByTagName("head")[0],o=document.createElement("style");o.type="text/css","top"===t&&r.firstChild?r.insertBefore(o,r.firstChild):r.appendChild(o),o.styleSheet?o.styleSheet.cssText=e:o.appendChild(document.createTextNode(e))}}a(".container {\n margin: 0 auto;\n width: 100%;\n}\n.title {\n color: var(--brand-color);\n font-weight: 600;\n}\n\n.footer {\n margin-top: 20px;\n border-top: 1px solid var(--default-background-color);\n border-top: 1px solid var(--background-color, var(--default-background-color));\n padding-top: 20px;\n display: flex;\n justify-content: center;\n font-size: 12px;\n}\n\n.widget span {\n color: #aaa;\n font-size: 12px;\n}\n.widget button {\n display: inline-block;\n font-size: 16px;\n white-space: nowrap;\n vertical-align: middle;\n background: none;\n border: none;\n box-shadow: none;\n cursor: pointer;\n text-align: center;\n font-weight: 500;\n border-radius: 4px;\n margin: 0;\n outline: none;\n margin-left: -1px;\n width: 40px;\n height: 40px;\n transform: scale(1);\n transition: background 0.2s ease-in, color 0.2s ease-in,\n border-color 0.2s ease-in, transform 0.2s cubic-bezier(0.5, 2, 0.5, 0.75);\n}\n.widget button:hover {\n color: white;\n transform: scale(1.15);\n z-index: 2;\n position: relative;\n}\n.widget button.active {\n color: white;\n transform: scale(1.15);\n z-index: 2;\n position: relative;\n}\n\n.choices {\n width: 100%;\n display: flex;\n justify-content: space-between;\n}\n\n.choice.active,\n.choice:hover:nth-child(1) {\n background: #eb5b56;\n}\n.choice.active,\n.choice:hover:nth-child(2) {\n background: #fb8774;\n}\n.choice.active,\n.choice:hover:nth-child(3) {\n background: #f58f6b;\n}\n.choice.active,\n.choice:hover:nth-child(4) {\n background: #f6996a;\n}\n.choice.active,\n.choice:hover:nth-child(5) {\n background: #eab268;\n}\n.choice.active,\n.choice:hover:nth-child(6) {\n background: #cebb69;\n}\n.choice.active,\n.choice:hover:nth-child(7) {\n background: #bdc46c;\n}\n.choice.active,\n.choice:hover:nth-child(8) {\n background: #a4cd72;\n}\n.choice.active,\n.choice:hover:nth-child(9) {\n background: #77c955;\n}\n.choice.active,\n.choice:hover:nth-child(10) {\n background: #37c248;\n}\n\n.widget.highlighted button.active,\n.widget.highlighted button:hover {\n background: var(--brand-color) !important;\n}\n.widget .rounded button {\n border-radius: 100%;\n}\n.widget .boxed button {\n border-radius: 0;\n}\n.widget {\n padding: 35px 0;\n box-sizing: border-box;\n position: relative;\n padding-bottom: 30px;\n}\n.widget .button-container {\n display: flex;\n justify-content: space-between;\n background: var(--default-background-color);\n background: var(--background-color, var(--default-background-color));\n}\n.widget .positive-text,\n.widget .negative-text {\n position: absolute;\n color: var(--color-elephant-500);\n}\n.widget .positive-text {\n right: 0px;\n bottom: 5px;\n text-align: right;\n}\n.widget .negative-text {\n left: 0;\n bottom: 5px;\n text-align: left;\n}\n@media (max-width: 550px) {\n .widget .button-container {\n background: transparent;\n }\n .widget .choices {\n flex-wrap: wrap;\n justify-content: center;\n grid-gap: 16px;\n gap: 16px;\n background: transparent;\n }\n .widget button {\n border-radius: 50%;\n background: #ebeff3;\n }\n}\n");const i=t=>{const{type_info:{linear_scale:{button_shape:r,button_style:o},score_presets:{start:a,end:i},validation:{min:l},footer_text:c}}=t,d=e=>{switch(e){case e<4:return"detractor";case e<7:return"passive";default:return"promoter"}},s=n(Array.from({length:10},((e,n)=>n+l)));return e.createElement("div",{className:"container"},e.createElement("div",{className:`widget ${r} ${o}`},e.createElement("div",{className:"button-container"},e.createElement("span",{className:"negative-text"},a),e.createElement("div",{className:"choices"},s.current.map((n=>e.createElement("button",{onClick:e=>{t.onChangeHandler(n)},className:`choice ${d(n)} ${t.npsValue===n&&"active"}`},n)))),e.createElement("span",{className:"positive-text"},i))),e.createElement("div",{className:"footer"},c))},l=(e,n)=>(e.defaultProps=n,e);a(".input-container,\n.textarea-container {\n display: flex;\n flex-direction: column;\n width: 100%;\n border-radius: 4px;\n position: relative;\n}\nlabel.input-label {\n display: inline-block;\n padding-bottom: 8px;\n padding-left: 2px;\n font-size: 12px;\n font-weight: 400;\n}\nlabel.required::after {\n content: '*';\n position: relative;\n top: 2px;\n font-weight: 500;\n font-size: 0.85rem;\n padding-left: 3px;\n color: var(--default-error-highlight-color);\n color: var(--error-highlight-color,var(--default-error-highlight-color));\n}\n\n.input-basic {\n width: 100%;\n display: flex;\n align-items: center;\n border-radius: var(--default-border-radius);\n border-radius: var(--border-radius,var(--default-border-radius));\n border: 1px solid var(--default-input-border-color));\n border: 1px solid var(--input-border-color,var(--default-input-border-color)));\n transition: border-color 0.2s linear;\n background: #fff;\n}\n.textarea-container .input-basic {\n flex-direction: column;\n align-items: unset;\n}\n.input-basic.error {\n border: 1px solid var(--default-error-highlight-color);\n border: 1px solid var(--error-highlight-color,var(--default-error-highlight-color));\n}\n.input-basic.error:hover {\n border: 1px solid var(--default-error-highlight-color);\n border: 1px solid var(--error-highlight-color,var(--default-error-highlight-color));\n}\n.input-basic.error[focus-within] {\n box-shadow: none;\n}\n.input-basic.error:focus-within {\n box-shadow: none;\n}\n.input-basic:hover {\n border-color: var(--default-input-hover-border-color));\n border-color: var(--input-hover-border-color,var(--default-input-hover-border-color)));\n transition: 0.2s linear;\n}\n.input-basic[focus-within] {\n border: 1px solid transparent;\n box-shadow: 0 0 0 2px\n var(--default-input-highlight-color);\n box-shadow: 0 0 0 2px\n var(--input-highlight-color, var(--default-input-highlight-color));\n}\n.input-basic:focus-within {\n border: 1px solid transparent;\n box-shadow: 0 0 0 2px\n var(--default-input-highlight-color);\n box-shadow: 0 0 0 2px\n var(--input-highlight-color, var(--default-input-highlight-color));\n}\n.end-max-length {\n padding: 0 8px;\n font-size: 0.85rem;\n}\n.textarea-container .end-max-length {\n padding: 8px;\n align-self: flex-end;\n}\nspan.input-error {\n display: block;\n padding-left: 2px;\n padding-top: 4px;\n font-size: 0.9rem;\n color: var(--default-error-highlight-color);\n color: var(--error-highlight-color,var(--default-error-highlight-color));\n}\ninput[type='text'] {\n padding: 4px 12px;\n flex: 1;\n border: unset;\n height: 32px;\n font-size: 1rem;\n /* line-height: ${typography.input.text.lineHeight}; */\n font-weight: 500;\n border-radius: 4px;\n}\ninput[type='text'],\ntextarea {\n outline: none;\n border: none;\n}\ninput[type='text']::-moz-placeholder {\n color: var(--input-placeholder-color);\n}\ninput[type='text']:-ms-input-placeholder {\n color: var(--input-placeholder-color);\n}\ninput[type='text']::placeholder {\n color: var(--input-placeholder-color);\n}\ntextarea {\n min-height: 116px;\n padding: 4px 12px;\n flex: 1;\n border: unset;\n resize: none;\n font-size: 1rem;\n /* line-height: ${typography.input.text.lineHeight}; */\n font-weight: 500;\n border-radius: 4px;\n}\ntextarea::-moz-placeholder {\n color: var(--input-placeholder-color);\n}\ntextarea:-ms-input-placeholder {\n color: var(--input-placeholder-color);\n}\ntextarea::placeholder {\n color: var(--input-placeholder-color);\n}\n");const c={isRequired:!1,showCount:!1,isErrored:!1,inline:!1,spellCheck:!1,autoFocus:!1},d=t(((n,t)=>{const{inputStyle:r,style:o,className:a,showCount:i,isErrored:l,startLabel:c,isRequired:d,errorText:s,endLabel:u,maxLength:p,...h}=n;return console.log(n.value),e.createElement("div",{className:"input-container",style:o},n.label&&e.createElement("label",{className:"input-label "+(d?"required":"")},n.label),e.createElement("div",null,c&&e.createElement("div",{className:"start-label"},c),e.createElement("div",{className:`input-basic ${l?"error":""}${a||""}`},e.createElement("input",Object.assign({type:"text",autoComplete:"off"},h,{ref:t,style:r})),i&&p>0&&e.createElement("div",{className:"end-max-length"},`${n.value&&n.value.length||0}/${n.maxLength}`)),u&&e.createElement("div",{className:"end-label"},u)),l&&s&&e.createElement("span",{className:"input-error"},n.errorText))})),s=t(((n,t)=>{const{inputStyle:r,style:o,className:a,showCount:i,maxLength:l,isErrored:c,startLabel:d,isRequired:s,...u}=n;return console.log(n.value),e.createElement(e.Fragment,null,e.createElement("div",{className:"textarea-container",style:o},n.label&&e.createElement("label",{className:"input-label "+(s?"required":"")},n.label),d&&e.createElement("div",{className:"start-label"},d),e.createElement("div",{className:`input-basic ${c?"error":""} ${a||""}`},e.createElement("textarea",Object.assign({autoComplete:"off"},u,{ref:t,style:r})),i&&l&&l>0&&e.createElement("div",{className:"end-max-length"},`${n.value&&n.value.length||0}/${n.maxLength}`)),n.endLabel&&e.createElement("div",{className:"end-label"},n.endLabel)),n.isErrored&&n.errorText&&e.createElement("span",{className:"input-error"},n.errorText))})),u=l(d,c),p=l(s,c);a(".checkbox-group {\n display: flex;\n align-items: center;\n grid-gap: 12px;\n gap: 12px;\n flex-direction: column;\n white-space: nowrap;\n flex-wrap: wrap;\n}\n.icon-container {\n display: inline-block;\n flex: 0 0 12px;\n width: 12px;\n height: 12px;\n min-width: 12px;\n min-height: 12px;\n color: inherit;\n position: absolute;\n left: 1px;\n top: 2px;\n}\n.tick-icon {\n position: absolute;\n top: 0;\n right: 0;\n bottom: 0;\n left: 0;\n height: 100%;\n width: 100%;\n color: inherit;\n fill: currentColor;\n}\ninput[type='checkbox'] {\n clip: rect(0px 0px 0px 0px);\n width: 0px;\n height: 0px;\n}\ninput[type='checkbox']:focus ~ .checkbox {\n /* box-shadow: ${pseudo.focus} 0px 0px 0px 2px; */\n box-shadow: var(--default-input-highlight-color)\n 0px 0px 0px 2px;\n box-shadow: var(--input-highlight-color, var(--default-input-highlight-color))\n 0px 0px 0px 2px;\n border-color: transparent;\n}\n.checkbox-label {\n display: flex;\n align-items: center;\n -webkit-user-select: none;\n -moz-user-select: none;\n -ms-user-select: none;\n user-select: none;\n opacity: 1;\n cursor: pointer;\n font-size: 1rem;\n font-weight: 500;\n padding: 16px;\n min-width: 200px;\n border: 1px solid #ebeff3;\n box-shadow: 0px 2px 5px rgb(18 52 77 / 10%);\n border-radius: 4px;\n}\n.checkbox-label.disabled {\n opacity: 0.5;\n cursor: 'not-allowed';\n}\n.checkbox {\n transition: background-color ease-in 0.2s;\n min-width: 14px;\n min-height: 14px;\n border-radius: 2px;\n position: relative;\n margin-right: 10px;\n background-color: #fff;\n border: 1px solid;\n border-color: var(--default-input-highlight-color)\n ;\n border-color: var(\n --input-highlight-color,\n var(--default-input-highlight-color)\n );\n}\n.checkbox:hover {\n border-color: var(--default-input-highlight-color)\n ;\n border-color: var(\n --input-highlight-color,\n var(--default-input-highlight-color)\n );\n box-shadow: var(--default-background-color) 0px 0px\n 0px 5px;\n box-shadow: var(--background-color, var(--default-background-color)) 0px 0px\n 0px 5px;\n}\ninput[type='checkbox']:checked ~ .checkbox {\n background-color: var(--default-input-highlight-color)\n ;\n background-color: var(\n --input-highlight-color,\n var(--default-input-highlight-color)\n );\n border-color: var(--default-input-highlight-color)\n ;\n border-color: var(\n --input-highlight-color,\n var(--default-input-highlight-color)\n );\n}\ninput[type='checkbox']:checked ~ .checkbox:hover {\n border-color: var(--default-input-highlight-color)\n ;\n border-color: var(\n --input-highlight-color,\n var(--default-input-highlight-color)\n );\n}\ninput[type='checkbox']:disabled ~ .checkbox:hover {\n box-shadow: unset;\n border-color: unset;\n}\n");const h=()=>e.createElement("svg",{id:"tick",className:"tick-icon",xmlns:"http://www.w3.org/2000/svg","aria-labelledby":"title",viewBox:"0 0 10 10"},e.createElement("path",{d:"M3 5.87c-.18666814.00267463-.36667109-.06932655-.5-.2L.21 3.41c-.1786328-.17863279-.24839684-.43899577-.1830127-.6830127.06538414-.24401694.25598306-.43461586.5-.5C.77100423 2.16160316 1.0313672 2.23136721 1.21 2.41L3 4.18 6.8.33c.27679776-.27455556.72320224-.27455556 1 0 .13696438.13025306.21450026.31098915.21450026.5S7.93696438 1.19974694 7.8 1.33L3.45 5.67c-.12082534.11896945-.28072735.19003701-.45.2Z",fill:"#fff",fillRule:"evenodd"})),g=({values:n,options:t,onChangeHandler:r})=>e.createElement("div",{className:"checkbox-group"},t.map(((t,o)=>e.createElement(b,{key:t.id,checked:n?.includes(t.id),name:t.name??t.id,id:t.id,autoFocus:0===o,onChange:(e,o)=>{if(o)r([...n||[],t.id]);else{const e=n.indexOf(t.id);e>-1&&n.splice(e,1),r([...n])}}},t.label)))),b=l(t(((n,t)=>e.createElement("label",{className:`checkbox-label ${n.disabled&&"disabled"}`},e.createElement("input",{ref:t,id:n.id,type:"checkbox",name:n.name,readOnly:n.readOnly,disabled:n.disabled,"aria-disabled":n.disabled,value:n.value,checked:n.checked,autoFocus:n.autoFocus,onChange:n.readOnly?()=>{}:e=>n.onChange(e,e.target.checked)}),e.createElement("div",{className:"checkbox"},n.checked&&e.createElement("div",{className:"icon-container"},e.createElement(h,null)," ")),e.createElement("div",null,n.children)))),{checked:!1});a(".radio-group {\n display: flex;\n align-items: center;\n grid-gap: 12px;\n gap: 12px;\n white-space: nowrap;\n flex-direction: column;\n}\n\n.radio {\n background-color: #fff;\n border: 1px solid;\n border-color: var(--default-input-border-color));\n border-color: var(--input-border-color,var(--default-input-border-color)));\n transition: background-color ease-in 0.2s;\n width: 18px;\n height: 18px;\n border-radius: 50%;\n position: relative;\n margin-right: 12px;\n}\n.radio:before {\n left: 3px;\n top: 3px;\n content: '';\n position: absolute;\n width: 10px;\n height: 10px;\n border-radius: 50%;\n transition: all ease-in 0.2s;\n background-color: #fff;\n}\n.radio-label {\n display: flex;\n align-items: center;\n -webkit-user-select: none;\n -moz-user-select: none;\n -ms-user-select: none;\n user-select: none;\n cursor: pointer;\n font-size: 1rem;\n font-weight: 500;\n padding: 16px;\n min-width: 200px;\n border: 1px solid #ebeff3;\n box-shadow: 0px 2px 5px rgb(18 52 77 / 10%);\n border-radius: 4px;\n}\ninput[type='radio'] {\n clip: rect(0, 0, 0, 0);\n position: absolute;\n}\ninput[type='radio']:focus ~ .radio {\n /* box-shadow: ${pseudo.focus} 0px 0px 0px 3px; */\n box-shadow: var(--default-input-highlight-color)\n 0px 0px 0px 3px;\n box-shadow: var(--input-highlight-color, var(--default-input-highlight-color))\n 0px 0px 0px 3px;\n border-color: transparent;\n}\n\ninput[type='radio']:checked ~ .radio:before {\n background-color: var(--default-input-highlight-color)\n ;\n background-color: var(\n --input-highlight-color,\n var(--default-input-highlight-color)\n );\n}\n.radio-container:hover .radio {\n border-color: var(--default-input-highlight-color)\n ;\n border-color: var(\n --input-highlight-color,\n var(--default-input-highlight-color)\n );\n box-shadow: var(--default-background-color) 0px 0px 0px 5px;\n box-shadow: var(--background-color,var(--default-background-color)) 0px 0px 0px 5px;\n}\n");const x=({name:n,options:t,value:r,onChangeHandler:o})=>e.createElement("div",{className:"radio-group"},t.map((t=>e.createElement(m,{key:t.id,value:t.id,name:n,onChange:e=>{o(e.currentTarget.value)},checked:r===t.id},t.label)))),m=l(t(((n,t)=>e.createElement("label",{className:"radio-label"},e.createElement("input",{ref:t,type:"radio",name:n.name,value:n.value,checked:n.checked,onClick:n.onChange,autoFocus:!0}),e.createElement("div",{className:"radio"}),e.createElement("div",null,n.children)))),{checked:!1});a(".progressbar-container {\n width: 100%;\n height: 6px;\n position: fixed;\n top: 0;\n left: 0;\n z-index: 1;\n}\n.progressbar {\n transition: transform 0.25s linear;\n transform-origin: left;\n height: 100%;\n background-color: var(--brand-color);\n}\n");const f=n=>{const{totalSteps:t,completedSteps:r}=n;return e.createElement("div",{className:"progressbar-container"},e.createElement("div",{className:"progressbar",style:{width:(r>0?100/t:0)+"%",transform:`scaleX(${r})`}}))};a(".action-button {\n width: auto;\n display: block;\n margin: 0;\n padding: 8px 16px;\n cursor: pointer;\n line-height: 1.5;\n text-align: center;\n font-weight: 500;\n letter-spacing: 0.3px;\n border-radius: 4px;\n white-space: nowrap;\n -webkit-user-select: none;\n -moz-user-select: none;\n -ms-user-select: none;\n user-select: none;\n color: #fff;\n background: var(--primary-button-color);\n border: 1px solid var(--primary-button-color);\n border-radius: 4px;\n min-width: 200px;\n}\n@media (max-width: 550px) {\n .action-button {\n min-width: 120px;\n }\n}\n\n.action-button:not([disabled]):hover {\n background: var(--primary-button-hover-color);\n /* background-color: ${hover}; */\n}\n\n.action-button:not([disabled]):active {\n}\n\n.action-button[disabled] {\n cursor: not-allowed;\n}\n\nbutton:focus:not(:active) {\n border: 1px solid transparent;\n /* box-shadow: 0 0 0 2px ${pseudo.focus}; */\n}\n");const v=()=>e.createElement(e.Fragment,null,"..."),w={LARGE:"large",MINI:"mini",NORMAL:"normal"},k=n=>{const{inline:t=!1,children:r,disabled:o,className:a="",htmlType:i,type:l="primary",onClick:c,size:d,overrideStyleClassName:s="",loading:u=!1,...p}=n;return e.createElement("button",Object.assign({style:t?{display:"inline-block"}:{},disabled:o,className:`action-button ${a} ${s}`,type:i,onClick:c},p),u?e.createElement(v,null):r)},y=({question:n,formValues:t,onChangeHandler:r})=>{switch(n.type_info.question_type){case"RANGE":return e.createElement(i,{type_info:n.type_info,onChangeHandler:r,npsValue:t[n.name]});case"CHECKBOX":return e.createElement(g,{values:t[n.name],options:n.type_info.choices,onChangeHandler:r});case"CHECKBOX":return e.createElement(x,{name:n.name,onChangeHandler:r,options:n.type_info.choices,value:t[n.name]});case"MESSAGE":return e.createElement("div",{className:"responsive-text-field"},e.createElement(u,{autoFocus:!0,label:"",maxLength:300,showCount:!0,isRequired:n.is_required,value:t[n.name]||"",onChange:e=>r(e.target.value)}),e.createElement(p,{autoFocus:!0,label:"",maxLength:300,showCount:!0,isRequired:n.is_required,value:t[n.name]||"",onChange:e=>r(e.target.value)}));case"PARAGRAPH":return e.createElement(p,{autoFocus:!0,label:"",isRequired:n.is_required,value:t[n.name]||"",onChange:e=>r(e.target.value)});default:return console.error(`Question type ${n.type_info.question_type} not found`),null}};a(":root {\n --default-primary-button-color: #d72d30;\n --default-primary-button-hover-color: #f1171b;\n --default-brand-color: #264966;\n --default-input-highlight-color: #2c5cc5;\n --default-input-border-color: #92a2b1;\n --default-input-hover-border-color: #264966;\n --default-input-placeholder-color: #92a2b1;\n --default-border-radius: 4px;\n --default-background-color: #ebeff3;\n --default-error-highlight-color: #d72d30;\n}\n.question-container {\n display: flex;\n flex-direction: column;\n text-align: center;\n max-width: 700px;\n margin: 0 auto;\n align-items: center;\n background: #ffffff;\n border-radius: 4px;\n transition: transform 400ms ease 0ms, opacity 200ms ease 0ms;\n box-shadow: 0px 2px 16px rgba(18, 52, 77, 0.1);\n margin-bottom: 40px;\n padding: 20px;\n grid-gap: 28px;\n gap: 28px;\n}\n.question-text {\n font-size: 1.1rem;\n line-height: 1.5;\n}\n\n.action-buttons {\n display: flex;\n justify-content: space-between;\n width: 100%;\n align-items: center;\n}\n.skip-button {\n cursor: pointer;\n background: transparent;\n border: none;\n min-width: 40px;\n padding: 4px 12px;\n border-radius: 4px;\n}\n\n.next-button {\n margin: 0 auto;\n}\n.submit {\n padding-bottom: 40px;\n display: flex;\n justify-content: center;\n}\n.responsive-text-field {\n width: 100%;\n}\n.responsive-text-field .textarea-container {\n display: none;\n}\n\n@media (max-width: 550px) {\n .responsive-text-field .input-container {\n display: none;\n }\n .responsive-text-field .textarea-container {\n display: flex;\n }\n}\n");const E=["RANGE","NPS","RADIO"],N=()=>e.createElement("div",{className:"question-container",style:{gap:"16px"}},e.createElement("h4",null,"Thank you for taking our survey!."),e.createElement("p",null," Your response is very important to us.")),q=({survey:t,onSubmit:a})=>{const{meta:{blocks:i},question_details:{questions:l}}=t,[c,d]=r({}),[s,u]=r(!1),[p,h]=r([]),g=n(null),b=n(null),x=n(null),m=n(0),v=n(!1),w=n([]);o((()=>{i&&!g.current&&i.length>0&&C(i[0])}),[i]),o((()=>{x.current?.scrollIntoView({block:"center",behavior:"smooth"}),w.current=p}),[p]),o((()=>{Object.keys(c).length>0&&b.current&&(E.includes(b.current.type_info.question_type)||v.current)&&!q()&&z()}),[c]);const q=()=>m.current===i.length-1||"end"===g.current.branchOption,C=e=>{let n={};if(e.is_based_on_score){const t=l[0].type_info.choices[c?.[l[0].name]]?.dependent_question_names,r=e.question_names.find((e=>t?.includes(e)));n=l.find((e=>e.name===r))}else n=l.find((n=>n.name===e.question_names[0]));g.current=e,b.current=n;w.current.find((e=>e.question.name===n.name))||h([...w.current,{...e,question:n}])},_=(e,n,t)=>{if(t)if(null!=c[e.question.name]&&e.name!==p[p.length-1].name){const[t,r]=(e=>{const n=p.findIndex((n=>n.name===e.name)),t=p.slice(0,n+1),r=t.reduce(((e,n)=>(e[n.question.name]=c[n.question.name],e)),{});return m.current=i.findIndex((n=>n.name===e.name)),[t,r]})(e);d({...r,...null!=n&&{[e.question.name]:n}}),w.current=t}else d({...c,...null!=n&&{[e.question.name]:n}});else d({...c,...null!=n&&{[e.question.name]:n}})},z=()=>{q()?u(!0):(g.current.nextBlock?m.current=i.findIndex((e=>e.name===g.current.nextBlock)):m.current+=1,C(i[m.current]))},$=e=>{const n=p.findIndex((n=>n.name===e.name)),t=[...p];t.splice(n,1),w.current=t,z()};return g.current&&b.current?s?e.createElement(N,null):e.createElement(e.Fragment,null,e.createElement(f,{totalSteps:i.length,completedSteps:m.current}),p.map(((n,t)=>{return e.createElement("div",{className:"question-container",ref:x,id:n.title,key:n.title},e.createElement("div",{className:"question-text"},n.question.text),e.createElement(y,{question:n.question,formValues:c,onChangeHandler:e=>{v.current=!1,m.current=i.findIndex((e=>e.name===n.name)),g.current=n,b.current=n.question,_(n,e,E.includes(n.question.type_info.question_type)&&!q())}}),e.createElement("div",{className:"action-buttons"},(r=n.question,r.name===b.current.name&&!E.includes(r.type_info.question_type)&&!q()&&e.createElement(k,{onClick:()=>{v.current=!0,_(n,null,!0)},className:"next-button"},"Next")),((e,n)=>!e.required&&n.name===b.current.name)(n,n.question)&&e.createElement("button",{className:"skip-button",onClick:$},"Skip")));var r})),q()&&e.createElement("div",{className:"submit"},e.createElement(k,{onClick:()=>{u(!0),a(c)}},"Submit Survey"))):null};export{w as BUTTON_SIZE_VARIANTS,k as Button,g as CheckboxGroup,u as Input,i as NPS,f as ProgressBar,m as Radio,x as RadioGroup,q as Survey,p as TextArea};
1
+ import n,{useRef as e,forwardRef as t,useState as r,useEffect as o}from"react";function a(n,e){void 0===e&&(e={});var t=e.insertAt;if(n&&"undefined"!=typeof document){var r=document.head||document.getElementsByTagName("head")[0],o=document.createElement("style");o.type="text/css","top"===t&&r.firstChild?r.insertBefore(o,r.firstChild):r.appendChild(o),o.styleSheet?o.styleSheet.cssText=n:o.appendChild(document.createTextNode(n))}}a(".nps-container {\n margin: 0 auto;\n width: 100%;\n display: flex;\n flex-direction: column;\n grid-gap: 52px;\n gap: 52px;\n}\n.nps-container .footer {\n border-top: 1px solid var(--default-background-color);\n border-top: 1px solid var(--background-color, var(--default-background-color));\n padding-top: 20px;\n display: flex;\n justify-content: center;\n font-size: 0.75rem;\n}\n.nps-container .widget {\n position: relative;\n}\n.nps-container .widget .button-container {\n display: flex;\n justify-content: space-between;\n background: var(--default-background-color);\n background: var(--background-color, var(--default-background-color));\n}\n.nps-container .widget .positive-text {\n position: absolute;\n color: var(--color-elephant-500);\n bottom: -28px;\n right: 0px;\n text-align: right;\n}\n.nps-container .widget .negative-text {\n position: absolute;\n color: var(--color-elephant-500);\n bottom: -28px;\n left: 0;\n text-align: left;\n}\n.nps-container .widget span {\n color: #aaa;\n font-size: 0.75rem;\n}\n.nps-container .widget button {\n display: inline-block;\n font-size: 1rem;\n white-space: nowrap;\n vertical-align: middle;\n background: none;\n border: none;\n box-shadow: none;\n cursor: pointer;\n text-align: center;\n font-weight: 400;\n border-radius: 4px;\n margin: 0;\n outline: none;\n margin-left: -1px;\n width: 40px;\n height: 40px;\n transform: scale(1);\n transition: background 0.2s ease-in, color 0.2s ease-in, border-color 0.2s ease-in, transform 0.2s cubic-bezier(0.5, 2, 0.5, 0.75);\n}\n.nps-container .widget button:hover {\n color: white;\n transform: scale(1.15);\n z-index: 2;\n position: relative;\n}\n.nps-container .widget button.active {\n color: white;\n transform: scale(1.15);\n z-index: 2;\n position: relative;\n}\n.nps-container .widget.highlighted button:hover, .nps-container .widget.highlighted button.active {\n background: var(--default-brand-color) !important;\n background: var(--brand-color, var(--default-brand-color)) !important;\n}\n.nps-container .widget.rounded button {\n border-radius: 50%;\n}\n.nps-container .widget.rounded.boxed button {\n border-radius: 0;\n}\n.nps-container .choices {\n width: 100%;\n display: flex;\n justify-content: space-between;\n}\n.nps-container .choice:nth-child(1).active, .nps-container .choice:nth-child(1):hover {\n background: #eb5b56;\n}\n.nps-container .choice:nth-child(2).active, .nps-container .choice:nth-child(2):hover {\n background: #fb8774;\n}\n.nps-container .choice:nth-child(3).active, .nps-container .choice:nth-child(3):hover {\n background: #f58f6b;\n}\n.nps-container .choice:nth-child(4).active, .nps-container .choice:nth-child(4):hover {\n background: #f6996a;\n}\n.nps-container .choice:nth-child(5).active, .nps-container .choice:nth-child(5):hover {\n background: #eab268;\n}\n.nps-container .choice:nth-child(6).active, .nps-container .choice:nth-child(6):hover {\n background: #cebb69;\n}\n.nps-container .choice:nth-child(7).active, .nps-container .choice:nth-child(7):hover {\n background: #bdc46c;\n}\n.nps-container .choice:nth-child(8).active, .nps-container .choice:nth-child(8):hover {\n background: #a4cd72;\n}\n.nps-container .choice:nth-child(9).active, .nps-container .choice:nth-child(9):hover {\n background: #77c955;\n}\n.nps-container .choice:nth-child(9).active, .nps-container .choice:nth-child(9):hover {\n background: #37c248;\n}\n\n@media (max-width: 550px) {\n .nps-container .widget .button-container {\n background: transparent;\n }\n .nps-container .widget .choices {\n flex-wrap: wrap;\n justify-content: center;\n grid-gap: 16px;\n gap: 16px;\n background: transparent;\n }\n .nps-container .widget button {\n border-radius: 50%;\n background: #ebeff3;\n }\n}");const i=t=>{const{type_info:{linear_scale:{button_shape:r,button_style:o},score_presets:{start:a,end:i},validation:{min:l},footer_text:c}}=t,d=n=>{switch(n){case n<4:return"detractor";case n<7:return"passive";default:return"promoter"}},s=e(Array.from({length:10},((n,e)=>e+l)));return n.createElement("div",{className:"nps-container"},n.createElement("div",{className:`widget ${r} ${o}`},n.createElement("div",{className:"button-container"},n.createElement("span",{className:"negative-text"},a),n.createElement("div",{className:"choices"},s.current.map((e=>n.createElement("button",{key:e,onClick:n=>{t.onChangeHandler(e)},className:`choice ${d(e)} ${t.npsValue===e&&"active"}`},e)))),n.createElement("span",{className:"positive-text"},i))),n.createElement("div",{className:"footer"},c))},l=(n,e)=>(n.defaultProps=e,n);a(".input-container,\n.textarea-container {\n display: flex;\n flex-direction: column;\n width: 100%;\n border-radius: 4px;\n position: relative;\n}\nlabel.input-label {\n display: inline-block;\n padding-bottom: 8px;\n padding-left: 2px;\n font-size: 0.75rem;\n font-weight: 400;\n}\nlabel.required::after {\n content: '*';\n position: relative;\n top: 2px;\n font-weight: 500;\n font-size: 0.85rem;\n padding-left: 3px;\n color: var(--default-error-highlight-color);\n color: var(--error-highlight-color, var(--default-error-highlight-color));\n}\n\n.input-basic {\n width: 100%;\n display: flex;\n align-items: center;\n border-radius: var(--default-border-radius);\n border-radius: var(--border-radius, var(--default-border-radius));\n border: 1px solid var(--default-input-border-color);\n border: 1px solid var(--input-border-color, var(--default-input-border-color));\n transition: border-color 0.2s linear;\n background: #fff;\n}\n.textarea-container .input-basic {\n flex-direction: column;\n align-items: unset;\n}\n.input-basic.error {\n border: 1px solid\n var(--default-error-highlight-color);\n border: 1px solid\n var(--error-highlight-color, var(--default-error-highlight-color));\n}\n.input-basic.error:hover {\n border: 1px solid\n var(--default-error-highlight-color);\n border: 1px solid\n var(--error-highlight-color, var(--default-error-highlight-color));\n}\n.input-basic.error[focus-within] {\n box-shadow: none;\n}\n.input-basic.error:focus-within {\n box-shadow: none;\n}\n.input-basic:hover {\n border-color: var(--default-input-hover-border-color)\n ;\n border-color: var(\n --input-hover-border-color,\n var(--default-input-hover-border-color)\n );\n transition: 0.2s linear;\n}\n.input-basic[focus-within] {\n border: 1px solid transparent;\n box-shadow: 0 0 0 2px\n var(--default-input-highlight-color);\n box-shadow: 0 0 0 2px\n var(--input-highlight-color, var(--default-input-highlight-color));\n}\n.input-basic:focus-within {\n border: 1px solid transparent;\n box-shadow: 0 0 0 2px\n var(--default-input-highlight-color);\n box-shadow: 0 0 0 2px\n var(--input-highlight-color, var(--default-input-highlight-color));\n}\n.end-max-length {\n padding: 0 8px;\n font-size: 0.85rem;\n}\n.textarea-container .end-max-length {\n padding: 8px;\n align-self: flex-end;\n}\nspan.input-error {\n display: block;\n padding-left: 2px;\n padding-top: 4px;\n font-size: 0.9rem;\n color: var(--default-error-highlight-color);\n color: var(--error-highlight-color, var(--default-error-highlight-color));\n}\ninput[type='text'] {\n padding: 4px 12px;\n flex: 1;\n border: unset;\n height: 32px;\n font-size: 1rem;\n /* line-height: ${typography.input.text.lineHeight}; */\n border-radius: 4px;\n}\ninput[type='text'],\ntextarea {\n outline: none;\n border: none;\n}\ninput[type='text']::-moz-placeholder {\n color: var(--default-input-placeholder-color);\n color: var(--input-placeholder-color, var(--default-input-placeholder-color));\n}\ninput[type='text']:-ms-input-placeholder {\n color: var(--default-input-placeholder-color);\n color: var(--input-placeholder-color, var(--default-input-placeholder-color));\n}\ninput[type='text']::placeholder {\n color: var(--default-input-placeholder-color);\n color: var(--input-placeholder-color, var(--default-input-placeholder-color));\n}\ntextarea {\n min-height: 116px;\n padding: 4px 12px;\n flex: 1;\n border: unset;\n resize: none;\n font-size: 1rem;\n /* line-height: ${typography.input.text.lineHeight}; */\n border-radius: 4px;\n}\ntextarea::-moz-placeholder {\n color: var(--input-placeholder-color);\n}\ntextarea:-ms-input-placeholder {\n color: var(--input-placeholder-color);\n}\ntextarea::placeholder {\n color: var(--input-placeholder-color);\n}\n");const c={isRequired:!1,showCount:!1,isErrored:!1,inline:!1,spellCheck:!1,autoFocus:!1},d=t(((e,t)=>{const{inputStyle:r,style:o,className:a,showCount:i,isErrored:l,startLabel:c,isRequired:d,errorText:s,endLabel:p,maxLength:u,...h}=e;return console.log(e.value),n.createElement("div",{className:"input-container",style:o},e.label&&n.createElement("label",{className:"input-label "+(d?"required":"")},e.label),n.createElement("div",null,c&&n.createElement("div",{className:"start-label"},c),n.createElement("div",{className:`input-basic ${l?"error":""}${a||""}`},n.createElement("input",Object.assign({type:"text",autoComplete:"off"},h,{ref:t,style:r})),i&&u>0&&n.createElement("div",{className:"end-max-length"},`${e.value&&e.value.length||0}/${e.maxLength}`)),p&&n.createElement("div",{className:"end-label"},p)),l&&s&&n.createElement("span",{className:"input-error"},e.errorText))})),s=t(((e,t)=>{const{inputStyle:r,style:o,className:a,showCount:i,maxLength:l,isErrored:c,startLabel:d,isRequired:s,...p}=e;return console.log(e.value),n.createElement(n.Fragment,null,n.createElement("div",{className:"textarea-container",style:o},e.label&&n.createElement("label",{className:"input-label "+(s?"required":"")},e.label),d&&n.createElement("div",{className:"start-label"},d),n.createElement("div",{className:`input-basic ${c?"error":""} ${a||""}`},n.createElement("textarea",Object.assign({autoComplete:"off"},p,{ref:t,style:r})),i&&l&&l>0&&n.createElement("div",{className:"end-max-length"},`${e.value&&e.value.length||0}/${e.maxLength}`)),e.endLabel&&n.createElement("div",{className:"end-label"},e.endLabel)),e.isErrored&&e.errorText&&n.createElement("span",{className:"input-error"},e.errorText))})),p=l(d,c),u=l(s,c);a(".checkbox-group {\n display: flex;\n grid-gap: 12px;\n gap: 12px;\n flex-direction: column;\n white-space: nowrap;\n flex-wrap: wrap;\n}\n.icon-container {\n display: inline-block;\n flex: 0 0 12px;\n width: 12px;\n height: 12px;\n min-width: 12px;\n min-height: 12px;\n color: inherit;\n position: absolute;\n left: 1px;\n top: 2px;\n}\n.tick-icon {\n position: absolute;\n top: 0;\n right: 0;\n bottom: 0;\n left: 0;\n height: 100%;\n width: 100%;\n color: inherit;\n fill: currentColor;\n}\ninput[type='checkbox'] {\n position: absolute;\n clip: rect(0px 0px 0px 0px);\n width: 0px;\n height: 0px;\n}\ninput[type='checkbox']:focus ~ .checkbox {\n /* box-shadow: ${pseudo.focus} 0px 0px 0px 2px; */\n box-shadow: var(--default-input-highlight-color)\n 0px 0px 0px 2px;\n box-shadow: var(--input-highlight-color, var(--default-input-highlight-color))\n 0px 0px 0px 2px;\n border-color: transparent;\n}\n.checkbox-label {\n display: flex;\n align-items: center;\n -webkit-user-select: none;\n -moz-user-select: none;\n -ms-user-select: none;\n user-select: none;\n opacity: 1;\n cursor: pointer;\n font-size: 1rem;\n padding: 16px 24px;\n min-width: 200px;\n border: 1px solid #ebeff3;\n box-shadow: 0px 2px 5px rgb(18 52 77 / 6%);\n border-radius: 4px;\n white-space: pre-wrap;\n}\n.checkbox-label.disabled {\n opacity: 0.5;\n cursor: 'not-allowed';\n}\n.checkbox {\n transition: background-color ease-in 0.2s;\n min-width: 14px;\n min-height: 14px;\n min-height: 14px;\n max-height: 14px;\n border-radius: 2px;\n position: relative;\n margin-right: 10px;\n background-color: #fff;\n border: 1px solid;\n border-color: var(--default-input-highlight-color)\n ;\n border-color: var(\n --input-highlight-color,\n var(--default-input-highlight-color)\n );\n}\n.checkbox:hover {\n border-color: var(--default-input-highlight-color)\n ;\n border-color: var(\n --input-highlight-color,\n var(--default-input-highlight-color)\n );\n box-shadow: var(--default-background-color) 0px 0px\n 0px 5px;\n box-shadow: var(--background-color, var(--default-background-color)) 0px 0px\n 0px 5px;\n}\ninput[type='checkbox']:checked ~ .checkbox {\n background-color: var(--default-input-highlight-color)\n ;\n background-color: var(\n --input-highlight-color,\n var(--default-input-highlight-color)\n );\n border-color: var(--default-input-highlight-color)\n ;\n border-color: var(\n --input-highlight-color,\n var(--default-input-highlight-color)\n );\n}\ninput[type='checkbox']:checked ~ .checkbox:hover {\n border-color: var(--default-input-highlight-color)\n ;\n border-color: var(\n --input-highlight-color,\n var(--default-input-highlight-color)\n );\n}\ninput[type='checkbox']:disabled ~ .checkbox:hover {\n box-shadow: unset;\n border-color: unset;\n}\n");const h=()=>n.createElement("svg",{id:"tick",className:"tick-icon",xmlns:"http://www.w3.org/2000/svg","aria-labelledby":"title",viewBox:"0 0 10 10"},n.createElement("path",{d:"M3 5.87c-.18666814.00267463-.36667109-.06932655-.5-.2L.21 3.41c-.1786328-.17863279-.24839684-.43899577-.1830127-.6830127.06538414-.24401694.25598306-.43461586.5-.5C.77100423 2.16160316 1.0313672 2.23136721 1.21 2.41L3 4.18 6.8.33c.27679776-.27455556.72320224-.27455556 1 0 .13696438.13025306.21450026.31098915.21450026.5S7.93696438 1.19974694 7.8 1.33L3.45 5.67c-.12082534.11896945-.28072735.19003701-.45.2Z",fill:"#fff",fillRule:"evenodd"})),b=({values:e,options:t,onChangeHandler:r})=>n.createElement("div",{className:"checkbox-group"},t.map(((t,o)=>n.createElement(g,{key:t.id,checked:e?.includes(t.id),name:t.name??t.id,id:t.id,autoFocus:0===o,onChange:(n,o)=>{if(o)r([...e||[],t.id]);else{const n=e.indexOf(t.id);n>-1&&e.splice(n,1),r([...e])}}},t.label)))),g=l(t(((e,t)=>n.createElement("label",{className:`checkbox-label ${e.disabled&&"disabled"}`},n.createElement("input",{ref:t,id:e.id,type:"checkbox",name:e.name,readOnly:e.readOnly,disabled:e.disabled,"aria-disabled":e.disabled,value:e.value,checked:e.checked,autoFocus:e.autoFocus,onChange:e.readOnly?()=>{}:n=>e.onChange(n,n.target.checked)}),n.createElement("div",{className:"checkbox"},e.checked&&n.createElement("div",{className:"icon-container"},n.createElement(h,null)," ")),n.createElement("div",null,e.children)))),{checked:!1});a(".radio-group {\n display: flex;\n grid-gap: 12px;\n gap: 12px;\n white-space: nowrap;\n flex-direction: column;\n}\n\n.radio {\n background-color: #fff;\n border: 1px solid;\n border-color: var(--default-input-border-color);\n border-color: var(--input-border-color, var(--default-input-border-color));\n transition: background-color ease-in 0.2s;\n min-width: 18px;\n max-width: 18px;\n min-height: 18px;\n max-height: 18px;\n border-radius: 50%;\n position: relative;\n margin-right: 12px;\n}\n.radio:before {\n left: 3px;\n top: 3px;\n content: '';\n position: absolute;\n width: 10px;\n height: 10px;\n border-radius: 50%;\n transition: all ease-in 0.2s;\n background-color: #fff;\n}\n.radio-label {\n display: flex;\n align-items: center;\n -webkit-user-select: none;\n -moz-user-select: none;\n -ms-user-select: none;\n user-select: none;\n cursor: pointer;\n font-size: 1rem;\n font-weight: 400;\n padding: 16px 24px;\n min-width: 200px;\n border: 1px solid #ebeff3;\n box-shadow: 0px 2px 5px rgb(18 52 77 / 6%);\n border-radius: 4px;\n white-space: pre-wrap;\n}\ninput[type='radio'] {\n position: absolute;\n clip: rect(0, 0, 0, 0);\n width: 0px;\n height: 0px;\n}\ninput[type='radio']:focus ~ .radio {\n /* box-shadow: ${pseudo.focus} 0px 0px 0px 3px; */\n box-shadow: var(--default-input-highlight-color)\n 0px 0px 0px 3px;\n box-shadow: var(--input-highlight-color, var(--default-input-highlight-color))\n 0px 0px 0px 3px;\n border-color: transparent;\n}\n\ninput[type='radio']:checked ~ .radio:before {\n background-color: var(--default-input-highlight-color)\n ;\n background-color: var(\n --input-highlight-color,\n var(--default-input-highlight-color)\n );\n}\n.radio-container:hover .radio {\n border-color: var(--default-input-highlight-color)\n ;\n border-color: var(\n --input-highlight-color,\n var(--default-input-highlight-color)\n );\n box-shadow: var(--default-background-color) 0px 0px\n 0px 5px;\n box-shadow: var(--background-color, var(--default-background-color)) 0px 0px\n 0px 5px;\n}\n");const x=({name:e,options:t,value:r,onChangeHandler:o})=>n.createElement("div",{className:"radio-group"},t.map(((t,a)=>n.createElement(m,{key:t.id,value:t.id,name:e,onChange:n=>{o(n.currentTarget.value)},autoFocus:0===a,checked:r===t.id},t.label)))),m=l(t(((e,t)=>n.createElement("label",{className:"radio-label"},n.createElement("input",{ref:t,type:"radio",name:e.name,value:e.value,checked:e.checked,onChange:e.onChange,autoFocus:e.autoFocus}),n.createElement("div",{className:"radio"}),n.createElement("div",null,e.children)))),{checked:!1,autoFocus:!1});a(".progressbar-container {\n width: 100%;\n height: 6px;\n position: fixed;\n top: 0;\n left: 0;\n z-index: 1;\n}\n.progressbar {\n transition: transform 0.25s linear;\n transform-origin: left;\n height: 100%;\n background-color: var(--default-brand-color);\n background-color: var(--brand-color, var(--default-brand-color));\n}\n");const f=e=>{const{totalSteps:t,completedSteps:r}=e;return n.createElement("div",{className:"progressbar-container"},n.createElement("div",{className:"progressbar",style:{width:(r>0?100/t:0)+"%",transform:`scaleX(${r})`}}))};a(".action-button {\n width: auto;\n display: block;\n margin: 0;\n padding: 8px 16px;\n cursor: pointer;\n line-height: 1.5;\n text-align: center;\n font-weight: 500;\n letter-spacing: 0.3px;\n border-radius: 4px;\n white-space: nowrap;\n -webkit-user-select: none;\n -moz-user-select: none;\n -ms-user-select: none;\n user-select: none;\n color: #fff;\n background: var(--default-primary-button-color);\n background: var(--primary-button-color, var(--default-primary-button-color));\n border: 1px solid var(--default-primary-button-color);\n border: 1px solid var(--primary-button-color, var(--default-primary-button-color));\n border-radius: 4px;\n min-width: 200px;\n}\n\n@media (max-width: 550px) {\n .action-button {\n min-width: 120px;\n }\n}\n.action-button:not([disabled]):hover {\n background: var(--default-primary-button-color);\n background: var(--primary-button-hover-color, var(--default-primary-button-color));\n}\n\n.action-button[disabled] {\n cursor: not-allowed;\n}\n\nbutton:focus:not(:active) {\n border: 1px solid transparent;\n /* box-shadow: 0 0 0 2px ${pseudo.focus}; */\n}");const v=()=>n.createElement(n.Fragment,null,"..."),y={LARGE:"large",MINI:"mini",NORMAL:"normal"},k=e=>{const{inline:t=!1,children:r,disabled:o,className:a="",htmlType:i,type:l="primary",onClick:c,size:d,overrideStyleClassName:s="",loading:p=!1,...u}=e;return n.createElement("button",Object.assign({style:t?{display:"inline-block"}:{},disabled:o,className:`action-button ${a} ${s}`,type:i,onClick:c},u),p?n.createElement(v,null):r)},w=({question:e,formValues:t,onChangeHandler:r})=>{switch(e.type_info.question_type){case"RANGE":return n.createElement(i,{type_info:e.type_info,onChangeHandler:r,npsValue:t[e.name]});case"CHECKBOX":case"DROPDOWN":return n.createElement(b,{values:t[e.name],options:e.type_info.choices,onChangeHandler:r});case"RADIO":case"MULTICHOICE":return n.createElement(x,{name:e.name,onChangeHandler:r,options:e.type_info.choices,value:t[e.name]});case"INPUT":return n.createElement("div",{className:"responsive-text-field"},n.createElement(p,{autoFocus:!0,label:"",maxLength:300,showCount:!0,isRequired:e.is_required,value:t[e.name]||"",onChange:n=>r(n.target.value)}),n.createElement(u,{autoFocus:!0,label:"",maxLength:300,showCount:!0,isRequired:e.is_required,value:t[e.name]||"",onChange:n=>r(n.target.value)}));case"PARAGRAPH":return n.createElement(u,{autoFocus:!0,label:"",isRequired:e.is_required,value:t[e.name]||"",onChange:n=>r(n.target.value)});case"MESSAGE":return n.createElement("div",{className:"message-container"},e.type_info?.meta?.value);default:return console.error(`Question type ${e.type_info.question_type} not found`),null}};a(":root {\n --default-primary-button-color: rgb(0, 0, 0, 1);\n --default-primary-button-hover-color: #f1171b;\n --default-brand-color: #264966;\n --default-input-highlight-color: #2c5cc5;\n --default-input-border-color: #92a2b1;\n --default-input-hover-border-color: #264966;\n --default-input-placeholder-color: #92a2b1;\n --default-border-radius: 4px;\n --default-background-color: #ebeff3;\n --default-error-highlight-color: #d72d30;\n}\n\n.question-container {\n display: flex;\n flex-direction: column;\n text-align: center;\n max-width: 700px;\n margin: 0 auto;\n align-items: center;\n background: #ffffff;\n border-radius: 4px;\n transition: transform 400ms ease 0ms, opacity 200ms ease 0ms;\n box-shadow: 0px 2px 16px rgba(18, 52, 77, 0.1);\n margin-bottom: 52px;\n padding: 28px;\n grid-gap: 36px;\n gap: 36px;\n}\n\n.question-text {\n font-size: 1rem;\n line-height: 1.5;\n}\n\n.action-buttons {\n display: flex;\n justify-content: space-between;\n width: 100%;\n align-items: center;\n}\n\n.skip-button {\n cursor: pointer;\n background: transparent;\n border: none;\n min-width: 40px;\n padding: 4px 12px;\n border-radius: 4px;\n}\n\n.next-button {\n margin: 0 auto;\n}\n\n.submit {\n padding-bottom: 40px;\n display: flex;\n justify-content: center;\n}\n\n.responsive-text-field {\n width: 100%;\n}\n\n.responsive-text-field .textarea-container {\n display: none;\n}\n\n@media (max-width: 550px) {\n .responsive-text-field .input-container {\n display: none;\n }\n\n .responsive-text-field .textarea-container {\n display: flex;\n }\n}");const E=["RANGE","NPS","RADIO"],N=()=>n.createElement("div",{className:"question-container",style:{gap:"16px"}},n.createElement("h4",null,"Thank you for taking our survey!."),n.createElement("p",null," Your response is very important to us.")),q=({survey:t,onSubmit:a})=>{const{meta:{blocks:i},question_details:{questions:l}}=t,[c,d]=r({}),[s,p]=r(!1),[u,h]=r([]),b=e(null),g=e(null),x=e(null),m=e(0),v=e(!1),y=e([]);o((()=>{i&&!b.current&&i.length>0&&C(i[0])}),[i]),o((()=>{x.current?.scrollIntoView({block:"center",behavior:"smooth"}),y.current=u}),[u]),o((()=>{Object.keys(c).length>0&&g.current&&(E.includes(g.current.type_info.question_type)||v.current)&&!q()&&z()}),[c]);const q=()=>m.current===i.length-1||"end"===b.current.branchOption,C=n=>{let e={};if(n.is_based_on_score){const t=l[0].type_info.choices[c?.[l[0].name]]?.dependent_question_names,r=n.question_names.find((n=>t?.includes(n)));e=l.find((n=>n.name===r))}else e=l.find((e=>e.name===n.question_names[0]));b.current=n,g.current=e;y.current.find((n=>n.question.name===e.name))||h([...y.current,{...n,question:e}])},_=(n,e,t)=>{if(t)if(null!=c[n.question.name]&&n.name!==u[u.length-1].name){const[t,r]=(n=>{const e=u.findIndex((e=>e.name===n.name)),t=u.slice(0,e+1),r=t.reduce(((n,e)=>(n[e.question.name]=c[e.question.name],n)),{});return m.current=i.findIndex((e=>e.name===n.name)),[t,r]})(n);d({...r,...null!=e&&{[n.question.name]:e}}),y.current=t}else d({...c,...null!=e&&{[n.question.name]:e}});else d({...c,...null!=e&&{[n.question.name]:e}})},z=()=>{q()?p(!0):(b.current.nextBlock?m.current=i.findIndex((n=>n.name===b.current.nextBlock)):m.current+=1,C(i[m.current]))},$=n=>{const e=u.findIndex((e=>e.name===n.name)),t=[...u];t.splice(e,1),y.current=t,z()},L=(n,e)=>e.name===g.current.name&&!E.includes(e.type_info.question_type)&&!q(),S=(n,e)=>!n.required&&e.name===g.current.name;return b.current&&g.current?s?n.createElement(N,null):n.createElement(n.Fragment,null,n.createElement(f,{totalSteps:i.length,completedSteps:m.current}),u.map(((e,t)=>n.createElement("div",{className:"question-container",ref:x,id:e.title,key:e.title},n.createElement("div",{className:"question-text"},e.question.text),n.createElement(w,{question:e.question,formValues:c,onChangeHandler:n=>{v.current=!1,m.current=i.findIndex((n=>n.name===e.name)),b.current=e,g.current=e.question,_(e,n,E.includes(e.question.type_info.question_type)&&!q())}}),L(0,e.question)||S(e,e.question)?n.createElement("div",{className:"action-buttons"},L(0,e.question)&&n.createElement(k,{onClick:()=>{v.current=!0,_(e,null,!0)},className:"next-button"},"Next"),S(e,e.question)&&n.createElement("button",{className:"skip-button",onClick:$},"Skip")):null))),q()&&n.createElement("div",{className:"submit"},n.createElement(k,{onClick:()=>{p(!0),a(c)}},"Submit Survey"))):null};export{y as BUTTON_SIZE_VARIANTS,k as Button,b as CheckboxGroup,p as Input,i as NPS,f as ProgressBar,m as Radio,x as RadioGroup,q as Survey,u as TextArea};
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import './style.css';
2
+ import './style.scss';
3
3
  export declare const BUTTON_SIZE_VARIANTS: {
4
4
  LARGE: string;
5
5
  MINI: string;
@@ -24,7 +24,6 @@ export declare type ButtonProps = {
24
24
  };
25
25
  export declare const Button: {
26
26
  (props: ButtonProps & React.HTMLAttributes<HTMLButtonElement>): JSX.Element;
27
- parameters: any;
28
27
  displayName: string;
29
28
  __docgenInfo: {
30
29
  description: string;
@@ -1,5 +1,5 @@
1
1
  /// <reference types="react" />
2
- import './style.css';
2
+ import './style.scss';
3
3
  export declare type ButtonShapeType = 'rounded' | 'square' | 'curved';
4
4
  declare type NPSProps = {
5
5
  type_info: {
@@ -7,6 +7,7 @@ interface RadioButtonProps {
7
7
  name: string;
8
8
  onChange: (e: any) => void;
9
9
  id?: string;
10
+ autoFocus?: boolean;
10
11
  }
11
12
  interface RadioGroupInterface {
12
13
  options: Array<{
@@ -66,5 +67,6 @@ declare const RadioGroup: {
66
67
  };
67
68
  declare const Radio: React.ComponentType<Partial<{
68
69
  checked: boolean;
70
+ autoFocus: boolean;
69
71
  }> & Pick<RadioButtonProps & React.RefAttributes<HTMLInputElement>, "value" | "name" | "ref" | "id" | "onChange" | "children" | "key">>;
70
72
  export { Radio, RadioGroup };
@@ -1,215 +1,2 @@
1
- declare const _default: {
2
- name: string;
3
- desc: string;
4
- type: string;
5
- header_message: string;
6
- gratitude_message: string;
7
- ui_branding: {
8
- logo_url: string;
9
- footer_html: string;
10
- };
11
- meta: {
12
- blocks: ({
13
- name: string;
14
- title: string;
15
- order: number;
16
- question_names: string[];
17
- type: string;
18
- required: boolean;
19
- is_based_on_score: boolean;
20
- is_same_for_all: boolean;
21
- jump_logic: null;
22
- branchOption?: undefined;
23
- nextBlock?: undefined;
24
- position?: undefined;
25
- } | {
26
- name: string;
27
- order: number;
28
- type: string;
29
- title: string;
30
- question_names: string[];
31
- required: boolean;
32
- is_based_on_score: boolean;
33
- is_same_for_all: boolean;
34
- jump_logic: null;
35
- branchOption: string;
36
- nextBlock: string;
37
- position?: undefined;
38
- } | {
39
- name: string;
40
- order: number;
41
- type: string;
42
- title: string;
43
- question_names: string[];
44
- position: number;
45
- required: boolean;
46
- is_based_on_score: boolean;
47
- is_same_for_all: boolean;
48
- jump_logic: null;
49
- branchOption?: undefined;
50
- nextBlock?: undefined;
51
- })[];
52
- };
53
- question_details: {
54
- questions: ({
55
- text: string;
56
- name: string;
57
- position: number;
58
- type_info: {
59
- question_type: string;
60
- validation: {
61
- min: number;
62
- max: number;
63
- };
64
- choices: {
65
- value: number;
66
- position: number;
67
- dependent_question_names: string[];
68
- }[];
69
- linear_scale: {
70
- button_style: string;
71
- button_shape: string;
72
- };
73
- score_presets: {
74
- start: string;
75
- end: string;
76
- };
77
- footer_text: string;
78
- meta?: undefined;
79
- };
80
- question_type?: undefined;
81
- choices?: undefined;
82
- } | {
83
- text: string;
84
- name: string;
85
- position: number;
86
- type_info: {
87
- question_type: string;
88
- choices: {
89
- id: string;
90
- label: string;
91
- }[];
92
- meta: {
93
- value: string;
94
- };
95
- validation?: undefined;
96
- linear_scale?: undefined;
97
- score_presets?: undefined;
98
- footer_text?: undefined;
99
- };
100
- question_type: string;
101
- choices?: undefined;
102
- } | {
103
- text: string;
104
- name: string;
105
- position: number;
106
- type_info: {
107
- question_type: string;
108
- choices: {
109
- id: string;
110
- label: string;
111
- }[];
112
- meta: {
113
- value: string;
114
- };
115
- validation?: undefined;
116
- linear_scale?: undefined;
117
- score_presets?: undefined;
118
- footer_text?: undefined;
119
- };
120
- question_type: string;
121
- choices: {
122
- id: string;
123
- label: string;
124
- }[];
125
- } | {
126
- name: string;
127
- position: number;
128
- text: string;
129
- type_info: {
130
- question_type: string;
131
- choices: {
132
- id: string;
133
- label: string;
134
- }[];
135
- meta: {
136
- value?: undefined;
137
- };
138
- validation?: undefined;
139
- linear_scale?: undefined;
140
- score_presets?: undefined;
141
- footer_text?: undefined;
142
- };
143
- question_type: string;
144
- choices?: undefined;
145
- } | {
146
- name: string;
147
- position: number;
148
- text: string;
149
- type_info: {
150
- question_type: string;
151
- choices: {
152
- id: string;
153
- label: string;
154
- }[];
155
- meta: {
156
- value?: undefined;
157
- };
158
- validation?: undefined;
159
- linear_scale?: undefined;
160
- score_presets?: undefined;
161
- footer_text?: undefined;
162
- };
163
- question_type: string;
164
- choices: {
165
- id: string;
166
- label: string;
167
- }[];
168
- } | {
169
- name: string;
170
- position: number;
171
- text: string;
172
- type_info: {
173
- question_type: string;
174
- choices: {
175
- id: string;
176
- label: string;
177
- }[];
178
- meta: {
179
- value?: undefined;
180
- };
181
- validation?: undefined;
182
- linear_scale?: undefined;
183
- score_presets?: undefined;
184
- footer_text?: undefined;
185
- };
186
- question_type?: undefined;
187
- choices?: undefined;
188
- })[];
189
- };
190
- state: string;
191
- created_on: string;
192
- updated_on: string;
193
- schedule_info: {
194
- start_date: string;
195
- end_date: string;
196
- preferred_time: {
197
- hour: number;
198
- minute: number;
199
- };
200
- remind_in: number[];
201
- next_survey_when_responded: number;
202
- next_survey_when_not_responded: number;
203
- };
204
- throttle_info: {
205
- limit_per_day: number;
206
- };
207
- ui_theme: {
208
- body_background_color: string;
209
- primary_font: string;
210
- secondary_font: string;
211
- primary_button_color: string;
212
- secondary_button_color: string;
213
- };
214
- };
215
- export default _default;
1
+ declare const survey: any;
2
+ export default survey;
@@ -1,5 +1,5 @@
1
1
  /// <reference types="react" />
2
- import './style.css';
2
+ import './style.scss';
3
3
  declare const Survey: {
4
4
  ({ survey, onSubmit }: any): JSX.Element | null;
5
5
  displayName: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "freemium-survey-components",
3
- "version": "0.2.0",
3
+ "version": "0.5.1",
4
4
  "description": "React Survey Ui Components",
5
5
  "main": "lib/index.cjs.js",
6
6
  "module": "lib/index.esm.js",
@@ -50,6 +50,7 @@
50
50
  "@storybook/addon-links": "~6.3.0",
51
51
  "@storybook/addon-postcss": "^2.0.0",
52
52
  "@storybook/addons": "~6.3.12",
53
+ "@storybook/preset-scss": "^1.0.3",
53
54
  "@storybook/react": "~6.3.12",
54
55
  "@storybook/theming": "~6.3.12",
55
56
  "@types/jest": "25.1.4",
@@ -65,7 +66,7 @@
65
66
  "babel-loader": "8.1.0",
66
67
  "clean-webpack-plugin": "^3.0.0",
67
68
  "copy-webpack-plugin": "^6.0.1",
68
- "css-loader": "^3.5.3",
69
+ "css-loader": "<6.0.0",
69
70
  "eslint": "^7.1.0",
70
71
  "eslint-config-prettier": "^6.11.0",
71
72
  "eslint-loader": "^4.0.2",
@@ -87,6 +88,8 @@
87
88
  "rollup-plugin-postcss": "^4.0.1",
88
89
  "rollup-plugin-terser": "^7.0.2",
89
90
  "rollup-plugin-typescript2": "0.27.1",
91
+ "sass": "^1.44.0",
92
+ "style-loader": "<3.0.0",
90
93
  "ts-jest": "25.2.1",
91
94
  "ts-loader": "^7.0.5",
92
95
  "typescript": "^3.9.3",