(false);
/**
* Handles setting global context values. Stub for theme and background addons
@@ -67,6 +69,7 @@ export function useGlobalsParameters(): GlobalParameters {
setThemeId(themeIdFromParams);
setTogglesJSON(JSON.stringify(globals.toggles ?? '{}'));
applyThemeCSS(themeIdFromParams);
+ setResize(parameters?.resize);
}
// using toggles object creates an infinite update loop, thus using JSON state.
@@ -76,6 +79,7 @@ export function useGlobalsParameters(): GlobalParameters {
themeId,
backgroundId,
toggles,
+ resize,
setParams,
};
}
diff --git a/storybook/stories/metric/1_basic.story.tsx b/storybook/stories/metric/1_basic.story.tsx
index 7f02afc330..fca6f2f987 100644
--- a/storybook/stories/metric/1_basic.story.tsx
+++ b/storybook/stories/metric/1_basic.story.tsx
@@ -117,40 +117,35 @@ export const Example: ChartsStory = (_, { title: storyTitle, description }) => {
const configuredData = [[numberTextSwitch ? numericData : textualData]];
return (
-
-
- {
- if (isMetricElementEvent(d)) {
- const { rowIndex, columnIndex } = d;
- onEventClickAction(
- `row:${rowIndex} col:${columnIndex} value:${configuredData[rowIndex][columnIndex].value}`,
- );
- }
- }}
- onElementOver={([d]) => {
- if (isMetricElementEvent(d)) {
- const { rowIndex, columnIndex } = d;
- onEventOverAction(
- `row:${rowIndex} col:${columnIndex} value:${configuredData[rowIndex][columnIndex].value}`,
- );
- }
- }}
- onElementOut={() => onEventOutAction('out')}
- />
-
-
-
+
+ {
+ if (isMetricElementEvent(d)) {
+ const { rowIndex, columnIndex } = d;
+ onEventClickAction(
+ `row:${rowIndex} col:${columnIndex} value:${configuredData[rowIndex][columnIndex].value}`,
+ );
+ }
+ }}
+ onElementOver={([d]) => {
+ if (isMetricElementEvent(d)) {
+ const { rowIndex, columnIndex } = d;
+ onEventOverAction(
+ `row:${rowIndex} col:${columnIndex} value:${configuredData[rowIndex][columnIndex].value}`,
+ );
+ }
+ }}
+ onElementOut={() => onEventOutAction('out')}
+ />
+
+
);
};
+
+Example.parameters = {
+ resize: {
+ height: '200px',
+ width: '200px',
+ },
+};
diff --git a/storybook/stories/test_cases/11_resize_debounce.story.tsx b/storybook/stories/test_cases/11_resize_debounce.story.tsx
index 12e9dcbee0..f368f81344 100644
--- a/storybook/stories/test_cases/11_resize_debounce.story.tsx
+++ b/storybook/stories/test_cases/11_resize_debounce.story.tsx
@@ -37,57 +37,46 @@ export const Example: ChartsStory = (_, { title, description }) => {
const resizeDebounce = number('resizeDebounce (ms)', 10, { min: 0, step: 20 });
const cardinality = number('cardinality', 100, { min: 1, max: maxCardinality });
return (
-
-
-
-
-
+
+
+
+
- values.slice(0, cardinality).map(({ v, cat }) => ({ t, v, cat })))}
- />
-
-
+ values.slice(0, cardinality).map(({ v, cat }) => ({ t, v, cat })))}
+ />
+
);
};
Example.parameters = {
markdown: `The \`resizeDebounce\` option on the \`Settings\` spec provides control over the eagerness of the chart to re-render upon resize. A value of \`0\` will remove the debounce altogether.
You can play with the cardinality and debounce time to see how the debouncing affects the chart render timing`,
+ resize: true,
};
diff --git a/storybook/story_wrapper.tsx b/storybook/story_wrapper.tsx
index a413305430..8a6d9ff2fe 100644
--- a/storybook/story_wrapper.tsx
+++ b/storybook/story_wrapper.tsx
@@ -9,24 +9,35 @@
import { EuiProvider, EuiMarkdownFormat, EuiFlexGroup, EuiFlexItem, EuiHorizontalRule, EuiText } from '@elastic/eui';
import { DecoratorFunction } from '@storybook/addons';
import classNames from 'classnames';
-import React from 'react';
+import React, { FC, PropsWithChildren } from 'react';
+import { StoryGlobals, StoryParameters } from './types';
import { ThemeId, ThemeIdProvider, BackgroundIdProvider } from './use_base_theme';
+const ResizeWrapper: FC> = ({ resize, children }) =>
+ resize ? (
+
+ {children}
+
+ ) : (
+ <>{children}>
+ );
+
export const StoryWrapper: DecoratorFunction = (Story, context) => {
if (!Story) return No Story
;
- const { globals, parameters } = context;
+ const globals = (context.globals as StoryGlobals) ?? {};
+ const parameters = (context.parameters as StoryParameters) ?? {};
- const themeId = globals?.theme ?? ThemeId.Light;
- const backgroundId = globals?.background;
+ const themeId = (globals.theme as ThemeId) ?? ThemeId.Light;
+ const backgroundId = globals.background;
const {
showHeader = false,
showChartTitle = false,
showChartDescription = false,
showChartBoundary = false,
- } = globals?.toggles ?? {};
- const markdown = parameters?.markdown;
+ } = globals.toggles ?? {};
+ const { markdown, resize } = parameters;
const colorMode = themeId.includes('light') ? 'light' : 'dark';
return (
@@ -56,11 +67,13 @@ export const StoryWrapper: DecoratorFunction = (Story, context) =>
-
+
+
+
{markdown && (
diff --git a/storybook/style.scss b/storybook/style.scss
index 226e3abab3..f46b3eded2 100644
--- a/storybook/style.scss
+++ b/storybook/style.scss
@@ -141,6 +141,15 @@ body {
}
}
+#story-resize-wrapper {
+ resize: both;
+ height: 100%;
+ width: 100%;
+ overflow: auto;
+ max-width: 100%;
+ max-height: 80vh;
+}
+
#story-header {
padding: 20px 40px 16px;
}
diff --git a/storybook/types.ts b/storybook/types.ts
index d96a5c3530..5d4e502013 100644
--- a/storybook/types.ts
+++ b/storybook/types.ts
@@ -8,7 +8,7 @@
import type { Parameters as SBParameters } from '@storybook/addons';
import { ArgTypes, Args, StoryContext as SBStoryContext } from '@storybook/react';
-import { ReactElement } from 'react';
+import { CSSProperties, ReactElement } from 'react';
import { StoryBackgroundParameter, BackgroundGlobals } from 'storybook-addon-background-toggle';
import { StoryThemeParameter, ThemeGlobals } from 'storybook-addon-theme-toggle';
import { StoryTogglesParameter, TogglesGlobals } from 'storybook-addon-toggles';
@@ -16,7 +16,7 @@ import { StoryTogglesParameter, TogglesGlobals } from 'storybook-addon-toggles';
/**
* Parameter accessible at the story level
*/
-type StoryParameters = SBParameters &
+export type StoryParameters = SBParameters &
StoryThemeParameter &
StoryBackgroundParameter &
StoryTogglesParameter & {
@@ -24,6 +24,10 @@ type StoryParameters = SBParameters &
* Renders markdown content below story
*/
markdown?: string;
+ /**
+ * Defines resize wrapper under `#story-root` to define
+ */
+ resize?: boolean | CSSProperties;
};
export type StoryGlobals = ThemeGlobals & BackgroundGlobals & TogglesGlobals;