@kelet-ai/feedback-ui 1.2.0 → 1.3.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.
- package/dist/components/vote-feedback.d.ts +2 -1
- package/dist/feedback-ui.es.js +33 -11
- package/dist/feedback-ui.es.js.map +1 -1
- package/dist/feedback-ui.es.min.js +617 -601
- package/dist/feedback-ui.es.min.js.map +1 -1
- package/dist/feedback-ui.umd.js +32 -10
- package/dist/feedback-ui.umd.js.map +1 -1
- package/dist/feedback-ui.umd.min.js +10 -10
- package/dist/feedback-ui.umd.min.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
import { default as React } from 'react';
|
|
1
2
|
import { DownvoteButtonProps, PopoverProps, SubmitButtonProps, TextareaProps, UpvoteButtonProps, VoteFeedbackRootProps } from '../types';
|
|
2
3
|
export declare const VoteFeedback: {
|
|
3
4
|
Root: ({ children, onFeedback, defaultText, session_id: sessionIdProp, metadata, trigger_name: triggerProp, trace_id, }: VoteFeedbackRootProps) => import("react/jsx-runtime").JSX.Element;
|
|
4
5
|
UpvoteButton: ({ asChild, children, onClick, ...props }: UpvoteButtonProps) => import("react/jsx-runtime").JSX.Element;
|
|
5
|
-
DownvoteButton: ({ asChild, children, onClick, ...props }: DownvoteButtonProps) => string | number | bigint | true | Iterable<
|
|
6
|
+
DownvoteButton: ({ asChild, children, onClick, ...props }: DownvoteButtonProps) => string | number | bigint | true | Iterable<React.ReactNode> | Promise<string | number | bigint | boolean | React.ReactPortal | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | Iterable<React.ReactNode> | null | undefined> | import("react/jsx-runtime").JSX.Element;
|
|
6
7
|
Popover: ({ asChild, children, ...props }: PopoverProps) => import("react/jsx-runtime").JSX.Element | null;
|
|
7
8
|
Textarea: ({ asChild, value, onChange, ...props }: TextareaProps) => import("react/jsx-runtime").JSX.Element;
|
|
8
9
|
SubmitButton: ({ asChild, children, onClick, ...props }: SubmitButtonProps) => import("react/jsx-runtime").JSX.Element;
|
package/dist/feedback-ui.es.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import require$$0$1, { createContext, useEffect, useContext, useCallback, isValidElement, cloneElement,
|
|
1
|
+
import require$$0$1, { createContext, useEffect, useContext, useCallback, isValidElement, cloneElement, useRef, useState, useId } from "react";
|
|
2
2
|
function getDefaultExportFromCjs(x) {
|
|
3
3
|
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, "default") ? x["default"] : x;
|
|
4
4
|
}
|
|
@@ -575,6 +575,11 @@ const VoteFeedbackRoot = ({
|
|
|
575
575
|
setVote(null);
|
|
576
576
|
setTimeout(() => triggerRef.current?.focus(), 0);
|
|
577
577
|
}, [session_id, defaultText]);
|
|
578
|
+
const closePopover = useCallback(() => {
|
|
579
|
+
setShowPopover(false);
|
|
580
|
+
setFeedbackText(defaultText);
|
|
581
|
+
setTimeout(() => triggerRef.current?.focus(), 0);
|
|
582
|
+
}, [defaultText]);
|
|
578
583
|
const handleUpvote = useCallback(async () => {
|
|
579
584
|
setVote("upvote");
|
|
580
585
|
const data = {
|
|
@@ -673,9 +678,7 @@ const VoteFeedbackRoot = ({
|
|
|
673
678
|
const handleKeyDown = useCallback(
|
|
674
679
|
(e) => {
|
|
675
680
|
if (e.key === "Escape") {
|
|
676
|
-
|
|
677
|
-
setFeedbackText(defaultText);
|
|
678
|
-
triggerRef.current?.focus();
|
|
681
|
+
closePopover();
|
|
679
682
|
} else if ((e.metaKey || e.ctrlKey) && e.key === "Enter") {
|
|
680
683
|
e.preventDefault();
|
|
681
684
|
handleSubmit().then((_) => {
|
|
@@ -698,7 +701,7 @@ const VoteFeedbackRoot = ({
|
|
|
698
701
|
}
|
|
699
702
|
}
|
|
700
703
|
},
|
|
701
|
-
[handleSubmit, showPopover, popoverId,
|
|
704
|
+
[handleSubmit, showPopover, popoverId, closePopover]
|
|
702
705
|
);
|
|
703
706
|
const contextValue = {
|
|
704
707
|
onFeedback: handler,
|
|
@@ -714,6 +717,7 @@ const VoteFeedbackRoot = ({
|
|
|
714
717
|
handleTextareaChange,
|
|
715
718
|
handleSubmit,
|
|
716
719
|
handleKeyDown,
|
|
720
|
+
closePopover,
|
|
717
721
|
textareaRef,
|
|
718
722
|
triggerRef,
|
|
719
723
|
popoverId,
|
|
@@ -803,7 +807,25 @@ const DownvoteButton = ({
|
|
|
803
807
|
return /* @__PURE__ */ jsxRuntimeExports.jsx("button", { ...slotProps, children: typeof children === "function" ? children({ isSelected }) : children });
|
|
804
808
|
};
|
|
805
809
|
const Popover = ({ asChild, children, ...props }) => {
|
|
806
|
-
const {
|
|
810
|
+
const {
|
|
811
|
+
showPopover,
|
|
812
|
+
closePopover,
|
|
813
|
+
handleKeyDown,
|
|
814
|
+
popoverId,
|
|
815
|
+
triggerId,
|
|
816
|
+
triggerRef
|
|
817
|
+
} = useVoteFeedbackContext();
|
|
818
|
+
const containerRef = useRef(null);
|
|
819
|
+
useEffect(() => {
|
|
820
|
+
if (!showPopover) return;
|
|
821
|
+
const handleMouseDown = (event) => {
|
|
822
|
+
if (containerRef.current && !containerRef.current.contains(event.target) && !triggerRef.current?.contains(event.target)) {
|
|
823
|
+
closePopover();
|
|
824
|
+
}
|
|
825
|
+
};
|
|
826
|
+
document.addEventListener("mousedown", handleMouseDown);
|
|
827
|
+
return () => document.removeEventListener("mousedown", handleMouseDown);
|
|
828
|
+
}, [showPopover, closePopover, triggerRef]);
|
|
807
829
|
if (!showPopover) {
|
|
808
830
|
return null;
|
|
809
831
|
}
|
|
@@ -819,14 +841,14 @@ const Popover = ({ asChild, children, ...props }) => {
|
|
|
819
841
|
};
|
|
820
842
|
if (asChild && isValidElement(children)) {
|
|
821
843
|
return /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
|
|
822
|
-
cloneElement(
|
|
823
|
-
children,
|
|
824
|
-
|
|
825
|
-
),
|
|
844
|
+
cloneElement(children, {
|
|
845
|
+
...mergeProps(slotProps, children.props),
|
|
846
|
+
ref: containerRef
|
|
847
|
+
}),
|
|
826
848
|
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { id: `${popoverId}-description`, className: "sr-only", children: "Provide additional feedback for your downvote" })
|
|
827
849
|
] });
|
|
828
850
|
}
|
|
829
|
-
return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { ...slotProps, children: [
|
|
851
|
+
return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { ref: containerRef, ...slotProps, children: [
|
|
830
852
|
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { id: `${popoverId}-description`, className: "sr-only", children: "Provide additional feedback for your downvote" }),
|
|
831
853
|
children
|
|
832
854
|
] });
|