gotcha-feedback 1.0.12 → 1.0.14
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 +40 -2
- package/dist/index.d.mts +6 -1
- package/dist/index.d.ts +6 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -39,7 +39,8 @@ function FeatureCard() {
|
|
|
39
39
|
## Features
|
|
40
40
|
|
|
41
41
|
- **Feedback Mode** - Star rating + text input
|
|
42
|
-
- **Vote Mode** - Thumbs up/down
|
|
42
|
+
- **Vote Mode** - Thumbs up/down with customizable labels
|
|
43
|
+
- **Poll Mode** - Custom options (single or multi-select)
|
|
43
44
|
- **User Segmentation** - Analyze feedback by custom user attributes
|
|
44
45
|
- **Edit Support** - Users can update their previous submissions
|
|
45
46
|
- **Customizable** - Themes, sizes, positions
|
|
@@ -64,12 +65,15 @@ function FeatureCard() {
|
|
|
64
65
|
| Prop | Type | Default | Description |
|
|
65
66
|
|------|------|---------|-------------|
|
|
66
67
|
| `elementId` | `string` | Required | Unique identifier for this element |
|
|
67
|
-
| `mode` | `'feedback' \| 'vote'` | `'feedback'` | Feedback mode |
|
|
68
|
+
| `mode` | `'feedback' \| 'vote' \| 'poll'` | `'feedback'` | Feedback mode |
|
|
68
69
|
| `position` | `'top-right' \| 'top-left' \| 'bottom-right' \| 'bottom-left' \| 'inline'` | `'top-right'` | Button position |
|
|
69
70
|
| `size` | `'sm' \| 'md' \| 'lg'` | `'md'` | Button size |
|
|
70
71
|
| `theme` | `'light' \| 'dark' \| 'auto'` | `'light'` | Color theme |
|
|
71
72
|
| `showOnHover` | `boolean` | `true` | Only show on hover |
|
|
72
73
|
| `promptText` | `string` | Mode-specific | Custom prompt text |
|
|
74
|
+
| `voteLabels` | `{ up: string, down: string }` | `{ up: 'Like', down: 'Dislike' }` | Custom vote button labels |
|
|
75
|
+
| `options` | `string[]` | - | Poll options (2-6 items, required for poll mode) |
|
|
76
|
+
| `allowMultiple` | `boolean` | `false` | Allow selecting multiple poll options |
|
|
73
77
|
| `user` | `object` | - | User metadata for segmentation |
|
|
74
78
|
| `onSubmit` | `function` | - | Callback after submission |
|
|
75
79
|
| `onOpen` | `function` | - | Callback when modal opens |
|
|
@@ -96,6 +100,40 @@ function FeatureCard() {
|
|
|
96
100
|
/>
|
|
97
101
|
```
|
|
98
102
|
|
|
103
|
+
### Vote Mode with Custom Labels
|
|
104
|
+
|
|
105
|
+
```tsx
|
|
106
|
+
<Gotcha
|
|
107
|
+
elementId="ship-feature"
|
|
108
|
+
mode="vote"
|
|
109
|
+
voteLabels={{ up: "Yes", down: "No" }}
|
|
110
|
+
promptText="Should we ship this feature?"
|
|
111
|
+
/>
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
### Poll Mode
|
|
115
|
+
|
|
116
|
+
```tsx
|
|
117
|
+
<Gotcha
|
|
118
|
+
elementId="priority-poll"
|
|
119
|
+
mode="poll"
|
|
120
|
+
options={["Yes", "No", "Maybe"]}
|
|
121
|
+
promptText="Should we ship this feature?"
|
|
122
|
+
/>
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
### Poll Mode (Multi-Select)
|
|
126
|
+
|
|
127
|
+
```tsx
|
|
128
|
+
<Gotcha
|
|
129
|
+
elementId="feature-priority"
|
|
130
|
+
mode="poll"
|
|
131
|
+
options={["Analytics", "Segments", "Exports", "API"]}
|
|
132
|
+
allowMultiple
|
|
133
|
+
promptText="Which features matter most?"
|
|
134
|
+
/>
|
|
135
|
+
```
|
|
136
|
+
|
|
99
137
|
### Dark Theme
|
|
100
138
|
|
|
101
139
|
```tsx
|
package/dist/index.d.mts
CHANGED
|
@@ -88,6 +88,11 @@ interface GotchaProps {
|
|
|
88
88
|
experimentId?: string;
|
|
89
89
|
/** Current A/B variant shown to user */
|
|
90
90
|
variant?: string;
|
|
91
|
+
/** Custom labels for vote buttons (default: Like/Dislike) */
|
|
92
|
+
voteLabels?: {
|
|
93
|
+
up: string;
|
|
94
|
+
down: string;
|
|
95
|
+
};
|
|
91
96
|
/** Required if mode is 'poll' (2-6 options) */
|
|
92
97
|
options?: string[];
|
|
93
98
|
/** Allow selecting multiple options */
|
|
@@ -125,7 +130,7 @@ interface GotchaProps {
|
|
|
125
130
|
/** Called on error */
|
|
126
131
|
onError?: (error: GotchaError) => void;
|
|
127
132
|
}
|
|
128
|
-
declare function Gotcha({ elementId, user, mode, experimentId, variant, options, allowMultiple, showResults, position, size, theme, customStyles, visible, showOnHover, touchBehavior, promptText, placeholder, submitText, thankYouMessage, onSubmit, onOpen, onClose, onError, }: GotchaProps): react_jsx_runtime.JSX.Element | null;
|
|
133
|
+
declare function Gotcha({ elementId, user, mode, experimentId, variant, voteLabels, options, allowMultiple, showResults, position, size, theme, customStyles, visible, showOnHover, touchBehavior, promptText, placeholder, submitText, thankYouMessage, onSubmit, onOpen, onClose, onError, }: GotchaProps): react_jsx_runtime.JSX.Element | null;
|
|
129
134
|
|
|
130
135
|
/**
|
|
131
136
|
* Hook to access Gotcha context
|
package/dist/index.d.ts
CHANGED
|
@@ -88,6 +88,11 @@ interface GotchaProps {
|
|
|
88
88
|
experimentId?: string;
|
|
89
89
|
/** Current A/B variant shown to user */
|
|
90
90
|
variant?: string;
|
|
91
|
+
/** Custom labels for vote buttons (default: Like/Dislike) */
|
|
92
|
+
voteLabels?: {
|
|
93
|
+
up: string;
|
|
94
|
+
down: string;
|
|
95
|
+
};
|
|
91
96
|
/** Required if mode is 'poll' (2-6 options) */
|
|
92
97
|
options?: string[];
|
|
93
98
|
/** Allow selecting multiple options */
|
|
@@ -125,7 +130,7 @@ interface GotchaProps {
|
|
|
125
130
|
/** Called on error */
|
|
126
131
|
onError?: (error: GotchaError) => void;
|
|
127
132
|
}
|
|
128
|
-
declare function Gotcha({ elementId, user, mode, experimentId, variant, options, allowMultiple, showResults, position, size, theme, customStyles, visible, showOnHover, touchBehavior, promptText, placeholder, submitText, thankYouMessage, onSubmit, onOpen, onClose, onError, }: GotchaProps): react_jsx_runtime.JSX.Element | null;
|
|
133
|
+
declare function Gotcha({ elementId, user, mode, experimentId, variant, voteLabels, options, allowMultiple, showResults, position, size, theme, customStyles, visible, showOnHover, touchBehavior, promptText, placeholder, submitText, thankYouMessage, onSubmit, onOpen, onClose, onError, }: GotchaProps): react_jsx_runtime.JSX.Element | null;
|
|
129
134
|
|
|
130
135
|
/**
|
|
131
136
|
* Hook to access Gotcha context
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
'use strict';var react=require('react'),jsxRuntime=require('react/jsx-runtime'),reactDom=require('react-dom');var
|
|
1
|
+
'use strict';var react=require('react'),jsxRuntime=require('react/jsx-runtime'),reactDom=require('react-dom');var Te="https://gotcha.cx/api/v1";var ce={ANONYMOUS_ID:"gotcha_anonymous_id"},M={POSITION:"top-right",SIZE:"md",THEME:"light",SHOW_ON_HOVER:true,TOUCH_BEHAVIOR:"always-visible",SUBMIT_TEXT:"Submit",THANK_YOU_MESSAGE:"Thanks for your feedback!"};var q={MAX_RETRIES:2,BASE_DELAY_MS:500,MAX_DELAY_MS:5e3};function we(){if(typeof window>"u")return `anon_${crypto.randomUUID()}`;let e=localStorage.getItem(ce.ANONYMOUS_ID);if(e)return e;let a=`anon_${crypto.randomUUID()}`;return localStorage.setItem(ce.ANONYMOUS_ID,a),a}var Z={maxRetries:q.MAX_RETRIES,baseDelayMs:q.BASE_DELAY_MS,maxDelayMs:q.MAX_DELAY_MS};async function de(e,a,l=Z,o=false){let b=null;for(let m=0;m<=l.maxRetries;m++){try{o&&m>0&&console.log(`[Gotcha] Retry attempt ${m}/${l.maxRetries}`);let t=await fetch(e,a);if(t.status>=400&&t.status<500&&t.status!==429||t.ok)return t;b=new Error(`HTTP ${t.status}`);}catch(t){b=t,o&&console.log(`[Gotcha] Network error: ${b.message}`);}if(m<l.maxRetries){let t=Math.min(l.baseDelayMs*Math.pow(2,m),l.maxDelayMs);await new Promise(c=>setTimeout(c,t));}}throw b}function Ce(e){let{apiKey:a,baseUrl:l=Te,debug:o=false}=e,b={"Content-Type":"application/json",Authorization:`Bearer ${a}`};async function m(t,c,r){let u=`${l}${c}`,d=crypto.randomUUID();o&&console.log(`[Gotcha] ${t} ${c}`,r);let s=await de(u,{method:t,headers:{...b,"Idempotency-Key":d},body:r?JSON.stringify(r):void 0},Z,o),i=await s.json();if(!s.ok){let f=i.error;throw o&&console.error(`[Gotcha] Error: ${f.code} - ${f.message}`),f}return o&&console.log("[Gotcha] Response:",i),i}return {async submitResponse(t){let c=t.user||{};c.id||(c.id=we());let r={...t,user:c,context:{url:typeof window<"u"?window.location.href:void 0,userAgent:typeof navigator<"u"?navigator.userAgent:void 0}};return m("POST","/responses",r)},async checkExistingResponse(t,c){let r=`${l}/responses/check?elementId=${encodeURIComponent(t)}&userId=${encodeURIComponent(c)}`;o&&console.log("[Gotcha] GET /responses/check");let u=await de(r,{method:"GET",headers:b},Z,o),d=await u.json();if(!u.ok){let s=d.error;throw o&&console.error(`[Gotcha] Error: ${s.code} - ${s.message}`),s}return d.exists?(o&&console.log("[Gotcha] Found existing response:",d.response),d.response):null},async updateResponse(t,c,r){let u=`${l}/responses/${t}${r?`?userId=${encodeURIComponent(r)}`:""}`;o&&console.log(`[Gotcha] PATCH /responses/${t}`,c);let d=await de(u,{method:"PATCH",headers:b,body:JSON.stringify(c)},Z,o),s=await d.json();if(!d.ok){let i=s.error;throw o&&console.error(`[Gotcha] Error: ${i.code} - ${i.message}`),i}return o&&console.log("[Gotcha] Response updated:",s),s},getBaseUrl(){return l}}}var Ge=react.createContext(null);function je({apiKey:e,children:a,baseUrl:l,debug:o=false,disabled:b=false,defaultUser:m={}}){let[t,c]=react.useState(null),r=react.useMemo(()=>Ce({apiKey:e,baseUrl:l,debug:o}),[e,l,o]),u=react.useCallback(i=>{c(i);},[]),d=react.useCallback(()=>{c(null);},[]),s=react.useMemo(()=>({client:r,disabled:b,defaultUser:m,debug:o,activeModalId:t,openModal:u,closeModal:d}),[r,b,m,o,t,u,d]);return jsxRuntime.jsx(Ge.Provider,{value:s,children:a})}function L(){let e=react.useContext(Ge);if(!e)throw new Error("useGotchaContext must be used within a GotchaProvider");return e}function Pe(e){let{client:a,defaultUser:l}=L(),[o,b]=react.useState(false),[m,t]=react.useState(false),[c,r]=react.useState(null),[u,d]=react.useState(null);return react.useEffect(()=>{let i=e.user?.id||l?.id;if(!i){d(null);return}let f=false;return (async()=>{t(true);try{let g=await a.checkExistingResponse(e.elementId,i);f||d(g);}catch{f||d(null);}finally{f||t(false);}})(),()=>{f=true;}},[a,e.elementId,e.user?.id,l?.id]),{submit:react.useCallback(async i=>{b(true),r(null);try{let f=e.user?.id||l?.id,p;return u&&f?p=await a.updateResponse(u.id,{content:i.content,title:i.title,rating:i.rating,vote:i.vote,pollSelected:i.pollSelected},f):p=await a.submitResponse({elementId:e.elementId,mode:e.mode,content:i.content,title:i.title,rating:i.rating,vote:i.vote,pollOptions:e.pollOptions,pollSelected:i.pollSelected,experimentId:e.experimentId,variant:e.variant,user:{...l,...e.user}}),e.onSuccess?.(p),p}catch(f){let p=f instanceof Error?f.message:"Something went wrong";throw r(p),e.onError?.(f instanceof Error?f:new Error(p)),f}finally{b(false);}},[a,l,e,u]),isLoading:o,isCheckingExisting:m,error:c,existingResponse:u,isEditing:!!u,clearError:()=>r(null)}}function ee(...e){return e.filter(Boolean).join(" ")}var I=()=>typeof window>"u"?false:"ontouchstart"in window||navigator.maxTouchPoints>0,Ae=(e,a)=>{let l={sm:{desktop:24,mobile:32},md:{desktop:32,mobile:36},lg:{desktop:40,mobile:40}};return a?l[e].mobile:l[e].desktop};function Je(){return typeof window>"u"?"light":window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light"}function De({size:e,theme:a,customStyles:l,showOnHover:o,touchBehavior:b,onClick:m,isOpen:t,isParentHovered:c=false}){let[r,u]=react.useState(false),[d,s]=react.useState(false),[i,f]=react.useState(Je);react.useEffect(()=>{u(I());let C=window.matchMedia("(prefers-color-scheme: dark)"),A=S=>f(S.matches?"dark":"light");return C.addEventListener("change",A),()=>C.removeEventListener("change",A)},[]);let p=t?true:!r&&o?c:r&&b==="tap-to-reveal"?d:true,g=()=>{if(r&&b==="tap-to-reveal"&&!d){s(true);return}m();},n=Ae(e,r),h=(a==="auto"?i:a)==="dark",P={width:n,height:n,borderRadius:"50%",border:h?"1px solid rgba(255,255,255,0.15)":"none",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",background:h?"linear-gradient(180deg, rgba(255,255,255,0.16) 0%, rgba(255,255,255,0.04) 60%, rgba(0,0,0,0.05) 100%)":"linear-gradient(160deg, rgba(255,255,255,0.7) 0%, rgba(200,210,230,0.4) 40%, rgba(180,192,220,0.5) 100%)",backdropFilter:"blur(16px) saturate(170%)",WebkitBackdropFilter:"blur(16px) saturate(170%)",color:h?"rgba(255,255,255,0.88)":"rgba(0,0,0,0.75)",boxShadow:h?"0 4px 14px rgba(0,0,0,0.45), 0 1px 3px rgba(0,0,0,0.35)":"0 3px 12px rgba(0,0,0,0.12), 0 0 1px rgba(0,0,0,0.2)",transition:"all 0.2s cubic-bezier(0.4, 0, 0.2, 1)",opacity:p?1:0,transform:p?"scale(1)":"scale(0.6)",pointerEvents:p?"auto":"none",...l?.button};return jsxRuntime.jsx("button",{type:"button",onClick:g,style:P,className:ee("gotcha-button",t&&"gotcha-button--open"),"aria-label":"Give feedback on this feature","aria-expanded":t,"aria-haspopup":"dialog",children:jsxRuntime.jsx(tt,{size:n*.65})})}var Oe="gotcha-carter-one";function et(){react.useEffect(()=>{if(document.getElementById(Oe))return;let e=document.createElement("link");e.id=Oe,e.rel="stylesheet",e.href="https://fonts.googleapis.com/css2?family=Carter+One&display=swap",document.head.appendChild(e);},[]);}function tt({size:e}){return et(),jsxRuntime.jsx("span",{"aria-hidden":"true",style:{fontFamily:"'Carter One', cursive",fontSize:e,lineHeight:1,display:"flex",alignItems:"center",justifyContent:"center",marginTop:e*.05,marginRight:e*.05,userSelect:"none"},children:"G"})}function _({size:e=16,color:a="currentColor"}){return jsxRuntime.jsxs("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",style:{animation:"gotcha-spin 0.8s linear infinite"},children:[jsxRuntime.jsx("style",{children:`
|
|
2
2
|
@keyframes gotcha-spin {
|
|
3
3
|
from { transform: rotate(0deg); }
|
|
4
4
|
to { transform: rotate(360deg); }
|
|
@@ -8,5 +8,5 @@
|
|
|
8
8
|
50% { stroke-dasharray: 40, 62; stroke-dashoffset: -12; }
|
|
9
9
|
100% { stroke-dasharray: 1, 62; stroke-dashoffset: -62; }
|
|
10
10
|
}
|
|
11
|
-
`}),jsxRuntime.jsx("circle",{cx:"12",cy:"12",r:"10",stroke:s,strokeWidth:"2",strokeOpacity:"0.12"}),jsxRuntime.jsx("circle",{cx:"12",cy:"12",r:"10",stroke:s,strokeWidth:"2",strokeLinecap:"round",style:{animation:"gotcha-dash 1.2s ease-in-out infinite"}})]})}function De({theme:e,placeholder:s,submitText:a,isLoading:n,onSubmit:u,customStyles:c,initialValues:t,isEditing:p=false}){let[r,d]=react.useState(t?.content||""),[l,g]=react.useState(t?.rating??null),[o,f]=react.useState(false);react.useEffect(()=>{f(D());},[]),react.useEffect(()=>{t?.content!==void 0&&d(t.content||""),t?.rating!==void 0&&g(t.rating??null);},[t?.content,t?.rating]);let i=e==="dark",m=h=>{h.preventDefault(),!(!r.trim()&&l===null)&&u({content:r.trim()||void 0,rating:l??void 0});},x={width:"100%",padding:o?"12px 14px":"10px 12px",border:`1px solid ${i?"rgba(255,255,255,0.08)":"#e2e8f0"}`,borderRadius:8,backgroundColor:i?"rgba(55,65,81,0.5)":"#fafbfc",color:i?"#f9fafb":"#111827",fontSize:o?16:14,resize:"vertical",minHeight:o?100:80,fontFamily:"inherit",outline:"none",transition:"border-color 0.2s cubic-bezier(0.4, 0, 0.2, 1), box-shadow 0.2s cubic-bezier(0.4, 0, 0.2, 1)",lineHeight:1.5,...c?.input},k={width:"100%",padding:o?"14px 16px":"10px 16px",border:"none",borderRadius:8,backgroundColor:i?"#e2e8f0":"#1e293b",color:i?"#1e293b":"#ffffff",fontSize:o?16:14,fontWeight:500,cursor:n?"not-allowed":"pointer",transition:"all 0.2s cubic-bezier(0.4, 0, 0.2, 1)",letterSpacing:"0.01em",...c?.submitButton};return jsxRuntime.jsxs("form",{onSubmit:m,children:[jsxRuntime.jsx("div",{style:{marginBottom:o?16:12},children:jsxRuntime.jsx(qe,{value:l,onChange:g,isDark:i,isTouch:o})}),jsxRuntime.jsx("textarea",{value:r,onChange:h=>d(h.target.value),placeholder:s||"Share your thoughts...",style:x,disabled:n,"aria-label":"Your feedback",onFocus:h=>{h.currentTarget.style.borderColor="#1e293b",h.currentTarget.style.boxShadow="0 0 0 2px rgba(30,41,59,0.15)",h.currentTarget.style.backgroundColor=i?"rgba(55,65,81,0.7)":"#ffffff";},onBlur:h=>{h.currentTarget.style.borderColor=i?"rgba(255,255,255,0.08)":"#e2e8f0",h.currentTarget.style.boxShadow="none",h.currentTarget.style.backgroundColor=i?"rgba(55,65,81,0.5)":"#fafbfc";}}),jsxRuntime.jsxs("button",{type:"submit",disabled:n||!r.trim()&&l===null,style:{...k,marginTop:12,opacity:n?.8:1,backgroundColor:!r.trim()&&l===null?i?"#374151":"#e2e8f0":i?"#e2e8f0":"#1e293b",color:!r.trim()&&l===null?i?"#6b7280":"#94a3b8":i?"#1e293b":"#ffffff",display:"flex",alignItems:"center",justifyContent:"center",gap:8},onMouseEnter:h=>{h.currentTarget.disabled||(h.currentTarget.style.backgroundColor=i?"#cbd5e1":"#334155");},onMouseLeave:h=>{h.currentTarget.disabled||(h.currentTarget.style.backgroundColor=i?"#e2e8f0":"#1e293b");},children:[n&&jsxRuntime.jsx($,{size:o?18:16,color:i?"#1e293b":"#ffffff"}),n?p?"Updating...":"Submitting...":p?"Update":a]})]})}function qe({value:e,onChange:s,isDark:a,isTouch:n}){let[u,c]=react.useState(null),t=n?28:18,p=n?6:3;return jsxRuntime.jsx("div",{style:{display:"flex",gap:n?6:2},role:"group","aria-label":"Rating",children:[1,2,3,4,5].map(r=>{let d=(u??e??0)>=r;return jsxRuntime.jsx("button",{type:"button",onClick:()=>s(r),onMouseEnter:()=>c(r),onMouseLeave:()=>c(null),"aria-label":`Rate ${r} out of 5`,"aria-pressed":e===r,style:{background:"none",border:"none",cursor:"pointer",padding:p,color:d?"#f59e0b":a?"rgba(255,255,255,0.12)":"#e2e8f0",transition:"color 0.15s cubic-bezier(0.4, 0, 0.2, 1), transform 0.15s cubic-bezier(0.4, 0, 0.2, 1)",transform:u!==null&&u>=r?"scale(1.1)":"scale(1)"},children:jsxRuntime.jsx("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"currentColor",children:jsxRuntime.jsx("path",{d:"M12 2l3.09 6.26L22 9.27l-5 4.87 1.18 6.88L12 17.77l-6.18 3.25L7 14.14 2 9.27l6.91-1.01L12 2z"})})},r)})})}function Le({theme:e,isLoading:s,onSubmit:a,initialVote:n,isEditing:u=false}){let[c,t]=react.useState(false),[p,r]=react.useState(n||null),[d,l]=react.useState(n||null);react.useEffect(()=>{t(D());},[]),react.useEffect(()=>{n!==void 0&&(l(n),r(n));},[n]),react.useEffect(()=>{!s&&!u&&r(null);},[s,u]);let g=m=>{r(m),a({vote:m});},o=e==="dark",f=m=>{let x=d===m;return {flex:1,minWidth:0,overflow:"hidden",padding:c?"14px 18px":"10px 14px",border:`1px solid ${x?m==="up"?o?"rgba(16,185,129,0.3)":"rgba(16,185,129,0.25)":o?"rgba(239,68,68,0.3)":"rgba(239,68,68,0.25)":o?"rgba(255,255,255,0.08)":"#e2e8f0"}`,borderRadius:c?10:8,backgroundColor:x?m==="up"?o?"rgba(16,185,129,0.08)":"rgba(16,185,129,0.06)":o?"rgba(239,68,68,0.08)":"rgba(239,68,68,0.06)":o?"rgba(55,65,81,0.5)":"#fafbfc",color:x?m==="up"?"#10b981":"#ef4444":o?"#d1d5db":"#64748b",fontSize:c?28:24,cursor:s?"not-allowed":"pointer",transition:"background-color 0.2s, border-color 0.2s, color 0.2s, transform 0.2s, box-shadow 0.2s",display:"flex",alignItems:"center",justifyContent:"center",gap:c?10:8}},i=c?24:20;return jsxRuntime.jsxs("div",{style:{display:"flex",gap:c?12:10},role:"group","aria-label":"Vote",children:[jsxRuntime.jsx("button",{type:"button",onClick:()=>g("up"),disabled:s,style:f("up"),"aria-label":"Vote up - I like this","aria-pressed":d==="up",onMouseEnter:m=>{s||(m.currentTarget.style.transform="translateY(-1px)",m.currentTarget.style.boxShadow="0 2px 8px rgba(0,0,0,0.06)");},onMouseLeave:m=>{m.currentTarget.style.transform="translateY(0)",m.currentTarget.style.boxShadow="none";},children:s&&p==="up"?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx($,{size:i,color:o?"#f9fafb":"#111827"}),jsxRuntime.jsx("span",{style:{fontSize:c?15:13,fontWeight:500,letterSpacing:"0.01em"},children:u?"Updating...":"Sending..."})]}):jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(Ze,{size:i}),jsxRuntime.jsx("span",{style:{fontSize:c?15:13,fontWeight:500,letterSpacing:"0.01em"},children:d==="up"?"Liked":"Like"})]})}),jsxRuntime.jsx("button",{type:"button",onClick:()=>g("down"),disabled:s,style:f("down"),"aria-label":"Vote down - I don't like this","aria-pressed":d==="down",onMouseEnter:m=>{s||(m.currentTarget.style.transform="translateY(-1px)",m.currentTarget.style.boxShadow="0 2px 8px rgba(0,0,0,0.06)");},onMouseLeave:m=>{m.currentTarget.style.transform="translateY(0)",m.currentTarget.style.boxShadow="none";},children:s&&p==="down"?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx($,{size:i,color:o?"#f9fafb":"#111827"}),jsxRuntime.jsx("span",{style:{fontSize:c?15:13,fontWeight:500,letterSpacing:"0.01em"},children:u?"Updating...":"Sending..."})]}):jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(Je,{size:i}),jsxRuntime.jsx("span",{style:{fontSize:c?15:13,fontWeight:500,letterSpacing:"0.01em"},children:d==="down"?"Disliked":"Dislike"})]})})]})}function Ze({size:e=24}){return jsxRuntime.jsx("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",children:jsxRuntime.jsx("path",{d:"M14 9V5a3 3 0 0 0-3-3l-4 9v11h11.28a2 2 0 0 0 2-1.7l1.38-9a2 2 0 0 0-2-2.3zM7 22H4a2 2 0 0 1-2-2v-7a2 2 0 0 1 2-2h3"})})}function Je({size:e=24}){return jsxRuntime.jsx("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",children:jsxRuntime.jsx("path",{d:"M10 15v4a3 3 0 0 0 3 3l4-9V2H5.72a2 2 0 0 0-2 1.7l-1.38 9a2 2 0 0 0 2 2.3zm7-13h2.67A2.31 2.31 0 0 1 22 4v7a2.31 2.31 0 0 1-2.33 2H17"})})}function me({mode:e,theme:s,customStyles:a,promptText:n,placeholder:u,submitText:c,thankYouMessage:t,isLoading:p,isSubmitted:r,error:d,existingResponse:l,isEditing:g=false,onSubmit:o,onClose:f,anchorRect:i}){let m=react.useRef(null),x=react.useRef(null),[k,h]=react.useState(false),[S,G]=react.useState(false),[A,O]=react.useState("light");react.useEffect(()=>{G(window.innerWidth<640);let y=window.matchMedia("(prefers-color-scheme: dark)");O(y.matches?"dark":"light");let w=T=>O(T.matches?"dark":"light");return y.addEventListener("change",w),()=>y.removeEventListener("change",w)},[]),react.useEffect(()=>{let y=requestAnimationFrame(()=>h(true));return ()=>cancelAnimationFrame(y)},[]);let L=s==="auto"?A:s,b=L==="dark",U=(i?window.innerHeight-i.bottom:window.innerHeight/2)<280+20;react.useEffect(()=>{let y=m.current;if(!y)return;x.current?.focus();let w=T=>{if(T.key==="Escape"){f();return}if(T.key==="Tab"){let C=y.querySelectorAll('button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])'),P=C[0],B=C[C.length-1];T.shiftKey&&document.activeElement===P?(T.preventDefault(),B?.focus()):!T.shiftKey&&document.activeElement===B&&(T.preventDefault(),P?.focus());}};return document.addEventListener("keydown",w),()=>document.removeEventListener("keydown",w)},[f]);let z=e==="vote"?"What do you think?":"What do you think of this feature?",W=S?20:16,N=b?"0 1px 2px rgba(0,0,0,0.2), 0 4px 12px rgba(0,0,0,0.3), 0 12px 32px rgba(0,0,0,0.2)":"0 1px 2px rgba(0,0,0,0.04), 0 4px 12px rgba(0,0,0,0.06), 0 12px 32px rgba(0,0,0,0.06)",K=S?{position:"fixed",left:"50%",top:"50%",width:"calc(100vw - 32px)",maxWidth:320,padding:W,borderRadius:12,backgroundColor:b?"#1f2937":"#ffffff",color:b?"#f9fafb":"#111827",boxShadow:N,border:`1px solid ${b?"rgba(255,255,255,0.06)":"rgba(0,0,0,0.06)"}`,zIndex:9999,transition:"opacity 0.25s cubic-bezier(0.4, 0, 0.2, 1), transform 0.25s cubic-bezier(0.4, 0, 0.2, 1)",opacity:k?1:0,transform:k?"translate(-50%, -50%) scale(1)":"translate(-50%, -50%) scale(0.96)",...a?.modal}:{position:"absolute",left:"50%",width:320,padding:W,borderRadius:10,backgroundColor:b?"#1f2937":"#ffffff",color:b?"#f9fafb":"#111827",boxShadow:N,border:`1px solid ${b?"rgba(255,255,255,0.06)":"rgba(0,0,0,0.06)"}`,zIndex:9999,...U?{bottom:"100%",marginBottom:8}:{top:"100%",marginTop:8},transition:"opacity 0.25s cubic-bezier(0.4, 0, 0.2, 1), transform 0.25s cubic-bezier(0.4, 0, 0.2, 1)",opacity:k?1:0,transform:k?"translateX(-50%) scale(1) translateY(0)":`translateX(-50%) scale(0.96) translateY(${U?"6px":"-6px"})`,...a?.modal};return jsxRuntime.jsxs("div",{ref:m,role:"dialog","aria-modal":"true","aria-labelledby":"gotcha-modal-title",style:K,className:Z("gotcha-modal",b&&"gotcha-modal--dark"),children:[jsxRuntime.jsx("button",{ref:x,type:"button",onClick:f,"aria-label":"Close feedback form",style:{position:"absolute",top:S?12:8,right:S?12:8,width:S?36:28,height:S?36:28,border:"none",background:"transparent",cursor:"pointer",color:b?"#6b7280":"#9ca3af",display:"flex",alignItems:"center",justifyContent:"center",borderRadius:6,transition:"all 0.15s cubic-bezier(0.4, 0, 0.2, 1)"},onMouseEnter:y=>{y.currentTarget.style.backgroundColor=b?"rgba(255,255,255,0.06)":"rgba(0,0,0,0.04)",y.currentTarget.style.color=b?"#9ca3af":"#6b7280";},onMouseLeave:y=>{y.currentTarget.style.backgroundColor="transparent",y.currentTarget.style.color=b?"#6b7280":"#9ca3af";},children:jsxRuntime.jsx("svg",{width:S?16:12,height:S?16:12,viewBox:"0 0 14 14",fill:"none",children:jsxRuntime.jsx("path",{d:"M1 1L13 13M1 13L13 1",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"})})}),jsxRuntime.jsx("h2",{id:"gotcha-modal-title",style:{margin:"0 0 16px 0",fontSize:S?16:14,fontWeight:600,paddingRight:S?40:32,letterSpacing:"-0.01em",lineHeight:1.4},children:n||z}),r&&jsxRuntime.jsxs("div",{style:{textAlign:"center",padding:"24px 0",color:b?"#10b981":"#059669"},children:[jsxRuntime.jsx("div",{style:{width:44,height:44,borderRadius:"50%",backgroundColor:b?"rgba(16,185,129,0.1)":"rgba(5,150,105,0.08)",display:"flex",alignItems:"center",justifyContent:"center",margin:"0 auto 12px"},children:jsxRuntime.jsx("svg",{width:"22",height:"22",viewBox:"0 0 24 24",fill:"none",children:jsxRuntime.jsx("path",{d:"M20 6L9 17L4 12",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})})}),jsxRuntime.jsx("p",{style:{margin:0,fontSize:13,fontWeight:500,color:b?"#d1d5db":"#374151"},children:t})]}),d&&!r&&jsxRuntime.jsx("div",{style:{padding:"8px 10px",marginBottom:12,borderRadius:8,backgroundColor:b?"rgba(127,29,29,0.3)":"#fef2f2",border:`1px solid ${b?"rgba(254,202,202,0.1)":"rgba(220,38,38,0.1)"}`,color:b?"#fecaca":"#dc2626",fontSize:13,lineHeight:1.4},children:d}),!r&&jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[e==="feedback"&&jsxRuntime.jsx(De,{theme:L,placeholder:u,submitText:c,isLoading:p,onSubmit:o,customStyles:a,initialValues:l?{content:l.content,rating:l.rating}:void 0,isEditing:g}),e==="vote"&&jsxRuntime.jsx(Le,{theme:L,isLoading:p,onSubmit:o,initialVote:l?.vote||void 0,isEditing:g})]}),jsxRuntime.jsxs("div",{"aria-live":"polite",className:"sr-only",style:{position:"absolute",left:-9999},children:[r&&"Thank you! Your feedback has been submitted.",d&&`Error: ${d}`]})]})}function nt({elementId:e,user:s,mode:a="feedback",experimentId:n,variant:u,options:c,allowMultiple:t=false,showResults:p=true,position:r=I.POSITION,size:d=I.SIZE,theme:l=I.THEME,customStyles:g,visible:o=true,showOnHover:f=I.SHOW_ON_HOVER,touchBehavior:i=I.TOUCH_BEHAVIOR,promptText:m,placeholder:x,submitText:k=I.SUBMIT_TEXT,thankYouMessage:h=I.THANK_YOU_MESSAGE,onSubmit:S,onOpen:G,onClose:A,onError:O}){let{disabled:L,activeModalId:b,openModal:ne,closeModal:V}=_(),[U,z]=react.useState(false),[W,N]=react.useState(false),[K,y]=react.useState(null),[w,T]=react.useState(false),C=react.useRef(null);react.useEffect(()=>{T(window.innerWidth<640);},[]);let P=b===e;react.useEffect(()=>{if(!f)return;let E=C.current;if(!E)return;let H=E.parentElement;if(!H)return;let Se=()=>N(true),ve=()=>N(false);return H.addEventListener("mouseenter",Se),H.addEventListener("mouseleave",ve),()=>{H.removeEventListener("mouseenter",Se),H.removeEventListener("mouseleave",ve);}},[f]);let{submit:B,isLoading:he,error:be,existingResponse:ye,isEditing:X}=Ie({elementId:e,mode:a,experimentId:n,variant:u,pollOptions:c,user:s,onSuccess:E=>{z(true),S?.(E),setTimeout(()=>{V(),z(false);},3e3);},onError:E=>{console.warn("[Gotcha] Submission failed:",E instanceof Error?E.message:E),O?.(E);}}),Ne=react.useCallback(()=>{C.current&&y(C.current.getBoundingClientRect()),ne(e),G?.();},[e,ne,G]),re=react.useCallback(()=>{V(),z(false),A?.();},[V,A]),xe=react.useCallback(E=>{B(E);},[B]);return L||!o?null:jsxRuntime.jsxs("div",{ref:C,style:{...{"top-right":{position:"absolute",top:0,right:0,transform:"translate(50%, -50%)"},"top-left":{position:"absolute",top:0,left:0,transform:"translate(-50%, -50%)"},"bottom-right":{position:"absolute",bottom:0,right:0,transform:"translate(50%, 50%)"},"bottom-left":{position:"absolute",bottom:0,left:0,transform:"translate(-50%, 50%)"},inline:{position:"relative",display:"inline-flex"}}[r],zIndex:P?1e4:"auto"},className:"gotcha-container","data-gotcha-element":e,children:[jsxRuntime.jsx(Pe,{size:d,theme:l,customStyles:g,showOnHover:f,touchBehavior:i,onClick:Ne,isOpen:P,isParentHovered:W}),P&&!w&&jsxRuntime.jsx(me,{mode:a,theme:l,customStyles:g,promptText:m,placeholder:x,submitText:k,thankYouMessage:X?"Your feedback has been updated!":h,isLoading:he,isSubmitted:U,error:be,existingResponse:ye,isEditing:X,onSubmit:xe,onClose:re,anchorRect:K||void 0}),P&&w&&reactDom.createPortal(jsxRuntime.jsx("div",{style:{position:"fixed",inset:0,zIndex:99999,backgroundColor:"rgba(0, 0, 0, 0.3)"},onClick:re,"aria-hidden":"true",children:jsxRuntime.jsx("div",{onClick:E=>E.stopPropagation(),children:jsxRuntime.jsx(me,{mode:a,theme:l,customStyles:g,promptText:m,placeholder:x,submitText:k,thankYouMessage:X?"Your feedback has been updated!":h,isLoading:he,isSubmitted:U,error:be,existingResponse:ye,isEditing:X,onSubmit:xe,onClose:re,anchorRect:K||void 0})})}),document.body)]})}function st(){let{client:e,disabled:s,defaultUser:a,debug:n}=_();return {client:e,disabled:s,defaultUser:a,debug:n,submitFeedback:e.submitResponse.bind(e)}}exports.Gotcha=nt;exports.GotchaProvider=Ye;exports.useGotcha=st;//# sourceMappingURL=index.js.map
|
|
11
|
+
`}),jsxRuntime.jsx("circle",{cx:"12",cy:"12",r:"10",stroke:a,strokeWidth:"2",strokeOpacity:"0.12"}),jsxRuntime.jsx("circle",{cx:"12",cy:"12",r:"10",stroke:a,strokeWidth:"2",strokeLinecap:"round",style:{animation:"gotcha-dash 1.2s ease-in-out infinite"}})]})}function ze({theme:e,placeholder:a,submitText:l,isLoading:o,onSubmit:b,customStyles:m,initialValues:t,isEditing:c=false}){let[r,u]=react.useState(t?.content||""),[d,s]=react.useState(t?.rating??null),[i,f]=react.useState(false);react.useEffect(()=>{f(I());},[]),react.useEffect(()=>{t?.content!==void 0&&u(t.content||""),t?.rating!==void 0&&s(t.rating??null);},[t?.content,t?.rating]);let p=e==="dark",g=h=>{h.preventDefault(),!(!r.trim()&&d===null)&&b({content:r.trim()||void 0,rating:d??void 0});},n={width:"100%",padding:i?"12px 14px":"10px 12px",border:`1px solid ${p?"rgba(255,255,255,0.08)":"#e2e8f0"}`,borderRadius:8,backgroundColor:p?"rgba(55,65,81,0.5)":"#fafbfc",color:p?"#f9fafb":"#111827",fontSize:i?16:14,resize:"vertical",minHeight:i?100:80,fontFamily:"inherit",outline:"none",transition:"border-color 0.2s cubic-bezier(0.4, 0, 0.2, 1), box-shadow 0.2s cubic-bezier(0.4, 0, 0.2, 1)",lineHeight:1.5,...m?.input},v={width:"100%",padding:i?"14px 16px":"10px 16px",border:"none",borderRadius:8,backgroundColor:p?"#e2e8f0":"#1e293b",color:p?"#1e293b":"#ffffff",fontSize:i?16:14,fontWeight:500,cursor:o?"not-allowed":"pointer",transition:"all 0.2s cubic-bezier(0.4, 0, 0.2, 1)",letterSpacing:"0.01em",...m?.submitButton};return jsxRuntime.jsxs("form",{onSubmit:g,children:[jsxRuntime.jsx("div",{style:{marginBottom:i?16:12},children:jsxRuntime.jsx(rt,{value:d,onChange:s,isDark:p,isTouch:i})}),jsxRuntime.jsx("textarea",{value:r,onChange:h=>u(h.target.value),placeholder:a||"Share your thoughts...",style:n,disabled:o,"aria-label":"Your feedback",onFocus:h=>{h.currentTarget.style.borderColor="#1e293b",h.currentTarget.style.boxShadow="0 0 0 2px rgba(30,41,59,0.15)",h.currentTarget.style.backgroundColor=p?"rgba(55,65,81,0.7)":"#ffffff";},onBlur:h=>{h.currentTarget.style.borderColor=p?"rgba(255,255,255,0.08)":"#e2e8f0",h.currentTarget.style.boxShadow="none",h.currentTarget.style.backgroundColor=p?"rgba(55,65,81,0.5)":"#fafbfc";}}),jsxRuntime.jsxs("button",{type:"submit",disabled:o||!r.trim()&&d===null,style:{...v,marginTop:12,opacity:o?.8:1,backgroundColor:!r.trim()&&d===null?p?"#374151":"#e2e8f0":p?"#e2e8f0":"#1e293b",color:!r.trim()&&d===null?p?"#6b7280":"#94a3b8":p?"#1e293b":"#ffffff",display:"flex",alignItems:"center",justifyContent:"center",gap:8},onMouseEnter:h=>{h.currentTarget.disabled||(h.currentTarget.style.backgroundColor=p?"#cbd5e1":"#334155");},onMouseLeave:h=>{h.currentTarget.disabled||(h.currentTarget.style.backgroundColor=p?"#e2e8f0":"#1e293b");},children:[o&&jsxRuntime.jsx(_,{size:i?18:16,color:p?"#1e293b":"#ffffff"}),o?c?"Updating...":"Submitting...":c?"Update":l]})]})}function rt({value:e,onChange:a,isDark:l,isTouch:o}){let[b,m]=react.useState(null),t=o?28:18,c=o?6:3;return jsxRuntime.jsx("div",{style:{display:"flex",gap:o?6:2},role:"group","aria-label":"Rating",children:[1,2,3,4,5].map(r=>{let u=(b??e??0)>=r;return jsxRuntime.jsx("button",{type:"button",onClick:()=>a(r),onMouseEnter:()=>m(r),onMouseLeave:()=>m(null),"aria-label":`Rate ${r} out of 5`,"aria-pressed":e===r,style:{background:"none",border:"none",cursor:"pointer",padding:c,color:u?"#f59e0b":l?"rgba(255,255,255,0.12)":"#e2e8f0",transition:"color 0.15s cubic-bezier(0.4, 0, 0.2, 1), transform 0.15s cubic-bezier(0.4, 0, 0.2, 1)",transform:b!==null&&b>=r?"scale(1.1)":"scale(1)"},children:jsxRuntime.jsx("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"currentColor",children:jsxRuntime.jsx("path",{d:"M12 2l3.09 6.26L22 9.27l-5 4.87 1.18 6.88L12 17.77l-6.18 3.25L7 14.14 2 9.27l6.91-1.01L12 2z"})})},r)})})}function Ne({theme:e,isLoading:a,onSubmit:l,initialVote:o,isEditing:b=false,labels:m}){let[t,c]=react.useState(false),[r,u]=react.useState(o||null),[d,s]=react.useState(o||null);react.useEffect(()=>{c(I());},[]),react.useEffect(()=>{o!==void 0&&(s(o),u(o));},[o]),react.useEffect(()=>{!a&&!b&&u(null);},[a,b]);let i=n=>{u(n),l({vote:n});},f=e==="dark",p=n=>{let v=d===n;return {flex:1,minWidth:0,overflow:"hidden",padding:t?"14px 18px":"10px 14px",border:`1px solid ${v?n==="up"?f?"rgba(16,185,129,0.3)":"rgba(16,185,129,0.25)":f?"rgba(239,68,68,0.3)":"rgba(239,68,68,0.25)":f?"rgba(255,255,255,0.08)":"#e2e8f0"}`,borderRadius:t?10:8,backgroundColor:v?n==="up"?f?"rgba(16,185,129,0.08)":"rgba(16,185,129,0.06)":f?"rgba(239,68,68,0.08)":"rgba(239,68,68,0.06)":f?"rgba(55,65,81,0.5)":"#fafbfc",color:v?n==="up"?"#10b981":"#ef4444":f?"#d1d5db":"#64748b",fontSize:t?28:24,cursor:a?"not-allowed":"pointer",transition:"background-color 0.2s, border-color 0.2s, color 0.2s, transform 0.2s, box-shadow 0.2s",display:"flex",alignItems:"center",justifyContent:"center",gap:t?10:8}},g=t?24:20;return jsxRuntime.jsxs("div",{style:{display:"flex",gap:t?12:10},role:"group","aria-label":"Vote",children:[jsxRuntime.jsx("button",{type:"button",onClick:()=>i("up"),disabled:a,style:p("up"),"aria-label":"Vote up - I like this","aria-pressed":d==="up",onMouseEnter:n=>{a||(n.currentTarget.style.transform="translateY(-1px)",n.currentTarget.style.boxShadow="0 2px 8px rgba(0,0,0,0.06)");},onMouseLeave:n=>{n.currentTarget.style.transform="translateY(0)",n.currentTarget.style.boxShadow="none";},children:a&&r==="up"?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(_,{size:g,color:f?"#f9fafb":"#111827"}),jsxRuntime.jsx("span",{style:{fontSize:t?15:13,fontWeight:500,letterSpacing:"0.01em"},children:b?"Updating...":"Sending..."})]}):jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(nt,{size:g}),jsxRuntime.jsx("span",{style:{fontSize:t?15:13,fontWeight:500,letterSpacing:"0.01em"},children:m?.up||(d==="up"?"Liked":"Like")})]})}),jsxRuntime.jsx("button",{type:"button",onClick:()=>i("down"),disabled:a,style:p("down"),"aria-label":"Vote down - I don't like this","aria-pressed":d==="down",onMouseEnter:n=>{a||(n.currentTarget.style.transform="translateY(-1px)",n.currentTarget.style.boxShadow="0 2px 8px rgba(0,0,0,0.06)");},onMouseLeave:n=>{n.currentTarget.style.transform="translateY(0)",n.currentTarget.style.boxShadow="none";},children:a&&r==="down"?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(_,{size:g,color:f?"#f9fafb":"#111827"}),jsxRuntime.jsx("span",{style:{fontSize:t?15:13,fontWeight:500,letterSpacing:"0.01em"},children:b?"Updating...":"Sending..."})]}):jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(st,{size:g}),jsxRuntime.jsx("span",{style:{fontSize:t?15:13,fontWeight:500,letterSpacing:"0.01em"},children:m?.down||(d==="down"?"Disliked":"Dislike")})]})})]})}function nt({size:e=24}){return jsxRuntime.jsx("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",children:jsxRuntime.jsx("path",{d:"M14 9V5a3 3 0 0 0-3-3l-4 9v11h11.28a2 2 0 0 0 2-1.7l1.38-9a2 2 0 0 0-2-2.3zM7 22H4a2 2 0 0 1-2-2v-7a2 2 0 0 1 2-2h3"})})}function st({size:e=24}){return jsxRuntime.jsx("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",children:jsxRuntime.jsx("path",{d:"M10 15v4a3 3 0 0 0 3 3l4-9V2H5.72a2 2 0 0 0-2 1.7l-1.38 9a2 2 0 0 0 2 2.3zm7-13h2.67A2.31 2.31 0 0 1 22 4v7a2.31 2.31 0 0 1-2.33 2H17"})})}function $e({theme:e,options:a,allowMultiple:l,isLoading:o,onSubmit:b,initialSelected:m,isEditing:t=false}){let[c,r]=react.useState(m||[]),[u,d]=react.useState(false);react.useEffect(()=>{d(I());},[]),react.useEffect(()=>{m&&r(m);},[m]);let s=e==="dark",i=g=>{r(l?n=>n.includes(g)?n.filter(v=>v!==g):[...n,g]:n=>n.includes(g)?[]:[g]);},f=()=>{c.length!==0&&b({pollSelected:c});},p=g=>{let n=c.includes(g);return {width:"100%",padding:u?"12px 14px":"9px 12px",border:`1px solid ${n?s?"rgba(226,232,240,0.25)":"rgba(30,41,59,0.25)":s?"rgba(255,255,255,0.08)":"#e2e8f0"}`,borderRadius:u?10:8,backgroundColor:n?s?"rgba(226,232,240,0.08)":"rgba(30,41,59,0.05)":s?"rgba(55,65,81,0.5)":"#fafbfc",color:n?s?"#e2e8f0":"#1e293b":s?"#d1d5db":"#374151",fontSize:u?15:13,fontWeight:500,cursor:o?"not-allowed":"pointer",transition:"background-color 0.2s, border-color 0.2s, color 0.2s",textAlign:"left",letterSpacing:"0.01em",display:"flex",alignItems:"center",gap:8}};return jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("div",{style:{display:"flex",flexDirection:"column",gap:u?8:6},role:"group","aria-label":l?"Select one or more options":"Select an option",children:a.map(g=>{let n=c.includes(g);return jsxRuntime.jsxs("button",{type:"button",onClick:()=>i(g),disabled:o,style:p(g),"aria-pressed":n,children:[jsxRuntime.jsx("span",{style:{width:16,height:16,borderRadius:l?4:"50%",border:`2px solid ${n?s?"#e2e8f0":"#1e293b":s?"rgba(255,255,255,0.2)":"#cbd5e1"}`,backgroundColor:n?s?"#e2e8f0":"#1e293b":"transparent",display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0,transition:"all 0.15s"},children:n&&jsxRuntime.jsx("svg",{width:10,height:10,viewBox:"0 0 12 12",fill:"none",children:jsxRuntime.jsx("path",{d:"M2 6l3 3 5-5",stroke:"#fff",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})})}),g]},g)})}),jsxRuntime.jsxs("button",{type:"button",onClick:f,disabled:o||c.length===0,style:{width:"100%",marginTop:12,padding:u?"14px 16px":"10px 16px",border:"none",borderRadius:8,backgroundColor:c.length===0?s?"#374151":"#e2e8f0":s?"#e2e8f0":"#1e293b",color:c.length===0?s?"#6b7280":"#94a3b8":s?"#1e293b":"#ffffff",fontSize:u?16:14,fontWeight:500,cursor:o||c.length===0?"not-allowed":"pointer",transition:"all 0.2s cubic-bezier(0.4, 0, 0.2, 1)",letterSpacing:"0.01em",display:"flex",alignItems:"center",justifyContent:"center",gap:8,opacity:o?.8:1},onMouseEnter:g=>{g.currentTarget.disabled||(g.currentTarget.style.backgroundColor=s?"#cbd5e1":"#334155");},onMouseLeave:g=>{g.currentTarget.disabled||(g.currentTarget.style.backgroundColor=c.length===0?s?"#374151":"#e2e8f0":s?"#e2e8f0":"#1e293b");},children:[o&&jsxRuntime.jsx(_,{size:u?18:16,color:s?"#1e293b":"#ffffff"}),o?t?"Updating...":"Submitting...":t?"Update":"Submit"]})]})}function xe({mode:e,theme:a,customStyles:l,promptText:o,placeholder:b,submitText:m,thankYouMessage:t,isLoading:c,isSubmitted:r,error:u,existingResponse:d,isEditing:s=false,voteLabels:i,options:f,allowMultiple:p=false,onSubmit:g,onClose:n,anchorRect:v}){let h=react.useRef(null),P=react.useRef(null),[C,A]=react.useState(false),[S,se]=react.useState(false),[ae,F]=react.useState("light");react.useEffect(()=>{se(window.innerWidth<640);let x=window.matchMedia("(prefers-color-scheme: dark)");F(x.matches?"dark":"light");let w=E=>F(E.matches?"dark":"light");return x.addEventListener("change",w),()=>x.removeEventListener("change",w)},[]),react.useEffect(()=>{let x=requestAnimationFrame(()=>A(true));return ()=>cancelAnimationFrame(x)},[]);let O=a==="auto"?ae:a,y=O==="dark",V=(v?window.innerHeight-v.bottom:window.innerHeight/2)<280+20;react.useEffect(()=>{let x=h.current;if(!x)return;P.current?.focus();let w=E=>{if(E.key==="Escape"){n();return}if(E.key==="Tab"){let D=x.querySelectorAll('button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])'),z=D[0],N=D[D.length-1];E.shiftKey&&document.activeElement===z?(E.preventDefault(),N?.focus()):!E.shiftKey&&document.activeElement===N&&(E.preventDefault(),z?.focus());}};return document.addEventListener("keydown",w),()=>document.removeEventListener("keydown",w)},[n]);let K=e==="vote"?"What do you think?":e==="poll"?"Cast your vote":"What do you think of this feature?",U=S?20:16,X=y?"0 1px 2px rgba(0,0,0,0.2), 0 4px 12px rgba(0,0,0,0.3), 0 12px 32px rgba(0,0,0,0.2)":"0 1px 2px rgba(0,0,0,0.04), 0 4px 12px rgba(0,0,0,0.06), 0 12px 32px rgba(0,0,0,0.06)",j=S?{position:"fixed",left:"50%",top:"50%",width:"calc(100vw - 32px)",maxWidth:320,padding:U,borderRadius:12,backgroundColor:y?"#1f2937":"#ffffff",color:y?"#f9fafb":"#111827",boxShadow:X,border:`1px solid ${y?"rgba(255,255,255,0.06)":"rgba(0,0,0,0.06)"}`,zIndex:9999,transition:"opacity 0.25s cubic-bezier(0.4, 0, 0.2, 1), transform 0.25s cubic-bezier(0.4, 0, 0.2, 1)",opacity:C?1:0,transform:C?"translate(-50%, -50%) scale(1)":"translate(-50%, -50%) scale(0.96)",...l?.modal}:{position:"absolute",left:"50%",width:320,padding:U,borderRadius:10,backgroundColor:y?"#1f2937":"#ffffff",color:y?"#f9fafb":"#111827",boxShadow:X,border:`1px solid ${y?"rgba(255,255,255,0.06)":"rgba(0,0,0,0.06)"}`,zIndex:9999,...V?{bottom:"100%",marginBottom:8}:{top:"100%",marginTop:8},transition:"opacity 0.25s cubic-bezier(0.4, 0, 0.2, 1), transform 0.25s cubic-bezier(0.4, 0, 0.2, 1)",opacity:C?1:0,transform:C?"translateX(-50%) scale(1) translateY(0)":`translateX(-50%) scale(0.96) translateY(${V?"6px":"-6px"})`,...l?.modal};return jsxRuntime.jsxs("div",{ref:h,role:"dialog","aria-modal":"true","aria-labelledby":"gotcha-modal-title",style:j,className:ee("gotcha-modal",y&&"gotcha-modal--dark"),children:[jsxRuntime.jsx("button",{ref:P,type:"button",onClick:n,"aria-label":"Close feedback form",style:{position:"absolute",top:S?12:8,right:S?12:8,width:S?36:28,height:S?36:28,border:"none",background:"transparent",cursor:"pointer",color:y?"#6b7280":"#9ca3af",display:"flex",alignItems:"center",justifyContent:"center",borderRadius:6,transition:"all 0.15s cubic-bezier(0.4, 0, 0.2, 1)"},onMouseEnter:x=>{x.currentTarget.style.backgroundColor=y?"rgba(255,255,255,0.06)":"rgba(0,0,0,0.04)",x.currentTarget.style.color=y?"#9ca3af":"#6b7280";},onMouseLeave:x=>{x.currentTarget.style.backgroundColor="transparent",x.currentTarget.style.color=y?"#6b7280":"#9ca3af";},children:jsxRuntime.jsx("svg",{width:S?16:12,height:S?16:12,viewBox:"0 0 14 14",fill:"none",children:jsxRuntime.jsx("path",{d:"M1 1L13 13M1 13L13 1",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"})})}),jsxRuntime.jsx("h2",{id:"gotcha-modal-title",style:{margin:"0 0 16px 0",fontSize:S?16:14,fontWeight:600,paddingRight:S?40:32,letterSpacing:"-0.01em",lineHeight:1.4},children:o||K}),r&&jsxRuntime.jsxs("div",{style:{textAlign:"center",padding:"24px 0",color:y?"#10b981":"#059669"},children:[jsxRuntime.jsx("div",{style:{width:44,height:44,borderRadius:"50%",backgroundColor:y?"rgba(16,185,129,0.1)":"rgba(5,150,105,0.08)",display:"flex",alignItems:"center",justifyContent:"center",margin:"0 auto 12px"},children:jsxRuntime.jsx("svg",{width:"22",height:"22",viewBox:"0 0 24 24",fill:"none",children:jsxRuntime.jsx("path",{d:"M20 6L9 17L4 12",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})})}),jsxRuntime.jsx("p",{style:{margin:0,fontSize:13,fontWeight:500,color:y?"#d1d5db":"#374151"},children:t})]}),u&&!r&&jsxRuntime.jsx("div",{style:{padding:"8px 10px",marginBottom:12,borderRadius:8,backgroundColor:y?"rgba(127,29,29,0.3)":"#fef2f2",border:`1px solid ${y?"rgba(254,202,202,0.1)":"rgba(220,38,38,0.1)"}`,color:y?"#fecaca":"#dc2626",fontSize:13,lineHeight:1.4},children:u}),!r&&jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[e==="feedback"&&jsxRuntime.jsx(ze,{theme:O,placeholder:b,submitText:m,isLoading:c,onSubmit:g,customStyles:l,initialValues:d?{content:d.content,rating:d.rating}:void 0,isEditing:s}),e==="vote"&&jsxRuntime.jsx(Ne,{theme:O,isLoading:c,onSubmit:g,initialVote:d?.vote||void 0,isEditing:s,labels:i}),e==="poll"&&f&&f.length>0&&jsxRuntime.jsx($e,{theme:O,options:f,allowMultiple:p,isLoading:c,onSubmit:g,initialSelected:d?.pollSelected||void 0,isEditing:s})]}),jsxRuntime.jsxs("div",{"aria-live":"polite",className:"sr-only",style:{position:"absolute",left:-9999},children:[r&&"Thank you! Your feedback has been submitted.",u&&`Error: ${u}`]})]})}function ct({elementId:e,user:a,mode:l="feedback",experimentId:o,variant:b,voteLabels:m,options:t,allowMultiple:c=false,showResults:r=true,position:u=M.POSITION,size:d=M.SIZE,theme:s=M.THEME,customStyles:i,visible:f=true,showOnHover:p=M.SHOW_ON_HOVER,touchBehavior:g=M.TOUCH_BEHAVIOR,promptText:n,placeholder:v,submitText:h=M.SUBMIT_TEXT,thankYouMessage:P=M.THANK_YOU_MESSAGE,onSubmit:C,onOpen:A,onClose:S,onError:se}){let{disabled:ae,activeModalId:F,openModal:O,closeModal:y}=L(),[ie,W]=react.useState(false),[V,K]=react.useState(false),[U,X]=react.useState(null),[j,x]=react.useState(false),w=react.useRef(null);react.useEffect(()=>{x(window.innerWidth<640);},[]);let E=F===e;react.useEffect(()=>{if(!p)return;let R=w.current;if(!R)return;let B=R.parentElement;if(!B)return;let Ee=()=>K(true),Re=()=>K(false);return B.addEventListener("mouseenter",Ee),B.addEventListener("mouseleave",Re),()=>{B.removeEventListener("mouseenter",Ee),B.removeEventListener("mouseleave",Re);}},[p]);let{submit:D,isLoading:z,error:N,existingResponse:ve,isEditing:Q}=Pe({elementId:e,mode:l,experimentId:o,variant:b,pollOptions:t,user:a,onSuccess:R=>{W(true),C?.(R),setTimeout(()=>{y(),W(false);},3e3);},onError:R=>{console.warn("[Gotcha] Submission failed:",R instanceof Error?R.message:R),se?.(R);}}),We=react.useCallback(()=>{w.current&&X(w.current.getBoundingClientRect()),O(e),A?.();},[e,O,A]),le=react.useCallback(()=>{y(),W(false),S?.();},[y,S]),ke=react.useCallback(R=>{D(R);},[D]);return ae||!f?null:jsxRuntime.jsxs("div",{ref:w,style:{...{"top-right":{position:"absolute",top:0,right:0,transform:"translate(50%, -50%)"},"top-left":{position:"absolute",top:0,left:0,transform:"translate(-50%, -50%)"},"bottom-right":{position:"absolute",bottom:0,right:0,transform:"translate(50%, 50%)"},"bottom-left":{position:"absolute",bottom:0,left:0,transform:"translate(-50%, 50%)"},inline:{position:"relative",display:"inline-flex"}}[u],zIndex:E?1e4:"auto"},className:"gotcha-container","data-gotcha-element":e,children:[jsxRuntime.jsx(De,{size:d,theme:s,customStyles:i,showOnHover:p,touchBehavior:g,onClick:We,isOpen:E,isParentHovered:V}),E&&!j&&jsxRuntime.jsx(xe,{mode:l,theme:s,customStyles:i,promptText:n,placeholder:v,submitText:h,thankYouMessage:Q?"Your feedback has been updated!":P,isLoading:z,isSubmitted:ie,error:N,existingResponse:ve,isEditing:Q,voteLabels:m,options:t,allowMultiple:c,onSubmit:ke,onClose:le,anchorRect:U||void 0}),E&&j&&reactDom.createPortal(jsxRuntime.jsx("div",{style:{position:"fixed",inset:0,zIndex:99999,backgroundColor:"rgba(0, 0, 0, 0.3)"},onClick:le,"aria-hidden":"true",children:jsxRuntime.jsx("div",{onClick:R=>R.stopPropagation(),children:jsxRuntime.jsx(xe,{mode:l,theme:s,customStyles:i,promptText:n,placeholder:v,submitText:h,thankYouMessage:Q?"Your feedback has been updated!":P,isLoading:z,isSubmitted:ie,error:N,existingResponse:ve,isEditing:Q,voteLabels:m,options:t,allowMultiple:c,onSubmit:ke,onClose:le,anchorRect:U||void 0})})}),document.body)]})}function ut(){let{client:e,disabled:a,defaultUser:l,debug:o}=L();return {client:e,disabled:a,defaultUser:l,debug:o,submitFeedback:e.submitResponse.bind(e)}}exports.Gotcha=ct;exports.GotchaProvider=je;exports.useGotcha=ut;//# sourceMappingURL=index.js.map
|
|
12
12
|
//# sourceMappingURL=index.js.map
|