Skip to content

Commit 9a7435e

Browse files
committed
add dynamic params to AvatarComponent
1 parent 14223cc commit 9a7435e

File tree

8 files changed

+74
-15
lines changed

8 files changed

+74
-15
lines changed

app/assets/javascripts/polaris_view_components.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2299,8 +2299,8 @@ function popperGenerator(generatorOptions) {
22992299
}
23002300
}));
23012301
function runModifierEffects() {
2302-
state.orderedModifiers.forEach((function(_ref3) {
2303-
var name = _ref3.name, _ref3$options = _ref3.options, options = _ref3$options === void 0 ? {} : _ref3$options, effect = _ref3.effect;
2302+
state.orderedModifiers.forEach((function(_ref) {
2303+
var name = _ref.name, _ref$options = _ref.options, options = _ref$options === void 0 ? {} : _ref$options, effect = _ref.effect;
23042304
if (typeof effect === "function") {
23052305
var cleanupFn = effect({
23062306
state: state,

app/components/polaris/avatar_component.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<%= render Polaris::BaseComponent.new(**system_arguments) do %>
22
<% if @source %>
3-
<%= image_tag @source, class: "Polaris-Avatar__Image", role: "presentation" %>
3+
<img src="<%= @source %>" class="Polaris-Avatar__Image" role="presentation" onerror="this.src=''" />
44
<% else %>
55
<span class="Polaris-Avatar__Initials">
66
<% if @initials %>
Lines changed: 66 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,77 @@
11
class AvatarComponentPreview < ViewComponent::Preview
2-
def default
2+
# Avatar Component
3+
# ------------
4+
# Avatars are used to show a thumbnail representation of an individual or business in the interface.
5+
#
6+
# @param customer toggle "Whether the avatar is for a customer"
7+
# @param name text "The name of the person"
8+
# @param size select "Size of avatar" {{Polaris::AvatarComponent::SIZE_MAPPINGS.keys}}
9+
def default(customer: true, name: "Farrah", size: :medium)
10+
render_with_template(
11+
locals: {
12+
customer: customer,
13+
name: name,
14+
size: size
15+
}
16+
)
317
end
418

5-
def extra_small
19+
# @param customer toggle "Whether the avatar is for a customer"
20+
# @param name text "The name of the person"
21+
# @param size select "Size of avatar" {{Polaris::AvatarComponent::SIZE_MAPPINGS.keys}}
22+
def extra_small(customer: true, name: "Farrah", size: :extra_small)
23+
render_with_template(
24+
locals: {
25+
customer: customer,
26+
name: name,
27+
size: size
28+
}
29+
)
630
end
731

8-
def square
32+
# @param customer toggle "Whether the avatar is for a customer"
33+
# @param name text "The name of the person"
34+
# @param size select "Size of avatar" {{Polaris::AvatarComponent::SIZE_MAPPINGS.keys}}
35+
# @param shape select "Shape of avatar" {{Polaris::AvatarComponent::SHAPE_MAPPINGS.keys}}
36+
def square(customer: true, name: "Farrah", size: :medium, shape: :square)
37+
render_with_template(
38+
locals: {
39+
customer: customer,
40+
name: name,
41+
size: size,
42+
shape: shape
43+
}
44+
)
945
end
1046

11-
def initials
47+
# @param initials text "Initials of person to display"
48+
# @param size select "Size of avatar" {{Polaris::AvatarComponent::SIZE_MAPPINGS.keys}}
49+
def initials(initials: "AK", size: :medium)
50+
render_with_template(
51+
locals: {
52+
initials: initials,
53+
size: size
54+
}
55+
)
1256
end
1357

14-
def image
58+
# @param size select "Size of avatar" {{Polaris::AvatarComponent::SIZE_MAPPINGS.keys}}
59+
# @param shape select "Shape of avatar" {{Polaris::AvatarComponent::SHAPE_MAPPINGS.keys}}
60+
# @param source url "URL of the avatar image which falls back to default if blank"
61+
# @param initials text "Initials of person to display"
62+
def image(
63+
size: :medium,
64+
shape: :round,
65+
source: "https://www.redditstatic.com/desktop2x/img/favicon/apple-icon-180x180.png",
66+
initials: "AK"
67+
)
68+
render_with_template(
69+
locals: {
70+
size: size,
71+
shape: shape,
72+
source: source,
73+
initials: initials
74+
}
75+
)
1576
end
1677
end
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<%= polaris_avatar(customer: true, name: "Farrah") %>
1+
<%= polaris_avatar(customer: customer, name: name) %>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<%= polaris_avatar(customer: true, size: :extra_small, name: "Farrah") %>
1+
<%= polaris_avatar(customer: customer, size: size, name: name) %>
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
<%= polaris_avatar(
2-
source: "https://www.redditstatic.com/desktop2x/img/favicon/apple-icon-180x180.png",
3-
) %>
1+
<%= polaris_avatar(source: source) %>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<%= polaris_avatar(initials: "KP", size: :small) %>
1+
<%= polaris_avatar(initials: initials, size: size) %>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<%= polaris_avatar(name: "Shop One", shape: :square) %>
1+
<%= polaris_avatar(name: name, shape: shape) %>

0 commit comments

Comments
 (0)