diff --git a/src/stories/ContextMixin.stories.tsx b/src/stories/ContextMixin.stories.tsx index 630e8ea..24fd452 100644 --- a/src/stories/ContextMixin.stories.tsx +++ b/src/stories/ContextMixin.stories.tsx @@ -53,7 +53,7 @@ export const Playground: StoryFn = (args) => { }, [args.STORYBOOK_BACKGROUND]) return ( -
+
diff --git a/src/stories/styles/ContextMixin.css b/src/stories/styles/ContextMixin.css index 113a945..1dd1753 100644 --- a/src/stories/styles/ContextMixin.css +++ b/src/stories/styles/ContextMixin.css @@ -16,13 +16,13 @@ } @supports selector(:has(div)) { - *[debug='true'] .fluent.menu .menuoption:has(~ .menuoption.hovering) .icon { /* Above */ + *[data-debug='true'] .fluent.menu .menuoption:has(~ .menuoption.hovering) .icon { /* Above */ background: red; } - *[debug='true'] .fluent.menu .menuoption.hovering .icon { + *[data-debug='true'] .fluent.menu .menuoption.hovering .icon { background: blue; } - *[debug='true'] .fluent.menu .menuoption.hovering ~ .menuoption .icon { /* Below */ + *[data-debug='true'] .fluent.menu .menuoption.hovering ~ .menuoption .icon { /* Below */ background: green; } } diff --git a/src/stories/styles/Tutorials.css b/src/stories/styles/Tutorials.css index b83929f..dc24e72 100644 --- a/src/stories/styles/Tutorials.css +++ b/src/stories/styles/Tutorials.css @@ -29,7 +29,7 @@ animation: hide 1s ease-out 1 normal forwards; z-index: 2; } -.demonstration #instructions .instruction[data-active='true'] { +.demonstration #instructions .instruction[data-active=true] { display: block; animation: reveal 1s ease-out 1 normal forwards; } diff --git a/src/stories/tutorials/Context.tsx b/src/stories/tutorials/Context.tsx index 578d852..ba65354 100644 --- a/src/stories/tutorials/Context.tsx +++ b/src/stories/tutorials/Context.tsx @@ -1,9 +1,9 @@ -import { - React, +import React, { useEffect, - useState, - useRef + useRef, + useReducer } from 'react' +import { type StoryFn } from '@storybook/react' import { linkTo } from '@storybook/addon-links' @@ -14,48 +14,56 @@ import { import deviceToolbar from '../assets/device_toolbar.webp' -function advanceStep (step, setStep) { +enum ContextStep { + LAUNCH, + HOVER, + TRIGGER +} + +function stepReducer (state: ContextStep): ContextStep { if (document.getElementById('fluentmenu')) { const list = document.getElementById('instructions') - list.children.item(step).setAttribute('active', 'false') - list.children.item(step + 1).setAttribute('active', 'true') - - setStep(step + 1) + list?.children?.item(state)?.setAttribute('data-active', 'false') + list?.children?.item(state + 1)?.setAttribute('data-active', 'true') } + + return state + 1 } -function displayCopied () { - const display = document.getElementById('copied') +function displayCopied (): void { + const display = document.getElementById('copied') as HTMLDivElement - display.textContent = window.getSelection().toString() + display.textContent = window.getSelection()?.toString() ?? null } -export const Context = () => { - const menuRef = useRef(null) - const [step, setStep] = useState(0) +export const Context: StoryFn = () => { + const menuRef = useRef(null) + const [step, advanceStep] = useReducer(stepReducer, 0) useEffect(() => { - function launchStep (e) { - if (menuRef.current.state.holdingTag) { + const menu = menuRef.current! + + function launchStep (): void { + if (menu.state.holdingTag) { document.removeEventListener('contextmenu', launchStep) - advanceStep(step, setStep) + advanceStep() } } - function hoverStep () { - if (menuRef.current.hoveringIndex) { + function hoverStep (): void { + if (menu.hoveringIndex) { document.removeEventListener('touchmove', hoverStep) - advanceStep(step, setStep) + advanceStep() } } - function triggerStep (e) { + function triggerStep (): void { document.removeEventListener('touchend', triggerStep) - advanceStep(step, setStep) + advanceStep() } document.addEventListener('copy', displayCopied) @@ -91,7 +99,7 @@ export const Context = () => { device toolbar
- If you're on PC, try pressing Ctrl+Shift+I and clicking the Device Toolbar button. + If you're on PC, try pressing Ctrl+Shift+I and clicking the Device Toolbar button.
@@ -103,13 +111,13 @@ export const Context = () => { random portrait
-
+

Try opening a context menu!

Hold down on an image or link @@ -149,7 +157,7 @@ export const Context = () => {

-
+
diff --git a/src/stories/tutorials/Selection.tsx b/src/stories/tutorials/Selection.tsx index f3bec87..343da36 100644 --- a/src/stories/tutorials/Selection.tsx +++ b/src/stories/tutorials/Selection.tsx @@ -22,7 +22,7 @@ enum SelectionStep { DISMISS } -function stepReducer (state: SelectionStep): number { +function stepReducer (state: SelectionStep): SelectionStep { if (document.getElementById('fluentselectionmanipulator')) { const list = document.getElementById('instructions')