EnumStyleProp
Table of contents
Extends StyleProp<T>.
See StyleProp & StyleProp.defineEnum
class EnumStyleProp<T> extends StyleProp<T> {}Properties
defaultValue
defaultValue: Type;id
readonly id: string;type
readonly type: T.Validatable<Type>;values
readonly values: T[];Methods
define( )
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
| Name | Description |
|---|---|
| Each StyleProp must have a unique ID. We recommend you prefix this with your app/library name. |
|
|
Returns
StyleProp<Type>;defineEnum( )
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
| Name | Description |
|---|---|
| Each StyleProp must have a unique ID. We recommend you prefix this with your app/library name. |
|
|
Returns
EnumStyleProp<Values[number]>;addValues( )
Add new values to this enum style prop at runtime. This is useful for extending the built-in styles with custom values (e.g. adding custom colors). Be sure to also modify the associated types.
addValues(...newValues: T[]): void;Parameters
| Name | Description |
|---|---|
| The new values to add. |
Returns
void;removeValues( )
Remove values from this enum style prop at runtime. This is useful for narrowing the built-in styles with custom values (e.g. adding custom colors). Be sure to also modify the associated types.
removeValues(...valuesToRemove: T[]): void;Parameters
| Name | Description |
|---|---|
| The values to remove. |
Returns
void;setDefaultValue( )
setDefaultValue(value: Type): void;Parameters
| Name | Description |
|---|---|
| |
Returns
void;validate( )
validate(value: unknown): Type;Parameters
| Name | Description |
|---|---|
| |
Returns
Type;validateUsingKnownGoodVersion( )
validateUsingKnownGoodVersion(prevValue: Type, newValue: unknown): Type;Parameters
| Name | Description |
|---|---|
| |
| |
Returns
Type;