webcoreui 1.1.0 → 1.2.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.
- package/README.md +9 -1
- package/astro.d.ts +5 -0
- package/astro.js +2 -0
- package/components/BottomNavigation/BottomNavigation.astro +1 -3
- package/components/Breadcrumb/Breadcrumb.astro +1 -3
- package/components/Carousel/Carousel.astro +79 -9
- package/components/Carousel/Carousel.svelte +40 -9
- package/components/Carousel/Carousel.tsx +46 -11
- package/components/Carousel/carousel.ts +3 -1
- package/components/Copy/Copy.astro +3 -5
- package/components/Copy/Copy.svelte +1 -1
- package/components/Copy/Copy.tsx +1 -1
- package/components/Input/input.ts +62 -62
- package/components/Modal/Modal.astro +75 -75
- package/components/Modal/modal.ts +25 -25
- package/components/OTPInput/OTPInput.astro +194 -96
- package/components/OTPInput/OTPInput.svelte +141 -26
- package/components/OTPInput/OTPInput.tsx +140 -36
- package/components/OTPInput/otpinput.module.scss +59 -85
- package/components/Pagination/Pagination.astro +3 -3
- package/components/Pagination/Pagination.svelte +4 -4
- package/components/Pagination/pagination.module.scss +3 -3
- package/components/RangeSlider/RangeSlider.astro +270 -0
- package/components/RangeSlider/RangeSlider.svelte +188 -0
- package/components/RangeSlider/RangeSlider.tsx +205 -0
- package/components/RangeSlider/rangeslider.module.scss +143 -0
- package/components/RangeSlider/rangeslider.ts +37 -0
- package/components/Sidebar/Sidebar.astro +1 -3
- package/components/Stepper/Stepper.astro +1 -3
- package/index.d.ts +23 -4
- package/index.js +2 -0
- package/package.json +109 -103
- package/react.d.ts +5 -0
- package/react.js +2 -0
- package/scss/global/breakpoints.scss +15 -0
- package/scss/setup.scss +7 -1
- package/svelte.d.ts +5 -0
- package/svelte.js +2 -0
- package/utils/DOMUtils.ts +27 -2
- package/utils/bodyFreeze.ts +1 -1
- package/utils/context.ts +2 -2
- package/utils/getBreakpoint.ts +17 -0
- package/utils/isOneOf.ts +5 -0
- package/utils/modal.ts +54 -55
- package/utils/toast.ts +1 -1
package/utils/DOMUtils.ts
CHANGED
|
@@ -8,8 +8,8 @@ export const on = (
|
|
|
8
8
|
callback: any,
|
|
9
9
|
all?: boolean
|
|
10
10
|
) => {
|
|
11
|
-
if (all) {
|
|
12
|
-
const elements = document.querySelectorAll(selector
|
|
11
|
+
if (all && typeof selector === 'string') {
|
|
12
|
+
const elements = document.querySelectorAll(selector)
|
|
13
13
|
|
|
14
14
|
elements?.forEach(element => {
|
|
15
15
|
element.addEventListener(event, callback)
|
|
@@ -26,3 +26,28 @@ export const on = (
|
|
|
26
26
|
|
|
27
27
|
selector?.addEventListener(event, callback)
|
|
28
28
|
}
|
|
29
|
+
|
|
30
|
+
export const off = (
|
|
31
|
+
selector: string | HTMLElement | Document,
|
|
32
|
+
event: string,
|
|
33
|
+
fn: any,
|
|
34
|
+
all?: boolean
|
|
35
|
+
) => {
|
|
36
|
+
if (all && typeof selector === 'string') {
|
|
37
|
+
const elements = document.querySelectorAll(selector)
|
|
38
|
+
|
|
39
|
+
elements?.forEach(element => {
|
|
40
|
+
element.removeEventListener(event, fn)
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
return
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (typeof selector === 'string') {
|
|
47
|
+
(get(selector) as HTMLElement)?.removeEventListener(event, fn)
|
|
48
|
+
|
|
49
|
+
return
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
selector?.removeEventListener(event, fn)
|
|
53
|
+
}
|
package/utils/bodyFreeze.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export const bodyFreeze = (freeze = true) => {
|
|
2
|
-
const scrollbarWidth = window.innerWidth - document.
|
|
2
|
+
const scrollbarWidth = window.innerWidth - document.documentElement.clientWidth
|
|
3
3
|
|
|
4
4
|
if (freeze) {
|
|
5
5
|
document.body.style.paddingRight = `${scrollbarWidth}px`
|
package/utils/context.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
export const closeContext = (ctx: string | HTMLElement) => {
|
|
2
2
|
const element = typeof ctx === 'string'
|
|
3
|
-
? document.querySelector(ctx)
|
|
3
|
+
? document.querySelector(ctx)
|
|
4
4
|
: ctx
|
|
5
5
|
|
|
6
|
-
const parent = element?.parentElement
|
|
6
|
+
const parent = element?.parentElement
|
|
7
7
|
|
|
8
8
|
if (!parent) {
|
|
9
9
|
// eslint-disable-next-line no-console
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { isOneOf } from './isOneOf'
|
|
2
|
+
|
|
3
|
+
const breakpoints = ['xs', 'sm', 'md', 'lg'] as const
|
|
4
|
+
|
|
5
|
+
export type Breakpoint = typeof breakpoints[number]
|
|
6
|
+
|
|
7
|
+
export const getBreakpoint = (): Breakpoint => {
|
|
8
|
+
const value = getComputedStyle(document.documentElement)
|
|
9
|
+
.getPropertyValue('--w-breakpoint')
|
|
10
|
+
.trim()
|
|
11
|
+
|
|
12
|
+
if (isOneOf<Breakpoint>(breakpoints)(value)) {
|
|
13
|
+
return value
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
throw new Error(`Unexpected breakpoint: ${value}`)
|
|
17
|
+
}
|
package/utils/isOneOf.ts
ADDED
package/utils/modal.ts
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
import { bodyFreeze } from './bodyFreeze'
|
|
2
2
|
|
|
3
|
+
export type ModalInstance = {
|
|
4
|
+
open: (freeze?: boolean) => void
|
|
5
|
+
close: () => void
|
|
6
|
+
replaceWith: (modal: ModalInstance) => void
|
|
7
|
+
remove: () => void
|
|
8
|
+
}
|
|
9
|
+
|
|
3
10
|
export type ModalCallback = {
|
|
4
11
|
trigger: Element | null
|
|
5
12
|
modal: HTMLElement
|
|
@@ -12,7 +19,7 @@ export type Modal = {
|
|
|
12
19
|
onClose?: (args: ModalCallback) => unknown
|
|
13
20
|
}
|
|
14
21
|
|
|
15
|
-
export const modal = (config: Modal | string) => {
|
|
22
|
+
export const modal = (config: Modal | string): ModalInstance | undefined => {
|
|
16
23
|
const {
|
|
17
24
|
trigger,
|
|
18
25
|
modal,
|
|
@@ -23,44 +30,51 @@ export const modal = (config: Modal | string) => {
|
|
|
23
30
|
const modalSelector = typeof config === 'string' ? config : modal
|
|
24
31
|
|
|
25
32
|
const triggerDOM = document.querySelector(trigger)
|
|
26
|
-
const modalDOM = document.querySelector(modalSelector)
|
|
33
|
+
const modalDOM = document.querySelector(modalSelector)
|
|
27
34
|
|
|
28
|
-
if (modalDOM) {
|
|
35
|
+
if (modalDOM instanceof HTMLElement) {
|
|
29
36
|
const closeOptions = modalDOM.dataset.close?.split(',')
|
|
30
37
|
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
|
|
38
|
+
const handleOpen = (_e?: Event, freeze = true) => {
|
|
39
|
+
modalDOM.dataset.show = 'true'
|
|
40
|
+
|
|
41
|
+
if (freeze) {
|
|
42
|
+
bodyFreeze()
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
onOpen?.({
|
|
46
|
+
trigger: triggerDOM,
|
|
47
|
+
modal: modalDOM
|
|
48
|
+
})
|
|
49
|
+
}
|
|
34
50
|
|
|
35
|
-
|
|
36
|
-
|
|
51
|
+
const handleClose = (_e?: Event, unfreeze = true) => {
|
|
52
|
+
modalDOM.dataset.show = ''
|
|
37
53
|
|
|
38
|
-
|
|
54
|
+
if (unfreeze) {
|
|
55
|
+
bodyFreeze(false)
|
|
56
|
+
}
|
|
39
57
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
58
|
+
onClose?.({
|
|
59
|
+
trigger: triggerDOM,
|
|
60
|
+
modal: modalDOM
|
|
61
|
+
})
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const closeHandlers = {
|
|
65
|
+
icon() {
|
|
66
|
+
const close = modalDOM.querySelector('[data-id="close"]')
|
|
45
67
|
|
|
46
68
|
return {
|
|
47
|
-
add: () => close?.addEventListener('click',
|
|
48
|
-
remove: () => close?.removeEventListener('click',
|
|
69
|
+
add: () => close?.addEventListener('click', handleClose),
|
|
70
|
+
remove: () => close?.removeEventListener('click', handleClose)
|
|
49
71
|
}
|
|
50
72
|
},
|
|
51
73
|
|
|
52
74
|
esc() {
|
|
53
75
|
const listener = (event: KeyboardEvent) => {
|
|
54
76
|
if (modalDOM.dataset.show && event.key === 'Escape') {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
bodyFreeze(false)
|
|
58
|
-
|
|
59
|
-
onClose?.({
|
|
60
|
-
trigger: triggerDOM,
|
|
61
|
-
modal: modalDOM
|
|
62
|
-
})
|
|
63
|
-
|
|
77
|
+
handleClose()
|
|
64
78
|
}
|
|
65
79
|
}
|
|
66
80
|
|
|
@@ -73,50 +87,35 @@ export const modal = (config: Modal | string) => {
|
|
|
73
87
|
overlay() {
|
|
74
88
|
const close = modalDOM.nextElementSibling
|
|
75
89
|
|
|
76
|
-
const listener = () => {
|
|
77
|
-
modalDOM.dataset.show = ''
|
|
78
|
-
|
|
79
|
-
bodyFreeze(false)
|
|
80
|
-
|
|
81
|
-
onClose?.({
|
|
82
|
-
trigger: triggerDOM,
|
|
83
|
-
modal: modalDOM
|
|
84
|
-
})
|
|
85
|
-
}
|
|
86
|
-
|
|
87
90
|
return {
|
|
88
|
-
add: () => close?.addEventListener('click',
|
|
89
|
-
remove: () => close?.removeEventListener('click',
|
|
91
|
+
add: () => close?.addEventListener('click', handleClose),
|
|
92
|
+
remove: () => close?.removeEventListener('click', handleClose)
|
|
90
93
|
}
|
|
91
94
|
}
|
|
92
95
|
}
|
|
93
96
|
|
|
94
|
-
const handleOpen = () => {
|
|
95
|
-
modalDOM.dataset.show = 'true'
|
|
96
|
-
|
|
97
|
-
bodyFreeze()
|
|
98
|
-
|
|
99
|
-
onOpen?.({
|
|
100
|
-
trigger: triggerDOM,
|
|
101
|
-
modal: modalDOM
|
|
102
|
-
})
|
|
103
|
-
}
|
|
104
|
-
|
|
105
97
|
triggerDOM?.addEventListener('click', handleOpen)
|
|
106
98
|
|
|
107
99
|
closeOptions?.forEach(option => {
|
|
108
|
-
|
|
100
|
+
closeHandlers[option as keyof typeof closeHandlers]().add()
|
|
109
101
|
})
|
|
110
102
|
|
|
111
103
|
return {
|
|
112
|
-
open() {
|
|
113
|
-
handleOpen()
|
|
104
|
+
open(freeze?: boolean) {
|
|
105
|
+
handleOpen(undefined, freeze)
|
|
106
|
+
},
|
|
107
|
+
close() {
|
|
108
|
+
handleClose()
|
|
109
|
+
},
|
|
110
|
+
replaceWith(modal: ModalInstance) {
|
|
111
|
+
modal.open(false)
|
|
112
|
+
handleClose(undefined, false)
|
|
114
113
|
},
|
|
115
114
|
remove() {
|
|
116
115
|
triggerDOM?.removeEventListener('click', handleOpen)
|
|
117
116
|
|
|
118
117
|
closeOptions?.forEach(option => {
|
|
119
|
-
|
|
118
|
+
closeHandlers[option as keyof typeof closeHandlers]().remove()
|
|
120
119
|
})
|
|
121
120
|
}
|
|
122
121
|
}
|
|
@@ -124,9 +123,9 @@ export const modal = (config: Modal | string) => {
|
|
|
124
123
|
}
|
|
125
124
|
|
|
126
125
|
export const closeModal = (modal: string) => {
|
|
127
|
-
const modalDOM = document.querySelector(modal)
|
|
126
|
+
const modalDOM = document.querySelector(modal)
|
|
128
127
|
|
|
129
|
-
if (modalDOM) {
|
|
128
|
+
if (modalDOM instanceof HTMLElement) {
|
|
130
129
|
modalDOM.dataset.show = ''
|
|
131
130
|
|
|
132
131
|
bodyFreeze(false)
|
package/utils/toast.ts
CHANGED
|
@@ -23,7 +23,7 @@ export const toast = (config: Toast | string) => {
|
|
|
23
23
|
title,
|
|
24
24
|
content,
|
|
25
25
|
position
|
|
26
|
-
} = (typeof config === 'string' ? {} : config)
|
|
26
|
+
} = (typeof config === 'string' ? {} : config)
|
|
27
27
|
|
|
28
28
|
const htmlElement = document.querySelector(element) as HTMLElement
|
|
29
29
|
|