Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🙈 Hide Content based on tags #517

Merged
merged 1 commit into from
Jan 9, 2025
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
7 changes: 7 additions & 0 deletions .changeset/silent-months-trade.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'myst-to-react': patch
'@myst-theme/jupyter': patch
'@myst-theme/site': patch
---

Hide content when tags are activated
8 changes: 6 additions & 2 deletions packages/jupyter/src/output.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { JupyterOutputs } from './jupyter.js';
import { useMemo } from 'react';
import { useCellExecution } from './execute/index.js';
import { usePlaceholder } from './decoration.js';
import { MyST } from 'myst-to-react';
import { Details, MyST } from 'myst-to-react';

export const DIRECT_OUTPUT_TYPES = new Set(['stream', 'error']);

Expand Down Expand Up @@ -91,7 +91,7 @@ export function JupyterOutput({
}

export function Output({ node }: { node: GenericNode }) {
return (
const output = (
<JupyterOutput
className={classNames({ hidden: node.visibility === 'remove' })}
outputId={node.id}
Expand All @@ -100,4 +100,8 @@ export function Output({ node }: { node: GenericNode }) {
data={node.data}
/>
);
if (node.visibility === 'hide') {
return <Details title="Output">{output}</Details>;
}
return output;
}
7 changes: 6 additions & 1 deletion packages/myst-to-react/src/code.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { CopyIcon } from './components/index.js';
import { MyST } from './MyST.js';
import { useMemo } from 'react';
import type { ComponentProps } from 'react';
import { Details } from './dropdown.js';

type Props = {
value: string;
Expand Down Expand Up @@ -117,7 +118,7 @@ export function CodeBlock(props: Props) {
}

const code: NodeRenderer = ({ node }) => {
return (
const child = (
<CodeBlock
identifier={node.html_id}
// data-cell-id={node.executable ? parentId : undefined}
Expand All @@ -135,6 +136,10 @@ const code: NodeRenderer = ({ node }) => {
className={classNames({ hidden: node.visibility === 'remove' }, node.class)}
/>
);
if (node.visibility === 'hide') {
return <Details title="Source">{child}</Details>;
}
return child;
};

function isColor(maybeColorHash: string): string | undefined {
Expand Down
11 changes: 8 additions & 3 deletions packages/site/src/components/ContentBlocks.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MyST } from 'myst-to-react';
import { Details, MyST } from 'myst-to-react';
import { SourceFileKind } from 'myst-spec-ext';
import type { GenericParent } from 'myst-common';
import classNames from 'classnames';
Expand All @@ -22,17 +22,18 @@ export function Block({
className?: string;
}) {
const grid = useGridSystemProvider();
const subGrid = `${grid} subgrid-gap col-screen`;
const subGrid = node.visibility === 'hide' ? '' : `${grid} subgrid-gap col-screen`;
const dataClassName = typeof node.data?.class === 'string' ? node.data?.class : undefined;
// Hide the subgrid if either the dataClass or the className exists and includes `col-`
const noSubGrid =
(dataClassName && dataClassName.includes('col-')) || (className && className.includes('col-'));
return (
const block = (
<div
key={`block-${id}`}
id={id}
className={classNames('relative group/block', className, dataClassName, {
[subGrid]: !noSubGrid,
hidden: node.visibility === 'remove',
})}
>
{pageKind === SourceFileKind.Notebook && isACodeCell(node) && (
Expand All @@ -53,6 +54,10 @@ export function Block({
<MyST ast={node.children} />
</div>
);
if (node.visibility === 'hide') {
return <Details title="Notebook Cell">{block}</Details>;
}
return block;
}

export function ContentBlocks({
Expand Down
Loading