Skip to content

Commit 4aa7be2

Browse files
committed
✨ Extraie ImageFileInput et IconFileInput
Depuis Hedwige
1 parent 05b058d commit 4aa7be2

3 files changed

Lines changed: 52 additions & 0 deletions

File tree

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
2+
@mixin icon() {
3+
object-fit: cover;
4+
border-radius: 3px;
5+
}
6+
7+
.icon-preview {
8+
@include icon;
9+
width: 78px;
10+
height: 78px;
11+
12+
&__small {
13+
@include icon;
14+
width: 36px;
15+
height: 36px;
16+
}
17+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
class IconFileInput < ImageFileInput
2+
def image_preview_html_options
3+
options = super
4+
options[:class] ||= ''
5+
options[:class] += ' icon-preview'
6+
options
7+
end
8+
end
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
class ImageFileInput < Formtastic::Inputs::FileInput
2+
def to_html
3+
input_wrapping do
4+
label_html <<
5+
builder.file_field(method, input_html_options) <<
6+
image_preview_html
7+
end
8+
end
9+
10+
def image_preview_html
11+
if object.send(method)&.attached?
12+
builder.template.image_tag(object.send(method), image_preview_html_options)
13+
else
14+
''
15+
end
16+
end
17+
18+
def input_html_options
19+
{
20+
accept: 'image/*',
21+
}.merge(super)
22+
end
23+
24+
def image_preview_html_options
25+
options[:image_preview_html] ||= { style: 'max-width: 100%;' }
26+
end
27+
end

0 commit comments

Comments
 (0)