LanguageToggle
The mock's language circle: shows the other language's short name, named in that language. The name starts with the words on screen (WCAG 2.5.3 label in name: "EN, English", "عربي، العربية"), so a speech user can say what they see.
import { LanguageToggle } from '@ergasti/bricks';Examples
The EN / العربية switch
It only calls onToggle; you flip your own language state and the BricksProvider. This one is wired to nothing, so use the Language switch at the top of the page to see both.
Code
import { LanguageToggle, useLanguage } from '@ergasti/bricks';
function Toggle() {
const language = useLanguage();
return <div style={{ display: 'flex', gap: 16, alignItems: 'center' }}><LanguageToggle onToggle={() => {}} /><small>Current: {language}</small></div>;
}Props
Prop
Type
Design guidance
How the BRICKS design system uses LanguageToggle. Written in docs/content/components/LanguageToggle.md; the props above are read from the code, which wins where the two disagree.
The header's round language button: it shows the other language's short name ("عربي" in English, "EN" in Arabic) and calls onToggle; use it through AppHeader onToggleLanguage, or alone in a custom header.
It is the mocks' .circle language button (#langBtn, "عربي") in the Brand dashboard's top bar. It names the other language in that language, the bilingual-UI convention, and its accessible name starts with the words on screen ("عربي، العربية" / "EN, English") so speech-input users can say what they see. The component only reports the press; the app switches the BricksProvider language and direction.
Anatomy
- Circle (
.kit-shell-circle.kit-shell-lang): 44px, 1px--lineborder,--cardfill, 14px 700 text. - Label:
otherLanguageShort("عربي" or "EN"), withlangset to the other language; Latin "EN" uses Inter inside an Arabic page.
Variants
Current language | Shows | Accessible name | Tooltip |
|---|---|---|---|
'en' | "عربي" | "عربي، العربية" | "العربية" |
'ar' | "EN" | "EN, English" | "English" |
States
| State | Look |
|---|---|
| Default | Ink text on card. |
| Hover | Border darkens (--color-control-border-hover). |
| Focus-visible | Raspberry border + focus ring. |
Usage
// Usually through the header
const [language, setLanguage] = useState<Lang>('en');
<BricksProvider preset={trndrPreset} language={language}>
<div dir={language === 'ar' ? 'rtl' : 'ltr'} lang={language}>
<AppHeader title="Home" onToggleLanguage={() => setLanguage(OTHER_LANGUAGE[language])} />
</div>
</BricksProvider>// Alone, e.g. in a custom header or a sign-in page
<LanguageToggle onToggle={() => setLanguage(OTHER_LANGUAGE[language])} />Where it appears
- Brand › every screen › top bar, after the search pill. Screen: Home and the other Brand dashboard pages.
- The PR Portal mock has no language circle (its gallery screens are rendered per language instead).
Guidelines
Do
- Switch
language,dirandlangtogether when it is pressed. - Keep it after the search, before help and the bell.
Don't
- Don't label it with a flag or "Language".
- Don't show it in a one-language app (omit
onToggleLanguage).
RTL and Arabic
- In Arabic it shows "EN" in Inter; it moves to the left side with the tools row.
- Arabic punctuation (،) joins the name in Arabic.
Tokens
--line, --card, --ink, --lh-ar, --rasp, --focus-ring, --color-control-border-hover.
Accessibility
- A
<button type="button">withlangof the target language, so screen readers pronounce it correctly. - Label-in-name: the accessible name starts with the visible text (WCAG 2.5.3).
- 44px target; visible focus ring.
Found in the source
- ARIA attributes set:
aria-label,aria-haspopup,aria-expanded,aria-hidden. - Its tests cover: “puts breadcrumbs above the title in a labelled nav, and gives the h1 the id asked for”; “touch tiers: the search field and the breadcrumb links are 44px tall targets”; “names the other language in that language and toggles with the keyboard”.
Read from the component's source and tests. See Accessibility for the patterns the library follows.
Related
AppHeader: draws it withonToggleLanguage.OTHER_LANGUAGE: the helper that gives the other language code.
See also: useAppShell · useLanguage · HeaderSearch · LogoutButton · TopbarMenu
Source
src/shell/AppHeader.tsx (line 92) on GitHub.