From a623648ccf1edbd42b8a88869ff592ac0c77659e Mon Sep 17 00:00:00 2001 From: dan Date: Fri, 9 Sep 2022 03:44:28 +0100 Subject: [PATCH] [Beta] Auto-expand on inline search (#5019) --- beta/src/components/MDX/ExpandableExample.tsx | 21 ++++++++++++++----- beta/src/styles/index.css | 4 ++++ 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/beta/src/components/MDX/ExpandableExample.tsx b/beta/src/components/MDX/ExpandableExample.tsx index 3419b9ca..402f1131 100644 --- a/beta/src/components/MDX/ExpandableExample.tsx +++ b/beta/src/components/MDX/ExpandableExample.tsx @@ -22,17 +22,29 @@ function ExpandableExample({ excerpt, type, }: ExpandableExampleProps) { + const ref = React.useRef(null); const [isExpanded, setIsExpanded] = React.useState(false); const isDeepDive = type === 'DeepDive'; const isExample = type === 'Example'; return ( -
{ + 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', { 'dark:bg-opacity-20 dark:bg-purple-60 bg-purple-5': isDeepDive, 'dark:bg-opacity-20 dark:bg-yellow-60 bg-yellow-5': isExample, })}> -
+
{isExpanded ? 'Hide Details' : 'Show Details'} -
+
{children}
-
+ ); } diff --git a/beta/src/styles/index.css b/beta/src/styles/index.css index 1a9bbc92..1482c24a 100644 --- a/beta/src/styles/index.css +++ b/beta/src/styles/index.css @@ -143,6 +143,10 @@ max-width: calc(min(700px, 100%)); } + summary::-webkit-details-marker { + display: none; + } + @keyframes nav-fadein { from { opacity: 0.5;