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

Allowed hiding demo code in LiveExample #2350

Merged
merged 4 commits into from
Nov 20, 2024
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
24 changes: 17 additions & 7 deletions apps/website/src/components/LiveExample.astro
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,23 @@ import itwinuiStyles from '@itwin/itwinui-react/styles.css?url';
const require = createRequire(import.meta.url);

export type Props = {
/** name of the file to read code example from, should be located in ~/examples folder */
/** Name of the file to read code example from, should be located in ~/examples folder */
src: string;

/**
* whether the first code snippet will truncate and turn into an expandable disclosure.
* A flag to determine whether the first code snippet will truncate and turn into an expandable disclosure.
* @default true
*/
truncate?: boolean;

/**
* A flag to determine whether the demo code should be visible.
* @default false
*/
hideCode?: boolean;
mayank99 marked this conversation as resolved.
Show resolved Hide resolved
};

const { src, truncate = true } = Astro.props;
const { src, truncate = true, hideCode = false } = Astro.props;

const jsxPath = require.resolve(`examples/${src}`);
const cssPath = jsxPath.replace(/\.jsx$/, '.css');
Expand Down Expand Up @@ -61,10 +67,14 @@ const cssCode = await (async () => {
/>
</demo-box>

<demo-code>
{truncate && <button aria-expanded='false'>Toggle full code</button>}
<Code code={jsxCode} lang='tsx' theme={'github-dark'} />
</demo-code>
{
!hideCode && (
<demo-code>
{truncate && <button aria-expanded='false'>Toggle full code</button>}
<Code code={jsxCode} lang='tsx' theme={'github-dark'} />
</demo-code>
)
}

<script>
customElements.define(
Expand Down
2 changes: 1 addition & 1 deletion apps/website/src/content/docs/skiptocontentlink.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ thumbnail: #TODO

<p>{frontmatter.description}</p>

<LiveExample src='SkipToContentLink.main.jsx' truncate={true}>
<LiveExample src='SkipToContentLink.main.jsx' hideCode={true}>
<AllExamples.SkipToContentLinkMainExample client:load />
</LiveExample>

Expand Down
Loading