New: Implement propTypes.stringLiteral()
This commit is contained in:
parent
9809042762
commit
4038ad34a4
2 changed files with 25 additions and 3 deletions
|
@ -57,7 +57,27 @@ export const string = (defaultValue: string): PropTypeConfig_String => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type IValidSheetountProps = {
|
export interface PropTypeConfig_StringLiteral<T extends string>
|
||||||
|
extends IBasePropType<T> {
|
||||||
|
type: 'stringLiteral'
|
||||||
|
default: T
|
||||||
|
options: ReadonlyArray<T>
|
||||||
|
}
|
||||||
|
|
||||||
|
export function stringLiteral<T extends string>(
|
||||||
|
defaultValue: T,
|
||||||
|
options: ReadonlyArray<T>,
|
||||||
|
): PropTypeConfig_StringLiteral<T> {
|
||||||
|
return {
|
||||||
|
type: 'stringLiteral',
|
||||||
|
default: defaultValue,
|
||||||
|
options: [...options],
|
||||||
|
[s]: 'TheatrePropType',
|
||||||
|
valueType: null as $IntentionalAny,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
type IValidCompoundProps = {
|
||||||
[K in string]: PropTypeConfig
|
[K in string]: PropTypeConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -66,13 +86,13 @@ type IValidSheetountProps = {
|
||||||
* I didn't want to use 'object' as it could get confused with
|
* I didn't want to use 'object' as it could get confused with
|
||||||
* SheetObject.
|
* SheetObject.
|
||||||
*/
|
*/
|
||||||
export interface PropTypeConfig_Compound<Props extends IValidSheetountProps>
|
export interface PropTypeConfig_Compound<Props extends IValidCompoundProps>
|
||||||
extends IBasePropType<{[K in keyof Props]: Props[K]['valueType']}> {
|
extends IBasePropType<{[K in keyof Props]: Props[K]['valueType']}> {
|
||||||
type: 'compound'
|
type: 'compound'
|
||||||
props: Record<string, PropTypeConfig>
|
props: Record<string, PropTypeConfig>
|
||||||
}
|
}
|
||||||
|
|
||||||
export const compound = <Props extends IValidSheetountProps>(
|
export const compound = <Props extends IValidCompoundProps>(
|
||||||
props: Props,
|
props: Props,
|
||||||
): PropTypeConfig_Compound<Props> => {
|
): PropTypeConfig_Compound<Props> => {
|
||||||
return {
|
return {
|
||||||
|
@ -93,6 +113,7 @@ export type PropTypeConfig_AllPrimitives =
|
||||||
| PropTypeConfig_Number
|
| PropTypeConfig_Number
|
||||||
| PropTypeConfig_Boolean
|
| PropTypeConfig_Boolean
|
||||||
| PropTypeConfig_String
|
| PropTypeConfig_String
|
||||||
|
| PropTypeConfig_StringLiteral<$IntentionalAny>
|
||||||
|
|
||||||
export type PropTypeConfig =
|
export type PropTypeConfig =
|
||||||
| PropTypeConfig_AllPrimitives
|
| PropTypeConfig_AllPrimitives
|
||||||
|
|
|
@ -65,6 +65,7 @@ const propEditorByPropType: {
|
||||||
string: () => <>Implement me</>,
|
string: () => <>Implement me</>,
|
||||||
enum: () => <>Implement me</>,
|
enum: () => <>Implement me</>,
|
||||||
boolean: () => <>Implement me</>,
|
boolean: () => <>Implement me</>,
|
||||||
|
stringLiteral: () => <>Implement me</>,
|
||||||
}
|
}
|
||||||
|
|
||||||
const DeterminePropEditor: React.FC<{
|
const DeterminePropEditor: React.FC<{
|
||||||
|
|
Loading…
Reference in a new issue