webcoreui 0.9.0 → 0.10.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.
Files changed (138) hide show
  1. package/README.md +20 -6
  2. package/components/Accordion/Accordion.astro +15 -10
  3. package/components/Accordion/Accordion.svelte +14 -12
  4. package/components/Accordion/Accordion.tsx +2 -2
  5. package/components/Alert/Alert.svelte +17 -12
  6. package/components/Alert/Alert.tsx +1 -1
  7. package/components/Alert/alert.ts +10 -3
  8. package/components/AspectRatio/AspectRatio.svelte +7 -4
  9. package/components/AspectRatio/aspectratio.ts +6 -0
  10. package/components/Avatar/Avatar.svelte +11 -9
  11. package/components/Badge/Badge.svelte +14 -10
  12. package/components/Badge/badge.ts +2 -1
  13. package/components/Banner/Banner.astro +10 -4
  14. package/components/Banner/Banner.svelte +14 -10
  15. package/components/Banner/Banner.tsx +1 -0
  16. package/components/Banner/banner.ts +6 -0
  17. package/components/BottomNavigation/BottomNavigation.svelte +7 -5
  18. package/components/Breadcrumb/Breadcrumb.astro +1 -1
  19. package/components/Breadcrumb/Breadcrumb.svelte +8 -6
  20. package/components/Breadcrumb/Breadcrumb.tsx +2 -2
  21. package/components/Button/Button.svelte +12 -8
  22. package/components/Button/Button.tsx +2 -2
  23. package/components/Button/button.ts +2 -3
  24. package/components/Card/Card.svelte +14 -10
  25. package/components/Card/card.ts +6 -0
  26. package/components/Carousel/Carousel.astro +46 -41
  27. package/components/Carousel/carousel.ts +3 -0
  28. package/components/Checkbox/Checkbox.svelte +12 -9
  29. package/components/Checkbox/checkbox.module.scss +4 -0
  30. package/components/Collapsible/Collapsible.astro +8 -5
  31. package/components/Collapsible/Collapsible.svelte +54 -49
  32. package/components/Collapsible/collapsible.ts +8 -0
  33. package/components/ConditionalWrapper/ConditionalWrapper.svelte +10 -6
  34. package/components/ConditionalWrapper/conditionalwrapper.ts +6 -0
  35. package/components/Copy/Copy.astro +17 -11
  36. package/components/Copy/Copy.svelte +68 -61
  37. package/components/Copy/Copy.tsx +1 -0
  38. package/components/Copy/copy.ts +8 -2
  39. package/components/DataTable/DataTable.astro +103 -93
  40. package/components/DataTable/DataTable.svelte +276 -272
  41. package/components/DataTable/datatable.ts +5 -2
  42. package/components/Flex/Flex.svelte +14 -10
  43. package/components/Flex/flex.ts +6 -0
  44. package/components/Footer/Footer.svelte +12 -9
  45. package/components/Footer/footer.ts +6 -0
  46. package/components/Grid/Grid.svelte +12 -8
  47. package/components/Grid/grid.ts +6 -0
  48. package/components/Group/Group.svelte +7 -4
  49. package/components/Group/group.ts +6 -0
  50. package/components/Icon/Icon.astro +19 -5
  51. package/components/Icon/Icon.svelte +23 -7
  52. package/components/Icon/Icon.tsx +19 -5
  53. package/components/Icon/icon.ts +9 -3
  54. package/components/Icon/map.ts +8 -10
  55. package/components/Input/Input.svelte +24 -20
  56. package/components/Input/input.ts +10 -3
  57. package/components/Kbd/Kbd.svelte +7 -4
  58. package/components/Kbd/kbd.ts +6 -0
  59. package/components/List/List.astro +65 -60
  60. package/components/List/List.svelte +149 -147
  61. package/components/List/List.tsx +1 -1
  62. package/components/Masonry/Masonry.svelte +12 -10
  63. package/components/Menu/Menu.astro +8 -3
  64. package/components/Menu/Menu.svelte +15 -10
  65. package/components/Menu/Menu.tsx +3 -1
  66. package/components/Menu/menu.ts +6 -0
  67. package/components/Modal/Modal.astro +1 -0
  68. package/components/Modal/Modal.svelte +18 -13
  69. package/components/Modal/Modal.tsx +2 -1
  70. package/components/Modal/modal.ts +6 -1
  71. package/components/Pagination/Pagination.astro +75 -69
  72. package/components/Pagination/Pagination.svelte +29 -26
  73. package/components/Pagination/Pagination.tsx +5 -4
  74. package/components/Pagination/pagination.module.scss +4 -0
  75. package/components/Popover/Popover.svelte +10 -6
  76. package/components/Popover/popover.ts +6 -0
  77. package/components/Progress/Progress.svelte +12 -10
  78. package/components/Progress/progress.ts +1 -1
  79. package/components/Radio/Radio.svelte +12 -9
  80. package/components/Radio/radio.ts +4 -2
  81. package/components/Rating/Rating.svelte +16 -14
  82. package/components/Ribbon/Ribbon.svelte +9 -6
  83. package/components/Ribbon/ribbon.ts +6 -0
  84. package/components/Select/Select.astro +73 -63
  85. package/components/Select/Select.svelte +27 -22
  86. package/components/Select/Select.tsx +8 -6
  87. package/components/Sheet/Sheet.svelte +9 -5
  88. package/components/Sheet/sheet.ts +6 -2
  89. package/components/Sidebar/Sidebar.svelte +7 -4
  90. package/components/Sidebar/sidebar.ts +6 -0
  91. package/components/Skeleton/Skeleton.svelte +9 -7
  92. package/components/Slider/Slider.svelte +15 -13
  93. package/components/Slider/slider.module.scss +4 -0
  94. package/components/Slider/slider.ts +4 -2
  95. package/components/Spinner/Spinner.svelte +7 -5
  96. package/components/Spoiler/Spoiler.astro +13 -8
  97. package/components/Spoiler/Spoiler.svelte +13 -10
  98. package/components/Spoiler/spoiler.ts +6 -0
  99. package/components/Stepper/Stepper.svelte +9 -7
  100. package/components/Switch/Switch.svelte +15 -12
  101. package/components/Table/Table.svelte +11 -9
  102. package/components/Table/table.ts +1 -1
  103. package/components/Tabs/Tabs.astro +8 -5
  104. package/components/Tabs/Tabs.svelte +14 -11
  105. package/components/Tabs/tabs.ts +7 -1
  106. package/components/Textarea/Textarea.svelte +14 -11
  107. package/components/Textarea/textarea.ts +9 -4
  108. package/components/ThemeSwitcher/ThemeSwitcher.astro +43 -37
  109. package/components/ThemeSwitcher/ThemeSwitcher.svelte +14 -10
  110. package/components/ThemeSwitcher/themeswitcher.ts +7 -0
  111. package/components/Timeline/Timeline.svelte +12 -9
  112. package/components/Timeline/timeline.ts +7 -2
  113. package/components/TimelineItem/TimelineItem.svelte +8 -5
  114. package/components/TimelineItem/timelineitem.ts +6 -0
  115. package/components/Toast/Toast.svelte +18 -10
  116. package/components/Toast/toast.ts +6 -1
  117. package/icons/alert.svg +2 -2
  118. package/icons/check.svg +2 -2
  119. package/icons/chevron-down.svg +3 -0
  120. package/icons/chevron-left.svg +3 -0
  121. package/icons/chevron-right.svg +3 -0
  122. package/icons/chevron-up.svg +3 -0
  123. package/icons/circle-check.svg +3 -3
  124. package/icons/info.svg +3 -3
  125. package/icons.d.ts +4 -5
  126. package/icons.js +4 -5
  127. package/index.d.ts +1 -0
  128. package/index.js +1 -0
  129. package/package.json +20 -20
  130. package/react.d.ts +3 -3
  131. package/svelte.d.ts +98 -98
  132. package/utils/bodyFreeze.ts +13 -0
  133. package/utils/modal.ts +12 -0
  134. package/icons/arrow-down.svg +0 -3
  135. package/icons/arrow-left.svg +0 -3
  136. package/icons/arrow-right.svg +0 -3
  137. package/icons/components.svg +0 -3
  138. package/icons/file.svg +0 -3
@@ -1,5 +1,5 @@
1
1
  <script lang="ts">
2
- import type { FooterProps } from './footer'
2
+ import type { SvelteFooterProps } from './footer'
3
3
 
4
4
  import ConditionalWrapper from '../ConditionalWrapper/ConditionalWrapper.svelte'
5
5
 
@@ -7,12 +7,15 @@
7
7
 
8
8
  import styles from './footer.module.scss'
9
9
 
10
- export let logo: FooterProps['logo'] = null
11
- export let columns: FooterProps['columns'] = []
12
- export let subText: FooterProps['subText'] = ''
13
- export let className: FooterProps['className'] = ''
14
- export let wrapperClassName: FooterProps['wrapperClassName'] = ''
15
- export let subTextClassName: FooterProps['subTextClassName'] = ''
10
+ const {
11
+ logo,
12
+ columns,
13
+ subText,
14
+ className,
15
+ wrapperClassName,
16
+ subTextClassName,
17
+ children
18
+ }: SvelteFooterProps = $props()
16
19
 
17
20
  const classes = classNames([
18
21
  styles.footer,
@@ -82,12 +85,12 @@
82
85
  </ConditionalWrapper>
83
86
  {/if}
84
87
  </ConditionalWrapper>
85
- {#if subText || $$slots.default}
88
+ {#if subText || children}
86
89
  <div class={subTextClasses}>
87
90
  {#if subText}
88
91
  <span>{@html subText}</span>
89
92
  {/if}
90
- <slot />
93
+ {@render children?.()}
91
94
  </div>
92
95
  {/if}
93
96
  </div>
@@ -1,3 +1,5 @@
1
+ import type { Snippet } from 'svelte'
2
+
1
3
  import type { ButtonProps } from '../Button/button'
2
4
 
3
5
  export type FooterProps = {
@@ -24,6 +26,10 @@ export type FooterProps = {
24
26
  subTextClassName?: string
25
27
  }
26
28
 
29
+ export type SvelteFooterProps = {
30
+ children?: Snippet
31
+ } & FooterProps
32
+
27
33
  export type ReactFooterProps = {
28
34
  children?: React.ReactNode
29
35
  } & FooterProps
@@ -1,13 +1,17 @@
1
1
  <script lang="ts">
2
- import type { GridProps } from './grid'
2
+ import type { SvelteGridProps } from './grid'
3
3
 
4
4
  import { classNames } from '../../utils/classNames'
5
5
  import { getLayoutClasses } from '../../utils/getLayoutClasses'
6
6
 
7
- export let element: GridProps['className'] = 'div'
8
- export let gap: GridProps['gap'] = ''
9
- export let column: GridProps['column'] = null
10
- export let className: GridProps['className'] = ''
7
+ const {
8
+ element = 'div',
9
+ gap,
10
+ column,
11
+ className,
12
+ children,
13
+ ...rest
14
+ }: SvelteGridProps = $props()
11
15
 
12
16
  const classes = classNames([
13
17
  'grid',
@@ -15,11 +19,11 @@
15
19
  className
16
20
  ])
17
21
 
18
- const props = {
22
+ const componentProps = {
19
23
  class: classes
20
24
  }
21
25
  </script>
22
26
 
23
- <svelte:element this={element} {...props} {...$$restProps}>
24
- <slot />
27
+ <svelte:element this={element} {...componentProps} {...rest}>
28
+ {@render children?.()}
25
29
  </svelte:element>
@@ -1,3 +1,5 @@
1
+ import type { Snippet } from 'svelte'
2
+
1
3
  import type {
2
4
  Column,
3
5
  Gap,
@@ -12,6 +14,10 @@ export type GridProps = {
12
14
  [key: string]: any
13
15
  }
14
16
 
17
+ export type SvelteGridProps = {
18
+ children: Snippet
19
+ } & GridProps
20
+
15
21
  export type ReactGridProps = {
16
22
  Element?: keyof JSX.IntrinsicElements
17
23
  children: React.ReactNode
@@ -1,12 +1,15 @@
1
1
  <script lang="ts">
2
- import type { GroupProps } from './group'
2
+ import type { SvelteGroupProps } from './group'
3
3
 
4
4
  import { classNames } from '../../utils/classNames'
5
5
 
6
6
  import styles from './group.module.scss'
7
7
 
8
- export let withSeparator: GroupProps['withSeparator'] = false
9
- export let className: GroupProps['className'] = ''
8
+ const {
9
+ withSeparator,
10
+ className,
11
+ children
12
+ }: SvelteGroupProps = $props()
10
13
 
11
14
  const classes = classNames([
12
15
  styles.group,
@@ -16,5 +19,5 @@
16
19
  </script>
17
20
 
18
21
  <div class={classes}>
19
- <slot />
22
+ {@render children?.()}
20
23
  </div>
@@ -1,8 +1,14 @@
1
+ import type { Snippet } from 'svelte'
2
+
1
3
  export type GroupProps = {
2
4
  withSeparator?: boolean
3
5
  className?: string
4
6
  }
5
7
 
8
+ export type SvelteGroupProps = {
9
+ children: Snippet
10
+ } & GroupProps
11
+
6
12
  export type ReactGroupProps = {
7
13
  children: React.ReactNode
8
14
  } & GroupProps
@@ -7,13 +7,27 @@ interface Props extends IconProps {}
7
7
  const {
8
8
  type,
9
9
  size = 24,
10
- color
10
+ color,
11
+ theme,
12
+ iconSet
11
13
  } = Astro.props
12
14
 
13
- const icon = iconMap[type as keyof typeof iconMap]
14
- .replace('width="24"', `width=${size}`)
15
- .replace('height="24"', color
16
- ? `height=${size} color=${color}`
15
+ const icons = {
16
+ ...iconMap,
17
+ ...(iconSet || {})
18
+ }
19
+
20
+ const svg = icons[type as keyof typeof iconMap]
21
+
22
+ if (!svg) {
23
+ // eslint-disable-next-line no-console
24
+ console.error('Cannot find icon type:', type)
25
+ }
26
+
27
+ const icon = svg
28
+ ?.replace('width="24"', `width=${size}`)
29
+ ?.replace('height="24"', color || theme
30
+ ? `height=${size} color=${color || `var(--w-color-${theme})`}`
17
31
  : `height=${size}`)
18
32
  ---
19
33
 
@@ -2,14 +2,30 @@
2
2
  import type { IconProps } from './icon'
3
3
  import iconMap from './map'
4
4
 
5
- export let type: IconProps['type'] = 'alert'
6
- export let size: IconProps['size'] = 24
7
- export let color: IconProps['color'] = ''
5
+ const {
6
+ type,
7
+ size = 24,
8
+ color,
9
+ theme,
10
+ iconSet
11
+ }: IconProps = $props()
8
12
 
9
- const icon = iconMap[type as keyof typeof iconMap]
10
- .replace('width="24"', `width=${size}`)
11
- .replace('height="24"', color
12
- ? `height=${size} color=${color}`
13
+ const icons = {
14
+ ...iconMap,
15
+ ...(iconSet || {})
16
+ }
17
+
18
+ const svg = icons[type as keyof typeof iconMap]
19
+
20
+ if (!svg) {
21
+ // eslint-disable-next-line no-console
22
+ console.error('Cannot find icon type:', type)
23
+ }
24
+
25
+ const icon = svg
26
+ ?.replace('width="24"', `width=${size}`)
27
+ ?.replace('height="24"', color || theme
28
+ ? `height=${size} color=${color || `var(--w-color-${theme})`}`
13
29
  : `height=${size}`)
14
30
  </script>
15
31
 
@@ -5,12 +5,26 @@ import iconMap from './map'
5
5
  const Icon = ({
6
6
  type,
7
7
  size = 24,
8
- color
8
+ color,
9
+ theme,
10
+ iconSet
9
11
  }: IconProps) => {
10
- const icon = iconMap[type as keyof typeof iconMap]
11
- .replace('width="24"', `width=${size}`)
12
- .replace('height="24"', color
13
- ? `height=${size} color=${color}`
12
+ const icons = {
13
+ ...iconMap,
14
+ ...(iconSet || {})
15
+ }
16
+
17
+ const svg = icons[type as keyof typeof iconMap]
18
+
19
+ if (!svg) {
20
+ // eslint-disable-next-line no-console
21
+ console.error('Cannot find icon type:', type)
22
+ }
23
+
24
+ const icon = svg
25
+ ?.replace('width="24"', `width=${size}`)
26
+ ?.replace('height="24"', color || theme
27
+ ? `height=${size} color=${color || `var(--w-color-${theme})`}`
14
28
  : `height=${size}`)
15
29
 
16
30
  return <span dangerouslySetInnerHTML={{ __html: icon }} />
@@ -1,9 +1,10 @@
1
1
  export type IconProps = {
2
2
  type: 'alert'
3
- | 'arrow-down'
4
- | 'arrow-left'
5
- | 'arrow-right'
6
3
  | 'check'
4
+ | 'chevron-down'
5
+ | 'chevron-left'
6
+ | 'chevron-right'
7
+ | 'chevron-up'
7
8
  | 'circle-check'
8
9
  | 'circle-close'
9
10
  | 'close'
@@ -18,6 +19,11 @@ export type IconProps = {
18
19
  | 'search'
19
20
  | 'sun'
20
21
  | 'warning'
22
+ | string
21
23
  size?: number
22
24
  color?: string
25
+ theme?: 'info' | 'success' | 'warning' | 'alert'
26
+ iconSet?: {
27
+ [key: string]: string
28
+ }
23
29
  }
@@ -1,14 +1,13 @@
1
1
  import Alert from '../../icons/alert.svg?raw'
2
- import ArrowDown from '../../icons/arrow-down.svg?raw'
3
- import ArrowLeft from '../../icons/arrow-left.svg?raw'
4
- import ArrowRight from '../../icons/arrow-right.svg?raw'
5
2
  import Check from '../../icons/check.svg?raw'
3
+ import ChevronDown from '../../icons/chevron-down.svg?raw'
4
+ import ChevronLeft from '../../icons/chevron-left.svg?raw'
5
+ import ChevronRight from '../../icons/chevron-right.svg?raw'
6
+ import ChevronUp from '../../icons/chevron-up.svg?raw'
6
7
  import CircleCheck from '../../icons/circle-check.svg?raw'
7
8
  import CircleClose from '../../icons/circle-close.svg?raw'
8
9
  import Close from '../../icons/close.svg?raw'
9
- import Components from '../../icons/components.svg?raw'
10
10
  import Copy from '../../icons/copy.svg?raw'
11
- import File from '../../icons/file.svg?raw'
12
11
  import Github from '../../icons/github.svg?raw'
13
12
  import Home from '../../icons/home.svg?raw'
14
13
  import Info from '../../icons/info.svg?raw'
@@ -21,16 +20,15 @@ import Warning from '../../icons/warning.svg?raw'
21
20
 
22
21
  const iconMap = {
23
22
  'alert': Alert,
24
- 'arrow-down': ArrowDown,
25
- 'arrow-left': ArrowLeft,
26
- 'arrow-right': ArrowRight,
27
23
  'check': Check,
24
+ 'chevron-down': ChevronDown,
25
+ 'chevron-left': ChevronLeft,
26
+ 'chevron-right': ChevronRight,
27
+ 'chevron-up': ChevronUp,
28
28
  'circle-check': CircleCheck,
29
29
  'circle-close': CircleClose,
30
30
  'close': Close,
31
- 'components': Components,
32
31
  'copy': Copy,
33
- 'file': File,
34
32
  'github': Github,
35
33
  'home': Home,
36
34
  'info': Info,
@@ -7,17 +7,21 @@
7
7
 
8
8
  import styles from './input.module.scss'
9
9
 
10
- export let type: SvelteInputProps['type'] = 'text'
11
- export let theme: SvelteInputProps['theme'] = null
12
- export let label: SvelteInputProps['label'] = ''
13
- export let value: SvelteInputProps['value'] = ''
14
- export let subText: SvelteInputProps['subText'] = ''
15
- export let className: SvelteInputProps['className'] = ''
16
- export let labelClassName: SvelteInputProps['labelClassName'] = ''
17
- export let onChange: SvelteInputProps['onChange'] = () => {}
18
- export let onKeyUp: SvelteInputProps['onKeyUp'] = () => {}
19
- export let onInput: SvelteInputProps['onInput'] = () => {}
20
- export let onClick: SvelteInputProps['onClick'] = () => {}
10
+ let {
11
+ type = 'text',
12
+ theme,
13
+ label,
14
+ value = $bindable(''),
15
+ subText,
16
+ className,
17
+ labelClassName,
18
+ onChange,
19
+ onKeyUp,
20
+ onInput,
21
+ onClick,
22
+ children,
23
+ ...rest
24
+ }: SvelteInputProps = $props()
21
25
 
22
26
  const classes = classNames([
23
27
  styles.input,
@@ -30,7 +34,7 @@
30
34
  labelClassName
31
35
  ])
32
36
 
33
- const useLabel = !!(label || subText || $$slots.default)
37
+ const useLabel = !!(label || subText || children)
34
38
  </script>
35
39
 
36
40
  <ConditionalWrapper
@@ -42,20 +46,20 @@
42
46
  <div class={styles.label}>{@html label}</div>
43
47
  {/if}
44
48
  <ConditionalWrapper
45
- condition={$$slots.default}
49
+ condition={!!children}
46
50
  element="div"
47
51
  class={styles.wrapper}
48
52
  >
49
- <slot />
53
+ {@render children?.()}
50
54
  <input
51
- class={classes}
52
55
  bind:value
53
- on:change={onChange}
54
- on:keyup={onKeyUp}
55
- on:input={onInput}
56
- on:click={onClick}
56
+ class={classes}
57
+ onchange={onChange}
58
+ onkeyup={onKeyUp}
59
+ oninput={onInput}
60
+ onclick={onClick}
57
61
  {...{ type }}
58
- {...$$restProps}
62
+ {...rest}
59
63
  />
60
64
  </ConditionalWrapper>
61
65
  {#if subText}
@@ -1,3 +1,9 @@
1
+ import type { Snippet } from 'svelte'
2
+
3
+ export type InputTarget = {
4
+ currentTarget: HTMLInputElement
5
+ }
6
+
1
7
  export type InputProps = {
2
8
  type?: 'text'
3
9
  | 'email'
@@ -40,10 +46,11 @@ export type InputProps = {
40
46
  }
41
47
 
42
48
  export type SvelteInputProps = {
43
- onChange?: (event: Event & { currentTarget: HTMLInputElement }) => void
44
- onKeyUp?: (event: KeyboardEvent & { currentTarget: HTMLInputElement }) => void
49
+ onChange?: (event: Event & InputTarget) => void
50
+ onKeyUp?: (event: KeyboardEvent & InputTarget) => void
45
51
  onInput?: (event: any) => void
46
- onClick?: (event: MouseEvent & { currentTarget: HTMLInputElement }) => void
52
+ onClick?: (event: MouseEvent & InputTarget) => void
53
+ children?: Snippet
47
54
  } & InputProps
48
55
 
49
56
  export type ReactInputProps = {
@@ -1,13 +1,16 @@
1
1
  <script lang="ts">
2
- import type { KbdProps } from './kbd'
2
+ import type { SvelteKbdProps } from './kbd'
3
3
  import { keyMap } from './keyMap'
4
4
 
5
5
  import { classNames } from '../../utils/classNames'
6
6
 
7
7
  import styles from './kbd.module.scss'
8
8
 
9
- export let keys: KbdProps['keys'] = []
10
- export let className: KbdProps['className'] = ''
9
+ const {
10
+ keys,
11
+ className,
12
+ children
13
+ }: SvelteKbdProps = $props()
11
14
 
12
15
  const classes = classNames([
13
16
  styles.kbd,
@@ -15,4 +18,4 @@
15
18
  ])
16
19
  </script>
17
20
 
18
- <kbd class={classes}>{keys?.map(key => keyMap[key]).join('')}<slot /></kbd>
21
+ <kbd class={classes}>{keys?.map(key => keyMap[key]).join('')}{@render children?.()}</kbd>
@@ -1,3 +1,5 @@
1
+ import type { Snippet } from 'svelte'
2
+
1
3
  export type KbdProps = {
2
4
  keys?: ('cmd'
3
5
  | 'shift'
@@ -21,6 +23,10 @@ export type KbdProps = {
21
23
  className?: string
22
24
  }
23
25
 
26
+ export type SvelteKbdProps = {
27
+ children?: Snippet
28
+ } & KbdProps
29
+
24
30
  export type ReactKbdProps = {
25
31
  children?: React.ReactNode
26
32
  } & KbdProps
@@ -93,77 +93,82 @@ const wrapperClasses = [
93
93
  <script>
94
94
  import { dispatch } from '../../utils/event'
95
95
 
96
- const lists = document.querySelectorAll('[data-id="w-list"]')
97
- const searchInputs = document.querySelectorAll('[data-id="w-list-search"]')
98
-
99
- const handleClick = (list: Element, items: Element[], event: Event) => {
100
- const target = event.target as HTMLElement
101
-
102
- if (target.dataset.value && !target.dataset.disabled) {
103
- dispatch('listOnSelect', {
104
- value: target.dataset.value,
105
- name: target.dataset.name,
106
- list
107
- })
96
+ const addEventListeners = () => {
97
+ const lists = document.querySelectorAll('[data-id="w-list"]')
98
+ const searchInputs = document.querySelectorAll('[data-id="w-list-search"]')
99
+
100
+ const handleClick = (list: Element, items: Element[], event: Event) => {
101
+ const target = event.target as HTMLElement
102
+
103
+ if (target.dataset.value && !target.dataset.disabled) {
104
+ dispatch('listOnSelect', {
105
+ value: target.dataset.value,
106
+ name: target.dataset.name,
107
+ list
108
+ })
108
109
 
109
- items.forEach(item => item.removeAttribute('data-selected'))
110
- target.dataset.selected = 'true'
110
+ items.forEach(item => item.removeAttribute('data-selected'))
111
+ target.dataset.selected = 'true'
112
+ }
111
113
  }
112
- }
113
114
 
114
- Array.from(lists).forEach(list => {
115
- const items = Array.from(list.children)
115
+ Array.from(lists).forEach(list => {
116
+ const items = Array.from(list.children)
116
117
 
117
- list.addEventListener('click', event => handleClick(list, items, event))
118
- list.addEventListener('keyup', event => {
119
- if ((event as KeyboardEvent).key === 'Enter') {
120
- handleClick(list, items, event)
121
- }
122
- })
123
- })
124
-
125
- Array.from(searchInputs).forEach(element => {
126
- element.addEventListener('input', event => {
127
- const target = event.target as HTMLInputElement
128
- const ul = target.closest('[data-id="w-list-wrapper"]')
129
- ?.querySelector('ul') as HTMLUListElement
130
-
131
- const noResults = ul.querySelector('[data-id="w-no-results"]')
132
- const items = Array.from(ul.children)
133
- const value = target.value.toLowerCase()
134
-
135
- items.forEach(item => {
136
- const li = item as HTMLLIElement
137
- const hideItem = (!li.dataset.value?.toLowerCase().includes(value)
138
- && !li.innerText.toLowerCase().includes(value))
139
- || li.dataset.id === 'w-list-title'
140
- || li.dataset.id === 'w-no-results'
141
-
142
- if (hideItem) {
143
- li.dataset.hidden = 'true'
144
- } else if (li.dataset.id !== 'w-no-results') {
145
- li.removeAttribute('data-hidden')
118
+ list.addEventListener('click', event => handleClick(list, items, event))
119
+ list.addEventListener('keyup', event => {
120
+ if ((event as KeyboardEvent).key === 'Enter') {
121
+ handleClick(list, items, event)
146
122
  }
147
123
  })
124
+ })
148
125
 
149
- const numberOfResults = items.filter(item => {
150
- const li = item as HTMLLIElement
151
- return li.dataset.name && !li.dataset.hidden
152
- }).length
126
+ Array.from(searchInputs).forEach(element => {
127
+ element.addEventListener('input', event => {
128
+ const target = event.target as HTMLInputElement
129
+ const ul = target.closest('[data-id="w-list-wrapper"]')
130
+ ?.querySelector('ul') as HTMLUListElement
153
131
 
154
- if (!numberOfResults) {
155
- noResults?.removeAttribute('data-hidden')
156
- }
132
+ const noResults = ul.querySelector('[data-id="w-no-results"]')
133
+ const items = Array.from(ul.children)
134
+ const value = target.value.toLowerCase()
157
135
 
158
- if (!value) {
159
136
  items.forEach(item => {
160
137
  const li = item as HTMLLIElement
161
-
162
- li.dataset.id === 'w-no-results'
163
- ? li.dataset.hidden = 'true'
164
- : li.removeAttribute('data-hidden')
138
+ const hideItem = (!li.dataset.value?.toLowerCase().includes(value)
139
+ && !li.innerText.toLowerCase().includes(value))
140
+ || li.dataset.id === 'w-list-title'
141
+ || li.dataset.id === 'w-no-results'
142
+
143
+ if (hideItem) {
144
+ li.dataset.hidden = 'true'
145
+ } else if (li.dataset.id !== 'w-no-results') {
146
+ li.removeAttribute('data-hidden')
147
+ }
165
148
  })
166
- }
149
+
150
+ const numberOfResults = items.filter(item => {
151
+ const li = item as HTMLLIElement
152
+ return li.dataset.name && !li.dataset.hidden
153
+ }).length
154
+
155
+ if (!numberOfResults) {
156
+ noResults?.removeAttribute('data-hidden')
157
+ }
158
+
159
+ if (!value) {
160
+ items.forEach(item => {
161
+ const li = item as HTMLLIElement
162
+
163
+ li.dataset.id === 'w-no-results'
164
+ ? li.dataset.hidden = 'true'
165
+ : li.removeAttribute('data-hidden')
166
+ })
167
+ }
168
+ })
167
169
  })
168
- })
170
+ }
171
+
172
+ document.addEventListener('astro:after-swap', addEventListeners)
173
+ addEventListeners()
169
174
  </script>