salla-localization-modal
A modal that lets the customer pick the store language and currency.
A modal that lets the customer pick the store language and currency. Place one instance in the theme (usually the
header or footer). It opens when the localization::open event fires (and, outside native mobile apps, on
currency::open and language::open), when open() is called, or from its own trigger button when show-trigger is set.
A language or currency list is only shown if the store offers more than one choice; the modal closes itself if
there is nothing to choose. Lists with fewer than 6 entries render as radio buttons, longer lists as a <select>.
Confirming sets the s-lang and s-curr cookies, changes the currency through the API and reloads the page
with the chosen language.
Use it
In HTML or JSX, use the tag <salla-localization-modal> with the Attribute names below. In React, the wrapper takes the Property names (camelCase).
import { SallaLocalizationModal } from '@salla.sa/twilight-components-react/localization-modal';Client-only. On the server this wrapper renders a placeholder (a skeleton, or nothing), and the real component mounts in the browser. Do not rely on it for content that search engines must see.
Example
import { SallaLocalizationModal } from '@salla.sa/twilight-components-react/localization-modal';
export function Example() {
return (
<SallaLocalizationModal showTrigger />
);
}import { SallaLocalizationModal } from '@salla.sa/twilight-components-react/localization-modal';
export function Example() {
return (
<SallaLocalizationModal>
<div slot="language"><label htmlFor="lang-{code}">{'{'}name{'}'}</label></div>
<div slot="currency"><label htmlFor="currency-{code}">{'{'}name{'}'} {'{'}symbol{'}'}</label></div>
</SallaLocalizationModal>
);
}Properties
| Property | Attribute | Description | Type | Default |
|---|---|---|---|---|
currency | currency | Current currency code (for example SAR, USD). Defaults to the currency of the current user; it is updated when the customer selects another one. | string | |
language | language | Current language code (for example ar, en). Defaults to the language of the current user; it is updated when the customer selects another one. | string | |
showTrigger | show-trigger | When true, renders a button showing the current language name and currency symbol that opens the modal when clicked. | boolean | false |
Methods
Call these on the element or a React ref.
close() => Promise<HTMLElement>
Closes the modal.
Returns Promise<HTMLElement>: A Promise that resolves when the modal has closed.
open() => Promise<any>
Opens the modal, loads the available languages and currencies, and closes it again if there is nothing to choose between.
Returns Promise<any>: A Promise that resolves when loading has finished.
submit() => Promise<void>
Applies the selected currency and language: changes the currency through the API, stores the s-lang and
s-curr cookies, closes the modal and navigates to the same page with the chosen language.
Slots
| Slot | Description |
|---|---|
currency | Template for each currency radio label (read once when the component is created, only used for the radio list). Placeholders: {name}, {code}, {symbol}, {country_code}. |
language | Template for each language radio label (read once when the component is created, only used for the radio list). Placeholders: {name}, {code}, {country_code}. |
Related
Renders: <salla-modal>, <salla-skeleton>, <salla-placeholder>, <salla-button>.