sprint-asia-custom-component 0.1.155 → 0.1.157

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/package.json CHANGED
@@ -1,19 +1,22 @@
1
1
  {
2
2
  "name": "sprint-asia-custom-component",
3
3
  "main": "dist/index.js",
4
- "version": "0.1.155",
4
+ "version": "0.1.157",
5
5
  "private": false,
6
6
  "dependencies": {
7
7
  "@headlessui/react": "^1.7.18",
8
8
  "@testing-library/jest-dom": "^5.17.0",
9
9
  "@testing-library/react": "^13.4.0",
10
10
  "@testing-library/user-event": "^13.5.0",
11
+ "country-codes-list": "^2.0.0",
11
12
  "file-saver": "^2.0.5",
13
+ "flag-icon-css": "^4.1.7",
12
14
  "react": "^18.2.0",
13
15
  "react-datepicker": "^6.1.0",
14
16
  "react-dom": "^18.2.0",
15
17
  "react-dropzone": "^14.2.3",
16
18
  "react-icons": "^4.12.0",
19
+ "react-phone-input-2": "^2.15.1",
17
20
  "react-quill": "^2.0.0",
18
21
  "react-router-dom": "^6.22.1",
19
22
  "react-scripts": "5.0.1",
@@ -0,0 +1,173 @@
1
+ import React, { useState, useEffect, useRef } from "react";
2
+ import { PiCaretDown, PiCaretUp, PiInfo } from "react-icons/pi";
3
+ import { customList } from "country-codes-list";
4
+
5
+ const DropdownPhone = ({
6
+ dropdownCountry = { option: "+62", value: "id", label: "Indonesia" },
7
+ setDropdownCountry,
8
+ title = "",
9
+ isRequired = true,
10
+ value = "",
11
+ onChangeInput,
12
+ footer = null,
13
+ mode = "default",
14
+ placeholder = "",
15
+ }) => {
16
+ const [isOpen, setIsOpen] = useState(false);
17
+ const wrapperRef = useRef(null);
18
+ const [wrapperWidth, setWrapperWidth] = useState(0);
19
+ const [options, setOptions] = useState([]);
20
+
21
+ useEffect(() => {
22
+ const list = Object.entries(
23
+ customList("countryCode", "{countryNameEn} +{countryCallingCode}")
24
+ ).map(([code, label]) => {
25
+ const [countryName, callingCode] = label.split(" +");
26
+ return {
27
+ option: `+${callingCode}`,
28
+ value: code.toLowerCase(),
29
+ label: countryName,
30
+ };
31
+ });
32
+
33
+ const sortedList = list.sort((a, b) => a.label.localeCompare(b.label));
34
+
35
+ const indonesiaExists = sortedList.some(
36
+ (item) => item.value === "id" && item.option === "+62"
37
+ );
38
+ if (!indonesiaExists) {
39
+ sortedList.push({
40
+ option: "+62",
41
+ value: "id",
42
+ label: "Indonesia",
43
+ });
44
+ }
45
+
46
+ setOptions(sortedList);
47
+ }, []);
48
+
49
+ useEffect(() => {
50
+ if (wrapperRef.current) {
51
+ setWrapperWidth(wrapperRef.current.offsetWidth);
52
+ }
53
+ }, [wrapperRef.current, value]);
54
+
55
+ const handleClickOption = (data) => {
56
+ setIsOpen(false);
57
+ setDropdownCountry(data);
58
+ };
59
+
60
+ return (
61
+ <div className="w-full">
62
+ {title && (
63
+ <div className="flex mb-1">
64
+ <p className="text-sm font-normal text-black">{title}</p>
65
+ {isRequired && <p className="text-sm font-normal text-danger500 ml-1">*</p>}
66
+ </div>
67
+ )}
68
+
69
+ <div ref={wrapperRef} className="relative w-full">
70
+ <div
71
+ className={`
72
+ flex items-center rounded-md overflow-hidden w-full pr-3
73
+ ${mode === "danger"
74
+ ? "border border-danger500 bg-danger50"
75
+ : "border border-neutral50 bg-neutral20"}
76
+ `}
77
+ >
78
+ <div
79
+ className="flex items-center px-3 py-2 cursor-pointer border-r border-neutral50 mr-3"
80
+ onClick={() => setIsOpen(!isOpen)}
81
+ >
82
+ <img
83
+ src={`https://flagcdn.com/w40/${dropdownCountry.value}.png`}
84
+ alt={dropdownCountry.label}
85
+ className="w-4 h-4 object-cover rounded-full"
86
+ />
87
+ <p className="text-sm font-bold text-neutral300 ml-3 mr-2">
88
+ {dropdownCountry.option}
89
+ </p>
90
+ {isOpen ? <PiCaretUp /> : <PiCaretDown />}
91
+ </div>
92
+
93
+ <input
94
+ type="number"
95
+ value={value}
96
+ onChange={onChangeInput}
97
+ className={`
98
+ flex-1 w-full py-2.5 text-sm text-black focus:outline-none
99
+ placeholder:text-neutral300
100
+ ${mode === "danger" ? "bg-danger50 text-danger500" : "bg-neutral20"}
101
+ `}
102
+ placeholder={placeholder}
103
+ />
104
+ </div>
105
+
106
+ {isOpen && (
107
+ <div
108
+ className="absolute top-full mt-1 z-10 rounded-md shadow-md bg-neutral20 ring-1 ring-black ring-opacity-5 overflow-y-auto max-h-64 no-scrollbar"
109
+ style={{ width: wrapperWidth }}
110
+ >
111
+ <div className="py-2 bg-white">
112
+ <div className="bg-neutral20 rounded-lg px-4 py-2.5 my-1 mx-2 cursor-default">
113
+ <div className="flex items-center gap-2">
114
+ <img
115
+ src={`https://flagcdn.com/w40/${dropdownCountry.value}.png`}
116
+ alt={dropdownCountry.label}
117
+ className="w-5 h-5 object-cover rounded-full"
118
+ />
119
+ <p className="text-sm text-black">
120
+ {
121
+ dropdownCountry.label ||
122
+ options.find((opt) => opt.value === dropdownCountry.value && opt.option === dropdownCountry.option)?.label
123
+ }
124
+ </p>
125
+ <p className="text-sm text-black">{dropdownCountry.option}</p>
126
+ </div>
127
+ </div>
128
+
129
+ {options
130
+ .filter(
131
+ (opt) =>
132
+ opt.value !== dropdownCountry.value ||
133
+ opt.option !== dropdownCountry.option
134
+ )
135
+ .map((option, index) => (
136
+ <div
137
+ key={index}
138
+ className="bg-white rounded-lg px-4 py-2.5 my-1 mx-2 cursor-pointer transition-all hover:bg-neutral20"
139
+ onClick={() => handleClickOption(option)}
140
+ >
141
+ <div className="flex items-center gap-2">
142
+ <img
143
+ src={`https://flagcdn.com/w40/${option.value}.png`}
144
+ alt={option.label}
145
+ className="w-5 h-5 object-cover rounded-full"
146
+ />
147
+ <p className="text-sm text-black">{option.label}</p>
148
+ <p className="text-sm text-black">{option.option}</p>
149
+ </div>
150
+ </div>
151
+ ))}
152
+ </div>
153
+ </div>
154
+ )}
155
+ </div>
156
+
157
+ {footer && (
158
+ <div className="mt-1">
159
+ {mode === "danger" ? (
160
+ <div className="flex items-center">
161
+ <PiInfo size={16} className="text-danger500" />
162
+ <p className="text-danger500 text-xs ml-1">{footer}</p>
163
+ </div>
164
+ ) : (
165
+ <p className="text-black text-xs">{footer}</p>
166
+ )}
167
+ </div>
168
+ )}
169
+ </div>
170
+ );
171
+ };
172
+
173
+ export default DropdownPhone;
package/src/index.js CHANGED
@@ -84,6 +84,7 @@ import CellModelSix from "./components/table/listTable/cellmodesix";
84
84
  import CellModelSeven from "./components/table/listTable/cellmodelseven";
85
85
  import DetailDivision from "./components/table/listTable/report/detaildivision";
86
86
  import SearchDropdown from "./components/searchdropdown";
87
+ import DropdownPhone from "./components/dropdownphone";
87
88
  import FilterDropdown from "./components/filter/filterDropdown";
88
89
  import Footer from "./components/footer";
89
90
  import Header from "./components/header";
@@ -104,6 +105,7 @@ export {
104
105
  CellModelSeven,
105
106
  DetailDivision,
106
107
  SearchDropdown,
108
+ DropdownPhone,
107
109
  FilterDropdown,
108
110
  HeaderTable,
109
111
  TextInput,
@@ -44,6 +44,7 @@ import ModalBilling from "../components/modal/modalBilling";
44
44
  import ModalDeclineBilling from "../components/modal/modalDeclineBilling";
45
45
  import TextEditor from "../components/texteditor";
46
46
  import SearchDropdown from "../components/searchdropdown";
47
+ import DropdownPhone from "../components/dropdownphone";
47
48
  import LimitList from "../components/table/listTable/limit";
48
49
  import ModalLimit from "../components/modal/modalLimit";
49
50
  import VerticalStepBar from "../components/verticalstepbar";
@@ -836,6 +837,12 @@ const Templates = () => {
836
837
  value: "dfdsf",
837
838
  });
838
839
 
840
+ const [dropdownCountry, setDropdownCountry] = useState({
841
+ option: "+62",
842
+ value: "id",
843
+ label: "Indonesia"
844
+ });
845
+
839
846
  const onHandleEnter = () => {
840
847
  console.log(searchFilter, filterDropdown);
841
848
  };
@@ -863,9 +870,9 @@ const Templates = () => {
863
870
  titleRightButton="Submit"
864
871
  isActiveLeftButton
865
872
  isActiveRightButton
866
- onClickLeftButton={() => {}}
867
- onClickRightButton={() => {}}
868
- additionalButton={<PrimaryButton title={"Additional"} onClick={() => {}} isActive={true} />}
873
+ onClickLeftButton={() => { }}
874
+ onClickRightButton={() => { }}
875
+ additionalButton={<PrimaryButton title={"Additional"} onClick={() => { }} isActive={true} />}
869
876
  />
870
877
  </div>
871
878
 
@@ -1104,13 +1111,13 @@ const Templates = () => {
1104
1111
  <Description
1105
1112
  title="Sample Title"
1106
1113
  value={"This is a sample description.\n HHEHEEH \n LOh"}
1107
- // image="https://static.promediateknologi.id/crop/0x0:0x0/0x0/webp/photo/jawapos/2022/09/one-piece-red.jpeg"
1114
+ // image="https://static.promediateknologi.id/crop/0x0:0x0/0x0/webp/photo/jawapos/2022/09/one-piece-red.jpeg"
1108
1115
  />
1109
1116
  <Description
1110
1117
  title="Sample Title"
1111
1118
  value={"This is a sample description.\n HHEHEEH \n LOh"}
1112
1119
  icon={<PiCalendarBlank size={20} />}
1113
- // image="https://static.promediateknologi.id/crop/0x0:0x0/0x0/webp/photo/jawapos/2022/09/one-piece-red.jpeg"
1120
+ // image="https://static.promediateknologi.id/crop/0x0:0x0/0x0/webp/photo/jawapos/2022/09/one-piece-red.jpeg"
1114
1121
  />
1115
1122
 
1116
1123
  <div className="m-9"></div>
@@ -1392,6 +1399,18 @@ const Templates = () => {
1392
1399
  onEnterPress={onHandleEnter}
1393
1400
  />
1394
1401
 
1402
+ <div className="m-9"></div>
1403
+ <DropdownPhone
1404
+ title="PIC Phone Number"
1405
+ placeholder="Input Phone Number"
1406
+ dropdownCountry={dropdownCountry}
1407
+ setDropdownCountry={setDropdownCountry}
1408
+ value={inputValue}
1409
+ onChange={setInputValue}
1410
+ footer="Error message here"
1411
+ mode="danger"
1412
+ />
1413
+
1395
1414
  <div className="m-9"></div>
1396
1415
  <p className="text-black font-bold text-2xl text-center py-2">Stepper</p>
1397
1416
  {scenarios.map((scenario, index) => (