From c1528d743a35f921d98a1c8ba4adc6feab8ca2e8 Mon Sep 17 00:00:00 2001 From: yarema184 Date: Mon, 6 Nov 2023 17:11:44 +0200 Subject: [PATCH 1/3] Add new code preview for app [MDS-771] --- docs/app/@types/global.d.ts | 3 + docs/app/components/server/accordion/page.tsx | 2 +- docs/app/components/server/button/page.tsx | 3 +- docs/app/components/shared/CodeCopy.tsx | 49 ++++++++++++ docs/app/components/shared/CodePreview.tsx | 14 ++-- .../components/shared/CodePreviewWrapper.tsx | 74 +++++++++++++++++++ .../components/shared/ComponentPreview.tsx | 2 +- docs/app/components/shared/ExampleSection.tsx | 34 +++++++-- 8 files changed, 168 insertions(+), 13 deletions(-) create mode 100644 docs/app/@types/global.d.ts create mode 100644 docs/app/components/shared/CodeCopy.tsx create mode 100644 docs/app/components/shared/CodePreviewWrapper.tsx diff --git a/docs/app/@types/global.d.ts b/docs/app/@types/global.d.ts new file mode 100644 index 0000000000..81f263a855 --- /dev/null +++ b/docs/app/@types/global.d.ts @@ -0,0 +1,3 @@ +type SC

