tera-system-ui 0.0.20 → 0.0.22
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/dist/components/avatar/Avatar.d.ts +82 -0
- package/dist/components/avatar/Avatar.js +35 -0
- package/dist/components/avatar/Avatar.svelte +43 -0
- package/dist/components/avatar/Avatar.svelte.d.ts +3 -0
- package/dist/components/avatar/index.d.ts +1 -0
- package/dist/components/avatar/index.js +1 -0
- package/dist/components/brand-logo/BrandLogo.svelte +31 -31
- package/dist/components/button/Button.svelte +49 -49
- package/dist/components/combobox/Combobox.svelte +8 -8
- package/dist/components/command/command.scss +72 -72
- package/dist/components/command/components/Command.svelte +120 -120
- package/dist/components/command/components/CommandEmpty.svelte +30 -30
- package/dist/components/command/components/CommandGroup.svelte +110 -110
- package/dist/components/command/components/CommandInput.svelte +92 -92
- package/dist/components/command/components/CommandItem.svelte +110 -110
- package/dist/components/command/components/CommandList.svelte +56 -56
- package/dist/components/command/components/CommandLoading.svelte +28 -28
- package/dist/components/command/components/CommandSeparator.svelte +21 -21
- package/dist/components/dialog/Dialog.astro +63 -63
- package/dist/components/dialog/Dialog.svelte +109 -109
- package/dist/components/dialog/dialog.scss +115 -115
- package/dist/components/dropdown-menu/DropdownMenu.d.ts +22 -0
- package/dist/components/dropdown-menu/DropdownMenu.js +15 -0
- package/dist/components/dropdown-menu/components/DropdownMenu.svelte +34 -0
- package/dist/components/dropdown-menu/components/DropdownMenu.svelte.d.ts +3 -0
- package/dist/components/dropdown-menu/components/DropdownMenuGroup.svelte +12 -0
- package/dist/components/dropdown-menu/components/DropdownMenuGroup.svelte.d.ts +5 -0
- package/dist/components/dropdown-menu/components/DropdownMenuHeader.svelte +12 -0
- package/dist/components/dropdown-menu/components/DropdownMenuHeader.svelte.d.ts +5 -0
- package/dist/components/dropdown-menu/components/DropdownMenuItem.svelte +30 -0
- package/dist/components/dropdown-menu/components/DropdownMenuItem.svelte.d.ts +3 -0
- package/dist/components/dropdown-menu/components/DropdownMenuSeparator.svelte +11 -0
- package/dist/components/dropdown-menu/components/DropdownMenuSeparator.svelte.d.ts +5 -0
- package/dist/components/dropdown-menu/index.d.ts +5 -0
- package/dist/components/dropdown-menu/index.js +5 -0
- package/dist/components/header/Header.svelte +36 -36
- package/dist/components/header/header.scss +19 -19
- package/dist/components/icons/IconArrowBigRightFilled.svelte +10 -10
- package/dist/components/icons/IconBook.svelte +10 -10
- package/dist/components/icons/IconBookmarkPlus.svelte +10 -10
- package/dist/components/icons/IconCalculator.svelte +10 -10
- package/dist/components/icons/IconCheck.svelte +10 -10
- package/dist/components/icons/IconChevronDown.svelte +10 -10
- package/dist/components/icons/IconCopy.svelte +10 -10
- package/dist/components/icons/IconCopyCheckFilled.svelte +10 -10
- package/dist/components/icons/IconHamburger.svelte +10 -10
- package/dist/components/icons/IconLanguage.svelte +10 -10
- package/dist/components/icons/IconLoader2.svelte +10 -10
- package/dist/components/icons/IconLogout.svelte +10 -0
- package/dist/components/icons/IconLogout.svelte.d.ts +4 -0
- package/dist/components/icons/IconMoon.svelte +10 -10
- package/dist/components/icons/IconPointFilled.svelte +10 -10
- package/dist/components/icons/IconSearch.svelte +10 -10
- package/dist/components/icons/IconSettings.svelte +10 -0
- package/dist/components/icons/IconSettings.svelte.d.ts +4 -0
- package/dist/components/icons/IconSun.svelte +10 -10
- package/dist/components/icons/IconSwitchHorizontal.svelte +10 -10
- package/dist/components/icons/IconSwitchVertical.svelte +10 -10
- package/dist/components/icons/IconTransform.svelte +10 -10
- package/dist/components/icons/IconX.svelte +10 -10
- package/dist/components/icons/index.d.ts +2 -0
- package/dist/components/icons/index.js +2 -0
- package/dist/components/input/Input.svelte +24 -24
- package/dist/components/language-picker-button/LanguagePickerButton.svelte +109 -109
- package/dist/components/light-dark-toggle/LightDarkToggle.svelte +36 -36
- package/dist/components/popover/Popover.svelte +159 -137
- package/dist/components/popover-responsive/PopoverResponsive.svelte +87 -87
- package/dist/components/side-navigation/SideNavigation.svelte +114 -114
- package/dist/components/side-navigation/SideNavigationItem.svelte +17 -17
- package/dist/components/side-navigation/SideNavigationLayout.svelte +19 -19
- package/dist/components/side-navigation/sidenav.scss +149 -149
- package/dist/components/tera-ui-context/TeraUiContext.d.ts +1 -0
- package/dist/components/tera-ui-context/TeraUiContext.svelte +28 -28
- package/dist/components/user-avatar-with-menu/UserAvatarWithMenu.d.ts +11 -0
- package/dist/components/user-avatar-with-menu/UserAvatarWithMenu.js +7 -0
- package/dist/components/user-avatar-with-menu/UserAvatarWithMenu.svelte +68 -0
- package/dist/components/user-avatar-with-menu/UserAvatarWithMenu.svelte.d.ts +3 -0
- package/dist/components/user-avatar-with-menu/index.d.ts +1 -0
- package/dist/components/user-avatar-with-menu/index.js +1 -0
- package/dist/index.d.ts +4 -1
- package/dist/index.js +4 -1
- package/dist/internal/service/user.service.d.ts +2 -0
- package/dist/internal/service/user.service.js +20 -0
- package/dist/themes/scrollbar.scss +37 -37
- package/dist/themes/tera-ui-base.css +210 -210
- package/dist/themes/tw-preset.cjs +153 -153
- package/dist/types/user-data.d.ts +31 -0
- package/dist/types/user-data.js +1 -0
- package/package.json +98 -96
- package/scripts/add-component-template.js +120 -120
- package/scripts/generate-ts-index.js +138 -136
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
<script lang="ts">
|
|
2
|
-
import {type IconsProps, styles} from "./Icons";
|
|
3
|
-
import {IconX} from "@tabler/icons-svelte";
|
|
4
|
-
|
|
5
|
-
let {children, ...props}: IconsProps = $props();
|
|
6
|
-
|
|
7
|
-
</script>
|
|
8
|
-
|
|
9
|
-
<IconX class={styles({...props})}/>
|
|
10
|
-
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import {type IconsProps, styles} from "./Icons";
|
|
3
|
+
import {IconX} from "@tabler/icons-svelte";
|
|
4
|
+
|
|
5
|
+
let {children, ...props}: IconsProps = $props();
|
|
6
|
+
|
|
7
|
+
</script>
|
|
8
|
+
|
|
9
|
+
<IconX class={styles({...props})}/>
|
|
10
|
+
|
|
@@ -9,9 +9,11 @@ export { default as IconCopyCheckFilled } from './IconCopyCheckFilled.svelte';
|
|
|
9
9
|
export { default as IconHamburger } from './IconHamburger.svelte';
|
|
10
10
|
export { default as IconLanguage } from './IconLanguage.svelte';
|
|
11
11
|
export { default as IconLoader2 } from './IconLoader2.svelte';
|
|
12
|
+
export { default as IconLogout } from './IconLogout.svelte';
|
|
12
13
|
export { default as IconMoon } from './IconMoon.svelte';
|
|
13
14
|
export { default as IconPointFilled } from './IconPointFilled.svelte';
|
|
14
15
|
export { default as IconSearch } from './IconSearch.svelte';
|
|
16
|
+
export { default as IconSettings } from './IconSettings.svelte';
|
|
15
17
|
export { default as IconSun } from './IconSun.svelte';
|
|
16
18
|
export { default as IconSwitchHorizontal } from './IconSwitchHorizontal.svelte';
|
|
17
19
|
export { default as IconSwitchVertical } from './IconSwitchVertical.svelte';
|
|
@@ -9,9 +9,11 @@ export { default as IconCopyCheckFilled } from './IconCopyCheckFilled.svelte';
|
|
|
9
9
|
export { default as IconHamburger } from './IconHamburger.svelte';
|
|
10
10
|
export { default as IconLanguage } from './IconLanguage.svelte';
|
|
11
11
|
export { default as IconLoader2 } from './IconLoader2.svelte';
|
|
12
|
+
export { default as IconLogout } from './IconLogout.svelte';
|
|
12
13
|
export { default as IconMoon } from './IconMoon.svelte';
|
|
13
14
|
export { default as IconPointFilled } from './IconPointFilled.svelte';
|
|
14
15
|
export { default as IconSearch } from './IconSearch.svelte';
|
|
16
|
+
export { default as IconSettings } from './IconSettings.svelte';
|
|
15
17
|
export { default as IconSun } from './IconSun.svelte';
|
|
16
18
|
export { default as IconSwitchHorizontal } from './IconSwitchHorizontal.svelte';
|
|
17
19
|
export { default as IconSwitchVertical } from './IconSwitchVertical.svelte';
|
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
<script lang="ts">
|
|
2
|
-
import {type InputProps, styles} from "./Input";
|
|
3
|
-
|
|
4
|
-
let {
|
|
5
|
-
children,
|
|
6
|
-
class: className,
|
|
7
|
-
value = $bindable(),
|
|
8
|
-
ref = $bindable(),
|
|
9
|
-
size,
|
|
10
|
-
disabled,
|
|
11
|
-
variant = 'outlined',
|
|
12
|
-
prefix,
|
|
13
|
-
...props
|
|
14
|
-
}: InputProps = $props();
|
|
15
|
-
|
|
16
|
-
</script>
|
|
17
|
-
|
|
18
|
-
<input
|
|
19
|
-
type="text"
|
|
20
|
-
bind:this={ref}
|
|
21
|
-
class={styles({ variant, disabled , size, className})}
|
|
22
|
-
{disabled}
|
|
23
|
-
{...props}
|
|
24
|
-
bind:value
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import {type InputProps, styles} from "./Input";
|
|
3
|
+
|
|
4
|
+
let {
|
|
5
|
+
children,
|
|
6
|
+
class: className,
|
|
7
|
+
value = $bindable(),
|
|
8
|
+
ref = $bindable(),
|
|
9
|
+
size,
|
|
10
|
+
disabled,
|
|
11
|
+
variant = 'outlined',
|
|
12
|
+
prefix,
|
|
13
|
+
...props
|
|
14
|
+
}: InputProps = $props();
|
|
15
|
+
|
|
16
|
+
</script>
|
|
17
|
+
|
|
18
|
+
<input
|
|
19
|
+
type="text"
|
|
20
|
+
bind:this={ref}
|
|
21
|
+
class={styles({ variant, disabled , size, className})}
|
|
22
|
+
{disabled}
|
|
23
|
+
{...props}
|
|
24
|
+
bind:value
|
|
25
25
|
/>
|
|
@@ -1,112 +1,112 @@
|
|
|
1
|
-
<script lang="ts">
|
|
2
|
-
import {type LanguagePickerButtonProps} from "./LanguagePickerButton";
|
|
3
|
-
import {IconLanguage} from "../icons";
|
|
4
|
-
import {Dialog} from "../dialog";
|
|
5
|
-
import IconCheck from "../icons/IconCheck.svelte";
|
|
6
|
-
import {getGlobalContext} from "../tera-ui-context/global-context";
|
|
7
|
-
import * as m from '../../paraglide/messages.js'
|
|
8
|
-
|
|
9
|
-
let {
|
|
10
|
-
children,
|
|
11
|
-
onLangSelect,
|
|
12
|
-
...props
|
|
13
|
-
}: LanguagePickerButtonProps & {
|
|
14
|
-
onLangSelect: (langCode: string) => void
|
|
15
|
-
} = $props();
|
|
16
|
-
|
|
17
|
-
let context = getGlobalContext()
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
const LANGUAGE_LIST = [
|
|
21
|
-
{
|
|
22
|
-
code: "en",
|
|
23
|
-
label: "English (US)",
|
|
24
|
-
flag: 'united states'
|
|
25
|
-
},
|
|
26
|
-
{
|
|
27
|
-
code: "de",
|
|
28
|
-
label: "Deutsch",
|
|
29
|
-
flag: 'germany'
|
|
30
|
-
},
|
|
31
|
-
{
|
|
32
|
-
code: "es",
|
|
33
|
-
label: "Español",
|
|
34
|
-
flag: 'spain'
|
|
35
|
-
},
|
|
36
|
-
{
|
|
37
|
-
code: "fr",
|
|
38
|
-
label: "Français",
|
|
39
|
-
flag: 'france'
|
|
40
|
-
},
|
|
41
|
-
{
|
|
42
|
-
code: "it",
|
|
43
|
-
label: "Italiano",
|
|
44
|
-
flag: 'italy'
|
|
45
|
-
},
|
|
46
|
-
{
|
|
47
|
-
code: "pt",
|
|
48
|
-
label: "Português",
|
|
49
|
-
flag: 'portugal'
|
|
50
|
-
},
|
|
51
|
-
{
|
|
52
|
-
code: "ru",
|
|
53
|
-
label: "Русский",
|
|
54
|
-
flag: 'russia'
|
|
55
|
-
},
|
|
56
|
-
{
|
|
57
|
-
code: "vi",
|
|
58
|
-
label: "Tiếng Việt",
|
|
59
|
-
flag: 'vietnam'
|
|
60
|
-
}
|
|
61
|
-
// @ts-ignore
|
|
62
|
-
].filter(lang => context.supportLanguages!.includes(lang.code))
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
let currentLangItem = $derived(LANGUAGE_LIST.find(l => l.code === context.language)!)
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
function getFlagUrl(flag: string) {
|
|
69
|
-
if (flag === 'spain') {
|
|
70
|
-
return `${context.basePath ?? ''}/world-flags/${flag}.png`
|
|
71
|
-
}
|
|
72
|
-
return `${context.basePath ?? ''}/world-flags/${flag}.svg`
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
let openDialog = $state(false)
|
|
76
|
-
</script>
|
|
77
|
-
|
|
78
|
-
<!--add component here-->
|
|
79
|
-
<button onclick={() => {openDialog = true}}
|
|
80
|
-
class="h-8 flex items-center bg-neutral-token-4 text-neutral-token-9 rounded-full ps-2 pe-1 hover:bg-neutral-token-5 transition-all duration-element-react">
|
|
81
|
-
<IconLanguage class="size-icon-xs"/>
|
|
82
|
-
<img class="size-6 flag-img" src={getFlagUrl(currentLangItem.flag)} alt={currentLangItem.flag}>
|
|
83
|
-
</button>
|
|
84
|
-
|
|
85
|
-
<Dialog bind:open={openDialog} class="text-neutral-token-13" size="xs" staticRender>
|
|
86
|
-
{#snippet header()}
|
|
87
|
-
{m.text_select_language()}
|
|
88
|
-
{/snippet}
|
|
89
|
-
<div class="grid grid-cols-1 mx-auto gap-2">
|
|
90
|
-
{#each LANGUAGE_LIST as lang}
|
|
91
|
-
<button class="w-full flex gap-1 items-center justify-between text-start px-1 py-1 pe-2 rounded-full bg-neutral-token-3"
|
|
92
|
-
onclick={() => {
|
|
93
|
-
onLangSelect?.(lang.code)
|
|
94
|
-
openDialog = false
|
|
95
|
-
}}
|
|
96
|
-
data-selected={lang.code === context.language ? '' : undefined}>
|
|
97
|
-
<div class="flex items-center gap-2">
|
|
98
|
-
<img class="size-8 flag-img" src={getFlagUrl(lang.flag)} alt={currentLangItem.flag} loading="lazy">
|
|
99
|
-
{lang.label}
|
|
100
|
-
</div>
|
|
101
|
-
<div class="check">
|
|
102
|
-
<IconCheck class="check size-icon-sm"/>
|
|
103
|
-
</div>
|
|
104
|
-
</button>
|
|
105
|
-
{/each}
|
|
106
|
-
</div>
|
|
107
|
-
</Dialog>
|
|
108
|
-
|
|
109
|
-
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import {type LanguagePickerButtonProps} from "./LanguagePickerButton";
|
|
3
|
+
import {IconLanguage} from "../icons";
|
|
4
|
+
import {Dialog} from "../dialog";
|
|
5
|
+
import IconCheck from "../icons/IconCheck.svelte";
|
|
6
|
+
import {getGlobalContext} from "../tera-ui-context/global-context";
|
|
7
|
+
import * as m from '../../paraglide/messages.js'
|
|
8
|
+
|
|
9
|
+
let {
|
|
10
|
+
children,
|
|
11
|
+
onLangSelect,
|
|
12
|
+
...props
|
|
13
|
+
}: LanguagePickerButtonProps & {
|
|
14
|
+
onLangSelect: (langCode: string) => void
|
|
15
|
+
} = $props();
|
|
16
|
+
|
|
17
|
+
let context = getGlobalContext()
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
const LANGUAGE_LIST = [
|
|
21
|
+
{
|
|
22
|
+
code: "en",
|
|
23
|
+
label: "English (US)",
|
|
24
|
+
flag: 'united states'
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
code: "de",
|
|
28
|
+
label: "Deutsch",
|
|
29
|
+
flag: 'germany'
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
code: "es",
|
|
33
|
+
label: "Español",
|
|
34
|
+
flag: 'spain'
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
code: "fr",
|
|
38
|
+
label: "Français",
|
|
39
|
+
flag: 'france'
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
code: "it",
|
|
43
|
+
label: "Italiano",
|
|
44
|
+
flag: 'italy'
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
code: "pt",
|
|
48
|
+
label: "Português",
|
|
49
|
+
flag: 'portugal'
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
code: "ru",
|
|
53
|
+
label: "Русский",
|
|
54
|
+
flag: 'russia'
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
code: "vi",
|
|
58
|
+
label: "Tiếng Việt",
|
|
59
|
+
flag: 'vietnam'
|
|
60
|
+
}
|
|
61
|
+
// @ts-ignore
|
|
62
|
+
].filter(lang => context.supportLanguages!.includes(lang.code))
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
let currentLangItem = $derived(LANGUAGE_LIST.find(l => l.code === context.language)!)
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
function getFlagUrl(flag: string) {
|
|
69
|
+
if (flag === 'spain') {
|
|
70
|
+
return `${context.basePath ?? ''}/world-flags/${flag}.png`
|
|
71
|
+
}
|
|
72
|
+
return `${context.basePath ?? ''}/world-flags/${flag}.svg`
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
let openDialog = $state(false)
|
|
76
|
+
</script>
|
|
77
|
+
|
|
78
|
+
<!--add component here-->
|
|
79
|
+
<button onclick={() => {openDialog = true}}
|
|
80
|
+
class="h-8 flex items-center bg-neutral-token-4 text-neutral-token-9 rounded-full ps-2 pe-1 hover:bg-neutral-token-5 transition-all duration-element-react">
|
|
81
|
+
<IconLanguage class="size-icon-xs"/>
|
|
82
|
+
<img class="size-6 flag-img" src={getFlagUrl(currentLangItem.flag)} alt={currentLangItem.flag}>
|
|
83
|
+
</button>
|
|
84
|
+
|
|
85
|
+
<Dialog bind:open={openDialog} class="text-neutral-token-13" size="xs" staticRender>
|
|
86
|
+
{#snippet header()}
|
|
87
|
+
{m.text_select_language()}
|
|
88
|
+
{/snippet}
|
|
89
|
+
<div class="grid grid-cols-1 mx-auto gap-2">
|
|
90
|
+
{#each LANGUAGE_LIST as lang}
|
|
91
|
+
<button class="w-full flex gap-1 items-center justify-between text-start px-1 py-1 pe-2 rounded-full bg-neutral-token-3"
|
|
92
|
+
onclick={() => {
|
|
93
|
+
onLangSelect?.(lang.code)
|
|
94
|
+
openDialog = false
|
|
95
|
+
}}
|
|
96
|
+
data-selected={lang.code === context.language ? '' : undefined}>
|
|
97
|
+
<div class="flex items-center gap-2">
|
|
98
|
+
<img class="size-8 flag-img" src={getFlagUrl(lang.flag)} alt={currentLangItem.flag} loading="lazy">
|
|
99
|
+
{lang.label}
|
|
100
|
+
</div>
|
|
101
|
+
<div class="check">
|
|
102
|
+
<IconCheck class="check size-icon-sm"/>
|
|
103
|
+
</div>
|
|
104
|
+
</button>
|
|
105
|
+
{/each}
|
|
106
|
+
</div>
|
|
107
|
+
</Dialog>
|
|
108
|
+
|
|
109
|
+
|
|
110
110
|
<style>button .check {
|
|
111
111
|
opacity: 0;
|
|
112
112
|
}
|
|
@@ -1,36 +1,36 @@
|
|
|
1
|
-
<script lang="ts">
|
|
2
|
-
import {type LightDarkToggleProps} from "./LightDarkToggle";
|
|
3
|
-
import {Button} from "../button";
|
|
4
|
-
import IconSun from "../icons/IconSun.svelte";
|
|
5
|
-
import IconMoon from "../icons/IconMoon.svelte";
|
|
6
|
-
|
|
7
|
-
let {children, ...props}: LightDarkToggleProps = $props();
|
|
8
|
-
|
|
9
|
-
// $effect(() => {
|
|
10
|
-
// const htmlElement = document.documentElement;
|
|
11
|
-
// // Check for saved theme preference
|
|
12
|
-
// const currentTheme = localStorage.getItem('theme');
|
|
13
|
-
// if (currentTheme === 'dark') {
|
|
14
|
-
// htmlElement.classList.add('dark');
|
|
15
|
-
// } else {
|
|
16
|
-
// htmlElement.classList.remove('dark');
|
|
17
|
-
// }
|
|
18
|
-
// })
|
|
19
|
-
|
|
20
|
-
function toggleLightDarkTheme() {
|
|
21
|
-
const htmlElement = document.documentElement;
|
|
22
|
-
|
|
23
|
-
htmlElement.classList.toggle('dark');
|
|
24
|
-
const theme = htmlElement.classList.contains('dark') ? 'dark' : 'light';
|
|
25
|
-
localStorage.setItem('theme', theme);
|
|
26
|
-
}
|
|
27
|
-
</script>
|
|
28
|
-
|
|
29
|
-
<!--add component here-->
|
|
30
|
-
<Button variant="ghost" icon
|
|
31
|
-
onclick={toggleLightDarkTheme}>
|
|
32
|
-
<!-- Sun icon, animates out when in dark mode -->
|
|
33
|
-
<IconSun class="icon-sun dark:hidden"/>
|
|
34
|
-
<!-- Moon icon, animates in when in dark mode -->
|
|
35
|
-
<IconMoon class="icon-moon hidden dark:block"/>
|
|
36
|
-
</Button>
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import {type LightDarkToggleProps} from "./LightDarkToggle";
|
|
3
|
+
import {Button} from "../button";
|
|
4
|
+
import IconSun from "../icons/IconSun.svelte";
|
|
5
|
+
import IconMoon from "../icons/IconMoon.svelte";
|
|
6
|
+
|
|
7
|
+
let {children, ...props}: LightDarkToggleProps = $props();
|
|
8
|
+
|
|
9
|
+
// $effect(() => {
|
|
10
|
+
// const htmlElement = document.documentElement;
|
|
11
|
+
// // Check for saved theme preference
|
|
12
|
+
// const currentTheme = localStorage.getItem('theme');
|
|
13
|
+
// if (currentTheme === 'dark') {
|
|
14
|
+
// htmlElement.classList.add('dark');
|
|
15
|
+
// } else {
|
|
16
|
+
// htmlElement.classList.remove('dark');
|
|
17
|
+
// }
|
|
18
|
+
// })
|
|
19
|
+
|
|
20
|
+
function toggleLightDarkTheme() {
|
|
21
|
+
const htmlElement = document.documentElement;
|
|
22
|
+
|
|
23
|
+
htmlElement.classList.toggle('dark');
|
|
24
|
+
const theme = htmlElement.classList.contains('dark') ? 'dark' : 'light';
|
|
25
|
+
localStorage.setItem('theme', theme);
|
|
26
|
+
}
|
|
27
|
+
</script>
|
|
28
|
+
|
|
29
|
+
<!--add component here-->
|
|
30
|
+
<Button variant="ghost" icon
|
|
31
|
+
onclick={toggleLightDarkTheme}>
|
|
32
|
+
<!-- Sun icon, animates out when in dark mode -->
|
|
33
|
+
<IconSun class="icon-sun dark:hidden"/>
|
|
34
|
+
<!-- Moon icon, animates in when in dark mode -->
|
|
35
|
+
<IconMoon class="icon-moon hidden dark:block"/>
|
|
36
|
+
</Button>
|