The open and composable observability and data visualization platform. Visualize metrics, logs, and traces from multiple sources like Prometheus, Loki, Elasticsearch, InfluxDB, Postgres and many more.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
grafana/packages/grafana-ui/src/components/Segment/SegmentInput.story.tsx

85 lines
2.0 KiB

import React, { useState } from 'react';
import { action } from '@storybook/addon-actions';
import { SegmentInput } from '.';
import { Icon } from '../Icon/Icon';
const SegmentFrame = ({ children }: any) => (
<>
<div className="gf-form-inline">
<div className="gf-form">
<span className="gf-form-label width-8 query-keyword">Segment Name</span>
</div>
{children}
</div>
</>
);
export const BasicInput = () => {
const [value, setValue] = useState('some text');
return (
<SegmentFrame>
<SegmentInput
value={value}
onChange={text => {
setValue(text as string);
action('Segment value changed')(text);
}}
/>
</SegmentFrame>
);
};
export default {
title: 'Data Source/Segment/SegmentInput',
component: SegmentInput,
};
export const BasicInputWithPlaceholder = () => {
const [value, setValue] = useState('');
return (
<SegmentFrame>
<SegmentInput
placeholder="add text"
value={value}
onChange={text => {
setValue(text as string);
action('Segment value changed')(text);
}}
/>
</SegmentFrame>
);
};
const InputComponent = ({ initialValue }: any) => {
const [value, setValue] = useState(initialValue);
return (
<SegmentInput
placeholder="add text"
autofocus
value={value}
onChange={text => {
setValue(text as string);
action('Segment value changed')(text);
}}
/>
);
};
export const InputWithAutoFocus = () => {
const [inputComponents, setInputComponents] = useState<any>([]);
return (
<SegmentFrame>
{inputComponents.map((InputComponent: any) => (
<InputComponent intitialValue="test"></InputComponent>
))}
<a
className="gf-form-label query-part"
onClick={() => {
setInputComponents([...inputComponents, InputComponent]);
}}
>
<Icon name="plus" />
</a>
</SegmentFrame>
);
};