the-omelet-ui 0.1.9 → 1.0.0
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.cjs +221 -7
- package/dist/index.d.cts +59 -2
- package/dist/index.d.ts +59 -2
- package/dist/index.js +219 -8
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -55,13 +55,13 @@ var buttonStyles = classVarianceAuthority.cva(
|
|
|
55
55
|
variants: {
|
|
56
56
|
variant: {
|
|
57
57
|
solid: "",
|
|
58
|
-
outline: "border bg-transparent",
|
|
58
|
+
outline: "border bg-transparent border-[#C9D7E3]",
|
|
59
59
|
ghost: "bg-transparent"
|
|
60
60
|
},
|
|
61
61
|
size: {
|
|
62
|
-
sm: "h-
|
|
63
|
-
md: "h-
|
|
64
|
-
lg: "h-
|
|
62
|
+
sm: "h-8 px-2 py-3 text-sm",
|
|
63
|
+
md: "h-10 px-2 py-3 text-md",
|
|
64
|
+
lg: "h-12 px-2 py-4 text-xl"
|
|
65
65
|
},
|
|
66
66
|
color: {
|
|
67
67
|
// แผงสีพรีเซ็ต (เพิ่มได้ตามต้องการ)
|
|
@@ -85,8 +85,8 @@ var buttonStyles = classVarianceAuthority.cva(
|
|
|
85
85
|
{ variant: "solid", color: "yellow", class: "bg-yellow-500 text-black hover:bg-yellow-600" },
|
|
86
86
|
{ variant: "solid", color: "violet", class: "bg-violet-600 text-white hover:bg-violet-700" },
|
|
87
87
|
// OUTLINE
|
|
88
|
-
{ variant: "outline", color: "neutral", class: "border-
|
|
89
|
-
{ variant: "outline", color: "primary", class: "border-
|
|
88
|
+
{ variant: "outline", color: "neutral", class: "border-[#C9D7E3] text-neutral-900 hover:bg-neutral-50" },
|
|
89
|
+
{ variant: "outline", color: "primary", class: "border-[#C9D7E3] text-black hover:bg-black/[0.06]" },
|
|
90
90
|
{ variant: "outline", color: "red", class: "border-red-600 text-red-700 hover:bg-red-50" },
|
|
91
91
|
{ variant: "outline", color: "green", class: "border-green-600 text-green-700 hover:bg-green-50" },
|
|
92
92
|
{ variant: "outline", color: "blue", class: "border-blue-600 text-blue-700 hover:bg-blue-50" },
|
|
@@ -27115,7 +27115,9 @@ function SearchSelect({
|
|
|
27115
27115
|
searchButtonClassName,
|
|
27116
27116
|
checkedColor = "primary",
|
|
27117
27117
|
checkedClassName,
|
|
27118
|
-
renderTriggerValue
|
|
27118
|
+
renderTriggerValue,
|
|
27119
|
+
label,
|
|
27120
|
+
required
|
|
27119
27121
|
}) {
|
|
27120
27122
|
const [open, setOpen] = React29__namespace.useState(false);
|
|
27121
27123
|
const [q, setQ] = React29__namespace.useState("");
|
|
@@ -27164,6 +27166,7 @@ function SearchSelect({
|
|
|
27164
27166
|
return `\u0E40\u0E25\u0E37\u0E2D\u0E01 ${selectedItems.length} \u0E23\u0E32\u0E22\u0E01\u0E32\u0E23`;
|
|
27165
27167
|
}, [selectedItems, isMulti, triggerPlaceholder]);
|
|
27166
27168
|
return /* @__PURE__ */ jsxRuntime.jsxs(Root22, { open, onOpenChange: setOpen, children: [
|
|
27169
|
+
label && /* @__PURE__ */ jsxRuntime.jsx(LabelInput, { label, required }),
|
|
27167
27170
|
/* @__PURE__ */ jsxRuntime.jsx(Trigger, { asChild: true, children: trigger ?? // Trigger แบบ "ฟิลด์มีกรอบ + ลูกศร"
|
|
27168
27171
|
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
27169
27172
|
"button",
|
|
@@ -28141,14 +28144,225 @@ var CheckboxBase = React29__namespace.forwardRef(function CheckboxBase2({
|
|
|
28141
28144
|
});
|
|
28142
28145
|
CheckboxBase.displayName = "Checkbox";
|
|
28143
28146
|
var Checkbox = CheckboxBase;
|
|
28147
|
+
var toDistrict = (district, locale) => {
|
|
28148
|
+
if (locale === "en") {
|
|
28149
|
+
return {
|
|
28150
|
+
id: district.id,
|
|
28151
|
+
name: district.name_en,
|
|
28152
|
+
value: district.id,
|
|
28153
|
+
label: district.name_en
|
|
28154
|
+
};
|
|
28155
|
+
} else {
|
|
28156
|
+
return {
|
|
28157
|
+
id: district.id,
|
|
28158
|
+
name: district.name_th,
|
|
28159
|
+
value: district.id,
|
|
28160
|
+
label: district.name_th
|
|
28161
|
+
};
|
|
28162
|
+
}
|
|
28163
|
+
};
|
|
28164
|
+
var getDistricts = async (provinceId) => {
|
|
28165
|
+
const response = await fetch("https://raw.githubusercontent.com/kongvut/thai-province-data/refs/heads/master/api/latest/district.json");
|
|
28166
|
+
const data = await response.json();
|
|
28167
|
+
const districts = data.filter((district) => district.province_id === provinceId);
|
|
28168
|
+
return districts;
|
|
28169
|
+
};
|
|
28170
|
+
var DistrictDropdown = ({ locale = "th", searchPlaceholder = "Search District", placeholder = "Select District", label, searchButtonClassName = "bg-blue-500", onChange, value, required = false, provinceId }) => {
|
|
28171
|
+
const [districts, setDistricts] = React29.useState([]);
|
|
28172
|
+
const [currentDistrict, setCurrentDistrict] = React29.useState(null);
|
|
28173
|
+
React29.useEffect(() => {
|
|
28174
|
+
if (!provinceId) return;
|
|
28175
|
+
getDistricts(provinceId).then(setDistricts);
|
|
28176
|
+
}, [provinceId]);
|
|
28177
|
+
React29.useEffect(() => {
|
|
28178
|
+
if (value) {
|
|
28179
|
+
const district = districts.find((d) => {
|
|
28180
|
+
if (locale === "th") {
|
|
28181
|
+
return d.name_th === value;
|
|
28182
|
+
} else {
|
|
28183
|
+
return d.name_en === value;
|
|
28184
|
+
}
|
|
28185
|
+
});
|
|
28186
|
+
if (district) {
|
|
28187
|
+
setCurrentDistrict(district);
|
|
28188
|
+
}
|
|
28189
|
+
}
|
|
28190
|
+
}, [districts, value, locale]);
|
|
28191
|
+
const onSelect = React29.useCallback((id) => {
|
|
28192
|
+
const district = districts.find((d) => d.id === id);
|
|
28193
|
+
if (district) {
|
|
28194
|
+
setCurrentDistrict(district);
|
|
28195
|
+
onChange?.(district);
|
|
28196
|
+
}
|
|
28197
|
+
}, [districts]);
|
|
28198
|
+
return /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
28199
|
+
SearchSelect,
|
|
28200
|
+
{
|
|
28201
|
+
items: districts.map((district) => toDistrict(district, locale)),
|
|
28202
|
+
placeholder: searchPlaceholder,
|
|
28203
|
+
triggerPlaceholder: placeholder,
|
|
28204
|
+
label,
|
|
28205
|
+
selectionMode: "single",
|
|
28206
|
+
searchButtonClassName,
|
|
28207
|
+
onChange: (value2) => {
|
|
28208
|
+
if (typeof value2 === "string") {
|
|
28209
|
+
onSelect(value2);
|
|
28210
|
+
}
|
|
28211
|
+
},
|
|
28212
|
+
value: currentDistrict?.id,
|
|
28213
|
+
required
|
|
28214
|
+
}
|
|
28215
|
+
) });
|
|
28216
|
+
};
|
|
28217
|
+
var toProvince = (province, locale) => {
|
|
28218
|
+
if (locale === "en") {
|
|
28219
|
+
return {
|
|
28220
|
+
id: province.id,
|
|
28221
|
+
name: province.name_en,
|
|
28222
|
+
value: province.id,
|
|
28223
|
+
label: province.name_en
|
|
28224
|
+
};
|
|
28225
|
+
} else {
|
|
28226
|
+
return {
|
|
28227
|
+
id: province.id,
|
|
28228
|
+
name: province.name_th,
|
|
28229
|
+
value: province.id,
|
|
28230
|
+
label: province.name_th
|
|
28231
|
+
};
|
|
28232
|
+
}
|
|
28233
|
+
};
|
|
28234
|
+
var getProvinces = async () => {
|
|
28235
|
+
const response = await fetch("https://raw.githubusercontent.com/kongvut/thai-province-data/refs/heads/master/api/latest/province.json");
|
|
28236
|
+
const data = await response.json();
|
|
28237
|
+
return data;
|
|
28238
|
+
};
|
|
28239
|
+
var ProvinceDropdown = ({ locale = "th", searchPlaceholder = "Search Province", placeholder = "Select Province", label, searchButtonClassName = "bg-blue-500", onChange, value, required = false }) => {
|
|
28240
|
+
const [provinces, setProvinces] = React29.useState([]);
|
|
28241
|
+
const [currentProvince, setCurrentProvince] = React29.useState(null);
|
|
28242
|
+
React29.useEffect(() => {
|
|
28243
|
+
getProvinces().then(setProvinces);
|
|
28244
|
+
}, []);
|
|
28245
|
+
React29.useEffect(() => {
|
|
28246
|
+
if (value) {
|
|
28247
|
+
const province = provinces.find((p) => {
|
|
28248
|
+
if (locale === "th") {
|
|
28249
|
+
return p.name_th === value;
|
|
28250
|
+
} else {
|
|
28251
|
+
return p.name_en === value;
|
|
28252
|
+
}
|
|
28253
|
+
});
|
|
28254
|
+
if (province) {
|
|
28255
|
+
setCurrentProvince(province);
|
|
28256
|
+
}
|
|
28257
|
+
}
|
|
28258
|
+
}, [provinces, value, locale]);
|
|
28259
|
+
const onSelect = React29.useCallback((id) => {
|
|
28260
|
+
const province = provinces.find((p) => p.id === id);
|
|
28261
|
+
if (province) {
|
|
28262
|
+
setCurrentProvince(province);
|
|
28263
|
+
onChange?.(province);
|
|
28264
|
+
}
|
|
28265
|
+
}, [provinces]);
|
|
28266
|
+
return /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
28267
|
+
SearchSelect,
|
|
28268
|
+
{
|
|
28269
|
+
items: provinces.map((province) => toProvince(province, locale)),
|
|
28270
|
+
placeholder: searchPlaceholder,
|
|
28271
|
+
triggerPlaceholder: placeholder,
|
|
28272
|
+
label,
|
|
28273
|
+
selectionMode: "single",
|
|
28274
|
+
searchButtonClassName,
|
|
28275
|
+
onChange: (value2) => {
|
|
28276
|
+
if (typeof value2 === "string") {
|
|
28277
|
+
onSelect(value2);
|
|
28278
|
+
}
|
|
28279
|
+
},
|
|
28280
|
+
value: currentProvince?.id,
|
|
28281
|
+
required
|
|
28282
|
+
}
|
|
28283
|
+
) });
|
|
28284
|
+
};
|
|
28285
|
+
var toSubDistrict = (subDistrict, locale) => {
|
|
28286
|
+
if (locale === "en") {
|
|
28287
|
+
return {
|
|
28288
|
+
id: subDistrict.id,
|
|
28289
|
+
name: subDistrict.name_en,
|
|
28290
|
+
value: subDistrict.id,
|
|
28291
|
+
label: subDistrict.name_en
|
|
28292
|
+
};
|
|
28293
|
+
} else {
|
|
28294
|
+
return {
|
|
28295
|
+
id: subDistrict.id,
|
|
28296
|
+
name: subDistrict.name_th,
|
|
28297
|
+
value: subDistrict.id,
|
|
28298
|
+
label: subDistrict.name_th
|
|
28299
|
+
};
|
|
28300
|
+
}
|
|
28301
|
+
};
|
|
28302
|
+
var getSubDistricts = async (districtId) => {
|
|
28303
|
+
const response = await fetch("https://raw.githubusercontent.com/kongvut/thai-province-data/refs/heads/master/api/latest/sub_district.json");
|
|
28304
|
+
const data = await response.json();
|
|
28305
|
+
const subDistricts = data.filter((subDistrict) => subDistrict.district_id === districtId);
|
|
28306
|
+
return subDistricts;
|
|
28307
|
+
};
|
|
28308
|
+
var SubDistrictDropdown = ({ locale = "th", searchPlaceholder = "Search District", placeholder = "Select District", label, searchButtonClassName = "bg-blue-500", onChange, value, required = false, districtId }) => {
|
|
28309
|
+
const [districts, setDistricts] = React29.useState([]);
|
|
28310
|
+
const [currentDistrict, setCurrentDistrict] = React29.useState(null);
|
|
28311
|
+
React29.useEffect(() => {
|
|
28312
|
+
if (!districtId) return;
|
|
28313
|
+
getSubDistricts(districtId).then(setDistricts);
|
|
28314
|
+
}, [districtId]);
|
|
28315
|
+
React29.useEffect(() => {
|
|
28316
|
+
if (value) {
|
|
28317
|
+
const district = districts.find((d) => {
|
|
28318
|
+
if (locale === "th") {
|
|
28319
|
+
return d.name_th === value;
|
|
28320
|
+
} else {
|
|
28321
|
+
return d.name_en === value;
|
|
28322
|
+
}
|
|
28323
|
+
});
|
|
28324
|
+
if (district) {
|
|
28325
|
+
setCurrentDistrict(district);
|
|
28326
|
+
}
|
|
28327
|
+
}
|
|
28328
|
+
}, [districts, value, locale]);
|
|
28329
|
+
const onSelect = React29.useCallback((id) => {
|
|
28330
|
+
const district = districts.find((d) => d.id === id);
|
|
28331
|
+
if (district) {
|
|
28332
|
+
setCurrentDistrict(district);
|
|
28333
|
+
onChange?.(district);
|
|
28334
|
+
}
|
|
28335
|
+
}, [districts]);
|
|
28336
|
+
return /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
28337
|
+
SearchSelect,
|
|
28338
|
+
{
|
|
28339
|
+
items: districts.map((district) => toSubDistrict(district, locale)),
|
|
28340
|
+
placeholder: searchPlaceholder,
|
|
28341
|
+
triggerPlaceholder: placeholder,
|
|
28342
|
+
label,
|
|
28343
|
+
selectionMode: "single",
|
|
28344
|
+
searchButtonClassName,
|
|
28345
|
+
onChange: (value2) => {
|
|
28346
|
+
if (typeof value2 === "string") {
|
|
28347
|
+
onSelect(value2);
|
|
28348
|
+
}
|
|
28349
|
+
},
|
|
28350
|
+
value: currentDistrict?.id,
|
|
28351
|
+
required
|
|
28352
|
+
}
|
|
28353
|
+
) });
|
|
28354
|
+
};
|
|
28144
28355
|
|
|
28145
28356
|
exports.Avatar = Avatar;
|
|
28146
28357
|
exports.Button = Button;
|
|
28147
28358
|
exports.Checkbox = Checkbox;
|
|
28148
28359
|
exports.DatePickerInput = DatePickerInput;
|
|
28360
|
+
exports.DistrictDropdown = DistrictDropdown;
|
|
28149
28361
|
exports.LabelInput = LabelInput;
|
|
28150
28362
|
exports.Pagination = Pagination;
|
|
28363
|
+
exports.ProvinceDropdown = ProvinceDropdown;
|
|
28151
28364
|
exports.SearchSelect = SearchSelect;
|
|
28365
|
+
exports.SubDistrictDropdown = SubDistrictDropdown;
|
|
28152
28366
|
exports.TextInput = TextInput;
|
|
28153
28367
|
exports.Toggle = Toggle;
|
|
28154
28368
|
exports.UploadImage = UploadImage;
|
package/dist/index.d.cts
CHANGED
|
@@ -144,8 +144,10 @@ type SearchSelectProps = {
|
|
|
144
144
|
checkedClassName?: string;
|
|
145
145
|
/** สรุปค่าที่เลือกบน trigger (ถ้าไม่ส่ง: single=label, multi="เลือก n รายการ") */
|
|
146
146
|
renderTriggerValue?: (selectedIds: string[], selectedItems: BaseItem[]) => React.ReactNode;
|
|
147
|
+
label?: string;
|
|
148
|
+
required?: boolean;
|
|
147
149
|
};
|
|
148
|
-
declare function SearchSelect({ trigger, triggerPlaceholder, items, selectionMode, value, defaultValue, onChange, searchable, placeholder, searchButtonLabel, onQueryChange, onSearch, loading, emptyLabel, contentClassName, maxHeight, renderItem, buttonColor, searchButtonColor, searchButtonClassName, checkedColor, checkedClassName, renderTriggerValue, }: SearchSelectProps): react_jsx_runtime.JSX.Element;
|
|
150
|
+
declare function SearchSelect({ trigger, triggerPlaceholder, items, selectionMode, value, defaultValue, onChange, searchable, placeholder, searchButtonLabel, onQueryChange, onSearch, loading, emptyLabel, contentClassName, maxHeight, renderItem, buttonColor, searchButtonColor, searchButtonClassName, checkedColor, checkedClassName, renderTriggerValue, label, required }: SearchSelectProps): react_jsx_runtime.JSX.Element;
|
|
149
151
|
|
|
150
152
|
type LocaleKey = "th" | "en";
|
|
151
153
|
type DatePickerInputProps = {
|
|
@@ -247,4 +249,59 @@ type UICheckboxProps = {
|
|
|
247
249
|
/** Export: memo เพื่อลด re-render */
|
|
248
250
|
declare const Checkbox: React.ForwardRefExoticComponent<UICheckboxProps & React.RefAttributes<HTMLInputElement>>;
|
|
249
251
|
|
|
250
|
-
|
|
252
|
+
type District = {
|
|
253
|
+
id: string;
|
|
254
|
+
name_th: string;
|
|
255
|
+
name_en: string;
|
|
256
|
+
province_id: number;
|
|
257
|
+
};
|
|
258
|
+
type DistrictProps = {
|
|
259
|
+
locale?: "en" | "th";
|
|
260
|
+
searchPlaceholder?: string;
|
|
261
|
+
placeholder?: string;
|
|
262
|
+
label?: string;
|
|
263
|
+
searchButtonClassName?: string;
|
|
264
|
+
onChange?: (district: District) => void;
|
|
265
|
+
value?: string;
|
|
266
|
+
required?: boolean;
|
|
267
|
+
provinceId: number;
|
|
268
|
+
};
|
|
269
|
+
declare const DistrictDropdown: ({ locale, searchPlaceholder, placeholder, label, searchButtonClassName, onChange, value, required, provinceId }: DistrictProps) => react_jsx_runtime.JSX.Element;
|
|
270
|
+
|
|
271
|
+
type Province = {
|
|
272
|
+
id: string;
|
|
273
|
+
name_th: string;
|
|
274
|
+
name_en: string;
|
|
275
|
+
};
|
|
276
|
+
type ProvinceProps = {
|
|
277
|
+
locale?: "en" | "th";
|
|
278
|
+
searchPlaceholder?: string;
|
|
279
|
+
placeholder?: string;
|
|
280
|
+
label?: string;
|
|
281
|
+
searchButtonClassName?: string;
|
|
282
|
+
onChange?: (province: Province) => void;
|
|
283
|
+
value?: string;
|
|
284
|
+
required?: boolean;
|
|
285
|
+
};
|
|
286
|
+
declare const ProvinceDropdown: ({ locale, searchPlaceholder, placeholder, label, searchButtonClassName, onChange, value, required }: ProvinceProps) => react_jsx_runtime.JSX.Element;
|
|
287
|
+
|
|
288
|
+
type SubDistrict = {
|
|
289
|
+
id: string;
|
|
290
|
+
name_th: string;
|
|
291
|
+
name_en: string;
|
|
292
|
+
district_id: number;
|
|
293
|
+
};
|
|
294
|
+
type SubDistrictProps = {
|
|
295
|
+
locale?: "en" | "th";
|
|
296
|
+
searchPlaceholder?: string;
|
|
297
|
+
placeholder?: string;
|
|
298
|
+
label?: string;
|
|
299
|
+
searchButtonClassName?: string;
|
|
300
|
+
onChange?: (district: SubDistrict) => void;
|
|
301
|
+
value?: string;
|
|
302
|
+
required?: boolean;
|
|
303
|
+
districtId: number;
|
|
304
|
+
};
|
|
305
|
+
declare const SubDistrictDropdown: ({ locale, searchPlaceholder, placeholder, label, searchButtonClassName, onChange, value, required, districtId }: SubDistrictProps) => react_jsx_runtime.JSX.Element;
|
|
306
|
+
|
|
307
|
+
export { Avatar, type AvatarProps, Button, type ButtonProps, Checkbox, DatePickerInput, type DatePickerInputProps, type District, DistrictDropdown, type DistrictProps, LabelInput, Pagination, type PaginationProps, type Province, ProvinceDropdown, type ProvinceProps, SearchSelect, type SearchSelectProps, type SubDistrict, SubDistrictDropdown, type SubDistrictProps, TextInput, type TextInputProps, Toggle, type ToggleProps, type UICheckboxProps, UploadImage, type UploadImageProps };
|
package/dist/index.d.ts
CHANGED
|
@@ -144,8 +144,10 @@ type SearchSelectProps = {
|
|
|
144
144
|
checkedClassName?: string;
|
|
145
145
|
/** สรุปค่าที่เลือกบน trigger (ถ้าไม่ส่ง: single=label, multi="เลือก n รายการ") */
|
|
146
146
|
renderTriggerValue?: (selectedIds: string[], selectedItems: BaseItem[]) => React.ReactNode;
|
|
147
|
+
label?: string;
|
|
148
|
+
required?: boolean;
|
|
147
149
|
};
|
|
148
|
-
declare function SearchSelect({ trigger, triggerPlaceholder, items, selectionMode, value, defaultValue, onChange, searchable, placeholder, searchButtonLabel, onQueryChange, onSearch, loading, emptyLabel, contentClassName, maxHeight, renderItem, buttonColor, searchButtonColor, searchButtonClassName, checkedColor, checkedClassName, renderTriggerValue, }: SearchSelectProps): react_jsx_runtime.JSX.Element;
|
|
150
|
+
declare function SearchSelect({ trigger, triggerPlaceholder, items, selectionMode, value, defaultValue, onChange, searchable, placeholder, searchButtonLabel, onQueryChange, onSearch, loading, emptyLabel, contentClassName, maxHeight, renderItem, buttonColor, searchButtonColor, searchButtonClassName, checkedColor, checkedClassName, renderTriggerValue, label, required }: SearchSelectProps): react_jsx_runtime.JSX.Element;
|
|
149
151
|
|
|
150
152
|
type LocaleKey = "th" | "en";
|
|
151
153
|
type DatePickerInputProps = {
|
|
@@ -247,4 +249,59 @@ type UICheckboxProps = {
|
|
|
247
249
|
/** Export: memo เพื่อลด re-render */
|
|
248
250
|
declare const Checkbox: React.ForwardRefExoticComponent<UICheckboxProps & React.RefAttributes<HTMLInputElement>>;
|
|
249
251
|
|
|
250
|
-
|
|
252
|
+
type District = {
|
|
253
|
+
id: string;
|
|
254
|
+
name_th: string;
|
|
255
|
+
name_en: string;
|
|
256
|
+
province_id: number;
|
|
257
|
+
};
|
|
258
|
+
type DistrictProps = {
|
|
259
|
+
locale?: "en" | "th";
|
|
260
|
+
searchPlaceholder?: string;
|
|
261
|
+
placeholder?: string;
|
|
262
|
+
label?: string;
|
|
263
|
+
searchButtonClassName?: string;
|
|
264
|
+
onChange?: (district: District) => void;
|
|
265
|
+
value?: string;
|
|
266
|
+
required?: boolean;
|
|
267
|
+
provinceId: number;
|
|
268
|
+
};
|
|
269
|
+
declare const DistrictDropdown: ({ locale, searchPlaceholder, placeholder, label, searchButtonClassName, onChange, value, required, provinceId }: DistrictProps) => react_jsx_runtime.JSX.Element;
|
|
270
|
+
|
|
271
|
+
type Province = {
|
|
272
|
+
id: string;
|
|
273
|
+
name_th: string;
|
|
274
|
+
name_en: string;
|
|
275
|
+
};
|
|
276
|
+
type ProvinceProps = {
|
|
277
|
+
locale?: "en" | "th";
|
|
278
|
+
searchPlaceholder?: string;
|
|
279
|
+
placeholder?: string;
|
|
280
|
+
label?: string;
|
|
281
|
+
searchButtonClassName?: string;
|
|
282
|
+
onChange?: (province: Province) => void;
|
|
283
|
+
value?: string;
|
|
284
|
+
required?: boolean;
|
|
285
|
+
};
|
|
286
|
+
declare const ProvinceDropdown: ({ locale, searchPlaceholder, placeholder, label, searchButtonClassName, onChange, value, required }: ProvinceProps) => react_jsx_runtime.JSX.Element;
|
|
287
|
+
|
|
288
|
+
type SubDistrict = {
|
|
289
|
+
id: string;
|
|
290
|
+
name_th: string;
|
|
291
|
+
name_en: string;
|
|
292
|
+
district_id: number;
|
|
293
|
+
};
|
|
294
|
+
type SubDistrictProps = {
|
|
295
|
+
locale?: "en" | "th";
|
|
296
|
+
searchPlaceholder?: string;
|
|
297
|
+
placeholder?: string;
|
|
298
|
+
label?: string;
|
|
299
|
+
searchButtonClassName?: string;
|
|
300
|
+
onChange?: (district: SubDistrict) => void;
|
|
301
|
+
value?: string;
|
|
302
|
+
required?: boolean;
|
|
303
|
+
districtId: number;
|
|
304
|
+
};
|
|
305
|
+
declare const SubDistrictDropdown: ({ locale, searchPlaceholder, placeholder, label, searchButtonClassName, onChange, value, required, districtId }: SubDistrictProps) => react_jsx_runtime.JSX.Element;
|
|
306
|
+
|
|
307
|
+
export { Avatar, type AvatarProps, Button, type ButtonProps, Checkbox, DatePickerInput, type DatePickerInputProps, type District, DistrictDropdown, type DistrictProps, LabelInput, Pagination, type PaginationProps, type Province, ProvinceDropdown, type ProvinceProps, SearchSelect, type SearchSelectProps, type SubDistrict, SubDistrictDropdown, type SubDistrictProps, TextInput, type TextInputProps, Toggle, type ToggleProps, type UICheckboxProps, UploadImage, type UploadImageProps };
|
package/dist/index.js
CHANGED
|
@@ -34,13 +34,13 @@ var buttonStyles = cva(
|
|
|
34
34
|
variants: {
|
|
35
35
|
variant: {
|
|
36
36
|
solid: "",
|
|
37
|
-
outline: "border bg-transparent",
|
|
37
|
+
outline: "border bg-transparent border-[#C9D7E3]",
|
|
38
38
|
ghost: "bg-transparent"
|
|
39
39
|
},
|
|
40
40
|
size: {
|
|
41
|
-
sm: "h-
|
|
42
|
-
md: "h-
|
|
43
|
-
lg: "h-
|
|
41
|
+
sm: "h-8 px-2 py-3 text-sm",
|
|
42
|
+
md: "h-10 px-2 py-3 text-md",
|
|
43
|
+
lg: "h-12 px-2 py-4 text-xl"
|
|
44
44
|
},
|
|
45
45
|
color: {
|
|
46
46
|
// แผงสีพรีเซ็ต (เพิ่มได้ตามต้องการ)
|
|
@@ -64,8 +64,8 @@ var buttonStyles = cva(
|
|
|
64
64
|
{ variant: "solid", color: "yellow", class: "bg-yellow-500 text-black hover:bg-yellow-600" },
|
|
65
65
|
{ variant: "solid", color: "violet", class: "bg-violet-600 text-white hover:bg-violet-700" },
|
|
66
66
|
// OUTLINE
|
|
67
|
-
{ variant: "outline", color: "neutral", class: "border-
|
|
68
|
-
{ variant: "outline", color: "primary", class: "border-
|
|
67
|
+
{ variant: "outline", color: "neutral", class: "border-[#C9D7E3] text-neutral-900 hover:bg-neutral-50" },
|
|
68
|
+
{ variant: "outline", color: "primary", class: "border-[#C9D7E3] text-black hover:bg-black/[0.06]" },
|
|
69
69
|
{ variant: "outline", color: "red", class: "border-red-600 text-red-700 hover:bg-red-50" },
|
|
70
70
|
{ variant: "outline", color: "green", class: "border-green-600 text-green-700 hover:bg-green-50" },
|
|
71
71
|
{ variant: "outline", color: "blue", class: "border-blue-600 text-blue-700 hover:bg-blue-50" },
|
|
@@ -27094,7 +27094,9 @@ function SearchSelect({
|
|
|
27094
27094
|
searchButtonClassName,
|
|
27095
27095
|
checkedColor = "primary",
|
|
27096
27096
|
checkedClassName,
|
|
27097
|
-
renderTriggerValue
|
|
27097
|
+
renderTriggerValue,
|
|
27098
|
+
label,
|
|
27099
|
+
required
|
|
27098
27100
|
}) {
|
|
27099
27101
|
const [open, setOpen] = React29.useState(false);
|
|
27100
27102
|
const [q, setQ] = React29.useState("");
|
|
@@ -27143,6 +27145,7 @@ function SearchSelect({
|
|
|
27143
27145
|
return `\u0E40\u0E25\u0E37\u0E2D\u0E01 ${selectedItems.length} \u0E23\u0E32\u0E22\u0E01\u0E32\u0E23`;
|
|
27144
27146
|
}, [selectedItems, isMulti, triggerPlaceholder]);
|
|
27145
27147
|
return /* @__PURE__ */ jsxs(Root22, { open, onOpenChange: setOpen, children: [
|
|
27148
|
+
label && /* @__PURE__ */ jsx(LabelInput, { label, required }),
|
|
27146
27149
|
/* @__PURE__ */ jsx(Trigger, { asChild: true, children: trigger ?? // Trigger แบบ "ฟิลด์มีกรอบ + ลูกศร"
|
|
27147
27150
|
/* @__PURE__ */ jsxs(
|
|
27148
27151
|
"button",
|
|
@@ -28120,5 +28123,213 @@ var CheckboxBase = React29.forwardRef(function CheckboxBase2({
|
|
|
28120
28123
|
});
|
|
28121
28124
|
CheckboxBase.displayName = "Checkbox";
|
|
28122
28125
|
var Checkbox = CheckboxBase;
|
|
28126
|
+
var toDistrict = (district, locale) => {
|
|
28127
|
+
if (locale === "en") {
|
|
28128
|
+
return {
|
|
28129
|
+
id: district.id,
|
|
28130
|
+
name: district.name_en,
|
|
28131
|
+
value: district.id,
|
|
28132
|
+
label: district.name_en
|
|
28133
|
+
};
|
|
28134
|
+
} else {
|
|
28135
|
+
return {
|
|
28136
|
+
id: district.id,
|
|
28137
|
+
name: district.name_th,
|
|
28138
|
+
value: district.id,
|
|
28139
|
+
label: district.name_th
|
|
28140
|
+
};
|
|
28141
|
+
}
|
|
28142
|
+
};
|
|
28143
|
+
var getDistricts = async (provinceId) => {
|
|
28144
|
+
const response = await fetch("https://raw.githubusercontent.com/kongvut/thai-province-data/refs/heads/master/api/latest/district.json");
|
|
28145
|
+
const data = await response.json();
|
|
28146
|
+
const districts = data.filter((district) => district.province_id === provinceId);
|
|
28147
|
+
return districts;
|
|
28148
|
+
};
|
|
28149
|
+
var DistrictDropdown = ({ locale = "th", searchPlaceholder = "Search District", placeholder = "Select District", label, searchButtonClassName = "bg-blue-500", onChange, value, required = false, provinceId }) => {
|
|
28150
|
+
const [districts, setDistricts] = useState([]);
|
|
28151
|
+
const [currentDistrict, setCurrentDistrict] = useState(null);
|
|
28152
|
+
useEffect(() => {
|
|
28153
|
+
if (!provinceId) return;
|
|
28154
|
+
getDistricts(provinceId).then(setDistricts);
|
|
28155
|
+
}, [provinceId]);
|
|
28156
|
+
useEffect(() => {
|
|
28157
|
+
if (value) {
|
|
28158
|
+
const district = districts.find((d) => {
|
|
28159
|
+
if (locale === "th") {
|
|
28160
|
+
return d.name_th === value;
|
|
28161
|
+
} else {
|
|
28162
|
+
return d.name_en === value;
|
|
28163
|
+
}
|
|
28164
|
+
});
|
|
28165
|
+
if (district) {
|
|
28166
|
+
setCurrentDistrict(district);
|
|
28167
|
+
}
|
|
28168
|
+
}
|
|
28169
|
+
}, [districts, value, locale]);
|
|
28170
|
+
const onSelect = useCallback((id) => {
|
|
28171
|
+
const district = districts.find((d) => d.id === id);
|
|
28172
|
+
if (district) {
|
|
28173
|
+
setCurrentDistrict(district);
|
|
28174
|
+
onChange?.(district);
|
|
28175
|
+
}
|
|
28176
|
+
}, [districts]);
|
|
28177
|
+
return /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(
|
|
28178
|
+
SearchSelect,
|
|
28179
|
+
{
|
|
28180
|
+
items: districts.map((district) => toDistrict(district, locale)),
|
|
28181
|
+
placeholder: searchPlaceholder,
|
|
28182
|
+
triggerPlaceholder: placeholder,
|
|
28183
|
+
label,
|
|
28184
|
+
selectionMode: "single",
|
|
28185
|
+
searchButtonClassName,
|
|
28186
|
+
onChange: (value2) => {
|
|
28187
|
+
if (typeof value2 === "string") {
|
|
28188
|
+
onSelect(value2);
|
|
28189
|
+
}
|
|
28190
|
+
},
|
|
28191
|
+
value: currentDistrict?.id,
|
|
28192
|
+
required
|
|
28193
|
+
}
|
|
28194
|
+
) });
|
|
28195
|
+
};
|
|
28196
|
+
var toProvince = (province, locale) => {
|
|
28197
|
+
if (locale === "en") {
|
|
28198
|
+
return {
|
|
28199
|
+
id: province.id,
|
|
28200
|
+
name: province.name_en,
|
|
28201
|
+
value: province.id,
|
|
28202
|
+
label: province.name_en
|
|
28203
|
+
};
|
|
28204
|
+
} else {
|
|
28205
|
+
return {
|
|
28206
|
+
id: province.id,
|
|
28207
|
+
name: province.name_th,
|
|
28208
|
+
value: province.id,
|
|
28209
|
+
label: province.name_th
|
|
28210
|
+
};
|
|
28211
|
+
}
|
|
28212
|
+
};
|
|
28213
|
+
var getProvinces = async () => {
|
|
28214
|
+
const response = await fetch("https://raw.githubusercontent.com/kongvut/thai-province-data/refs/heads/master/api/latest/province.json");
|
|
28215
|
+
const data = await response.json();
|
|
28216
|
+
return data;
|
|
28217
|
+
};
|
|
28218
|
+
var ProvinceDropdown = ({ locale = "th", searchPlaceholder = "Search Province", placeholder = "Select Province", label, searchButtonClassName = "bg-blue-500", onChange, value, required = false }) => {
|
|
28219
|
+
const [provinces, setProvinces] = useState([]);
|
|
28220
|
+
const [currentProvince, setCurrentProvince] = useState(null);
|
|
28221
|
+
useEffect(() => {
|
|
28222
|
+
getProvinces().then(setProvinces);
|
|
28223
|
+
}, []);
|
|
28224
|
+
useEffect(() => {
|
|
28225
|
+
if (value) {
|
|
28226
|
+
const province = provinces.find((p) => {
|
|
28227
|
+
if (locale === "th") {
|
|
28228
|
+
return p.name_th === value;
|
|
28229
|
+
} else {
|
|
28230
|
+
return p.name_en === value;
|
|
28231
|
+
}
|
|
28232
|
+
});
|
|
28233
|
+
if (province) {
|
|
28234
|
+
setCurrentProvince(province);
|
|
28235
|
+
}
|
|
28236
|
+
}
|
|
28237
|
+
}, [provinces, value, locale]);
|
|
28238
|
+
const onSelect = useCallback((id) => {
|
|
28239
|
+
const province = provinces.find((p) => p.id === id);
|
|
28240
|
+
if (province) {
|
|
28241
|
+
setCurrentProvince(province);
|
|
28242
|
+
onChange?.(province);
|
|
28243
|
+
}
|
|
28244
|
+
}, [provinces]);
|
|
28245
|
+
return /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(
|
|
28246
|
+
SearchSelect,
|
|
28247
|
+
{
|
|
28248
|
+
items: provinces.map((province) => toProvince(province, locale)),
|
|
28249
|
+
placeholder: searchPlaceholder,
|
|
28250
|
+
triggerPlaceholder: placeholder,
|
|
28251
|
+
label,
|
|
28252
|
+
selectionMode: "single",
|
|
28253
|
+
searchButtonClassName,
|
|
28254
|
+
onChange: (value2) => {
|
|
28255
|
+
if (typeof value2 === "string") {
|
|
28256
|
+
onSelect(value2);
|
|
28257
|
+
}
|
|
28258
|
+
},
|
|
28259
|
+
value: currentProvince?.id,
|
|
28260
|
+
required
|
|
28261
|
+
}
|
|
28262
|
+
) });
|
|
28263
|
+
};
|
|
28264
|
+
var toSubDistrict = (subDistrict, locale) => {
|
|
28265
|
+
if (locale === "en") {
|
|
28266
|
+
return {
|
|
28267
|
+
id: subDistrict.id,
|
|
28268
|
+
name: subDistrict.name_en,
|
|
28269
|
+
value: subDistrict.id,
|
|
28270
|
+
label: subDistrict.name_en
|
|
28271
|
+
};
|
|
28272
|
+
} else {
|
|
28273
|
+
return {
|
|
28274
|
+
id: subDistrict.id,
|
|
28275
|
+
name: subDistrict.name_th,
|
|
28276
|
+
value: subDistrict.id,
|
|
28277
|
+
label: subDistrict.name_th
|
|
28278
|
+
};
|
|
28279
|
+
}
|
|
28280
|
+
};
|
|
28281
|
+
var getSubDistricts = async (districtId) => {
|
|
28282
|
+
const response = await fetch("https://raw.githubusercontent.com/kongvut/thai-province-data/refs/heads/master/api/latest/sub_district.json");
|
|
28283
|
+
const data = await response.json();
|
|
28284
|
+
const subDistricts = data.filter((subDistrict) => subDistrict.district_id === districtId);
|
|
28285
|
+
return subDistricts;
|
|
28286
|
+
};
|
|
28287
|
+
var SubDistrictDropdown = ({ locale = "th", searchPlaceholder = "Search District", placeholder = "Select District", label, searchButtonClassName = "bg-blue-500", onChange, value, required = false, districtId }) => {
|
|
28288
|
+
const [districts, setDistricts] = useState([]);
|
|
28289
|
+
const [currentDistrict, setCurrentDistrict] = useState(null);
|
|
28290
|
+
useEffect(() => {
|
|
28291
|
+
if (!districtId) return;
|
|
28292
|
+
getSubDistricts(districtId).then(setDistricts);
|
|
28293
|
+
}, [districtId]);
|
|
28294
|
+
useEffect(() => {
|
|
28295
|
+
if (value) {
|
|
28296
|
+
const district = districts.find((d) => {
|
|
28297
|
+
if (locale === "th") {
|
|
28298
|
+
return d.name_th === value;
|
|
28299
|
+
} else {
|
|
28300
|
+
return d.name_en === value;
|
|
28301
|
+
}
|
|
28302
|
+
});
|
|
28303
|
+
if (district) {
|
|
28304
|
+
setCurrentDistrict(district);
|
|
28305
|
+
}
|
|
28306
|
+
}
|
|
28307
|
+
}, [districts, value, locale]);
|
|
28308
|
+
const onSelect = useCallback((id) => {
|
|
28309
|
+
const district = districts.find((d) => d.id === id);
|
|
28310
|
+
if (district) {
|
|
28311
|
+
setCurrentDistrict(district);
|
|
28312
|
+
onChange?.(district);
|
|
28313
|
+
}
|
|
28314
|
+
}, [districts]);
|
|
28315
|
+
return /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(
|
|
28316
|
+
SearchSelect,
|
|
28317
|
+
{
|
|
28318
|
+
items: districts.map((district) => toSubDistrict(district, locale)),
|
|
28319
|
+
placeholder: searchPlaceholder,
|
|
28320
|
+
triggerPlaceholder: placeholder,
|
|
28321
|
+
label,
|
|
28322
|
+
selectionMode: "single",
|
|
28323
|
+
searchButtonClassName,
|
|
28324
|
+
onChange: (value2) => {
|
|
28325
|
+
if (typeof value2 === "string") {
|
|
28326
|
+
onSelect(value2);
|
|
28327
|
+
}
|
|
28328
|
+
},
|
|
28329
|
+
value: currentDistrict?.id,
|
|
28330
|
+
required
|
|
28331
|
+
}
|
|
28332
|
+
) });
|
|
28333
|
+
};
|
|
28123
28334
|
|
|
28124
|
-
export { Avatar, Button, Checkbox, DatePickerInput, LabelInput, Pagination, SearchSelect, TextInput, Toggle, UploadImage };
|
|
28335
|
+
export { Avatar, Button, Checkbox, DatePickerInput, DistrictDropdown, LabelInput, Pagination, ProvinceDropdown, SearchSelect, SubDistrictDropdown, TextInput, Toggle, UploadImage };
|