> = ( + props: P & { children?: React.ReactNode } +) => Promise; diff --git a/docs/app/components/server/accordion/page.tsx b/docs/app/components/server/accordion/page.tsx index fa3b8b63c0..14176819b0 100644 --- a/docs/app/components/server/accordion/page.tsx +++ b/docs/app/components/server/accordion/page.tsx @@ -11,7 +11,7 @@ export default async function Accordion() { const { server } = await getExamples(); const examplesList = Object.keys(server.accordion.examples); return ( -

+

Accordion

diff --git a/docs/app/components/server/button/page.tsx b/docs/app/components/server/button/page.tsx index 9c06553ca9..afb547bccb 100644 --- a/docs/app/components/server/button/page.tsx +++ b/docs/app/components/server/button/page.tsx @@ -15,12 +15,13 @@ export default async function Button() { const { server } = await getExamples(); const examplesList = Object.keys(server.button.examples); return ( -
+

Button

} code={server.button.examples.Default} /> diff --git a/docs/app/components/shared/CodeCopy.tsx b/docs/app/components/shared/CodeCopy.tsx new file mode 100644 index 0000000000..a72c5d0ff5 --- /dev/null +++ b/docs/app/components/shared/CodeCopy.tsx @@ -0,0 +1,49 @@ +import { useState, useCallback } from 'react'; +import { IconButton, Snackbar } from '@heathmont/moon-core-tw'; +import { FilesCopy } from '@heathmont/moon-icons-tw'; + +const CodeCopy = ({ code }: { code: string }) => { + const [snackbar, setSnackbar] = useState(''); + + const openSnackbarHandler = useCallback( + (type: string) => { + if (snackbar) { + setSnackbar(''); + setTimeout(() => { + setSnackbar(type); + }, 400); + } else { + setSnackbar(type); + } + }, + [snackbar] + ); + + const copyCode = () => { + console.log('copyCode', code); + if (navigator?.clipboard) { + navigator.clipboard.writeText(code ? code : ''); + openSnackbarHandler('bottom-center'); + } + }; + return ( + <> + + } + /> + + + Copy code + + + ); +}; + +export default CodeCopy; diff --git a/docs/app/components/shared/CodePreview.tsx b/docs/app/components/shared/CodePreview.tsx index 2e5d83169f..1f7a8af676 100644 --- a/docs/app/components/shared/CodePreview.tsx +++ b/docs/app/components/shared/CodePreview.tsx @@ -1,7 +1,11 @@ -const CodePreview = ({ code }: { code: string }) => ( -
-    {code}
-  
-); +import CodePreviewWrapper from './CodePreviewWrapper'; + +const CodePreview = ({ code }: { code: string }) => { + return ( + +
{code}
+
+ ); +}; export default CodePreview; diff --git a/docs/app/components/shared/CodePreviewWrapper.tsx b/docs/app/components/shared/CodePreviewWrapper.tsx new file mode 100644 index 0000000000..db0f3a9b11 --- /dev/null +++ b/docs/app/components/shared/CodePreviewWrapper.tsx @@ -0,0 +1,74 @@ +'use client'; + +import { useState, useEffect, useRef } from 'react'; +import { mergeClassnames } from '@heathmont/moon-base-tw'; +import { ControlsChevronDown } from '@heathmont/moon-icons-tw'; +import CodeCopy from './CodeCopy'; + +const CodePreviewWrapper = ({ + children, + code, +}: { + children?: React.ReactNode; + code: string; +}) => { + const [expand, setExpand] = useState(false); + const [height, setHeight] = useState(0); + const wrapperRef = useRef(null); + const clickHandler = () => { + setExpand(!expand); + }; + useEffect(() => { + if (wrapperRef) { + setHeight(wrapperRef?.current?.querySelector('#code')?.clientHeight || 0); + } + }, []); + return ( +
+
+ {children} +
+ + {height > 72 && ( +
+ +
+ )} +
+ ); +}; + +export default CodePreviewWrapper; diff --git a/docs/app/components/shared/ComponentPreview.tsx b/docs/app/components/shared/ComponentPreview.tsx index a077a8fd40..3b9947a79a 100644 --- a/docs/app/components/shared/ComponentPreview.tsx +++ b/docs/app/components/shared/ComponentPreview.tsx @@ -1,7 +1,7 @@ const ComponentPreview = ({ component }: { component: JSX.Element }) => (
{component} diff --git a/docs/app/components/shared/ExampleSection.tsx b/docs/app/components/shared/ExampleSection.tsx index 937f41ac13..e6cfde833d 100644 --- a/docs/app/components/shared/ExampleSection.tsx +++ b/docs/app/components/shared/ExampleSection.tsx @@ -1,17 +1,41 @@ +import { mergeClassnames } from '@heathmont/moon-base-tw'; +import { GenericLink } from '@heathmont/moon-icons-tw'; import CodePreview from './CodePreview'; import ComponentPreview from './ComponentPreview'; type Props = { title: string; + description?: string | JSX.Element; component: JSX.Element; code: string; }; -const ExampleSection = async ({ title, component, code }: Props) => ( -
-

{title}

- - +const ExampleSection: SC = async ({ + title, + description, + component, + code, +}) => ( +
+

+ {title} + +

+ {description && ( +
{description}
+ )} +
+ + +
); From 712e376ffb92b0a10b2b63161ec432033d8ccd53 Mon Sep 17 00:00:00 2001 From: yarema184 Date: Tue, 7 Nov 2023 16:27:04 +0200 Subject: [PATCH 2/3] New code preview widget [MDS-771] --- docs/app/components/server/accordion/page.tsx | 2 +- docs/app/components/server/button/page.tsx | 2 +- docs/app/components/server/checkbox/page.tsx | 2 +- docs/app/components/server/chip/page.tsx | 2 +- docs/app/components/server/input/page.tsx | 2 +- docs/app/components/server/loader/page.tsx | 2 +- .../components/server/nativeSelect/page.tsx | 2 +- .../app/components/server/pagination/page.tsx | 2 +- docs/app/components/server/table/page.tsx | 2 +- docs/app/components/server/tabs/page.tsx | 2 +- docs/app/components/server/tag/page.tsx | 2 +- docs/app/components/shared/CodeCopy.tsx | 13 ++++--- .../components/shared/CodePreviewWrapper.tsx | 35 +++++++++---------- .../components/shared/ComponentPreview.tsx | 2 +- docs/app/components/shared/ExampleSection.tsx | 23 ++++++------ 15 files changed, 47 insertions(+), 48 deletions(-) diff --git a/docs/app/components/server/accordion/page.tsx b/docs/app/components/server/accordion/page.tsx index 14176819b0..718b590d9c 100644 --- a/docs/app/components/server/accordion/page.tsx +++ b/docs/app/components/server/accordion/page.tsx @@ -11,7 +11,7 @@ export default async function Accordion() { const { server } = await getExamples(); const examplesList = Object.keys(server.accordion.examples); return ( -
+

Accordion

diff --git a/docs/app/components/server/button/page.tsx b/docs/app/components/server/button/page.tsx index afb547bccb..6089606b21 100644 --- a/docs/app/components/server/button/page.tsx +++ b/docs/app/components/server/button/page.tsx @@ -15,7 +15,7 @@ export default async function Button() { const { server } = await getExamples(); const examplesList = Object.keys(server.button.examples); return ( -
+

Button

diff --git a/docs/app/components/server/checkbox/page.tsx b/docs/app/components/server/checkbox/page.tsx index 63ce389451..af86b1b326 100644 --- a/docs/app/components/server/checkbox/page.tsx +++ b/docs/app/components/server/checkbox/page.tsx @@ -8,7 +8,7 @@ export default async function Checkbox() { const { server } = await getExamples(); const examplesList = Object.keys(server.checkbox.examples); return ( -
+

Checkbox

diff --git a/docs/app/components/server/chip/page.tsx b/docs/app/components/server/chip/page.tsx index 70ca65e179..5d3027d427 100644 --- a/docs/app/components/server/chip/page.tsx +++ b/docs/app/components/server/chip/page.tsx @@ -8,7 +8,7 @@ export default async function Chip() { const { server } = await getExamples(); const examplesList = Object.keys(server.chip.examples); return ( -
+

Chip

diff --git a/docs/app/components/server/input/page.tsx b/docs/app/components/server/input/page.tsx index c1c8064d43..5f2abbbad4 100644 --- a/docs/app/components/server/input/page.tsx +++ b/docs/app/components/server/input/page.tsx @@ -8,7 +8,7 @@ export default async function Input() { const { server } = await getExamples(); const examplesList = Object.keys(server.input.examples); return ( -
+

Input

diff --git a/docs/app/components/server/loader/page.tsx b/docs/app/components/server/loader/page.tsx index 7e532cc0b6..43e7ea5168 100644 --- a/docs/app/components/server/loader/page.tsx +++ b/docs/app/components/server/loader/page.tsx @@ -8,7 +8,7 @@ export default async function Loader() { const { server } = await getExamples(); const examplesList = Object.keys(server.loader.examples); return ( -
+

Loader

diff --git a/docs/app/components/server/nativeSelect/page.tsx b/docs/app/components/server/nativeSelect/page.tsx index 9fe32c35d7..af647bb572 100644 --- a/docs/app/components/server/nativeSelect/page.tsx +++ b/docs/app/components/server/nativeSelect/page.tsx @@ -8,7 +8,7 @@ export default async function NativeSelect() { const { server } = await getExamples(); const examplesList = Object.keys(server.nativeSelect.examples); return ( -
+

NativeSelect

diff --git a/docs/app/components/server/pagination/page.tsx b/docs/app/components/server/pagination/page.tsx index fc2ad6cbff..4b1f2ceeb8 100644 --- a/docs/app/components/server/pagination/page.tsx +++ b/docs/app/components/server/pagination/page.tsx @@ -8,7 +8,7 @@ export default async function Pagination() { const { server } = await getExamples(); const examplesList = Object.keys(server.pagination.examples); return ( -
+

Pagination

diff --git a/docs/app/components/server/table/page.tsx b/docs/app/components/server/table/page.tsx index a53d5609ed..22d1e3e687 100644 --- a/docs/app/components/server/table/page.tsx +++ b/docs/app/components/server/table/page.tsx @@ -8,7 +8,7 @@ export default async function Table() { const { server } = await getExamples(); const examplesList = Object.keys(server.table.examples); return ( -
+

Table

diff --git a/docs/app/components/server/tabs/page.tsx b/docs/app/components/server/tabs/page.tsx index e397a6dd4a..7398935c29 100644 --- a/docs/app/components/server/tabs/page.tsx +++ b/docs/app/components/server/tabs/page.tsx @@ -8,7 +8,7 @@ export default async function Tabs() { const { server } = await getExamples(); const examplesList = Object.keys(server.tabs.examples); return ( -
+

Tabs

diff --git a/docs/app/components/server/tag/page.tsx b/docs/app/components/server/tag/page.tsx index 946da63543..d3bf686a4a 100644 --- a/docs/app/components/server/tag/page.tsx +++ b/docs/app/components/server/tag/page.tsx @@ -8,7 +8,7 @@ export default async function Tag() { const { server } = await getExamples(); const examplesList = Object.keys(server.tag.examples); return ( -
+

Tag

diff --git a/docs/app/components/shared/CodeCopy.tsx b/docs/app/components/shared/CodeCopy.tsx index a72c5d0ff5..6d1618e27e 100644 --- a/docs/app/components/shared/CodeCopy.tsx +++ b/docs/app/components/shared/CodeCopy.tsx @@ -1,6 +1,6 @@ import { useState, useCallback } from 'react'; import { IconButton, Snackbar } from '@heathmont/moon-core-tw'; -import { FilesCopy } from '@heathmont/moon-icons-tw'; +import { FilesCopy, GenericCheckAlternative } from '@heathmont/moon-icons-tw'; const CodeCopy = ({ code }: { code: string }) => { const [snackbar, setSnackbar] = useState(''); @@ -23,7 +23,7 @@ const CodeCopy = ({ code }: { code: string }) => { console.log('copyCode', code); if (navigator?.clipboard) { navigator.clipboard.writeText(code ? code : ''); - openSnackbarHandler('bottom-center'); + openSnackbarHandler('top-right'); } }; return ( @@ -36,11 +36,14 @@ const CodeCopy = ({ code }: { code: string }) => { /> - Copy code + + + Copy code + ); diff --git a/docs/app/components/shared/CodePreviewWrapper.tsx b/docs/app/components/shared/CodePreviewWrapper.tsx index db0f3a9b11..617dc82abb 100644 --- a/docs/app/components/shared/CodePreviewWrapper.tsx +++ b/docs/app/components/shared/CodePreviewWrapper.tsx @@ -2,7 +2,7 @@ import { useState, useEffect, useRef } from 'react'; import { mergeClassnames } from '@heathmont/moon-base-tw'; -import { ControlsChevronDown } from '@heathmont/moon-icons-tw'; +import { ControlsChevronDownSmall } from '@heathmont/moon-icons-tw'; import CodeCopy from './CodeCopy'; const CodePreviewWrapper = ({ @@ -27,12 +27,12 @@ const CodePreviewWrapper = ({
@@ -42,28 +42,27 @@ const CodePreviewWrapper = ({ {height > 72 && (
)} diff --git a/docs/app/components/shared/ComponentPreview.tsx b/docs/app/components/shared/ComponentPreview.tsx index 3b9947a79a..1e9a1dbd52 100644 --- a/docs/app/components/shared/ComponentPreview.tsx +++ b/docs/app/components/shared/ComponentPreview.tsx @@ -1,7 +1,7 @@ const ComponentPreview = ({ component }: { component: JSX.Element }) => (
{component} diff --git a/docs/app/components/shared/ExampleSection.tsx b/docs/app/components/shared/ExampleSection.tsx index e6cfde833d..057c790870 100644 --- a/docs/app/components/shared/ExampleSection.tsx +++ b/docs/app/components/shared/ExampleSection.tsx @@ -16,23 +16,20 @@ const ExampleSection: SC = async ({ component, code, }) => ( -
-

- {title} - +
+

+ + {title} + +

{description && (
{description}
)} -
+
From fc99df8875fd2686ff1b6351c1391b308482e2d7 Mon Sep 17 00:00:00 2001 From: yarema184 Date: Wed, 8 Nov 2023 10:04:47 +0200 Subject: [PATCH 3/3] code refactoring [MDS-771] --- docs/app/components/server/accordion/page.tsx | 2 +- docs/app/components/server/button/page.tsx | 2 +- docs/app/components/server/checkbox/page.tsx | 2 +- docs/app/components/server/chip/page.tsx | 2 +- docs/app/components/server/input/page.tsx | 2 +- docs/app/components/server/loader/page.tsx | 2 +- .../components/server/nativeSelect/page.tsx | 2 +- .../app/components/server/pagination/page.tsx | 2 +- docs/app/components/server/table/page.tsx | 2 +- docs/app/components/server/tabs/page.tsx | 2 +- docs/app/components/server/tag/page.tsx | 2 +- .../components/shared/CodePreviewWrapper.tsx | 73 ------------------- .../{ => exampleSection}/ComponentPreview.tsx | 0 .../{ => exampleSection}/ExampleSection.tsx | 17 +---- .../shared/exampleSection/HeaderSection.tsx | 24 ++++++ .../codePreview}/CodeCopy.tsx | 1 - .../codePreview}/CodePreview.tsx | 2 +- .../wrapper/CodePreviewWrapper.tsx | 49 +++++++++++++ .../codePreview/wrapper/ToggleCodeBtn.tsx | 36 +++++++++ 19 files changed, 124 insertions(+), 100 deletions(-) delete mode 100644 docs/app/components/shared/CodePreviewWrapper.tsx rename docs/app/components/shared/{ => exampleSection}/ComponentPreview.tsx (100%) rename docs/app/components/shared/{ => exampleSection}/ExampleSection.tsx (54%) create mode 100644 docs/app/components/shared/exampleSection/HeaderSection.tsx rename docs/app/components/shared/{ => exampleSection/codePreview}/CodeCopy.tsx (97%) rename docs/app/components/shared/{ => exampleSection/codePreview}/CodePreview.tsx (76%) create mode 100644 docs/app/components/shared/exampleSection/codePreview/wrapper/CodePreviewWrapper.tsx create mode 100644 docs/app/components/shared/exampleSection/codePreview/wrapper/ToggleCodeBtn.tsx diff --git a/docs/app/components/server/accordion/page.tsx b/docs/app/components/server/accordion/page.tsx index 718b590d9c..2faab589b4 100644 --- a/docs/app/components/server/accordion/page.tsx +++ b/docs/app/components/server/accordion/page.tsx @@ -2,7 +2,7 @@ import { ContentOutsideSizes } from '@/app/components/server/accordion/examples/ import { Default } from '@/app/components/server/accordion/examples/Default'; import { Disabled } from '@/app/components/server/accordion/examples/Disabled'; import { Sizes } from '@/app/components/server/accordion/examples/Sizes'; -import ExampleSection from '@/app/components/shared/ExampleSection'; +import ExampleSection from '@/app/components/shared/exampleSection/ExampleSection'; import QuickNav from '@/app/components/shared/QuickNav'; import { getExamples } from '@/app/utils/getExamples'; import { MDX } from '@/components/MDX'; diff --git a/docs/app/components/server/button/page.tsx b/docs/app/components/server/button/page.tsx index 6089606b21..785b6b8d3f 100644 --- a/docs/app/components/server/button/page.tsx +++ b/docs/app/components/server/button/page.tsx @@ -6,7 +6,7 @@ import { Icons } from '@/app/components/server/button/examples/Icons'; import { Multiline } from '@/app/components/server/button/examples/Multiline'; import { Sizes } from '@/app/components/server/button/examples/Sizes'; import { Variants } from '@/app/components/server/button/examples/Variants'; -import ExampleSection from '@/app/components/shared/ExampleSection'; +import ExampleSection from '@/app/components/shared/exampleSection/ExampleSection'; import QuickNav from '@/app/components/shared/QuickNav'; import { getExamples } from '@/app/utils/getExamples'; import { MDX } from '@/components/MDX'; diff --git a/docs/app/components/server/checkbox/page.tsx b/docs/app/components/server/checkbox/page.tsx index af86b1b326..4734044395 100644 --- a/docs/app/components/server/checkbox/page.tsx +++ b/docs/app/components/server/checkbox/page.tsx @@ -1,5 +1,5 @@ import { Default } from '@/app/components/server/checkbox/examples/Default'; -import ExampleSection from '@/app/components/shared/ExampleSection'; +import ExampleSection from '@/app/components/shared/exampleSection/ExampleSection'; import QuickNav from '@/app/components/shared/QuickNav'; import { getExamples } from '@/app/utils/getExamples'; import { MDX } from '@/components/MDX'; diff --git a/docs/app/components/server/chip/page.tsx b/docs/app/components/server/chip/page.tsx index 5d3027d427..5dbde83182 100644 --- a/docs/app/components/server/chip/page.tsx +++ b/docs/app/components/server/chip/page.tsx @@ -1,5 +1,5 @@ import { Default } from '@/app/components/server/chip/examples/Default'; -import ExampleSection from '@/app/components/shared/ExampleSection'; +import ExampleSection from '@/app/components/shared/exampleSection/ExampleSection'; import QuickNav from '@/app/components/shared/QuickNav'; import { getExamples } from '@/app/utils/getExamples'; import { MDX } from '@/components/MDX'; diff --git a/docs/app/components/server/input/page.tsx b/docs/app/components/server/input/page.tsx index 5f2abbbad4..c11af9f9ce 100644 --- a/docs/app/components/server/input/page.tsx +++ b/docs/app/components/server/input/page.tsx @@ -1,5 +1,5 @@ import { Default } from '@/app/components/server/input/examples/Default'; -import ExampleSection from '@/app/components/shared/ExampleSection'; +import ExampleSection from '@/app/components/shared/exampleSection/ExampleSection'; import QuickNav from '@/app/components/shared/QuickNav'; import { getExamples } from '@/app/utils/getExamples'; import { MDX } from '@/components/MDX'; diff --git a/docs/app/components/server/loader/page.tsx b/docs/app/components/server/loader/page.tsx index 43e7ea5168..1dfc4ab520 100644 --- a/docs/app/components/server/loader/page.tsx +++ b/docs/app/components/server/loader/page.tsx @@ -1,5 +1,5 @@ import { Default } from '@/app/components/server/loader/examples/Default'; -import ExampleSection from '@/app/components/shared/ExampleSection'; +import ExampleSection from '@/app/components/shared/exampleSection/ExampleSection'; import QuickNav from '@/app/components/shared/QuickNav'; import { getExamples } from '@/app/utils/getExamples'; import { MDX } from '@/components/MDX'; diff --git a/docs/app/components/server/nativeSelect/page.tsx b/docs/app/components/server/nativeSelect/page.tsx index af647bb572..c036358f0a 100644 --- a/docs/app/components/server/nativeSelect/page.tsx +++ b/docs/app/components/server/nativeSelect/page.tsx @@ -1,5 +1,5 @@ import { Default } from '@/app/components/server/nativeSelect/examples/Default'; -import ExampleSection from '@/app/components/shared/ExampleSection'; +import ExampleSection from '@/app/components/shared/exampleSection/ExampleSection'; import QuickNav from '@/app/components/shared/QuickNav'; import { getExamples } from '@/app/utils/getExamples'; import { MDX } from '@/components/MDX'; diff --git a/docs/app/components/server/pagination/page.tsx b/docs/app/components/server/pagination/page.tsx index 4b1f2ceeb8..959350f594 100644 --- a/docs/app/components/server/pagination/page.tsx +++ b/docs/app/components/server/pagination/page.tsx @@ -1,5 +1,5 @@ import { Default } from '@/app/components/server/pagination/examples/Default'; -import ExampleSection from '@/app/components/shared/ExampleSection'; +import ExampleSection from '@/app/components/shared/exampleSection/ExampleSection'; import QuickNav from '@/app/components/shared/QuickNav'; import { getExamples } from '@/app/utils/getExamples'; import { MDX } from '@/components/MDX'; diff --git a/docs/app/components/server/table/page.tsx b/docs/app/components/server/table/page.tsx index 22d1e3e687..ca27b93040 100644 --- a/docs/app/components/server/table/page.tsx +++ b/docs/app/components/server/table/page.tsx @@ -1,5 +1,5 @@ import { Default } from '@/app/components/server/table/examples/Default'; -import ExampleSection from '@/app/components/shared/ExampleSection'; +import ExampleSection from '@/app/components/shared/exampleSection/ExampleSection'; import QuickNav from '@/app/components/shared/QuickNav'; import { getExamples } from '@/app/utils/getExamples'; import { MDX } from '@/components/MDX'; diff --git a/docs/app/components/server/tabs/page.tsx b/docs/app/components/server/tabs/page.tsx index 7398935c29..f30bf6582f 100644 --- a/docs/app/components/server/tabs/page.tsx +++ b/docs/app/components/server/tabs/page.tsx @@ -1,5 +1,5 @@ import { Default } from '@/app/components/server/tabs/examples/Default'; -import ExampleSection from '@/app/components/shared/ExampleSection'; +import ExampleSection from '@/app/components/shared/exampleSection/ExampleSection'; import QuickNav from '@/app/components/shared/QuickNav'; import { getExamples } from '@/app/utils/getExamples'; import { MDX } from '@/components/MDX'; diff --git a/docs/app/components/server/tag/page.tsx b/docs/app/components/server/tag/page.tsx index d3bf686a4a..cbea18c67e 100644 --- a/docs/app/components/server/tag/page.tsx +++ b/docs/app/components/server/tag/page.tsx @@ -1,5 +1,5 @@ import { Default } from '@/app/components/server/tag/examples/Default'; -import ExampleSection from '@/app/components/shared/ExampleSection'; +import ExampleSection from '@/app/components/shared/exampleSection/ExampleSection'; import QuickNav from '@/app/components/shared/QuickNav'; import { getExamples } from '@/app/utils/getExamples'; import { MDX } from '@/components/MDX'; diff --git a/docs/app/components/shared/CodePreviewWrapper.tsx b/docs/app/components/shared/CodePreviewWrapper.tsx deleted file mode 100644 index 617dc82abb..0000000000 --- a/docs/app/components/shared/CodePreviewWrapper.tsx +++ /dev/null @@ -1,73 +0,0 @@ -'use client'; - -import { useState, useEffect, useRef } from 'react'; -import { mergeClassnames } from '@heathmont/moon-base-tw'; -import { ControlsChevronDownSmall } from '@heathmont/moon-icons-tw'; -import CodeCopy from './CodeCopy'; - -const CodePreviewWrapper = ({ - children, - code, -}: { - children?: React.ReactNode; - code: string; -}) => { - const [expand, setExpand] = useState(false); - const [height, setHeight] = useState(0); - const wrapperRef = useRef(null); - const clickHandler = () => { - setExpand(!expand); - }; - useEffect(() => { - if (wrapperRef) { - setHeight(wrapperRef?.current?.querySelector('#code')?.clientHeight || 0); - } - }, []); - return ( -
-
- {children} -
- - {height > 72 && ( -
- -
- )} -
- ); -}; - -export default CodePreviewWrapper; diff --git a/docs/app/components/shared/ComponentPreview.tsx b/docs/app/components/shared/exampleSection/ComponentPreview.tsx similarity index 100% rename from docs/app/components/shared/ComponentPreview.tsx rename to docs/app/components/shared/exampleSection/ComponentPreview.tsx diff --git a/docs/app/components/shared/ExampleSection.tsx b/docs/app/components/shared/exampleSection/ExampleSection.tsx similarity index 54% rename from docs/app/components/shared/ExampleSection.tsx rename to docs/app/components/shared/exampleSection/ExampleSection.tsx index 057c790870..03c584f149 100644 --- a/docs/app/components/shared/ExampleSection.tsx +++ b/docs/app/components/shared/exampleSection/ExampleSection.tsx @@ -1,7 +1,7 @@ import { mergeClassnames } from '@heathmont/moon-base-tw'; -import { GenericLink } from '@heathmont/moon-icons-tw'; -import CodePreview from './CodePreview'; +import CodePreview from './codePreview/CodePreview'; import ComponentPreview from './ComponentPreview'; +import HeaderSection from './HeaderSection'; type Props = { title: string; @@ -17,18 +17,7 @@ const ExampleSection: SC = async ({ code, }) => (
-

- - {title} - - -

- {description && ( -
{description}
- )} +
diff --git a/docs/app/components/shared/exampleSection/HeaderSection.tsx b/docs/app/components/shared/exampleSection/HeaderSection.tsx new file mode 100644 index 0000000000..0f3351143a --- /dev/null +++ b/docs/app/components/shared/exampleSection/HeaderSection.tsx @@ -0,0 +1,24 @@ +import { GenericLink } from '@heathmont/moon-icons-tw'; + +type Props = { + title?: string; + description?: string | JSX.Element; +}; +const HeaderSection = ({ title, description }: Props) => ( + <> +

+ + {title} + + +

+ {description && ( +
{description}
+ )} + +); + +export default HeaderSection; diff --git a/docs/app/components/shared/CodeCopy.tsx b/docs/app/components/shared/exampleSection/codePreview/CodeCopy.tsx similarity index 97% rename from docs/app/components/shared/CodeCopy.tsx rename to docs/app/components/shared/exampleSection/codePreview/CodeCopy.tsx index 6d1618e27e..ced3cdc829 100644 --- a/docs/app/components/shared/CodeCopy.tsx +++ b/docs/app/components/shared/exampleSection/codePreview/CodeCopy.tsx @@ -20,7 +20,6 @@ const CodeCopy = ({ code }: { code: string }) => { ); const copyCode = () => { - console.log('copyCode', code); if (navigator?.clipboard) { navigator.clipboard.writeText(code ? code : ''); openSnackbarHandler('top-right'); diff --git a/docs/app/components/shared/CodePreview.tsx b/docs/app/components/shared/exampleSection/codePreview/CodePreview.tsx similarity index 76% rename from docs/app/components/shared/CodePreview.tsx rename to docs/app/components/shared/exampleSection/codePreview/CodePreview.tsx index 1f7a8af676..e1cd1e6472 100644 --- a/docs/app/components/shared/CodePreview.tsx +++ b/docs/app/components/shared/exampleSection/codePreview/CodePreview.tsx @@ -1,4 +1,4 @@ -import CodePreviewWrapper from './CodePreviewWrapper'; +import CodePreviewWrapper from './wrapper/CodePreviewWrapper'; const CodePreview = ({ code }: { code: string }) => { return ( diff --git a/docs/app/components/shared/exampleSection/codePreview/wrapper/CodePreviewWrapper.tsx b/docs/app/components/shared/exampleSection/codePreview/wrapper/CodePreviewWrapper.tsx new file mode 100644 index 0000000000..c6d69c053d --- /dev/null +++ b/docs/app/components/shared/exampleSection/codePreview/wrapper/CodePreviewWrapper.tsx @@ -0,0 +1,49 @@ +'use client'; + +import { useState, useEffect, useRef } from 'react'; +import { mergeClassnames } from '@heathmont/moon-base-tw'; +import ToggleCodeBtn from './ToggleCodeBtn'; +import CodeCopy from '../CodeCopy'; + +const CodePreviewWrapper = ({ + children, + code, +}: { + children?: React.ReactNode; + code: string; +}) => { + const [expand, setExpand] = useState(false); + const [height, setHeight] = useState(0); + const wrapperRef = useRef(null); + const clickHandler = () => { + setExpand(!expand); + }; + useEffect(() => { + if (wrapperRef) { + setHeight(wrapperRef?.current?.querySelector('#code')?.clientHeight || 0); + } + }, []); + return ( +
+
+ {children} +
+ + {height > 72 && ( + + )} +
+ ); +}; + +export default CodePreviewWrapper; diff --git a/docs/app/components/shared/exampleSection/codePreview/wrapper/ToggleCodeBtn.tsx b/docs/app/components/shared/exampleSection/codePreview/wrapper/ToggleCodeBtn.tsx new file mode 100644 index 0000000000..59c884875e --- /dev/null +++ b/docs/app/components/shared/exampleSection/codePreview/wrapper/ToggleCodeBtn.tsx @@ -0,0 +1,36 @@ +import { mergeClassnames } from '@heathmont/moon-base-tw'; +import { ControlsChevronDownSmall } from '@heathmont/moon-icons-tw'; + +type Props = { + expand?: boolean; + clickHandler?: () => void; +}; + +const ToggleCodeBtn = ({ expand, clickHandler }: Props) => { + return ( +
+ +
+ ); +}; + +export default ToggleCodeBtn;