Last active
November 8, 2019 23:00
-
-
Save sgregson/0a92f7896b399652d942c0766db5ee5b to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
This file contains 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
const fetchMachine = Machine({ | |
id: 'Radio Group', | |
initial: 'unfocused', | |
context: { | |
// | |
insideToolbar: false, | |
checkedIndex: -1 | |
}, | |
states: { | |
unfocused: { | |
on: { | |
TAB: 'focused' | |
} | |
}, | |
focused: { | |
on: { | |
KEYDOWN: [ | |
{ | |
target: "unfocused", | |
cond: "tab" | |
}, | |
{ | |
target: "unfocused", | |
cond: "shiftTab" | |
}, | |
{ | |
target: "focused", | |
cond: "rightOrDown" | |
}, | |
{ | |
target: "focused", | |
cond: "leftOrUp" | |
} | |
], | |
} | |
}, | |
success: { | |
type: 'final' | |
}, | |
failure: { | |
on: { | |
RETRY: { | |
target: 'unfocused', | |
actions: assign({ | |
retries: (context, event) => context.retries + 1 | |
}) | |
} | |
} | |
} | |
} | |
},{ | |
guards: { | |
tab: (c,e) => { | |
// tab key, no shift | |
if(e.which == 9 && !e.shiftKey) { | |
// no other modifiers | |
return !(e.altKey || e.ctrlKey || e.metaKey) | |
} | |
return false | |
}, | |
shiftTab: (c,e) => { | |
// tab key w/ shift | |
if(e.which == 9 && e.shiftKey) { | |
// no other modifiers | |
return !(e.altKey || e.ctrlKey || e.metaKey) | |
} | |
return false | |
}, | |
rightOrDown: () => { | |
return true | |
}, | |
leftOrUp: () => { | |
return true | |
} | |
} | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment