free-astro-components 0.0.37 → 0.0.38

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.
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "description": "A collection of free Astro components",
4
4
  "author": "Denis Ventura",
5
5
  "type": "module",
6
- "version": "0.0.37",
6
+ "version": "0.0.38",
7
7
  "exports": {
8
8
  ".": {
9
9
  "import": {
@@ -81,6 +81,7 @@ const selectClasses = ['ac-select', statusClasses, className]
81
81
  <button
82
82
  data-select-option
83
83
  disabled
84
+ role="option"
84
85
  aria-selected={option.selected ? 'true' : 'false'}
85
86
  >
86
87
  <span>{option.label}</span>
@@ -0,0 +1,135 @@
1
+ ---
2
+ interface Props {
3
+ label?: string
4
+ }
5
+
6
+ const { label } = Astro.props
7
+ ---
8
+
9
+ <label class="ac-theme-switch-wrapper">
10
+ <input
11
+ data-theme-switch
12
+ class="ac-theme-switch"
13
+ aria-checked="false"
14
+ type="checkbox"
15
+ />
16
+ <svg
17
+ class="ac-theme-switch-icon ac-theme-switch-icon--dark block w-5 h-5"
18
+ viewBox="0 0 24 24"
19
+ >
20
+ <path
21
+ d="M12 9c1.654 0 3 1.346 3 3s-1.346 3-3 3-3-1.346-3-3 1.346-3 3-3zm0-2c-2.762 0-5 2.238-5 5s2.238 5 5 5 5-2.238 5-5-2.238-5-5-5zm-4.184-.599l-3.593-3.594-1.415 1.414 3.595 3.595c.401-.537.876-1.013 1.413-1.415zm4.184-1.401c.34 0 .672.033 1 .08v-5.08h-2v5.08c.328-.047.66-.08 1-.08zm5.598 2.815l3.595-3.595-1.414-1.414-3.595 3.595c.537.402 1.012.878 1.414 1.414zm-12.598 4.185c0-.34.033-.672.08-1h-5.08v2h5.08c-.047-.328-.08-.66-.08-1zm11.185 5.598l3.594 3.593 1.415-1.414-3.594-3.593c-.403.536-.879 1.012-1.415 1.414zm-9.784-1.414l-3.593 3.593 1.414 1.414 3.593-3.593c-.536-.402-1.011-.877-1.414-1.414zm12.519-5.184c.047.328.08.66.08 1s-.033.672-.08 1h5.08v-2h-5.08zm-6.92 8c-.34 0-.672-.033-1-.08v5.08h2v-5.08c-.328.047-.66.08-1 .08z"
22
+ fill="currentColor"></path>
23
+ </svg>
24
+ <svg
25
+ class="ac-theme-switch-icon ac-theme-switch-icon--light hidden w-5 h-5"
26
+ viewBox="0 0 24 24"
27
+ >
28
+ <path
29
+ d="M10.719 2.082c-2.572 2.028-4.719 5.212-4.719 9.918 0 4.569 1.938 7.798 4.548 9.895-4.829-.705-8.548-4.874-8.548-9.895 0-5.08 3.808-9.288 8.719-9.918zm1.281-2.082c-6.617 0-12 5.383-12 12s5.383 12 12 12c1.894 0 3.87-.333 5.37-1.179-3.453-.613-9.37-3.367-9.37-10.821 0-7.555 6.422-10.317 9.37-10.821-1.74-.682-3.476-1.179-5.37-1.179zm0 10.999c1.437.438 2.562 1.564 2.999 3.001.44-1.437 1.565-2.562 3.001-3-1.436-.439-2.561-1.563-3.001-3-.437 1.436-1.562 2.561-2.999 2.999zm8.001.001c.958.293 1.707 1.042 2 2.001.291-.959 1.042-1.709 1.999-2.001-.957-.292-1.707-1.042-2-2-.293.958-1.042 1.708-1.999 2zm-1-9c-.437 1.437-1.563 2.562-2.998 3.001 1.438.44 2.561 1.564 3.001 3.002.437-1.438 1.563-2.563 2.996-3.002-1.433-.437-2.559-1.564-2.999-3.001z"
30
+ fill="currentColor"></path>
31
+ </svg>
32
+ {
33
+ label ? (
34
+ <span class="ac-theme-switch-label absolute opacity-0 w-0 h-0 overflow-hidden">
35
+ {label}
36
+ </span>
37
+ ) : (
38
+ <span class="ac-theme-switch-label ac-theme-switch-label--hidden">
39
+ Toggle theme
40
+ </span>
41
+ )
42
+ }
43
+ </label>
44
+
45
+ <style>
46
+ .ac-theme-switch-wrapper {
47
+ cursor: pointer;
48
+ display: inline-flex;
49
+ align-items: center;
50
+ gap: var(--ac-spacing-2);
51
+ font-family: var(--ac-font-sans);
52
+ color: rgb(var(--ac-color-700));
53
+ font-size: var(--ac-text-sm);
54
+
55
+ &:has([aria-checked='true']) {
56
+ .ac-theme-switch-icon--dark {
57
+ display: none;
58
+ }
59
+ }
60
+
61
+ &:has([aria-checked='false']) {
62
+ .ac-theme-switch-icon--light {
63
+ display: none;
64
+ }
65
+ }
66
+
67
+ &:hover {
68
+ .ac-theme-switch-icon {
69
+ color: var(--ac-primary-hover);
70
+ }
71
+
72
+ .ac-theme-switch-label {
73
+ color: rgb(var(--ac-color-700));
74
+ }
75
+ }
76
+ }
77
+
78
+ .ac-theme-switch {
79
+ height: 0;
80
+ opacity: 0;
81
+ overflow: hidden;
82
+ position: absolute;
83
+ width: 0;
84
+ }
85
+
86
+ .ac-theme-switch-icon {
87
+ height: var(--ac-spacing-5);
88
+ transition: all 0.3s ease-in-out;
89
+ width: var(--ac-spacing-5);
90
+ }
91
+
92
+ .ac-theme-switch-label {
93
+ color: rgb(var(--ac-color-500));
94
+ transition: all 0.3s ease-in-out;
95
+
96
+ &.ac-theme-switch-label--hidden {
97
+ height: 0;
98
+ overflow: hidden;
99
+ position: absolute;
100
+ width: 0;
101
+ }
102
+ }
103
+ </style>
104
+
105
+ <script>
106
+ import { DOMLoaded } from '../utils/utils'
107
+
108
+ DOMLoaded(() => {
109
+ const themeSwitch = document.querySelector(
110
+ '[data-theme-switch]'
111
+ ) as HTMLInputElement | null
112
+ const theme = localStorage.getItem('theme') || 'light'
113
+
114
+ if (themeSwitch) {
115
+ document.documentElement.setAttribute('data-theme', theme)
116
+ const isLight = theme === 'light'
117
+ themeSwitch.checked = isLight
118
+ themeSwitch.setAttribute('aria-checked', isLight.toString())
119
+ }
120
+
121
+ const toggleTheme = (isLight: boolean) => {
122
+ document.documentElement.setAttribute(
123
+ 'data-theme',
124
+ isLight ? 'light' : 'dark'
125
+ )
126
+ localStorage.setItem('theme', isLight ? 'light' : 'dark')
127
+ themeSwitch?.setAttribute('aria-checked', isLight.toString())
128
+ }
129
+
130
+ themeSwitch?.addEventListener('change', () => {
131
+ const isLight = themeSwitch.checked
132
+ toggleTheme(isLight)
133
+ })
134
+ })
135
+ </script>
package/src/index.js CHANGED
@@ -8,3 +8,4 @@ export { default as Textarea } from './components/Textarea.astro'
8
8
  export { default as Select } from './components/Select.astro'
9
9
  export { default as Tab } from './components/Tab.astro'
10
10
  export { default as TabItem } from './components/TabItem.astro'
11
+ export { default as ThemeSwitch } from './components/ThemeSwitch.astro'
@@ -37,3 +37,7 @@ export const Tab: Tab
37
37
  // TabItem component
38
38
  export type TabItem = typeof import('../index.js').TabItem
39
39
  export const TabItem: TabItem
40
+
41
+ // ThemeSwitch component
42
+ export type ThemeSwitch = typeof import('../index.js').ThemeSwitch
43
+ export const ThemeSwitch: ThemeSwitch