|
@ -22,17 +22,29 @@ function ExpandableExample({ |
|
|
excerpt, |
|
|
excerpt, |
|
|
type, |
|
|
type, |
|
|
}: ExpandableExampleProps) { |
|
|
}: ExpandableExampleProps) { |
|
|
|
|
|
const ref = React.useRef<null | HTMLDetailsElement>(null); |
|
|
const [isExpanded, setIsExpanded] = React.useState(false); |
|
|
const [isExpanded, setIsExpanded] = React.useState(false); |
|
|
const isDeepDive = type === 'DeepDive'; |
|
|
const isDeepDive = type === 'DeepDive'; |
|
|
const isExample = type === 'Example'; |
|
|
const isExample = type === 'Example'; |
|
|
|
|
|
|
|
|
return ( |
|
|
return ( |
|
|
<div |
|
|
<details |
|
|
|
|
|
open={isExpanded} |
|
|
|
|
|
onToggle={(e: any) => { |
|
|
|
|
|
setIsExpanded(e.target!.open); |
|
|
|
|
|
}} |
|
|
|
|
|
onClick={(e) => { |
|
|
|
|
|
// We toggle using a button instead of this whole area.
|
|
|
|
|
|
e.preventDefault(); |
|
|
|
|
|
}} |
|
|
|
|
|
ref={ref} |
|
|
className={cn('my-12 rounded-lg shadow-inner relative', { |
|
|
className={cn('my-12 rounded-lg shadow-inner relative', { |
|
|
'dark:bg-opacity-20 dark:bg-purple-60 bg-purple-5': isDeepDive, |
|
|
'dark:bg-opacity-20 dark:bg-purple-60 bg-purple-5': isDeepDive, |
|
|
'dark:bg-opacity-20 dark:bg-yellow-60 bg-yellow-5': isExample, |
|
|
'dark:bg-opacity-20 dark:bg-yellow-60 bg-yellow-5': isExample, |
|
|
})}> |
|
|
})}> |
|
|
<div className="p-8"> |
|
|
<summary |
|
|
|
|
|
className="list-none p-8" |
|
|
|
|
|
tabIndex={-1 /* there's a button instead */}> |
|
|
<h5 |
|
|
<h5 |
|
|
className={cn('mb-4 uppercase font-bold flex items-center text-sm', { |
|
|
className={cn('mb-4 uppercase font-bold flex items-center text-sm', { |
|
|
'dark:text-purple-30 text-purple-50': isDeepDive, |
|
|
'dark:text-purple-30 text-purple-50': isDeepDive, |
|
@ -71,16 +83,15 @@ function ExpandableExample({ |
|
|
</span> |
|
|
</span> |
|
|
{isExpanded ? 'Hide Details' : 'Show Details'} |
|
|
{isExpanded ? 'Hide Details' : 'Show Details'} |
|
|
</Button> |
|
|
</Button> |
|
|
</div> |
|
|
</summary> |
|
|
<div |
|
|
<div |
|
|
className={cn('p-8 border-t', { |
|
|
className={cn('p-8 border-t', { |
|
|
'dark:border-purple-60 border-purple-10 ': isDeepDive, |
|
|
'dark:border-purple-60 border-purple-10 ': isDeepDive, |
|
|
'dark:border-yellow-60 border-yellow-50': isExample, |
|
|
'dark:border-yellow-60 border-yellow-50': isExample, |
|
|
hidden: !isExpanded, |
|
|
|
|
|
})}> |
|
|
})}> |
|
|
{children} |
|
|
{children} |
|
|
</div> |
|
|
</div> |
|
|
</div> |
|
|
</details> |
|
|
); |
|
|
); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|