Display figure captions as margin notes
On a thin viewport like a phone these show up as hidden at first until the user expands them by interacting with the "writing hand" icon. Each margin note needs a small bit of markup near it to enable the toggle. Each also needs a unique ID to ensure it doesn't interact with alternate content. The `hash` value of the FigureCaption's `children` provides this unique value.
This commit is contained in:
parent
6baba80309
commit
6726dff526
2 changed files with 17 additions and 5 deletions
|
@ -112,15 +112,14 @@ describe PageContent do
|
|||
end
|
||||
|
||||
it "renders a figure and figure caption" do
|
||||
children = [Text.new("A caption")] of Child
|
||||
page = Page.new(
|
||||
title: "Title",
|
||||
subtitle: nil,
|
||||
nodes: [
|
||||
Figure.new(children: [
|
||||
Image.new(src: "image.png", originalWidth: 100, originalHeight: 200),
|
||||
FigureCaption.new(children: [
|
||||
Text.new("A caption"),
|
||||
] of Child),
|
||||
FigureCaption.new(children: children),
|
||||
] of Child),
|
||||
] of Child
|
||||
)
|
||||
|
@ -130,7 +129,11 @@ describe PageContent do
|
|||
html.should eq stripped_html <<-HTML
|
||||
<figure>
|
||||
<img src="https://cdn-images-1.medium.com/fit/c/100/200/image.png" width="100">
|
||||
<figcaption>A caption</figcaption>
|
||||
<label class="margin-toggle" for="#{children.hash}">✍︎</label>
|
||||
<input class="margin-toggle" type="checkbox" id="#{children.hash}">
|
||||
<span class="marginnote">
|
||||
A caption
|
||||
</span>
|
||||
</figure>
|
||||
HTML
|
||||
end
|
||||
|
|
|
@ -43,7 +43,16 @@ class PageContent < BaseComponent
|
|||
end
|
||||
|
||||
def render_child(node : FigureCaption)
|
||||
figcaption { render_children(node.children) }
|
||||
writing_hand = "✍"
|
||||
text_variant = "︎"
|
||||
footnote_id = node.children.hash.to_s
|
||||
label class: "margin-toggle", for: footnote_id do
|
||||
raw writing_hand + text_variant
|
||||
end
|
||||
input class: "margin-toggle", type: "checkbox", id: footnote_id
|
||||
span class: "marginnote" do
|
||||
render_children(node.children)
|
||||
end
|
||||
end
|
||||
|
||||
def render_child(node : Heading2)
|
||||
|
|
Loading…
Reference in a new issue