webcoreui 0.6.0 → 0.7.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 (63) hide show
  1. package/README.md +30 -1
  2. package/astro.d.ts +15 -0
  3. package/astro.js +10 -0
  4. package/components/Accordion/Accordion.astro +32 -20
  5. package/components/Accordion/Accordion.svelte +22 -4
  6. package/components/Accordion/Accordion.tsx +29 -7
  7. package/components/Accordion/accordion.module.scss +12 -0
  8. package/components/Accordion/accordion.ts +4 -0
  9. package/components/AspectRatio/AspectRatio.astro +21 -0
  10. package/components/AspectRatio/AspectRatio.svelte +19 -0
  11. package/components/AspectRatio/AspectRatio.tsx +28 -0
  12. package/components/AspectRatio/aspect-ratio.module.scss +10 -0
  13. package/components/AspectRatio/aspectratio.ts +8 -0
  14. package/components/Banner/Banner.astro +56 -0
  15. package/components/Banner/Banner.svelte +47 -0
  16. package/components/Banner/Banner.tsx +54 -0
  17. package/components/Banner/banner.module.scss +57 -0
  18. package/components/Banner/banner.ts +12 -0
  19. package/components/Button/button.ts +1 -1
  20. package/components/Carousel/Carousel.astro +16 -7
  21. package/components/Carousel/Carousel.svelte +15 -5
  22. package/components/Carousel/Carousel.tsx +15 -5
  23. package/components/Carousel/carousel.module.scss +4 -1
  24. package/components/Carousel/carousel.ts +1 -1
  25. package/components/DataTable/DataTable.astro +2 -2
  26. package/components/DataTable/DataTable.tsx +287 -287
  27. package/components/Icon/map.ts +2 -0
  28. package/components/Kbd/Kbd.astro +20 -0
  29. package/components/Kbd/Kbd.svelte +18 -0
  30. package/components/Kbd/Kbd.tsx +27 -0
  31. package/components/Kbd/kbd.module.scss +8 -0
  32. package/components/Kbd/kbd.ts +26 -0
  33. package/components/Kbd/keyMap.ts +21 -0
  34. package/components/Pagination/Pagination.astro +2 -0
  35. package/components/Pagination/Pagination.svelte +6 -3
  36. package/components/Pagination/Pagination.tsx +5 -3
  37. package/components/Pagination/pagination.ts +1 -0
  38. package/components/Spoiler/Spoiler.astro +50 -0
  39. package/components/Spoiler/Spoiler.svelte +45 -0
  40. package/components/Spoiler/Spoiler.tsx +50 -0
  41. package/components/Spoiler/spoiler.module.scss +40 -0
  42. package/components/Spoiler/spoiler.ts +11 -0
  43. package/components/Stepper/Stepper.astro +61 -0
  44. package/components/Stepper/Stepper.svelte +59 -0
  45. package/components/Stepper/Stepper.tsx +60 -0
  46. package/components/Stepper/stepper.module.scss +102 -0
  47. package/components/Stepper/stepper.ts +17 -0
  48. package/icons/close.svg +1 -1
  49. package/icons/plus.svg +3 -0
  50. package/icons.d.ts +1 -0
  51. package/icons.js +1 -0
  52. package/index.d.ts +8 -0
  53. package/index.js +1 -0
  54. package/package.json +5 -4
  55. package/react.d.ts +15 -0
  56. package/react.js +10 -0
  57. package/scss/config/typography.scss +3 -1
  58. package/scss/global/utility.scss +5 -1
  59. package/scss/resets.scss +5 -0
  60. package/svelte.d.ts +15 -0
  61. package/svelte.js +10 -0
  62. package/utils/DOMUtils.ts +28 -0
  63. package/scss/global/elements.scss +0 -31
