Add picker for string values in the Layout Editor
Summary: This diff adds a new PoC widget for the Layout Editor to select a string from a picker. It takes a Set of values and uses them as representation. One of them is considered selected. Reviewed By: muraziz Differential Revision: D23374681 fbshipit-source-id: 324a3dd74a6b16edb77b862345d5288dd714fea1
This commit is contained in:
committed by
Facebook GitHub Bot
parent
0a09699e07
commit
d2ceb1238c
@@ -18,6 +18,7 @@ import Input from '../Input';
|
|||||||
import React, {KeyboardEvent} from 'react';
|
import React, {KeyboardEvent} from 'react';
|
||||||
import Glyph from '../Glyph';
|
import Glyph from '../Glyph';
|
||||||
import {HighlightContext} from '../Highlight';
|
import {HighlightContext} from '../Highlight';
|
||||||
|
import Select from '../Select';
|
||||||
|
|
||||||
const NullValue = styled.span({
|
const NullValue = styled.span({
|
||||||
color: 'rgb(128, 128, 128)',
|
color: 'rgb(128, 128, 128)',
|
||||||
@@ -540,6 +541,11 @@ function parseColor(
|
|||||||
|
|
||||||
const pencilStyle = {cursor: 'pointer', marginLeft: 8};
|
const pencilStyle = {cursor: 'pointer', marginLeft: 8};
|
||||||
|
|
||||||
|
type Picker = {
|
||||||
|
values: Set<string>;
|
||||||
|
selected: string;
|
||||||
|
};
|
||||||
|
|
||||||
class DataDescriptionContainer extends PureComponent<{
|
class DataDescriptionContainer extends PureComponent<{
|
||||||
type: string;
|
type: string;
|
||||||
value: any;
|
value: any;
|
||||||
@@ -610,6 +616,27 @@ class DataDescriptionContainer extends PureComponent<{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case 'picker': {
|
||||||
|
const picker: Picker = JSON.parse(val);
|
||||||
|
const options = [...picker.values].reduce((obj, value) => {
|
||||||
|
return {...obj, [value]: value};
|
||||||
|
}, {});
|
||||||
|
return (
|
||||||
|
<Select
|
||||||
|
options={options}
|
||||||
|
selected={picker.selected}
|
||||||
|
onChangeWithKey={(value: string) =>
|
||||||
|
this.props.commit({
|
||||||
|
value,
|
||||||
|
keep: true,
|
||||||
|
clear: false,
|
||||||
|
set: true,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
case 'text':
|
case 'text':
|
||||||
case 'string':
|
case 'string':
|
||||||
const isUrl = val.startsWith('http://') || val.startsWith('https://');
|
const isUrl = val.startsWith('http://') || val.startsWith('https://');
|
||||||
|
|||||||
Reference in New Issue
Block a user