keystone_ui 0.51.0 → 0.52.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/app/assets/javascripts/keystone_ui/theme_toggle_controller.js +8 -11
- data/app/components/keystone/ui/theme_toggle_component.html.erb +13 -10
- data/app/components/keystone/ui/theme_toggle_component.rb +3 -15
- data/app/helpers/keystone_ui_helper.rb +1 -1
- data/lib/keystone_ui/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 0f67e6bd82fbcc8daa1e455f60140395bb002aee59ba2f055191130827707b0a
|
|
4
|
+
data.tar.gz: 6335b10c5578ce27579cab7e1da5a2f05e4eeca7c99d5e92173d7278a25efd9c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b49bb408da1f06272f711cbe7f077f8b7b438f89ae13c91d18309e3afda1d81689667ac45ff6bccb5fb94fae2abc02457caae6fc6890278635b2aae641b872ef
|
|
7
|
+
data.tar.gz: 2e7fd2e99b1368b703f3f29ee435ad4a2695856fd2301e182d5022d84ea29122d448712c940f77e9a0ab43310d436c37e80c4298001536d137a2b68cbd24db7c
|
|
@@ -4,21 +4,18 @@ const COOKIE = "keystone_theme"
|
|
|
4
4
|
const ONE_YEAR = 60 * 60 * 24 * 365
|
|
5
5
|
|
|
6
6
|
export default class extends Controller {
|
|
7
|
-
|
|
7
|
+
toggle() {
|
|
8
8
|
const page = this.element.ownerDocument
|
|
9
|
-
this.#
|
|
9
|
+
const mode = this.#shownMode(page) === "dark" ? "light" : "dark"
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
delete page.documentElement.dataset.theme
|
|
13
|
-
} else {
|
|
14
|
-
page.documentElement.dataset.theme = mode
|
|
15
|
-
}
|
|
11
|
+
page.documentElement.dataset.theme = mode
|
|
16
12
|
page.cookie = `${COOKIE}=${mode}; path=/; max-age=${ONE_YEAR}; samesite=lax`
|
|
17
13
|
}
|
|
18
14
|
|
|
19
|
-
#
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
15
|
+
#shownMode(page) {
|
|
16
|
+
const marked = page.documentElement.dataset.theme
|
|
17
|
+
if (marked) return marked
|
|
18
|
+
|
|
19
|
+
return page.defaultView.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light"
|
|
23
20
|
}
|
|
24
21
|
}
|
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
<
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
<button
|
|
2
|
+
type="button"
|
|
3
|
+
class="<%= BUTTON_CLASSES %>"
|
|
4
|
+
aria-label="Switch between light and dark"
|
|
5
|
+
data-controller="theme-toggle"
|
|
6
|
+
data-action="theme-toggle#toggle">
|
|
7
|
+
<svg data-icon="sun" class="<%= SUN_CLASSES %>" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" aria-hidden="true">
|
|
8
|
+
<path stroke-linecap="round" stroke-linejoin="round" d="M12 3v2.25m6.364.386-1.591 1.591M21 12h-2.25m-.386 6.364-1.591-1.591M12 18.75V21m-4.773-4.227-1.591 1.591M5.25 12H3m4.227-4.773L5.636 5.636M15.75 12a3.75 3.75 0 1 1-7.5 0 3.75 3.75 0 0 1 7.5 0Z" />
|
|
9
|
+
</svg>
|
|
10
|
+
<svg data-icon="moon" class="<%= MOON_CLASSES %>" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" aria-hidden="true">
|
|
11
|
+
<path stroke-linecap="round" stroke-linejoin="round" d="M21.752 15.002A9.72 9.72 0 0 1 18 15.75c-5.385 0-9.75-4.365-9.75-9.75 0-1.33.266-2.597.748-3.752A9.753 9.753 0 0 0 3 11.25C3 16.635 7.365 21 12.75 21a9.753 9.753 0 0 0 9.002-5.998Z" />
|
|
12
|
+
</svg>
|
|
13
|
+
</button>
|
|
@@ -3,21 +3,9 @@
|
|
|
3
3
|
module Keystone
|
|
4
4
|
module Ui
|
|
5
5
|
class ThemeToggleComponent < ViewComponent::Base
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
def initialize(current: nil)
|
|
11
|
-
@current = current
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
def options
|
|
15
|
-
OPTIONS
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
def pressed?(mode)
|
|
19
|
-
mode == KeystoneUi::ThemeChoice.new(@current).mode
|
|
20
|
-
end
|
|
6
|
+
BUTTON_CLASSES = "ks-theme-toggle ks-button ks-button-sm ks-button-secondary"
|
|
7
|
+
SUN_CLASSES = "size-5 dark:hidden"
|
|
8
|
+
MOON_CLASSES = "size-5 hidden dark:block"
|
|
21
9
|
end
|
|
22
10
|
end
|
|
23
11
|
end
|
data/lib/keystone_ui/version.rb
CHANGED