-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Expand file tree
/
Copy pathSendButton.tsx
More file actions
70 lines (66 loc) · 2.57 KB
/
SendButton.tsx
File metadata and controls
70 lines (66 loc) · 2.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import { Show } from 'solid-js';
import { JSX } from 'solid-js/jsx-runtime';
import { DeleteIcon, SendIcon } from '../icons';
type SendButtonProps = {
sendButtonColor?: string;
isDisabled?: boolean;
isLoading?: boolean;
disableIcon?: boolean;
} & JSX.ButtonHTMLAttributes<HTMLButtonElement>;
export const SendButton = (props: SendButtonProps) => {
return (
<button
type="submit"
disabled={props.isDisabled || props.isLoading}
{...props}
class={
'py-2 px-4 justify-center font-semibold text-white focus:outline-none flex items-center disabled:opacity-50 disabled:cursor-not-allowed disabled:brightness-100 transition-all filter hover:brightness-90 active:brightness-75 chatbot-button ' +
props.class
}
style={{ background: 'transparent', border: 'none' }}
>
<Show when={!props.isLoading} fallback={<Spinner class="text-white" />}>
<SendIcon color={props.sendButtonColor} class={'send-icon flex ' + (props.disableIcon ? 'hidden' : '')} />
</Show>
</button>
);
};
export const DeleteButton = (props: SendButtonProps) => {
// Check if <flowise-fullchatbot> is present in the DOM
const isFullChatbot = document.querySelector('flowise-fullchatbot') !== null;
const paddingClass = isFullChatbot ? 'px-4' : 'px-12';
return (
<button
type="submit"
disabled={props.isDisabled || props.isLoading}
{...props}
class={
`resetbutton py-2 ${paddingClass} justify-center font-semibold text-white focus:outline-none flex items-center disabled:opacity-50 disabled:cursor-not-allowed disabled:brightness-100 transition-all filter hover:brightness-90 active:brightness-75 chatbot-button ` +
props.class
}
style={{ background: 'transparent', border: 'none' }}
title="Reset Chat"
>
<Show when={!props.isLoading} fallback={<Spinner class="text-white" />}>
<DeleteIcon color={props.sendButtonColor} class={'send-icon flex ' + (props.disableIcon ? 'hidden' : '')} />
</Show>
</button>
);
};
export const Spinner = (props: JSX.SvgSVGAttributes<SVGSVGElement>) => (
<svg
{...props}
class={'animate-spin -ml-1 mr-3 h-5 w-5 ' + props.class}
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
data-testid="loading-spinner"
>
<circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4" />
<path
class="opacity-75"
fill="currentColor"
d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"
/>
</svg>
);