From 0a345e73f28e9149154c32cb4420121f157bb319 Mon Sep 17 00:00:00 2001 From: Remy Wang Date: Tue, 9 Jul 2024 09:18:13 +0200 Subject: [PATCH] Support icon in avatar component (#429) * feat: support icon in avatar component * feat: add lookbook preview for icon --- app/components/polaris/avatar_component.html.erb | 2 ++ app/components/polaris/avatar_component.rb | 2 ++ demo/app/previews/avatar_component_preview.rb | 9 +++++++++ demo/app/previews/avatar_component_preview/icon.html.erb | 1 + 4 files changed, 14 insertions(+) create mode 100644 demo/app/previews/avatar_component_preview/icon.html.erb diff --git a/app/components/polaris/avatar_component.html.erb b/app/components/polaris/avatar_component.html.erb index 8d6875a9..1aa65994 100644 --- a/app/components/polaris/avatar_component.html.erb +++ b/app/components/polaris/avatar_component.html.erb @@ -9,6 +9,8 @@ <%= @initials %> + <% elsif @icon %> + <%= polaris_icon(name: @icon) %> <% else %> diff --git a/app/components/polaris/avatar_component.rb b/app/components/polaris/avatar_component.rb index 8ff6c5ec..3ba5dcc9 100644 --- a/app/components/polaris/avatar_component.rb +++ b/app/components/polaris/avatar_component.rb @@ -27,6 +27,7 @@ def initialize( size: SIZE_DEFAULT, shape: SHAPE_DEFAULT, source: nil, + icon: nil, **system_arguments ) @customer = customer @@ -35,6 +36,7 @@ def initialize( @size = size @shape = shape @source = source + @icon = icon @system_arguments = system_arguments end diff --git a/demo/app/previews/avatar_component_preview.rb b/demo/app/previews/avatar_component_preview.rb index 78c2b0d2..9b316230 100644 --- a/demo/app/previews/avatar_component_preview.rb +++ b/demo/app/previews/avatar_component_preview.rb @@ -77,4 +77,13 @@ def image(source: "https://www.redditstatic.com/desktop2x/img/favicon/apple-icon } ) end + + # @param icon text "name of Polaris icon" + def icon(icon: "StoreIcon") + render_with_template( + locals: { + icon: icon + } + ) + end end diff --git a/demo/app/previews/avatar_component_preview/icon.html.erb b/demo/app/previews/avatar_component_preview/icon.html.erb new file mode 100644 index 00000000..760be1f7 --- /dev/null +++ b/demo/app/previews/avatar_component_preview/icon.html.erb @@ -0,0 +1 @@ +<%= polaris_avatar(icon: icon) %>