Skip to content
Open
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
16 changes: 8 additions & 8 deletions packages/utils/error-overlay/src/components/Collapsible.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

/* @flow */
import {useState} from 'preact/hooks';
import {useRef} from 'preact/hooks';
import {theme} from '../styles';

const _collapsibleStyle = {
Expand Down Expand Up @@ -40,15 +40,12 @@ type CollapsiblePropsType = {|
|};

function Collapsible(props: CollapsiblePropsType): React$Element<'details'> {
const [collapsed, setCollapsed] = useState(true);

const toggleCollapsed = () => {
setCollapsed(!collapsed);
};
const ref = useRef(null);
const collapsed = ref.current?.open;

const count = props.children.length;
return (
<details open={!collapsed} onToggle={toggleCollapsed}>
<details ref={ref}>
<summary
style={collapsed ? collapsibleCollapsedStyle : collapsibleExpandedStyle}
>
Expand All @@ -58,7 +55,10 @@ function Collapsible(props: CollapsiblePropsType): React$Element<'details'> {
</summary>
<div>
{props.children}
<button onClick={toggleCollapsed} style={collapsibleExpandedStyle}>
<button
onClick={() => ref.current?.removeAttribute('open')}
style={collapsibleExpandedStyle}
>
{`▲ ${count} stack frames were expanded.`}
</button>
</div>
Expand Down
Loading