Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 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 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 86x 86x 86x 86x 86x 86x 86x 86x 86x 86x 86x 86x 86x 86x 86x 86x 86x 86x 86x 86x 86x 86x 86x 86x 86x 86x 86x 86x 86x 2x 2x 86x 172x 172x 172x 4x 4x 172x 86x 4x 4x 4x 86x 86x 86x 86x 86x 86x 86x 86x 86x 86x 86x 86x 86x 86x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 86x 86x 86x 86x 86x 86x 86x 86x 86x 86x 86x 1x 1x 1x | // Libs
import { forwardRef, useRef, useState, type CSSProperties } from 'react';
import EmojiPicker, { EmojiClickData, Theme } from 'emoji-picker-react';
// Types
import { BaseVariant } from '@/types';
// Utils
import { combineClasses } from '@shared/utils';
// Hooks
import {
useTheme,
useDismissOnOutsideClick,
useContainedWheelScroll,
} from '@/hooks';
// Components
import { LinearSendIcon, SmileFaceIcon } from '@/components/icons/reacts';
// Constants
import { MENU_FEEDBACK_LABELS } from '@/constants/dailyFeedback';
// Styles
import './styles/feedback-submit.css';
const EMOJI_PICKER_WIDTH = 240;
const EMOJI_PICKER_HEIGHT = 280;
const compactEmojiPickerStyle = {
'--epr-emoji-size': '20px',
'--epr-emoji-padding': '3px',
'--epr-horizontal-padding': '6px',
'--epr-category-navigation-button-size': '22px',
'--epr-search-input-height': '32px',
'--epr-category-label-height': '28px',
} as CSSProperties;
const variantTheme = {
[BaseVariant.PRIMARY]: {
root: 'feedback-submit-root',
emojiButton: 'feedback-submit-emoji-button',
submitButton: 'feedback-submit-button',
submitIcon: 'feedback-submit-icon',
emojiPickerWrapper: 'feedback-submit-emoji-picker-wrapper',
emojiPicker: 'feedback-submit-emoji-picker',
},
};
export interface FeedbackSubmitProps {
onEmojiSelect?: (emoji: string) => void;
onSubmit?: () => void;
isSendDisabled?: boolean;
textareaRef?: React.RefObject<HTMLTextAreaElement>;
className?: string;
variant?: BaseVariant;
}
const FeedbackSubmitComponent = (
{
onEmojiSelect,
onSubmit,
isSendDisabled = false,
textareaRef,
className = '',
variant = BaseVariant.PRIMARY,
}: FeedbackSubmitProps,
emojiButtonRef: React.ForwardedRef<HTMLButtonElement>,
) => {
const theme = variantTheme[variant];
const { isDarkMode } = useTheme();
const [showEmojiPicker, setShowEmojiPicker] = useState(false);
const emojiPickerRef = useRef<HTMLDivElement>(null);
const internalEmojiButtonRef = useRef<HTMLButtonElement>(null);
useDismissOnOutsideClick({
enabled: showEmojiPicker,
ignoreRefs: [
emojiPickerRef,
internalEmojiButtonRef,
...(textareaRef ? [textareaRef] : []),
],
onDismiss: () => setShowEmojiPicker(false),
});
useContainedWheelScroll({
enabled: showEmojiPicker,
containerRef: emojiPickerRef,
});
const handleEmojiSelect = (emojiData: EmojiClickData) => {
onEmojiSelect?.(emojiData.emoji);
};
const handleEmojiButtonRef = (el: HTMLButtonElement | null) => {
internalEmojiButtonRef.current = el;
if (typeof emojiButtonRef === 'function') {
emojiButtonRef(el);
} else if (emojiButtonRef) {
emojiButtonRef.current = el;
}
};
const handleEmojiButtonClick = (e: React.MouseEvent<HTMLButtonElement>) => {
e.stopPropagation();
setShowEmojiPicker((prev) => !prev);
};
return (
<div
data-variant={variant}
className={combineClasses(theme.root, className)}
>
<div className={theme.emojiPickerWrapper}>
<button
ref={handleEmojiButtonRef}
type="button"
aria-label={MENU_FEEDBACK_LABELS.addEmoji}
onClick={handleEmojiButtonClick}
className={theme.emojiButton}
>
<SmileFaceIcon className="size-5" />
</button>
{showEmojiPicker && (
<div ref={emojiPickerRef} className={theme.emojiPicker}>
<EmojiPicker
onEmojiClick={handleEmojiSelect}
theme={isDarkMode ? Theme.DARK : Theme.LIGHT}
width={EMOJI_PICKER_WIDTH}
height={EMOJI_PICKER_HEIGHT}
skinTonesDisabled
previewConfig={{ showPreview: false }}
style={compactEmojiPickerStyle}
/>
</div>
)}
</div>
<button
type="button"
onClick={onSubmit}
disabled={isSendDisabled}
className={theme.submitButton}
>
<LinearSendIcon className={theme.submitIcon} />
{MENU_FEEDBACK_LABELS.submit}
</button>
</div>
);
};
export const FeedbackSubmit = forwardRef<
HTMLButtonElement,
FeedbackSubmitProps
>(FeedbackSubmitComponent);
FeedbackSubmit.displayName = 'FeedbackSubmit';
|