mirror of https://github.com/grafana/grafana
UI: Segment fixes (#20947)
* Add support for primitive values/onchange * Fix segment clickaway bug * Fix onchange * Use primitive in cloudwatch * Add placeholder * Use placeholder in cloudwatch editor * Fix lint error * Fix lodash import * Use new component story format * Add support for autofocus * Use selectable value for onchange event * Fix lint errorpull/20938/head
parent
26789d1eb6
commit
0e4850f203
@ -1,29 +1,84 @@ |
|||||||
import React from 'react'; |
import React, { useState } from 'react'; |
||||||
import { storiesOf } from '@storybook/react'; |
|
||||||
import { action } from '@storybook/addon-actions'; |
import { action } from '@storybook/addon-actions'; |
||||||
const SegmentStories = storiesOf('UI/Segment/SegmentInput', module); |
|
||||||
import { SegmentInput } from '.'; |
import { SegmentInput } from '.'; |
||||||
import { UseState } from '../../utils/storybook/UseState'; |
|
||||||
|
|
||||||
SegmentStories.add('Segment Input', () => { |
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: 'UI/Segment/SegmentInput', |
||||||
|
component: BasicInput, |
||||||
|
}; |
||||||
|
|
||||||
|
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 ( |
return ( |
||||||
<UseState initialState={'some text'}> |
<SegmentFrame> |
||||||
{(value, updateValue) => ( |
{inputComponents.map((InputComponent: any) => ( |
||||||
<> |
<InputComponent intitialValue="test"></InputComponent> |
||||||
<div className="gf-form-inline"> |
))} |
||||||
<div className="gf-form"> |
<a |
||||||
<span className="gf-form-label width-8 query-keyword">Segment Name</span> |
className="gf-form-label query-part" |
||||||
</div> |
onClick={() => { |
||||||
<SegmentInput |
setInputComponents([...inputComponents, InputComponent]); |
||||||
value={value} |
}} |
||||||
onChange={text => { |
> |
||||||
updateValue(text as string); |
<i className="fa fa-plus" /> |
||||||
action('Segment value changed')(text); |
</a> |
||||||
}} |
</SegmentFrame> |
||||||
/> |
|
||||||
</div> |
|
||||||
</> |
|
||||||
)} |
|
||||||
</UseState> |
|
||||||
); |
); |
||||||
}); |
}; |
||||||
|
Loading…
Reference in new issue