diff --git a/static/app/components/core/disclosure/disclosure.mdx b/static/app/components/core/disclosure/disclosure.mdx index 9c21636387d781..aab1c2538450ec 100644 --- a/static/app/components/core/disclosure/disclosure.mdx +++ b/static/app/components/core/disclosure/disclosure.mdx @@ -191,16 +191,13 @@ function LocalStorageDisclosure() { Disclosures can maintain their expanded state across page reloads by using URL state. +import {parseAsBoolean, useQueryState} from 'nuqs'; + export function URLStateDisclosure() { - const [expanded, setExpanded] = useState(new URLSearchParams(window.location.search).get('my-disclosure-key') === 'true'); + const [expanded, setExpanded] = useQueryState('my-disclosure-key', parseAsBoolean.withDefault(false)); return ( - { - const url = new URL(window.location.href); - url.searchParams.set('my-disclosure-key', expanded ? 'true' : 'false'); - window.history.pushState({}, '', url.toString()); - setExpanded(expanded); - }}> + The expanded state is saved to URL state Reload the page to see the expanded state is remembered and new params are added to the URL @@ -215,21 +212,16 @@ export function URLStateDisclosure() { ```tsx +import {parseAsBoolean, useQueryState} from 'nuqs'; + function URLStateDisclosure() { - const [expanded, setExpanded] = useState( - new URLSearchParams(window.location.search).get('my-disclosure-key') === 'true' + const [expanded, setExpanded] = useQueryState( + 'my-disclosure-key', + parseAsBoolean.withDefault(false) ); return ( - { - const url = new URL(window.location.href); - url.searchParams.set('my-disclosure-key', expanded ? 'true' : 'false'); - window.history.pushState({}, '', url.toString()); - setExpanded(expanded); - }} - > + The expanded state is saved to URL state Reload the page to see the expanded state is remembered diff --git a/static/app/components/core/disclosure/disclosure.tsx b/static/app/components/core/disclosure/disclosure.tsx index 0a4d1c93873fc4..b1010945e625b5 100644 --- a/static/app/components/core/disclosure/disclosure.tsx +++ b/static/app/components/core/disclosure/disclosure.tsx @@ -111,9 +111,14 @@ function Title({children, trailingItems, ...rest}: DisclosureTitleProps) { } const HoverStyleFlex = styled(Flex)` - &:hover { - background-color: ${p => p.theme.backgroundSecondary}; - } + ${p => + p.theme.isChonk + ? '' + : css` + &:hover { + background-color: ${p.theme.backgroundSecondary}; + } + `} `; const StretchedButton = styled(Button)` @@ -121,10 +126,6 @@ const StretchedButton = styled(Button)` justify-content: flex-start; padding-left: ${p => p.theme.space.xs}; - &:hover { - background-color: transparent; - } - ${p => p.theme.isChonk ? ''