Skip to content

Commit

Permalink
Add open in Stackblitz in the documentation (#564)
Browse files Browse the repository at this point in the history
  • Loading branch information
victortrinh2 authored Jan 2, 2025
2 parents 7daa59c + d09a413 commit 672cb06
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 9 deletions.
12 changes: 7 additions & 5 deletions apps/docs/app/playground/headings-link/page.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { allPages } from "contentlayer/generated";
import getSectionLinks from "@/app/lib/getSectionLinks";
import Aside from "@/app/ui/layout/aside/Aside.tsx";
import Mdx from "@/components/mdx/Mdx";
import { allPages } from "contentlayer/generated";
import { notFound } from "next/navigation";
import Aside from "@/app/ui/layout/aside/Aside.tsx";
import getSectionLinks from "@/app/lib/getSectionLinks";

export default function HeadingsLinkPage() {
const page = allPages.find(playgroundPage => playgroundPage._id === "pages/playground-headings-links.mdx");
Expand All @@ -13,13 +13,15 @@ export default function HeadingsLinkPage() {

const sectionLinks = getSectionLinks(page);

const { _id, body: { code } } = page;

return (
<div className="hd-wrapper hd-flex">
<div className="hd-container">
<Aside title="On this page" links={sectionLinks} />
<main>
<article className="hd-content" key={page._id}>
{page.body && <Mdx code={page.body.code} />}
<article className="hd-content" key={_id}>
<Mdx code={code} />
</article>
</main>
</div>
Expand Down
15 changes: 12 additions & 3 deletions apps/docs/app/ui/components/componentExample/ComponentExample.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
"use client";

import { memo, useState, useEffect, type ReactNode } from "react";
import clsx from "clsx";
import { memo, useEffect, useState, type ReactNode } from "react";

import { CodeIcon } from "@/components/icon";
import { CodeIcon, Icon, StackblitzIcon } from "@/components/icon";
import { ToggleButton } from "@/components/toggleButton/ToggleButton.tsx";
import { useToggle } from "@/hooks/useToggle.ts";

import ComponentPreviewWrapper from "./ComponentPreviewWrapper.tsx";

import "./componentExample.css";
import ComponentSkeleton from "@/app/ui/components/componentExample/ComponentSkeleton.tsx";
import LinkButton from "@/components/button/LinkButton.tsx";
import "./componentExample.css";

interface CommonProps {
src: string;
Expand Down Expand Up @@ -78,13 +79,21 @@ const ComponentExample = memo(({
);
};

const openInStackblitzButton = (
<LinkButton variant="secondary" size="sm" href="https://stackblitz.com/edit/hopper-sandbox?file=src%2FComponent.tsx" target="_blank">
Open in Stackblitz
<Icon src={StackblitzIcon} slot="end-icon" />
</LinkButton>
);

const renderPreviewComponent = () => {
if (!showPreviewComponent) {
return null;
}

return (
<ComponentPreviewWrapper
openInStackblitzButton={openInStackblitzButton}
preview={(type === "preview" || type === "both") ? (props as PreviewProps | BothProps).preview : undefined}
toggleButton={renderToggleButton()}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@ import { HopperProvider } from "@hopper-ui/components";
import "./componentPreviewWrapper.css";

interface ComponentPreviewWrapperProps {
openInStackblitzButton?: ReactNode;
preview?: ReactNode;
toggleButton?: ReactNode;
minHeight?: string;
}

const ComponentPreviewWrapper = memo(({ preview, toggleButton, minHeight = "13rem" }: ComponentPreviewWrapperProps) => {
const ComponentPreviewWrapper = memo(({ openInStackblitzButton, preview, toggleButton, minHeight = "13rem" }: ComponentPreviewWrapperProps) => {
const { colorMode = "light" } = useContext(ThemeContext);
const [localColorMode, setLocalColorMode] = useState(colorMode);

Expand All @@ -38,6 +39,7 @@ const ComponentPreviewWrapper = memo(({ preview, toggleButton, minHeight = "13re
style={{ minHeight: minHeight }}
>
<div className="hd-component-preview-wrapper__actions">
{openInStackblitzButton}
{toggleButton}
<ThemeSwitch className="hd-component-preview-wrapper__action"
onChange={toggleTheme}
Expand Down
2 changes: 2 additions & 0 deletions apps/docs/components/button/Button.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"use client";

import { IconContext } from "@/components/icon/IconContext.ts";
import clsx from "clsx";
import { Provider, Button as RACButton, type ButtonProps as RACButtonProps } from "react-aria-components";
Expand Down
3 changes: 3 additions & 0 deletions apps/docs/components/icon/assets/stackblitz.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions apps/docs/components/icon/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import NpmIcon from "./assets/npm.svg";
import ProductMenuIcon from "./assets/product-menu.svg";
import RightAngleIcon from "./assets/right-angle.svg";
import SelectArrowIcon from "./assets/select-arrow.svg";
import StackblitzIcon from "./assets/stackblitz.svg";
import TokenIcon from "./assets/tokens.svg";
import TypescriptIcon from "./assets/typescript.svg";
import WaiAriaIcon from "./assets/wai-aria.svg";
Expand All @@ -34,5 +35,6 @@ export {
GithubIcon, Icon, IconProps, InfoIcon, InternationalIcon,
LineHeightIcon,
MarginIcon, MessageIcon, NpmIcon, ProductMenuIcon, RightAngleIcon, SelectArrowIcon,
StackblitzIcon,
TokenIcon, TypescriptIcon, WaiAriaIcon, WarningIcon
};

0 comments on commit 672cb06

Please sign in to comment.