fix: split component file

This commit is contained in:
p-sw 2024-06-14 23:59:50 +09:00
parent 2a53a2d3e9
commit 22ab752b75
3 changed files with 36 additions and 27 deletions

View File

@ -1,32 +1,13 @@
import React, { Dispatch, SetStateAction, useState } from "react";
import React, { useState } from "react";
import { Slot, VariantProps, vcn } from "@pswui-lib";
import ReactDOM from "react-dom";
/**
* =========================
* DialogContext
* =========================
*/
interface DialogContext {
opened: boolean;
}
const initialDialogContext: DialogContext = { opened: false };
const DialogContext = React.createContext<
[DialogContext, Dispatch<SetStateAction<DialogContext>>]
>([
import {
DialogContext,
initialDialogContext,
() => {
if (process.env.NODE_ENV && process.env.NODE_ENV === "development") {
console.warn(
"It seems like you're using DialogContext outside of a provider.",
);
}
},
]);
const useDialogContext = () => React.useContext(DialogContext);
useDialogContext,
IDialogContext,
} from "./Context";
/**
* =========================
@ -39,7 +20,7 @@ interface DialogRootProps {
}
const DialogRoot = ({ children }: DialogRootProps) => {
const state = useState<DialogContext>(initialDialogContext);
const state = useState<IDialogContext>(initialDialogContext);
return (
<DialogContext.Provider value={state}>{children}</DialogContext.Provider>
);
@ -411,7 +392,6 @@ const DialogFooter = React.forwardRef<HTMLDivElement, DialogFooterProps>(
);
export {
useDialogContext,
DialogRoot,
DialogTrigger,
DialogOverlay,

View File

@ -0,0 +1,27 @@
import { Dispatch, SetStateAction, useContext, createContext } from "react";
/**
* =========================
* DialogContext
* =========================
*/
export interface IDialogContext {
opened: boolean;
}
export const initialDialogContext: IDialogContext = { opened: false };
export const DialogContext = createContext<
[IDialogContext, Dispatch<SetStateAction<IDialogContext>>]
>([
initialDialogContext,
() => {
if (process.env.NODE_ENV && process.env.NODE_ENV === "development") {
console.warn(
"It seems like you're using DialogContext outside of a provider.",
);
}
},
]);
export const useDialogContext = () => useContext(DialogContext);

View File

@ -0,0 +1,2 @@
export * from "./Component";
export { useDialogContext } from "./Context";