Skip to content

Commit 70beb82

Browse files
committed
Update the visual code component to support iframes
1 parent 937a03e commit 70beb82

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

app/components/docs/visual_code_example.rb

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@ def self.reset_collected_code
1313
@@collected_code = []
1414
end
1515

16-
def initialize(title: nil, description: nil, context: nil)
16+
def initialize(title: nil, description: nil, src: nil, context: nil)
1717
@title = title
1818
@description = description
19+
@src = src
1920
@context = context
2021
end
2122

@@ -43,7 +44,7 @@ def view_template(&)
4344
def render_header
4445
div do
4546
if @title
46-
div(class: "flex items-center gap-x-2 mb-1") do
47+
div do
4748
Components.Heading(level: 4) { @title.capitalize }
4849
end
4950
end
@@ -71,6 +72,20 @@ def render_tab_contents(&)
7172
end
7273

7374
def render_preview_tab(&block)
75+
return iframe_preview if @src
76+
77+
raw_preview
78+
end
79+
80+
def iframe_preview
81+
div(class: "relative aspect-[4/2.5] w-full overflow-hidden rounded-md border") do
82+
div(class: "absolute inset-0 hidden w-[1600px] bg-background md:block") do
83+
iframe(src: @src, class: "size-full")
84+
end
85+
end
86+
end
87+
88+
def raw_preview
7489
div(class: "mt-2 ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 relative rounded-md border") do
7590
div(class: "preview flex min-h-[350px] w-full justify-center p-10 items-center") do
7691
decoded_code = CGI.unescapeHTML(@display_code)

0 commit comments

Comments
 (0)