Files
xenia-pos-local/packages/i18n/src/hooks.js
T
bonaminandClaude Opus 5.5 77e0adbe9c feat(ui): board design language as global tokens; KDS on tokens and shared components (platform-v2 3.2b-2)
- @xenia/ui: --x-board-* tokens (the kitchen display's look: dark board, light cards,
  status colours, card radius/shadows, number font), Tailwind board.* colours, contrast
  test for the board pairs; near-identical shades merged.
- New shared Stepper component (gallery + ui.mjs), labels ui.decrease / ui.increase.
- KDS: theme.js maps to the board tokens, no colour literals left (only stored setting
  values); decline / call waiter / settings use Dialog, Button, Switch, Select, Stepper;
  toasts are @xenia/ui toasts (ToastProvider at the terminal root).
- Terminal: apps can set their theme (APP_THEMES, KDS dark) while they run.
- CS-16: board screens and "no hard-coded colours in app code".

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-14 20:02:35 +02:00

43 lines
1.5 KiB
JavaScript

import { useContext, useMemo } from 'react'
import { useTranslation } from 'react-i18next'
import { FormatContext } from './context.js'
import { SUPPORTED_LANGUAGES } from './locale.js'
/** formatTime, formatDateTime, formatDate, formatRelative, formatMoney, formatNumber, formatPercent, venueToday… */
export function useFormat() {
const ctx = useContext(FormatContext)
if (!ctx) throw new Error('useFormat() needs an <I18nProvider> above it')
return ctx
}
/** { language, languages, changeLanguage } for language pickers (screen only; see setUserLanguage to save). */
export function useLanguage() {
const { i18n } = useTranslation()
return {
language: i18n.resolvedLanguage || i18n.language,
languages: SUPPORTED_LANGUAGES,
changeLanguage: lng => i18n.changeLanguage(lng),
}
}
/**
* The @xenia/ui components' own texts, translated (common:ui.*). Use once at the root:
* <UiLabelsProvider labels={useUiLabels()}>
*/
export function useUiLabels() {
const { t, i18n } = useTranslation('common')
const language = i18n.resolvedLanguage || i18n.language
return useMemo(() => ({
close: t('ui.close'),
dismiss: t('ui.dismiss'),
loading: t('ui.loading'),
moreInfo: t('ui.moreInfo'),
notifications: t('ui.notifications'),
backspace: t('ui.backspace'),
decrease: t('ui.decrease'),
increase: t('ui.increase'),
submit: t('ui.submit'),
pinProgress: (count, total) => t('ui.pinProgress', { count, total }),
}), [t, language]) // eslint-disable-line react-hooks/exhaustive-deps
}