webcoreui 1.5.0-0 → 1.5.0-beta.2

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.
Files changed (228) hide show
  1. package/astro.d.ts +62 -56
  2. package/astro.js +4 -0
  3. package/components/Accordion/Accordion.astro +1 -1
  4. package/components/Accordion/Accordion.svelte +60 -58
  5. package/components/Accordion/Accordion.tsx +4 -2
  6. package/components/Alert/Alert.astro +2 -1
  7. package/components/Alert/Alert.svelte +9 -2
  8. package/components/Alert/Alert.tsx +10 -3
  9. package/components/Alert/alert.ts +2 -18
  10. package/components/AspectRatio/AspectRatio.astro +1 -1
  11. package/components/AspectRatio/AspectRatio.svelte +7 -2
  12. package/components/AspectRatio/AspectRatio.tsx +6 -3
  13. package/components/AspectRatio/aspectratio.ts +0 -10
  14. package/components/Avatar/Avatar.astro +1 -1
  15. package/components/Avatar/Avatar.svelte +3 -1
  16. package/components/Avatar/Avatar.tsx +3 -2
  17. package/components/Badge/Badge.astro +2 -1
  18. package/components/Badge/Badge.svelte +9 -2
  19. package/components/Badge/Badge.tsx +8 -3
  20. package/components/Badge/badge.ts +11 -13
  21. package/components/Banner/Banner.astro +1 -1
  22. package/components/Banner/Banner.svelte +7 -2
  23. package/components/Banner/Banner.tsx +6 -2
  24. package/components/Banner/banner.ts +0 -10
  25. package/components/BottomNavigation/BottomNavigation.astro +1 -1
  26. package/components/BottomNavigation/BottomNavigation.svelte +3 -1
  27. package/components/BottomNavigation/BottomNavigation.tsx +3 -2
  28. package/components/Breadcrumb/Breadcrumb.astro +1 -1
  29. package/components/Breadcrumb/Breadcrumb.svelte +3 -1
  30. package/components/Breadcrumb/Breadcrumb.tsx +3 -1
  31. package/components/Button/Button.astro +2 -1
  32. package/components/Button/Button.svelte +9 -2
  33. package/components/Button/Button.tsx +7 -2
  34. package/components/Button/button.ts +23 -20
  35. package/components/Card/Card.astro +9 -2
  36. package/components/Card/Card.svelte +17 -4
  37. package/components/Card/Card.tsx +23 -6
  38. package/components/Card/card.module.scss +11 -4
  39. package/components/Card/card.ts +3 -16
  40. package/components/Carousel/Carousel.astro +1 -1
  41. package/components/Carousel/Carousel.svelte +8 -3
  42. package/components/Carousel/Carousel.tsx +7 -2
  43. package/components/Carousel/carousel.ts +0 -12
  44. package/components/CarouselItem/CarouselItem.astro +14 -0
  45. package/components/CarouselItem/CarouselItem.svelte +18 -0
  46. package/components/CarouselItem/CarouselItem.tsx +18 -0
  47. package/components/CarouselItem/carouselItem.ts +4 -0
  48. package/components/Checkbox/Checkbox.astro +3 -6
  49. package/components/Checkbox/Checkbox.svelte +9 -7
  50. package/components/Checkbox/Checkbox.tsx +8 -5
  51. package/components/Checkbox/checkbox.ts +2 -17
  52. package/components/Collapsible/Collapsible.astro +1 -1
  53. package/components/Collapsible/Collapsible.svelte +9 -2
  54. package/components/Collapsible/Collapsible.tsx +8 -2
  55. package/components/Collapsible/collapsible.ts +0 -15
  56. package/components/ConditionalWrapper/ConditionalWrapper.astro +1 -1
  57. package/components/ConditionalWrapper/ConditionalWrapper.svelte +8 -2
  58. package/components/ConditionalWrapper/ConditionalWrapper.tsx +7 -2
  59. package/components/ConditionalWrapper/conditionalwrapper.ts +2 -14
  60. package/components/ContextMenu/ContextMenu.astro +2 -1
  61. package/components/ContextMenu/ContextMenu.svelte +9 -3
  62. package/components/ContextMenu/ContextMenu.tsx +8 -2
  63. package/components/ContextMenu/contextmenu.ts +2 -17
  64. package/components/Copy/Copy.astro +2 -2
  65. package/components/Copy/Copy.svelte +8 -3
  66. package/components/Copy/Copy.tsx +7 -3
  67. package/components/Copy/copy.ts +2 -12
  68. package/components/Counter/Counter.astro +3 -2
  69. package/components/Counter/Counter.svelte +10 -5
  70. package/components/Counter/Counter.tsx +11 -7
  71. package/components/Counter/counter.ts +2 -11
  72. package/components/DataTable/DataTable.astro +1 -1
  73. package/components/DataTable/DataTable.svelte +8 -2
  74. package/components/DataTable/DataTable.tsx +7 -2
  75. package/components/DataTable/datatable.ts +0 -12
  76. package/components/Flex/Flex.astro +2 -1
  77. package/components/Flex/Flex.svelte +8 -2
  78. package/components/Flex/Flex.tsx +8 -3
  79. package/components/Flex/flex.ts +2 -15
  80. package/components/Footer/Footer.astro +1 -1
  81. package/components/Footer/Footer.svelte +7 -2
  82. package/components/Footer/Footer.tsx +6 -2
  83. package/components/Footer/footer.ts +0 -10
  84. package/components/Grid/Grid.astro +2 -1
  85. package/components/Grid/Grid.svelte +8 -2
  86. package/components/Grid/Grid.tsx +8 -3
  87. package/components/Grid/grid.ts +2 -15
  88. package/components/Group/Group.astro +1 -1
  89. package/components/Group/Group.svelte +7 -2
  90. package/components/Group/Group.tsx +6 -2
  91. package/components/Group/group.ts +0 -10
  92. package/components/Icon/Icon.astro +1 -1
  93. package/components/Icon/Icon.svelte +3 -1
  94. package/components/Icon/Icon.tsx +3 -2
  95. package/components/Image/Image.astro +2 -1
  96. package/components/Image/Image.svelte +4 -1
  97. package/components/Image/Image.tsx +3 -1
  98. package/components/Image/image.ts +2 -3
  99. package/components/ImageLoader/ImageLoader.astro +1 -1
  100. package/components/ImageLoader/ImageLoader.svelte +3 -1
  101. package/components/ImageLoader/ImageLoader.tsx +4 -2
  102. package/components/Input/Input.astro +3 -2
  103. package/components/Input/Input.svelte +14 -4
  104. package/components/Input/Input.tsx +11 -3
  105. package/components/Input/input.ts +26 -53
  106. package/components/Kbd/Kbd.astro +1 -1
  107. package/components/Kbd/Kbd.svelte +7 -2
  108. package/components/Kbd/Kbd.tsx +6 -2
  109. package/components/Kbd/kbd.ts +0 -10
  110. package/components/List/List.astro +1 -1
  111. package/components/List/List.svelte +6 -2
  112. package/components/List/List.tsx +8 -4
  113. package/components/List/list.ts +0 -8
  114. package/components/Masonry/Masonry.astro +1 -1
  115. package/components/Masonry/Masonry.svelte +7 -2
  116. package/components/Masonry/Masonry.tsx +7 -3
  117. package/components/Masonry/masonry.ts +2 -13
  118. package/components/Menu/Menu.astro +1 -1
  119. package/components/Menu/Menu.svelte +7 -2
  120. package/components/Menu/Menu.tsx +6 -2
  121. package/components/Menu/menu.ts +0 -10
  122. package/components/Modal/Modal.astro +2 -3
  123. package/components/Modal/Modal.svelte +8 -4
  124. package/components/Modal/Modal.tsx +6 -4
  125. package/components/Modal/modal.ts +2 -14
  126. package/components/OTPInput/OTPInput.astro +3 -5
  127. package/components/OTPInput/OTPInput.svelte +6 -6
  128. package/components/OTPInput/OTPInput.tsx +10 -8
  129. package/components/OTPInput/otpinput.ts +2 -4
  130. package/components/Pagination/Pagination.astro +1 -1
  131. package/components/Pagination/Pagination.svelte +6 -2
  132. package/components/Pagination/Pagination.tsx +6 -2
  133. package/components/Pagination/pagination.ts +0 -8
  134. package/components/Popover/Popover.astro +3 -7
  135. package/components/Popover/Popover.svelte +9 -8
  136. package/components/Popover/Popover.tsx +9 -12
  137. package/components/Popover/popover.ts +2 -15
  138. package/components/Progress/Progress.astro +1 -1
  139. package/components/Progress/Progress.svelte +3 -1
  140. package/components/Progress/Progress.tsx +3 -1
  141. package/components/Radio/Radio.astro +3 -4
  142. package/components/Radio/Radio.svelte +10 -5
  143. package/components/Radio/Radio.tsx +7 -5
  144. package/components/Radio/radio.ts +2 -14
  145. package/components/RangeSlider/RangeSlider.astro +1 -1
  146. package/components/RangeSlider/RangeSlider.svelte +6 -2
  147. package/components/RangeSlider/RangeSlider.tsx +7 -3
  148. package/components/RangeSlider/rangeslider.ts +0 -9
  149. package/components/Rating/Rating.astro +1 -1
  150. package/components/Rating/Rating.svelte +3 -1
  151. package/components/Rating/Rating.tsx +3 -1
  152. package/components/Ribbon/Ribbon.astro +1 -1
  153. package/components/Ribbon/Ribbon.svelte +7 -2
  154. package/components/Ribbon/Ribbon.tsx +6 -2
  155. package/components/Ribbon/ribbon.ts +0 -10
  156. package/components/Select/Select.astro +1 -1
  157. package/components/Select/Select.svelte +9 -4
  158. package/components/Select/Select.tsx +9 -4
  159. package/components/Select/select.ts +1 -12
  160. package/components/Sheet/Sheet.astro +2 -1
  161. package/components/Sheet/Sheet.svelte +5 -3
  162. package/components/Sheet/Sheet.tsx +5 -4
  163. package/components/Sheet/sheet.ts +3 -10
  164. package/components/Sidebar/Sidebar.astro +1 -1
  165. package/components/Sidebar/Sidebar.svelte +7 -2
  166. package/components/Sidebar/Sidebar.tsx +6 -2
  167. package/components/Sidebar/sidebar.ts +0 -10
  168. package/components/Skeleton/Skeleton.astro +1 -1
  169. package/components/Skeleton/Skeleton.svelte +3 -1
  170. package/components/Skeleton/Skeleton.tsx +3 -1
  171. package/components/Slider/Slider.astro +1 -1
  172. package/components/Slider/Slider.svelte +8 -2
  173. package/components/Slider/Slider.tsx +6 -2
  174. package/components/Slider/slider.ts +0 -10
  175. package/components/SpeedDial/SpeedDial.astro +1 -1
  176. package/components/SpeedDial/SpeedDial.svelte +3 -1
  177. package/components/SpeedDial/SpeedDial.tsx +4 -2
  178. package/components/Spinner/Spinner.astro +1 -1
  179. package/components/Spinner/Spinner.svelte +3 -1
  180. package/components/Spinner/Spinner.tsx +3 -1
  181. package/components/Spoiler/Spoiler.astro +1 -1
  182. package/components/Spoiler/Spoiler.svelte +7 -2
  183. package/components/Spoiler/Spoiler.tsx +6 -2
  184. package/components/Spoiler/spoiler.ts +0 -10
  185. package/components/Stepper/Stepper.astro +1 -1
  186. package/components/Stepper/Stepper.svelte +3 -1
  187. package/components/Stepper/Stepper.tsx +3 -1
  188. package/components/Switch/Switch.astro +7 -2
  189. package/components/Switch/Switch.svelte +13 -4
  190. package/components/Switch/Switch.tsx +8 -4
  191. package/components/Switch/switch.ts +2 -16
  192. package/components/Tab/Tab.astro +25 -0
  193. package/components/Tab/Tab.svelte +28 -0
  194. package/components/Tab/Tab.tsx +30 -0
  195. package/components/Tab/tab.ts +6 -0
  196. package/components/Table/Table.astro +1 -1
  197. package/components/Table/Table.svelte +3 -1
  198. package/components/Table/Table.tsx +3 -1
  199. package/components/Tabs/Tabs.astro +58 -25
  200. package/components/Tabs/Tabs.svelte +45 -12
  201. package/components/Tabs/Tabs.tsx +42 -11
  202. package/components/Tabs/tabs.module.scss +7 -6
  203. package/components/Tabs/tabs.ts +0 -10
  204. package/components/Textarea/Textarea.astro +3 -6
  205. package/components/Textarea/Textarea.svelte +10 -7
  206. package/components/Textarea/Textarea.tsx +9 -7
  207. package/components/Textarea/textarea.ts +2 -17
  208. package/components/ThemeSwitcher/ThemeSwitcher.astro +1 -1
  209. package/components/ThemeSwitcher/ThemeSwitcher.svelte +9 -3
  210. package/components/ThemeSwitcher/ThemeSwitcher.tsx +7 -2
  211. package/components/ThemeSwitcher/themeswitcher.ts +0 -13
  212. package/components/Timeline/Timeline.astro +1 -1
  213. package/components/Timeline/Timeline.svelte +7 -2
  214. package/components/Timeline/Timeline.tsx +6 -2
  215. package/components/Timeline/timeline.ts +0 -10
  216. package/components/TimelineItem/TimelineItem.astro +1 -1
  217. package/components/TimelineItem/TimelineItem.svelte +7 -2
  218. package/components/TimelineItem/TimelineItem.tsx +8 -3
  219. package/components/TimelineItem/timelineitem.ts +0 -12
  220. package/components/Toast/Toast.astro +2 -1
  221. package/components/Toast/Toast.svelte +5 -3
  222. package/components/Toast/Toast.tsx +5 -4
  223. package/components/Toast/toast.ts +3 -11
  224. package/package.json +19 -19
  225. package/react.d.ts +145 -138
  226. package/react.js +4 -0
  227. package/svelte.d.ts +145 -138
  228. package/svelte.js +4 -0
