/* eslint-disable jsx-a11y/click-events-have-key-events */ import React from 'react'; import cls from 'classnames'; import { cssClasses, strings } from '@douyinfe/semi-foundation/feedback/constants'; import BaseComponent from '../_base/baseComponent'; import { ArrayElement } from '../_base/base'; import { TextArea, RadioGroup, CheckboxGroup, Button, Modal, SideSheet } from '../index'; import { RadioGroupProps } from '../radio/radioGroup'; import { CheckboxGroupProps } from '../checkbox/checkboxGroup'; import { omit, noop } from 'lodash'; import { ModalReactProps } from '../modal'; import { SideSheetReactProps } from '../sideSheet'; import { TextAreaProps } from '../input/textarea'; import { Locale } from '../locale/interface'; import LocaleConsumer from '../locale/localeConsumer'; import { ButtonProps } from '../button'; import FeedbackFoundation, { FeedbackAdapter } from '@douyinfe/semi-foundation/feedback/foundation'; import { RadioChangeEvent } from '../radio'; import '@douyinfe/semi-foundation/feedback/feedback.scss'; const { Emoji } = strings; const prefixCls = cssClasses.PREFIX; export interface BasicFeedbackProps { mode?: ArrayElement; type?: ArrayElement; onValueChange?: (value: FeedbackValue) => void; textAreaProps?: TextAreaProps; radioGroupProps?: RadioGroupProps; checkboxGroupProps?: CheckboxGroupProps; renderContent?: (content: React.ReactNode) => React.ReactNode } export interface FeedbackModalProps extends ModalReactProps, BasicFeedbackProps { } export interface FeedbackSideSheetProps extends Omit, BasicFeedbackProps { onOk?: (e: React.MouseEvent) => void | Promise; onCancel?: (e: React.MouseEvent) => void | Promise; okButtonProps?: ButtonProps; cancelButtonProps?: ButtonProps; afterClose?: () => void } export type FeedbackProps = FeedbackModalProps | FeedbackSideSheetProps; interface EmojiResult { emoji?: string; text?: string } type FeedbackValue = string | string[] | EmojiResult; interface FeedbackState { value: FeedbackValue; onOKReturnPromiseStatus?: "pending" | "fulfilled" | "rejected"; onCancelReturnPromiseStatus?: "pending" | "fulfilled" | "rejected" } export default class Feedback extends BaseComponent { static __SemiComponentName__ = "Feedback"; static defaultProps = { mode: 'popup', type: 'emoji', onValueChange: noop, onCancel: noop, onOk: noop, afterClose: noop, }; foundation: FeedbackFoundation; constructor(props: FeedbackProps) { super(props); this.state = { value: null, onOKReturnPromiseStatus: "fulfilled", onCancelReturnPromiseStatus: "fulfilled", }; this.foundation = new FeedbackFoundation(this.adapter); } get adapter() { return { ...super.adapter, setValue: (value: FeedbackValue) => { this.setState({ value: value }); }, notifyValueChange: (value: FeedbackValue) => { this.setState({ value: value }); this.props.onValueChange(value); }, notifyClose: () => { return this.props.afterClose(); }, notifyCancel: (e: React.MouseEvent) => { return this.props.onCancel(e); }, notifyOk: (e: React.MouseEvent) => { return this.props.onOk(e); }, notifyTextAreaChange: (value: string, e: React.MouseEvent) => { const { textAreaProps = {} } = this.props; const { onChange } = textAreaProps; onChange?.(value, e); }, notifyCheckBoxChange: (value: any[]) => { const { checkboxGroupProps = {} } = this.props; const { onChange } = checkboxGroupProps; onChange?.(value); }, notifyRadioChange: (e: RadioChangeEvent) => { const { onChange } = this.props?.radioGroupProps; onChange?.(e); } }; } textNode = () => { const { textAreaProps } = this.props; return