bd-geo-info
Version:
A comprehensive Bangladesh geographical data package with hierarchical selection and address form components
77 lines (76 loc) • 4.15 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = UpazilaSelect;
const react_1 = __importStar(require("react"));
const utils_1 = require("../utils");
function UpazilaSelect({ district, value, onChange, language = 'en', className = '', placeholder = 'Select Upazila', customLabel, customError, theme, errorClassName = '', labelClassName = '', containerClassName = '', }) {
const [upazilas, setUpazilas] = (0, react_1.useState)([]);
(0, react_1.useEffect)(() => {
const loadUpazilas = async () => {
if (district) {
const upazilaData = await (0, utils_1.getUpazilas)(district.id);
setUpazilas(upazilaData);
}
else {
setUpazilas([]);
}
};
loadUpazilas();
}, [district]);
return (react_1.default.createElement("div", { className: `${containerClassName} relative flex flex-col gap-2`, style: {
width: '100%',
transition: 'all 0.3s ease-in-out'
} },
customLabel && (react_1.default.createElement("label", { className: `${labelClassName} text-sm font-medium text-gray-700 mb-1`, style: {
display: 'block',
transition: 'color 0.3s ease'
} }, customLabel)),
react_1.default.createElement("div", { className: "relative w-full" },
react_1.default.createElement("select", { value: (value === null || value === void 0 ? void 0 : value.id) || '', onChange: (e) => {
const upazila = upazilas.find((u) => u.id === e.target.value);
if (upazila) {
onChange === null || onChange === void 0 ? void 0 : onChange(upazila);
}
}, className: `${className} w-full px-4 py-2.5 text-gray-900 bg-white border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent hover:border-blue-500 transition-all duration-300 ease-in-out appearance-none cursor-pointer disabled:bg-gray-100 disabled:cursor-not-allowed`, disabled: !district, style: {
minHeight: '2.75rem',
boxShadow: '0 1px 2px rgba(0, 0, 0, 0.05)',
} },
react_1.default.createElement("option", { value: "", className: "text-gray-500" }, placeholder),
upazilas.map((upazila) => (react_1.default.createElement("option", { key: upazila.id, value: upazila.id, className: "py-2 text-gray-900" }, language === 'bn' ? upazila.bn_name : upazila.name))))),
customError && (react_1.default.createElement("div", { className: `${errorClassName} text-sm text-red-600 mt-1`, style: {
animation: 'fadeIn 0.3s ease-in-out'
} }, customError))));
}