Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 10 additions & 18 deletions static/app/components/core/disclosure/disclosure.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<Disclosure defaultExpanded={expanded} onExpandedChange={(expanded) => {
const url = new URL(window.location.href);
url.searchParams.set('my-disclosure-key', expanded ? 'true' : 'false');
window.history.pushState({}, '', url.toString());
setExpanded(expanded);
}}>
<Disclosure defaultExpanded={expanded} onExpandedChange={setExpanded}>
<Disclosure.Title>The expanded state is saved to URL state</Disclosure.Title>
<Disclosure.Content>Reload the page to see the expanded state is remembered and new params are added to the URL</Disclosure.Content>
</Disclosure>
Expand All @@ -215,21 +212,16 @@ export function URLStateDisclosure() {
</Storybook.Demo>

```tsx
import {parseAsBoolean, useQueryState} from 'nuqs';

function URLStateDisclosure() {
const [expanded, setExpanded] = useState<boolean>(
new URLSearchParams(window.location.search).get('my-disclosure-key') === 'true'
const [expanded, setExpanded] = useQueryState(
'my-disclosure-key',
parseAsBoolean.withDefault(false)
);

return (
<Disclosure
defaultExpanded={expanded}
onExpandedChange={expanded => {
const url = new URL(window.location.href);
url.searchParams.set('my-disclosure-key', expanded ? 'true' : 'false');
window.history.pushState({}, '', url.toString());
setExpanded(expanded);
}}
>
<Disclosure defaultExpanded={expanded} onExpandedChange={setExpanded}>
<Disclosure.Title>The expanded state is saved to URL state</Disclosure.Title>
<Disclosure.Content>
Reload the page to see the expanded state is remembered
Expand Down
15 changes: 8 additions & 7 deletions static/app/components/core/disclosure/disclosure.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,20 +111,21 @@ 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)`
flex-grow: 1;
justify-content: flex-start;
padding-left: ${p => p.theme.space.xs};

&:hover {
background-color: transparent;
}

${p =>
p.theme.isChonk
? ''
Expand Down
Loading