winduum 3.0.0-next.6 → 3.0.0-next.8

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "winduum",
3
- "version": "3.0.0-next.6",
3
+ "version": "3.0.0-next.8",
4
4
  "type": "module",
5
5
  "types": "types/index.d.ts",
6
6
  "main": "plugin/index.cjs",
@@ -82,7 +82,6 @@
82
82
  "default": "./src/components/details/index.js"
83
83
  },
84
84
  "./src/components/dialog": {
85
- "types": "./src/components/dialog/index.d.ts",
86
85
  "default": "./src/components/dialog/index.js"
87
86
  },
88
87
  "./src/components/drawer": {
@@ -1,40 +1,19 @@
1
- export interface ObserveCarouselOptions {
2
- visibleAttribute?: string
3
- observerOptions?: {
4
- rootMargin?: string
5
- threshold?: number | number[]
6
- }
7
- }
8
-
9
- export interface PaginationCarouselOptions {
10
- element?: HTMLElement | Element
11
- itemContent?: string
12
- activeAttribute?: string
13
- }
14
-
15
- export interface ScrollCarouselOptions {
16
- observe?: ObserveCarouselOptions
17
- pagination?: PaginationCarouselOptions
18
- progressElement?: HTMLProgressElement | Element
19
- counterMinElement?: HTMLElement | Element
20
- counterMaxElement?: HTMLElement | Element
21
- }
1
+ export type CarouselPlacement = 'left' | 'right' | 'top' | 'bottom'
22
2
 
23
- export interface AutoplayCarouselOptions {
24
- delay?: number
25
- pauseElements?: HTMLElement[] | Element[]
3
+ export interface ScrollByOptions {
4
+ direction?: number
5
+ vertical?: boolean
6
+ ratio?: number
26
7
  }
27
8
 
28
- export interface DragCarouselOptions {
29
- activeAttribute?: string
9
+ export interface ToggleScrollStateOptions {
10
+ prevElement?: HTMLButtonElement | null
11
+ nextElement?: HTMLButtonElement | null
12
+ vertical?: boolean
30
13
  }
31
14
 
32
- export function scrollPrev(element: HTMLElement | Element): void
33
- export function scrollNext(element: HTMLElement | Element): void
34
- export function scrollTo(element: HTMLElement | Element, selected?: number): void
35
- export function getItemCount(element: HTMLElement | Element, scrollWidth?: number, mathFloor?: boolean): number
36
- export function observeCarousel(element: HTMLElement | Element, options?: ObserveCarouselOptions): void
37
- export function scrollCarousel(element: HTMLElement | Element, options?: ScrollCarouselOptions): void
38
- export function paginationCarousel(element: HTMLElement | Element, options?: PaginationCarouselOptions): void
39
- export function autoplayCarousel(element: HTMLElement | Element, options?: AutoplayCarouselOptions): void
40
- export function dragCarousel(element: HTMLElement | Element, options?: DragCarouselOptions): void
15
+ export function scrollBy(element: HTMLElement, options?: ScrollByOptions): void
16
+ export function toggleScrollState(element: HTMLElement, options?: ToggleScrollStateOptions): void
17
+ export function setCurrentAttribute(element: HTMLElement, index: number, attributeName?: string): void
18
+ export function setSnappedAttribute(element: HTMLElement, target: HTMLElement, markerGroupElement?: HTMLElement | null): void
19
+ export function scrollToMarker(element: HTMLElement, target: HTMLElement, markerGroupElement: HTMLElement, scrollIntoViewOptions?: ScrollIntoViewOptions): void
@@ -0,0 +1,5 @@
1
+ export interface ToggleDetailsOptions {
2
+ selector?: string
3
+ }
4
+
5
+ export function toggleDetails(element: HTMLInputElement, options?: ToggleDetailsOptions): void
@@ -0,0 +1,13 @@
1
+ /**
2
+ * @param {HTMLInputElement} element
3
+ * @param {import("./").ToggleDetailsOptions} options
4
+ * @returns void
5
+ */
6
+ export const toggleDetails = (element, options = {}) => {
7
+ const { selector } = {
8
+ selector: 'details',
9
+ ...options,
10
+ }
11
+
12
+ element?.closest(selector)?.toggleAttribute('open', element.checked)
13
+ }
@@ -1,8 +1,5 @@
1
1
  # [Details](https://winduum.dev/docs/components/details.html)
2
2
 
3
- ## Dependencies
4
- * [slide-element](https://www.npmjs.com/package/slide-element)
5
-
6
3
  ## Installation
7
4
  ```shell
8
5
  npm i winduum
@@ -10,7 +7,7 @@ npm i winduum
10
7
  Learn more how to set up Winduum [here](https://winduum.dev/docs/).
11
8
 
12
9
  ```js
13
- import { showDetails } from 'winduum/src/components/details/index.js'
10
+ import { toggleDetails } from 'winduum/src/components/details/index.js'
14
11
  ```
15
12
 
16
13
  ### Local imports
@@ -18,7 +15,7 @@ By default, imports are directly from `npm` so you can leverage updates.
18
15
  You can also copy and paste the code from this directory to your project and remap the imports to local.
19
16
 
20
17
  ```js
21
- import { showDetails } from '@/components/details/assets/index.js'
18
+ import { toggleDetails } from '@/components/details/assets/index.js'
22
19
  ```
23
20
 
24
21
  ### Docs
@@ -1,16 +1,9 @@
1
- export interface ScrollDrawerOptions {
2
- snapClass?: string
3
- opacityProperty?: string
4
- opacityRatio?: number
5
- scrollOpen?: number
6
- scrollClose?: number
7
- scrollSize?: number
8
- scrollDirection?:number
9
- }
1
+ export type DrawerPlacement = 'left' | 'right' | 'top' | 'bottom'
10
2
 
11
- export function showDrawer(element: HTMLElement | Element, distance?: number, direction?: 'left' | 'top'): void
12
- export function closeDrawer(element: HTMLElement | Element, distance?: number, direction?: 'left' | 'top'): void
13
- export function scrollInitDrawer(element: HTMLElement | Element, distance?: number, direction?: 'left' | 'top'): void
14
- export function toggleDrawerAttributes(element: HTMLDialogElement | Element, state?: 'open' | 'close', snapClass?: string): void
15
- export function scrollDrawerState(scrollState: number, scrollDirection: number): boolean
16
- export function scrollDrawer(element: HTMLDialogElement | Element, options?: ScrollDrawerOptions): void
3
+ export function isVerticalDrawer(placement: DrawerPlacement): boolean
4
+ export function scrollDrawer(element: HTMLElement | Element, placement: DrawerPlacement, reverse?: boolean, behavior?: 'auto' | 'instant'): void
5
+ export function showDrawer(element: HTMLElement | Element, placement: DrawerPlacement): Promise<void>
6
+ export function closeDrawer(element: HTMLElement | Element, placement: DrawerPlacement): void
7
+ export function drawerEvents(element: HTMLDialogElement | Element, contentElement: HTMLElement | Element, placement: DrawerPlacement, signal?: AbortSignal): void
8
+ export function drawerObserver(element: HTMLDialogElement | Element, placement: DrawerPlacement): IntersectionObserver
9
+ export function drawerProperties(element: HTMLElement | Element, placement: DrawerPlacement): ['top' | 'left', number, number]
@@ -7,14 +7,14 @@ export interface ValidateFormOptions {
7
7
  }
8
8
 
9
9
  export interface ValidateFieldOptions {
10
- validate?: boolean
11
10
  validationMessage?: string
12
11
  selector?: string
13
12
  validitySelector?: string
14
13
  infoContent?: string
15
- endParentSelector?: string
16
- endSelector?: string
17
- endContent?: string
14
+ iconParentSelector?: string
15
+ iconSelector?: string
16
+ iconContent?: string
17
+ validIcon?: string | null
18
18
  invalidIcon?: string
19
19
  }
20
20
 
@@ -6,26 +6,22 @@
6
6
  export const validateForm = (event, options = {}) => {
7
7
  options = {
8
8
  validateSelector: '.x-field',
9
- validateOptions: {
10
- validate: true,
11
- },
9
+ validateOptions: {},
12
10
  validateField,
13
11
  submitterLoadingAttribute: 'data-loading',
14
12
  scrollOptions: { behavior: 'smooth', block: 'center' },
15
13
  ...options,
16
14
  }
17
15
 
18
- if (options.validateOptions.validate) {
19
- if (!event.target.checkValidity()) {
20
- event.preventDefault()
21
- event.stopImmediatePropagation()
16
+ if (!event.target.checkValidity()) {
17
+ event.preventDefault()
18
+ event.stopImmediatePropagation()
22
19
 
23
- event.target.querySelector(':invalid').scrollIntoView(options.scrollOptions)
24
- event.target.querySelector(':invalid').focus()
25
- }
26
- else if (options.submitterLoadingAttribute) {
27
- event?.submitter?.setAttribute(options.submitterLoadingAttribute, '')
28
- }
20
+ event.target.querySelector(':invalid').scrollIntoView(options.scrollOptions)
21
+ event.target.querySelector(':invalid').focus()
22
+ }
23
+ else if (options.submitterLoadingAttribute) {
24
+ event?.submitter?.setAttribute(options.submitterLoadingAttribute, '')
29
25
  }
30
26
 
31
27
  event.target.querySelectorAll(options.validateSelector).forEach((element) => {
@@ -40,39 +36,40 @@ export const validateForm = (event, options = {}) => {
40
36
  */
41
37
  export const validateField = (element, options = {}) => {
42
38
  options = {
43
- validate: true,
44
39
  selector: ':is(input:not([type="hidden"]), textarea, select):not([readonly], [data-novalidate])',
45
40
  validitySelector: '[data-validity]',
46
41
  infoContent: '<div class="x-info text-error" data-validity></div>',
47
- endParentSelector: '.x-control',
48
- endSelector: '.ms-auto',
49
- endContent: '<div class="ms-auto"></div>',
50
- invalidIcon: '<svg class="text-error" data-validity aria-hidden="true"><use href="#icon-exclamation-circle"></use></svg>',
42
+ iconParentSelector: '.x-control',
43
+ iconSelector: '.ms-auto',
44
+ iconContent: '<div class="ms-auto"></div>',
45
+ validIcon: null,
46
+ invalidIcon: '<svg class="text-error" data-validity aria-hidden="true"><use href="#heroicons-outline/exclamation-circle"></use></svg>',
51
47
  ...options,
52
48
  }
53
49
 
54
- const validationElements = /** @type {HTMLInputElement[]} */ ([...element.querySelectorAll(options.selector)])
50
+ const validationElements = [...element.querySelectorAll(options.selector)]
55
51
 
56
- if (!validationElements.length || !options.validate) return
52
+ if (!validationElements.length) return
57
53
 
58
54
  element.querySelectorAll(options.validitySelector).forEach(el => el.remove())
59
55
 
60
56
  const invalidElements = validationElements.filter(validationElement => !validationElement.checkValidity())
61
57
 
62
- if (!invalidElements.length) return
58
+ validationElements.forEach((validationElement) => {
59
+ const icon = invalidElements.includes(validationElement) ? options.invalidIcon : options.validIcon
60
+ const iconParentElement = validationElement.closest(options.iconParentSelector)
63
61
 
64
- invalidElements.forEach((validationElement) => {
65
- const endParentElement = validationElement.closest(options.endParentSelector)
62
+ if (!iconParentElement || !icon) return
66
63
 
67
- if (!endParentElement || !options.invalidIcon) return
68
-
69
- if (!endParentElement.querySelector(options.endSelector)) {
70
- endParentElement.insertAdjacentHTML('beforeend', options.endContent)
64
+ if (!iconParentElement.querySelector(options.iconSelector)) {
65
+ iconParentElement.insertAdjacentHTML('beforeend', options.iconContent)
71
66
  }
72
67
 
73
- endParentElement.querySelector(options.endSelector).insertAdjacentHTML('afterbegin', options.invalidIcon)
68
+ iconParentElement.querySelector(options.iconSelector).insertAdjacentHTML('afterbegin', icon)
74
69
  })
75
70
 
71
+ if (!invalidElements.length) return
72
+
76
73
  element.insertAdjacentHTML('beforeend', options.infoContent)
77
74
  element.lastElementChild.textContent = options.validationMessage ?? invalidElements[0].dataset.validationMessage ?? invalidElements[0].validationMessage
78
75
  }
package/types/index.d.ts CHANGED
@@ -129,14 +129,14 @@ declare module 'winduum/src/components/form' {
129
129
  }
130
130
 
131
131
  export interface ValidateFieldOptions {
132
- validate?: boolean
133
132
  validationMessage?: string
134
133
  selector?: string
135
134
  validitySelector?: string
136
135
  infoContent?: string
137
- endParentSelector?: string
138
- endSelector?: string
139
- endContent?: string
136
+ iconParentSelector?: string
137
+ iconSelector?: string
138
+ iconContent?: string
139
+ validIcon?: string | null
140
140
  invalidIcon?: string
141
141
  }
142
142