Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import { PropsWithChildren, createContext, useContext, useState } from "react";
interface ITemplate {
/**
* If the template is being used
*/
enable: boolean;
/**
* URL of the template image being used
*/
url?: string;
/**
* Width of the template being displayed
*
* @default min(template.width,canvas.width)
*/
width?: number;
x: number;
y: number;
opacity: number;
setEnable(v: boolean): void;
setURL(v?: string): void;
setWidth(v?: number): void;
setX(v: number): void;
setY(v: number): void;
setOpacity(v: number): void;
}
const templateContext = createContext<ITemplate>({} as any);
export const useTemplateContext = () => useContext(templateContext);
export const TemplateContext = ({ children }: PropsWithChildren) => {
const [enable, setEnable] = useState(false);
const [url, setURL] = useState<string>();
const [width, setWidth] = useState<number>();
const [x, setX] = useState(0);
const [y, setY] = useState(0);
const [opacity, setOpacity] = useState(100);
return (
<templateContext.Provider
value={{
enable,
setEnable,
url,
setURL,
width,
setWidth,
x,
setX,
y,
setY,
opacity,
setOpacity,
}}
>
{children}
</templateContext.Provider>
);
};