@@ -0,0 +1,54 @@
1
+ import React, { useState } from 'react'
2
+ import type { ReactBannerProps } from './banner'
3
+
4
+ import Button from '../Button/Button.tsx'
5
+
6
+ import { classNames } from '../../utils/classNames'
7
+
8
+ import closeIcon from '../../icons/close.svg?raw'
9
+
10
+ import styles from './banner.module.scss'
11
+
12
+ const Banner = ({
13
+ top,
14
+ bottom,
15
+ closeable,
16
+ padded,
17
+ sticky = true,
18
+ className,
19
+ children
20
+ }: ReactBannerProps) => {
21
+ const [visible, setVisible] = useState(true)
22
+
23
+ const classes = classNames([
24
+ styles.banner,
25
+ bottom && styles.bottom,
26
+ padded && styles.padded,
27
+ !sticky && styles.relative,
28
+ className
29
+ ])
30
+
31
+ const style = top
32
+ ? { '--w-banner-top': `${top}px` } as React.CSSProperties
33
+ : undefined
34
+
35
+ if (!visible) {
36
+ return null
37
+ }
38
+
39
+ return (
40
+ <div className={classes} style={style}>
41
+ {children}
42
+ {closeable && (
43
+ <Button
44
+ theme="flat"
45
+ className={styles.close}
46
+ dangerouslySetInnerHTML={{ __html: closeIcon }}
47
+ onClick={() => setVisible(false)}
48
+ />
49
+ )}
50
+ </div>
51
+ )
52
+ }
53
+
54
+ export default Banner
@@ -0,0 +1,57 @@
1
+ @import '../../scss/config.scss';
2
+
3
+ body {
4
+ --w-banner-top: 0;
5
+ }
6
+
7
+ .banner {
8
+ @include background(primary-60);
9
+ @include spacing(p-default);
10
+ @include position(sticky);
11
+ @include layer(top);
12
+ @include typography(center);
13
+
14
+ top: var(--w-banner-top);
15
+
16
+ &.padded {
17
+ @include border-radius();
18
+ @include position(l20px);
19
+
20
+ width: calc(100% - 40px);
21
+ top: calc(var(--w-banner-top) + 20px);
22
+
23
+ &.bottom {
24
+ @include position(l20px, b20px);
25
+ }
26
+ }
27
+
28
+ &.relative {
29
+ @include position(relative);
30
+ top: auto;
31
+ }
32
+
33
+ &.bottom {
34
+ @include position(fixed, b0, l0, r0);
35
+
36
+ top: auto;
37
+ }
38
+
39
+ &.closeable {
40
+ @include spacing(pl-default, pt-default, pb-default, pr-3xl);
41
+ }
42
+
43
+ .close {
44
+ @include position(absolute, v-center, r10px);
45
+ @include spacing(p-xs);
46
+
47
+ svg {
48
+ @include size(10px);
49
+ }
50
+ }
51
+ }
52
+
53
+ @include media(xs) {
54
+ .banner.closeable {
55
+ @include spacing(p-default);
56
+ }
57
+ }
@@ -0,0 +1,12 @@
1
+ export type BannerProps = {
2
+ top?: number
3
+ bottom?: boolean
4
+ closeable?: boolean
5
+ padded?: boolean
6
+ sticky?: boolean
7
+ className?: string
8
+ }
9
+
10
+ export type ReactBannerProps = {
11
+ children: React.ReactNode
12
+ } & BannerProps
@@ -15,7 +15,7 @@ export type ButtonProps = {
15
15
  | '_parent'
16
16
  | '_top'
17
17
  | '_unfencedTop'
18
- | null
18
+ | ''
19
19
  | undefined
20
20
  href?: string
21
21
  className?: string
@@ -13,7 +13,7 @@ interface Props extends CarouselProps {}
13
13
 
14
14
  const {
15
15
  items,
16
- visibleItems = 1,
16
+ itemsPerSlide = 1,
17
17
  subText,
18
18
  scrollSnap = true,
19
19
  progress,
@@ -38,6 +38,7 @@ const containerClasses = [
38
38
  const wrapperClasses = [
39
39
  styles.wrapper,
40
40
  effect && styles[effect],
41
+ itemsPerSlide > 1 && styles['no-snap'],
41
42
  wrapperClassName
42
43
  ]
43
44
 
@@ -51,10 +52,10 @@ const paginationClasses = classNames([
51
52
  !subText && paginationClassName
52
53
  ])
53
54
 
54
- const totalPages = Math.ceil(items / visibleItems)
55
+ const totalPages = Math.ceil(items / itemsPerSlide)
55
56
  const subTextValue = subText?.match(/\{0\}|\{1\}/g) ? subText : undefined
56
- const style = visibleItems > 1
57
- ? `--w-slide-width: ${100 / visibleItems}%;`
57
+ const style = itemsPerSlide > 1
58
+ ? `--w-slide-width: calc(${100 / itemsPerSlide}% - 5px);`
58
59
  : null
59
60
  ---
60
61
 
@@ -67,7 +68,7 @@ const style = visibleItems > 1
67
68
  <ul
68
69
  class:list={wrapperClasses}
69
70
  style={style}
70
- data-visible-items={visibleItems > 1 ? visibleItems : null}
71
+ data-visible-items={itemsPerSlide > 1 ? itemsPerSlide : null}
71
72
  >
72
73
  <slot />
73
74
  </ul>
@@ -159,8 +160,16 @@ const style = visibleItems > 1
159
160
 
160
161
  const progress = target.closest('section').querySelector('.w-carousel-progress')
161
162
  const progressValue = (100 / (Number(target.dataset.totalPages) - 1))
162
- const visibleItems = Number(carousel.dataset.visibleItems) || 0
163
- const pageIndex = (event.page + visibleItems) - 1
163
+ const itemsPerSlide = Number(carousel.dataset.visibleItems) || 1
164
+ const totalItems = carousel.children.length
165
+ const indexes = Array.from({ length: Math.ceil(totalItems / itemsPerSlide) }, (_, i) => {
166
+ return Array.from({ length: itemsPerSlide }, (_, j) => (i * itemsPerSlide) + j)
167
+ .filter(index => index < totalItems)
168
+ })
169
+
170
+ const pageIndex = event.direction === 'prev'
171
+ ? indexes[event.page - 1][0]
172
+ : indexes[event.page - 1][indexes[event.page - 1].length - 1]
164
173
 
165
174
  const liElement = carousel.children[pageIndex]
166
175
  const subText = event.target.nextElementSibling
@@ -14,7 +14,7 @@
14
14
  import type { PaginationEventType } from '../Pagination/pagination'
15
15
 
16
16
  export let items: SvelteCarouselProps['items'] = 0
17
- export let visibleItems: SvelteCarouselProps['visibleItems'] = 1
17
+ export let itemsPerSlide: SvelteCarouselProps['itemsPerSlide'] = 1
18
18
  export let subText: SvelteCarouselProps['subText'] = ''
19
19
  export let scrollSnap: SvelteCarouselProps['scrollSnap'] = true
20
20
  export let progress: SvelteCarouselProps['progress'] = false
@@ -46,6 +46,7 @@
46
46
  const wrapperClasses = classNames([
47
47
  styles.wrapper,
48
48
  effect && styles[effect],
49
+ itemsPerSlide! > 1 && styles['no-snap'],
49
50
  wrapperClassName
50
51
  ])
51
52
 
@@ -59,10 +60,10 @@
59
60
  !subText && paginationClassName
60
61
  ])
61
62
 
62
- const totalPages = Math.ceil(items / visibleItems!)
63
+ const totalPages = Math.ceil(items / itemsPerSlide!)
63
64
  const subTextValue = subText?.match(/\{0\}|\{1\}/g) ? subText : undefined
64
- const style = visibleItems! > 1
65
- ? `--w-slide-width: ${100 / visibleItems!}%;`
65
+ const style = itemsPerSlide! > 1
66
+ ? `--w-slide-width: calc(${100 / itemsPerSlide!}% - 5px);`
66
67
  : null
67
68
 
68
69
  const updateValues = () => {
@@ -100,7 +101,16 @@
100
101
  }, debounce)
