From 4038ad34a4500e359e003f74f27234b82b682f7d Mon Sep 17 00:00:00 2001 From: Aria Minaei Date: Sat, 3 Jul 2021 15:03:52 +0200 Subject: [PATCH] New: Implement propTypes.stringLiteral() --- theatre/core/src/propTypes/index.ts | 27 ++++++++++++++++--- .../propEditors/DeterminePropEditor.tsx | 1 + 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/theatre/core/src/propTypes/index.ts b/theatre/core/src/propTypes/index.ts index 65e2d1a..d6a78c1 100644 --- a/theatre/core/src/propTypes/index.ts +++ b/theatre/core/src/propTypes/index.ts @@ -57,7 +57,27 @@ export const string = (defaultValue: string): PropTypeConfig_String => { } } -type IValidSheetountProps = { +export interface PropTypeConfig_StringLiteral + extends IBasePropType { + type: 'stringLiteral' + default: T + options: ReadonlyArray +} + +export function stringLiteral( + defaultValue: T, + options: ReadonlyArray, +): PropTypeConfig_StringLiteral { + return { + type: 'stringLiteral', + default: defaultValue, + options: [...options], + [s]: 'TheatrePropType', + valueType: null as $IntentionalAny, + } +} + +type IValidCompoundProps = { [K in string]: PropTypeConfig } @@ -66,13 +86,13 @@ type IValidSheetountProps = { * I didn't want to use 'object' as it could get confused with * SheetObject. */ -export interface PropTypeConfig_Compound +export interface PropTypeConfig_Compound extends IBasePropType<{[K in keyof Props]: Props[K]['valueType']}> { type: 'compound' props: Record } -export const compound = ( +export const compound = ( props: Props, ): PropTypeConfig_Compound => { return { @@ -93,6 +113,7 @@ export type PropTypeConfig_AllPrimitives = | PropTypeConfig_Number | PropTypeConfig_Boolean | PropTypeConfig_String + | PropTypeConfig_StringLiteral<$IntentionalAny> export type PropTypeConfig = | PropTypeConfig_AllPrimitives diff --git a/theatre/studio/src/panels/ObjectEditorPanel/propEditors/DeterminePropEditor.tsx b/theatre/studio/src/panels/ObjectEditorPanel/propEditors/DeterminePropEditor.tsx index e0a4916..b433929 100644 --- a/theatre/studio/src/panels/ObjectEditorPanel/propEditors/DeterminePropEditor.tsx +++ b/theatre/studio/src/panels/ObjectEditorPanel/propEditors/DeterminePropEditor.tsx @@ -65,6 +65,7 @@ const propEditorByPropType: { string: () => <>Implement me, enum: () => <>Implement me, boolean: () => <>Implement me, + stringLiteral: () => <>Implement me, } const DeterminePropEditor: React.FC<{