|
1 | 1 | import { HTMLPreview } from "types"; |
2 | | -import ExpandIcon from "./ExpandIcon"; |
3 | 2 |
|
4 | 3 | const Preview: React.FC<{ |
5 | 4 | htmlPreview: HTMLPreview; |
6 | | - isResponsiveExpanded: boolean; |
7 | | - setIsResponsiveExpanded: (value: boolean) => void; |
8 | 5 | }> = (props) => { |
9 | | - const previewWidths = [45, 80, 140]; |
10 | | - const labels = ["sm", "md", "lg"]; |
| 6 | + const targetWidth = 240; |
| 7 | + const targetHeight = 120; |
| 8 | + const scaleFactor = Math.min( |
| 9 | + targetWidth / props.htmlPreview.size.width, |
| 10 | + targetHeight / props.htmlPreview.size.height, |
| 11 | + ); |
11 | 12 |
|
12 | 13 | return ( |
13 | 14 | <div className="flex flex-col w-full"> |
14 | 15 | <div className="py-1.5 flex gap-2 w-full text-lg font-medium text-center dark:text-white rounded-lg justify-between"> |
15 | 16 | <span>Responsive Preview</span> |
16 | | - <button |
17 | | - className={`px-2 py-1 text-sm font-semibold border border-green-500 rounded-md shadow-sm hover:bg-green-500 dark:hover:bg-green-600 hover:text-white hover:border-transparent transition-all duration-300 ${"bg-neutral-100 dark:bg-neutral-700 text-neutral-700 dark:text-neutral-200 border-neutral-300 dark:border-neutral-600"}`} |
18 | | - onClick={() => { |
19 | | - props.setIsResponsiveExpanded(!props.isResponsiveExpanded); |
20 | | - }} |
21 | | - > |
22 | | - <ExpandIcon size={16} /> |
23 | | - </button> |
24 | 17 | </div> |
25 | 18 | <div className="flex gap-2 justify-center items-center"> |
26 | | - {previewWidths.map((targetWidth, index) => { |
27 | | - const targetHeight = props.isResponsiveExpanded ? 260 : 120; |
28 | | - const scaleFactor = Math.min( |
29 | | - targetWidth / props.htmlPreview.size.width, |
30 | | - targetHeight / props.htmlPreview.size.height, |
31 | | - ); |
32 | | - return ( |
| 19 | + <div |
| 20 | + className="relative flex flex-col items-center" |
| 21 | + style={{ |
| 22 | + width: targetWidth, |
| 23 | + resize: "both", |
| 24 | + overflow: "auto", |
| 25 | + minWidth: "100px", |
| 26 | + minHeight: "100px", |
| 27 | + }} |
| 28 | + > |
| 29 | + <div |
| 30 | + className="flex flex-col justify-center items-center border border-neutral-200 dark:border-neutral-700 rounded-md shadow-sm w-full h-full" |
| 31 | + style={{ |
| 32 | + clipPath: "inset(0px round 6px)", |
| 33 | + }} |
| 34 | + > |
33 | 35 | <div |
34 | | - key={"preview " + index} |
35 | | - className="relative flex flex-col items-center" |
36 | | - style={{ width: targetWidth }} |
37 | | - > |
38 | | - <div |
39 | | - className="flex flex-col justify-center items-center border border-neutral-200 dark:border-neutral-700 rounded-md shadow-sm" |
40 | | - style={{ |
41 | | - width: targetWidth, |
42 | | - height: targetHeight, |
43 | | - clipPath: "inset(0px round 6px)", |
44 | | - }} |
45 | | - > |
46 | | - <div |
47 | | - style={{ |
48 | | - zoom: scaleFactor, |
49 | | - width: "100%", |
50 | | - height: "100%", |
51 | | - display: "flex", |
52 | | - }} |
53 | | - dangerouslySetInnerHTML={{ |
54 | | - __html: props.htmlPreview.content, |
55 | | - }} |
56 | | - /> |
57 | | - </div> |
58 | | - <span className="mt-auto text-xs text-gray-500"> |
59 | | - {labels[index]} |
60 | | - </span> |
61 | | - </div> |
62 | | - ); |
63 | | - })} |
| 36 | + style={{ |
| 37 | + zoom: scaleFactor, |
| 38 | + width: "100%", |
| 39 | + height: "100%", |
| 40 | + }} |
| 41 | + dangerouslySetInnerHTML={{ |
| 42 | + __html: props.htmlPreview.content, |
| 43 | + }} |
| 44 | + /> |
| 45 | + </div> |
| 46 | + </div> |
64 | 47 | </div> |
65 | 48 | </div> |
66 | 49 | ); |
|
0 commit comments