mirror of
https://github.com/nextui-org/nextui.git
synced 2025-12-08 19:26:11 +00:00
* refactor: replace lodash with native approaches
* refactor(deps): update framer-motion versions
* feat(utilities): add @nextui-org/dom-animation
* refactor(components): load domAnimation dynamically
* refactor(deps): add @nextui-org/dom-animation
* fix(utilities): relocate index.ts
* feat(changeset): framer motion optimization
* chore(deps): bump framer-motion version
* fix(docs): conflict issue
* refactor(hooks): remove the unnecessary this aliasing
* refactor(utilities): remove the unnecessary this aliasing
* chore(docs): remove {} so that it won't be true all the time
* chore(dom-animation): end with new line
* refactor(hooks): use debounce from `@nextui-org/shared-utils`
* chore(deps): add `@nextui-org/shared-utils`
* refactor: move mapKeys logic to `@nextui-org/shared-utils`
* refactor: use `get` from `@nextui-org/shared-utils`
* refactor(docs): use `get` from `@nextui-org/shared-utils`
* refactor(shared-utils): mapKeys
* chore(deps): bump framer-motion version
* chore(deps): remove lodash
* refactor(docs): use intersectionBy from shared-utils
* feat(shared-utils): add intersectionBy
* chore(dom-animation): remove extra blank line
* refactor(shared-utils): revise intersectionBy
* fix(modal): add willChange
* refactor(shared-utils): add comments
* fix: build & tests
---------
Co-authored-by: Junior Garcia <jrgarciadev@gmail.com>
90 lines
2.3 KiB
TypeScript
90 lines
2.3 KiB
TypeScript
"use client";
|
|
|
|
import {FC, useState} from "react";
|
|
import {
|
|
Modal,
|
|
Button,
|
|
ModalContent,
|
|
ModalHeader,
|
|
Link as NextUILink,
|
|
ModalBody,
|
|
ModalFooter,
|
|
Skeleton,
|
|
} from "@nextui-org/react";
|
|
import Link from "next/link";
|
|
|
|
import {CodeWindow} from "@/components/code-window";
|
|
import {useIsMobile} from "@/hooks/use-media-query";
|
|
|
|
export interface DemoCodeModalProps {
|
|
isOpen: boolean;
|
|
code: string;
|
|
title: string;
|
|
subtitle?: string;
|
|
onClose: () => void;
|
|
}
|
|
|
|
export const DemoCodeModal: FC<DemoCodeModalProps> = ({isOpen, code, title, subtitle, onClose}) => {
|
|
const [isCodeVisible, setIsCodeVisible] = useState(false);
|
|
|
|
const isMobile = useIsMobile();
|
|
|
|
const lowerTitle = title.toLowerCase();
|
|
const fileName = `${lowerTitle}.tsx`;
|
|
|
|
return (
|
|
<Modal
|
|
classNames={{
|
|
backdrop: "z-[100002]", // to appear above the navbar
|
|
wrapper: "z-[100003]", // to appear above the backdrop
|
|
}}
|
|
isOpen={isOpen}
|
|
motionProps={{
|
|
onAnimationComplete: () => {
|
|
setIsCodeVisible(isOpen);
|
|
},
|
|
}}
|
|
radius={isMobile ? "none" : "lg"}
|
|
size={isMobile ? "full" : "2xl"}
|
|
onClose={onClose}
|
|
>
|
|
<ModalContent>
|
|
<ModalHeader className="flex flex-col gap-2">
|
|
<h3>{title} code</h3>
|
|
<p className="text-base font-normal">
|
|
{subtitle || (
|
|
<>
|
|
This is an example of how to use the {lowerTitle} component, for more information
|
|
please visit the
|
|
<NextUILink as={Link} href={`/docs/components/${lowerTitle}`}>
|
|
{lowerTitle}
|
|
</NextUILink>
|
|
docs.
|
|
</>
|
|
)}
|
|
</p>
|
|
</ModalHeader>
|
|
<ModalBody className="flex-initial md:pb-6">
|
|
{isCodeVisible ? (
|
|
<CodeWindow
|
|
showCopy
|
|
showWindowIcons
|
|
className="min-h-[320px] !h-[60vh] max-h-full"
|
|
language="jsx"
|
|
title={fileName}
|
|
value={code}
|
|
/>
|
|
) : (
|
|
<Skeleton className="h-[60vh] rounded-xl" />
|
|
)}
|
|
</ModalBody>
|
|
<ModalFooter className="md:hidden">
|
|
<Button fullWidth onPress={onClose}>
|
|
Close
|
|
</Button>
|
|
</ModalFooter>
|
|
</ModalContent>
|
|
</Modal>
|
|
);
|
|
};
|