sprint-asia-custom-component 0.1.136 → 0.1.137
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +90 -0
- package/package.json +1 -1
- package/src/components/filter/filterCheckboxDropdown/index.js +109 -0
- package/src/index.js +2 -0
- package/src/templates/index.js +23 -0
package/dist/index.js
CHANGED
|
@@ -26797,6 +26797,95 @@
|
|
|
26797
26797
|
}, option))))));
|
|
26798
26798
|
};
|
|
26799
26799
|
|
|
26800
|
+
const FilterCheckboxDropdown = ({
|
|
26801
|
+
options = [{
|
|
26802
|
+
option: "Option 1",
|
|
26803
|
+
value: "value 1"
|
|
26804
|
+
}, {
|
|
26805
|
+
option: "Option 2",
|
|
26806
|
+
value: "value 2"
|
|
26807
|
+
}, {
|
|
26808
|
+
option: "Option 3",
|
|
26809
|
+
value: "value 3"
|
|
26810
|
+
}],
|
|
26811
|
+
currentValue = [],
|
|
26812
|
+
buttonText = "Filter",
|
|
26813
|
+
onSelect
|
|
26814
|
+
}) => {
|
|
26815
|
+
const [isOpen, setIsOpen] = React.useState(false);
|
|
26816
|
+
const [selectedOptions, setSelectedOptions] = React.useState([]);
|
|
26817
|
+
const dropdownRef = React.useRef(null);
|
|
26818
|
+
|
|
26819
|
+
// Inisialisasi selectedOptions dengan currentValue saat pertama kali render
|
|
26820
|
+
React.useEffect(() => {
|
|
26821
|
+
setSelectedOptions(currentValue);
|
|
26822
|
+
}, [currentValue]);
|
|
26823
|
+
React.useEffect(() => {
|
|
26824
|
+
const handleOutsideClick = event => {
|
|
26825
|
+
if (dropdownRef.current && !dropdownRef.current.contains(event.target)) {
|
|
26826
|
+
setIsOpen(false);
|
|
26827
|
+
}
|
|
26828
|
+
};
|
|
26829
|
+
if (isOpen) {
|
|
26830
|
+
document.addEventListener('mousedown', handleOutsideClick);
|
|
26831
|
+
}
|
|
26832
|
+
return () => {
|
|
26833
|
+
document.removeEventListener('mousedown', handleOutsideClick);
|
|
26834
|
+
};
|
|
26835
|
+
}, [isOpen]);
|
|
26836
|
+
const handleToggleFilterCheckboxDropdown = () => {
|
|
26837
|
+
setIsOpen(!isOpen);
|
|
26838
|
+
};
|
|
26839
|
+
const handleOptionClick = optionValue => {
|
|
26840
|
+
const updatedOptions = selectedOptions.some(option => option.value === optionValue) ? selectedOptions.filter(selected => selected.value !== optionValue) : [...selectedOptions, options.find(option => option.value === optionValue)];
|
|
26841
|
+
setSelectedOptions(updatedOptions);
|
|
26842
|
+
|
|
26843
|
+
// Menampilkan selectedOptions setelah setiap klik
|
|
26844
|
+
console.log('Current selected options:', updatedOptions);
|
|
26845
|
+
if (onSelect) {
|
|
26846
|
+
onSelect(updatedOptions);
|
|
26847
|
+
}
|
|
26848
|
+
};
|
|
26849
|
+
return /*#__PURE__*/React__default["default"].createElement("div", {
|
|
26850
|
+
className: "relative inline-block text-left",
|
|
26851
|
+
ref: dropdownRef
|
|
26852
|
+
}, /*#__PURE__*/React__default["default"].createElement("div", null, /*#__PURE__*/React__default["default"].createElement("span", {
|
|
26853
|
+
className: "rounded-md shadow-sm"
|
|
26854
|
+
}, /*#__PURE__*/React__default["default"].createElement("button", {
|
|
26855
|
+
type: "button",
|
|
26856
|
+
className: "flex items-center w-60 py-2.5 text-left px-4 bg-neutral20 border-neutral50 font-normal text-sm text-neutral300 rounded-md border focus:outline-none",
|
|
26857
|
+
onClick: handleToggleFilterCheckboxDropdown
|
|
26858
|
+
}, /*#__PURE__*/React__default["default"].createElement("span", {
|
|
26859
|
+
className: "flex-grow"
|
|
26860
|
+
}, buttonText), /*#__PURE__*/React__default["default"].createElement("span", {
|
|
26861
|
+
className: "ml-2"
|
|
26862
|
+
}, isOpen ? /*#__PURE__*/React__default["default"].createElement(PiCaretUp, {
|
|
26863
|
+
size: 16,
|
|
26864
|
+
className: "text-neutral300"
|
|
26865
|
+
}) : /*#__PURE__*/React__default["default"].createElement(PiCaretDown, {
|
|
26866
|
+
size: 16,
|
|
26867
|
+
className: "text-neutral300"
|
|
26868
|
+
}))))), isOpen && /*#__PURE__*/React__default["default"].createElement("div", {
|
|
26869
|
+
className: "z-10 origin-top-right absolute left-0 mt-2 w-60 rounded-md shadow-md bg-white ring-1 ring-black ring-opacity-5 focus:outline-none",
|
|
26870
|
+
role: "menu",
|
|
26871
|
+
"aria-orientation": "vertical",
|
|
26872
|
+
"aria-labelledby": "options-menu"
|
|
26873
|
+
}, /*#__PURE__*/React__default["default"].createElement("div", {
|
|
26874
|
+
className: "px-1 py-2"
|
|
26875
|
+
}, options.map(val => /*#__PURE__*/React__default["default"].createElement("div", {
|
|
26876
|
+
key: val.value,
|
|
26877
|
+
className: `hover:bg-neutral20 bg-white py-2.5 px-4 my-0.5 rounded-md flex items-center cursor-pointer ${selectedOptions.some(option => option.value === val.value) ? 'bg-primary500' : ''}`,
|
|
26878
|
+
onClick: () => handleOptionClick(val.value)
|
|
26879
|
+
}, /*#__PURE__*/React__default["default"].createElement("input", {
|
|
26880
|
+
type: "checkbox",
|
|
26881
|
+
className: "mr-2",
|
|
26882
|
+
checked: selectedOptions.some(option => option.value === val.value),
|
|
26883
|
+
onChange: () => handleOptionClick(val.value)
|
|
26884
|
+
}), /*#__PURE__*/React__default["default"].createElement("p", {
|
|
26885
|
+
className: `text-sm ${selectedOptions.some(option => option.value === val.value) ? 'text-primary500' : 'text-black'}`
|
|
26886
|
+
}, val.option))))));
|
|
26887
|
+
};
|
|
26888
|
+
|
|
26800
26889
|
const FilterText = ({
|
|
26801
26890
|
options = ["Type", "Company"],
|
|
26802
26891
|
onSelect
|
|
@@ -48775,6 +48864,7 @@
|
|
|
48775
48864
|
exports.EmptyData = EmptyData;
|
|
48776
48865
|
exports.ExportToExcel = ExportToExcel;
|
|
48777
48866
|
exports.FilterCheckbox = FilterCheckbox;
|
|
48867
|
+
exports.FilterCheckboxDropdown = FilterCheckboxDropdown;
|
|
48778
48868
|
exports.FilterDropdown = FilterDropdown;
|
|
48779
48869
|
exports.FilterText = FilterText;
|
|
48780
48870
|
exports.Footer = Footer;
|
package/package.json
CHANGED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import React, { useState, useEffect, useRef } from 'react';
|
|
2
|
+
import { PiCaretDown, PiCaretUp } from 'react-icons/pi';
|
|
3
|
+
|
|
4
|
+
const FilterCheckboxDropdown = ({
|
|
5
|
+
options = [
|
|
6
|
+
{ option: "Option 1", value: "value 1" },
|
|
7
|
+
{ option: "Option 2", value: "value 2" },
|
|
8
|
+
{ option: "Option 3", value: "value 3" },
|
|
9
|
+
],
|
|
10
|
+
currentValue = [],
|
|
11
|
+
buttonText = "Filter",
|
|
12
|
+
onSelect
|
|
13
|
+
}) => {
|
|
14
|
+
const [isOpen, setIsOpen] = useState(false);
|
|
15
|
+
const [selectedOptions, setSelectedOptions] = useState([]);
|
|
16
|
+
const dropdownRef = useRef(null);
|
|
17
|
+
|
|
18
|
+
// Inisialisasi selectedOptions dengan currentValue saat pertama kali render
|
|
19
|
+
useEffect(() => {
|
|
20
|
+
setSelectedOptions(currentValue);
|
|
21
|
+
}, [currentValue]);
|
|
22
|
+
|
|
23
|
+
useEffect(() => {
|
|
24
|
+
const handleOutsideClick = (event) => {
|
|
25
|
+
if (dropdownRef.current && !dropdownRef.current.contains(event.target)) {
|
|
26
|
+
setIsOpen(false);
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
if (isOpen) {
|
|
31
|
+
document.addEventListener('mousedown', handleOutsideClick);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return () => {
|
|
35
|
+
document.removeEventListener('mousedown', handleOutsideClick);
|
|
36
|
+
};
|
|
37
|
+
}, [isOpen]);
|
|
38
|
+
|
|
39
|
+
const handleToggleFilterCheckboxDropdown = () => {
|
|
40
|
+
setIsOpen(!isOpen);
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
const handleOptionClick = (optionValue) => {
|
|
44
|
+
const updatedOptions = selectedOptions.some(option => option.value === optionValue)
|
|
45
|
+
? selectedOptions.filter((selected) => selected.value !== optionValue)
|
|
46
|
+
: [...selectedOptions, options.find(option => option.value === optionValue)];
|
|
47
|
+
|
|
48
|
+
setSelectedOptions(updatedOptions);
|
|
49
|
+
|
|
50
|
+
// Menampilkan selectedOptions setelah setiap klik
|
|
51
|
+
console.log('Current selected options:', updatedOptions);
|
|
52
|
+
|
|
53
|
+
if (onSelect) {
|
|
54
|
+
onSelect(updatedOptions);
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
return (
|
|
59
|
+
<div className='relative inline-block text-left' ref={dropdownRef}>
|
|
60
|
+
<div>
|
|
61
|
+
<span className='rounded-md shadow-sm'>
|
|
62
|
+
<button
|
|
63
|
+
type='button'
|
|
64
|
+
className="flex items-center w-60 py-2.5 text-left px-4 bg-neutral20 border-neutral50 font-normal text-sm text-neutral300 rounded-md border focus:outline-none"
|
|
65
|
+
onClick={handleToggleFilterCheckboxDropdown}
|
|
66
|
+
>
|
|
67
|
+
<span className='flex-grow'>{buttonText}</span>
|
|
68
|
+
<span className='ml-2'>
|
|
69
|
+
{isOpen ? <PiCaretUp size={16} className='text-neutral300' /> : <PiCaretDown size={16} className='text-neutral300' />}
|
|
70
|
+
</span>
|
|
71
|
+
</button>
|
|
72
|
+
</span>
|
|
73
|
+
</div>
|
|
74
|
+
|
|
75
|
+
{isOpen && (
|
|
76
|
+
<div
|
|
77
|
+
className='z-10 origin-top-right absolute left-0 mt-2 w-60 rounded-md shadow-md bg-white ring-1 ring-black ring-opacity-5 focus:outline-none'
|
|
78
|
+
role='menu'
|
|
79
|
+
aria-orientation='vertical'
|
|
80
|
+
aria-labelledby='options-menu'
|
|
81
|
+
>
|
|
82
|
+
<div className='px-1 py-2'>
|
|
83
|
+
{options.map((val) => (
|
|
84
|
+
<div
|
|
85
|
+
key={val.value}
|
|
86
|
+
className={`hover:bg-neutral20 bg-white py-2.5 px-4 my-0.5 rounded-md flex items-center cursor-pointer ${
|
|
87
|
+
selectedOptions.some(option => option.value === val.value) ? 'bg-primary500' : ''
|
|
88
|
+
}`}
|
|
89
|
+
onClick={() => handleOptionClick(val.value)}
|
|
90
|
+
>
|
|
91
|
+
<input
|
|
92
|
+
type='checkbox'
|
|
93
|
+
className='mr-2'
|
|
94
|
+
checked={selectedOptions.some(option => option.value === val.value)}
|
|
95
|
+
onChange={() => handleOptionClick(val.value)}
|
|
96
|
+
/>
|
|
97
|
+
<p className={`text-sm ${selectedOptions.some(option => option.value === val.value) ? 'text-primary500' : 'text-black'}`}>
|
|
98
|
+
{val.option}
|
|
99
|
+
</p>
|
|
100
|
+
</div>
|
|
101
|
+
))}
|
|
102
|
+
</div>
|
|
103
|
+
</div>
|
|
104
|
+
)}
|
|
105
|
+
</div>
|
|
106
|
+
);
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
export default FilterCheckboxDropdown;
|
package/src/index.js
CHANGED
|
@@ -48,6 +48,7 @@ import EmptyData from "./components/emptystate/table/emptydata";
|
|
|
48
48
|
import NotFound from "./components/emptystate/table/notfound";
|
|
49
49
|
import ExportToExcel from "./components/export/excel";
|
|
50
50
|
import FilterCheckbox from "./components/filter/filterCheckbox";
|
|
51
|
+
import FilterCheckboxDropdown from "./components/filter/filterCheckboxDropdown";
|
|
51
52
|
import FilterText from "./components/filter/filterText";
|
|
52
53
|
import Menu from "./components/menu";
|
|
53
54
|
import ModalLoading from "./components/modal/modalLoading";
|
|
@@ -123,6 +124,7 @@ export {
|
|
|
123
124
|
Menu,
|
|
124
125
|
FilterText,
|
|
125
126
|
FilterCheckbox,
|
|
127
|
+
FilterCheckboxDropdown,
|
|
126
128
|
ExportToExcel,
|
|
127
129
|
NotFound,
|
|
128
130
|
EmptyData,
|
package/src/templates/index.js
CHANGED
|
@@ -61,6 +61,7 @@ import CellModelSix from "../components/table/listTable/cellmodesix";
|
|
|
61
61
|
import CellModelSeven from "../components/table/listTable/cellmodelseven";
|
|
62
62
|
import CustomPhone from "../components/customphone";
|
|
63
63
|
import DescriptionFile from "../components/description/file";
|
|
64
|
+
import FilterCheckboxDropdown from "../components/filter/filterCheckboxDropdown";
|
|
64
65
|
|
|
65
66
|
const Templates = () => {
|
|
66
67
|
const [startDate, setStartDate] = useState(null);
|
|
@@ -828,6 +829,7 @@ const Templates = () => {
|
|
|
828
829
|
});
|
|
829
830
|
|
|
830
831
|
const [searchFilter, setSearchFilter] = useState();
|
|
832
|
+
const [valueSelectFilter, setValueSelectFilter] = useState([]);
|
|
831
833
|
const [filterDropdown, setFilterDropdown] = useState({
|
|
832
834
|
option: "duar",
|
|
833
835
|
value: "dfdsf",
|
|
@@ -1171,6 +1173,27 @@ const Templates = () => {
|
|
|
1171
1173
|
<div className="m-9"></div>
|
|
1172
1174
|
<FilterText options={["Option 1", "Option 2", "Option 3"]} onSelect={handleSelect} />
|
|
1173
1175
|
|
|
1176
|
+
<div className="m-9"></div>
|
|
1177
|
+
<FilterCheckboxDropdown
|
|
1178
|
+
options={[
|
|
1179
|
+
{
|
|
1180
|
+
option : "Option1",
|
|
1181
|
+
value : "value 1"
|
|
1182
|
+
},
|
|
1183
|
+
{
|
|
1184
|
+
option : "Option2",
|
|
1185
|
+
value : "value 2"
|
|
1186
|
+
},
|
|
1187
|
+
]}
|
|
1188
|
+
buttonText="Division"
|
|
1189
|
+
currentValue={valueSelectFilter}
|
|
1190
|
+
onSelect={setValueSelectFilter}
|
|
1191
|
+
/>
|
|
1192
|
+
|
|
1193
|
+
{
|
|
1194
|
+
console.log("ini value select", valueSelectFilter)
|
|
1195
|
+
}
|
|
1196
|
+
|
|
1174
1197
|
<div className="m-9"></div>
|
|
1175
1198
|
<FilterDropdown
|
|
1176
1199
|
options={[
|