-
Notifications
You must be signed in to change notification settings - Fork 42
docs (editor): Adding Stateful Components #681
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jeffatrive
wants to merge
1
commit into
main
Choose a base branch
from
stateful-components
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -126,6 +126,56 @@ Layout mode is used when your Component contains Layouts that need to remain res | |
|
|
||
| When set to Fixed, the width and height of the Component can be set to either pixel or percent values. This is different than the scale property, which changes the Components's scale. Typically scale should not be used when Layout mode is selected. | ||
|
|
||
| ## Stateful Components | ||
|
|
||
| Stateful components let you expose specific view model properties directly on a nested component, so each instance can have its own values. This makes it faster to create and iterate on designs that reuse the same component with different content or styling — without wiring up a separate nested view model instance for each one. | ||
|
|
||
| ### Setting Up a Component for Stateful Use | ||
|
|
||
| Before a component can be used statefully, its artboard needs a view model with the properties you want to expose. | ||
|
|
||
| 1. Create or open the artboard you want to use as a component. | ||
| 2. Add a view model and bind the relevant properties to elements in the artboard (for example, a label string bound to a text run, or a background color bound to a fill). | ||
| 3. Mark the artboard as a component using the component toggle in the inspector, or press Shift + N. | ||
| 4. In the inspector, find the Properties section. Click + to add the view model properties you want to expose. | ||
| 5. For each property, choose whether it's an Input or an Output: | ||
| • Input — the value can be set on each instance when nested as a stateful component. | ||
| • Output — the value is read-only when nested; it reports back to the parent. | ||
|
|
||
|  | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It might just be the live preview, but this image doesn't seem to be working. |
||
|
|
||
| ### Using a Stateful Component | ||
|
|
||
| When you nest a component (press N and select it from the menu), it comes in as a stateless component by default. Switch it to a stateful component in the inspector. | ||
|
|
||
|  | ||
|
|
||
| Once switched to stateful, the nested view model instance selector goes away, and you'll see the exposed properties instead. Set override values directly in the inspector. Each instance of the component can have its own values for those properties. | ||
|
|
||
| Because the values are owned by the component instance, you don't need a separate view model instance for each one. | ||
|
|
||
| ### Nesting Stateful Components | ||
|
|
||
| Stateful components can be nested inside other components. For example, a card component might contain a stateful button component. | ||
|
|
||
| If you want the card's parent to be able to override the button's properties, add those properties to the card's view model and data bind them to the button's stateful properties. Once added to the card's Properties panel as inputs, they'll be available to override when the card is nested. | ||
|
|
||
| ### Output Properties | ||
|
|
||
| Output properties report a value out of a component when it's nested. They appear with a lock icon in the inspector and are marked as read-only — you can interact with the component, but you can't set the value from outside. | ||
|
|
||
|  | ||
|
|
||
| To read an output value in the parent artboard, add a property to the parent's view model and data bind it (target to source) to the component's output property. The value will update in real time as the state machine runs. | ||
|
|
||
| ### Keying Input Properties on Timelines | ||
|
|
||
| Input properties can be keyed on a timeline. Open the timeline view with a stateful component selected and you'll see a key indicator next to each exposed input property. Key the values at different points in the timeline to animate them on a loop or as part of a sequence. | ||
|
|
||
|  | ||
|
|
||
| <YouTube id="unMfjqrKjNc" /> | ||
|
|
||
| ## Exposing Inputs and Events | ||
|
|
||
| Expose the Inputs and/or Events of a Component to control them from a parent/host Artboard. This allows you to control one Component with another via a State Machine. | ||
|
|
||
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That video is such a useful overview, I'm thinking it might be better here than at the bottom.