Skip to content

Commit

Permalink
add dynamic params to AvatarComponent
Browse files Browse the repository at this point in the history
  • Loading branch information
k0va1 committed Jul 25, 2023
1 parent 14223cc commit 1b849e6
Show file tree
Hide file tree
Showing 9 changed files with 79 additions and 15 deletions.
4 changes: 2 additions & 2 deletions app/assets/javascripts/polaris_view_components.js
Original file line number Diff line number Diff line change
Expand Up @@ -2299,8 +2299,8 @@ function popperGenerator(generatorOptions) {
}
}));
function runModifierEffects() {
state.orderedModifiers.forEach((function(_ref3) {
var name = _ref3.name, _ref3$options = _ref3.options, options = _ref3$options === void 0 ? {} : _ref3$options, effect = _ref3.effect;
state.orderedModifiers.forEach((function(_ref) {
var name = _ref.name, _ref$options = _ref.options, options = _ref$options === void 0 ? {} : _ref$options, effect = _ref.effect;
if (typeof effect === "function") {
var cleanupFn = effect({
state: state,
Expand Down
2 changes: 1 addition & 1 deletion app/components/polaris/avatar_component.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<%= render Polaris::BaseComponent.new(**system_arguments) do %>
<% if @source %>
<%= image_tag @source, class: "Polaris-Avatar__Image", role: "presentation" %>
<img src="<%= @source %>" class="Polaris-Avatar__Image" role="presentation" onerror="this.src=''" />
<% else %>
<span class="Polaris-Avatar__Initials">
<% if @initials %>
Expand Down
75 changes: 70 additions & 5 deletions demo/app/previews/avatar_component_preview.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,81 @@
class AvatarComponentPreview < ViewComponent::Preview
def default
# Avatar Component
# ------------
# Avatars are used to show a thumbnail representation of an individual or business in the interface.
#
# @param customer toggle "Whether the avatar is for a customer"
# @param name text "The name of the person"
# @param size select "Size of avatar" {{Polaris::AvatarComponent::SIZE_MAPPINGS.keys}}
# @param shape select "Shape of avatar" {{Polaris::AvatarComponent::SHAPE_MAPPINGS.keys}}
# @param source url "URL of the avatar image which falls back to default if blank"
# @param initials text "Initials of person to display"
def default(
customer: true,
name: "Farrah",
size: :medium,
shape: :round,
source: "https://www.redditstatic.com/desktop2x/img/favicon/apple-icon-180x180.png",
initials: "AK"
)
render_with_template(
locals: {
customer: customer,
name: name,
size: size,
shape: shape,
source: source,
initials: initials
}
)
end

def extra_small

# @param customer toggle "Whether the avatar is for a customer"
# @param name text "The name of the person"
# @param size select "Size of avatar" {{Polaris::AvatarComponent::SIZE_MAPPINGS.keys}}
def basic(customer: true, name: "Farrah", size: :medium)
render_with_template(
locals: {
customer: customer,
name: name,
size: size
}
)
end

# @param size select "Size of avatar" {{Polaris::AvatarComponent::SIZE_MAPPINGS.keys}}
def extra_small(size: :extra_small)
render_with_template(
locals: {
size: size
}
)
end

def square
# @param shape select "Shape of avatar" {{Polaris::AvatarComponent::SHAPE_MAPPINGS.keys}}
def square(shape: :square)
render_with_template(
locals: {
shape: shape
}
)
end

def initials
# @param initials text "Initials of person to display"
def initials(initials: "AK")
render_with_template(
locals: {
initials: initials
}
)
end

def image
# @param source url "URL of the avatar image which falls back to default if blank"
def image(source: "https://www.redditstatic.com/desktop2x/img/favicon/apple-icon-180x180.png")
render_with_template(
locals: {
source: source
}
)
end
end
1 change: 1 addition & 0 deletions demo/app/previews/avatar_component_preview/basic.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<%= polaris_avatar(customer: customer, name: name, size: size) %>
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<%= polaris_avatar(customer: true, name: "Farrah") %>
<%= polaris_avatar(customer: customer, name: name, size: size, shape: shape, source: source, initials: initials) %>
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<%= polaris_avatar(customer: true, size: :extra_small, name: "Farrah") %>
<%= polaris_avatar(size: size) %>
4 changes: 1 addition & 3 deletions demo/app/previews/avatar_component_preview/image.html.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
<%= polaris_avatar(
source: "https://www.redditstatic.com/desktop2x/img/favicon/apple-icon-180x180.png",
) %>
<%= polaris_avatar(source: source) %>
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<%= polaris_avatar(initials: "KP", size: :small) %>
<%= polaris_avatar(initials: initials) %>
2 changes: 1 addition & 1 deletion demo/app/previews/avatar_component_preview/square.html.erb
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<%= polaris_avatar(name: "Shop One", shape: :square) %>
<%= polaris_avatar(shape: shape) %>

0 comments on commit 1b849e6

Please sign in to comment.