@c2n/modal 0.0.6 → 0.0.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/dist/modal.js +10 -15
- package/package.json +18 -6
- package/react.d.ts +24 -0
- package/react.js +3 -0
- package/types/src/modal.d.ts +14 -1
- package/types/src/modal.d.ts.map +1 -1
- package/vue.d.ts +39 -0
- package/vue.js +3 -0
package/dist/modal.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { LitElement, html, nothing, unsafeCSS } from "lit";
|
|
2
2
|
import { isServer } from "lit-html/is-server.js";
|
|
3
|
-
import {
|
|
3
|
+
import { property, query, state } from "lit/decorators.js";
|
|
4
|
+
import { customElement } from "@c2n/core/element-helper.js";
|
|
4
5
|
import { classMap } from "lit/directives/class-map.js";
|
|
5
|
-
import { redispatchEvent } from "@c2n/core/dom-helper.js";
|
|
6
|
+
import { lockPageScroll, redispatchEvent } from "@c2n/core/dom-helper.js";
|
|
6
7
|
//#region src/modal.scss?inline
|
|
7
8
|
var modal_default = "/* ex : var((width: 24px), width, c2-checkbox) returns var(--c2-checkbox-width, 24px) */\n:host {\n display: contents;\n}\n\n.c2-modal {\n box-sizing: border-box;\n width: var(--c2-modal--width,min(480px, calc(100vw - 32px)));\n max-width: 100vw;\n max-height: var(--c2-modal--max-height,calc(100vh - 64px));\n margin-top: var(--c2-modal--margin-top,auto);\n margin-bottom: var(--c2-modal--margin-bottom,auto);\n margin-left: auto;\n margin-right: auto;\n padding: 0;\n border: var(--c2-modal--border,none);\n border-top-left-radius: var(--c2-modal--border-top-left-radius,14px);\n border-top-right-radius: var(--c2-modal--border-top-right-radius,14px);\n border-bottom-left-radius: var(--c2-modal--border-bottom-left-radius,14px);\n border-bottom-right-radius: var(--c2-modal--border-bottom-right-radius,14px);\n background: var(--c2-modal--background,#ffffff);\n color: var(--c2-modal--color,#18181b);\n box-shadow: var(--c2-modal--box-shadow,0 24px 60px rgba(0, 0, 0, 0.25));\n overflow: hidden;\n opacity: 0;\n transform: var(--c2-modal--enter-transform,translateY(12px) scale(0.98));\n transition: opacity var(--c2-modal--transition-duration,200ms) cubic-bezier(0.2, 0, 0, 1), transform var(--c2-modal--transition-duration,200ms) cubic-bezier(0.2, 0, 0, 1), display var(--c2-modal--transition-duration,200ms) allow-discrete, overlay var(--c2-modal--transition-duration,200ms) allow-discrete;\n}\n.c2-modal[open] {\n opacity: 1;\n transform: none;\n}\n.c2-modal::backdrop {\n background: var(--c2-modal__backdrop--background,rgba(9, 9, 11, 0.45));\n backdrop-filter: var(--c2-modal__backdrop--backdrop-filter);\n opacity: 0;\n transition: opacity var(--c2-modal--transition-duration,200ms) cubic-bezier(0.2, 0, 0, 1), display var(--c2-modal--transition-duration,200ms) allow-discrete, overlay var(--c2-modal--transition-duration,200ms) allow-discrete;\n}\n.c2-modal[open]::backdrop {\n opacity: 1;\n}\n\n@starting-style {\n .c2-modal[open] {\n opacity: 0;\n transform: var(--c2-modal--enter-transform,translateY(12px) scale(0.98));\n }\n .c2-modal[open]::backdrop {\n opacity: 0;\n }\n}\n.c2-modal__panel {\n display: flex;\n flex-direction: column;\n max-height: var(--c2-modal--max-height,calc(100vh - 64px));\n min-height: 0;\n}\n\n.c2-modal__header {\n display: flex;\n align-items: flex-start;\n gap: 12px;\n flex: none;\n padding-top: var(--c2-modal__header--padding-top,20px);\n padding-right: var(--c2-modal__header--padding-right,20px);\n padding-bottom: var(--c2-modal__header--padding-bottom,0px);\n padding-left: var(--c2-modal__header--padding-left,24px);\n border-bottom: var(--c2-modal__header--border-bottom);\n}\n.c2-modal__header[hidden] {\n display: none;\n}\n\n.c2-modal__title {\n flex: 1;\n min-width: 0;\n font-size: var(--c2-modal__header--font-size,17px);\n font-weight: var(--c2-modal__header--font-weight,600);\n line-height: var(--c2-modal__header--line-height,1.35);\n min-height: var(--c2-modal__close--size,32px);\n display: flex;\n align-items: center;\n}\n.c2-modal__title ::slotted(*) {\n margin: 0;\n font: inherit;\n}\n\n.c2-modal__close {\n display: inline-flex;\n align-items: center;\n justify-content: center;\n flex: none;\n box-sizing: border-box;\n width: var(--c2-modal__close--size,32px);\n height: var(--c2-modal__close--size,32px);\n margin: 0;\n padding: 0;\n border: none;\n border-radius: var(--c2-modal__close--border-radius,8px);\n background: transparent;\n color: var(--c2-modal__close--color,#71717a);\n cursor: pointer;\n transition: background 250ms cubic-bezier(0.2, 0, 0, 1), color 250ms cubic-bezier(0.2, 0, 0, 1);\n}\n.c2-modal__close svg,\n.c2-modal__close ::slotted(*) {\n width: var(--c2-modal__close--icon-size,18px);\n height: var(--c2-modal__close--icon-size,18px);\n}\n.c2-modal__close:hover {\n background: var(--c2-modal__close__hover--background,#f4f4f5);\n color: var(--c2-modal__close__hover--color,#18181b);\n}\n.c2-modal__close:focus-visible {\n outline: var(--c2-modal__close__focus--outline,2px solid rgba(2, 101, 220, 0.4));\n outline-offset: 1px;\n}\n\n.c2-modal__body {\n flex: 1;\n min-height: 0;\n overflow: auto;\n padding-top: var(--c2-modal__body--padding-top,12px);\n padding-right: var(--c2-modal__body--padding-right,24px);\n padding-bottom: var(--c2-modal__body--padding-bottom,20px);\n padding-left: var(--c2-modal__body--padding-left,24px);\n font-size: var(--c2-modal__body--font-size,14px);\n line-height: var(--c2-modal__body--line-height,1.6);\n color: var(--c2-modal__body--color);\n}\n\n.c2-modal__footer {\n display: flex;\n align-items: center;\n flex: none;\n gap: var(--c2-modal__footer--gap,8px);\n justify-content: var(--c2-modal__footer--justify-content,flex-end);\n padding-top: var(--c2-modal__footer--padding-top,0px);\n padding-right: var(--c2-modal__footer--padding-right,24px);\n padding-bottom: var(--c2-modal__footer--padding-bottom,20px);\n padding-left: var(--c2-modal__footer--padding-left,24px);\n border-top: var(--c2-modal__footer--border-top);\n}\n.c2-modal__footer[hidden] {\n display: none;\n}\n\n@media (prefers-reduced-motion: reduce) {\n .c2-modal,\n .c2-modal::backdrop {\n transition: none;\n }\n}";
|
|
8
9
|
//#endregion
|
|
@@ -15,8 +16,6 @@ function __decorate(decorators, target, key, desc) {
|
|
|
15
16
|
}
|
|
16
17
|
//#endregion
|
|
17
18
|
//#region src/modal.ts
|
|
18
|
-
var scrollLocks = 0;
|
|
19
|
-
var previousOverflow = "";
|
|
20
19
|
var Modal = class Modal extends LitElement {
|
|
21
20
|
constructor(..._args) {
|
|
22
21
|
super(..._args);
|
|
@@ -29,8 +28,8 @@ var Modal = class Modal extends LitElement {
|
|
|
29
28
|
this.returnValue = "";
|
|
30
29
|
this.hasTitle = false;
|
|
31
30
|
this.hasFooter = false;
|
|
32
|
-
this.
|
|
33
|
-
|
|
31
|
+
this.handleDialogClose = (event) => {
|
|
32
|
+
if (event.target !== this.dialog) return;
|
|
34
33
|
this.returnValue = this.dialog.returnValue;
|
|
35
34
|
this.unlockScroll();
|
|
36
35
|
this.open = false;
|
|
@@ -41,6 +40,7 @@ var Modal = class Modal extends LitElement {
|
|
|
41
40
|
}));
|
|
42
41
|
};
|
|
43
42
|
this.handleDialogCancel = (event) => {
|
|
43
|
+
if (event.target !== this.dialog) return;
|
|
44
44
|
if (this.noEscape) {
|
|
45
45
|
event.preventDefault();
|
|
46
46
|
return;
|
|
@@ -69,17 +69,12 @@ var Modal = class Modal extends LitElement {
|
|
|
69
69
|
else this.open = false;
|
|
70
70
|
}
|
|
71
71
|
lockScroll() {
|
|
72
|
-
if (this.noScrollLock || this.
|
|
73
|
-
|
|
74
|
-
previousOverflow = document.documentElement.style.overflow;
|
|
75
|
-
document.documentElement.style.overflow = "hidden";
|
|
76
|
-
}
|
|
77
|
-
this.locked = true;
|
|
72
|
+
if (this.noScrollLock || this.releaseScroll || isServer) return;
|
|
73
|
+
this.releaseScroll = lockPageScroll();
|
|
78
74
|
}
|
|
79
75
|
unlockScroll() {
|
|
80
|
-
|
|
81
|
-
this.
|
|
82
|
-
if (--scrollLocks === 0) document.documentElement.style.overflow = previousOverflow;
|
|
76
|
+
this.releaseScroll?.();
|
|
77
|
+
this.releaseScroll = void 0;
|
|
83
78
|
}
|
|
84
79
|
handleSlotChange(event) {
|
|
85
80
|
this.updateSlot(event.target);
|
package/package.json
CHANGED
|
@@ -1,18 +1,30 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@c2n/modal",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.8",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/modal.js",
|
|
6
6
|
"exports": {
|
|
7
7
|
".": {
|
|
8
|
-
"
|
|
9
|
-
"
|
|
8
|
+
"types": "./types/src/modal.d.ts",
|
|
9
|
+
"default": "./dist/modal.js"
|
|
10
|
+
},
|
|
11
|
+
"./react": {
|
|
12
|
+
"types": "./react.d.ts",
|
|
13
|
+
"default": "./react.js"
|
|
14
|
+
},
|
|
15
|
+
"./vue": {
|
|
16
|
+
"types": "./vue.d.ts",
|
|
17
|
+
"default": "./vue.js"
|
|
10
18
|
},
|
|
11
19
|
"./custom-elements.json": "./custom-elements.json"
|
|
12
20
|
},
|
|
13
21
|
"files": [
|
|
14
22
|
"dist",
|
|
15
|
-
"types"
|
|
23
|
+
"types",
|
|
24
|
+
"react.d.ts",
|
|
25
|
+
"react.js",
|
|
26
|
+
"vue.d.ts",
|
|
27
|
+
"vue.js"
|
|
16
28
|
],
|
|
17
29
|
"keywords": [
|
|
18
30
|
"modal",
|
|
@@ -50,12 +62,12 @@
|
|
|
50
62
|
}
|
|
51
63
|
},
|
|
52
64
|
"dependencies": {
|
|
53
|
-
"@c2n/core": "0.0.
|
|
65
|
+
"@c2n/core": "0.0.8",
|
|
54
66
|
"lit": "3.3.3"
|
|
55
67
|
},
|
|
56
68
|
"devDependencies": {
|
|
57
69
|
"@c2n/config": "*"
|
|
58
70
|
},
|
|
59
71
|
"customElements": "custom-elements.json",
|
|
60
|
-
"gitHead": "
|
|
72
|
+
"gitHead": "be59cbccee1d33ca248e39f69b05c0b595ec6c6d"
|
|
61
73
|
}
|
package/react.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// GENERATED by @c2n/framework-types. Do not edit by hand.
|
|
2
|
+
//
|
|
3
|
+
// JSX types for the custom elements of @c2n/modal. Import once, anywhere in the program:
|
|
4
|
+
//
|
|
5
|
+
// import '@c2n/modal/react'
|
|
6
|
+
//
|
|
7
|
+
// Register the elements at module scope before React renders, or React writes an object prop as an
|
|
8
|
+
// attribute and it stringifies.
|
|
9
|
+
|
|
10
|
+
import type { DetailedHTMLProps, HTMLAttributes } from 'react'
|
|
11
|
+
import type { Modal } from '@c2n/modal'
|
|
12
|
+
|
|
13
|
+
/** Standard React host-element attributes plus the element's own public properties. */
|
|
14
|
+
type C2Props<T> = DetailedHTMLProps<HTMLAttributes<T>, T> & Partial<Omit<T, keyof HTMLElement>>
|
|
15
|
+
|
|
16
|
+
declare module 'react' {
|
|
17
|
+
namespace JSX {
|
|
18
|
+
interface IntrinsicElements {
|
|
19
|
+
'c2-modal': C2Props<Modal>
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export {}
|
package/react.js
ADDED
package/types/src/modal.d.ts
CHANGED
|
@@ -1,4 +1,17 @@
|
|
|
1
1
|
import { LitElement, type PropertyValues } from 'lit';
|
|
2
|
+
import type { TypedAddEventListener, TypedRemoveEventListener } from '@c2n/core/event-helper.js';
|
|
3
|
+
/** Events fired by {@link Modal}, keyed for `addEventListener`. */
|
|
4
|
+
export interface ModalEventMap {
|
|
5
|
+
open: Event;
|
|
6
|
+
close: CustomEvent<{
|
|
7
|
+
returnValue: string;
|
|
8
|
+
}>;
|
|
9
|
+
cancel: Event;
|
|
10
|
+
}
|
|
11
|
+
export interface Modal {
|
|
12
|
+
addEventListener: TypedAddEventListener<Modal, ModalEventMap>;
|
|
13
|
+
removeEventListener: TypedRemoveEventListener<Modal, ModalEventMap>;
|
|
14
|
+
}
|
|
2
15
|
/**
|
|
3
16
|
* Modal dialog built on the native `<dialog>` element: focus is trapped and restored, Escape closes, the page behind
|
|
4
17
|
* is inert and covered by a backdrop. Open it with the `open` attribute or `show()`, close it with `close(returnValue)`,
|
|
@@ -87,7 +100,7 @@ export declare class Modal extends LitElement {
|
|
|
87
100
|
private hasTitle;
|
|
88
101
|
private hasFooter;
|
|
89
102
|
private dialog;
|
|
90
|
-
private
|
|
103
|
+
private releaseScroll;
|
|
91
104
|
disconnectedCallback(): void;
|
|
92
105
|
/** Opens the dialog (modal). */
|
|
93
106
|
show(): void;
|
package/types/src/modal.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"modal.d.ts","sourceRoot":"","sources":["../../src/modal.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAA4B,KAAK,cAAc,EAAE,MAAM,KAAK,CAAA;
|
|
1
|
+
{"version":3,"file":"modal.d.ts","sourceRoot":"","sources":["../../src/modal.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAA4B,KAAK,cAAc,EAAE,MAAM,KAAK,CAAA;AAI/E,OAAO,KAAK,EAAE,qBAAqB,EAAE,wBAAwB,EAAE,MAAM,2BAA2B,CAAA;AAKhG,mEAAmE;AACnE,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,KAAK,CAAA;IACX,KAAK,EAAE,WAAW,CAAC;QAAE,WAAW,EAAE,MAAM,CAAA;KAAE,CAAC,CAAA;IAC3C,MAAM,EAAE,KAAK,CAAA;CACd;AAED,MAAM,WAAW,KAAK;IACpB,gBAAgB,EAAE,qBAAqB,CAAC,KAAK,EAAE,aAAa,CAAC,CAAA;IAC7D,mBAAmB,EAAE,wBAAwB,CAAC,KAAK,EAAE,aAAa,CAAC,CAAA;CACpE;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoEG;AACH,qBACa,KAAM,SAAQ,UAAU;IACnC,OAAgB,MAAM,0BAAoB;IAE1C,yDAAyD;IACb,IAAI,UAAQ;IAExD,qDAAqD;IACzC,KAAK,EAAE,MAAM,GAAG,SAAS,CAAY;IAEjD,yDAAyD;IACI,eAAe,UAAQ;IAEpF,qBAAqB;IACgC,QAAQ,UAAQ;IAErE,kCAAkC;IACmC,SAAS,UAAQ;IAEtF,0DAA0D;IACA,YAAY,UAAQ;IAE9E,wFAAwF;IACxF,WAAW,SAAK;IAEP,OAAO,CAAC,QAAQ,CAAQ;IACxB,OAAO,CAAC,SAAS,CAAQ;IAEjB,OAAO,CAAC,MAAM,CAAoB;IAEnD,OAAO,CAAC,aAAa,CAA0B;IAEtC,oBAAoB;IAK7B,gCAAgC;IAChC,IAAI;IAIJ,wDAAwD;IACxD,KAAK,CAAC,WAAW,SAAK;IAMtB,OAAO,CAAC,UAAU;IAKlB,OAAO,CAAC,YAAY;IAKpB,OAAO,CAAC,iBAAiB,CAOxB;IAED,OAAO,CAAC,kBAAkB,CAOzB;IAED,OAAO,CAAC,iBAAiB,CAGxB;IAED,OAAO,CAAC,gBAAgB;IAIxB,OAAO,CAAC,UAAU;IAMT,YAAY;IAIZ,OAAO,CAAC,OAAO,EAAE,cAAc,CAAC,IAAI,CAAC;IAYrC,MAAM;CA+BhB;AAED,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,qBAAqB;QAC7B,UAAU,EAAE,KAAK,CAAA;KAClB;CACF"}
|
package/vue.d.ts
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// GENERATED by @c2n/framework-types. Do not edit by hand.
|
|
2
|
+
//
|
|
3
|
+
// Vue template types for the custom elements of @c2n/modal. Import once, anywhere in the program:
|
|
4
|
+
//
|
|
5
|
+
// import '@c2n/modal/vue'
|
|
6
|
+
//
|
|
7
|
+
// Tell the compiler about the tags as well, or every c2-* tag is resolved as a Vue component and renders
|
|
8
|
+
// nothing: template.compilerOptions.isCustomElement = (tag) => tag.startsWith('c2-') in vite.config.ts.
|
|
9
|
+
|
|
10
|
+
import type { DefineComponent, HTMLAttributes } from 'vue'
|
|
11
|
+
import type { Modal, ModalEventMap } from '@c2n/modal'
|
|
12
|
+
|
|
13
|
+
/** The element's own public properties, plus every attribute Vue understands on a host element. */
|
|
14
|
+
type C2Props<T> = Partial<Omit<T, keyof HTMLElement>> & HTMLAttributes
|
|
15
|
+
|
|
16
|
+
declare module 'vue' {
|
|
17
|
+
interface GlobalComponents {
|
|
18
|
+
'c2-modal': DefineComponent<
|
|
19
|
+
C2Props<Modal> & {
|
|
20
|
+
'no-backdrop-close'?: unknown
|
|
21
|
+
'no-escape'?: unknown
|
|
22
|
+
'hide-close'?: unknown
|
|
23
|
+
'no-scroll-lock'?: unknown
|
|
24
|
+
onOpen?: (event: ModalEventMap['open']) => void
|
|
25
|
+
onClose?: (event: ModalEventMap['close']) => void
|
|
26
|
+
onCancel?: (event: ModalEventMap['cancel']) => void
|
|
27
|
+
}
|
|
28
|
+
>
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
declare module '@vue/runtime-dom' {
|
|
33
|
+
interface HTMLAttributes {
|
|
34
|
+
/** Vue's own definition omits it, and slotting a plain element into a component needs it. */
|
|
35
|
+
slot?: string
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export {}
|
package/vue.js
ADDED