Last active
November 21, 2019 19:30
-
-
Save zettadam/064a901c4f10d83c9409d03299f43bfb to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
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
| // Available variables: | |
| // - Machine | |
| // - interpret | |
| // - assign | |
| // - send | |
| // - sendParent | |
| // - spawn | |
| // - raise | |
| // - actions | |
| // - XState (all XState exports) | |
| const textInputMachine = Machine({ | |
| id: 'textInput', | |
| context: { | |
| validateOnEnable: true, | |
| validateOnBlur: true, | |
| validateOnChange: false | |
| }, | |
| initial: 'enabled', | |
| states: { | |
| enabled: { | |
| initial: 'idle', | |
| on: { | |
| DISABLE: 'disabled', | |
| }, | |
| states: { | |
| idle: { | |
| on: { | |
| VALIDATE: { | |
| target: 'validating', | |
| cond: 'shouldValidateOnEnable' | |
| }, | |
| FOCUS: 'focused' | |
| } | |
| }, | |
| blurred: { | |
| on: { | |
| FOCUS: 'focused', | |
| VALIDATE: { | |
| target: 'validating', | |
| cond: 'shouldValidateOnBlur' | |
| } | |
| } | |
| }, | |
| focused: { | |
| on: { | |
| BLUR: 'blurred', | |
| CHANGE: 'focused', | |
| CLEAR: 'focused', | |
| VALIDATE: { | |
| target: 'validating', | |
| cond: 'shouldValidateOnChange' | |
| } | |
| } | |
| }, | |
| validating: { | |
| on: { | |
| VALID: 'valid', | |
| INVALID: 'invalid' | |
| } | |
| }, | |
| valid: { | |
| on: { | |
| '': 'idle', | |
| } | |
| }, | |
| invalid: { | |
| on: { | |
| '': 'idle' | |
| } | |
| } | |
| } | |
| }, | |
| disabled: { | |
| on: { | |
| ENABLE: 'enabled' | |
| } | |
| } | |
| }, | |
| guards: { | |
| shouldValidateOnEnable: (context, event) => context.validateOnEnable, | |
| shouldValidateOnBlur: (context, event) => context.validateOnBlur, | |
| shouldValidateOnChange: (context, event) => context.validateOnChange | |
| } | |
| }); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment