@corndev/ui-overlays 0.0.0-reserved.0 → 1.0.0-beta.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.
- package/LICENSE +21 -0
- package/README.md +44 -1
- package/dist/components/accordion/accordion.css +109 -0
- package/dist/components/accordion/accordion.d.ts +41 -0
- package/dist/components/drawer/drawer.css +117 -0
- package/dist/components/drawer/drawer.d.ts +29 -0
- package/dist/components/menu/menu.css +106 -0
- package/dist/components/menu/menu.d.ts +71 -0
- package/dist/components/modal/modal.css +122 -0
- package/dist/components/modal/modal.d.ts +27 -0
- package/dist/components/popover/popover.css +115 -0
- package/dist/components/popover/popover.d.ts +36 -0
- package/dist/components/tooltip/tooltip.css +60 -0
- package/dist/components/tooltip/tooltip.d.ts +19 -0
- package/dist/index.css +13 -0
- package/dist/index.js +1089 -0
- package/dist/lib/after-transition.d.ts +18 -0
- package/dist/lib/described-by.d.ts +23 -0
- package/dist/lib/dialog-focus.d.ts +48 -0
- package/dist/lib/inert.d.ts +56 -0
- package/dist/lib/styles-check.d.ts +12 -0
- package/dist/overlays.d.ts +7 -0
- package/package.json +43 -3
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
.corn-popover {
|
|
2
|
+
position: fixed;
|
|
3
|
+
z-index: 8000;
|
|
4
|
+
background-color: var(--corn-bg-primary);
|
|
5
|
+
border: 1px solid var(--corn-border-light);
|
|
6
|
+
border-radius: var(--corn-radius-md);
|
|
7
|
+
box-shadow: var(--corn-shadow-lg);
|
|
8
|
+
min-width: 200px;
|
|
9
|
+
max-width: 320px;
|
|
10
|
+
font-family: var(--corn-font-family);
|
|
11
|
+
font-size: var(--corn-font-size-base);
|
|
12
|
+
color: var(--corn-text-primary);
|
|
13
|
+
opacity: 0;
|
|
14
|
+
transform: scale(0.95);
|
|
15
|
+
transition:
|
|
16
|
+
opacity var(--corn-transition-fast),
|
|
17
|
+
transform var(--corn-transition-fast);
|
|
18
|
+
pointer-events: none;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/* Closed is out of the tab order and the accessibility tree, not just
|
|
22
|
+
transparent: the vanilla popover stays in the document between openings, and
|
|
23
|
+
at opacity 0 alone its controls were still reachable by Tab. The visibility
|
|
24
|
+
change waits for the fade, so closing still animates: visibility interpolates
|
|
25
|
+
as "visible while either end is", so it holds for the whole fade and flips at
|
|
26
|
+
the end. Not a zero-length transition with the token as its delay — the token
|
|
27
|
+
carries its own easing, so that names two and the browser drops the whole
|
|
28
|
+
declaration, fade included. */
|
|
29
|
+
.corn-popover:not([data-visible]) {
|
|
30
|
+
visibility: hidden;
|
|
31
|
+
transition:
|
|
32
|
+
opacity var(--corn-transition-fast),
|
|
33
|
+
transform var(--corn-transition-fast),
|
|
34
|
+
visibility var(--corn-transition-fast);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
.corn-popover[data-visible] {
|
|
38
|
+
opacity: 1;
|
|
39
|
+
transform: scale(1);
|
|
40
|
+
pointer-events: auto;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/* Arrow */
|
|
44
|
+
.corn-popover::before {
|
|
45
|
+
content: '';
|
|
46
|
+
position: absolute;
|
|
47
|
+
border: 7px solid transparent;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
.corn-popover[data-placement='top']::before {
|
|
51
|
+
top: 100%;
|
|
52
|
+
left: 50%;
|
|
53
|
+
transform: translateX(-50%);
|
|
54
|
+
border-top-color: var(--corn-border-light);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
.corn-popover[data-placement='bottom']::before {
|
|
58
|
+
bottom: 100%;
|
|
59
|
+
left: 50%;
|
|
60
|
+
transform: translateX(-50%);
|
|
61
|
+
border-bottom-color: var(--corn-border-light);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
.corn-popover[data-placement='left']::before {
|
|
65
|
+
left: 100%;
|
|
66
|
+
top: 50%;
|
|
67
|
+
transform: translateY(-50%);
|
|
68
|
+
border-left-color: var(--corn-border-light);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
.corn-popover[data-placement='right']::before {
|
|
72
|
+
right: 100%;
|
|
73
|
+
top: 50%;
|
|
74
|
+
transform: translateY(-50%);
|
|
75
|
+
border-right-color: var(--corn-border-light);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/* Header */
|
|
79
|
+
.corn-popover-header {
|
|
80
|
+
display: flex;
|
|
81
|
+
align-items: center;
|
|
82
|
+
justify-content: space-between;
|
|
83
|
+
padding: var(--corn-spacing-sm) var(--corn-spacing-md);
|
|
84
|
+
border-bottom: 1px solid var(--corn-border-light);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
.corn-popover-title {
|
|
88
|
+
font-size: var(--corn-font-size-base);
|
|
89
|
+
font-weight: 600;
|
|
90
|
+
color: var(--corn-text-primary);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
.corn-popover-close {
|
|
94
|
+
background: none;
|
|
95
|
+
border: none;
|
|
96
|
+
cursor: pointer;
|
|
97
|
+
font-size: var(--corn-font-size-lg);
|
|
98
|
+
line-height: 1;
|
|
99
|
+
color: var(--corn-text-secondary);
|
|
100
|
+
padding: 0 4px;
|
|
101
|
+
border-radius: var(--corn-radius-sm);
|
|
102
|
+
transition: color var(--corn-transition-fast), background-color var(--corn-transition-fast);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
.corn-popover-close:hover {
|
|
106
|
+
color: var(--corn-text-primary);
|
|
107
|
+
background-color: var(--corn-bg-tertiary);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/* Body */
|
|
111
|
+
.corn-popover-body {
|
|
112
|
+
padding: var(--corn-spacing-md);
|
|
113
|
+
color: var(--corn-text-secondary);
|
|
114
|
+
line-height: 1.6;
|
|
115
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a popover attached to a trigger element.
|
|
3
|
+
*
|
|
4
|
+
* @param {HTMLElement} triggerEl - Element that opens/closes the popover
|
|
5
|
+
* @param {Object} options
|
|
6
|
+
* @param {string|HTMLElement} options.content - Popover body content (required). A string is shown as text, never parsed as HTML; pass an element for markup.
|
|
7
|
+
* @param {string} [options.title] - Optional heading inside the popover
|
|
8
|
+
* @param {'top'|'bottom'|'left'|'right'} [options.placement='bottom'] - Preferred placement
|
|
9
|
+
* @param {boolean} [options.defaultOpen=false] - Open as soon as it is created.
|
|
10
|
+
* @param {(open: boolean) => void} [options.onChange] - Called whenever it opens or closes,
|
|
11
|
+
* with the new state — by the trigger, Escape, an outside click, or `open()`/`close()`.
|
|
12
|
+
* @param {boolean} [options.trapFocus=false] - Make it a modal dialog: focus moves in and
|
|
13
|
+
* Tab stays inside, the page behind goes inert, Escape answers only the top layer,
|
|
14
|
+
* and closing hands focus back to the trigger — the same code Modal and Drawer
|
|
15
|
+
* run. Without it the popover is a non-modal panel and the page stays live.
|
|
16
|
+
* @param {boolean} [options.closeOnOutsideClick=true] - Dismiss when clicking outside
|
|
17
|
+
* @param {Function} [options.onOpen] - Called when popover opens
|
|
18
|
+
* @param {Function} [options.onClose] - Called when popover closes
|
|
19
|
+
* @returns {{ open: Function, close: Function, toggle: Function, destroy: Function }}
|
|
20
|
+
*/
|
|
21
|
+
export function createPopover(triggerEl: HTMLElement, options?: {
|
|
22
|
+
content: string | HTMLElement;
|
|
23
|
+
title?: string;
|
|
24
|
+
placement?: "top" | "bottom" | "left" | "right";
|
|
25
|
+
defaultOpen?: boolean;
|
|
26
|
+
onChange?: (open: boolean) => void;
|
|
27
|
+
trapFocus?: boolean;
|
|
28
|
+
closeOnOutsideClick?: boolean;
|
|
29
|
+
onOpen?: Function;
|
|
30
|
+
onClose?: Function;
|
|
31
|
+
}): {
|
|
32
|
+
open: Function;
|
|
33
|
+
close: Function;
|
|
34
|
+
toggle: Function;
|
|
35
|
+
destroy: Function;
|
|
36
|
+
};
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
.corn-tooltip {
|
|
2
|
+
position: fixed;
|
|
3
|
+
z-index: 9000;
|
|
4
|
+
padding: var(--corn-spacing-xs) var(--corn-spacing-sm);
|
|
5
|
+
background-color: var(--corn-text-primary);
|
|
6
|
+
color: var(--corn-text-inverse);
|
|
7
|
+
font-family: var(--corn-font-family);
|
|
8
|
+
font-size: var(--corn-font-size-sm);
|
|
9
|
+
line-height: 1.4;
|
|
10
|
+
border-radius: var(--corn-radius-sm);
|
|
11
|
+
white-space: nowrap;
|
|
12
|
+
max-width: 240px;
|
|
13
|
+
white-space: normal;
|
|
14
|
+
pointer-events: none;
|
|
15
|
+
opacity: 0;
|
|
16
|
+
transform: scale(0.95);
|
|
17
|
+
transition:
|
|
18
|
+
opacity var(--corn-transition-fast),
|
|
19
|
+
transform var(--corn-transition-fast);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
.corn-tooltip[data-visible] {
|
|
23
|
+
opacity: 1;
|
|
24
|
+
transform: scale(1);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/* Arrow */
|
|
28
|
+
.corn-tooltip::after {
|
|
29
|
+
content: '';
|
|
30
|
+
position: absolute;
|
|
31
|
+
border: 5px solid transparent;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
.corn-tooltip[data-placement='top']::after {
|
|
35
|
+
top: 100%;
|
|
36
|
+
left: 50%;
|
|
37
|
+
transform: translateX(-50%);
|
|
38
|
+
border-top-color: var(--corn-text-primary);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
.corn-tooltip[data-placement='bottom']::after {
|
|
42
|
+
bottom: 100%;
|
|
43
|
+
left: 50%;
|
|
44
|
+
transform: translateX(-50%);
|
|
45
|
+
border-bottom-color: var(--corn-text-primary);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
.corn-tooltip[data-placement='left']::after {
|
|
49
|
+
left: 100%;
|
|
50
|
+
top: 50%;
|
|
51
|
+
transform: translateY(-50%);
|
|
52
|
+
border-left-color: var(--corn-text-primary);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
.corn-tooltip[data-placement='right']::after {
|
|
56
|
+
right: 100%;
|
|
57
|
+
top: 50%;
|
|
58
|
+
transform: translateY(-50%);
|
|
59
|
+
border-right-color: var(--corn-text-primary);
|
|
60
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Attaches a tooltip to a trigger element.
|
|
3
|
+
*
|
|
4
|
+
* @param {HTMLElement} triggerEl - Element that triggers the tooltip
|
|
5
|
+
* @param {Object} options
|
|
6
|
+
* @param {string} options.content - Tooltip text (required)
|
|
7
|
+
* @param {'top'|'bottom'|'left'|'right'} [options.placement='top'] - Preferred placement
|
|
8
|
+
* @param {number} [options.delay=0] - Show delay in ms
|
|
9
|
+
* @returns {{ show: Function, hide: Function, destroy: Function }}
|
|
10
|
+
*/
|
|
11
|
+
export function createTooltip(triggerEl: HTMLElement, options?: {
|
|
12
|
+
content: string;
|
|
13
|
+
placement?: "top" | "bottom" | "left" | "right";
|
|
14
|
+
delay?: number;
|
|
15
|
+
}): {
|
|
16
|
+
show: Function;
|
|
17
|
+
hide: Function;
|
|
18
|
+
destroy: Function;
|
|
19
|
+
};
|
package/dist/index.css
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
@import './components/modal/modal.css';
|
|
2
|
+
@import './components/drawer/drawer.css';
|
|
3
|
+
@import './components/accordion/accordion.css';
|
|
4
|
+
@import './components/tooltip/tooltip.css';
|
|
5
|
+
@import './components/popover/popover.css';
|
|
6
|
+
@import './components/menu/menu.css';
|
|
7
|
+
|
|
8
|
+
/* Tells lib/styles-check.js this stylesheet is loaded, so a component rendered
|
|
9
|
+
without it can say which import is missing. */
|
|
10
|
+
:root {
|
|
11
|
+
--corn-styles-ui-overlays: 1;
|
|
12
|
+
}
|
|
13
|
+
|