Skip to content
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

[Storybook] Add playground stories for basic C components #7460

Merged
merged 8 commits into from
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions changelogs/upcoming/7460.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
**Deprecations**

- Remove unused public `EuiHue` and `EuiSaturation` subcomponent exports. Use the parent `EuiColorPicker` component instead
35 changes: 35 additions & 0 deletions src/components/call_out/call_out.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* 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 { EuiCallOut, EuiCallOutProps } from './call_out';

const meta: Meta<EuiCallOutProps> = {
title: 'EuiCallOut',
component: EuiCallOut,
argTypes: {
iconType: { control: 'text' },
},
args: {
// Component defaults
color: 'primary',
heading: 'p',
size: 'm',
},
};

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

export const Playground: Story = {
args: {
title: 'Callout title',
children: 'Callout text',
},
};
70 changes: 70 additions & 0 deletions src/components/card/card.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* 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, { useState } from 'react';
import type { Meta, StoryObj } from '@storybook/react';
import { action } from '@storybook/addon-actions';

import { BACKGROUND_COLORS } from '../../global_styling';
import { EuiIcon } from '../icon';

import { EuiCard, EuiCardProps } from './card';

const meta: Meta<EuiCardProps> = {
title: 'EuiCard',
component: EuiCard,
argTypes: {
display: { options: [undefined, ...BACKGROUND_COLORS] },
image: { control: 'text' },
},
args: {
// Component defaults
hasBorder: false,
paddingSize: 'm',
textAlign: 'center',
titleElement: 'p',
titleSize: 's',
},
};

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

export const Playground: Story = {
argTypes: {
// For quicker/easier testing
onClick: { control: 'boolean' },
selectable: { control: 'boolean' },
icon: { control: 'boolean' },
},
args: {
title: 'Card title',
description: 'Card description',
footer: '',
},
render: function Render({
icon,
selectable,
onClick,
...args
}: EuiCardProps) {
const [isSelected, setIsSelected] = useState(false);
const selectableOnClick = () => setIsSelected((isSelected) => !isSelected);

return (
<EuiCard
onClick={onClick ? action('onClick') : undefined}
icon={icon ? <EuiIcon type="logoElastic" size="xxl" /> : undefined}
selectable={
selectable ? { onClick: selectableOnClick, isSelected } : undefined
}
{...args}
/>
);
},
};
47 changes: 47 additions & 0 deletions src/components/card/checkable_card/checkable_card.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* 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 { action } from '@storybook/addon-actions';

import { EuiCheckableCard, EuiCheckableCardProps } from './checkable_card';

const meta: Meta<EuiCheckableCardProps> = {
title: 'EuiCheckableCard',
component: EuiCheckableCard,
// NOTE: Storybook isn't correctly inheriting certain props due to the exclusive union,
// so we have to do some manual polyfilling
argTypes: {
checkableType: {
options: ['radio', 'checkbox'],
control: 'radio',
},
onChange: {
JasonStoltz marked this conversation as resolved.
Show resolved Hide resolved
type: { name: 'function', required: true },
},
},
args: {
// Component defaults
checkableType: 'radio',
checked: false,
disabled: false,
hasBorder: true,
hasShadow: false,
},
};

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

export const Playground: Story = {
args: {
id: 'id',
label: 'Checkable option',
onChange: action('onChange'),
JasonStoltz marked this conversation as resolved.
Show resolved Hide resolved
},
};
29 changes: 29 additions & 0 deletions src/components/code/code.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* 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 { EuiCode, EuiCodeProps } from './code';

const meta: Meta<EuiCodeProps> = {
title: 'EuiCode',
component: EuiCode,
args: {
JasonStoltz marked this conversation as resolved.
Show resolved Hide resolved
// Component defaults
transparentBackground: false,
},
};

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

export const Playground: Story = {
args: {
children: '<!-- Hello world -->',
},
};
41 changes: 41 additions & 0 deletions src/components/code/code_block.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
JasonStoltz marked this conversation as resolved.
Show resolved Hide resolved
* 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 { EuiCodeBlock, EuiCodeBlockProps } from './code_block';

