mirror of
https://github.com/nextui-org/nextui.git
synced 2025-12-08 19:26:11 +00:00
* chore(deps): bump RA versions * chore(deps): bump RA versions * chore(deps): bump RA versions * chore: changeset * chore(deps): remove unnecessary dependencies * fix(calendar): typing issue * refactor(system): remove unused SupportedCalendars * refactor(system): move I18nProviderProps to type * refactor: use `spectrumCalendarProps<DateValue>["createCalendar"]` * feat: add consistent-type-imports * fix: eslint * chore: add changeset * refactor: remove unused deps
61 lines
1.6 KiB
TypeScript
61 lines
1.6 KiB
TypeScript
import type {SandpackFiles} from "@codesandbox/sandpack-react/types";
|
|
import type {ButtonProps} from "@/../../packages/components/button/src";
|
|
|
|
import React, {forwardRef} from "react";
|
|
import stackblitzSdk from "@stackblitz/sdk";
|
|
|
|
import {StackblitzIcon} from "./icons";
|
|
|
|
import {useStackblitz} from "@/hooks/use-stackblitz";
|
|
import {Tooltip} from "@/../../packages/components/tooltip/src";
|
|
import {Button} from "@/../../packages/components/button/src";
|
|
|
|
export interface StackblitzButtonProps extends ButtonProps {
|
|
files: SandpackFiles;
|
|
typescriptStrict?: boolean;
|
|
className?: string;
|
|
button?: React.ReactElement;
|
|
icon?: React.ReactNode;
|
|
}
|
|
|
|
export const StackblitzButton = forwardRef<HTMLButtonElement, StackblitzButtonProps>(
|
|
(props, ref) => {
|
|
const {
|
|
files,
|
|
typescriptStrict = false,
|
|
className,
|
|
button = <Button />,
|
|
icon = (
|
|
<StackblitzIcon
|
|
data-visible
|
|
className="opacity-0 data-[visible=true]:opacity-100 transition-transform-opacity"
|
|
/>
|
|
),
|
|
...rest
|
|
} = props;
|
|
const {stackblitzPrefillConfig, entryFile} = useStackblitz({
|
|
files,
|
|
typescriptStrict,
|
|
});
|
|
|
|
return (
|
|
<Tooltip closeDelay={0} content="Open in Stackblitz">
|
|
{React.cloneElement(button, {
|
|
ref,
|
|
className,
|
|
icon,
|
|
onPress: () => {
|
|
stackblitzSdk.openProject(stackblitzPrefillConfig, {
|
|
openFile: [entryFile],
|
|
});
|
|
},
|
|
children: icon,
|
|
...rest,
|
|
})}
|
|
</Tooltip>
|
|
);
|
|
},
|
|
);
|
|
|
|
StackblitzButton.displayName = "StackblitzButton";
|