redux-devtools/packages/devui/.storybook/themeAddon/Panel.js

61 lines
1.4 KiB
JavaScript
Raw Normal View History

2019-01-03 16:00:55 +03:00
import React from 'react';
import Form from '@storybook/addon-knobs/dist/components/PropForm';
import styled from 'styled-components';
import { EVENT_ID_DATA, DEFAULT_THEME_STATE } from './constant';
import { listSchemes, listThemes } from '../../src/utils/theme';
const FormWrapper = styled.div`
width: 100%;
padding: 5px;
label {
white-space: nowrap;
}
`;
const schemes = listSchemes();
const themes = listThemes();
export default class Panel extends React.Component {
state = DEFAULT_THEME_STATE;
onChange = (o) => {
2019-01-03 16:00:55 +03:00
const state = { [o.name.split(' ').slice(-1)[0]]: o.value };
this.props.channel.emit(EVENT_ID_DATA, state);
this.setState(state);
};
2019-01-09 02:08:34 +03:00
onClick = () => {};
2019-01-03 16:00:55 +03:00
render() {
const { theme, scheme, light } = this.state;
return (
<FormWrapper>
<Form
knobs={[
{
type: 'select',
name: 'theme',
value: theme,
options: themes,
2019-01-03 16:00:55 +03:00
},
{
type: 'select',
name: 'color scheme',
value: scheme,
options: schemes,
2019-01-03 16:00:55 +03:00
},
{
type: 'boolean',
name: 'light',
value: light,
},
2019-01-03 16:00:55 +03:00
]}
onFieldChange={this.onChange}
2019-01-09 02:08:34 +03:00
onFieldClick={this.onClick}
2019-01-03 16:00:55 +03:00
/>
</FormWrapper>
);
}
}