Skip to content

Commit

Permalink
Allowed hiding demo code in LiveExample (#2350)
Browse files Browse the repository at this point in the history
  • Loading branch information
smmr-dn authored Nov 20, 2024
1 parent 50f49aa commit 8256de8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
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;
};
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

0 comments on commit 8256de8

Please sign in to comment.