diff --git a/src/content/structured/components/popover-menu/code.mdx b/src/content/structured/components/popover-menu/code.mdx index 8d89efbe2..f349e1994 100644 --- a/src/content/structured/components/popover-menu/code.mdx +++ b/src/content/structured/components/popover-menu/code.mdx @@ -20,7 +20,7 @@ tabs: --- import { IcPopoverMenu, IcMenuItem, IcMenuGroup, IcButton } from "@ukic/react"; -import { useRef } from "react"; +import { useState } from "react"; ## Component demo @@ -77,7 +77,7 @@ export const snippets = [ variant="icon" title="More information" id="button-1" - onClick={handleClick} + onClick={handlePopoverToggled} > - + @@ -104,10 +104,9 @@ export const snippets = [ long: [ { language: "Typescript", - snippet: `const popoverEl = useRef(null); -const handleClick = () => { - popoverEl.current.open = !popoverEl.current.open; -}; + snippet: `const [popoverOpen, setPopoverOpen] = useState(false); +const handlePopoverToggled = () => setPopoverOpen(value => !value); +const handlePopoverClosed = () => setPopoverOpen(false); return ( <> {shortCode} @@ -116,10 +115,9 @@ return ( }, { language: "Javascript", - snippet: `const popoverEl = useRef(null); -const handleClick = () => { - popoverEl.current.open = !popoverEl.current.open; -}; + snippet: `const [popoverOpen, setPopoverOpen] = useState(false); +const handlePopoverToggled = () => setPopoverOpen(value => !value); +const handlePopoverClosed = () => setPopoverOpen(false); return ( <> {shortCode} @@ -132,17 +130,16 @@ return ( ]; export const DemoPopover = () => { - const popoverEl = useRef(null); - const handleClick = () => { - popoverEl.current.open = !popoverEl.current.open; - }; + const [popoverOpen, setPopoverOpen] = useState(false); + const handlePopoverToggled = () => setPopoverOpen((value) => !value); + const handlePopoverClosed = () => setPopoverOpen(false); return ( <> { - + @@ -258,7 +260,7 @@ export const snippetsButtons = [ variant="icon" title="More information" id="button-2" - onClick={handleClick} + onClick={handlePopoverToggled} > - + @@ -297,10 +299,9 @@ export const snippetsButtons = [ long: [ { language: "Typescript", - snippet: `const popoverEl = useRef(null); -const handleClick = () => { - popoverEl.current.open = !popoverEl.current.open; -}; + snippet: `const [popoverOpen, setPopoverOpen] = useState(false); +const handlePopoverToggled = () => setPopoverOpen(value => !value); +const handlePopoverClosed = () => setPopoverOpen(false); return ( <> {shortCode} @@ -309,10 +310,9 @@ return ( }, { language: "Javascript", - snippet: `const popoverEl = useRef(null); -const handleClick = () => { - popoverEl.current.open = !popoverEl.current.open; -}; + snippet: `const [popoverOpen, setPopoverOpen] = useState(false); +const handlePopoverToggled = () => setPopoverOpen(value => !value); +const handlePopoverClosed = () => setPopoverOpen(false); return ( <> {shortCode} @@ -325,17 +325,16 @@ return ( ]; export const ButtonsPopover = () => { - const popoverEl = useRef(null); - const handleClick = () => { - popoverEl.current.open = !popoverEl.current.open; - }; + const [popoverOpen, setPopoverOpen] = useState(false); + const handlePopoverToggled = () => setPopoverOpen((value) => !value); + const handlePopoverClosed = () => setPopoverOpen(false); return ( <> { - + - + @@ -465,10 +469,9 @@ export const snippetsGroups = [ long: [ { language: "Typescript", - snippet: `const popoverEl = useRef(null); -const handleClick = () => { - popoverEl.current.open = !popoverEl.current.open; -}; + snippet: `const [popoverOpen, setPopoverOpen] = useState(false); +const handlePopoverToggled = () => setPopoverOpen(value => !value); +const handlePopoverClosed = () => setPopoverOpen(false); return ( <> {shortCode} @@ -477,10 +480,9 @@ return ( }, { language: "Javascript", - snippet: `const popoverEl = useRef(null); -const handleClick = () => { - popoverEl.current.open = !popoverEl.current.open; -}; + snippet: `const [popoverOpen, setPopoverOpen] = useState(false); +const handlePopoverToggled = () => setPopoverOpen(value => !value); +const handlePopoverClosed = () => setPopoverOpen(false); return ( <> {shortCode} @@ -493,17 +495,16 @@ return ( ]; export const GroupsPopover = () => { - const popoverEl = useRef(null); - const handleClick = () => { - popoverEl.current.open = !popoverEl.current.open; - }; + const [popoverOpen, setPopoverOpen] = useState(false); + const handlePopoverToggled = () => setPopoverOpen((value) => !value); + const handlePopoverClosed = () => setPopoverOpen(false); return ( <> { - +