Commit f9c8d5ab by Peter Holmberg Committed by GitHub

grafana/ui: Migrate Field knobs to controls (#29433)

* migrate knobs to controls

* default value for error

* some fix after review
parent 3018c6a1
...@@ -20,17 +20,13 @@ export default { ...@@ -20,17 +20,13 @@ export default {
docs: { docs: {
page: mdx, page: mdx,
}, },
knobs: {
disabled: true,
},
}, },
}; };
export const Simple: Story<ButtonProps> = ({ disabled, icon, children, size, variant }) => { export const Simple: Story<ButtonProps> = ({ children, ...args }) => <Button {...args}>{children}</Button>;
return (
<Button variant={variant} size={size} icon={icon} disabled={disabled}>
{children}
</Button>
);
};
Simple.args = { Simple.args = {
variant: 'primary', variant: 'primary',
size: 'md', size: 'md',
......
import React, { useState, useCallback } from 'react'; import React, { useState, useCallback } from 'react';
import { boolean, number, text } from '@storybook/addon-knobs'; import { Story } from '@storybook/react';
import { Field, Input, Switch } from '@grafana/ui'; import { Field, FieldProps } from './Field';
import { Input, Switch } from '..';
import mdx from './Field.mdx'; import mdx from './Field.mdx';
export default { export default {
title: 'Forms/Field', title: 'Forms/Field',
component: Field, component: Field,
argTypes: {
children: { control: { disable: true } },
className: { control: { disable: true } },
},
parameters: { parameters: {
docs: { docs: {
page: mdx, page: mdx,
}, },
knobs: {
disabled: true,
},
}, },
}; };
const getKnobs = () => { export const Simple: Story<FieldProps> = args => (
const CONTAINER_GROUP = 'Container options'; <div>
// --- <Field {...args}>
const containerWidth = number( <Input id="thisField" />
'Container width', </Field>
300, </div>
{ );
range: true,
min: 100,
max: 500,
step: 10,
},
CONTAINER_GROUP
);
const BEHAVIOUR_GROUP = 'Behaviour props'; Simple.args = {
const disabled = boolean('Disabled', false, BEHAVIOUR_GROUP); label: 'Graphite API key',
const invalid = boolean('Invalid', false, BEHAVIOUR_GROUP); description: 'Your Graphite instance API key',
const loading = boolean('Loading', false, BEHAVIOUR_GROUP); disabled: false,
const error = text('Error message', '', BEHAVIOUR_GROUP); invalid: false,
loading: false,
return { containerWidth, disabled, invalid, loading, error }; error: 'Not valid input',
horizontal: false,
}; };
export const Simple = () => { export const HorizontalLayout: Story<FieldProps> = args => {
const { containerWidth, ...otherProps } = getKnobs();
return (
<div style={{ width: containerWidth }}>
<Field label="Graphite API key" description="Your Graphite instance API key" {...otherProps}>
<Input id="thisField" />
</Field>
</div>
);
};
export const HorizontalLayout = () => {
const [checked, setChecked] = useState(false); const [checked, setChecked] = useState(false);
const onChange = useCallback(e => setChecked(e.currentTarget.checked), [setChecked]); const onChange = useCallback(e => setChecked(e.currentTarget.checked), [setChecked]);
const { containerWidth, ...otherProps } = getKnobs();
return ( return (
<div style={{ width: containerWidth }}> <div>
<Field horizontal label="Show labels" description="Display thresholds's labels" {...otherProps}> <Field {...args}>
<Switch checked={checked} onChange={onChange} /> <Switch checked={checked} onChange={onChange} />
</Field> </Field>
</div> </div>
); );
}; };
HorizontalLayout.args = {
label: 'Show labels',
description: 'Display threshold labels',
disabled: false,
invalid: false,
loading: false,
error: 'Not valid input',
horizontal: true,
};
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment