webcoreui 0.0.10 → 0.0.12
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/README.md +35 -7
- package/astro.d.ts +8 -0
- package/astro.js +8 -0
- package/components/Accordion/Accordion.astro +10 -8
- package/components/Accordion/Accordion.svelte +8 -8
- package/components/Accordion/Accordion.tsx +7 -6
- package/components/Accordion/{accordion.scss → accordion.module.scss} +18 -10
- package/components/Alert/Alert.astro +11 -7
- package/components/Alert/Alert.svelte +9 -7
- package/components/Alert/Alert.tsx +11 -7
- package/components/Alert/alert.module.scss +54 -0
- package/components/Alert/alert.ts +3 -1
- package/components/Avatar/Avatar.astro +4 -4
- package/components/Avatar/Avatar.svelte +13 -7
- package/components/Avatar/Avatar.tsx +11 -9
- package/components/Avatar/{avatar.scss → avatar.module.scss} +2 -2
- package/components/Badge/Badge.astro +8 -8
- package/components/Badge/Badge.svelte +25 -13
- package/components/Badge/Badge.tsx +26 -8
- package/components/Badge/badge.module.scss +89 -0
- package/components/Badge/badge.ts +8 -1
- package/components/Button/Button.astro +10 -6
- package/components/Button/Button.svelte +15 -11
- package/components/Button/Button.tsx +11 -7
- package/components/Button/button.module.scss +94 -0
- package/components/Button/button.ts +6 -1
- package/components/Card/Card.astro +7 -15
- package/components/Card/Card.svelte +16 -13
- package/components/Card/Card.tsx +15 -11
- package/components/Card/card.module.scss +33 -0
- package/components/Checkbox/Checkbox.astro +10 -10
- package/components/Checkbox/Checkbox.svelte +19 -18
- package/components/Checkbox/Checkbox.tsx +12 -11
- package/components/Checkbox/{checkbox.scss → checkbox.module.scss} +16 -17
- package/components/Checkbox/checkbox.ts +5 -1
- package/components/ConditionalWrapper/ConditionalWrapper.svelte +1 -1
- package/components/Icon/Icon.svelte +1 -8
- package/components/Icon/Icon.tsx +1 -8
- package/components/Icon/map.ts +23 -0
- package/components/Input/Input.astro +50 -0
- package/components/Input/Input.svelte +52 -0
- package/components/Input/Input.tsx +59 -0
- package/components/Input/input.module.scss +87 -0
- package/components/Input/input.ts +50 -0
- package/components/Menu/Menu.astro +107 -0
- package/components/Menu/Menu.svelte +88 -0
- package/components/Menu/Menu.tsx +107 -0
- package/components/Menu/menu.module.scss +144 -0
- package/components/Menu/menu.ts +21 -0
- package/components/Progress/Progress.astro +42 -40
- package/components/Progress/Progress.svelte +40 -38
- package/components/Progress/Progress.tsx +48 -47
- package/components/Progress/{progress.scss → progress.module.scss} +66 -66
- package/components/Radio/Radio.astro +57 -57
- package/components/Radio/Radio.svelte +58 -56
- package/components/Radio/Radio.tsx +69 -68
- package/components/Radio/{radio.scss → radio.module.scss} +92 -92
- package/components/Radio/radio.ts +4 -0
- package/components/Rating/Rating.astro +13 -10
- package/components/Rating/Rating.svelte +15 -15
- package/components/Rating/Rating.tsx +22 -11
- package/components/Rating/{rating.scss → rating.module.scss} +10 -9
- package/components/Rating/rating.ts +1 -1
- package/components/Spinner/Spinner.astro +44 -42
- package/components/Spinner/Spinner.svelte +40 -38
- package/components/Spinner/Spinner.tsx +45 -44
- package/components/Spinner/{spinner.scss → spinner.module.scss} +41 -41
- package/components/Switch/Switch.astro +13 -11
- package/components/Switch/Switch.svelte +26 -24
- package/components/Switch/Switch.tsx +14 -12
- package/components/Switch/{switch.scss → switch.module.scss} +4 -4
- package/components/Switch/switch.ts +8 -4
- package/components/Table/Table.astro +60 -0
- package/components/Table/Table.svelte +56 -0
- package/components/Table/Table.tsx +64 -0
- package/components/Table/table.module.scss +64 -0
- package/components/Table/table.ts +10 -0
- package/components/Tabs/Tabs.astro +77 -76
- package/components/Tabs/Tabs.svelte +56 -54
- package/components/Tabs/Tabs.tsx +70 -69
- package/components/Tabs/{tabs.scss → tabs.module.scss} +30 -31
- package/components/ThemeSwitcher/ThemeSwitcher.astro +106 -0
- package/components/ThemeSwitcher/ThemeSwitcher.svelte +76 -0
- package/components/ThemeSwitcher/ThemeSwitcher.tsx +89 -0
- package/components/ThemeSwitcher/themeswitcher.module.scss +74 -0
- package/components/ThemeSwitcher/themeswitcher.ts +13 -0
- package/components/Timeline/Timeline.astro +36 -34
- package/components/Timeline/Timeline.svelte +32 -30
- package/components/Timeline/Timeline.tsx +38 -37
- package/components/Timeline/{timeline.scss → timeline.module.scss} +71 -71
- package/components/TimelineItem/TimelineItem.astro +27 -26
- package/components/TimelineItem/TimelineItem.svelte +24 -22
- package/components/TimelineItem/TimelineItem.tsx +33 -32
- package/components/TimelineItem/{timelineitem.scss → timelineitem.module.scss} +31 -31
- package/components/Toast/Toast.astro +41 -30
- package/components/Toast/Toast.svelte +32 -21
- package/components/Toast/Toast.tsx +38 -28
- package/components/Toast/{toast.scss → toast.module.scss} +44 -43
- package/components/Toast/toast.ts +3 -6
- package/icons/moon.svg +3 -0
- package/icons/sun.svg +3 -0
- package/index.js +3 -0
- package/package.json +3 -1
- package/react.d.ts +8 -0
- package/react.js +8 -0
- package/scss/global/elements.scss +1 -1
- package/scss/global/scrollbar.scss +21 -0
- package/scss/global/theme.scss +140 -0
- package/scss/global/tooltip.scss +8 -5
- package/scss/global/utility.scss +29 -0
- package/scss/global.scss +2 -0
- package/scss/resets.scss +5 -5
- package/scss/setup.scss +39 -18
- package/svelte.d.ts +18 -10
- package/svelte.js +8 -0
- package/utils/classNames.ts +4 -0
- package/utils/cookies.ts +28 -0
- package/utils/event.ts +17 -0
- package/utils/toast.ts +12 -9
- package/components/Alert/alert.scss +0 -53
- package/components/Badge/badge.scss +0 -85
- package/components/Button/button.scss +0 -91
- package/components/Card/card.scss +0 -37
|
@@ -1,76 +1,77 @@
|
|
|
1
|
-
---
|
|
2
|
-
import type { TabsProps } from './tabs'
|
|
3
|
-
import './tabs.scss'
|
|
4
|
-
|
|
5
|
-
interface Props extends TabsProps {}
|
|
6
|
-
|
|
7
|
-
const {
|
|
8
|
-
items,
|
|
9
|
-
theme,
|
|
10
|
-
vertical,
|
|
11
|
-
even,
|
|
12
|
-
className
|
|
13
|
-
} = Astro.props
|
|
14
|
-
|
|
15
|
-
const classes = [
|
|
16
|
-
|
|
17
|
-
theme && theme,
|
|
18
|
-
vertical &&
|
|
19
|
-
even &&
|
|
20
|
-
className
|
|
21
|
-
]
|
|
22
|
-
---
|
|
23
|
-
|
|
24
|
-
<section class:list={classes} data-id="w-tabs">
|
|
25
|
-
<div class=
|
|
26
|
-
<div class=
|
|
27
|
-
{items.map(item => (
|
|
28
|
-
<button
|
|
29
|
-
data-value={item.value}
|
|
30
|
-
|
|
31
|
-
disabled={item.disabled}
|
|
32
|
-
>
|
|
33
|
-
<Fragment set:html={item.label} />
|
|
34
|
-
</button>
|
|
35
|
-
))}
|
|
36
|
-
</div>
|
|
37
|
-
</div>
|
|
38
|
-
<div class=
|
|
39
|
-
<slot />
|
|
40
|
-
</div>
|
|
41
|
-
</section>
|
|
42
|
-
|
|
43
|
-
<script>
|
|
44
|
-
const tabs = document.querySelectorAll('[data-id="w-tabs"]')
|
|
45
|
-
|
|
46
|
-
Array.from(tabs).forEach(element => {
|
|
47
|
-
element.addEventListener('click', event => {
|
|
48
|
-
const target = event.target as HTMLDivElement
|
|
49
|
-
|
|
50
|
-
if (target.dataset.value) {
|
|
51
|
-
const tabContent = target.parentElement
|
|
52
|
-
?.parentElement
|
|
53
|
-
?.nextElementSibling as HTMLDivElement
|
|
54
|
-
|
|
55
|
-
Array.from(tabContent.children)
|
|
56
|
-
.forEach((element: any) => {
|
|
57
|
-
if (element.dataset.tab === target.dataset.value) {
|
|
58
|
-
element.dataset.active = true
|
|
59
|
-
} else {
|
|
60
|
-
element.dataset.active = false
|
|
61
|
-
}
|
|
62
|
-
})
|
|
63
|
-
|
|
64
|
-
const tabs = target.parentElement?.querySelectorAll('button') as NodeListOf<HTMLButtonElement>
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
1
|
+
---
|
|
2
|
+
import type { TabsProps } from './tabs'
|
|
3
|
+
import styles from './tabs.module.scss'
|
|
4
|
+
|
|
5
|
+
interface Props extends TabsProps {}
|
|
6
|
+
|
|
7
|
+
const {
|
|
8
|
+
items,
|
|
9
|
+
theme,
|
|
10
|
+
vertical,
|
|
11
|
+
even,
|
|
12
|
+
className
|
|
13
|
+
} = Astro.props
|
|
14
|
+
|
|
15
|
+
const classes = [
|
|
16
|
+
styles.tabs,
|
|
17
|
+
theme && styles[theme],
|
|
18
|
+
vertical && styles.vertical,
|
|
19
|
+
even && styles.even,
|
|
20
|
+
className
|
|
21
|
+
]
|
|
22
|
+
---
|
|
23
|
+
|
|
24
|
+
<section class:list={classes} data-id="w-tabs">
|
|
25
|
+
<div class={styles.wrapper}>
|
|
26
|
+
<div class={styles.items}>
|
|
27
|
+
{items.map(item => (
|
|
28
|
+
<button
|
|
29
|
+
data-value={item.value}
|
|
30
|
+
data-active={item.active ? 'true' : null}
|
|
31
|
+
disabled={item.disabled}
|
|
32
|
+
>
|
|
33
|
+
<Fragment set:html={item.label} />
|
|
34
|
+
</button>
|
|
35
|
+
))}
|
|
36
|
+
</div>
|
|
37
|
+
</div>
|
|
38
|
+
<div class={styles.content}>
|
|
39
|
+
<slot />
|
|
40
|
+
</div>
|
|
41
|
+
</section>
|
|
42
|
+
|
|
43
|
+
<script>
|
|
44
|
+
const tabs = document.querySelectorAll('[data-id="w-tabs"]')
|
|
45
|
+
|
|
46
|
+
Array.from(tabs).forEach(element => {
|
|
47
|
+
element.addEventListener('click', event => {
|
|
48
|
+
const target = event.target as HTMLDivElement
|
|
49
|
+
|
|
50
|
+
if (target.dataset.value) {
|
|
51
|
+
const tabContent = target.parentElement
|
|
52
|
+
?.parentElement
|
|
53
|
+
?.nextElementSibling as HTMLDivElement
|
|
54
|
+
|
|
55
|
+
Array.from(tabContent.children)
|
|
56
|
+
.forEach((element: any) => {
|
|
57
|
+
if (element.dataset.tab === target.dataset.value) {
|
|
58
|
+
element.dataset.active = true
|
|
59
|
+
} else {
|
|
60
|
+
element.dataset.active = false
|
|
61
|
+
}
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
const tabs = target.parentElement?.querySelectorAll('button') as NodeListOf<HTMLButtonElement>
|
|
65
|
+
|
|
66
|
+
// TODO - update logic
|
|
67
|
+
Array.from(tabs).forEach((tab: any) => {
|
|
68
|
+
tab.dataset.active = 'false'
|
|
69
|
+
|
|
70
|
+
if (tab.dataset.value === target.dataset.value) {
|
|
71
|
+
tab.dataset.active = 'true'
|
|
72
|
+
}
|
|
73
|
+
})
|
|
74
|
+
}
|
|
75
|
+
})
|
|
76
|
+
})
|
|
77
|
+
</script>
|
|
@@ -1,54 +1,56 @@
|
|
|
1
|
-
<script lang="ts">
|
|
2
|
-
import type { TabsProps } from './tabs'
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
export let
|
|
8
|
-
export let
|
|
9
|
-
export let
|
|
10
|
-
|
|
11
|
-
let
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
{
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { TabsProps } from './tabs'
|
|
3
|
+
|
|
4
|
+
import styles from './tabs.module.scss'
|
|
5
|
+
import { classNames } from '../../utils/classNames'
|
|
6
|
+
|
|
7
|
+
export let items: TabsProps['items'] = []
|
|
8
|
+
export let theme: TabsProps['theme'] = null
|
|
9
|
+
export let vertical: TabsProps['vertical'] = false
|
|
10
|
+
export let even: TabsProps['even'] = false
|
|
11
|
+
export let className: TabsProps['className'] = ''
|
|
12
|
+
|
|
13
|
+
let active = ''
|
|
14
|
+
let tabContainer: HTMLDivElement
|
|
15
|
+
|
|
16
|
+
const classes = classNames([
|
|
17
|
+
styles.tabs,
|
|
18
|
+
theme && styles[theme],
|
|
19
|
+
vertical && styles.vertical,
|
|
20
|
+
even && styles.even,
|
|
21
|
+
className
|
|
22
|
+
])
|
|
23
|
+
|
|
24
|
+
const setTab = (tab: string) => {
|
|
25
|
+
const tabs = tabContainer.querySelectorAll('[data-tab]')
|
|
26
|
+
|
|
27
|
+
active = tab
|
|
28
|
+
|
|
29
|
+
Array.from(tabs).forEach((item: any) => {
|
|
30
|
+
item.dataset.active = false
|
|
31
|
+
|
|
32
|
+
if (item.dataset.tab === active) {
|
|
33
|
+
item.dataset.active = true
|
|
34
|
+
}
|
|
35
|
+
})
|
|
36
|
+
}
|
|
37
|
+
</script>
|
|
38
|
+
|
|
39
|
+
<section class={classes}>
|
|
40
|
+
<div class={styles.wrapper}>
|
|
41
|
+
<div class={styles.items}>
|
|
42
|
+
{#each items as item}
|
|
43
|
+
<button
|
|
44
|
+
data-active={active ? active === item.value : item.active}
|
|
45
|
+
disabled={item.disabled}
|
|
46
|
+
on:click={() => setTab(item.value)}
|
|
47
|
+
>
|
|
48
|
+
{@html item.label}
|
|
49
|
+
</button>
|
|
50
|
+
{/each}
|
|
51
|
+
</div>
|
|
52
|
+
</div>
|
|
53
|
+
<div class={styles.content} bind:this={tabContainer}>
|
|
54
|
+
<slot />
|
|
55
|
+
</div>
|
|
56
|
+
</section>
|
package/components/Tabs/Tabs.tsx
CHANGED
|
@@ -1,69 +1,70 @@
|
|
|
1
|
-
import React, { useState, useRef } from 'react'
|
|
2
|
-
import type { ReactTabsProps } from './tabs'
|
|
3
|
-
|
|
4
|
-
import './tabs.scss'
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
1
|
+
import React, { useState, useRef } from 'react'
|
|
2
|
+
import type { ReactTabsProps } from './tabs'
|
|
3
|
+
|
|
4
|
+
import styles from './tabs.module.scss'
|
|
5
|
+
import { classNames } from '../../utils/classNames'
|
|
6
|
+
|
|
7
|
+
const Tabs = ({
|
|
8
|
+
items,
|
|
9
|
+
theme,
|
|
10
|
+
vertical,
|
|
11
|
+
even,
|
|
12
|
+
className,
|
|
13
|
+
children
|
|
14
|
+
}: ReactTabsProps) => {
|
|
15
|
+
const tabContainer = useRef<HTMLDivElement>(null)
|
|
16
|
+
const [active, setActive] = useState('')
|
|
17
|
+
|
|
18
|
+
const classes = classNames([
|
|
19
|
+
styles.tabs,
|
|
20
|
+
theme && styles[theme],
|
|
21
|
+
vertical && styles.vertical,
|
|
22
|
+
even && styles.even,
|
|
23
|
+
className
|
|
24
|
+
])
|
|
25
|
+
|
|
26
|
+
const setTab = (tab: string) => {
|
|
27
|
+
const tabs = tabContainer.current!.querySelectorAll('[data-tab]')
|
|
28
|
+
|
|
29
|
+
Array.from(tabs).forEach((item: any) => {
|
|
30
|
+
item.dataset.active = false
|
|
31
|
+
|
|
32
|
+
if (item.dataset.tab === tab) {
|
|
33
|
+
item.dataset.active = true
|
|
34
|
+
}
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
setActive(tab)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const isActive = (item: ReactTabsProps['items'][0]) => {
|
|
41
|
+
if (!active) {
|
|
42
|
+
return item.active ? 'true' : undefined
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return active === item.value ? 'true' : undefined
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return (
|
|
49
|
+
<section className={classes}>
|
|
50
|
+
<div className={styles.wrapper}>
|
|
51
|
+
<div className={styles.items}>
|
|
52
|
+
{items.map((item, index) => (
|
|
53
|
+
<button
|
|
54
|
+
key={index}
|
|
55
|
+
disabled={item.disabled}
|
|
56
|
+
dangerouslySetInnerHTML={{ __html: item.label }}
|
|
57
|
+
onClick={() => setTab(item.value)}
|
|
58
|
+
data-active={isActive(item)}
|
|
59
|
+
/>
|
|
60
|
+
))}
|
|
61
|
+
</div>
|
|
62
|
+
</div>
|
|
63
|
+
<div className={styles.content} ref={tabContainer}>
|
|
64
|
+
{children}
|
|
65
|
+
</div>
|
|
66
|
+
</section>
|
|
67
|
+
)
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export default Tabs
|
|
@@ -1,41 +1,40 @@
|
|
|
1
1
|
@import '../../scss/config.scss';
|
|
2
2
|
|
|
3
|
-
.
|
|
4
|
-
|
|
5
|
-
&.
|
|
6
|
-
|
|
7
|
-
background: #252525;
|
|
3
|
+
.tabs {
|
|
4
|
+
&.boxed .items,
|
|
5
|
+
&.outline .items {
|
|
6
|
+
background: var(--w-color-primary-50);
|
|
8
7
|
border-radius: 5px;
|
|
9
8
|
padding: 5px;
|
|
10
|
-
width:
|
|
9
|
+
width: max-content;
|
|
11
10
|
|
|
12
11
|
button {
|
|
13
12
|
@include Transition();
|
|
14
13
|
border-radius: 5px;
|
|
15
14
|
padding: 10px;
|
|
16
15
|
|
|
17
|
-
|
|
16
|
+
&[data-active="true"] {
|
|
18
17
|
border: 0;
|
|
19
|
-
background:
|
|
18
|
+
background: var(--w-color-primary-70);
|
|
20
19
|
padding-bottom: 10px;
|
|
21
20
|
}
|
|
22
21
|
}
|
|
23
22
|
}
|
|
24
23
|
|
|
25
|
-
&.outline .
|
|
24
|
+
&.outline .items {
|
|
26
25
|
background: transparent;
|
|
27
|
-
border: 1px solid
|
|
26
|
+
border: 1px solid var(--w-color-primary-50);
|
|
28
27
|
|
|
29
28
|
button {
|
|
30
29
|
margin-bottom: 0;
|
|
31
30
|
|
|
32
|
-
|
|
33
|
-
background:
|
|
31
|
+
&[data-active="true"] {
|
|
32
|
+
background: var(--w-color-primary-50);
|
|
34
33
|
}
|
|
35
34
|
}
|
|
36
35
|
}
|
|
37
36
|
|
|
38
|
-
&.even .
|
|
37
|
+
&.even .items button {
|
|
39
38
|
flex: 1;
|
|
40
39
|
justify-content: center;
|
|
41
40
|
}
|
|
@@ -44,36 +43,36 @@
|
|
|
44
43
|
display: flex;
|
|
45
44
|
gap: 20px;
|
|
46
45
|
|
|
47
|
-
&.boxed .
|
|
48
|
-
&.outline .
|
|
46
|
+
&.boxed .items button,
|
|
47
|
+
&.outline .items button {
|
|
49
48
|
border-bottom: 0;
|
|
50
49
|
}
|
|
51
50
|
|
|
52
|
-
.
|
|
51
|
+
.items {
|
|
53
52
|
flex-direction: column;
|
|
54
53
|
gap: 5px;
|
|
55
54
|
|
|
56
55
|
button {
|
|
57
56
|
padding: 10px;
|
|
58
|
-
border-bottom: 2px solid
|
|
57
|
+
border-bottom: 2px solid var(--w-color-primary-50);
|
|
59
58
|
|
|
60
|
-
|
|
59
|
+
&[data-active="true"] {
|
|
61
60
|
padding-bottom: 10px;
|
|
62
61
|
}
|
|
63
62
|
}
|
|
64
63
|
}
|
|
65
64
|
|
|
66
|
-
.
|
|
65
|
+
.content {
|
|
67
66
|
margin-top: 0;
|
|
68
67
|
}
|
|
69
68
|
}
|
|
70
69
|
|
|
71
|
-
.
|
|
70
|
+
.wrapper {
|
|
72
71
|
overflow: auto;
|
|
73
72
|
}
|
|
74
73
|
|
|
75
|
-
.
|
|
76
|
-
border-bottom: 2px solid
|
|
74
|
+
.items {
|
|
75
|
+
border-bottom: 2px solid var(--w-color-primary-50);
|
|
77
76
|
display: flex;
|
|
78
77
|
gap: 10px;
|
|
79
78
|
|
|
@@ -81,13 +80,13 @@
|
|
|
81
80
|
@include Transition(color);
|
|
82
81
|
background: transparent;
|
|
83
82
|
cursor: pointer;
|
|
84
|
-
color:
|
|
83
|
+
color: var(--w-color-primary);
|
|
85
84
|
border: 0;
|
|
86
85
|
font-size: 16px;
|
|
87
86
|
padding: 0;
|
|
88
87
|
margin-bottom: -2px;
|
|
89
88
|
padding: 15px 15px;
|
|
90
|
-
color:
|
|
89
|
+
color: var(--w-color-primary-20);
|
|
91
90
|
display: flex;
|
|
92
91
|
align-items: center;
|
|
93
92
|
gap: 10px;
|
|
@@ -100,19 +99,19 @@
|
|
|
100
99
|
}
|
|
101
100
|
|
|
102
101
|
&[disabled] {
|
|
103
|
-
color:
|
|
102
|
+
color: var(--w-color-primary-30);
|
|
104
103
|
cursor: no-drop;
|
|
105
104
|
}
|
|
106
105
|
|
|
107
|
-
|
|
108
|
-
color:
|
|
109
|
-
border-bottom: 2px solid
|
|
106
|
+
&[data-active="true"] {
|
|
107
|
+
color: var(--w-color-primary);
|
|
108
|
+
border-bottom: 2px solid var(--w-color-primary);
|
|
110
109
|
padding-bottom: 13px;
|
|
111
110
|
}
|
|
112
111
|
}
|
|
113
112
|
}
|
|
114
113
|
|
|
115
|
-
.
|
|
114
|
+
.content {
|
|
116
115
|
margin-top: 20px;
|
|
117
116
|
}
|
|
118
117
|
|
|
@@ -126,8 +125,8 @@
|
|
|
126
125
|
}
|
|
127
126
|
|
|
128
127
|
@include Media('xs') {
|
|
129
|
-
.
|
|
130
|
-
&.even .
|
|
128
|
+
.tabs {
|
|
129
|
+
&.even .items {
|
|
131
130
|
width: auto;
|
|
132
131
|
}
|
|
133
132
|
}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
---
|
|
2
|
+
import type { ThemeSwitcherProps } from './themeswitcher'
|
|
3
|
+
import styles from './themeswitcher.module.scss'
|
|
4
|
+
|
|
5
|
+
interface Props extends ThemeSwitcherProps {}
|
|
6
|
+
|
|
7
|
+
const {
|
|
8
|
+
themes,
|
|
9
|
+
toggle,
|
|
10
|
+
size,
|
|
11
|
+
className
|
|
12
|
+
} = Astro.props
|
|
13
|
+
|
|
14
|
+
const classes = [
|
|
15
|
+
styles.switcher,
|
|
16
|
+
toggle && styles.toggle,
|
|
17
|
+
className
|
|
18
|
+
]
|
|
19
|
+
|
|
20
|
+
const primaryTheme = themes[Object.keys(themes)[0]]
|
|
21
|
+
const secondaryTheme = themes[Object.keys(themes)[1]]
|
|
22
|
+
const useIcons = Astro.slots.has('primaryIcon') && Astro.slots.has('secondaryIcon')
|
|
23
|
+
|
|
24
|
+
const buttonClasses = [
|
|
25
|
+
styles.switch,
|
|
26
|
+
useIcons && styles.icons
|
|
27
|
+
]
|
|
28
|
+
---
|
|
29
|
+
|
|
30
|
+
<div
|
|
31
|
+
class:list={classes}
|
|
32
|
+
style={size ? `--w-theme-switcher-size: ${size}px;` : null}
|
|
33
|
+
data-id="w-theme-switcher"
|
|
34
|
+
data-primary-theme={primaryTheme}
|
|
35
|
+
data-secondary-theme={toggle ? secondaryTheme : undefined}
|
|
36
|
+
>
|
|
37
|
+
{Object.keys(themes as {}).map((theme, index) => (
|
|
38
|
+
<button
|
|
39
|
+
style={!useIcons ? `background:${theme};` : undefined}
|
|
40
|
+
data-theme={themes[theme]}
|
|
41
|
+
class:list={buttonClasses}
|
|
42
|
+
>
|
|
43
|
+
{index === 0 && <slot name="primaryIcon" />}
|
|
44
|
+
{index !== 0 && <slot name="secondaryIcon" />}
|
|
45
|
+
</button>
|
|
46
|
+
))}
|
|
47
|
+
</div>
|
|
48
|
+
|
|
49
|
+
<script>
|
|
50
|
+
import { setCookie, getCookie } from '../../utils/cookies'
|
|
51
|
+
import { listen, dispatch } from '../../utils/event'
|
|
52
|
+
|
|
53
|
+
const switchers = document.querySelectorAll('[data-id="w-theme-switcher"]')
|
|
54
|
+
|
|
55
|
+
let currentTheme = localStorage.getItem('w-theme')
|
|
56
|
+
|| getCookie('w-theme')
|
|
57
|
+
|| (switchers[0] as HTMLDivElement).dataset.primaryTheme
|
|
58
|
+
|| ''
|
|
59
|
+
|
|
60
|
+
const setActiveButton = (buttons: HTMLButtonElement[]) => {
|
|
61
|
+
buttons.forEach(button => button.dataset.active = 'false')
|
|
62
|
+
|
|
63
|
+
buttons.forEach(button => {
|
|
64
|
+
if (button.dataset.theme === currentTheme) {
|
|
65
|
+
button.dataset.active = 'true'
|
|
66
|
+
}
|
|
67
|
+
})
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
Array.from(switchers).forEach(switcher => {
|
|
71
|
+
const buttons = Array.from(switcher.querySelectorAll('button'))
|
|
72
|
+
|
|
73
|
+
setActiveButton(buttons)
|
|
74
|
+
|
|
75
|
+
listen('theme-switched', theme => {
|
|
76
|
+
currentTheme = theme
|
|
77
|
+
|
|
78
|
+
setActiveButton(buttons)
|
|
79
|
+
})
|
|
80
|
+
|
|
81
|
+
switcher.addEventListener('click', event => {
|
|
82
|
+
const target = event.target as HTMLButtonElement
|
|
83
|
+
|
|
84
|
+
if (target.nodeName === 'BUTTON') {
|
|
85
|
+
const toggleTheme = (switcher as HTMLDivElement).dataset.secondaryTheme
|
|
86
|
+
|
|
87
|
+
const theme = toggleTheme
|
|
88
|
+
? toggleTheme === target.dataset.theme
|
|
89
|
+
? (target.previousElementSibling as HTMLButtonElement).dataset.theme as string
|
|
90
|
+
: (target.nextElementSibling as HTMLButtonElement).dataset.theme as string
|
|
91
|
+
: target.dataset.theme as string
|
|
92
|
+
|
|
93
|
+
document.body.classList.replace(currentTheme, theme)
|
|
94
|
+
|
|
95
|
+
currentTheme = theme
|
|
96
|
+
|
|
97
|
+
setActiveButton(buttons)
|
|
98
|
+
setCookie('w-theme', currentTheme, 30)
|
|
99
|
+
localStorage.setItem('w-theme', currentTheme)
|
|
100
|
+
|
|
101
|
+
dispatch('theme-switched', currentTheme)
|
|
102
|
+
}
|
|
103
|
+
})
|
|
104
|
+
})
|
|
105
|
+
</script>
|
|
106
|
+
|