Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Admin] Add "Add Product" button #5263

Merged
merged 2 commits into from
Jul 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
<div class="<%= stimulus_id %>">
<header class="mb-6">
<div class="<%= stimulus_id %> px-4">
<header class="py-6 flex items-center">
<h1 class="body-title">
<%= Spree::Product.model_name.human.pluralize %>
</h1>

<div class="ml-auto">
<%= render @button_component.new(
tag: :a,
text: t('.add_product'),
href: spree.new_admin_product_path,
icon: "plus-line",
classes: "ml-auto"
) %>
</div>
</header>

<%= render @table_component.new(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ class SolidusAdmin::Products::Index::Component < SolidusAdmin::BaseComponent
def initialize(
page:,
badge_component: component('ui/badge'),
table_component: component('ui/table')
table_component: component('ui/table'),
button_component: component("ui/button")
)
@page = page

@badge_component = badge_component
@table_component = table_component
@button_component = button_component
end

def image_column(product)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
en:
product_image: 'Image'
add_product: 'Add Product'
status:
available: 'Available'
discontinued: 'Discontinued'
Expand Down
5 changes: 3 additions & 2 deletions admin/app/components/solidus_admin/ui/button/component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ class SolidusAdmin::UI::Button::Component < SolidusAdmin::BaseComponent
],
}

def initialize(text: nil, class_name: nil, size: :m, scheme: :primary, **attributes)
def initialize(tag: :button, text: nil, class_name: nil, size: :m, scheme: :primary, **attributes)
@tag = tag
@text = text
@attributes = attributes

Expand All @@ -53,6 +54,6 @@ def initialize(text: nil, class_name: nil, size: :m, scheme: :primary, **attribu
end

def call
content_tag(:button, @text, class: @class_name, **@attributes)
content_tag(@tag, @text, class: @class_name, **@attributes)
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,11 @@

</div>
<% end %>

<div class="mb-8">
<h6 class="text-gray-500 mb-3 mt-0">
As a link
</h6>

<%= render current_component.new(tag: :a, href: "#", text: "I'm a link!") %>
</div>