const meta: Meta<EuiCodeBlockProps> = {
title: 'EuiCodeBlock',
component: EuiCodeBlock,
argTypes: {
lineNumbers: { control: 'boolean' },
overflowHeight: { control: 'number' },
},
args: {
// Component defaults
fontSize: 's',
paddingSize: 'l',
whiteSpace: 'pre-wrap',
lineNumbers: false,
isCopyable: false,
isVirtualized: false,
transparentBackground: false,
},
};

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

export const Playground: Story = {
args: {
children: `<p>
<!-- Hello world -->
</p>`,
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* 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 { euiPaletteColorBlind } from '../../../services';

import {
EuiColorPaletteDisplay,
EuiColorPaletteDisplayProps,
} from './color_palette_display';

const meta: Meta<EuiColorPaletteDisplayProps> = {
title: 'EuiColorPaletteDisplay',
component: EuiColorPaletteDisplay,
args: {
// Component defaults
type: 'fixed',
size: 's',
},
};

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

export const Playground: Story = {
args: {
palette: euiPaletteColorBlind(),
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* 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 { euiPaletteColorBlind } from '../../../services';

import {
EuiColorPalettePicker,
EuiColorPalettePickerProps,
} from './color_palette_picker';

const meta: Meta<EuiColorPalettePickerProps<string>> = {
title: 'EuiColorPalettePicker',
component: EuiColorPalettePicker,
argTypes: {
placeholder: { control: 'text' },
append: { control: 'text' },
prepend: { control: 'text' },
},
args: {
// Component defaults
selectionDisplay: 'palette',
disabled: false,
readOnly: false,
fullWidth: false,
compressed: false,
isLoading: false,
isInvalid: false,
isOpen: false,
},
};

export default meta;
type Story = StoryObj<EuiColorPalettePickerProps<string>>;

export const Playground: Story = {
args: {
palettes: [
{
value: 'palette1',
title: 'Palette 1',
palette: euiPaletteColorBlind(),
type: 'fixed',
},
],
valueOfSelected: 'palette1',
},
};
40 changes: 40 additions & 0 deletions src/components/color_picker/color_picker.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* 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 { EuiColorPicker, EuiColorPickerProps } from './color_picker';

const meta: Meta<EuiColorPickerProps> = {
title: 'EuiColorPicker',
component: EuiColorPicker,
argTypes: {
color: { control: 'color' },
swatches: { control: 'array' }, // TODO: crashes if clicked in Storybook
append: { control: 'text' },
prepend: { control: 'text' },
},
args: {
// Component defaults
showAlpha: false,
disabled: false,
readOnly: false,
fullWidth: false,
compressed: false,
isClearable: false,
isInvalid: false,
display: 'default',
mode: 'default',
secondaryInputDisplay: 'none',
},
};

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

export const Playground: Story = {};
24 changes: 24 additions & 0 deletions src/components/color_picker/color_picker_swatch.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* 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 {
EuiColorPickerSwatch,
EuiColorPickerSwatchProps,
} from './color_picker_swatch';

const meta: Meta<EuiColorPickerSwatchProps> = {
title: 'EuiColorPickerSwatch',
component: EuiColorPickerSwatch,
};

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

export const Playground: Story = {};
4 changes: 0 additions & 4 deletions src/components/color_picker/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@ export type { EuiColorPickerProps } from './color_picker';
export { EuiColorPicker } from './color_picker';
export type { EuiColorPickerSwatchProps } from './color_picker_swatch';
export { EuiColorPickerSwatch } from './color_picker_swatch';
export type { EuiHueProps } from './hue';
export { EuiHue } from './hue';
export type { EuiSaturationProps } from './saturation';
export { EuiSaturation } from './saturation';
export type {
EuiColorPalettePickerProps,
EuiColorPalettePickerPaletteProps,
Expand Down
Loading
Loading