PluginProbe
Extendify / 3.0.5
Extendify v3.0.5
3.2.1 3.2.0 3.1.6 3.1.5 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 3.0.6 3.0.5 3.0.4 trunk 0.1.0 0.10.0 0.10.1 0.10.2 0.11.0 0.11.1 0.2.0 0.3.0 0.3.1 0.4.0 0.5.0 0.6.0 All 127 releases
extendify / src / Agent / components / Rating.jsx

Rating.jsx in Extendify 3.0.5, at src/Agent/components/Rating.jsx

65 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { rateAnswer } from '@agent/api';
2 import { thumbDown, thumbUp } from '@agent/icons';
3 import { useEffect, useState } from '@wordpress/element';
4 import { __ } from '@wordpress/i18n';
5 import { Icon } from '@wordpress/icons';
6 import classnames from 'classnames';
7
8 export const Rating = ({ answerId }) => {
9 const [rating, setRating] = useState(undefined);
10
11 useEffect(() => {
12 if (!answerId) return;
13 if (rating === undefined) return;
14 rateAnswer({ answerId, rating });
15 }, [rating, answerId]);
16
17 return (
18 <div className="flex items-center justify-end">
19 <div className="flex items-center gap-px rounded-xl border border-gray-400 bg-gray-50 px-2 text-right">
20 <button
21 type="button"
22 aria-pressed={rating === 1}
23 aria-live="polite"
24 onClick={() => setRating((current) => (current === 1 ? 0 : 1))}
25 aria-label={
26 rating === 1
27 ? __('Remove rating', 'extendify-local')
28 : __('Rate that this answer was helpful', 'extendify-local')
29 }
30 className={classnames(
31 'm-0 h-6 border-0 bg-transparent p-0 hover:text-design-main',
32 {
33 'text-design-main': rating === 1,
34 'text-gray-600': rating !== 1,
35 },
36 )}
37 >
38 <Icon className="fill-current" icon={thumbUp} />
39 </button>
40
41 <button
42 type="button"
43 aria-pressed={rating === -1}
44 aria-live="polite"
45 onClick={() => setRating((current) => (current === -1 ? 0 : -1))}
46 aria-label={
47 rating === -1
48 ? __('Remove rating', 'extendify-local')
49 : __('Rate that this answer was not helpful', 'extendify-local')
50 }
51 className={classnames(
52 'm-0 h-6 border-0 bg-transparent p-0 hover:text-design-main',
53 {
54 'text-design-main': rating === -1,
55 'text-gray-600': rating !== -1,
56 },
57 )}
58 >
59 <Icon className="fill-current" icon={thumbDown} />
60 </button>
61 </div>
62 </div>
63 );
64 };
65