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 { storiesOf } from '@storybook/react'; |
||||
import React, { useState } from 'react'; |
||||
import { action } from '@storybook/addon-actions'; |
||||
const SegmentStories = storiesOf('UI/Segment/SegmentInput', module); |
||||
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 ( |
||||
<UseState initialState={'some text'}> |
||||
{(value, updateValue) => ( |
||||
<> |
||||
<div className="gf-form-inline"> |
||||
<div className="gf-form"> |
||||
<span className="gf-form-label width-8 query-keyword">Segment Name</span> |
||||
</div> |
||||
<SegmentInput |
||||
value={value} |
||||
onChange={text => { |
||||
updateValue(text as string); |
||||
action('Segment value changed')(text); |
||||
}} |
||||
/> |
||||
</div> |
||||
</> |
||||
)} |
||||
</UseState> |
||||
<SegmentFrame> |
||||
{inputComponents.map((InputComponent: any) => ( |
||||
<InputComponent intitialValue="test"></InputComponent> |
||||
))} |
||||
<a |
||||
className="gf-form-label query-part" |
||||
onClick={() => { |
||||
setInputComponents([...inputComponents, InputComponent]); |
||||
}} |
||||
> |
||||
<i className="fa fa-plus" /> |
||||
</a> |
||||
</SegmentFrame> |
||||
); |
||||
}); |
||||
}; |
||||
|
Loading…
Reference in new issue