Skip to content

Commit

Permalink
[storybook] Move row height stories to their own file/subdir
Browse files Browse the repository at this point in the history
- allows us to expand props documentation & use controls for `rowHeightsOptions`

+ add test for lineHeight
  • Loading branch information
cee-chen committed Sep 6, 2024
1 parent 405e81e commit d7d7e53
Show file tree
Hide file tree
Showing 19 changed files with 106 additions and 73 deletions.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
73 changes: 0 additions & 73 deletions packages/eui/src/components/datagrid/data_grid.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,79 +60,6 @@ export const Virtualization: Story = {
render: (args: EuiDataGridProps) => <StatefulDataGrid {...args} />,
};

export const HeightLineCount: Story = {
parameters: {
controls: {
include: ['gridStyle', 'rowHeightsOptions', 'width', 'height'],
},
},
args: {
...defaultStorybookArgs,
rowCount: 5,
width: '700px',
toolbarVisibility: false,
rowHeightsOptions: {
defaultHeight: {
lineCount: 1,
},
lineHeight: undefined,
scrollAnchorRow: undefined,
},
},
render: (args: EuiDataGridProps) => <StatefulDataGrid {...args} />,
};

export const RowHeight: Story = {
parameters: {
controls: {
include: ['gridStyle', 'rowHeightsOptions', 'width', 'height'],
},
},
args: {
...defaultStorybookArgs,
rowCount: 5,
toolbarVisibility: false,
rowHeightsOptions: {
defaultHeight: {
height: 48,
},
rowHeights: {},
lineHeight: undefined,
scrollAnchorRow: undefined,
},
},
render: (args: EuiDataGridProps) => <StatefulDataGrid {...args} />,
};

export const CustomRowHeights: Story = {
parameters: {
controls: {
include: ['gridStyle', 'rowHeightsOptions', 'width', 'height'],
},
},
args: {
...defaultStorybookArgs,
rowCount: 5,
width: '700px',
toolbarVisibility: false,
rowHeightsOptions: {
defaultHeight: {
lineCount: 1,
},
rowHeights: {
2: 'auto',
3: 48,
4: {
height: 48,
},
},
lineHeight: undefined,
scrollAnchorRow: undefined,
},
},
render: (args: EuiDataGridProps) => <StatefulDataGrid {...args} />,
};

const CustomHeaderCell = ({ title }: { title: string }) => (
<>
<span>{title}</span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import type {
EuiDataGridColumnSortingConfig,
EuiDataGridProps,
EuiDataGridStyle,
EuiDataGridRowHeightsOptions,
EuiDataGridToolBarVisibilityOptions,
EuiDataGridToolBarAdditionalControlsOptions,
} from './data_grid_types';
Expand Down Expand Up @@ -382,3 +383,7 @@ export const EuiDataGridToolbarPropsComponent: FunctionComponent<
export const EuiDataGridStylePropsComponent: FunctionComponent<
EuiDataGridStyle
> = () => <></>;

export const EuiDataGridRowHeightsPropsComponent: FunctionComponent<
EuiDataGridRowHeightsOptions
> = () => <></>;
101 changes: 101 additions & 0 deletions packages/eui/src/components/datagrid/data_grid_row_heights.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import React from 'react';
import type { Meta, StoryObj } from '@storybook/react';
import { enableFunctionToggleControls } from '../../../.storybook/utils';

import {
StatefulDataGrid,
defaultStorybookArgs,
EuiDataGridRowHeightsPropsComponent,
} from './data_grid.stories.utils';
import type { EuiDataGridRowHeightsOptions } from './data_grid_types';

const meta: Meta<EuiDataGridRowHeightsOptions> = {
title: 'Tabular Content/EuiDataGrid/Row Heights',
component: EuiDataGridRowHeightsPropsComponent,
parameters: {
codeSnippet: {
snippet: `<EuiDataGrid rowHeightOptions={{{STORY_ARGS}}} />`,
},
},
};
enableFunctionToggleControls(meta, ['onChange']);

export default meta;
type Story = StoryObj<EuiDataGridRowHeightsOptions>;

const storyArgs = {
...defaultStorybookArgs,
width: 800, // make it easier to test wrapping text
rowCount: 5, // make VRT screenshots smaller
};

export const Auto: Story = {
args: {
defaultHeight: 'auto',
},
render: (rowHeightsOptions) => (
<StatefulDataGrid {...storyArgs} rowHeightsOptions={rowHeightsOptions} />
),
};

export const LineCount: Story = {
args: {
defaultHeight: { lineCount: 2 },
},
render: (rowHeightsOptions) => (
<StatefulDataGrid
{...storyArgs}
rowHeightsOptions={rowHeightsOptions}
// Visual regression test for https://github.com/elastic/eui/issues/7780
// Last two rows of the 'Location' column should *not* have any
// barely visible text below the ... line-clamp truncation
gridStyle={{ fontSize: 'm', cellPadding: 'l' }}
/>
),
};

export const StaticHeight: Story = {
args: {
defaultHeight: { height: 48 },
},
render: (rowHeightsOptions) => (
<StatefulDataGrid {...storyArgs} rowHeightsOptions={rowHeightsOptions} />
),
};

export const CustomRowHeights: Story = {
parameters: { controls: { include: ['rowHeights'] } },
args: {
rowHeights: {
2: 'auto',
3: 48,
4: {
height: 56,
},
5: {
lineCount: 2,
},
},
},
render: (rowHeightsOptions) => (
<StatefulDataGrid {...storyArgs} rowHeightsOptions={rowHeightsOptions} />
),
};

export const CustomLineHeight: Story = {
parameters: { controls: { include: ['lineHeight'] } },
args: {
lineHeight: '40px',
},
render: (rowHeightsOptions) => (
<StatefulDataGrid {...storyArgs} rowHeightsOptions={rowHeightsOptions} />
),
};

0 comments on commit d7d7e53

Please sign in to comment.