@s_mart/nps 3.0.0

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.
@@ -0,0 +1,53 @@
1
+ import { CSSProperties, FC } from 'react';
2
+ import { z } from 'zod';
3
+
4
+ declare const schema: z.ZodObject<{
5
+ nota: z.ZodNumber;
6
+ feedback: z.ZodOptional<z.ZodString>;
7
+ autorizoPublicacao: z.ZodBoolean;
8
+ }, "strip", z.ZodTypeAny, {
9
+ nota: number;
10
+ autorizoPublicacao: boolean;
11
+ feedback?: string | undefined;
12
+ }, {
13
+ nota: number;
14
+ autorizoPublicacao: boolean;
15
+ feedback?: string | undefined;
16
+ }>;
17
+ type FormValues = z.infer<typeof schema>;
18
+
19
+ interface NPSProps {
20
+ sistemaNome: string;
21
+ /**
22
+ * Determina se o backdrop aparecerá no fundo
23
+ */
24
+ mostrarBackdrop?: boolean;
25
+ /**
26
+ * Determina se o componente irá fechar quando o usuário clicar fora do paper
27
+ *
28
+ * Funciona apenas se `mostrarBackdrop` for true
29
+ */
30
+ shouldCloseOnBackdropClick?: boolean;
31
+ /**
32
+ * Style aplicado no paper do componente. Pode ser usado para alterar a posição do componente
33
+ */
34
+ paperStyle?: CSSProperties;
35
+ onClose: () => void;
36
+ /**
37
+ * Callback chamada quando o usuário clica no botão de uma nota.
38
+ */
39
+ onSelecionarNota?: (nota?: number) => void;
40
+ /**
41
+ * Callback chamada quando o usuário clica no botão
42
+ * "Enviar" após selecionar uma nota.
43
+ */
44
+ onEnviarNota?: (nota?: number) => void;
45
+ /**
46
+ * Callback chamada quando todo o formulário é finalizado.
47
+ */
48
+ onFinalizar: (values: FormValues) => void;
49
+ }
50
+
51
+ declare const NPS: FC<NPSProps>;
52
+
53
+ export { NPS, NPSProps };
package/dist/index.js ADDED
@@ -0,0 +1,21 @@
1
+ "use strict";var U=Object.create;var y=Object.defineProperty;var E=Object.getOwnPropertyDescriptor;var H=Object.getOwnPropertyNames,h=Object.getOwnPropertySymbols,L=Object.getPrototypeOf,g=Object.prototype.hasOwnProperty,O=Object.prototype.propertyIsEnumerable;var k=(o,e)=>{var t={};for(var r in o)g.call(o,r)&&e.indexOf(r)<0&&(t[r]=o[r]);if(o!=null&&h)for(var r of h(o))e.indexOf(r)<0&&O.call(o,r)&&(t[r]=o[r]);return t};var _=(o,e)=>{for(var t in e)y(o,t,{get:e[t],enumerable:!0})},S=(o,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let p of H(e))!g.call(o,p)&&p!==t&&y(o,p,{get:()=>e[p],enumerable:!(r=E(e,p))||r.enumerable});return o};var G=(o,e,t)=>(t=o!=null?U(L(o)):{},S(e||!o||!o.__esModule?y(t,"default",{value:o,enumerable:!0}):t,o)),J=o=>S(y({},"__esModule",{value:!0}),o);var to={};_(to,{NPS:()=>j});module.exports=J(to);var s=require("@s_mart/core"),b=require("@s_mart/form"),X=require("@s_mart/regular-icons");var c=require("@s_mart/core"),C=require("@s_mart/hooks"),v=require("@s_mart/tokens"),F=require("react-hook-form"),i=require("react/jsx-runtime"),K=({onSelecionarNota:o})=>{let{watch:e,setValue:t}=(0,F.useFormContext)(),r=(0,C.useMediaQuery)("(max-width: 500px)"),p=e("nota"),n=d=>{p!==d&&(t("nota",d),o==null||o(d))},m=(0,i.jsx)(c.Typography,{variant:"bodyXS",color:v.colorPalette.neutral[100],children:"Pouco prov\xE1vel"});return(0,i.jsxs)(i.Fragment,{children:[r&&(0,i.jsx)("div",{style:{marginBottom:"0.5rem"},children:m}),(0,i.jsx)("div",{style:{display:"flex",gap:"0.3rem",flexWrap:"wrap",justifyContent:"center"},children:Array(11).fill(void 0).map((d,l)=>(0,i.jsx)(c.Button,{variant:p===l?"contained":"outlined",style:{minWidth:"3rem"},onClick:()=>n(l),children:l},l))}),(0,i.jsxs)("div",{style:{display:"flex",justifyContent:"space-between",marginTop:"0.5rem"},children:[(0,i.jsx)("span",{children:!r&&m}),(0,i.jsx)(c.Typography,{variant:"bodyXS",color:v.colorPalette.neutral[100],children:"Muito prov\xE1vel"})]})]})},N=K;var w=require("@s_mart/form"),T=require("react/jsx-runtime"),Y=({tipo:o,sistemaNome:e})=>(0,T.jsx)(w.TextField,{name:"feedback",placeholder:o==="promotor"?`Para mim o ${e} \xE9...`:"Eu acho que...",multiline:!0,size:"large",minRows:2}),z=Y;var B=G(require("@emotion/styled")),$=require("@s_mart/tokens"),A=B.default.div`
2
+ display: flex;
3
+ flex-direction: column;
4
+ gap: 1rem;
5
+
6
+ padding: 1.5rem;
7
+ border-radius: 0.375rem;
8
+ box-shadow: 0px 0px 4px 0px rgba(0, 0, 0, 0.25);
9
+ border: 1px solid ${({theme:o})=>{var e;return(e=o.palette.primary)==null?void 0:e.main}};
10
+ background: ${$.colorPalette.neutral[0]};
11
+
12
+ position: absolute;
13
+ bottom: 1.5rem;
14
+ right: 1.75rem;
15
+ z-index: 1001;
16
+
17
+ @media (max-width: 650px) {
18
+ right: 1.25rem;
19
+ left: 1.25rem;
20
+ }
21
+ `;var V=require("react"),D=require("@s_mart/hooks"),Z=({onEnviarNota:o})=>{let[e,t]=(0,V.useState)("selecionarNota"),r=(0,D.useNotification)();return{step:e,handleEnviar:(n,m)=>{e==="selecionarNota"?(o==null||o(n),n>=9?t("feedbackPromotor"):t("feedbackDetrator")):(m(),r.setNotification({variant:"success",title:"Avalia\xE7\xE3o enviada",message:"Agradecemos muito pela sua avalia\xE7\xE3o.",autoHideDuration:5e3}))}}},M=Z;var f=require("zod"),oo=f.z.object({nota:f.z.number(),feedback:f.z.string().optional(),autorizoPublicacao:f.z.coerce.boolean()}),W=oo;var a=require("react/jsx-runtime"),eo=l=>{var x=l,{onFinalizar:o,mostrarBackdrop:e,sistemaNome:t,onClose:r,shouldCloseOnBackdropClick:p,onSelecionarNota:n,paperStyle:m}=x,d=k(x,["onFinalizar","mostrarBackdrop","sistemaNome","onClose","shouldCloseOnBackdropClick","onSelecionarNota","paperStyle"]);let{step:u,handleEnviar:q}=M(d),I={selecionarNota:`Qual a probabilidade de voc\xEA recomendar o ${t}?`,feedbackDetrator:`Como podemos melhorar a sua experi\xEAncia no ${t}?`,feedbackPromotor:`O que voc\xEA mais gosta no ${t}?`};return(0,a.jsx)(b.Form,{onSubmit:o,schema:W,children:({watch:Q,onSubmit:R})=>{let P=Q("nota");return(0,a.jsxs)(a.Fragment,{children:[!!e&&(0,a.jsx)(s.Backdrop,{open:!0,onClick:p?r:void 0,style:{zIndex:1e3}}),(0,a.jsxs)(A,{style:m,children:[(0,a.jsxs)("div",{style:{display:"flex",justifyContent:"space-between"},children:[(0,a.jsx)(s.Typography,{variant:"titleSM",children:I[u]}),(0,a.jsx)(s.LIcon,{icon:X.lineTimes,size:"25px",onClick:r,style:{cursor:"pointer"}})]}),(0,a.jsx)("div",{children:u==="selecionarNota"?(0,a.jsx)(N,{onSelecionarNota:n}):(0,a.jsx)(z,{tipo:u==="feedbackPromotor"?"promotor":"detrator",sistemaNome:t})}),(0,a.jsxs)("div",{style:{display:"flex",justifyContent:"space-between"},children:[(0,a.jsx)("div",{children:u==="feedbackPromotor"&&(0,a.jsx)(b.Checkbox,{name:"autorizoPublicacao",label:(0,a.jsxs)(s.Typography,{variant:"bodyXS",children:["Autorizo a publica\xE7\xE3o deste coment\xE1rio no site e em redes sociais do ",t]})})}),(0,a.jsx)(s.Button,{disabled:P===void 0,onClick:()=>q(P,R),children:"Enviar"})]})]})]})}})},j=eo;0&&(module.exports={NPS});
package/dist/index.mjs ADDED
@@ -0,0 +1,21 @@
1
+ var b=Object.getOwnPropertySymbols;var $=Object.prototype.hasOwnProperty,A=Object.prototype.propertyIsEnumerable;var v=(o,t)=>{var r={};for(var e in o)$.call(o,e)&&t.indexOf(e)<0&&(r[e]=o[e]);if(o!=null&&b)for(var e of b(o))t.indexOf(e)<0&&A.call(o,e)&&(r[e]=o[e]);return r};import{Backdrop as O,Button as _,LIcon as G,Typography as N}from"@s_mart/core";import{Checkbox as J,Form as K}from"@s_mart/form";import{lineTimes as Y}from"@s_mart/regular-icons";import{Button as V,Typography as x}from"@s_mart/core";import{useMediaQuery as D}from"@s_mart/hooks";import{colorPalette as P}from"@s_mart/tokens";import{useFormContext as M}from"react-hook-form";import{Fragment as X,jsx as n,jsxs as h}from"react/jsx-runtime";var W=({onSelecionarNota:o})=>{let{watch:t,setValue:r}=M(),e=D("(max-width: 500px)"),m=t("nota"),i=s=>{m!==s&&(r("nota",s),o==null||o(s))},p=n(x,{variant:"bodyXS",color:P.neutral[100],children:"Pouco prov\xE1vel"});return h(X,{children:[e&&n("div",{style:{marginBottom:"0.5rem"},children:p}),n("div",{style:{display:"flex",gap:"0.3rem",flexWrap:"wrap",justifyContent:"center"},children:Array(11).fill(void 0).map((s,d)=>n(V,{variant:m===d?"contained":"outlined",style:{minWidth:"3rem"},onClick:()=>i(d),children:d},d))}),h("div",{style:{display:"flex",justifyContent:"space-between",marginTop:"0.5rem"},children:[n("span",{children:!e&&p}),n(x,{variant:"bodyXS",color:P.neutral[100],children:"Muito prov\xE1vel"})]})]})},g=W;import{TextField as j}from"@s_mart/form";import{jsx as I}from"react/jsx-runtime";var q=({tipo:o,sistemaNome:t})=>I(j,{name:"feedback",placeholder:o==="promotor"?`Para mim o ${t} \xE9...`:"Eu acho que...",multiline:!0,size:"large",minRows:2}),k=q;import Q from"@emotion/styled";import{colorPalette as R}from"@s_mart/tokens";var S=Q.div`
2
+ display: flex;
3
+ flex-direction: column;
4
+ gap: 1rem;
5
+
6
+ padding: 1.5rem;
7
+ border-radius: 0.375rem;
8
+ box-shadow: 0px 0px 4px 0px rgba(0, 0, 0, 0.25);
9
+ border: 1px solid ${({theme:o})=>{var t;return(t=o.palette.primary)==null?void 0:t.main}};
10
+ background: ${R.neutral[0]};
11
+
12
+ position: absolute;
13
+ bottom: 1.5rem;
14
+ right: 1.75rem;
15
+ z-index: 1001;
16
+
17
+ @media (max-width: 650px) {
18
+ right: 1.25rem;
19
+ left: 1.25rem;
20
+ }
21
+ `;import{useState as U}from"react";import{useNotification as E}from"@s_mart/hooks";var H=({onEnviarNota:o})=>{let[t,r]=U("selecionarNota"),e=E();return{step:t,handleEnviar:(i,p)=>{t==="selecionarNota"?(o==null||o(i),i>=9?r("feedbackPromotor"):r("feedbackDetrator")):(p(),e.setNotification({variant:"success",title:"Avalia\xE7\xE3o enviada",message:"Agradecemos muito pela sua avalia\xE7\xE3o.",autoHideDuration:5e3}))}}},C=H;import{z as f}from"zod";var L=f.object({nota:f.number(),feedback:f.string().optional(),autorizoPublicacao:f.coerce.boolean()}),F=L;import{Fragment as eo,jsx as a,jsxs as l}from"react/jsx-runtime";var Z=d=>{var u=d,{onFinalizar:o,mostrarBackdrop:t,sistemaNome:r,onClose:e,shouldCloseOnBackdropClick:m,onSelecionarNota:i,paperStyle:p}=u,s=v(u,["onFinalizar","mostrarBackdrop","sistemaNome","onClose","shouldCloseOnBackdropClick","onSelecionarNota","paperStyle"]);let{step:c,handleEnviar:w}=C(s),z={selecionarNota:`Qual a probabilidade de voc\xEA recomendar o ${r}?`,feedbackDetrator:`Como podemos melhorar a sua experi\xEAncia no ${r}?`,feedbackPromotor:`O que voc\xEA mais gosta no ${r}?`};return a(K,{onSubmit:o,schema:F,children:({watch:T,onSubmit:B})=>{let y=T("nota");return l(eo,{children:[!!t&&a(O,{open:!0,onClick:m?e:void 0,style:{zIndex:1e3}}),l(S,{style:p,children:[l("div",{style:{display:"flex",justifyContent:"space-between"},children:[a(N,{variant:"titleSM",children:z[c]}),a(G,{icon:Y,size:"25px",onClick:e,style:{cursor:"pointer"}})]}),a("div",{children:c==="selecionarNota"?a(g,{onSelecionarNota:i}):a(k,{tipo:c==="feedbackPromotor"?"promotor":"detrator",sistemaNome:r})}),l("div",{style:{display:"flex",justifyContent:"space-between"},children:[a("div",{children:c==="feedbackPromotor"&&a(J,{name:"autorizoPublicacao",label:l(N,{variant:"bodyXS",children:["Autorizo a publica\xE7\xE3o deste coment\xE1rio no site e em redes sociais do ",r]})})}),a(_,{disabled:y===void 0,onClick:()=>w(y,B),children:"Enviar"})]})]})]})}})},oo=Z;export{oo as NPS};
package/package.json ADDED
@@ -0,0 +1,53 @@
1
+ {
2
+ "name": "@s_mart/nps",
3
+ "version": "3.0.0",
4
+ "main": "./dist/index.js",
5
+ "module": "./dist/index.mjs",
6
+ "types": "./dist/index.d.ts",
7
+ "sideEffects": false,
8
+ "license": "MIT",
9
+ "files": [
10
+ "dist/**"
11
+ ],
12
+ "scripts": {
13
+ "build": "tsup src/index.tsx --minify --format esm,cjs --dts --external react",
14
+ "dev": "tsup src/index.tsx --format esm,cjs --watch --dts --external react",
15
+ "lint": "eslint src/**/*.ts* --fix"
16
+ },
17
+ "dependencies": {
18
+ "tsup": "^6.7.0",
19
+ "typescript": "^5.0.4",
20
+ "@types/react": "18.2.5",
21
+ "@types/react-dom": "18.2.4",
22
+ "@s_mart/core": "*",
23
+ "@s_mart/form": "*",
24
+ "@s_mart/hooks": "*",
25
+ "@s_mart/tokens": "*",
26
+ "@s_mart/regular-icons": "*"
27
+ },
28
+ "peerDependencies": {
29
+ "react": ">=18.2.0",
30
+ "react-dom": ">=18.2.0",
31
+ "react-hook-form": ">=7.36.1",
32
+ "@types/react": ">=18.2.5",
33
+ "@types/react-dom": ">=18.2.4",
34
+ "@emotion/react": ">=11.10.8",
35
+ "@emotion/styled": ">=11.10.8",
36
+ "@s_mart/core": "*",
37
+ "@s_mart/form": "*",
38
+ "@s_mart/hooks": "*",
39
+ "@s_mart/regular-icons": "*",
40
+ "@s_mart/tokens": "*",
41
+ "notistack": ">=2.0.0",
42
+ "zod": ">=3.21.4"
43
+ },
44
+ "devDependencies": {
45
+ "@s_mart/eslint": "*",
46
+ "@s_mart/tsconfig": "*",
47
+ "@s_mart/typed": "*",
48
+ "eslint": "^8.32.0"
49
+ },
50
+ "publishConfig": {
51
+ "access": "public"
52
+ }
53
+ }