@pictogrammers/components 0.5.2 → 0.5.4
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 +1 -1
- package/pg/modal/__examples__/basic/basic.ts +5 -1
- package/pg/modalAlert/README.md +6 -7
- package/pg/modalAlert/__examples__/basic/basic.ts +2 -2
- package/pg/modalAlert/modalAlert.html +2 -3
- package/pg/modalAlert/modalAlert.ts +6 -12
- package/pg/modalAlert copy/modalAlert.css +40 -0
- package/pg/modalAlert copy/modalAlert.html +22 -0
- package/pg/modalAlert copy/modalAlert.ts +59 -0
- package/pg/modalConfirm/README.md +19 -0
- package/pg/modalConfirm/__examples__/basic/basic.html +4 -0
- package/pg/modalConfirm/__examples__/basic/basic.ts +29 -0
- package/pg/modalConfirm/modalConfirm.css +40 -0
- package/pg/modalConfirm/modalConfirm.html +22 -0
- package/pg/modalConfirm/modalConfirm.ts +61 -0
- package/pg/overlay/overlay.ts +2 -2
package/package.json
CHANGED
|
@@ -9,6 +9,10 @@ import template from './basic.html';
|
|
|
9
9
|
})
|
|
10
10
|
export class XMyModal extends PgModal {
|
|
11
11
|
|
|
12
|
+
@Prop() header: string = '';
|
|
13
|
+
@Prop() message: string = '';
|
|
14
|
+
|
|
15
|
+
|
|
12
16
|
@Part() $close: HTMLButtonElement;
|
|
13
17
|
|
|
14
18
|
connectedCallback() {
|
|
@@ -34,7 +38,7 @@ export default class XPgModalBasic extends HTMLElement {
|
|
|
34
38
|
async handleClick() {
|
|
35
39
|
const result = await XMyModal.open({
|
|
36
40
|
header: 'Delete Item',
|
|
37
|
-
message: 'Are you sure you want to delete the item?'
|
|
41
|
+
message: 'Are you sure you want to delete the item?',
|
|
38
42
|
});
|
|
39
43
|
this.$result.textContent = `${result}`;
|
|
40
44
|
}
|
package/pg/modalAlert/README.md
CHANGED
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
# `PgModalAlert`
|
|
2
2
|
|
|
3
|
-
The `PgModalAlert` creates a alert box
|
|
3
|
+
The `PgModalAlert` creates a alert box dialog. For options like okay/cancel use `PgModalConfirm`.
|
|
4
4
|
|
|
5
5
|
```typescript
|
|
6
|
-
import
|
|
6
|
+
import PgModalConfirm from '@pictogrammers/components/pg/modalAlert';
|
|
7
7
|
```
|
|
8
8
|
|
|
9
9
|
```typescript
|
|
10
10
|
const result = await PgModalAlert.open({
|
|
11
|
-
header: '
|
|
12
|
-
message: '
|
|
11
|
+
header: 'Something Went Wrong',
|
|
12
|
+
message: 'Some information to alert about.',
|
|
13
13
|
});
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
14
|
+
// we don't care about result
|
|
15
|
+
console.log('Okay was clicked');
|
|
17
16
|
```
|
|
@@ -18,8 +18,8 @@ export default class XPgModalAlertBasic extends HTMLElement {
|
|
|
18
18
|
|
|
19
19
|
async handleClick() {
|
|
20
20
|
const result = await PgModalAlert.open({
|
|
21
|
-
header: '
|
|
22
|
-
message: '
|
|
21
|
+
header: 'Something Went Wrong',
|
|
22
|
+
message: 'Some information to alert about.',
|
|
23
23
|
});
|
|
24
24
|
this.$result.textContent = `${result}`;
|
|
25
25
|
}
|
|
@@ -8,15 +8,14 @@
|
|
|
8
8
|
<h2 id="dialog_label"
|
|
9
9
|
class="dialog_label"
|
|
10
10
|
part="headerText">
|
|
11
|
-
|
|
11
|
+
Alert
|
|
12
12
|
</h2>
|
|
13
13
|
</header>
|
|
14
14
|
<main>
|
|
15
15
|
<p part="message"></p>
|
|
16
16
|
</main>
|
|
17
17
|
<footer>
|
|
18
|
-
<pg-button part="
|
|
19
|
-
<pg-button part="yes" variant="brand">Yes</pg-button>
|
|
18
|
+
<pg-button part="okay" variant="brand">Okay</pg-button>
|
|
20
19
|
</footer>
|
|
21
20
|
</div>
|
|
22
21
|
</div>
|
|
@@ -18,14 +18,12 @@ export default class PgModalAlert extends PgOverlay {
|
|
|
18
18
|
@Part() $header: HTMLDivElement;
|
|
19
19
|
@Part() $headerText: HTMLHeadingElement;
|
|
20
20
|
@Part() $message: HTMLDivElement;
|
|
21
|
-
@Part() $
|
|
22
|
-
@Part() $no: PgButton;
|
|
21
|
+
@Part() $okay: PgButton;
|
|
23
22
|
|
|
24
23
|
#cacheKeydownHandler: any;
|
|
25
24
|
|
|
26
25
|
connectedCallback() {
|
|
27
|
-
this.$
|
|
28
|
-
this.$no.addEventListener('click', this.#handleNo.bind(this));
|
|
26
|
+
this.$okay.addEventListener('click', this.#handleOkay.bind(this));
|
|
29
27
|
this.#cacheKeydownHandler ??= this.#handleKeyDown.bind(this);
|
|
30
28
|
document.addEventListener('keydown', this.#cacheKeydownHandler);
|
|
31
29
|
}
|
|
@@ -40,20 +38,16 @@ export default class PgModalAlert extends PgOverlay {
|
|
|
40
38
|
}
|
|
41
39
|
}
|
|
42
40
|
|
|
43
|
-
#
|
|
44
|
-
this.close(
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
#handleNo() {
|
|
48
|
-
this.close(false);
|
|
41
|
+
#handleOkay() {
|
|
42
|
+
this.close();
|
|
49
43
|
}
|
|
50
44
|
|
|
51
45
|
render(changes) {
|
|
52
46
|
if (changes.header) {
|
|
53
|
-
this.$headerText.
|
|
47
|
+
this.$headerText.textContent = this.header;
|
|
54
48
|
}
|
|
55
49
|
if (changes.message) {
|
|
56
|
-
this.$message.
|
|
50
|
+
this.$message.textContent = this.message;
|
|
57
51
|
}
|
|
58
52
|
}
|
|
59
53
|
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
.backdrop {
|
|
2
|
+
display: flex;
|
|
3
|
+
position: fixed;
|
|
4
|
+
top: 0;
|
|
5
|
+
left: 0;
|
|
6
|
+
right: 0;
|
|
7
|
+
bottom: 0;
|
|
8
|
+
background: rgba(0, 0, 0, 0.6);
|
|
9
|
+
justify-content: center;
|
|
10
|
+
align-items: center;
|
|
11
|
+
}
|
|
12
|
+
.dialog {
|
|
13
|
+
background: #fff;
|
|
14
|
+
border-radius: 0.5rem;
|
|
15
|
+
box-shadow: 0 1px 1rem rgba(0, 0, 0, 0.5);
|
|
16
|
+
overflow: hidden;
|
|
17
|
+
min-width: 15rem;
|
|
18
|
+
}
|
|
19
|
+
header {
|
|
20
|
+
border-bottom: 1px solid #ccc;
|
|
21
|
+
background: #f1f1f1;
|
|
22
|
+
padding: 0.75rem 1rem;
|
|
23
|
+
}
|
|
24
|
+
header h2 {
|
|
25
|
+
font-size: 1.25rem;
|
|
26
|
+
margin: 0;
|
|
27
|
+
font-weight: normal;
|
|
28
|
+
}
|
|
29
|
+
main {
|
|
30
|
+
padding: 0.5rem 1rem;
|
|
31
|
+
}
|
|
32
|
+
footer {
|
|
33
|
+
display: flex;
|
|
34
|
+
flex-direction: row;
|
|
35
|
+
padding: 0.75rem 1rem;
|
|
36
|
+
border-top: 1px solid #ccc;
|
|
37
|
+
background: #f1f1f1;
|
|
38
|
+
justify-content: flex-end;
|
|
39
|
+
gap: 0.5rem;
|
|
40
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
<div class="backdrop">
|
|
2
|
+
<div class="dialog"
|
|
3
|
+
role="dialog"
|
|
4
|
+
id="dialog1"
|
|
5
|
+
aria-labelledby="dialog_label"
|
|
6
|
+
aria-modal="true">
|
|
7
|
+
<header part="header">
|
|
8
|
+
<h2 id="dialog_label"
|
|
9
|
+
class="dialog_label"
|
|
10
|
+
part="headerText">
|
|
11
|
+
Add Delivery Address
|
|
12
|
+
</h2>
|
|
13
|
+
</header>
|
|
14
|
+
<main>
|
|
15
|
+
<p part="message"></p>
|
|
16
|
+
</main>
|
|
17
|
+
<footer>
|
|
18
|
+
<pg-button part="no">No</pg-button>
|
|
19
|
+
<pg-button part="yes" variant="brand">Yes</pg-button>
|
|
20
|
+
</footer>
|
|
21
|
+
</div>
|
|
22
|
+
</div>
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { Component, Prop, Part } from '@pictogrammers/element';
|
|
2
|
+
|
|
3
|
+
import template from './modalAlert.html';
|
|
4
|
+
import style from './modalAlert.css';
|
|
5
|
+
|
|
6
|
+
import PgOverlay from '../overlay/overlay';
|
|
7
|
+
import PgButton from '../button/button';
|
|
8
|
+
|
|
9
|
+
@Component({
|
|
10
|
+
selector: 'pg-modal-alert',
|
|
11
|
+
template,
|
|
12
|
+
style
|
|
13
|
+
})
|
|
14
|
+
export default class PgModalAlert extends PgOverlay {
|
|
15
|
+
@Prop() header: string = 'Are you sure?';
|
|
16
|
+
@Prop() message: string = 'Are you sure?';
|
|
17
|
+
|
|
18
|
+
@Part() $header: HTMLDivElement;
|
|
19
|
+
@Part() $headerText: HTMLHeadingElement;
|
|
20
|
+
@Part() $message: HTMLDivElement;
|
|
21
|
+
@Part() $yes: PgButton;
|
|
22
|
+
@Part() $no: PgButton;
|
|
23
|
+
|
|
24
|
+
#cacheKeydownHandler: any;
|
|
25
|
+
|
|
26
|
+
connectedCallback() {
|
|
27
|
+
this.$yes.addEventListener('click', this.#handleYes.bind(this));
|
|
28
|
+
this.$no.addEventListener('click', this.#handleNo.bind(this));
|
|
29
|
+
this.#cacheKeydownHandler ??= this.#handleKeyDown.bind(this);
|
|
30
|
+
document.addEventListener('keydown', this.#cacheKeydownHandler);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
disconnectedCallback() {
|
|
34
|
+
document.removeEventListener('keydown', this.#cacheKeydownHandler);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
#handleKeyDown(e: KeyboardEvent) {
|
|
38
|
+
if (e.key === 'Escape') {
|
|
39
|
+
this.close(null);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
#handleYes() {
|
|
44
|
+
this.close(true);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
#handleNo() {
|
|
48
|
+
this.close(false);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
render(changes) {
|
|
52
|
+
if (changes.header) {
|
|
53
|
+
this.$headerText.innerText = this.header;
|
|
54
|
+
}
|
|
55
|
+
if (changes.message) {
|
|
56
|
+
this.$message.innerText = this.message;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# `PgModalConfirm`
|
|
2
|
+
|
|
3
|
+
The `PgModalConfirm` creates a confirm box dialog.
|
|
4
|
+
|
|
5
|
+
```typescript
|
|
6
|
+
import PgModalConfirm from '@pictogrammers/components/pg/modalConfirm';
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
```typescript
|
|
10
|
+
const result = await PgModalConfirm.open({
|
|
11
|
+
header: 'Delete Item',
|
|
12
|
+
message: 'Are you sure you want to delete the item?',
|
|
13
|
+
okay: 'Delete',
|
|
14
|
+
cancel: 'Keep Item',
|
|
15
|
+
});
|
|
16
|
+
if (result) {
|
|
17
|
+
console.log('Item has been deleted.');
|
|
18
|
+
}
|
|
19
|
+
```
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Component, Part, Prop } from '@pictogrammers/element';
|
|
2
|
+
import PgModalConfirm from '../../modalConfirm';
|
|
3
|
+
|
|
4
|
+
import template from './basic.html';
|
|
5
|
+
|
|
6
|
+
@Component({
|
|
7
|
+
selector: 'x-pg-modal-confirm-basic',
|
|
8
|
+
template
|
|
9
|
+
})
|
|
10
|
+
export default class XPgModalConfirmBasic extends HTMLElement {
|
|
11
|
+
|
|
12
|
+
@Part() $button: HTMLButtonElement;
|
|
13
|
+
@Part() $result: HTMLSpanElement;
|
|
14
|
+
|
|
15
|
+
connectedCallback() {
|
|
16
|
+
this.$button.addEventListener('click', this.handleClick.bind(this));
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
async handleClick() {
|
|
20
|
+
const result = await PgModalConfirm.open({
|
|
21
|
+
header: 'Delete Item',
|
|
22
|
+
message: 'Are you sure you want to delete the item?',
|
|
23
|
+
okay: 'Delete',
|
|
24
|
+
cancel: 'Keep Item',
|
|
25
|
+
});
|
|
26
|
+
this.$result.textContent = `${result}`;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
.backdrop {
|
|
2
|
+
display: flex;
|
|
3
|
+
position: fixed;
|
|
4
|
+
top: 0;
|
|
5
|
+
left: 0;
|
|
6
|
+
right: 0;
|
|
7
|
+
bottom: 0;
|
|
8
|
+
background: rgba(0, 0, 0, 0.6);
|
|
9
|
+
justify-content: center;
|
|
10
|
+
align-items: center;
|
|
11
|
+
}
|
|
12
|
+
.dialog {
|
|
13
|
+
background: #fff;
|
|
14
|
+
border-radius: 0.5rem;
|
|
15
|
+
box-shadow: 0 1px 1rem rgba(0, 0, 0, 0.5);
|
|
16
|
+
overflow: hidden;
|
|
17
|
+
min-width: 15rem;
|
|
18
|
+
}
|
|
19
|
+
header {
|
|
20
|
+
border-bottom: 1px solid #ccc;
|
|
21
|
+
background: #f1f1f1;
|
|
22
|
+
padding: 0.75rem 1rem;
|
|
23
|
+
}
|
|
24
|
+
header h2 {
|
|
25
|
+
font-size: 1.25rem;
|
|
26
|
+
margin: 0;
|
|
27
|
+
font-weight: normal;
|
|
28
|
+
}
|
|
29
|
+
main {
|
|
30
|
+
padding: 0.5rem 1rem;
|
|
31
|
+
}
|
|
32
|
+
footer {
|
|
33
|
+
display: flex;
|
|
34
|
+
flex-direction: row;
|
|
35
|
+
padding: 0.75rem 1rem;
|
|
36
|
+
border-top: 1px solid #ccc;
|
|
37
|
+
background: #f1f1f1;
|
|
38
|
+
justify-content: flex-end;
|
|
39
|
+
gap: 0.5rem;
|
|
40
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
<div class="backdrop">
|
|
2
|
+
<div class="dialog"
|
|
3
|
+
role="dialog"
|
|
4
|
+
id="dialog1"
|
|
5
|
+
aria-labelledby="dialog_label"
|
|
6
|
+
aria-modal="true">
|
|
7
|
+
<header part="header">
|
|
8
|
+
<h2 id="dialog_label"
|
|
9
|
+
class="dialog_label"
|
|
10
|
+
part="headerText">
|
|
11
|
+
Confirm
|
|
12
|
+
</h2>
|
|
13
|
+
</header>
|
|
14
|
+
<main>
|
|
15
|
+
<p part="message"></p>
|
|
16
|
+
</main>
|
|
17
|
+
<footer>
|
|
18
|
+
<pg-button part="cancel">Cancel</pg-button>
|
|
19
|
+
<pg-button part="okay" variant="brand">Okay</pg-button>
|
|
20
|
+
</footer>
|
|
21
|
+
</div>
|
|
22
|
+
</div>
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { Component, Prop, Part } from '@pictogrammers/element';
|
|
2
|
+
|
|
3
|
+
import template from './modalConfirm.html';
|
|
4
|
+
import style from './modalConfirm.css';
|
|
5
|
+
|
|
6
|
+
import PgOverlay from '../overlay/overlay';
|
|
7
|
+
import PgButton from '../button/button';
|
|
8
|
+
|
|
9
|
+
@Component({
|
|
10
|
+
selector: 'pg-modal-confirm',
|
|
11
|
+
template,
|
|
12
|
+
style
|
|
13
|
+
})
|
|
14
|
+
export default class PgModalConfirm extends PgOverlay {
|
|
15
|
+
@Prop() header: string = 'Are you sure?';
|
|
16
|
+
@Prop() message: string = 'Are you sure?';
|
|
17
|
+
@Prop() cancel: string = 'Cancel';
|
|
18
|
+
@Prop() okay: string = 'Okay';
|
|
19
|
+
|
|
20
|
+
@Part() $header: HTMLDivElement;
|
|
21
|
+
@Part() $headerText: HTMLHeadingElement;
|
|
22
|
+
@Part() $message: HTMLDivElement;
|
|
23
|
+
@Part() $okay: PgButton;
|
|
24
|
+
@Part() $cancel: PgButton;
|
|
25
|
+
|
|
26
|
+
#cacheKeydownHandler: any;
|
|
27
|
+
|
|
28
|
+
connectedCallback() {
|
|
29
|
+
this.$okay.addEventListener('click', this.#handleOkay.bind(this));
|
|
30
|
+
this.$cancel.addEventListener('click', this.#handleCancel.bind(this));
|
|
31
|
+
this.#cacheKeydownHandler ??= this.#handleKeyDown.bind(this);
|
|
32
|
+
document.addEventListener('keydown', this.#cacheKeydownHandler);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
disconnectedCallback() {
|
|
36
|
+
document.removeEventListener('keydown', this.#cacheKeydownHandler);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
#handleKeyDown(e: KeyboardEvent) {
|
|
40
|
+
if (e.key === 'Escape') {
|
|
41
|
+
this.close(null);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
#handleOkay() {
|
|
46
|
+
this.close(true);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
#handleCancel() {
|
|
50
|
+
this.close(false);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
render(changes) {
|
|
54
|
+
if (changes.header) {
|
|
55
|
+
this.$headerText.textContent = this.header;
|
|
56
|
+
}
|
|
57
|
+
if (changes.message) {
|
|
58
|
+
this.$message.textContent = this.message;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
package/pg/overlay/overlay.ts
CHANGED
|
@@ -5,9 +5,9 @@ const promises: Map<HTMLElement, (value: any) => void> = new Map();
|
|
|
5
5
|
|
|
6
6
|
@Component()
|
|
7
7
|
export default class PgOverlay extends HTMLElement {
|
|
8
|
-
static open(props:
|
|
8
|
+
static open<T extends typeof PgOverlay>(this: T, props: Partial<Omit<InstanceType<T>, keyof PgOverlay>>): Promise<any> {
|
|
9
9
|
var ele = document.createElement(this.name);
|
|
10
|
-
Object.assign(ele, props);
|
|
10
|
+
props && Object.assign(ele, props);
|
|
11
11
|
document.body.appendChild(ele);
|
|
12
12
|
layers.add(ele);
|
|
13
13
|
return new Promise((resolve) => {
|