fix: split component file
This commit is contained in:
parent
2a53a2d3e9
commit
22ab752b75
@ -1,32 +1,13 @@
|
|||||||
import React, { Dispatch, SetStateAction, useState } from "react";
|
import React, { useState } from "react";
|
||||||
import { Slot, VariantProps, vcn } from "@pswui-lib";
|
import { Slot, VariantProps, vcn } from "@pswui-lib";
|
||||||
import ReactDOM from "react-dom";
|
import ReactDOM from "react-dom";
|
||||||
|
|
||||||
/**
|
import {
|
||||||
* =========================
|
DialogContext,
|
||||||
* DialogContext
|
|
||||||
* =========================
|
|
||||||
*/
|
|
||||||
|
|
||||||
interface DialogContext {
|
|
||||||
opened: boolean;
|
|
||||||
}
|
|
||||||
|
|
||||||
const initialDialogContext: DialogContext = { opened: false };
|
|
||||||
const DialogContext = React.createContext<
|
|
||||||
[DialogContext, Dispatch<SetStateAction<DialogContext>>]
|
|
||||||
>([
|
|
||||||
initialDialogContext,
|
initialDialogContext,
|
||||||
() => {
|
useDialogContext,
|
||||||
if (process.env.NODE_ENV && process.env.NODE_ENV === "development") {
|
IDialogContext,
|
||||||
console.warn(
|
} from "./Context";
|
||||||
"It seems like you're using DialogContext outside of a provider.",
|
|
||||||
);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
]);
|
|
||||||
|
|
||||||
const useDialogContext = () => React.useContext(DialogContext);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* =========================
|
* =========================
|
||||||
@ -39,7 +20,7 @@ interface DialogRootProps {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const DialogRoot = ({ children }: DialogRootProps) => {
|
const DialogRoot = ({ children }: DialogRootProps) => {
|
||||||
const state = useState<DialogContext>(initialDialogContext);
|
const state = useState<IDialogContext>(initialDialogContext);
|
||||||
return (
|
return (
|
||||||
<DialogContext.Provider value={state}>{children}</DialogContext.Provider>
|
<DialogContext.Provider value={state}>{children}</DialogContext.Provider>
|
||||||
);
|
);
|
||||||
@ -411,7 +392,6 @@ const DialogFooter = React.forwardRef<HTMLDivElement, DialogFooterProps>(
|
|||||||
);
|
);
|
||||||
|
|
||||||
export {
|
export {
|
||||||
useDialogContext,
|
|
||||||
DialogRoot,
|
DialogRoot,
|
||||||
DialogTrigger,
|
DialogTrigger,
|
||||||
DialogOverlay,
|
DialogOverlay,
|
27
packages/react/components/Dialog/Context.ts
Normal file
27
packages/react/components/Dialog/Context.ts
Normal 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);
|
2
packages/react/components/Dialog/index.ts
Normal file
2
packages/react/components/Dialog/index.ts
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
export * from "./Component";
|
||||||
|
export { useDialogContext } from "./Context";
|
Loading…
x
Reference in New Issue
Block a user