mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Chore: remove UseState from ColorPicker story (#52611)
* remove UseState from ColorPicker story * remove story meta type assertion
This commit is contained in:
@@ -1364,10 +1364,6 @@ exports[`better eslint`] = {
|
|||||||
"packages/grafana-ui/src/components/ClipboardButton/ClipboardButton.story.internal.tsx:5381": [
|
"packages/grafana-ui/src/components/ClipboardButton/ClipboardButton.story.internal.tsx:5381": [
|
||||||
[0, 0, 0, "Do not use any type assertions.", "0"]
|
[0, 0, 0, "Do not use any type assertions.", "0"]
|
||||||
],
|
],
|
||||||
"packages/grafana-ui/src/components/ColorPicker/ColorPicker.story.tsx:5381": [
|
|
||||||
[0, 0, 0, "Do not use any type assertions.", "0"],
|
|
||||||
[0, 0, 0, "Unexpected any. Specify a different type.", "1"]
|
|
||||||
],
|
|
||||||
"packages/grafana-ui/src/components/ColorPicker/ColorPicker.tsx:5381": [
|
"packages/grafana-ui/src/components/ColorPicker/ColorPicker.tsx:5381": [
|
||||||
[0, 0, 0, "Unexpected any. Specify a different type.", "0"],
|
[0, 0, 0, "Unexpected any. Specify a different type.", "0"],
|
||||||
[0, 0, 0, "Unexpected any. Specify a different type.", "1"],
|
[0, 0, 0, "Unexpected any. Specify a different type.", "1"],
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
import { action } from '@storybook/addon-actions';
|
import { action } from '@storybook/addon-actions';
|
||||||
|
import { useArgs } from '@storybook/client-api';
|
||||||
import { Meta, Story } from '@storybook/react';
|
import { Meta, Story } from '@storybook/react';
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
|
||||||
import { SeriesColorPicker, ColorPicker } from '@grafana/ui';
|
import { SeriesColorPicker, ColorPicker } from '@grafana/ui';
|
||||||
|
|
||||||
import { UseState } from '../../utils/storybook/UseState';
|
|
||||||
import { withCenteredStory } from '../../utils/storybook/withCenteredStory';
|
import { withCenteredStory } from '../../utils/storybook/withCenteredStory';
|
||||||
import { renderComponentWithTheme } from '../../utils/storybook/withTheme';
|
import { renderComponentWithTheme } from '../../utils/storybook/withTheme';
|
||||||
|
|
||||||
@@ -12,7 +12,7 @@ import mdx from './ColorPicker.mdx';
|
|||||||
import { ColorPickerInput, ColorPickerInputProps } from './ColorPickerInput';
|
import { ColorPickerInput, ColorPickerInputProps } from './ColorPickerInput';
|
||||||
import { ColorPickerProps } from './ColorPickerPopover';
|
import { ColorPickerProps } from './ColorPickerPopover';
|
||||||
|
|
||||||
export default {
|
const meta: Meta = {
|
||||||
title: 'Pickers and Editors/ColorPicker',
|
title: 'Pickers and Editors/ColorPicker',
|
||||||
component: ColorPicker,
|
component: ColorPicker,
|
||||||
subcomponents: { SeriesColorPicker, ColorPickerInput },
|
subcomponents: { SeriesColorPicker, ColorPickerInput },
|
||||||
@@ -22,66 +22,60 @@ export default {
|
|||||||
page: mdx,
|
page: mdx,
|
||||||
},
|
},
|
||||||
controls: {
|
controls: {
|
||||||
exclude: ['color', 'onChange', 'onColorChange'],
|
exclude: ['onChange', 'onColorChange'],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
args: {
|
args: {
|
||||||
enableNamedColors: false,
|
enableNamedColors: false,
|
||||||
|
color: '#00ff00',
|
||||||
},
|
},
|
||||||
} as Meta;
|
};
|
||||||
|
|
||||||
export const Basic: Story<ColorPickerProps> = ({ enableNamedColors }) => {
|
export const Basic: Story<ColorPickerProps> = ({ color, enableNamedColors }) => {
|
||||||
|
const [, updateArgs] = useArgs();
|
||||||
|
return renderComponentWithTheme(ColorPicker, {
|
||||||
|
enableNamedColors,
|
||||||
|
color,
|
||||||
|
onChange: (color: string) => {
|
||||||
|
action('Color changed')(color);
|
||||||
|
updateArgs({ color });
|
||||||
|
},
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
export const SeriesPicker: Story<ColorPickerProps> = ({ color, enableNamedColors }) => {
|
||||||
|
const [, updateArgs] = useArgs();
|
||||||
return (
|
return (
|
||||||
<UseState initialState="#00ff00">
|
<SeriesColorPicker
|
||||||
{(selectedColor, updateSelectedColor) => {
|
enableNamedColors={enableNamedColors}
|
||||||
return renderComponentWithTheme(ColorPicker, {
|
yaxis={1}
|
||||||
enableNamedColors,
|
onToggleAxis={() => {}}
|
||||||
color: selectedColor,
|
color={color}
|
||||||
onChange: (color: any) => {
|
onChange={(color) => {
|
||||||
action('Color changed')(color);
|
action('Color changed')(color);
|
||||||
updateSelectedColor(color);
|
updateArgs({ color });
|
||||||
},
|
|
||||||
});
|
|
||||||
}}
|
}}
|
||||||
</UseState>
|
>
|
||||||
|
{({ ref, showColorPicker, hideColorPicker }) => (
|
||||||
|
<div ref={ref} onMouseLeave={hideColorPicker} onClick={showColorPicker} style={{ color, cursor: 'pointer' }}>
|
||||||
|
Open color picker
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</SeriesColorPicker>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const SeriesPicker: Story<ColorPickerProps> = ({ enableNamedColors }) => {
|
export const Input: Story<ColorPickerInputProps> = ({ color }) => {
|
||||||
|
const [, updateArgs] = useArgs();
|
||||||
return (
|
return (
|
||||||
<UseState initialState="#00ff00">
|
<ColorPickerInput
|
||||||
{(selectedColor, updateSelectedColor) => {
|
value={color}
|
||||||
return (
|
onChange={(color) => {
|
||||||
<SeriesColorPicker
|
action('Color changed')(color);
|
||||||
enableNamedColors={enableNamedColors}
|
updateArgs({ color });
|
||||||
yaxis={1}
|
|
||||||
onToggleAxis={() => {}}
|
|
||||||
color={selectedColor}
|
|
||||||
onChange={(color) => updateSelectedColor(color)}
|
|
||||||
>
|
|
||||||
{({ ref, showColorPicker, hideColorPicker }) => (
|
|
||||||
<div
|
|
||||||
ref={ref}
|
|
||||||
onMouseLeave={hideColorPicker}
|
|
||||||
onClick={showColorPicker}
|
|
||||||
style={{ color: selectedColor, cursor: 'pointer' }}
|
|
||||||
>
|
|
||||||
Open color picker
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</SeriesColorPicker>
|
|
||||||
);
|
|
||||||
}}
|
}}
|
||||||
</UseState>
|
/>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const Input: Story<ColorPickerInputProps> = () => {
|
export default meta;
|
||||||
return (
|
|
||||||
<UseState initialState="#ffffff">
|
|
||||||
{(value, onChange) => {
|
|
||||||
return <ColorPickerInput value={value} onChange={onChange} />;
|
|
||||||
}}
|
|
||||||
</UseState>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|||||||
Reference in New Issue
Block a user