Made signature of types.stringLiteral() a bit more ergonomic
This commit is contained in:
parent
deb1ad8793
commit
97ce94d52a
3 changed files with 24 additions and 23 deletions
|
@ -293,20 +293,21 @@ const editorSheetObjectConfig = types.compound({
|
|||
showAxes: types.boolean(true),
|
||||
showGrid: types.boolean(true),
|
||||
showOverlayIcons: types.boolean(false),
|
||||
transformControlsMode: types.stringLiteral<TransformControlsMode>(
|
||||
'translate',
|
||||
['translate', 'rotate', 'scale'],
|
||||
),
|
||||
transformControlsSpace: types.stringLiteral<TransformControlsSpace>('world', [
|
||||
'local',
|
||||
'world',
|
||||
]),
|
||||
viewportShading: types.stringLiteral<ViewportShading>('rendered', [
|
||||
'flat',
|
||||
'rendered',
|
||||
'solid',
|
||||
'wireframe',
|
||||
]),
|
||||
transformControlsMode: types.stringLiteral('translate', {
|
||||
translate: 'Translate',
|
||||
rotate: 'Rotate',
|
||||
scale: 'Scale',
|
||||
}),
|
||||
transformControlsSpace: types.stringLiteral('world', {
|
||||
local: 'Local',
|
||||
world: 'World',
|
||||
}),
|
||||
viewportShading: types.stringLiteral('rendered', {
|
||||
flat: 'Flat',
|
||||
rendered: 'Rendered',
|
||||
solid: 'Solid',
|
||||
wireframe: 'Wireframe',
|
||||
}),
|
||||
})
|
||||
|
||||
export const bindToCanvas: BindFunction = ({
|
||||
|
|
|
@ -61,17 +61,17 @@ export interface PropTypeConfig_StringLiteral<T extends string>
|
|||
extends IBasePropType<T> {
|
||||
type: 'stringLiteral'
|
||||
default: T
|
||||
options: ReadonlyArray<T>
|
||||
options: Record<T, string>
|
||||
}
|
||||
|
||||
export function stringLiteral<T extends string>(
|
||||
defaultValue: T,
|
||||
options: ReadonlyArray<T>,
|
||||
): PropTypeConfig_StringLiteral<T> {
|
||||
export function stringLiteral<Opts extends {[key in string]: string}>(
|
||||
defaultValue: Extract<keyof Opts, string>,
|
||||
options: Opts,
|
||||
): PropTypeConfig_StringLiteral<Extract<keyof Opts, string>> {
|
||||
return {
|
||||
type: 'stringLiteral',
|
||||
default: defaultValue,
|
||||
options: [...options],
|
||||
options: {...options},
|
||||
[s]: 'TheatrePropType',
|
||||
valueType: null as $IntentionalAny,
|
||||
}
|
||||
|
|
|
@ -77,9 +77,9 @@ const StringLiteralPropEditor: React.FC<{
|
|||
{stuff.controlIndicators}
|
||||
<Body>
|
||||
<select value={stuff.value} onChange={onChange}>
|
||||
{propConfig.options.map((opt, i) => (
|
||||
<option key={'option-' + i} value={opt}>
|
||||
{opt}
|
||||
{Object.keys(propConfig.options).map((key, i) => (
|
||||
<option key={'option-' + i} value={key}>
|
||||
{propConfig.options[key]}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
|
|
Loading…
Reference in a new issue