winduum 2.2.20 → 3.0.0-next.1

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.
@@ -1,82 +1,7 @@
1
- import { animationsFinished, nextRepaint } from '../../common.js'
1
+ document.documentElement.addEventListener('click', ({ target }) => {
2
+ const closedBy = target?.getAttribute('closedby')
2
3
 
3
- /**
4
- * @type {import("./").DefaultOptions}
5
- */
6
- export const defaultOptions = {
7
- closedAttribute: 'data-closed',
8
- openAttribute: 'data-open',
9
- scrollbarWidthProperty: '--default-scrollbar-width',
10
- contentSelector: '.x-dialog-content',
11
- closable: true,
12
- modal: true,
13
- }
14
-
15
- /**
16
- * Shows a dialog.
17
- * @param {HTMLDialogElement | HTMLElement} element - The dialog element to show.
18
- * @param {import("./").DefaultOptions} options - The options for showing the dialog.
19
- * @returns Promise<void>
20
- */
21
- export const showDialog = async (element, options = {}) => {
22
- options = {
23
- ...defaultOptions,
24
- ...options,
25
- }
26
-
27
- if (options.scrollbarWidthProperty) {
28
- document.documentElement.style.setProperty(options.scrollbarWidthProperty, `${window.innerWidth - document.body.clientWidth}px`)
29
- }
30
-
31
- if (!element?._dialogHasEvents) {
32
- element.addEventListener('cancel', (e) => {
33
- e.preventDefault()
34
- options.closable && closeDialog(element, options)
35
- })
36
-
37
- element.addEventListener('click', ({ target }) => {
38
- if (target.nodeName === 'DIALOG' && options.closable) {
39
- closeDialog(element, options)
40
- }
41
- })
42
-
43
- element._dialogHasEvents = true
4
+ if (target?.matches('dialog[open]') && !document.activeElement.matches('input,textarea') && closedBy && closedBy !== 'none') {
5
+ target?.close()
44
6
  }
45
-
46
- element.setAttribute(options.closedAttribute, '')
47
-
48
- options.modal ? element.showModal() : element.show()
49
- element.scroll(0, 0)
50
-
51
- element.removeAttribute(options.closedAttribute)
52
- await animationsFinished(element.querySelector(options.contentSelector))
53
- element.setAttribute(options.openAttribute, '')
54
-
55
- element.dispatchEvent(new CustomEvent('x-dialog:show'))
56
- }
57
-
58
- /**
59
- * Closes and dismisses a dialog.
60
- * @param {HTMLDialogElement | HTMLElement} element - The dialog element to dismiss.
61
- * @param {import("./").DefaultOptions} options - The options for closing the dialog.
62
- * @returns Promise<void>
63
- */
64
- export const closeDialog = async (element, options = {}) => {
65
- options = {
66
- ...defaultOptions,
67
- ...options,
68
- }
69
-
70
- element.dispatchEvent(new CustomEvent('x-dialog:close'))
71
-
72
- element.removeAttribute(options.openAttribute)
73
- element.setAttribute(options.closedAttribute, '')
74
-
75
- await animationsFinished(element.querySelector(options.contentSelector))
76
-
77
- element.close()
78
-
79
- await nextRepaint()
80
-
81
- options.remove && element.remove()
82
- }
7
+ })
@@ -29,12 +29,8 @@ You can also copy and paste the code from this directory to your project and rem
29
29
  @import "@/components/dialog/assets/index.css" layer(components);
30
30
  ```
31
31
 
32
- ```js
33
- import { showDialog } from '@/components/dialog/assets/index.js'
34
- ```
35
-
36
32
  ### Docs
37
- Visit [docs](https://winduum.dev/docs/components/dialog.html) to learn more about Javascript API and see usage examples.
33
+ Visit [docs](https://winduum.dev/docs/components/dialog.html) to learn more about usage examples.
38
34
 
39
35
  ### Frameworks
40
36
  * [winduum/winduum-vue](https://github.com/winduum/winduum-vue/blob/main/src/components/dialog)
@@ -3,6 +3,7 @@
3
3
  @import "./check/index.css";
4
4
  @import "./color/index.css";
5
5
  @import "./control/index.css";
6
+ @import "./details/index.css";
6
7
  @import "./group/index.css";
7
8
  @import "./heading/index.css";
8
9
  @import "./image/index.css";
@@ -2,103 +2,14 @@
2
2
  background-color: var(--x-popover-content-background-color);
3
3
  border-radius: var(--x-popover-content-border-radius);
4
4
  padding: var(--x-popover-content-padding-block) var(--x-popover-content-padding-inline);
5
- z-index: var(--x-popover-content-z-index, var(--z-index-10));
6
- transition-property: var(--default-transition-property);
7
- transition-timing-function: var(--ease-in-out);
8
- transition-duration: var(--default-transition-duration);
9
- transform:
10
- translate(var(--tw-translate-x, 0), var(--tw-translate-y, 0))
11
- scaleX(var(--tw-scale-x, 1)) scaleY(var(--tw-scale-y, 1));
5
+ transition: inherit;
12
6
  will-change: transform;
13
- inline-size: max-content;
14
- position: absolute;
15
7
 
16
- &:where(.bottom),
17
- & {
18
- transform-origin: top;
8
+ @starting-style {
9
+ scale: var(--x-popover-content-starting-scale);
19
10
  }
20
11
 
21
- &:where(.bottom-start) {
22
- transform-origin: top left;
23
- }
24
-
25
- &:where(.bottom-end) {
26
- inset-inline-end: 0;
27
- transform-origin: top right;
28
- }
29
-
30
- &:where(.right) {
31
- inset-block-start: 0;
32
- inset-inline-start: 100%;
33
- transform-origin: left;
34
- }
35
-
36
- &:where(.right-start) {
37
- transform-origin: left top;
38
- }
39
-
40
- &:where(.right-end) {
41
- inset-block: auto 0;
42
- transform-origin: left bottom;
43
- }
44
-
45
- &:where(.left) {
46
- inset-block-start: 0;
47
- inset-inline-end: 100%;
48
- transform-origin: right;
49
- }
50
-
51
- &:where(.left-start) {
52
- transform-origin: right top;
53
- }
54
-
55
- &:where(.left-end) {
56
- inset-block: auto 0;
57
- transform-origin: right bottom;
58
- }
59
-
60
- &:where(.top) {
61
- inset-block-end: 100%;
62
- transform-origin: bottom;
63
- }
64
-
65
- &:where(.top-start) {
66
- transform-origin: bottom left;
67
- }
68
-
69
- &:where(.top-end) {
70
- inset-inline-end: 0;
71
- transform-origin: bottom right;
72
- }
73
-
74
- &:where(.inline-center) {
75
- --tw-translate-x: -50%;
76
-
77
- inset-inline-start: 50%;
78
- }
79
-
80
- &:where(.block-center) {
81
- --tw-translate-y: -50%;
82
-
83
- inset-block-start: 50%;
84
- }
85
-
86
- &[popover]:not([data-open]) {
87
- --tw-scale-x: var(--x-popover-content-scale-x);
88
- --tw-scale-y: var(--x-popover-content-scale-y);
89
-
90
- opacity: 0%;
91
- pointer-events: none;
92
- }
93
-
94
- &:not([popover]) {
95
- .trigger-focus:not(:focus, :focus-within) > &,
96
- .trigger-hover:not(:hover) > & {
97
- --tw-scale-x: var(--x-popover-content-scale-x);
98
- --tw-scale-y: var(--x-popover-content-scale-y);
99
-
100
- opacity: 0%;
101
- visibility: hidden;
102
- }
12
+ :where(.x-popover:not(:popover-open)) > & {
13
+ scale: var(--x-popover-content-starting-scale);
103
14
  }
104
15
  }
@@ -1,4 +1,17 @@
1
1
  .x-popover {
2
- position: relative;
3
- display: inline-block;
2
+ transition-property: var(--default-transition-property);
3
+ transition-timing-function: var(--ease-in-out);
4
+ transition-duration: var(--default-transition-duration);
5
+ transition-behavior: allow-discrete;
6
+ position: fixed;
7
+ inset: auto;
8
+ container-type: anchored;
9
+
10
+ @starting-style {
11
+ opacity: var(--x-popover-starting-opacity);
12
+ }
13
+
14
+ &:not(:popover-open) {
15
+ opacity: var(--x-popover-starting-opacity);
16
+ }
4
17
  }
@@ -1,3 +1,4 @@
1
+ @import "./props/default.css";
1
2
  @import "./props/content.css";
2
3
  @import "./default.css";
3
4
  @import "./content.css";
@@ -1,20 +1,16 @@
1
- import { FlipOptions, Middleware, OffsetOptions, Placement, ShiftOptions } from "@floating-ui/dom";
1
+ import type { ComputePositionConfig } from '@floating-ui/dom'
2
+ import type { Placement } from '@floating-ui/utils'
2
3
 
3
- export interface ShowPopoverOptions {
4
- anchorSelector: string,
5
- openAttribute?: string
6
- compute?: boolean
7
- placement?: Placement
8
- middleware?: Array<Middleware | null | undefined | false>
9
- offset?: OffsetOptions
10
- flip?: FlipOptions
11
- shift?: ShiftOptions
12
- }
4
+ export declare function computePositionPopover(
5
+ referenceElement: HTMLElement,
6
+ floatingElement: HTMLElement & { $currentPlacement?: string },
7
+ placement: Placement,
8
+ options?: ComputePositionConfig | boolean
9
+ ): Promise<void>
13
10
 
14
- export interface HidePopoverOptions {
15
- openAttribute?: string
16
- }
17
-
18
- export function showPopover(element: HTMLElement | Element, options?: ShowPopoverOptions): Promise<void>
19
- export function hidePopover(element: HTMLElement | Element): Promise<void>
20
- export function togglePopover(element: HTMLElement | Element, options?: ShowPopoverOptions): Promise<void>
11
+ export declare function autoUpdatePopover(
12
+ referenceElement: HTMLElement,
13
+ floatingElement: HTMLElement,
14
+ placement: Placement,
15
+ options?: ComputePositionConfig | boolean
16
+ ): Promise<() => void>
@@ -1,93 +1,53 @@
1
- import { animationsFinished, nextRepaint } from '../../common.js'
1
+ import { supportsAnchor } from '../../common.js'
2
2
 
3
3
  /**
4
- * @param {HTMLElement | Element} element
5
- * @param {HTMLElement | Element} popoverElement
6
- * @param {import("./").ShowPopoverOptions} options
7
- * @returns Promise<void>
4
+ * @param {HTMLElement} referenceElement
5
+ * @param {HTMLElement & { _currentPlacement?: import('@floating-ui/utils').Placement }} floatingElement
6
+ * @param {import('@floating-ui/utils').Placement} placement
7
+ * @param {import('@floating-ui/dom').ComputePositionConfig | boolean} [options={}]
8
+ * @returns {Promise<void>}
8
9
  */
9
- export const computePopover = async (element, popoverElement, options = {}) => {
10
- const { computePosition, flip, shift, offset } = await import('@floating-ui/dom')
11
-
12
- popoverElement.classList.remove(popoverElement._placement)
13
-
14
- await computePosition(element, popoverElement, {
15
- placement: options?.placement,
16
- middleware: options?.middleware ?? [offset(options?.offset ?? 12), flip(options?.flip), shift({ padding: 8, ...options?.shift })],
10
+ export const computePositionPopover = async (
11
+ referenceElement,
12
+ floatingElement,
13
+ placement,
14
+ options = {},
15
+ ) => {
16
+ const { computePosition, flip } = await import('@floating-ui/dom')
17
+
18
+ const autoUpdate = options === true
19
+ const middleware = autoUpdate ? [flip()] : []
20
+
21
+ floatingElement.classList.remove(floatingElement._currentPlacement ?? placement)
22
+ floatingElement.style.setProperty('--anchor-size', !supportsAnchor ? `${referenceElement.offsetWidth}px` : '')
23
+
24
+ await computePosition(referenceElement, floatingElement, {
25
+ middleware,
26
+ placement,
27
+ ...(autoUpdate ? {} : options),
17
28
  }).then(({ x, y, placement }) => {
18
- Object.assign(popoverElement.style, {
19
- inset: `${y}px auto auto ${x}px`,
20
- })
21
-
22
- popoverElement._placement = placement
23
- popoverElement.classList.add(popoverElement._placement)
29
+ floatingElement.style.inset = !supportsAnchor ? `${y}px auto auto ${x}px` : ''
30
+ floatingElement.classList.add(placement)
31
+ floatingElement._currentPlacement = placement
24
32
  })
25
33
  }
26
34
 
27
35
  /**
28
- * @param {HTMLElement | Element} element - The HTML content to insert into the dialog.
29
- * @param {import("./").HidePopoverOptions} options
30
- * @returns Promise<void>
36
+ * @param {HTMLElement} referenceElement
37
+ * @param {HTMLElement} floatingElement
38
+ * @param {import('@floating-ui/utils').Placement} placement
39
+ * @param {import('@floating-ui/dom').ComputePositionConfig | boolean} [options={}]
40
+ * @returns {Promise<() => void>}
31
41
  */
32
- export const hidePopover = async (element, options = { openAttribute: 'data-open' }) => {
33
- const popoverElement = document.getElementById(element.getAttribute('popovertarget'))
34
-
35
- popoverElement.removeAttribute(options?.openAttribute)
36
- await animationsFinished(popoverElement)
37
- popoverElement._cleanup && popoverElement._cleanup()
38
- popoverElement.hidePopover && popoverElement.hidePopover()
39
-
40
- element.ariaExpanded = 'false'
41
- }
42
-
43
- /**
44
- * @param {HTMLElement | Element} element
45
- * @param {import("./").ShowPopoverOptions} options
46
- * @returns Promise<void>
47
- */
48
- export const showPopover = async (element, options) => {
49
- options = {
50
- openAttribute: 'data-open',
51
- compute: true,
52
- ...options,
53
- }
54
-
42
+ export const autoUpdatePopover = async (
43
+ referenceElement,
44
+ floatingElement,
45
+ placement,
46
+ options = {},
47
+ ) => {
55
48
  const { autoUpdate } = await import('@floating-ui/dom')
56
49
 
57
- const popoverElement = document.getElementById(element.getAttribute('popovertarget'))
58
-
59
- element.ariaExpanded = 'true'
60
-
61
- if (!element.ariaHasPopup) (element.ariaHasPopup = 'dialog')
62
- if (!popoverElement.role) (popoverElement.role = element.ariaHasPopup)
63
-
64
- popoverElement.showPopover && popoverElement.showPopover()
65
-
66
- await nextRepaint()
67
-
68
- popoverElement.setAttribute(options?.openAttribute, '')
69
-
70
- if (!options.compute) {
71
- return
72
- }
73
-
74
- popoverElement._cleanup = autoUpdate(
75
- element,
76
- popoverElement,
77
- async () => await computePopover(options.anchorSelector ? document.querySelector(options.anchorSelector) : element, popoverElement, options),
50
+ return autoUpdate(referenceElement, floatingElement, () =>
51
+ computePositionPopover(referenceElement, floatingElement, placement, options),
78
52
  )
79
53
  }
80
-
81
- /**
82
- * @param {HTMLElement | Element} element
83
- * @param {import("./").ShowPopoverOptions} options
84
- * @returns Promise<void>
85
- */
86
- export const togglePopover = async (element, options) => {
87
- if (element.ariaExpanded !== 'true') {
88
- await showPopover(element, options)
89
- }
90
- else {
91
- await hidePopover(element)
92
- }
93
- }
@@ -4,6 +4,5 @@
4
4
  --x-popover-content-border-radius: var(--radius-xl);
5
5
  --x-popover-content-padding-block: calc(var(--spacing) * 2);
6
6
  --x-popover-content-padding-inline: calc(var(--spacing) * 2);
7
- --x-popover-content-scale-y: 0.75;
8
- --x-popover-content-scale-x: 0.75;
7
+ --x-popover-content-starting-scale: 0.75;
9
8
  }
@@ -0,0 +1,4 @@
1
+ :root,
2
+ :host {
3
+ --x-popover-starting-opacity: 0;
4
+ }
@@ -14,9 +14,8 @@ Include CSS either globally or to your component _([you can't use TailwindCSS la
14
14
  or modular (you can use your own props or CSS)
15
15
 
16
16
  ```css
17
- @import "winduum/src/components/popover/props/content.css" layer(components);
17
+ @import "winduum/src/components/popover/props/default.css" layer(components);
18
18
  @import "winduum/src/components/popover/default.css" layer(components);
19
- @import "winduum/src/components/popover/content.css" layer(components);
20
19
  ```
21
20
 
22
21
  ### Local imports
@@ -26,8 +26,8 @@
26
26
  pointer-events: none;
27
27
  }
28
28
 
29
- &:where(.top),
30
- &:where(.bottom) {
29
+ &:where(.tooltip-top),
30
+ &:where(.tooltip-bottom) {
31
31
  &::before {
32
32
  --tw-translate-x: -50%;
33
33
 
@@ -36,8 +36,8 @@
36
36
  }
37
37
  }
38
38
 
39
- &:where(.left),
40
- &:where(.right) {
39
+ &:where(.tooltip-left),
40
+ &:where(.tooltip-right) {
41
41
  &::before {
42
42
  --tw-translate-y: -50%;
43
43
 
@@ -46,28 +46,28 @@
46
46
  }
47
47
  }
48
48
 
49
- &:where(.bottom) {
49
+ &:where(.tooltip-bottom) {
50
50
  &::before {
51
51
  inset-block-start: 100%;
52
52
  transform-origin: top;
53
53
  }
54
54
  }
55
55
 
56
- &:where(.top) {
56
+ &:where(.tooltip-top) {
57
57
  &::before {
58
58
  inset-block-end: 100%;
59
59
  transform-origin: bottom;
60
60
  }
61
61
  }
62
62
 
63
- &:where(.left) {
63
+ &:where(.tooltip-left) {
64
64
  &::before {
65
65
  inset-inline-end: 100%;
66
66
  transform-origin: right;
67
67
  }
68
68
  }
69
69
 
70
- &:where(.right) {
70
+ &:where(.tooltip-right) {
71
71
  &::before {
72
72
  inset-inline-start: 100%;
73
73
  transform-origin: left;
@@ -0,0 +1,9 @@
1
+ :root,
2
+ :host {
3
+ --ease-in: cubic-bezier(0.4, 0, 1, 1);
4
+ --ease-out: cubic-bezier(0, 0, 0.2, 1);
5
+ --ease-in-out: cubic-bezier(0.4, 0, 0.2, 1);
6
+ --ease-anticipate: cubic-bezier(1, -0.4, 0.35, 0.95);
7
+ --ease-spring: linear(0, 0.009, 0.035 2.1%, 0.141, 0.281 6.7%, 0.723 12.9%, 0.938 16.7%, 1.017, 1.077, 1.121, 1.149 24.3%, 1.159, 1.163, 1.161, 1.154 29.9%, 1.129 32.8%, 1.051 39.6%, 1.017 43.1%, 0.991, 0.977 51%, 0.974 53.8%, 0.975 57.1%, 0.997 69.8%, 1.003 76.9%, 1.004 83.8%, 1);
8
+ --ease-emphasized: linear(0, 0.0341 6.4%, 0.1281 11.41%, 0.6604 20.61%, 0.7653 24.59%, 0.8448 30.42%, 0.9155 40.62%, 0.9633 54.99%, 1);
9
+ }
@@ -1,3 +1,4 @@
1
+ @import "./easing.css";
1
2
  @import "./font.css";
2
3
  @import "./radius.css";
3
4
  @import "./spacing.css";
@@ -2,10 +2,7 @@
2
2
  :host {
3
3
  --default-transition-duration: 150ms;
4
4
  --default-transition-property: color, background-color, border-color, text-decoration-color, fill, stroke, opacity, box-shadow, transform, filter, backdrop-filter, outline-color, outline-offset, visibility, display, overlay;
5
- --default-transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
6
- --ease-in: cubic-bezier(0.4, 0, 1, 1);
7
- --ease-out: cubic-bezier(0, 0, 0.2, 1);
8
- --ease-in-out: var(--default-transition-timing-function);
5
+ --default-transition-timing-function: var(--ease-in-out);
9
6
  --transition-all: all var(--default-transition-duration) var(--default-transition-timing-function);
10
7
  --transition-color: color var(--default-transition-duration) var(--default-transition-timing-function);
11
8
  --transition-background: background var(--default-transition-duration) var(--default-transition-timing-function);
@@ -0,0 +1,5 @@
1
+ @theme {
2
+ --ease-anticipate: cubic-bezier(1, -0.4, 0.35, 0.95);
3
+ --ease-spring: linear(0, 0.009, 0.035 2.1%, 0.141, 0.281 6.7%, 0.723 12.9%, 0.938 16.7%, 1.017, 1.077, 1.121, 1.149 24.3%, 1.159, 1.163, 1.161, 1.154 29.9%, 1.129 32.8%, 1.051 39.6%, 1.017 43.1%, 0.991, 0.977 51%, 0.974 53.8%, 0.975 57.1%, 0.997 69.8%, 1.003 76.9%, 1.004 83.8%, 1);
4
+ --ease-emphasized: linear(0, 0.0341 6.4%, 0.1281 11.41%, 0.6604 20.61%, 0.7653 24.59%, 0.8448 30.42%, 0.9155 40.62%, 0.9633 54.99%, 1);
5
+ }
@@ -1,4 +1,5 @@
1
1
  @import "./breakpoint.css";
2
+ @import "./easing.css";
2
3
  @import "./font.css";
3
4
  @import "./radius.css";
4
5
  @import "./transition.css";
@@ -5,6 +5,7 @@
5
5
  @import "./dot.css";
6
6
  @import "./grid-cols-container.css";
7
7
  @import "./link.css";
8
+ @import "./position.css";
8
9
  @import "./ripple.css";
9
10
  @import "./skeleton.css";
10
11
  @import "./spinner.css";