diff --git a/theatre/core/src/propTypes/index.ts b/theatre/core/src/propTypes/index.ts index 746e6e2..452ac57 100644 --- a/theatre/core/src/propTypes/index.ts +++ b/theatre/core/src/propTypes/index.ts @@ -511,30 +511,32 @@ function _ensureString(s: unknown): string | undefined { * @returns A stringLiteral prop type * */ -export function stringLiteral( +export function stringLiteral< + ValuesAndLabels extends {[key in string]: string}, +>( /** * Default value (a string that equals one of the options) */ - defaultValue: Extract, + defaultValue: Extract, /** * The options. Use the `"value": "Label"` format. * * An object like `{[value]: Label}`. Example: `{r: "Red", "g": "Green"}` */ - options: Opts, + valuesAndLabels: ValuesAndLabels, /** * opts.as Determines if editor is shown as a menu or a switch. Either 'menu' or 'switch'. Default: 'menu' */ opts: { as?: 'menu' | 'switch' label?: string - interpolate?: Interpolator> + interpolate?: Interpolator> } = {}, -): PropTypeConfig_StringLiteral> { +): PropTypeConfig_StringLiteral> { return { type: 'stringLiteral', default: defaultValue, - options: {...options}, + valuesAndLabels: {...valuesAndLabels}, [propTypeSymbol]: 'TheatrePropType', valueType: null as $IntentionalAny, as: opts.as ?? 'menu', @@ -542,9 +544,9 @@ export function stringLiteral( interpolate: opts.interpolate ?? leftInterpolate, deserializeAndSanitize( json: unknown, - ): undefined | Extract { + ): undefined | Extract { if (typeof json !== 'string') return undefined - if (Object.prototype.hasOwnProperty.call(options, json)) { + if (Object.prototype.hasOwnProperty.call(valuesAndLabels, json)) { return json as $IntentionalAny } else { return undefined @@ -665,7 +667,7 @@ export interface PropTypeConfig_String export interface PropTypeConfig_StringLiteral extends ISimplePropType<'stringLiteral', T> { - options: Record + valuesAndLabels: Record as: 'menu' | 'switch' } diff --git a/theatre/studio/src/panels/DetailPanel/propEditors/StringLiteralPropEditor.tsx b/theatre/studio/src/panels/DetailPanel/propEditors/StringLiteralPropEditor.tsx index 0dc7074..d504bd0 100644 --- a/theatre/studio/src/panels/DetailPanel/propEditors/StringLiteralPropEditor.tsx +++ b/theatre/studio/src/panels/DetailPanel/propEditors/StringLiteralPropEditor.tsx @@ -31,13 +31,13 @@ const StringLiteralPropEditor: React.FC<{ ) : ( )}