PluginProbe
Discount Rules for WooCommerce – Disco | Dynamic Pricing, Conditions, Bulk, Bundle, BOGO / 1.4.19
Discount Rules for WooCommerce – Disco | Dynamic Pricing, Conditions, Bulk, Bundle, BOGO v1.4.19
1.4.19 1.4.18 1.4.17 1.4.16 1.4.15 1.4.14 1.4.13 1.4.12 1.4.11 1.4.10 1.4.9 1.4.8 1.4.7 1.4.6 1.4.5 1.4.4 1.4.3 1.4.2 1.4.1 1.4.0 1.3.54 1.3.53 1.3.52 1.3.51 1.3.50 All 182 releases
disco / backend / views / components / Main / components / MultiSelect.jsx

MultiSelect.jsx in Discount Rules for WooCommerce – Disco | Dynamic Pricing, Conditions, Bulk, Bundle, BOGO 1.4.19, at backend/views/components/Main/components/MultiSelect.jsx

102 lines 3.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { Listbox, Transition } from '@headlessui/react';
2 import { ChevronUpDownIcon, XMarkIcon } from '@heroicons/react/24/outline';
3 import { __ } from '@wordpress/i18n';
4 import { Fragment, useEffect, useState } from 'react';
5
6 const MultiSelect = ({
7 placeholder = __('Select', 'disco'),
8 items,
9 selected = [],
10 onChange = () => {},
11 }) => {
12 const [selectValue, setSelectedValue] = useState(selected);
13
14 const handleChange = (selected) => {
15 setSelectedValue(selected);
16 };
17
18 const handleRemoveItem = (value) => {
19 setSelectedValue((prevState) =>
20 prevState.filter((item) => item !== value)
21 );
22 };
23
24 useEffect(() => {
25 onChange(selectValue);
26 }, [selectValue]);
27
28 return (
29 <Listbox value={selected} onChange={handleChange} multiple>
30 <div className="disco:relative disco-test">
31 <Listbox.Button className="disco:relative disco:cursor-pointer disco:min-w-[200px] disco:grow disco:w-full disco:rounded-md disco:border disco:text-base disco:border-gray-200 disco:py-2 disco:pl-3 disco:pr-10 disco:text-left disco:focus:outline-hidden">
32 <span className="disco:flex disco:flex-wrap disco:gap-1.5 disco:truncate">
33 {selected.length > 0
34 ? selected?.map((value) => (
35 <span
36 className="disco:flex disco:rounded-sm disco:items-center disco:text-[12px] disco:bg-gray-200 disco:px-1.5 disco:pe-0 disco:py-0.5"
37 key={value}
38 >
39 {items[value]}
40
41 <XMarkIcon
42 onClick={(e) => {
43 e.stopPropagation();
44 handleRemoveItem(value);
45 }}
46 className="disco:h-5 disco:w-5 disco:px-1"
47 />
48 </span>
49 ))
50 : placeholder}
51 </span>
52 <span className="disco:pointer-events-none disco:absolute disco:inset-y-0 disco:right-0 disco:flex disco:items-center disco:pr-2">
53 <ChevronUpDownIcon
54 className="disco:h-5 disco:w-5 disco:text-gray-400"
55 aria-hidden="true"
56 />
57 </span>
58 </Listbox.Button>
59 <Transition
60 as={Fragment}
61 leave="disco:transition disco:ease-in disco:duration-100"
62 leaveFrom="disco:opacity-100"
63 leaveTo="disco:opacity-0"
64 className="disco:absolute disco:z-50"
65 >
66 <Listbox.Options className="disco:absolute disco:cursor-pointer disco:mt-1.5 disco:max-h-60 disco:w-full disco:overflow-auto disco:rounded-md disco:bg-white disco:text-base disco:shadow-lg disco:ring-1 disco:ring-black/5 disco:focus:outline-hidden disco:sm:text-sm disco:z-41! ">
67 {items &&
68 Object.keys(items).map((item) => (
69 <Listbox.Option
70 key={item}
71 className={({ active }) =>
72 `disco:relative disco:py-1 disco:pl-4 disco:mb-0 ${
73 active
74 ? 'disco:bg-green-100'
75 : 'disco:text-gray-900'
76 }`
77 }
78 value={item}
79 >
80 {({ selected }) => (
81 <>
82 <span
83 className={`disco:block disco:truncate ${
84 selected
85 ? 'disco:font-medium'
86 : 'disco:font-normal'
87 }`}
88 >
89 {items[item]}
90 </span>
91 </>
92 )}
93 </Listbox.Option>
94 ))}
95 </Listbox.Options>
96 </Transition>
97 </div>
98 </Listbox>
99 );
100 };
101 export default MultiSelect;
102