Skip to content

Instantly share code, notes, and snippets.

@forresto
Last active April 14, 2020 19:12
Show Gist options
  • Save forresto/4c9eba1ad22da47533e94d8a345afbcf to your computer and use it in GitHub Desktop.
Save forresto/4c9eba1ad22da47533e94d8a345afbcf to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
// - XState (all XState exports)
const goLeft = assign({
tabIndex: (context, event) => Math.max(context.slideIndex - 1, 0)
});
const goRight = assign({
tabIndex: (context, event) => Math.min(context.slideIndex + 1, context.slideCount - 1)
});
const goHome = assign({
tabIndex: (context, event) => 0
});
const goEnd = assign({
tabIndex: (context, event) => context.slideCount - 1
});
const fetchMachine = Machine({
id: 'fetch',
initial: 'unfocused',
context: {
slideCount: 5,
slideIndex: 0
},
states: {
unfocused: {
on: {
FOCUS: 'focusSlider'
}
},
focusSlider: {
on: {
LEFT: {
actions: goLeft
},
RIGHT: {
actions: goRight
},
HOME: {
actions: goHome
},
END: {
actions: goEnd
},
TAB: 'focusContent',
}
},
focusContent: {
on: {SHIFT_TAB: 'focusSlider',}
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment