-
Notifications
You must be signed in to change notification settings - Fork 861
[Storybook] Add stories for more components (leftovers) #7797
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
mgadewoll
merged 10 commits into
elastic:main
from
mgadewoll:storybook/add-missing-stories
Jun 4, 2024
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
e22819f
docs(storybook): add EuiBasicTable stories
mgadewoll d5e8bdd
test(VRT): add basic table reference images
mgadewoll 7230a26
styles: clenaup
mgadewoll 7376ab2
docs(storybook): add auto refresh component stories
mgadewoll 12a9a6a
test(VRT): add auto refresh reference images
mgadewoll 2d9f676
docs(storybook): add EuiDatePickerRange stories
mgadewoll 2d9419e
test(VRT): add date picker range reference images
mgadewoll 412c312
docs(storybook): add EuiSuperDatePicker component stories
mgadewoll 5c9e055
test(VRT): add super date picker reference images
mgadewoll b8d8ecc
docs(storybook): ensure controls update the playground
mgadewoll File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Binary file added
BIN
+1.11 KB
...ference/chrome_desktop_Forms_EuiAutoRefresh_EuiAutoRefreshButton_Playground.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+2.57 KB
...oki/reference/chrome_desktop_Forms_EuiAutoRefresh_EuiAutoRefresh_Playground.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+1.26 KB
...ages/eui/.loki/reference/chrome_desktop_Forms_EuiDatePickerRange_Playground.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+4.45 KB
...ages/eui/.loki/reference/chrome_desktop_Forms_EuiRefreshInterval_Playground.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+4.37 KB
...sktop_Forms_EuiSuperDatePicker_EuiSuperDatePicker_Custom_Quick_Select_Panel.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+4.37 KB
...rence/chrome_desktop_Forms_EuiSuperDatePicker_EuiSuperDatePicker_Playground.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+1.75 KB
...nce/chrome_desktop_Forms_EuiSuperDatePicker_EuiSuperUpdateButton_Playground.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+37.2 KB
...i/.loki/reference/chrome_desktop_Tabular_Content_EuiBasicTable_Expanded_Row.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+37.3 KB
...eui/.loki/reference/chrome_desktop_Tabular_Content_EuiBasicTable_Playground.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+2.48 KB
...eference/chrome_mobile_Forms_EuiAutoRefresh_EuiAutoRefreshButton_Playground.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+6.77 KB
...loki/reference/chrome_mobile_Forms_EuiAutoRefresh_EuiAutoRefresh_Playground.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+2.04 KB
packages/eui/.loki/reference/chrome_mobile_Forms_EuiDatePickerRange_Playground.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+9.8 KB
packages/eui/.loki/reference/chrome_mobile_Forms_EuiRefreshInterval_Playground.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+7.62 KB
...obile_Forms_EuiSuperDatePicker_EuiSuperDatePicker_Custom_Quick_Select_Panel.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+7.62 KB
...erence/chrome_mobile_Forms_EuiSuperDatePicker_EuiSuperDatePicker_Playground.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+1.58 KB
...ence/chrome_mobile_Forms_EuiSuperDatePicker_EuiSuperUpdateButton_Playground.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+112 KB
...ui/.loki/reference/chrome_mobile_Tabular_Content_EuiBasicTable_Expanded_Row.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+120 KB
.../eui/.loki/reference/chrome_mobile_Tabular_Content_EuiBasicTable_Playground.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
299 changes: 299 additions & 0 deletions
299
packages/eui/src/components/basic_table/basic_table.stories.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,299 @@ | ||
| /* | ||
| * 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, { useCallback, useEffect, useState } from 'react'; | ||
| import type { Meta, StoryObj } from '@storybook/react'; | ||
| import { action } from '@storybook/addon-actions'; | ||
| import { faker } from '@faker-js/faker'; | ||
| import { moveStorybookControlsToCategory } from '../../../.storybook/utils'; | ||
|
|
||
| import { EuiLink } from '../link'; | ||
| import { EuiHealth } from '../health'; | ||
|
|
||
| import type { | ||
| CriteriaWithPagination, | ||
| EuiBasicTableColumn, | ||
| } from './basic_table'; | ||
| import { EuiBasicTable, EuiBasicTableProps } from './basic_table'; | ||
|
|
||
| // Set static seed so that the generated faker data is consistent between page loads | ||
| faker.seed(8_02_2010); | ||
|
|
||
| const meta: Meta<EuiBasicTableProps<User>> = { | ||
| title: 'Tabular Content/EuiBasicTable', | ||
| // @ts-ignore complex | ||
| component: EuiBasicTable, | ||
| argTypes: { | ||
| noItemsMessage: { control: 'text' }, | ||
| }, | ||
| args: { | ||
| error: '', | ||
| loading: false, | ||
| // Inherited from EuiTable | ||
| responsiveBreakpoint: 'm', | ||
| tableLayout: 'fixed', | ||
| // set up for easier testing/QA | ||
| cellProps: { | ||
| 'data-test-subj': `basic-table-cell`, | ||
| }, | ||
| rowProps: { | ||
| 'data-test-subj': `basic-table-row`, | ||
| }, | ||
| noItemsMessage: '', | ||
| }, | ||
| }; | ||
| moveStorybookControlsToCategory( | ||
| meta, | ||
| ['responsiveBreakpoint', 'tableLayout'], | ||
| 'EuiTable props' | ||
| ); | ||
|
|
||
| export default meta; | ||
| type Story = StoryObj<EuiBasicTableProps<User>>; | ||
|
|
||
| type User = { | ||
| id: number; | ||
| firstName: string | null | undefined; | ||
| lastName: string; | ||
| online: boolean; | ||
| location: { | ||
| city: string; | ||
| country: string; | ||
| }; | ||
| }; | ||
|
|
||
| const users: User[] = []; | ||
|
|
||
| for (let i = 0; i < 5; i++) { | ||
| users.push({ | ||
| id: i + 1, | ||
| firstName: faker.person.firstName(), | ||
| lastName: faker.person.lastName(), | ||
| online: faker.datatype.boolean(), | ||
| location: { | ||
| city: faker.location.city(), | ||
| country: faker.location.country(), | ||
| }, | ||
| }); | ||
| } | ||
|
|
||
| const columns: Array<EuiBasicTableColumn<User>> = [ | ||
| { | ||
| field: 'firstName', | ||
| name: 'First Name', | ||
| sortable: true, | ||
| truncateText: true, | ||
| mobileOptions: { | ||
| render: (user: User) => ( | ||
| <span> | ||
| {user.firstName} {user.lastName} | ||
| </span> | ||
| ), | ||
| header: false, | ||
| truncateText: false, | ||
| enlarge: true, | ||
| width: '100%', | ||
| }, | ||
| }, | ||
| { | ||
| field: 'lastName', | ||
| name: 'Last Name', | ||
| truncateText: true, | ||
| sortable: true, | ||
| mobileOptions: { | ||
| show: false, | ||
| }, | ||
| }, | ||
| { | ||
| field: 'location', | ||
| name: 'Location', | ||
| truncateText: true, | ||
| textOnly: true, | ||
| render: (location: User['location']) => { | ||
| return `${location.city}, ${location.country}`; | ||
| }, | ||
| }, | ||
| { | ||
| field: 'online', | ||
| name: 'Online', | ||
| dataType: 'boolean', | ||
| render: (online: User['online']) => { | ||
| const color = online ? 'success' : 'danger'; | ||
| const label = online ? 'Online' : 'Offline'; | ||
| return <EuiHealth color={color}>{label}</EuiHealth>; | ||
| }, | ||
| sortable: true, | ||
| mobileOptions: { | ||
| show: false, | ||
| }, | ||
| }, | ||
| { | ||
| name: 'Actions', | ||
| actions: [ | ||
| { | ||
| name: 'User profile', | ||
| description: ({ firstName, lastName }) => | ||
| `Visit ${firstName} ${lastName}'s profile`, | ||
| icon: 'editorLink', | ||
| color: 'primary', | ||
| type: 'icon', | ||
| enabled: ({ online }) => !!online, | ||
| href: ({ id }) => `${window.location.href}?id=${id}`, | ||
| target: '_self', | ||
| 'data-test-subj': 'action-outboundlink', | ||
| }, | ||
| { | ||
| name: <>Clone</>, | ||
| description: 'Clone this user', | ||
| icon: 'copy', | ||
| type: 'icon', | ||
| onClick: () => {}, | ||
| 'data-test-subj': 'action-clone', | ||
| }, | ||
| { | ||
| name: (user: User) => (user.id ? 'Delete' : 'Remove'), | ||
| description: ({ firstName, lastName }) => | ||
| `Delete ${firstName} ${lastName}`, | ||
| icon: 'trash', | ||
| color: 'danger', | ||
| type: 'icon', | ||
| onClick: () => {}, | ||
| isPrimary: true, | ||
| 'data-test-subj': ({ id }) => `action-delete-${id}`, | ||
| }, | ||
| { | ||
| name: 'Edit', | ||
| isPrimary: true, | ||
| available: ({ online }) => !online, | ||
| enabled: ({ online }) => !!online, | ||
| description: 'Edit this user', | ||
| icon: 'pencil', | ||
| type: 'icon', | ||
| onClick: () => {}, | ||
| 'data-test-subj': 'action-edit', | ||
| }, | ||
| { | ||
| name: 'Share', | ||
| isPrimary: true, | ||
| description: 'Share this user', | ||
| icon: 'share', | ||
| type: 'icon', | ||
| onClick: () => {}, | ||
| 'data-test-subj': 'action-share', | ||
| }, | ||
| ], | ||
| }, | ||
| { | ||
| name: 'Custom actions', | ||
| actions: [ | ||
| { | ||
| render: () => ( | ||
| <EuiLink onClick={() => {}} color="danger"> | ||
| Delete | ||
| </EuiLink> | ||
| ), | ||
| showOnHover: true, | ||
| }, | ||
| { | ||
| render: () => <EuiLink onClick={() => {}}>Edit</EuiLink>, | ||
| }, | ||
| ], | ||
| }, | ||
| ]; | ||
|
|
||
| const initialPageSize = 3; | ||
|
|
||
| export const Playground: Story = { | ||
| args: { | ||
| tableCaption: 'EuiBasicTable playground', | ||
| items: users, | ||
| itemId: 'id', | ||
| rowHeader: 'firstName', | ||
| columns, | ||
| itemIdToExpandedRowMap: {}, | ||
| pagination: { | ||
| pageIndex: 0, | ||
| totalItemCount: 5, | ||
| pageSize: initialPageSize, | ||
| pageSizeOptions: [3, 5], | ||
| }, | ||
| sorting: { | ||
| sort: { | ||
| field: 'lastName', | ||
| direction: 'asc' as const, | ||
| }, | ||
| }, | ||
| selection: { | ||
| selectable: (user) => user.online, | ||
| selectableMessage: (selectable) => | ||
| !selectable ? 'User is currently offline' : '', | ||
| onSelectionChange: action('onSelectionChange'), | ||
| }, | ||
| onChange: (criteria: CriteriaWithPagination<User>) => | ||
| action('onChange')(criteria), | ||
| }, | ||
| render: (args: EuiBasicTableProps<User>) => <StatefulPlayground {...args} />, | ||
| }; | ||
|
|
||
| export const ExpandedRow: Story = { | ||
| parameters: { | ||
| controls: { | ||
| include: ['columns', 'items', 'itemIdToExpandedRowMap'], | ||
| }, | ||
| }, | ||
| args: { | ||
| tableCaption: 'EuiBasicTable playground', | ||
| items: users, | ||
| itemId: 'id', | ||
| rowHeader: 'firstName', | ||
| columns, | ||
| itemIdToExpandedRowMap: { | ||
| 1: ( | ||
| <div> | ||
| <strong>Expanded row 1</strong> | ||
| <p>lorem ipsum dolor sit</p> | ||
| </div> | ||
| ), | ||
| }, | ||
| }, | ||
| }; | ||
|
|
||
| const StatefulPlayground = ({ | ||
| items, | ||
| pagination, | ||
| sorting, | ||
| ...rest | ||
| }: EuiBasicTableProps<User>) => { | ||
| const [_items, setItems] = useState<User[]>([]); | ||
|
|
||
| const updateItems = useCallback(() => { | ||
| let sortedItems = [...items]; | ||
|
|
||
| if (sorting?.sort) { | ||
| const { field, direction } = sorting?.sort; | ||
| const directionIndex = direction === 'desc' ? -1 : 1; | ||
|
|
||
| sortedItems = sortedItems.sort((a, b) => | ||
| a[field]! > b[field]! ? directionIndex : -directionIndex | ||
| ); | ||
| } | ||
|
|
||
| setItems(() => { | ||
| return [...sortedItems].splice( | ||
| 0, | ||
| pagination?.pageSize ?? initialPageSize | ||
| ); | ||
| }); | ||
| }, [items, pagination, sorting]); | ||
|
|
||
| useEffect(() => { | ||
| updateItems(); | ||
| }, [items, pagination, sorting, updateItems]); | ||
|
|
||
| return <EuiBasicTable items={_items} pagination={pagination!} {...rest} />; | ||
| }; | ||
56 changes: 56 additions & 0 deletions
56
packages/eui/src/components/date_picker/auto_refresh/auto_refresh.stories.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| /* | ||
| * 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 type { Meta, StoryObj } from '@storybook/react'; | ||
|
|
||
| import { enableFunctionToggleControls } from '../../../../.storybook/utils'; | ||
| import { REFRESH_UNIT_OPTIONS } from '../types'; | ||
|
|
||
| import { EuiAutoRefresh, EuiAutoRefreshProps } from './auto_refresh'; | ||
|
|
||
| const meta: Meta<EuiAutoRefreshProps> = { | ||
| title: 'Forms/EuiAutoRefresh/EuiAutoRefresh', | ||
| component: EuiAutoRefresh, | ||
| parameters: { | ||
| loki: { | ||
| // TODO: uncomment once loki CLI is fixed for portal component stories | ||
| // chromeSelector: LOKI_SELECTORS.portal, | ||
| }, | ||
| }, | ||
| argTypes: { | ||
| intervalUnits: { | ||
| control: 'radio', | ||
| options: [undefined, ...REFRESH_UNIT_OPTIONS], | ||
| }, | ||
| }, | ||
| args: { | ||
| isPaused: true, | ||
| refreshInterval: 1000, | ||
| minInterval: 0, | ||
| readOnly: true, | ||
| isDisabled: false, | ||
| }, | ||
| }; | ||
| enableFunctionToggleControls(meta, ['onRefreshChange']); | ||
|
|
||
| export default meta; | ||
| type Story = StoryObj<EuiAutoRefreshProps>; | ||
|
|
||
| export const Playground: Story = { | ||
| // TODO: uncomment once loki CLI is fixed for portal component stories | ||
| // play: lokiPlayDecorator(async (context) => { | ||
| // const { bodyElement, step } = context; | ||
| // const canvas = within(bodyElement); | ||
| // await step('show popover on click of the input', async () => { | ||
| // await userEvent.click(canvas.getByLabelText('Auto refresh')); | ||
| // await waitFor(() => { | ||
| // expect(canvas.getByRole('dialog')).toBeVisible(); | ||
| // }); | ||
| // }); | ||
| // }), | ||
| }; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.