-
Notifications
You must be signed in to change notification settings - Fork 244
Expand file tree
/
Copy pathadmin-widget.tsx
More file actions
161 lines (158 loc) · 5.8 KB
/
Copy pathadmin-widget.tsx
File metadata and controls
161 lines (158 loc) · 5.8 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
import React, { ChangeEvent, useEffect, useState } from "react";
import Settings from "./settings";
import {
horizontalPadding as defaultHorizontalPadding,
verticalPadding as defaultVerticalPadding,
height as defaultHeight,
} from "./defaults";
import {
CssIdField,
AdminWidgetPanel,
ColorSelector,
ContentPaddingSelector,
Form,
FormField,
Select,
Textarea,
AlertTitle,
AlertDescription,
Alert,
} from "@courselit/components-library";
import { AlertCircle, Lightbulb } from "lucide-react";
export default function AdminWidget({
settings,
onChange,
}: {
settings: Settings;
onChange: (...args: any[]) => void;
}) {
const [backgroundColor, setBackgroundColor] = useState(
settings.backgroundColor,
);
const [url, setUrl] = useState(settings.url);
const [script, setScript] = useState(settings.script);
const [aspectRatio, setAspectRatio] = useState(settings.aspectRatio);
const [height, setHeight] = useState(settings.height || defaultHeight);
const [horizontalPadding, setHorizontalPadding] = useState<number>(
settings.horizontalPadding || defaultHorizontalPadding,
);
const [verticalPadding, setVerticalPadding] = useState<number>(
settings.verticalPadding || defaultVerticalPadding,
);
const [cssId, setCssId] = useState(settings.cssId);
useEffect(() => {
onChange({
backgroundColor,
url,
script,
aspectRatio,
height,
horizontalPadding,
verticalPadding,
cssId,
});
}, [
backgroundColor,
url,
script,
aspectRatio,
height,
horizontalPadding,
verticalPadding,
cssId,
]);
return (
<div className="flex flex-col gap-4">
<Alert variant="destructive">
<AlertTitle>
<span className="flex items-center gap-2">
<AlertCircle className="w-4 h-4" /> Beware
</span>
</AlertTitle>
<AlertDescription className="text-sm">
Embedding external content may have security implications.
Only embed content from trusted sources.
</AlertDescription>
</Alert>
<AdminWidgetPanel title="Content">
<Form className="flex flex-col gap-4">
<FormField
label="URL"
value={url}
onChange={(e: ChangeEvent<HTMLInputElement>) =>
setUrl(e.target.value)
}
/>
<div className="flex items-center gap-4 my-1">
<hr className="flex-grow border-t border-gray-300" />
<span className="text-gray-500 text-sm font-medium">
OR
</span>
<hr className="flex-grow border-t border-gray-300" />
</div>
<div className="flex flex-col gap-2">
<label className="mb-1 font-semibold">Script</label>
<Textarea
value={script}
rows={10}
onChange={(e: ChangeEvent<HTMLTextAreaElement>) =>
setScript(e.target.value)
}
/>
</div>
<div className="text-xs text-gray-500 flex items-center gap-1">
<Lightbulb className="w-4 h-4" />
<p>
If you use the script option, the URL option will be
ignored.
</p>
</div>
</Form>
</AdminWidgetPanel>
<AdminWidgetPanel title="Design" className="flex flex-col gap-4">
<Form className="flex flex-col gap-4">
<FormField
label="Height"
type="number"
value={height}
min={0}
onChange={(e: ChangeEvent<HTMLInputElement>) =>
setHeight(Number(e.target.value))
}
/>
<Select
title="Aspect ratio"
value={aspectRatio}
onChange={(value?: string) =>
setAspectRatio(value as "16:9" | "4:3" | "1:1")
}
options={[
{ label: "Default", value: "default" },
{ label: "16:9", value: "16:9" },
{ label: "4:3", value: "4:3" },
{ label: "1:1", value: "1:1" },
]}
/>
</Form>
<ColorSelector
title="Background color"
value={backgroundColor || "inherit"}
onChange={(value?: string) => setBackgroundColor(value)}
/>
<ContentPaddingSelector
value={horizontalPadding}
min={50}
onChange={setHorizontalPadding}
/>
<ContentPaddingSelector
variant="vertical"
value={verticalPadding}
onChange={setVerticalPadding}
/>
</AdminWidgetPanel>
<AdminWidgetPanel title="Advanced">
<CssIdField value={cssId} onChange={setCssId} />
</AdminWidgetPanel>
</div>
);
}