CurrencySymbol
Shows the Saudi riyal icon for SAR and the plain currency code for any other currency.
import { CurrencySymbol } from '@salla.sa/twilight-theme-engine/components/common';In plain words
The Saudi riyal has its own symbol, and it is not a normal letter you can type, so it comes from Salla's icon font. CurrencySymbol shows that icon when the currency is SAR and simply writes the code (USD, AED) for everything else.
Signature
const CurrencySymbol: LazyExoticComponent<(props: { currency: string }) => JSX.Element>
// currency 'SAR' → <i className="sicon-sar" aria-hidden="true" />
// anything else → <span>{currency}</span>Try it live
250
import { CurrencySymbol } from '@salla.sa/twilight-theme-engine/components/common';
export function PlainPrice() {
return (
<span className="price">
{250} <CurrencySymbol currency={'SAR'} />
</span>
);
}
Example
import { CurrencySymbol } from '@salla.sa/twilight-theme-engine/components/common';
export function Total({ amount, currency }: { amount: string; currency: string }) {
return (
<p className="total">
{amount} <CurrencySymbol currency={currency} />
{currency === 'SAR' && <span className="sr-only">SAR</span>}
</p>
);
}
How it behaves
The comparison is exact: only the string
SARgets the icon, sosarrenders the text "sar".The icon is a glyph of the
siconicon font the theme loads.The engine's product details and add-to-cart form put it after the sale, regular and starting prices.
It is lazy (code-split).
Gotchas
The SAR icon is
aria-hiddenand has no text, so a screen reader reads "250" with no currency. Add visually hidden text next to it, as the example does.It ignores the store setting
use_sar_symbol, which the engineHeaderchecks before showing the same icon. Readstore.settings.use_sar_symbolyourself if the merchant's choice should apply.It formats nothing: no decimals, digits or placement. For a formatted price use
useMoney().format, which adds the riyal icon for SAR itself.