A responsive image component.
<br/> <%= pb_rails("image", props: { alt: "picture of a misty forest", size: "xs", url: "https://unsplash.it/500/400/?image=634" }) %> <br/> <%= pb_rails("image", props: { alt: "picture of a misty forest", size: "sm", url: "https://unsplash.it/500/400/?image=634" }) %> <br/> <%= pb_rails("image", props: { alt: "picture of a misty forest", size: "md", url: "https://unsplash.it/500/400/?image=634" }) %> <br/> <%= pb_rails("image", props: { alt: "picture of a misty forest", size: "lg", url: "https://unsplash.it/500/400/?image=634" }) %> <br/> <%= pb_rails("image", props: { alt: "picture of a misty forest", size: "xl", url: "https://unsplash.it/500/400/?image=634" }) %> <br/> <%= pb_rails("image", props: { alt: "picture of a misty forest", url: "https://unsplash.it/500/400/?image=634" }) %>
<%= pb_rails("image", props: { alt: "", rounded: true, size: "xs", url: "https://unsplash.it/500/400/?image=634" }) %> <br> <%= pb_rails("image", props: { alt: "", rounded: true, size: "sm", url: "https://unsplash.it/500/400/?image=634" }) %> <br> <%= pb_rails("image", props: { alt: "", rounded: true, size: "md", url: "https://unsplash.it/500/400/?image=634" }) %> <br> <%= pb_rails("image", props: { alt: "", rounded: true, size: "lg", url: "https://unsplash.it/500/400/?image=634" }) %> <br> <%= pb_rails("image", props: { alt: "", rounded: true, size: "xl", url: "https://unsplash.it/500/400/?image=634" }) %>
<style> .image-error:before { content: "Sorry, the image below seems to be broken."; display: block; margin-bottom: 10px; } .image-error { margin: 5px; padding: 5px; outline: 1px solid red; } </style> <%= pb_rails("body", props: { text: "Handle when an image fails to load or a broken link is passed. This is not neccessary most of the time." } ) %> <br> <br> <%= pb_rails("body", props: { text: "Alter the display when the image fails to load:" } ) %> <%= pb_rails("image", props: { alt: "This is the alt text!", on_error: "this.style.color = 'red'", rounded: true, size: "xs", url: "not_a_picture" } ) %> <br> <br> <%= pb_rails("body", props: { text: "Give it an error class:" } ) %> <%= pb_rails("image", props: { alt: "This is the alt text!", on_error: "this.classList.add('image-error')", padding_x: "none", rounded: true, size: "xs", url: "not_a_picture" } ) %> <br> <br> <%= pb_rails("body", props: { text: "Or hide it completely:" } ) %> <%= pb_rails("image", props: { alt: "This is the alt text!", on_error: "this.style.display = 'none'", rounded: true, size: "xs", url: "not_a_picture", } ) %>
To add a transition, simply use the transition prop and one of the three string options "fade", "blur", or "scale".
<%= pb_rails("flex") do %> <%= pb_rails("flex/flex_item", props: {fixed_size: "250px"}) do %> <%= pb_rails("select", props: { id: "transition-dropdown", label: "", blank_selection: "Select a Transition...", options: [ { value: 'fade', }, { value: 'blur', }, { value: 'scale', }, ] }) %> <% end %> <%= pb_rails("flex/flex_item") do %> <%= pb_rails("button", props: {classname: "button", text: "Load Image", margin_left: "sm", margin_top: "xs", disabled: true }) %> <% end %> <% end %> <%= pb_rails("image", props: { classname: "transition-image", alt: "picture of a misty forest", url: "", on_error: "this.style.display = 'none'" }) %> <script> window.addEventListener('DOMContentLoaded', () => { const button = document.querySelector(".button") const transitionDropdown = document.querySelector("#transition-dropdown") var option = '' transitionDropdown.addEventListener('change', function() { if (this.value === '') { button.className = button.className + ' _disabled' } else { button.removeAttribute("disabled"); button.className = button.className.replace(/\_disabled/gi, '') option = this.value } }); const updateTransition = (transition) => { const imageTransition = document.querySelector('.transition-image') imageTransition.removeAttribute("style") imageTransition.classList.remove("fade", "blur", "scale", "lazyloaded") imageTransition.classList.add(transition, "lazyload") imageTransition.src = "https://unsplash.it/500/400/?image=634" } button.addEventListener('click', function() { updateTransition(option) }) }); </script>
| Props | Type | Values |
|---|---|---|
align_content |
enum | responsive
|
start
end
center
spaceBetween
spaceAround
spaceEvenly
|
align_items |
enum | responsive
|
start
end
center
|
border_radius |
enum
|
none
xs
sm
md
lg
xl
rounded
|
cursor |
enum
|
auto
default
none
contextMenu
help
pointer
progress
wait
cell
|
dark |
boolean
|
true
false
|
flex |
enum | responsive
|
auto
initial
0
1
2
3
4
5
6
7
8
9
10
11
12
none
|
flex_direction |
enum | responsive
|
row
column
rowReverse
columnReverse
|
flex_wrap |
enum | responsive
|
wrap
nowrap
wrapReverse
|
justify_content |
enum | responsive
|
start
end
center
spaceBetween
spaceAround
spaceEvenly
|
line_height |
enum
|
loosest
looser
loose
normal
tight
tighter
tightest
|
margin_right |
array
|
none
xxs
xs
sm
md
lg
xl
|
margin_left |
array
|
none
xxs
xs
sm
md
lg
xl
|
margin_top |
array
|
none
xxs
xs
sm
md
lg
xl
|
margin_bottom |
array
|
none
xxs
xs
sm
md
lg
xl
|
margin_x |
array
|
none
xxs
xs
sm
md
lg
xl
|
margin_y |
array
|
none
xxs
xs
sm
md
lg
xl
|
margin |
array
|
none
xxs
xs
sm
md
lg
xl
|
width |
string
|
|
min_width |
string
|
|
max_width |
string
|
|
gap |
string | responsive
|
|
column_gap |
string | responsive
|
|
row_gap |
string | responsive
|
|
number_spacing |
enum
|
tabular
|
order |
enum | responsive
|
none
first
1
2
3
4
5
6
7
8
9
10
11
12
|
overflow_x |
enum
|
scroll
visible
hidden
auto
|
overflow_y |
enum
|
scroll
visible
hidden
auto
|
overflow |
enum
|
scroll
visible
hidden
auto
|
padding_right |
array
|
none
xxs
xs
sm
md
lg
xl
|
padding_left |
array
|
none
xxs
xs
sm
md
lg
xl
|
padding_top |
array
|
none
xxs
xs
sm
md
lg
xl
|
padding_bottom |
array
|
none
xxs
xs
sm
md
lg
xl
|
padding_x |
array
|
none
xxs
xs
sm
md
lg
xl
|
padding_y |
array
|
none
xxs
xs
sm
md
lg
xl
|
padding |
array
|
none
xxs
xs
sm
md
lg
xl
|
position |
enum
|
relative
absolute
fixed
sticky
static
|
shadow |
enum
|
none
deep
deeper
deepest
|
text_align |
enum | responsive
|
start
end
left
right
center
justify
justifyAll
matchParent
|
truncate |
enum
|
none
1
2
3
4
5
|
vertical_align |
enum | responsive
|
baseline
super
top
middle
bottom
sub
text-top
text-bottom
|
z_index |
enum | responsive
|
1
2
3
4
5
6
7
8
9
10
max
|
top |
enum | object
|
xxs
xs
sm
md
lg
xl
xxl
|
inset |
boolean
|
true
false
|
right |
enum | object
|
xxs
xs
sm
md
lg
xl
xxl
|
bottom |
enum | object
|
xxs
xs
sm
md
lg
xl
xxl
|
left |
enum | object
|
xxs
xs
sm
md
lg
xl
xxl
|
height |
string
|
|
max_height |
string
|
|
min_height |
string
|
|
hover |
object
|
|
group_hover |
boolean
|
true
false
|
| Props | Type | Values | Default |
|---|---|---|---|
alt |
string
|
||
on_error |
string
|
||
rounded |
boolean
|
true
false
|
false
|
size |
enum
|
xs
sm
md
lg
xl
none
|
none
|
transition |
enum
|
blur
fade
scale
none
|
fade
|
url |
string
|