Skip to content

Commit abc4cf7

Browse files
chore: dark mode support (#63)
* Convert indigo to violet * add dark mode support
1 parent 76c80c9 commit abc4cf7

6 files changed

+44
-30
lines changed

Diff for: app/components/sn_filterable/base_components/button_component.rb

+5-5
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
class SnFilterable::BaseComponents::ButtonComponent < SnFilterable::BaseComponents::BaseComponent
55
DEFAULT_BUTTON_TYPE = :default
66
BUTTON_TYPE_MAPPINGS = {
7-
DEFAULT_BUTTON_TYPE => "shadow-sm border-gray-300 text-gray-700 bg-white hover:bg-gray-50 focus:ring-indigo-500",
8-
:primary => "shadow-sm text-white bg-indigo-600 hover:bg-indigo-700 focus:ring-indigo-500",
9-
:danger => "border-transparent text-red-700 bg-red-100 hover:bg-red-200 focus:ring-red-500",
10-
:disabled => "shadow-sm border-gray-300 text-gray-700 bg-gray-200 cursor-default"
7+
DEFAULT_BUTTON_TYPE => "shadow-sm border-gray-300 dark:border-gray-600 text-gray-700 dark:text-gray-300 bg-white dark:bg-gray-700 hover:bg-gray-50 dark:hover:bg-gray-600 focus:ring-violet-500 dark:focus:ring-violet-400",
8+
:primary => "shadow-sm text-white bg-violet-600 dark:bg-violet-700 hover:bg-violet-700 dark:hover:bg-violet-600 focus:ring-violet-500 dark:focus:ring-violet-400",
9+
:danger => "border-transparent text-red-700 dark:text-red-400 bg-red-100 dark:bg-red-900 hover:bg-red-200 dark:hover:bg-red-800 focus:ring-red-500 dark:focus:ring-red-400",
10+
:disabled => "shadow-sm border-gray-300 dark:border-gray-600 text-gray-700 dark:text-gray-400 bg-gray-200 dark:bg-gray-600 cursor-default"
1111
}.freeze
1212
BUTTON_TYPE_OPTIONS = BUTTON_TYPE_MAPPINGS.keys
1313

@@ -56,7 +56,7 @@ def initialize(
5656
end
5757

5858
show_focus_ring = arguments[:show_focus_ring].nil? ? true : arguments[:show_focus_ring]
59-
focus_ring_class = show_focus_ring ? "focus:ring-2 focus:ring-offset-2" : ""
59+
focus_ring_class = show_focus_ring ? "focus:ring-2 focus:ring-offset-2 dark:focus:ring-offset-gray-800" : ""
6060

6161
@arguments[:classes] = class_names(
6262
"inline-flex items-center border rounded-md #{focus_ring_class} focus:outline-none disabled:opacity-50 disabled:cursor-not-allowed",

Diff for: app/components/sn_filterable/category_component.html.erb

+11-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
1-
<%= content_tag :fieldset, class: "w-full text-xs lg:text-sm app-word-break",
1+
<%= content_tag :fieldset,
2+
class: "w-full text-xs lg:text-sm app-word-break dark:bg-gray-800",
23
"x-data": { open: @open }.to_json do %>
3-
<button class="flex border-b justify-between w-full px-4 py-3 font-medium text-left text-gray-900 transition-colors hover:bg-gray-200 rounded-sm focus:outline-none focus-visible:ring focus-visible:ring-gray-500 focus-visible:ring-opacity-75" type="button" @click="open = !open">
4+
<button class="flex border-b dark:border-gray-700 justify-between w-full px-4 py-3 font-medium text-left text-gray-900 dark:text-white transition-colors hover:bg-gray-200 dark:hover:bg-gray-700 rounded-sm focus:outline-none focus-visible:ring focus-visible:ring-gray-500 dark:focus-visible:ring-gray-400 focus-visible:ring-opacity-75"
5+
type="button"
6+
@click="open = !open">
47
<span><%= @title %></span>
5-
<%= heroicon "chevron-down", options: { class: "transform w-5 h-5 text-gray-500 transition ease-out", ":class": "open && 'rotate-180'"} %>
8+
<%= heroicon "chevron-down",
9+
options: {
10+
class: "transform w-5 h-5 text-gray-500 dark:text-gray-400 transition ease-out",
11+
":class": "open && 'rotate-180'"
12+
} %>
613
</button>
7-
<div class="pb-2 text-gray-500" x-show="open" x-cloak>
14+
<div class="pb-2 text-gray-500 dark:text-gray-400" x-show="open" x-cloak>
815
<%= filter %>
916
<%= content %>
1017
</div>

Diff for: app/components/sn_filterable/chips_component.html.erb

+10-6
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
<% unless @known_filters.empty? %>
2-
<div class="relative app-filter-chips-content bg-gray-50 -mx-8 mt-4" x-data="filteringChipContainer" x-init="updateSidebarGap()">
2+
<div class="relative app-filter-chips-content bg-gray-50 dark:bg-gray-700 -mx-8 mt-4" x-data="filteringChipContainer" x-init="updateSidebarGap()">
33
<div class="mx-auto py-3 px-4 flex items-center px-4 sm:px-6 lg:px-8">
4-
<h3 class="sm:pr-0 text-xs font-semibold uppercase tracking-wide text-gray-500">
4+
<h3 class="sm:pr-0 text-xs font-semibold uppercase tracking-wide text-gray-500 dark:text-gray-300">
55
<span>Filters</span>
66
<span class="sr-only">, active</span>
77
</h3>
88

9-
<div aria-hidden="true" class="w-px h-5 bg-gray-300 block ml-2 sm:ml-4"></div>
9+
<div aria-hidden="true" class="w-px h-5 bg-gray-300 dark:bg-gray-500 block ml-2 sm:ml-4"></div>
1010

1111
<div class="ml-2 sm:ml-4 flex-1">
1212
<div class="app-filter-chips-container -m-1 flex flex-wrap items-center">
1313
<% @known_filters.each do |filter| %>
14-
<span class="app-filter-chip m-1 inline-flex rounded-full border border-gray-200 items-center py-1.5 pl-3 pr-2 text-xs sm:text-sm font-medium bg-white text-gray-900" x-data>
14+
<span class="app-filter-chip m-1 inline-flex rounded-full border border-gray-200 dark:border-gray-600 items-center py-1.5 pl-3 pr-2 text-xs sm:text-sm font-medium bg-white dark:bg-gray-800 text-gray-900 dark:text-gray-300" x-data>
1515
<span><%= filter[:name] %></span>
1616
<%= content_tag :a,
1717
href: filter[:multi] ? remove_sub_filter_url(@filtered, filter[:parent], filter[:value], url: @url) : remove_filter_url(@filtered, filter[:parent], url: @url),
18-
class: "flex-shrink-0 ml-1 h-4 w-4 p-1 rounded-full inline-flex text-gray-400 hover:bg-gray-200 hover:text-gray-500",
18+
class: "flex-shrink-0 ml-1 h-4 w-4 p-1 rounded-full inline-flex text-gray-400 hover:bg-gray-200 hover:text-gray-500 dark:hover:bg-gray-600 dark:hover:text-gray-300",
1919
"x-data": "filteringChip(#{filter.to_json})",
2020
"@click": "$event.preventDefault(); onClick()" do %>
2121
<span class="sr-only">Remove filter for Objects</span>
@@ -28,7 +28,11 @@
2828
</div>
2929
</div>
3030
<div class="pl-2 sm:pl-6">
31-
<%= link_to t("shared.filterable.clear_all"), clear_filter_url(@filtered, url: @url), class: "text-sm text-gray-500", "x-data": "filteringClear", "@click": "$event.preventDefault(); onClick()" %>
31+
<%= link_to t("shared.filterable.clear_all"),
32+
clear_filter_url(@filtered, url: @url),
33+
class: "text-sm text-gray-500 dark:text-gray-300 hover:text-gray-700 dark:hover:text-gray-100",
34+
"x-data": "filteringClear",
35+
"@click": "$event.preventDefault(); onClick()" %>
3236
</div>
3337
</div>
3438
</div>

Diff for: app/components/sn_filterable/filter_category_component.html.erb

+8-5
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
<% @filter[:filters].each_with_index do |sub_filter, index| %>
2-
<div class="relative flex items-start px-4 transition-colors hover:bg-gray-200 text-gray-700 hover:text-gray-900">
2+
<div class="relative flex items-start px-4 transition-colors hover:bg-gray-200 dark:hover:bg-gray-700 text-gray-700 dark:text-gray-300 hover:text-gray-900 dark:hover:text-white">
33
<div class="min-w-0 flex-1 flex-grow">
4-
<%= content_tag :label, sub_filter[:name], class: "block py-2 pr-4 text-gray-600 select-none w-full cursor-pointer", for: "filter-#{@filter[:filter_name]}-#{index}" %>
4+
<%= content_tag :label,
5+
sub_filter[:name],
6+
class: "block py-2 pr-4 text-gray-600 dark:text-gray-400 select-none w-full cursor-pointer",
7+
for: "filter-#{@filter[:filter_name]}-#{index}" %>
58
</div>
69
<div class="my-2 flex items-center">
710
<% if @filter[:multi] %>
811
<%= content_tag :input, "",
9-
class: "focus:ring-purple-400 cursor-pointer h-5 w-5 text-purple-500 bg-purple-100 border-0 rounded",
12+
class: "focus:ring-purple-400 dark:focus:ring-purple-600 cursor-pointer h-5 w-5 text-purple-500 dark:text-purple-400 bg-purple-100 dark:bg-purple-900 border-0 rounded",
1013
type: "checkbox",
1114
name: "filter[#{@filter[:filter_name]}][]",
1215
value: sub_filter[:value],
@@ -17,7 +20,7 @@
1720
%>
1821
<% else %>
1922
<%= content_tag :input, "",
20-
class: "focus:ring-purple-400 cursor-pointer h-5 w-5 text-purple-500 bg-purple-100 border-0",
23+
class: "focus:ring-purple-400 dark:focus:ring-purple-600 cursor-pointer h-5 w-5 text-purple-500 dark:text-purple-400 bg-purple-100 dark:bg-purple-900 border-0",
2124
type: "radio",
2225
name: "filter[#{@filter[:filter_name]}]",
2326
value: sub_filter[:value],
@@ -29,4 +32,4 @@
2932
<% end %>
3033
</div>
3134
</div>
32-
<% end %>
35+
<% end %>

Diff for: app/components/sn_filterable/main_component.html.erb

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<% url = @url || url_for %>
2-
<div x-data="{ filteringForm: $refs.filtering_form, entireComponenet: $el, filtersLoading: false, filtersPopupOpen: false, sidebarGapTarget: null }">
2+
<div x-data="{ filteringForm: $refs.filtering_form, entireComponenet: $el, filtersLoading: false, filtersPopupOpen: false, sidebarGapTarget: null }" class="dark:bg-gray-800 dark:text-white">
33
<%= content_tag :form,
44
"x-ref": "filtering_form",
55
"action": url,
@@ -26,12 +26,12 @@
2626
<% if @show_sidebar %>
2727
<div class="mt-16 h-full pointer-events-auto">
2828
<div class="h-full" x-init="sidebarGapTarget = $el">
29-
<div x-show="filtersPopupOpen" class="fixed top-0 left-0 right-0 bottom-0 z-10 sm:z-0 bg-gray-600 bg-opacity-75 sm:hidden" @click="filtersPopupOpen = false" x-cloak></div>
30-
<div x-show="filtersPopupOpen" class="fixed bottom-0 h-2/3 z-10 sm:z-0 left-0 w-full bg-white pt-4 sm:sticky sm:!block row-span-2 shrink-0 mr-4 self-start sm:top-16 lg:w-64 sm:w-52 sm:pt-2 sm:pb-6 sm:overflow-y-auto sm:h-[70vh] sm:max-h-[calc(100vh_-_5rem)]" x-cloak>
29+
<div x-show="filtersPopupOpen" class="fixed top-0 left-0 right-0 bottom-0 z-10 sm:z-0 bg-gray-600 bg-opacity-75 dark:bg-gray-900 dark:bg-opacity-75 sm:hidden" @click="filtersPopupOpen = false" x-cloak></div>
30+
<div x-show="filtersPopupOpen" class="fixed bottom-0 h-2/3 z-10 sm:z-0 left-0 w-full bg-white dark:bg-gray-800 pt-4 sm:sticky sm:!block row-span-2 shrink-0 mr-4 self-start sm:top-16 lg:w-64 sm:w-52 sm:pt-2 sm:pb-6 sm:overflow-y-auto sm:h-[70vh] sm:max-h-[calc(100vh_-_5rem)]" x-cloak>
3131
<div class="absolute top-0 right-0 -mt-12 mb-2 mr-2" x-show="filtersPopupOpen">
32-
<button type="button" class="ml-1 flex items-center justify-center h-10 w-10 rounded-full focus:outline-none focus:ring-2 focus:ring-inset focus:ring-white" @click="filtersPopupOpen = false">
32+
<button type="button" class="ml-1 flex items-center justify-center h-10 w-10 rounded-full focus:outline-none focus:ring-2 focus:ring-inset focus:ring-white dark:focus:ring-gray-600" @click="filtersPopupOpen = false">
3333
<span class="sr-only">Close filters</span>
34-
<%= heroicon "x-mark", variant: :outline, options: { class: "h-6 w-6 text-grey-500" } %>
34+
<%= heroicon "x-mark", variant: :outline, options: { class: "h-6 w-6 text-grey-500 dark:text-gray-400" } %>
3535
</button>
3636
</div>
3737
<div name="Filter Options" role="menu" aria-orientation="vertical" aria-labelledby="options-menu" class="overflow-y-auto max-h-full">
@@ -43,15 +43,15 @@
4343
<%= render SnFilterable::CategoryComponent.new(title: t("shared.filterable.results_per_page"), open: @filtered.queries.dig("per").present?) do %>
4444
<fieldset class="pt-2" x-data="{ wasInteracted: false }">
4545
<% ([@filtered.items.default_per_page] | [10, 25, 50]).sort.each do |value| %>
46-
<div class="relative flex items-start px-4 transition-colors hover:bg-gray-200 text-gray-700 hover:text-gray-900">
46+
<div class="relative flex items-start px-4 transition-colors hover:bg-gray-200 dark:hover:bg-gray-700 text-gray-700 dark:text-gray-300 hover:text-gray-900 dark:hover:text-white">
4747
<div class="min-w-0 flex-1 flex-grow">
48-
<%= content_tag :label, value, class: "block py-2 pr-4 text-gray-600 select-none w-full cursor-pointer", for: "per-#{value}" %>
48+
<%= content_tag :label, value, class: "block py-2 pr-4 text-gray-600 dark:text-gray-400 select-none w-full cursor-pointer", for: "per-#{value}" %>
4949
</div>
5050
<div class="my-2 flex items-center">
5151
<% selected_explcitly = value == @filtered.queries["per"].to_i %>
5252
<% selected_by_default = @filtered.queries["per"].blank? && value == @filtered.items.default_per_page %>
5353
<%= content_tag :input, "",
54-
class: "focus:ring-purple-400 cursor-pointer h-5 w-5 text-purple-500 bg-purple-100 border-0",
54+
class: "focus:ring-purple-400 dark:focus:ring-purple-600 cursor-pointer h-5 w-5 text-purple-500 dark:text-purple-400 bg-purple-100 dark:bg-purple-900 border-0",
5555
type: "radio",
5656
id: "per-#{value}",
5757
"x-data": { iteracted: selected_explcitly }.to_json,

Diff for: app/components/sn_filterable/search_component.html.erb

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<div class="mt-1 relative rounded-md shadow-sm">
22
<div class="absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none">
3-
<%= heroicon "magnifying-glass", options: { class: "h-5 w-5 text-gray-400" } %>
3+
<%= heroicon "magnifying-glass", options: { class: "h-5 w-5 text-gray-400 dark:text-gray-500" } %>
44
</div>
55
<%= content_tag :input, "",
6-
class: "focus:ring-indigo-500 focus:border-indigo-500 block w-full pl-10 sm:text-sm border-gray-300 rounded-md",
6+
class: "focus:ring-violet-500 focus:border-violet-500 block w-full pl-10 sm:text-sm border-gray-300 dark:border-gray-600 rounded-md bg-white dark:bg-gray-700 text-gray-900 dark:text-gray-300 placeholder-gray-500 dark:placeholder-gray-400",
77
placeholder: "Search...",
88
type: "search",
99
":name": "hasValue && `filter[#{@filter_name}]`",

0 commit comments

Comments
 (0)