101
102
 
102
103
  const paginate = (event: PaginationEventType) => {
103
- const liElement = carouselItems[event.page - 1] as HTMLLIElement
104
+ const indexes = Array.from({ length: Math.ceil(items / itemsPerSlide!) }, (_, i) => {
105
+ return Array.from({ length: itemsPerSlide! }, (_, j) => (i * itemsPerSlide!) + j)
106
+ .filter(index => index < items)
107
+ })
108
+
109
+ const pageIndex = event.direction === 'prev'
110
+ ? indexes[event.page - 1][0]
111
+ : indexes[event.page - 1][indexes[event.page - 1].length - 1]
112
+
113
+ const liElement = carouselItems[pageIndex] as HTMLLIElement
104
114
 
105
115
  liElement.scrollIntoView({ behavior: 'smooth', block: 'nearest' })
106
116
 
@@ -14,7 +14,7 @@ import type { PaginationEventType } from '../Pagination/pagination'
14
14
 
15
15
  const Carousel = ({
16
16
  items,
17
- visibleItems = 1,
17
+ itemsPerSlide = 1,
18
18
  subText,
19
19
  scrollSnap = true,
20
20
  progress,
@@ -49,6 +49,7 @@ const Carousel = ({
49
49
  const wrapperClasses = classNames([
50
50
  styles.wrapper,
51
51
  effect && styles[effect],
52
+ itemsPerSlide! > 1 && styles['no-snap'],
52
53
  wrapperClassName
53
54
  ])
54
55
 
@@ -62,10 +63,10 @@ const Carousel = ({
62
63
  !subText && paginationClassName
63
64
  ])
64
65
 
65
- const totalPages = Math.ceil(items / visibleItems!)
66
+ const totalPages = Math.ceil(items / itemsPerSlide!)
66
67
  const subTextValue = subText?.match(/\{0\}|\{1\}/g) ? subText : undefined
67
- const style = visibleItems > 1
68
- ? { '--w-slide-width': `${100 / visibleItems}%;` } as React.CSSProperties
68
+ const style = itemsPerSlide > 1
69
+ ? { '--w-slide-width': `calc(${100 / itemsPerSlide!}% - 5px);` } as React.CSSProperties
69
70
  : undefined
70
71
 
71
72
  const updateValues = (page: number) => {
@@ -105,7 +106,16 @@ const Carousel = ({
105
106
  }, debounce)
106
107
 
107
108
  const paginate = (event: PaginationEventType) => {
108
- const liElement = carouselItems.current[event.page - 1]
109
+ const indexes = Array.from({ length: Math.ceil(items / itemsPerSlide!) }, (_, i) => {
110
+ return Array.from({ length: itemsPerSlide! }, (_, j) => (i * itemsPerSlide!) + j)
111
+ .filter(index => index < items)
112
+ })
113
+
114
+ const pageIndex = event.direction === 'prev'
115
+ ? indexes[event.page - 1][0]
116
+ : indexes[event.page - 1][indexes[event.page - 1].length - 1]
117
+
118
+ const liElement = carouselItems.current[pageIndex]
109
119
 
110
120
  liElement.scrollIntoView({ behavior: 'smooth', block: 'nearest' })
111
121
 
@@ -34,12 +34,15 @@ body {
34
34
  filter: saturate(0);
35
35
  }
36
36
 
37
+ &:not(.no-snap) li {
38
+ scroll-snap-align: center;
39
+ }
40
+
37
41
  li {
38
42
  @include transition();
39
43
  @include spacing(m0);
40
44
  @include layout(flex, h-center);
41
45
 
42
- scroll-snap-align: center;
43
46
  min-width: var(--w-slide-width);
44
47
  }
45
48
  }
@@ -2,7 +2,7 @@ import type { PaginationProps } from '../Pagination/pagination'
2
2
 
3
3
  export type CarouselProps = {
4
4
  items: number
5
- visibleItems?: number
5
+ itemsPerSlide?: number
6
6
  subText?: string
7
7
  autoplay?: boolean
8
8
  vertical?: boolean
@@ -72,8 +72,8 @@ const columnToggleItems = [{
72
72
  }]
73
73
 
74
74
  const columnFilterItems = headings?.filter(heading => typeof heading !== 'string')
75
- .filter(heading => heading.filterable)
76
- .map(heading => heading.name)
75
+ .filter(heading => (heading as HeadingObject).filterable)
76
+ .map(heading => (heading as HeadingObject).name)
77
77
  .map(heading => getColumnName(heading))
78
78
 
79
79
  const hasPagination = data?.length && itemsPerPage