Add setDefaultValue
to StyleProp
(#4044)
This PR adds a way to set the default value of a style property. ### Change type - [ ] `bugfix` - [ ] `improvement` - [x] `feature` - [ ] `api` - [ ] `other` ### Release notes - Adds a method for changing the default style of a `StyleProp` instance.
This commit is contained in:
parent
4fff8a89af
commit
cafa0f5636
4 changed files with 33 additions and 2 deletions
|
@ -0,0 +1,12 @@
|
|||
import { DefaultSizeStyle, Tldraw } from 'tldraw'
|
||||
import 'tldraw/tldraw.css'
|
||||
|
||||
DefaultSizeStyle.setDefaultValue('s')
|
||||
|
||||
export default function ChangingDefaultStyleExample() {
|
||||
return (
|
||||
<div className="tldraw__editor">
|
||||
<Tldraw persistenceKey="example" />
|
||||
</div>
|
||||
)
|
||||
}
|
13
apps/examples/src/examples/changing-default-style/README.md
Normal file
13
apps/examples/src/examples/changing-default-style/README.md
Normal file
|
@ -0,0 +1,13 @@
|
|||
---
|
||||
title: Changing default style
|
||||
component: ./ChangingDefaultStyleExample.tsx
|
||||
category: ui
|
||||
priority: 1
|
||||
keywords: [size, styles, default]
|
||||
---
|
||||
|
||||
Change the default value for a style prop.
|
||||
|
||||
---
|
||||
|
||||
Want to set the default value for a property to something other than it's built-in default? In this example we make the size style have small as its default calue.
|
|
@ -839,7 +839,7 @@ export class StyleProp<Type> implements T.Validatable<Type> {
|
|||
// @internal
|
||||
protected constructor(id: string, defaultValue: Type, type: T.Validatable<Type>);
|
||||
// (undocumented)
|
||||
readonly defaultValue: Type;
|
||||
defaultValue: Type;
|
||||
static define<Type>(uniqueId: string, options: {
|
||||
defaultValue: Type;
|
||||
type?: T.Validatable<Type>;
|
||||
|
@ -851,6 +851,8 @@ export class StyleProp<Type> implements T.Validatable<Type> {
|
|||
// (undocumented)
|
||||
readonly id: string;
|
||||
// (undocumented)
|
||||
setDefaultValue(value: Type): void;
|
||||
// (undocumented)
|
||||
readonly type: T.Validatable<Type>;
|
||||
// (undocumented)
|
||||
validate(value: unknown): Type;
|
||||
|
|
|
@ -83,10 +83,14 @@ export class StyleProp<Type> implements T.Validatable<Type> {
|
|||
/** @internal */
|
||||
protected constructor(
|
||||
readonly id: string,
|
||||
readonly defaultValue: Type,
|
||||
public defaultValue: Type,
|
||||
readonly type: T.Validatable<Type>
|
||||
) {}
|
||||
|
||||
setDefaultValue(value: Type) {
|
||||
this.defaultValue = value
|
||||
}
|
||||
|
||||
validate(value: unknown) {
|
||||
return this.type.validate(value)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue