UNPKG

strapi-plugin-country-select

Version:

A strapi custom field for selecting any country based on the ISO 3166-1 country code standard.

58 lines (57 loc) 1.96 kB
import { jsx, jsxs } from "react/jsx-runtime"; import React from "react"; import { Field, Flex, Combobox, ComboboxOption } from "@strapi/design-system"; import { useIntl } from "react-intl"; import { g as getTranslation } from "./index-DeorT838.mjs"; const CountrySelect = React.forwardRef(({ value, onChange, name, label, labelAction, required, hint, placeholder, disabled, error, ...rest }, forwardedRef) => { const { formatMessage, messages } = useIntl(); const countries = messages[getTranslation("countries")] || "{}"; console.log(rest); const parsedOptions = JSON.parse(countries); const isValidValue = !value || parsedOptions.hasOwnProperty(value); return /* @__PURE__ */ jsx( Field.Root, { name, id: name, error: !isValidValue ? formatMessage({ id: getTranslation("country-select.unsupported-country-code") }, { countryCode: value }) : error, required, hint, children: /* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "stretch", gap: 1, children: [ /* @__PURE__ */ jsx(Field.Label, { action: labelAction, children: label }), /* @__PURE__ */ jsx( Combobox, { ref: forwardedRef, placeholder, "aria-label": label, "aria-disabled": disabled, disabled, value: isValidValue ? value : null, onChange: (countryCode) => onChange(name, countryCode), onClear: () => onChange(name, ""), children: Object.entries(parsedOptions).sort(([, n1], [, n2]) => n1.localeCompare(n2)).map(([countryCode, countryName]) => /* @__PURE__ */ jsx(ComboboxOption, { value: countryCode, children: countryName }, countryCode)) } ), /* @__PURE__ */ jsx(Field.Hint, {}), /* @__PURE__ */ jsx(Field.Error, {}) ] }) } ); }); export { CountrySelect as default }; //# sourceMappingURL=index-SmoHzJDA.mjs.map