1- import React , { useState } from 'react' ;
1+ import { useState } from 'react' ;
22
33// components
44import OverviewFooter from '../../../../../Shared/OverviewFooter' ;
@@ -25,6 +25,7 @@ import ToggleTab from "../../../../../Shared/Component/ToggleTab.jsx";
2525import ContentNavbar from "../../../../../Shared/Component/ContentNavbar.jsx" ;
2626import ComponentDescription from "../../../../../Shared/Component/ComponentDescription.jsx" ;
2727import ComponentWrapper from "../../../../../Shared/Component/ComponentWrapper.jsx" ;
28+ import NumberDropdown from './NumberDropDown.jsx' ;
2829
2930const TextInput = ( ) => {
3031 const sectionIds = textInputContents . map ( ( item ) => item . href . slice ( 1 ) ) ;
@@ -62,13 +63,23 @@ const TextInput = () => {
6263 const [ joinInputPreview , setJoinInputPreview ] = useState ( true ) ;
6364 const [ joinInputCode , setJoinInputCode ] = useState ( false ) ;
6465
66+ //international phone number
67+ const [ internationalNumberInputPreview , setInternationalNumberInputPreview ] = useState ( true ) ;
68+ const [ internationalNumberInputCode , setInternationalNumberInputCode ] = useState ( false ) ;
69+
6570 // actions
6671 const [ isEyeOpen , setIsEyeOpen ] = useState ( false ) ;
6772
6873 // price dropdown actions
6974 const [ priceDropdownOpen , setPriceDropdownOpen ] = useState ( false ) ;
7075 const [ selectedCurrencyType , setSelectedCurrencyType ] = useState ( 'USD' ) ;
7176
77+ const [ selectedCountry , setSelectedCountry ] = useState ( {
78+ name : "United States" ,
79+ code : "+1" ,
80+ flag : < span className = "me-2" > 🇺🇸</ span > ,
81+ } ) ;
82+
7283 const allCurrencyTypes = [ 'USD' , 'EUR' , 'BDT' ] ;
7384
7485 const handlePriceDropdownClick = ( currency ) => {
@@ -841,6 +852,141 @@ export default NewsletterSubscribeInput;
841852 ) }
842853 </ ComponentWrapper >
843854
855+ { /* international phone number input */ }
856+
857+ < div className = 'mt-8' >
858+ < ContentHeader text = { 'International number input' } id = { 'internation_number_input' } />
859+ </ div >
860+
861+ < ComponentDescription text = 'This is an international number input field, where users select the national phone number format and enter their number.' />
862+
863+ < ToggleTab preview = { internationalNumberInputPreview } setPreview = { setInternationalNumberInputPreview } code = { internationalNumberInputCode }
864+ setCode = { setInternationalNumberInputCode } />
865+
866+ < ComponentWrapper >
867+ { internationalNumberInputPreview && (
868+ < div className = 'p-8 mb-4 flex items-center flex-col gap-5 justify-center' >
869+ < div className = 'w-full 1024px:w-[80%] relative inline-flex' >
870+ < NumberDropdown
871+ selectedCountry = { selectedCountry }
872+ onSelect = { setSelectedCountry }
873+ />
874+ < input
875+ type = "text"
876+ name = "phone"
877+ placeholder = "Enter your phone number"
878+ className = "border border-gray-300 dark:border-[#58667c] px-4 py-2 rounded-e-lg w-full focus:outline-none dark:bg-[rgb(2,6,23)] text-black dark:text-[#8a9daf]"
879+ />
880+ </ div >
881+ </ div >
882+ ) }
883+
884+ { internationalNumberInputCode && (
885+ < Showcode
886+ code = '
887+ import { useState } from "react";
888+ const countries = [
889+ {
890+ name: "United States",
891+ code: "+1",
892+ flag: <span className="me-2">🇺🇸</span>,
893+ },
894+ {
895+ name: "Bangladesh",
896+ code: "+880",
897+ flag: <span className="me-2">🇧🇩</span>,
898+ },
899+ {
900+ name: "United Kingdom",
901+ code: "+44",
902+ flag: <span className="me-2">🇬🇧</span>,
903+ },
904+ {
905+ name: "Canada",
906+ code: "+1",
907+ flag: <span className="me-2">🇨🇦</span>,
908+ },
909+ // add other country numbers if your need.
910+ ];
911+ function PhoneDropdown({ selectedCountry, onSelect }) {
912+ const [isOpen, setIsOpen] = useState(false);
913+ const handleSelect = (country) => {
914+ onSelect(country);
915+ setIsOpen(false);
916+ };
917+ return (
918+ <div className="relative">
919+ <button
920+ type="button"
921+ className="flex items-center py-2.5 px-4 text-sm font-medium text-gray-900 border-y border-l border-gray-300 rounded-s-lg"
922+ onClick={() => setIsOpen(!isOpen)}
923+ >
924+ {selectedCountry.flag}
925+ {selectedCountry.code}
926+ <svg className="w-2.5 h-2.5 ms-2.5" fill="none" viewBox="0 0 10 6">
927+ <path
928+ d="M1 1l4 4 4-4"
929+ stroke="currentColor"
930+ strokeLinecap="round"
931+ strokeLinejoin="round"
932+ strokeWidth="2"
933+ />
934+ </svg>
935+ </button>
936+ {isOpen && (
937+ <div className="absolute z-10 mt-1 bg-white divide-y divide-gray-100 rounded-lg shadow-lg w-60 ">
938+ <ul className="py-2 text-sm text-gray-700 max-h-[400px] overflow-x-auto">
939+ {countries.map((country, index) => (
940+ <li key={index}>
941+ <button
942+ type="button"
943+ className="inline-flex w-full px-4 py-2 text-sm text-gray-700"
944+ onClick={() => handleSelect(country)}
945+ >
946+ <span className="inline-flex items-center">
947+ {country.flag}
948+ {country.name} ({country.code})
949+ </span>
950+ </button>
951+ </li>
952+ ))}
953+ </ul>
954+ </div>
955+ )}
956+ </div>
957+ );
958+ }
959+ const PhoneNumber = () => {
960+ const [selectedCountry, setSelectedCountry] = useState({
961+ name: "United States",
962+ code: "+1",
963+ flag: <span className="me-2">🇺🇸</span>,
964+ });
965+ const [phoneNumber, setPhoneNumber] = useState("");
966+ return (
967+ <div className="inline-flex">
968+ <PhoneDropdown
969+ selectedCountry={selectedCountry}
970+ onSelect={setSelectedCountry}
971+ />
972+ <input
973+ type="text"
974+ name="phone"
975+ placeholder="Enter your phone number"
976+ className="border border-gray-300 px-4 py-2 rounded-e-lg w-full focus:outline-none text-black"
977+ value={phoneNumber}
978+ onChange={(e) => setPhoneNumber(e.target.value)}
979+ />
980+ </div>
981+ );
982+ };
983+ export default PhoneNumber;
984+ '
985+ />
986+ ) }
987+ </ ComponentWrapper >
988+
989+
844990 < OverviewFooter
845991 backName = 'all components'
846992 backUrl = '/components/all-components'
0 commit comments