-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feat/DS-127-genereate-component-data' of https://github…
….com/workleap/wl-hopper into feat/DS-127-genereate-component-data
- Loading branch information
Showing
58 changed files
with
867 additions
and
279 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { highlightCode } from "@/components/highlightCode"; | ||
import { getFormattedCode } from "@/app/lib/getComponentCode.ts"; | ||
|
||
export async function mockGetComponentCode(code: string) { | ||
const mockCode = await getFormattedCode(code); | ||
|
||
return await highlightCode(mockCode); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
apps/docs/app/ui/components/componentExample/ComponentCodeWrapper.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { getComponentCode } from "@/app/lib/getComponentCode.ts"; | ||
import HighlightCode from "../../../../components/highlightCode/HighlightCode.tsx"; | ||
|
||
interface ComponentCodeWrapperProps { | ||
src: string; | ||
} | ||
|
||
export const ComponentCodeWrapper = async ({ src }: ComponentCodeWrapperProps) => { | ||
if (!src) { | ||
return null; | ||
} | ||
|
||
const code = await getComponentCode(src); | ||
|
||
return <HighlightCode code={code} />; | ||
}; |
51 changes: 51 additions & 0 deletions
51
apps/docs/app/ui/components/componentExample/ComponentExample.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import type { Meta, StoryObj } from "@storybook/react"; | ||
|
||
import { mockGetComponentCode } from "@/app/lib/getComponentCode.mock.ts"; | ||
import ComponentExample from "./ComponentExample.tsx"; | ||
import HighlightCode from "../../../../components/highlightCode/HighlightCode.tsx"; | ||
import ComponentPreview from "@/app/ui/components/componentExample/ComponentPreview.tsx"; | ||
|
||
const meta = { | ||
title: "components/ComponentExample", | ||
component: ComponentExample, | ||
args: { | ||
src: "buttons/docs/button" | ||
} | ||
} satisfies Meta<typeof ComponentExample>; | ||
|
||
export default meta; | ||
type Story = StoryObj<typeof meta>; | ||
|
||
const mockCode = await mockGetComponentCode("import { Button } from \"@headless/button\""); | ||
const preview = <ComponentPreview src="buttons/docs/button/preview" />; | ||
const MockComponentCodeWrapper = ({ code }: { code: string }) => <HighlightCode code={code} />; | ||
|
||
export const Default: Story = { | ||
args: { | ||
type: "both", | ||
preview, | ||
code: <MockComponentCodeWrapper code={mockCode} /> | ||
} | ||
}; | ||
|
||
export const Code: Story = { | ||
args: { | ||
type: "code", | ||
code: <MockComponentCodeWrapper code={mockCode} /> | ||
} | ||
}; | ||
|
||
export const Preview: Story = { | ||
args: { | ||
type: "preview", | ||
preview | ||
} | ||
}; | ||
|
||
export const Open: Story = { | ||
args: { | ||
type: "code", | ||
code: <MockComponentCodeWrapper code={mockCode} />, | ||
isOpen: true | ||
} | ||
}; |
106 changes: 106 additions & 0 deletions
106
apps/docs/app/ui/components/componentExample/ComponentExample.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
"use client"; | ||
|
||
import { memo, type ReactNode } from "react"; | ||
import clsx from "clsx"; | ||
|
||
import { CodeIcon } from "@/components/icon"; | ||
import { ToggleButton } from "@/components/toggleButton/ToggleButton.tsx"; | ||
import { useToggle } from "@/hooks/useToggle.ts"; | ||
|
||
import ComponentPreviewWrapper from "./ComponentPreviewWrapper.tsx"; | ||
|
||
import "./componentExample.css"; | ||
|
||
interface CommonProps { | ||
src: string; | ||
className?: string; | ||
isOpen?: boolean; | ||
} | ||
|
||
interface CodeProps extends CommonProps { | ||
type: "code"; | ||
code: ReactNode; | ||
} | ||
|
||
interface PreviewProps extends CommonProps { | ||
type: "preview"; | ||
preview: ReactNode; | ||
} | ||
|
||
interface BothProps extends CommonProps { | ||
type: "both"; | ||
code: ReactNode; | ||
preview: ReactNode; | ||
} | ||
|
||
export type ComponentExampleProps = CodeProps | PreviewProps | BothProps; | ||
|
||
const ComponentExample = memo(({ | ||
src, | ||
type = "both", | ||
className, | ||
isOpen = false, | ||
...props | ||
}: ComponentExampleProps) => { | ||
const [showCode, toggleShowCode] = useToggle(isOpen); | ||
|
||
const showBothComponent = type === "both"; | ||
const showPreviewComponent = type === "preview" || showBothComponent; | ||
const showCodeComponent = (showBothComponent && showCode) || type === "code"; | ||
|
||
if (!src) { | ||
return null; | ||
} | ||
|
||
const renderToggleButton = () => { | ||
if (!showBothComponent) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<ToggleButton isSelected={showCode} | ||
className="hd-component-preview-wrapper__action" | ||
onPress={toggleShowCode} | ||
> | ||
<CodeIcon /> | ||
<span>Show code</span> | ||
</ToggleButton> | ||
); | ||
}; | ||
|
||
const renderPreviewComponent = () => { | ||
if (!showPreviewComponent) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<ComponentPreviewWrapper | ||
preview={(type === "preview" || type === "both") ? (props as PreviewProps | BothProps).preview : undefined} | ||
toggleButton={renderToggleButton()} | ||
/> | ||
); | ||
}; | ||
|
||
const renderCodeComponent = () => { | ||
if (!showCodeComponent) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<div className={clsx("hd-component-code", showCodeComponent && "hd-component-code--expanded")}> | ||
{(type === "code" || type === "both") ? (props as CodeProps | BothProps).code : undefined} | ||
</div> | ||
); | ||
}; | ||
|
||
return ( | ||
<div data-usage={type} | ||
className={clsx("hd-component-example", showCodeComponent && "hd-component-example--expanded", className)} | ||
> | ||
{renderPreviewComponent()} | ||
{renderCodeComponent()} | ||
</div> | ||
); | ||
}); | ||
|
||
export default ComponentExample; |
23 changes: 23 additions & 0 deletions
23
apps/docs/app/ui/components/componentExample/ComponentPreview.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
"use client"; | ||
|
||
import { useMemo } from "react"; | ||
import dynamic from "next/dynamic"; | ||
|
||
import ComponentSkeleton from "./ComponentSkeleton.tsx"; | ||
|
||
import "./componentSkeleton.css"; | ||
|
||
interface ComponentPreviewProps { | ||
src: string; | ||
} | ||
|
||
const ComponentPreview = ({ src }: ComponentPreviewProps) => { | ||
const DynamicComponent = useMemo(() => dynamic(() => import(`../../../../../../packages/components/src/${src}.tsx`), { | ||
ssr: false, | ||
loading: () => <ComponentSkeleton overlay /> | ||
}), [src]); | ||
|
||
return <DynamicComponent />; | ||
}; | ||
|
||
export default ComponentPreview; |
51 changes: 51 additions & 0 deletions
51
apps/docs/app/ui/components/componentExample/ComponentPreviewWrapper.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
"use client"; | ||
|
||
import { useState, memo, type ReactNode, useCallback } from "react"; | ||
import Card from "@/components/card/Card.tsx"; | ||
import ThemeSwitch from "@/components/themeSwitch/ThemeSwitch.tsx"; | ||
import type { ColorScheme } from "@/context/theme/ThemeProvider.tsx"; | ||
import { StyledSystemProvider } from "@hopper-ui/styled-system"; | ||
|
||
import "./componentPreviewWrapper.css"; | ||
|
||
interface ComponentPreviewWrapperProps { | ||
preview?: ReactNode; | ||
toggleButton?: ReactNode; | ||
height?: string; | ||
} | ||
|
||
const ComponentPreviewWrapper = memo(({ preview, toggleButton, height = "13rem" }: ComponentPreviewWrapperProps) => { | ||
const [colorScheme, setColorScheme] = useState<"light" | "dark">("light"); | ||
|
||
const toggleTheme = useCallback(() => { | ||
const theme: ColorScheme = colorScheme === "dark" | ||
? "light" | ||
: "dark"; | ||
|
||
setColorScheme(theme); | ||
}, [colorScheme]); | ||
|
||
return ( | ||
<div | ||
className="hd-component-preview-wrapper" | ||
data-schema={colorScheme} | ||
style={{ height: height }} | ||
> | ||
<div className="hd-component-preview-wrapper__actions"> | ||
{toggleButton} | ||
<ThemeSwitch className="hd-component-preview-wrapper__action" | ||
onChange={toggleTheme} | ||
colorMode={colorScheme} | ||
/> | ||
</div> | ||
<Card className="hd-component-preview-wrapper__card" size="sm"> | ||
<StyledSystemProvider colorScheme={colorScheme}> | ||
{preview} | ||
</StyledSystemProvider> | ||
</Card> | ||
|
||
</div> | ||
); | ||
}); | ||
|
||
export default ComponentPreviewWrapper; |
13 changes: 13 additions & 0 deletions
13
apps/docs/app/ui/components/componentExample/ComponentSkeleton.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import clsx from "clsx"; | ||
|
||
interface ComponentSkeletonProps { | ||
overlay?: boolean; | ||
} | ||
|
||
const PreviewSkeleton = ({ overlay = false }: ComponentSkeletonProps) => <div | ||
className={clsx("hd-component-example-skeleton", { | ||
"hd-component-example-skeleton__overlay": overlay | ||
})} | ||
/>; | ||
|
||
export default PreviewSkeleton; |
Oops, something went wrong.