@@ -1,10 +1,14 @@
1
1
  import React from 'react'
2
- import type { ReactSpoilerProps } from './spoiler'
2
+ import type { SpoilerProps } from './spoiler'
3
3
 
4
4
  import { classNames } from '../../utils/classNames'
5
5
 
6
6
  import styles from './spoiler.module.scss'
7
7
 
8
+ export type Props = SpoilerProps & {
9
+ children: React.ReactNode
10
+ }
11
+
8
12
  const Spoiler = ({
9
13
  color,
10
14
  animated = true,
@@ -12,7 +16,7 @@ const Spoiler = ({
12
16
  tooltip,
13
17
  tooltipPosition,
14
18
  children
15
- }: ReactSpoilerProps) => {
19
+ }: Props) => {
16
20
  const classes = classNames([
17
21
  styles.spoiler,
18
22
  animated && styles.anim,
@@ -1,5 +1,3 @@
1
- import type { Snippet } from 'svelte'
2
-
3
1
  export type SpoilerProps = {
4
2
  color?: string
5
3
  animated?: boolean
@@ -7,11 +5,3 @@ export type SpoilerProps = {
7
5
  tooltip?: string
8
6
  tooltipPosition?: 'bottom' | null
9
7
  }
10
-
11
- export type SvelteSpoilerProps = {
12
- children: Snippet
13
- } & SpoilerProps
14
-
15
- export type ReactSpoilerProps = {
16
- children: React.ReactNode
17
- } & SpoilerProps
@@ -6,7 +6,7 @@ import Icon from '../Icon/Icon.astro'
6
6
 
7
7
  import styles from './stepper.module.scss'
8
8
 
9
- interface Props extends StepperProps {}
9
+ export type Props = StepperProps
10
10
 
11
11
  const {
12
12
  items,
@@ -7,6 +7,8 @@
7
7
 
8
8
  import styles from './stepper.module.scss'
9
9
 
10
+ export type Props = StepperProps
11
+
10
12
  const {
11
13
  items,
12
14
  color,
@@ -15,7 +17,7 @@
15
17
  borderless,
16
18
  vertical,
17
19
  className
18
- }: StepperProps = $props()
20
+ }: Props = $props()
19
21
 
20
22
  const classes = $derived(classNames([
21
23
  styles.stepper,
@@ -7,6 +7,8 @@ import { classNames } from '../../utils/classNames'
7
7
 
8
8
  import styles from './stepper.module.scss'
9
9
 
10
+ export type Props = StepperProps
11
+
10
12
  const Stepper = ({
11
13
  items,
12
14
  color,
@@ -15,7 +17,7 @@ const Stepper = ({
15
17
  borderless,
16
18
  vertical,
17
19
  className
18
- }: StepperProps) => {
20
+ }: Props) => {
19
21
  const classes = classNames([
20
22
  styles.stepper,
21
23
  borderless && styles.borderless,
@@ -1,11 +1,12 @@
1
1
  ---
2
+ import type { HTMLAttributes } from 'astro/types'
2
3
  import type { SwitchProps } from './switch'
3
4
 
4
5
  import { classNames } from '../../utils/classNames'
5
6
 
6
7
  import styles from './switch.module.scss'
7
8
 
8
- interface Props extends SwitchProps {}
9
+ export type Props = SwitchProps<HTMLAttributes<'textarea'>>
9
10
 
10
11
  const {
11
12
  label,
@@ -36,7 +37,11 @@ const styleVariables = classNames([
36
37
  ---
37
38
 
38
39
  <label class:list={classes} style={styleVariables}>
39
- <input type="checkbox" checked={toggled} disabled={disabled} {...rest} />
40
+ <input
41
+ {...rest}
42
+ type="checkbox"
43
+ checked={toggled}
44
+ />
40
45
  <span class={styles.toggle}></span>
41
46
  {label && <span class={styles.label} set:html={label} />}
42
47
  </label>
@@ -1,10 +1,20 @@
1
1
  <script lang="ts">
2
- import type { SvelteSwitchProps } from './switch'
2
+ import type {
3
+ ChangeEventHandler,
4
+ HTMLInputAttributes,
5
+ MouseEventHandler
6
+ } from 'svelte/elements'
7
+ import type { SwitchProps } from './switch'
3
8
 
4
9
  import { classNames } from '../../utils/classNames'
5
10
 
6
11
  import styles from './switch.module.scss'
7
12
 
13
+ export type Props = SwitchProps<HTMLInputAttributes> & {
14
+ onChange?: ChangeEventHandler<HTMLInputElement>
15
+ onClick?: MouseEventHandler<HTMLInputElement>
16
+ }
17
+
8
18
  const {
9
19
  label,
10
20
  toggled,
@@ -18,7 +28,7 @@
18
28
  onClick,
19
29
  onChange,
20
30
  ...rest
21
- }: SvelteSwitchProps = $props()
31
+ }: Props = $props()
22
32
 
23
33
  const classes = $derived(classNames([
24
34
  styles.switch,
@@ -37,12 +47,11 @@
37
47
 
38
48
  <label class={classes} style={styleVariables || null}>
39
49
  <input
50
+ {...rest}
40
51
  type="checkbox"
41
52
  checked={toggled}
42
- disabled={disabled}
43
53
  onclick={onClick}
44
54
  onchange={onChange}
45
- {...rest}
46
55
  />
47
56
  <span class={styles.toggle}></span>
48
57
  {#if label}
@@ -1,10 +1,15 @@
1
1
  import React from 'react'
2
- import type { ReactSwitchProps } from './switch'
2
+ import type { SwitchProps } from './switch'
3
3
 
4
4
  import { classNames } from '../../utils/classNames'
5
5
 
6
6
  import styles from './switch.module.scss'
7
7
 
8
+ export type Props = SwitchProps<React.InputHTMLAttributes<HTMLInputElement>> & {
9
+ onChange?: React.ChangeEventHandler<HTMLInputElement>
10
+ onClick?: React.MouseEventHandler<HTMLInputElement>
11
+ }
12
+
8
13
  const Switch = ({
9
14
  label,
10
15
  toggled,
@@ -16,7 +21,7 @@ const Switch = ({
16
21
  disabled,
17
22
  className,
18
23
  ...rest
19
- }: ReactSwitchProps) => {
24
+ }: Props) => {
20
25
  const classes = classNames([
21
26
  styles.switch,
22
27
  reverse && styles.reverse,
@@ -34,10 +39,9 @@ const Switch = ({
34
39
  return (
35
40
  <label className={classes} style={styleVariables || null}>
36
41
  <input
42
+ {...rest}
37
43
  type="checkbox"
38
44
  defaultChecked={toggled}
39
- disabled={disabled}
40
- {...rest}
41
45
  />
42
46
  <span className={styles.toggle}></span>
43
47
  {label && (
@@ -1,24 +1,10 @@
1
- import type { ChangeEventHandler, MouseEventHandler } from 'svelte/elements'
2
-
3
- export type SwitchProps = {
1
+ export type SwitchProps<T extends object = object> = {
4
2
  label?: string
5
3
  reverse?: boolean
6
4
  toggled?: boolean
7
- disabled?: boolean
8
5
  small?: boolean
9
6
  square?: boolean
10
7
  onColor?: string
11
8
  offColor?: string
12
9
  className?: string
13
- [key: string]: any
14
- }
15
-
16
- export type SvelteSwitchProps = {
17
- onChange?: ChangeEventHandler<HTMLInputElement>
18
- onClick?: MouseEventHandler<HTMLInputElement>
19
- } & SwitchProps
20
-
21
- export type ReactSwitchProps = {
22
- onChange?: React.ChangeEventHandler<HTMLInputElement>
23
- onClick?: React.MouseEventHandler<HTMLInputElement>
24
- } & SwitchProps
10
+ } & T
@@ -0,0 +1,25 @@
1
+ ---
2
+ import type { HTMLAttributes } from 'astro/types'
3
+ import type { TabProps } from './tab'
4
+
5
+ export type Props = TabProps<HTMLAttributes<'section'>>
6
+
7
+ const {
8
+ element = 'div',
9
+ id,
10
+ active,
11
+ className,
12
+ ...rest
13
+ } = Astro.props
14
+
15
+ const Element = element
16
+
17
+ const props = {
18
+ ...rest,
19
+ 'class': className,
20
+ 'data-tab': id,
21
+ 'data-active': active
22
+ }
23
+ ---
24
+
25
+ <Element {...props}><slot /></Element>
@@ -0,0 +1,28 @@
1
+ <script lang="ts">
2
+ import type { Snippet } from 'svelte'
3
+ import type { HTMLAttributes } from 'svelte/elements'
4
+ import type { TabProps } from './tab'
5
+
6
+ export type Props = TabProps<HTMLAttributes<HTMLElement>> & {
7
+ children: Snippet
8
+ }
9
+
10
+ const {
11
+ element = 'div',
12
+ id,
13
+ active,
14
+ className,
15
+ children,
16
+ ...rest
17
+ }: Props = $props()
18
+ </script>
19
+
20
+ <svelte:element
21
+ {...rest}
22
+ {...(className && { class: className })}
23
+ this={element}
24
+ data-tab={id}
25
+ data-active={active}
26
+ >
27
+ {@render children?.()}
28
+ </svelte:element>
@@ -0,0 +1,30 @@
1
+ import React from 'react'
2
+ import type { TabProps } from './tab'
3
+
4
+ export type Props = TabProps<React.HTMLAttributes<HTMLElement>> & {
5
+ children: React.ReactNode
6
+ }
7
+
8
+ const Tab = ({
9
+ element = 'div',
10
+ id,
11
+ active,
12
+ className,
13
+ children,
14
+ ...rest
15
+ }: Props) => {
16
+ const Element = element as React.ElementType<React.HTMLAttributes<HTMLElement>>
17
+
18
+ return (
19
+ <Element
20
+ {...rest}
21
+ className={className}
22
+ data-tab={id}
23
+ data-active={active}
24
+ >
25
+ {children}
26
+ </Element>
27
+ )
28
+ }
29
+
30
+ export default Tab
@@ -0,0 +1,6 @@
1
+ export type TabProps<T extends object = object> = {
2
+ element?: string
3
+ id?: string
4
+ active?: boolean
5
+ className?: string
6
+ } & T
@@ -3,7 +3,7 @@ import type { TableProps } from './table'
3
3
 
4
4
  import styles from './table.module.scss'
5
5
 
6
- interface Props extends TableProps {}
6
+ export type Props = TableProps
7
7
 
8
8
  const {
9
9
  headings,
@@ -4,6 +4,8 @@
4
4
  import { classNames } from '../../utils/classNames'
5
5
 
6
6
  import styles from './table.module.scss'
7
+
8
+ export type Props = TableProps
7
9
 
8
10
  const {
9
11
  headings,
@@ -15,7 +17,7 @@
15
17
  compact,
16
18
  maxHeight,
17
19
  className
18
- }: TableProps = $props()
20
+ }: Props = $props()
19
21
 
20
22
  const classes = $derived(classNames([
21
23
  styles.table,
@@ -4,6 +4,8 @@ import type { TableProps } from './table'
4
4
  import { classNames } from '../../utils/classNames'
5
5
 
6
6
  import styles from './table.module.scss'
7
+
8
+ export type Props = TableProps
7
9
 
8
10
  const Table = ({
9
11
  headings,
@@ -15,7 +17,7 @@ const Table = ({
15
17
  compact,
16
18
  maxHeight,
17
19
  className
18
- }: TableProps) => {
20
+ }: Props) => {
19
21
  const classes = classNames([
20
22
  styles.table,
21
23
  hover && styles.hover,
@@ -3,7 +3,7 @@ import type { TabsProps } from './tabs'
3
3
 
4
4
  import styles from './tabs.module.scss'
5
5
 
6
- interface Props extends TabsProps {}
6
+ export type Props = TabsProps
7
7
 
8
8
  const {
9
9
  items,
@@ -20,6 +20,12 @@ const classes = [
20
20
  even && styles.even,
21
21
  className
22
22
  ]
23
+
24
+ const hasActive = items.some(item => item.active)
25
+
26
+ if (!hasActive) {
27
+ items[0].active = true
28
+ }
23
29
  ---
24
30
 
25
31
  <section class:list={classes} data-id="w-tabs">
@@ -36,45 +42,72 @@ const classes = [
36
42
  ))}
37
43
  </div>
38
44
  </div>
39
- <div class={styles.content}>
45
+ <div
46
+ class={styles.content}
47
+ data-id="w-tabs-content"
48
+ data-active-index={items.findIndex(item => item.active)}
49
+ >
40
50
  <slot />
41
51
  </div>
42
52
  </section>
43
53
 
44
54
  <script>
45
- import { on } from '../../utils/DOMUtils'
55
+ import { get, on } from '../../utils/DOMUtils'
56
+
57
+ const setActiveTab = () => {
58
+ const tabContents = get('[data-id="w-tabs-content"]', true) as NodeListOf<HTMLDivElement>
59
+
60
+ tabContents.forEach((tabContent) => {
61
+ const contentChildren = Array.from(tabContent.children) as HTMLElement[]
62
+
63
+ if (!contentChildren.some(element => element.dataset.active === 'true')) {
64
+ const index = Number(tabContent.dataset.activeIndex)
65
+
66
+ if (contentChildren[index]) {
67
+ contentChildren[index].dataset.active = 'true'
68
+ }
69
+ }
70
+ })
71
+ }
46
72
 
47
73
  const addEventListeners = () => {
48
74
  on('[data-id="w-tabs"]', 'click', (event: Event) => {
49
- const target = event.target as HTMLDivElement
75
+ const target = event.target as HTMLButtonElement
76
+
77
+ if (!target.dataset.value) {
78
+ return
79
+ }
50
80
 
51
- if (target.dataset.value) {
52
- const tabContent = target.parentElement
53
- ?.parentElement
54
- ?.nextElementSibling as HTMLDivElement
81
+ const tabContent = target.parentElement
82
+ ?.parentElement
83
+ ?.nextElementSibling as HTMLDivElement
55
84
 
56
- Array.from(tabContent.children)
57
- .forEach((element: any) => {
58
- if (element.dataset.tab === target.dataset.value) {
59
- element.dataset.active = true
60
- } else {
61
- element.dataset.active = false
62
- }
63
- })
85
+ const btns = Array.from(target.parentElement?.querySelectorAll('button') as NodeListOf<HTMLButtonElement>)
86
+ const clickedIndex = btns.indexOf(target)
87
+ const contentChildren = Array.from(tabContent.children) as HTMLElement[]
88
+ const hasExplicitTabs = contentChildren.some((element: HTMLElement) => element.dataset.tab)
64
89
 
65
- const tabs = target.parentElement?.querySelectorAll('button') as NodeListOf<HTMLButtonElement>
90
+ btns.forEach((tab: HTMLElement, index: number) => {
91
+ tab.dataset.active = index === clickedIndex ? 'true' : 'false'
66
92
 
67
- Array.from(tabs).forEach((tab: any) => {
68
- tab.dataset.active = 'false'
93
+ if (contentChildren[index]) {
94
+ const content = contentChildren[index]
69
95
 
70
- if (tab.dataset.value === target.dataset.value) {
71
- tab.dataset.active = 'true'
96
+ if (hasExplicitTabs) {
97
+ content.dataset.active = content.dataset.tab === target.dataset.value ? 'true' : 'false'
98
+ } else {
99
+ content.dataset.active = index === clickedIndex ? 'true' : 'false'
72
100
  }
73
- })
74
- }
101
+ }
102
+ })
75
103
  }, true)
76
104
  }
77
105
 
78
- on(document, 'astro:after-swap', addEventListeners)
79
- addEventListeners()
106
+ const initTabs = () => {
107
+ setActiveTab()
108
+ addEventListeners()
109
+ }
110
+
111
+ on(document, 'astro:after-swap', initTabs)
112
+ initTabs()
80
113
  </script>
@@ -1,10 +1,15 @@
1
1
  <script lang="ts">
2
- import type { SvelteTabsProps } from './tabs'
2
+ import { onMount, type Snippet } from 'svelte'
3
+ import type { TabsProps } from './tabs'
3
4
 
4
5
  import { classNames } from '../../utils/classNames'
5
6
 
6
7
  import styles from './tabs.module.scss'
7
8
 
9
+ export type Props = TabsProps & {
10
+ children: Snippet
11
+ }
12
+
8
13
  const {
9
14
  items,
10
15
  theme,
@@ -12,11 +17,21 @@
12
17
  even,
13
18
  className,
14
19
  children
15
- }: SvelteTabsProps = $props()
20
+ }: Props = $props()
16
21
 
17
22
  let active = $state('')
18
23
  let tabContainer: HTMLDivElement | undefined = $state()
19
24
 
25
+ const usedInAstro = $derived(tabContainer?.children[0]?.nodeName === 'ASTRO-SLOT')
26
+ const hasActive = $derived(items.some(item => item.active))
27
+ const itemsState = $derived.by(() => {
28
+ if (!hasActive) {
29
+ items[0].active = true
30
+ }
31
+
32
+ return items
33
+ })
34
+
20
35
  const classes = $derived(classNames([
21
36
  styles.tabs,
22
37
  theme && styles[theme],
@@ -25,29 +40,47 @@
25
40
  className
26
41
  ]))
27
42
 
28
- const setTab = (tab: string) => {
29
- const tabs = tabContainer!.querySelectorAll('[data-tab]')
30
-
31
- active = tab
43
+ const setTab = (tab: string, index: number) => {
44
+ const contentChildren = usedInAstro
45
+ ? Array.from(tabContainer!.children[0].children) as HTMLElement[]
46
+ : Array.from(tabContainer!.children) as HTMLElement[]
32
47
 
33
- Array.from(tabs).forEach((item: any) => {
34
- item.dataset.active = false
48
+ const hasExplicitTabs = contentChildren.some((el: HTMLElement) => el.dataset.tab)
35
49
 
36
- if (item.dataset.tab === active) {
37
- item.dataset.active = true
50
+ contentChildren.forEach((item: HTMLElement, i: number) => {
51
+ if (hasExplicitTabs) {
52
+ item.dataset.active = item.dataset.tab === tab ? 'true' : 'false'
53
+ } else {
54
+ item.dataset.active = i === index ? 'true' : 'false'
38
55
  }
39
56
  })
57
+
58
+ active = tab
40
59
  }
60
+
61
+ onMount(() => {
62
+ const contentChildren = usedInAstro
63
+ ? Array.from(tabContainer!.children[0].children) as HTMLElement[]
64
+ : Array.from(tabContainer!.children) as HTMLElement[]
65
+
66
+ if (!contentChildren.some(element => element.dataset.active === 'true')) {
67
+ const index = itemsState.findIndex(item => item.active)
68
+
69
+ if (contentChildren[index]) {
70
+ contentChildren[index].dataset.active = 'true'
71
+ }
72
+ }
73
+ })
41
74
  </script>
42
75
 
43
76
  <section class={classes}>
44
77
  <div class={styles.wrapper}>
45
78
  <div class={styles.items}>
46
- {#each items as item}
79
+ {#each itemsState as item, i}
47
80
  <button
48
81
  data-active={active ? active === item.value : item.active}
49
82
  disabled={item.disabled}
50
- onclick={() => setTab(item.value)}
83
+ onclick={() => setTab(item.value, i)}
51
84
  >
52
85
  {@html item.label}
53
86
  </button>