mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
remove UseState from last 2 stories (#53596)
This commit is contained in:
@@ -2124,10 +2124,6 @@ exports[`better eslint`] = {
|
|||||||
"packages/grafana-ui/src/utils/storybook/ThemedDocsContainer.tsx:5381": [
|
"packages/grafana-ui/src/utils/storybook/ThemedDocsContainer.tsx:5381": [
|
||||||
[0, 0, 0, "Unexpected any. Specify a different type.", "0"]
|
[0, 0, 0, "Unexpected any. Specify a different type.", "0"]
|
||||||
],
|
],
|
||||||
"packages/grafana-ui/src/utils/storybook/UseState.tsx:5381": [
|
|
||||||
[0, 0, 0, "Unexpected any. Specify a different type.", "0"],
|
|
||||||
[0, 0, 0, "Unexpected any. Specify a different type.", "1"]
|
|
||||||
],
|
|
||||||
"packages/grafana-ui/src/utils/storybook/withTheme.tsx:5381": [
|
"packages/grafana-ui/src/utils/storybook/withTheme.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"]
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import React, { useState } from 'react';
|
|||||||
import { Button, Modal, ModalTabsHeader, TabContent } from '@grafana/ui';
|
import { Button, Modal, ModalTabsHeader, TabContent } from '@grafana/ui';
|
||||||
|
|
||||||
import { getAvailableIcons } from '../../types';
|
import { getAvailableIcons } from '../../types';
|
||||||
import { UseState } from '../../utils/storybook/UseState';
|
|
||||||
import { withCenteredStory } from '../../utils/storybook/withCenteredStory';
|
import { withCenteredStory } from '../../utils/storybook/withCenteredStory';
|
||||||
|
|
||||||
import mdx from './Modal.mdx';
|
import mdx from './Modal.mdx';
|
||||||
@@ -88,21 +87,15 @@ export const WithTabs: Story = (args) => {
|
|||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
return (
|
return (
|
||||||
<UseState initialState={tabs}>
|
<div>
|
||||||
{(state, updateState) => {
|
<Modal title={modalHeader} isOpen={true}>
|
||||||
return (
|
<TabContent>
|
||||||
<div>
|
{activeTab === tabs[0].value && <div>{args.body}</div>}
|
||||||
<Modal title={modalHeader} isOpen={true}>
|
{activeTab === tabs[1].value && <div>Second tab content</div>}
|
||||||
<TabContent>
|
{activeTab === tabs[2].value && <div>Third tab content</div>}
|
||||||
{activeTab === state[0].value && <div>{args.body}</div>}
|
</TabContent>
|
||||||
{activeTab === state[1].value && <div>Second tab content</div>}
|
</Modal>
|
||||||
{activeTab === state[2].value && <div>Third tab content</div>}
|
</div>
|
||||||
</TabContent>
|
|
||||||
</Modal>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}}
|
|
||||||
</UseState>
|
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
WithTabs.args = {
|
WithTabs.args = {
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
import { action } from '@storybook/addon-actions';
|
import { action } from '@storybook/addon-actions';
|
||||||
|
import { useArgs } from '@storybook/client-api';
|
||||||
import { ComponentMeta, ComponentStory } from '@storybook/react';
|
import { ComponentMeta, ComponentStory } from '@storybook/react';
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
|
||||||
import { UseState } from '../../utils/storybook/UseState';
|
|
||||||
import { withCenteredStory } from '../../utils/storybook/withCenteredStory';
|
import { withCenteredStory } from '../../utils/storybook/withCenteredStory';
|
||||||
|
|
||||||
import { SecretFormField } from './SecretFormField';
|
import { SecretFormField } from './SecretFormField';
|
||||||
@@ -13,7 +13,7 @@ const meta: ComponentMeta<typeof SecretFormField> = {
|
|||||||
decorators: [withCenteredStory],
|
decorators: [withCenteredStory],
|
||||||
parameters: {
|
parameters: {
|
||||||
controls: {
|
controls: {
|
||||||
exclude: ['onReset'],
|
exclude: ['onChange', 'onReset'],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
argTypes: {
|
argTypes: {
|
||||||
@@ -21,37 +21,32 @@ const meta: ComponentMeta<typeof SecretFormField> = {
|
|||||||
inputWidth: { control: { type: 'range', min: 0, max: 30 } },
|
inputWidth: { control: { type: 'range', min: 0, max: 30 } },
|
||||||
tooltip: { control: { type: 'text' } },
|
tooltip: { control: { type: 'text' } },
|
||||||
},
|
},
|
||||||
|
args: {
|
||||||
|
isConfigured: false,
|
||||||
|
inputWidth: 12,
|
||||||
|
label: 'Secret field',
|
||||||
|
labelWidth: 10,
|
||||||
|
placeholder: 'Password',
|
||||||
|
tooltip: 'this is a tooltip',
|
||||||
|
value: 'mySuperSecretPassword',
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
export const Basic: ComponentStory<typeof SecretFormField> = (args) => {
|
export const Basic: ComponentStory<typeof SecretFormField> = (args) => {
|
||||||
|
const [, updateArgs] = useArgs();
|
||||||
return (
|
return (
|
||||||
<UseState initialState="Input value">
|
<SecretFormField
|
||||||
{(value, setValue) => (
|
{...args}
|
||||||
<SecretFormField
|
onChange={(e) => {
|
||||||
label={args.label}
|
action('onChange')(e);
|
||||||
labelWidth={args.labelWidth}
|
updateArgs({ value: e.currentTarget.value });
|
||||||
value={value}
|
}}
|
||||||
isConfigured={args.isConfigured}
|
onReset={() => {
|
||||||
onChange={(e) => setValue(e.currentTarget.value)}
|
action('onReset')('');
|
||||||
onReset={() => {
|
updateArgs({ value: '' });
|
||||||
action('Value was reset')('');
|
}}
|
||||||
setValue('');
|
/>
|
||||||
}}
|
|
||||||
inputWidth={args.inputWidth}
|
|
||||||
tooltip={args.tooltip}
|
|
||||||
placeholder={args.placeholder}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
</UseState>
|
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
Basic.args = {
|
|
||||||
label: 'Secret field',
|
|
||||||
labelWidth: 10,
|
|
||||||
isConfigured: false,
|
|
||||||
inputWidth: 12,
|
|
||||||
tooltip: 'this is a tooltip',
|
|
||||||
placeholder: 'Password',
|
|
||||||
};
|
|
||||||
|
|
||||||
export default meta;
|
export default meta;
|
||||||
|
|||||||
@@ -1,42 +0,0 @@
|
|||||||
import { action } from '@storybook/addon-actions';
|
|
||||||
import React, { Component } from 'react';
|
|
||||||
|
|
||||||
interface StateHolderProps<T> {
|
|
||||||
logState?: boolean;
|
|
||||||
initialState: T;
|
|
||||||
children: (currentState: T, updateState: (nextState: T) => void) => React.ReactNode;
|
|
||||||
}
|
|
||||||
|
|
||||||
export class UseState<T> extends Component<StateHolderProps<T>, { value: T; initialState: T }> {
|
|
||||||
constructor(props: StateHolderProps<T>) {
|
|
||||||
super(props);
|
|
||||||
this.state = {
|
|
||||||
value: props.initialState,
|
|
||||||
initialState: props.initialState, // To enable control from knobs
|
|
||||||
};
|
|
||||||
}
|
|
||||||
// @ts-ignore
|
|
||||||
static getDerivedStateFromProps(props: StateHolderProps<{}>, state: { value: any; initialState: any }) {
|
|
||||||
if (props.initialState !== state.initialState) {
|
|
||||||
return {
|
|
||||||
initialState: props.initialState,
|
|
||||||
value: props.initialState,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
return {
|
|
||||||
...state,
|
|
||||||
value: state.value,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
handleStateUpdate = (nextState: T) => {
|
|
||||||
this.setState({ value: nextState });
|
|
||||||
};
|
|
||||||
|
|
||||||
render() {
|
|
||||||
if (this.props.logState) {
|
|
||||||
action('UseState current state')(this.state.value);
|
|
||||||
}
|
|
||||||
return this.props.children(this.state.value, this.handleStateUpdate);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user