import { useTranslation } from '../../src/lib/hooks'; import React, { useEffect, StrictMode } from 'react'; /** * Props for wrapper-komponenterne. Filen udgives (`files` indeholder * "stories/lib") og importeres af 18 repoer, saa den skal vaere typet — ikke * implicit `any`. */ type ThemeWrapperProps = { theme: string; children: React.ReactNode; withPageContentBlock?: boolean; }; type ThemeLanguageWrapperProps = ThemeWrapperProps & { defaultLabels: T; importPromises: [Promise, Promise | null]; translationContext: React.Context; lang: string; }; const globalTheme = { theme: { name: 'Theme', description: 'Global theme for components', defaultValue: 'light', toolbar: { icon: 'circlehollow', items: ['normal', 'dark'], showName: true, dynamicTitle: true, }, }, }; const globalLang = (items = ['da', 'en'], defaultValue = 'da') => ({ lang: { name: 'Language', description: 'Global language for components', defaultValue, toolbar: { icon: 'circlehollow', items, showName: true, dynamicTitle: true, }, }, }); const ThemeWrapper = ({ theme, children, withPageContentBlock = true }: ThemeWrapperProps) => { useEffect(() => { const body = document.querySelector('body'); if (body) { body.classList.remove('theme--normal'); body.classList.remove('theme--dark'); body.classList.add(`theme--${theme}`); } }); if (withPageContentBlock) { return (
{children}
); } return (
{children}
); } const ThemeLanguageWrapper = ({ theme, children, defaultLabels, importPromises, translationContext, lang, withPageContentBlock = true, }: ThemeLanguageWrapperProps) => { const translations = useTranslation(defaultLabels, importPromises, lang); useEffect(() => { const body = document.querySelector('body'); if (body) { body.classList.remove('theme--normal'); body.classList.remove('theme--dark'); body.classList.add(`theme--${theme}`); } }); if (withPageContentBlock) { return (
{children}
); } return (
{children}
); } const translations = { character_count: { overflow: { message: { recommended: 'Vi anbefaler, at du maksimalt skriver {{maxchars}} tegn.', allowed: 'Du må maks. skrive {{maxchars}} tegn.' }, count: { recommended: { one: 'Du har skrevet 1 tegn mere end anbefalet.', other: 'Du har skrevet {{overflow}} tegn mere end anbefalet.' }, allowed: { one: 'Du har skrevet 1 tegn for meget.', other: 'Du har skrevet {{overflow}} tegn for meget.' } } }, count_down: { one: 'Du har 1 tegn tilbage', other: 'Du har {{remaining}} tegn tilbage' } }, }; export { globalTheme, globalLang, ThemeWrapper, ThemeLanguageWrapper, translations, };