EnumStyleProp

See source code
Table of contents

Extends StyleProp<T>.

See StyleProp & StyleProp.defineEnum

class EnumStyleProp<T> extends StyleProp<T> {}

Properties

defaultValue

defaultValue: Type;

id

readonly
readonly id: string;

type

readonly
readonly type: T.Validatable<Type>;

values

readonly
readonly values: readonly T[];

Methods

define( )

static

Define a new StyleProp.

static define<Type>(
  uniqueId: string,
  options: {
    defaultValue: Type;
    type?: T.Validatable<Type>;
  },
): StyleProp<Type>;

Example

import { T } from "@tldraw/validate";
import { StyleProp } from "@tldraw/tlschema";

const MyLineWidthProp = StyleProp.define("myApp:lineWidth", {
  defaultValue: 1,
  type: T.number,
});

Parameters

NameDescription

uniqueId

string;

Each StyleProp must have a unique ID. We recommend you prefix this with your app/library name.

options

{
  defaultValue: Type;
  type?: T.Validatable<Type>;
};
  • defaultValue: The default value for this style prop.

  • type: Optionally, describe what type of data you expect for this style prop.

Returns

StyleProp<Type>;

defineEnum( )

static

Define a new StyleProp as a list of possible values.

static defineEnum<const Values extends readonly unknown[]>(
  uniqueId: string,
  options: {
    defaultValue: Values[number];
    values: Values;
  },
): EnumStyleProp<Values[number]>;

Example

import { StyleProp } from "@tldraw/tlschema";

const MySizeProp = StyleProp.defineEnum("myApp:size", {
  defaultValue: "medium",
  values: ["small", "medium", "large"],
});

Parameters

NameDescription

uniqueId

string;

Each StyleProp must have a unique ID. We recommend you prefix this with your app/library name.

options

{
  defaultValue: Values[number];
  values: Values;
};
  • defaultValue: The default value for this style prop.

  • values: An array of possible values of this style prop.

Returns

EnumStyleProp<Values[number]>;

setDefaultValue( )

setDefaultValue(value: Type): void;

Parameters

NameDescription

value

Type;

Returns

void;

validate( )

validate(value: unknown): Type;

Parameters

NameDescription

value

unknown;

Returns

Type;

validateUsingKnownGoodVersion( )

validateUsingKnownGoodVersion(prevValue: Type, newValue: unknown): Type;

Parameters

NameDescription

prevValue

Type;

newValue

unknown;

Returns

Type;

Prev
b64Vecs
Next
StyleProp