mirror of https://github.com/grafana/grafana
UX: Fix empty space in select (#19713)
parent
f7ad580356
commit
9b483e765b
@ -0,0 +1,38 @@ |
|||||||
|
import React from 'react'; |
||||||
|
import { storiesOf } from '@storybook/react'; |
||||||
|
import { action } from '@storybook/addon-actions'; |
||||||
|
import { withKnobs, object } from '@storybook/addon-knobs'; |
||||||
|
import { withCenteredStory } from '../../utils/storybook/withCenteredStory'; |
||||||
|
import { UseState } from '../../utils/storybook/UseState'; |
||||||
|
import { SelectableValue } from '@grafana/data'; |
||||||
|
import { Select } from './Select'; |
||||||
|
|
||||||
|
const SelectStories = storiesOf('UI/Select/Select', module); |
||||||
|
|
||||||
|
SelectStories.addDecorator(withCenteredStory).addDecorator(withKnobs); |
||||||
|
|
||||||
|
SelectStories.add('default', () => { |
||||||
|
const intialState: SelectableValue<string> = { label: 'A label', value: 'A value' }; |
||||||
|
const value = object<SelectableValue<string>>('Selected Value:', intialState); |
||||||
|
const options = object<Array<SelectableValue<string>>>('Options:', [ |
||||||
|
intialState, |
||||||
|
{ label: 'Another label', value: 'Another value' }, |
||||||
|
]); |
||||||
|
|
||||||
|
return ( |
||||||
|
<UseState initialState={value}> |
||||||
|
{(value, updateValue) => { |
||||||
|
return ( |
||||||
|
<Select |
||||||
|
value={value} |
||||||
|
options={options} |
||||||
|
onChange={value => { |
||||||
|
action('onChanged fired')(value); |
||||||
|
updateValue(value); |
||||||
|
}} |
||||||
|
/> |
||||||
|
); |
||||||
|
}} |
||||||
|
</UseState> |
||||||
|
); |
||||||
|
}); |
@ -0,0 +1,50 @@ |
|||||||
|
import React from 'react'; |
||||||
|
import { css } from 'emotion'; |
||||||
|
import { CSSTransition } from 'react-transition-group'; |
||||||
|
import { stylesFactory } from '../../themes'; |
||||||
|
|
||||||
|
const getStyles = stylesFactory((duration: number, measurement: 'width' | 'height', size: number) => { |
||||||
|
return { |
||||||
|
enter: css` |
||||||
|
label: enter; |
||||||
|
${measurement}: 0; |
||||||
|
opacity: 0; |
||||||
|
`,
|
||||||
|
enterActive: css` |
||||||
|
label: enterActive; |
||||||
|
${measurement}: ${size}px; |
||||||
|
opacity: 1; |
||||||
|
transition: opacity ${duration}ms ease-out, ${measurement} ${duration}ms ease-out; |
||||||
|
`,
|
||||||
|
exit: css` |
||||||
|
label: exit; |
||||||
|
${measurement}: ${size}px; |
||||||
|
opacity: 1; |
||||||
|
`,
|
||||||
|
exitActive: css` |
||||||
|
label: exitActive; |
||||||
|
opacity: 0; |
||||||
|
${measurement}: 0; |
||||||
|
transition: opacity ${duration}ms ease-out, ${measurement} ${duration}ms ease-out; |
||||||
|
`,
|
||||||
|
}; |
||||||
|
}); |
||||||
|
|
||||||
|
type Props = { |
||||||
|
children: React.ReactNode; |
||||||
|
visible: boolean; |
||||||
|
size: number; |
||||||
|
|
||||||
|
duration?: number; |
||||||
|
horizontal?: boolean; |
||||||
|
}; |
||||||
|
|
||||||
|
export function SlideOutTransition(props: Props) { |
||||||
|
const { visible, children, duration = 250, horizontal, size } = props; |
||||||
|
const styles = getStyles(duration, horizontal ? 'width' : 'height', size); |
||||||
|
return ( |
||||||
|
<CSSTransition in={visible} mountOnEnter={true} unmountOnExit={true} timeout={duration} classNames={styles}> |
||||||
|
{children} |
||||||
|
</CSSTransition> |
||||||
|
); |
||||||
|
} |
Loading…
Reference in new issue