2024-03-14 15:45:58 +01:00
|
|
|
/* Registering of global Storybook decorators.
|
|
|
|
* Copyright (C) 2024 André Jaenisch
|
|
|
|
* SPDX-FileCopyrightText: 2024 André Jaenisch
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2024-07-09 12:18:08 +02:00
|
|
|
import { computePosition, autoUpdate, offset, shift, flip, arrow } from '@floating-ui/dom';
|
|
|
|
import { initializeStores, storePopup } from '@skeletonlabs/skeleton';
|
2024-02-08 10:43:55 +01:00
|
|
|
import type { Preview } from '@storybook/svelte';
|
2024-02-17 23:50:27 +01:00
|
|
|
import { init, locale, register } from 'svelte-i18n';
|
|
|
|
|
2024-02-28 21:30:24 +01:00
|
|
|
import { mapLocaleToDir } from '../src/lib/i18n/index.ts';
|
|
|
|
|
2024-02-15 18:05:25 +01:00
|
|
|
// See src/routes/+layout.svelte
|
|
|
|
// Order is important!
|
|
|
|
import '../src/theme.postcss';
|
|
|
|
//import '@skeletonlabs/skeleton/styles/skeleton.css';
|
2024-02-09 21:13:06 +01:00
|
|
|
import '../src/app.postcss';
|
2024-02-15 19:18:52 +01:00
|
|
|
import './fix.css';
|
2024-02-08 10:43:55 +01:00
|
|
|
|
2024-06-24 11:38:01 +02:00
|
|
|
register('bg', () => import('../src/lib/i18n/locales/bg.json'));
|
2024-02-17 23:50:27 +01:00
|
|
|
register('de', () => import('../src/lib/i18n/locales/de.json'));
|
|
|
|
register('en', () => import('../src/lib/i18n/locales/en.json'));
|
|
|
|
register('he', () => import('../src/lib/i18n/locales/he.json'));
|
2024-06-24 11:38:01 +02:00
|
|
|
register('pl', () => import('../src/lib/i18n/locales/pl.json'));
|
2024-02-17 23:50:27 +01:00
|
|
|
init({ fallbackLocale: 'en', initialLocale: 'en' });
|
|
|
|
locale.set('en');
|
|
|
|
|
2024-02-28 21:30:24 +01:00
|
|
|
function withI18n(storyFn, context) {
|
|
|
|
const l = context.globals.locale;
|
|
|
|
|
|
|
|
locale.set(l);
|
|
|
|
document.dir = mapLocaleToDir(l);
|
|
|
|
|
|
|
|
return storyFn();
|
|
|
|
}
|
|
|
|
|
2024-07-09 12:18:08 +02:00
|
|
|
function withStores(storyFn) {
|
|
|
|
// Globally initialize stores for Skeleton.dev contexts
|
|
|
|
initializeStores();
|
|
|
|
return storyFn();
|
|
|
|
}
|
|
|
|
|
|
|
|
function withPopup(storyFn) {
|
|
|
|
storePopup.set({ computePosition, autoUpdate, offset, shift, flip, arrow });
|
|
|
|
return storyFn();
|
|
|
|
}
|
|
|
|
|
2024-02-08 10:43:55 +01:00
|
|
|
const preview: Preview = {
|
2024-02-17 23:50:27 +01:00
|
|
|
globalTypes: {
|
|
|
|
locale: {
|
|
|
|
description: 'Internationalization locale',
|
|
|
|
defaultValue: 'en',
|
|
|
|
toolbar: {
|
|
|
|
icon: 'globe',
|
|
|
|
items: [
|
2024-06-24 11:38:01 +02:00
|
|
|
{
|
|
|
|
value: 'bg',
|
|
|
|
title: 'Bulgarian'
|
|
|
|
},
|
2024-02-17 23:50:27 +01:00
|
|
|
{
|
|
|
|
value: 'de',
|
|
|
|
title: 'German'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
value: 'en',
|
|
|
|
title: 'English'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
value: 'he',
|
|
|
|
title: 'Hebrew'
|
2024-06-24 11:38:01 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
value: 'pl',
|
|
|
|
title: 'Polish'
|
2024-02-17 23:50:27 +01:00
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2024-02-08 10:43:55 +01:00
|
|
|
parameters: {
|
|
|
|
actions: { argTypesRegex: '^on[A-Z].*' },
|
|
|
|
controls: {
|
|
|
|
matchers: {
|
|
|
|
color: /(background|color)$/i,
|
|
|
|
date: /Date$/i
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2024-07-09 12:18:08 +02:00
|
|
|
export const decorators = [withI18n, withPopup, withStores];
|
2024-02-28 21:30:24 +01:00
|
|
|
|
2024-02-08 10:43:55 +01:00
|
|
|
export default preview;
|