Skip to content

v2.3.0 — Gridory

Choose a tag to compare

@VictorDiazJauregui VictorDiazJauregui released this 19 Nov 15:51
· 10 commits to main since this release
04cafdf

Minor release of Gridory: CountrySelect and PhoneInput cover what a form needs to replace its own country and
phone pickers, and the country catalog gets its own entry. Everything new is opt-in: without the new props both
controls render and emit exactly what they did in 2.2.0.

English · Español

English

Upgrade

npm install gridory@2.3.0

New

  • Country catalog: gridory/countries. CountryFlag, getCountryName(code, locale?), getDialCode(code),
    findCountryByDialCode(dialCode), listCountries(locale?) and isCountryCode, to show countries in a table, a
    card or a filter without loading the selects (about 2.5 KB gzip, no Radix, no icons). The 14 dial codes shared by
    several countries always give their most populous one, from a fixed table: +1 is the United States.
  • id and name. On the number of PhoneInput and on the combobox of CountrySelect: an outside
    <label htmlFor> works, and a form can move the focus to its first error by id or by name.
  • disabled. On both controls: native disabled on their buttons and inputs, an open list closes, the box
    carries data-disabled, and the look comes from --gdy-country-select-disabled-* and
    --gdy-phone-input-disabled-* (opacity 0.5 and the muted background by default).
  • "Not applicable" in CountrySelect. notApplicableOption adds it as the first option, single selection only.
    It is an answer, apart from null and from every country: required takes it. Its value is
    COUNTRY_NOT_APPLICABLE ("not-applicable") or your own notApplicableValue ("" works; a country code throws
    InvalidNotApplicableValueError, and mind that "NA" is Namibia). Its text, "No aplica" by default, is
    texts.notApplicable, and it is used in the list, the field and the search.
  • Number rule in PhoneInput. numberCharacters="digits" keeps digits only ("phone", the 2.2.0 rule, stays the
    default); maxNumberLength limits the length after that rule; splitPastedDialCode turns a pasted
    +51 987 654 321 into Peru in the prefix and 987654321 in the number, in a single onValueChange.
<CountrySelect id="country" name="country" required notApplicableOption disabled={isSaving} />
<PhoneInput id="whatsapp" name="whatsapp" numberCharacters="digits" maxNumberLength={9} splitPastedDialCode />

Good to know

  • The character rule and the maximum apply to what is typed or pasted; the initial value is shown as given. The rule
    filters the whole value on each change, as in 2.2.0: editing an old 987654321 / 912345678 in digits mode joins
    both numbers.
  • A paste is split only when it starts with +, the dial code is known and it replaces the whole number. Area codes
    are not read: a pasted +1 809… picks the United States unless a +1 country was already chosen.
  • Types: CountrySelectProps is now generic, CountrySelectProps<TNotApplicable = CountryNotApplicable>, and its
    union has a third member, NotApplicableCountrySelectProps. Rendering <CountrySelect … /> compiles as before,
    wrappers typed with CountrySelectProps included. Only code that reads props.value from a CountrySelectProps
    object sees the wider type. CountrySelectTexts.notApplicable is optional, so a full texts object written for
    2.2.0 still compiles.
  • In the selects nothing changes without the new props: same ids, no name, same list, same paste.

See the Country select,
Phone input and
Countries guides.

Español

Actualizar

npm install gridory@2.3.0

Novedades

  • Catálogo de países: gridory/countries. CountryFlag, getCountryName(code, locale?), getDialCode(code),
    findCountryByDialCode(dialCode), listCountries(locale?) e isCountryCode, para mostrar países en una tabla, una
    ficha o un filtro sin cargar los selectores (unos 2,5 KB gzip, sin Radix ni íconos). Los 14 prefijos que comparten
    varios países devuelven siempre el más poblado, de una tabla fija: +1 es EE. UU.
  • id y name. En el número de PhoneInput y en el combobox de CountrySelect: funciona un <label htmlFor>
    externo, y un formulario puede llevar el foco a su primer error por id o por nombre.
  • disabled. En los dos controles: disabled nativo en sus botones e inputs, la lista abierta se cierra, la caja
    lleva data-disabled y el aspecto sale de --gdy-country-select-disabled-* y --gdy-phone-input-disabled-*
    (opacidad 0,5 y el fondo apagado por defecto).
  • "No aplica" en CountrySelect. notApplicableOption la suma como primera opción, solo en selección simple. Es
    una respuesta, distinta de null y de cualquier país: required la acepta. Su valor es COUNTRY_NOT_APPLICABLE
    ("not-applicable") o tu propio notApplicableValue (sirve ""; un código de país lanza
    InvalidNotApplicableValueError, y ojo que "NA" es Namibia). Su texto, "No aplica" por defecto, es
    texts.notApplicable, y se usa en la lista, en el campo y en la búsqueda.
  • Regla del número en PhoneInput. numberCharacters="digits" guarda solo dígitos ("phone", la regla de la
    2.2.0, sigue por defecto); maxNumberLength limita el largo después de esa regla; splitPastedDialCode convierte un
    +51 987 654 321 pegado en Perú en el prefijo y 987654321 en el número, en un solo onValueChange.
<CountrySelect id="country" name="country" required notApplicableOption disabled={isSaving} />
<PhoneInput id="whatsapp" name="whatsapp" numberCharacters="digits" maxNumberLength={9} splitPastedDialCode />

Para tener en cuenta

  • La regla de caracteres y el máximo se aplican a lo que se escribe o se pega; el valor inicial se muestra tal cual.
    La regla filtra el valor entero en cada cambio, como en la 2.2.0: editar un 987654321 / 912345678 viejo en modo
    dígitos junta los dos números.
  • Un pegado se separa solo si empieza con +, el prefijo es conocido y reemplaza todo el número. No se leen códigos
    de área: un +1 809… pegado elige EE. UU. salvo que ya hubiera un país +1 elegido.
  • Tipos: CountrySelectProps ahora es genérico, CountrySelectProps<TNotApplicable = CountryNotApplicable>, y su
    unión tiene un tercer miembro, NotApplicableCountrySelectProps. Renderizar <CountrySelect … /> compila igual
    que antes, también desde envoltorios tipados con CountrySelectProps. Solo el código que lee props.value de un
    objeto CountrySelectProps ve el tipo más amplio. CountrySelectTexts.notApplicable es opcional, así un objeto de
    textos completo escrito para la 2.2.0 sigue compilando.
  • En los selectores nada cambia sin las props nuevas: mismos ids, sin name, la misma lista y el mismo pegado.

Ver las guías del Selector de país,
del Teléfono con prefijo y de
Países.