Skip to content

Commit

Permalink
🗃 Start admonitions in the open position (#452)
Browse files Browse the repository at this point in the history
  • Loading branch information
rowanc1 authored Aug 22, 2024
1 parent d80bcce commit 8e5320b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/two-hotels-own.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'myst-to-react': patch
---

Admonitions can start open
14 changes: 13 additions & 1 deletion packages/myst-to-react/src/admonitions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,19 @@ const WrapperElement = ({
dropdown,
className,
children,
open,
}: {
className?: string;
children: React.ReactNode;
dropdown?: boolean;
open?: boolean;
}) => {
if (dropdown) return <details className={className}>{children}</details>;
if (dropdown)
return (
<details className={className} open={open}>
{children}
</details>
);
return <aside className={className}>{children}</aside>;
};

Expand All @@ -151,6 +158,7 @@ export function Admonition({
children,
hideIcon,
className,
open,
}: {
title?: React.ReactNode;
color?: Color;
Expand All @@ -160,10 +168,12 @@ export function Admonition({
dropdown?: boolean;
hideIcon?: boolean;
className?: string;
open?: boolean;
}) {
return (
<WrapperElement
dropdown={dropdown}
open={open}
className={classNames(
'my-5 shadow-md dark:shadow-2xl dark:shadow-neutral-900',
'bg-gray-50/10 dark:bg-stone-800',
Expand Down Expand Up @@ -239,6 +249,7 @@ export const AdmonitionRenderer: NodeRenderer<AdmonitionSpec> = ({ node }) => {
const isDropdown = classes.includes('dropdown');
const isSimple = classes.includes('simple');
const hideIcon = node.icon === false;
const isOpen = node.open === true;

const useTitle = title?.type === 'admonitionTitle';

Expand All @@ -248,6 +259,7 @@ export const AdmonitionRenderer: NodeRenderer<AdmonitionSpec> = ({ node }) => {
kind={kind}
color={color}
dropdown={isDropdown}
open={isOpen}
simple={isSimple}
hideIcon={hideIcon}
className={classNames(classes)}
Expand Down

0 comments on commit 8e5320b

Please sign in to comment.