Skip to content

Commit

Permalink
Use add_class for default so Tailwind finds it
Browse files Browse the repository at this point in the history
Otherwise these styles are purged which we don't want.
  • Loading branch information
javierjulio committed Dec 26, 2023
1 parent d2dc54d commit 272083f
Show file tree
Hide file tree
Showing 12 changed files with 15 additions and 70 deletions.
7 changes: 0 additions & 7 deletions lib/active_admin/component.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
# frozen_string_literal: true
module ActiveAdmin
class Component < Arbre::Component
def initialize(*)
super
add_class default_class_name
end

def default_class_name
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,14 @@ class ActiveFiltersSidebarContent < ActiveAdmin::Component
builder_method :active_filters_sidebar_content

def build
add_class "active-filters"
active_filters = ActiveAdmin::Filters::Active.new(active_admin_config, assigns[:search])
active_scopes = assigns[:search].instance_variable_get(:@scope_args)

scope_block(current_scope)
filters_list(active_filters, active_scopes)
end

def default_class_name
"active-filters"
end

def scope_block(current_scope)
if current_scope
h3 I18n.t("active_admin.search_status.title_with_scope", name: scope_name(current_scope)), class: "active-filters-title"
Expand Down
5 changes: 1 addition & 4 deletions lib/active_admin/views/components/attributes_table.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ def build(obj, *attrs)
options = {}
options[:for] = @collection.first if single_record?
super(options)
add_class "attributes-table"
@table = table
build_colgroups
rows(*attrs)
Expand Down Expand Up @@ -43,10 +44,6 @@ def default_id_for_prefix
"attributes_table"
end

def default_class_name
"attributes-table"
end

# Build Colgroups
#
# Colgroups are only necessary for a collection of records; not
Expand Down
7 changes: 1 addition & 6 deletions lib/active_admin/views/components/dropdown_menu.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def build(name, options = {})
@menu = build_menu(menu_options)

super(options)
add_class "dropdown"
end

def item(*args, **kwargs, &block)
Expand All @@ -46,12 +47,6 @@ def item(*args, **kwargs, &block)
end
end

protected

def default_class_name
"dropdown"
end

private

def build_button(name, options)
Expand Down
5 changes: 1 addition & 4 deletions lib/active_admin/views/components/index_list.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@ class IndexList < ActiveAdmin::Component

include ::ActiveAdmin::Helpers::Collection

def default_class_name
"index-button-group index-list"
end

def tag_name
"div"
end
Expand All @@ -23,6 +19,7 @@ def tag_name
#
# @param [Array] index_classes The class constants that represent index page presenters
def build(index_classes)
add_class "index-button-group index-list"
unless current_filter_search_empty?
index_classes.each do |index_class|
build_index_list(index_class)
Expand Down
6 changes: 1 addition & 5 deletions lib/active_admin/views/components/paginated_collection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def build(collection, options = {})
unless collection.respond_to?(:total_pages)
raise(StandardError, "Collection is not a paginated scope. Set collection.page(params[:page]).per(10) before calling :paginated_collection.")
end

add_class "paginated-collection"
@contents = div(class: "paginated-collection-contents")
build_pagination_with_formats(options)
@built = true
Expand All @@ -65,10 +65,6 @@ def add_child(*args, &block)

protected

def default_class_name
"paginated-collection"
end

def build_pagination_with_formats(options)
div class: "paginated-collection-pagination" do
div page_entries_info(options).html_safe, class: "pagination-information"
Expand Down
5 changes: 1 addition & 4 deletions lib/active_admin/views/components/scopes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,13 @@ class Scopes < ActiveAdmin::Component
include ActiveAdmin::ScopeChain
include ::ActiveAdmin::Helpers::Collection

def default_class_name
"scopes"
end

def tag_name
"div"
end

def build(scopes, options = {})
super({ role: "toolbar" })
add_class "scopes"
scopes.group_by(&:group).each do |group, group_scopes|
div class: "index-button-group", role: "group", data: { "group": group_name(group) } do
group_scopes.each do |scope|
Expand Down
6 changes: 1 addition & 5 deletions lib/active_admin/views/components/status_tag.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,13 @@ def build(status, options = {})
end

super(content, options)

add_class "status-tag"
set_attribute("data-status", convert_status(status)) if status
add_class(classes) if classes
end

protected

def default_class_name
"status-tag"
end

def convert_to_boolean_status(status)
case status
when true, "true"
Expand Down
2 changes: 1 addition & 1 deletion lib/active_admin/views/components/table_for.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def build(obj, *attrs)

build_table
super(options)
add_class("data-table")
add_class "data-table"
columns(*attrs)
end

Expand Down
7 changes: 1 addition & 6 deletions lib/active_admin/views/components/tabs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ def tab(title, options = {}, &block)

def build(attributes = {}, &block)
super(attributes)
add_class "tabs"
@menu = nav(class: "tabs-nav", role: "tablist", "data-tabs-toggle": "#tabs-container-#{object_id}")
@tabs_content = div(class: "tabs-content", id: "tabs-container-#{object_id}")
end
Expand All @@ -29,12 +30,6 @@ def build_content_item(title, options, &block)
div(options, &block)
end

protected

def default_class_name
"tabs"
end

private

def fragmentize(string)
Expand Down
16 changes: 6 additions & 10 deletions lib/active_admin/views/index_as_table.rb
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ module Views
#
class IndexAsTable < ActiveAdmin::Component
def build(page_presenter, collection)
add_class "index-as-table"
table_options = {
id: "index_table_#{active_admin_config.resource_name.plural}",
sortable: true,
Expand Down Expand Up @@ -320,21 +321,16 @@ def defaults(resource, options = {})
class TableActions < ActiveAdmin::Component
builder_method :table_actions

def item *args, **kwargs
text_node link_to(*args, **kwargs)
def initialize(*)
super
add_class "data-table-resource-actions"
end

def default_class_name
"data-table-resource-actions"
def item *args, **kwargs
text_node link_to(*args, **kwargs)
end
end
end # IndexTableFor

protected

def default_class_name
"index-as-table"
end
end
end
end
14 changes: 0 additions & 14 deletions spec/unit/component_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,4 @@
it "should not have a CSS class name by default" do
expect(component.class_list.empty?).to eq true
end

describe "#default_class_name" do
let(:component_class) do
Class.new(described_class) do
def default_class_name
"my-component"
end
end
end

it "should add a default CSS class name if provided" do
expect(component.class_list).to include("my-component")
end
end
end

0 comments on commit 272083f

Please sign in to comment.