2023-05-11 07:26:12 -05:00
|
|
|
import { Preview } from '@storybook/react';
|
2019-04-24 03:14:18 -05:00
|
|
|
import 'jquery';
|
2024-04-23 03:09:08 -05:00
|
|
|
import { getTimeZone, getTimeZones } from '@grafana/data';
|
2023-05-11 07:26:12 -05:00
|
|
|
|
2019-04-24 03:14:18 -05:00
|
|
|
import '../../../public/vendor/flot/jquery.flot.js';
|
|
|
|
import '../../../public/vendor/flot/jquery.flot.selection';
|
|
|
|
import '../../../public/vendor/flot/jquery.flot.time';
|
|
|
|
import '../../../public/vendor/flot/jquery.flot.stack';
|
|
|
|
import '../../../public/vendor/flot/jquery.flot.stackpercent';
|
|
|
|
import '../../../public/vendor/flot/jquery.flot.fillbelow';
|
|
|
|
import '../../../public/vendor/flot/jquery.flot.crosshair';
|
|
|
|
import '../../../public/vendor/flot/jquery.flot.dashes';
|
|
|
|
import '../../../public/vendor/flot/jquery.flot.gauge';
|
2023-05-11 07:26:12 -05:00
|
|
|
|
2019-10-21 09:39:43 -05:00
|
|
|
import { withTheme } from '../src/utils/storybook/withTheme';
|
2024-04-23 03:09:08 -05:00
|
|
|
import { withTimeZone } from '../src/utils/storybook/withTimeZone';
|
2022-10-03 02:23:47 -05:00
|
|
|
import { ThemedDocsContainer } from '../src/utils/storybook/ThemedDocsContainer';
|
2023-05-11 07:26:12 -05:00
|
|
|
|
2019-03-21 10:06:55 -05:00
|
|
|
// @ts-ignore
|
2022-10-05 05:10:29 -05:00
|
|
|
import lightTheme from './grafana.light.scss';
|
2019-03-21 10:06:55 -05:00
|
|
|
// @ts-ignore
|
2022-10-05 05:10:29 -05:00
|
|
|
import darkTheme from './grafana.dark.scss';
|
2024-04-23 03:09:08 -05:00
|
|
|
import { GrafanaDark, GrafanaLight } from './storybookTheme';
|
2019-01-09 02:40:57 -06:00
|
|
|
|
2019-10-21 09:39:43 -05:00
|
|
|
const handleThemeChange = (theme: any) => {
|
2019-03-21 10:06:55 -05:00
|
|
|
if (theme !== 'light') {
|
|
|
|
lightTheme.unuse();
|
|
|
|
darkTheme.use();
|
|
|
|
} else {
|
|
|
|
darkTheme.unuse();
|
|
|
|
lightTheme.use();
|
|
|
|
}
|
|
|
|
};
|
2019-02-06 10:03:42 -06:00
|
|
|
|
2023-05-11 07:26:12 -05:00
|
|
|
const preview: Preview = {
|
2024-04-23 03:09:08 -05:00
|
|
|
decorators: [withTheme(handleThemeChange), withTimeZone()],
|
2023-05-11 07:26:12 -05:00
|
|
|
parameters: {
|
|
|
|
actions: { argTypesRegex: '^on[A-Z].*' },
|
|
|
|
darkMode: {
|
|
|
|
dark: GrafanaDark,
|
|
|
|
light: GrafanaLight,
|
|
|
|
},
|
|
|
|
docs: {
|
|
|
|
container: ThemedDocsContainer,
|
|
|
|
},
|
|
|
|
knobs: {
|
|
|
|
disable: true,
|
|
|
|
},
|
|
|
|
layout: 'fullscreen',
|
|
|
|
options: {
|
|
|
|
// Sort stories first by Docs Overview, then alphabetically
|
|
|
|
// We should be able to use the builtin alphabetical sort, but is broken in SB 7.0
|
|
|
|
// https://github.com/storybookjs/storybook/issues/22470
|
|
|
|
storySort: (a, b) => {
|
2024-02-16 05:13:50 -06:00
|
|
|
// Skip sorting for stories with nosort tag
|
|
|
|
if (a.tags.includes('nosort') || b.tags.includes('nosort')) {
|
|
|
|
return 0;
|
|
|
|
}
|
2023-05-11 07:26:12 -05:00
|
|
|
if (a.title.startsWith('Docs Overview')) {
|
|
|
|
if (b.title.startsWith('Docs Overview')) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
} else if (b.title.startsWith('Docs Overview')) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return a.id === b.id ? 0 : a.id.localeCompare(b.id, undefined, { numeric: true });
|
|
|
|
},
|
2020-04-15 14:51:20 -05:00
|
|
|
},
|
2019-10-21 09:39:43 -05:00
|
|
|
},
|
2024-04-23 03:09:08 -05:00
|
|
|
globalTypes: {
|
|
|
|
timeZone: {
|
|
|
|
description: 'Set the timezone for the storybook preview',
|
|
|
|
defaultValue: getTimeZone(),
|
|
|
|
toolbar: {
|
|
|
|
icon: 'globe',
|
|
|
|
items: getTimeZones(true)
|
|
|
|
.filter((timezone) => !!timezone)
|
|
|
|
.map((timezone) => ({
|
|
|
|
title: timezone,
|
|
|
|
value: timezone,
|
|
|
|
})),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2020-11-24 03:38:41 -06:00
|
|
|
};
|
2023-05-11 07:26:12 -05:00
|
|
|
|
|
|
|
export default preview;
|