@pictogrammers/components 0.5.1 → 0.5.3
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/button/__examples__/basic/basic.css +4 -0
- package/pg/button/__examples__/basic/basic.ts +3 -1
- package/pg/button/__examples__/states/states.css +3 -0
- package/pg/button/__examples__/states/states.ts +3 -1
- package/pg/button/__examples__/variants/variants.css +4 -0
- package/pg/button/__examples__/variants/variants.html +10 -0
- package/pg/button/__examples__/variants/variants.ts +13 -0
- package/pg/button/button.css +24 -14
- package/pg/button/button.ts +11 -1
- package/pg/inputPixelEditor/README.md +1 -1
- package/pg/inputPixelEditor/inputPixelEditor.ts +29 -3
- package/pg/inputPixelEditor/utils/maskToBitmap.ts +2 -2
- package/pg/inputText/inputText.css +2 -2
- 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 +3 -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.html +22 -0
- package/pg/modalConfirm/modalConfirm.ts +61 -0
- package/pg/overlay/overlay.ts +2 -2
- package/pg/overlayContextMenu/__examples__/basic/basic.ts +1 -1
package/package.json
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { Component, Part, Prop } from '@pictogrammers/element';
|
|
2
2
|
|
|
3
|
+
import style from './basic.css';
|
|
3
4
|
import template from './basic.html';
|
|
4
5
|
|
|
5
6
|
@Component({
|
|
6
7
|
selector: 'x-pg-button-basic',
|
|
7
|
-
|
|
8
|
+
style,
|
|
9
|
+
template,
|
|
8
10
|
})
|
|
9
11
|
export default class XPgButtonBasic extends HTMLElement {
|
|
10
12
|
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { Component, Part, Prop } from '@pictogrammers/element';
|
|
2
2
|
import PgButton from '../../button';
|
|
3
3
|
|
|
4
|
+
import style from './states.css';
|
|
4
5
|
import template from './states.html';
|
|
5
6
|
|
|
6
7
|
@Component({
|
|
7
8
|
selector: 'x-pg-button-states',
|
|
8
|
-
|
|
9
|
+
style,
|
|
10
|
+
template,
|
|
9
11
|
})
|
|
10
12
|
export default class XPgButtonStates extends HTMLElement {
|
|
11
13
|
@Part() $active: PgButton;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
<div class="example">
|
|
2
|
+
<div class="example-flex">
|
|
3
|
+
<pg-button variant="brand">Example Button</pg-button>
|
|
4
|
+
<pg-button variant="brand"><pg-icon path="M12,19.2C9.5,19.2 7.29,17.92 6,16C6.03,14 10,12.9 12,12.9C14,12.9 17.97,14 18,16C16.71,17.92 14.5,19.2 12,19.2M12,5A3,3 0 0,1 15,8A3,3 0 0,1 12,11A3,3 0 0,1 9,8A3,3 0 0,1 12,5M12,2A10,10 0 0,0 2,12A10,10 0 0,0 12,22A10,10 0 0,0 22,12C22,6.47 17.5,2 12,2Z"></pg-icon></pg-button>
|
|
5
|
+
<pg-button variant="brand">
|
|
6
|
+
<pg-icon path="M12,19.2C9.5,19.2 7.29,17.92 6,16C6.03,14 10,12.9 12,12.9C14,12.9 17.97,14 18,16C16.71,17.92 14.5,19.2 12,19.2M12,5A3,3 0 0,1 15,8A3,3 0 0,1 12,11A3,3 0 0,1 9,8A3,3 0 0,1 12,5M12,2A10,10 0 0,0 2,12A10,10 0 0,0 12,22A10,10 0 0,0 22,12C22,6.47 17.5,2 12,2Z"></pg-icon>
|
|
7
|
+
With Icon
|
|
8
|
+
</pg-button>
|
|
9
|
+
</div>
|
|
10
|
+
</div>
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Component, Part, Prop } from '@pictogrammers/element';
|
|
2
|
+
|
|
3
|
+
import style from './variants.css';
|
|
4
|
+
import template from './variants.html';
|
|
5
|
+
|
|
6
|
+
@Component({
|
|
7
|
+
selector: 'x-pg-button-variants',
|
|
8
|
+
style,
|
|
9
|
+
template,
|
|
10
|
+
})
|
|
11
|
+
export default class XPgVariantsBasic extends HTMLElement {
|
|
12
|
+
|
|
13
|
+
}
|
package/pg/button/button.css
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
display: inline-flex;
|
|
3
3
|
}
|
|
4
4
|
|
|
5
|
-
[part=
|
|
5
|
+
[part=button] {
|
|
6
6
|
display: flex;
|
|
7
7
|
align-items: center;
|
|
8
8
|
align-content: center;
|
|
@@ -17,25 +17,26 @@
|
|
|
17
17
|
outline: none;
|
|
18
18
|
--pg-icon-color: var(--pg-button-color, #453C4F);
|
|
19
19
|
cursor: var(--pg-button-cursor, var(--pg-cursor-default, default));
|
|
20
|
+
gap: var(--pg-button-gap, 0.325rem);
|
|
20
21
|
}
|
|
21
22
|
|
|
22
|
-
[part=
|
|
23
|
+
[part=button]:hover {
|
|
23
24
|
--pg-button-border-color: var(--pg-button-hover-border-color, #453C4F);
|
|
24
25
|
background-color: var(--pg-button-hover-background-color, #453C4F);
|
|
25
26
|
color: var(--pg-button-hover-color, #FFFFFF);
|
|
26
27
|
--pg-icon-color: var(--pg-button-hover-color, #FFFFFF);
|
|
27
28
|
}
|
|
28
29
|
|
|
29
|
-
[part=
|
|
30
|
+
[part=button]:active {
|
|
30
31
|
box-shadow: 0 1px 0.25rem rgba(0, 0, 0, 0.5) inset;
|
|
31
32
|
position: relative;
|
|
32
33
|
}
|
|
33
34
|
|
|
34
|
-
[part=
|
|
35
|
+
[part=button]:focus-visible {
|
|
35
36
|
position: relative;
|
|
36
37
|
}
|
|
37
38
|
|
|
38
|
-
[part=
|
|
39
|
+
[part=button]:active::before {
|
|
39
40
|
content: '';
|
|
40
41
|
position: absolute;
|
|
41
42
|
top: -1px;
|
|
@@ -45,7 +46,7 @@
|
|
|
45
46
|
border-radius: var(--pg-button-border-radius, 0.25rem);
|
|
46
47
|
box-shadow: 0 0 0 3px var(--pg-focus-color, rgb(79, 143, 249, 0.6));
|
|
47
48
|
}
|
|
48
|
-
[part=
|
|
49
|
+
[part=button]:focus-visible::before {
|
|
49
50
|
pointer-events: none;
|
|
50
51
|
content: '';
|
|
51
52
|
position: absolute;
|
|
@@ -57,37 +58,46 @@
|
|
|
57
58
|
box-shadow: 0 0 0 3px var(--pg-focus-color, rgb(79, 143, 249, 0.5));
|
|
58
59
|
}
|
|
59
60
|
|
|
60
|
-
[part=
|
|
61
|
+
[part=button].start {
|
|
61
62
|
border-top-right-radius: 0;
|
|
62
63
|
border-bottom-right-radius: 0;
|
|
63
64
|
margin-right: -1px;
|
|
64
65
|
}
|
|
65
66
|
|
|
66
|
-
[part=
|
|
67
|
+
[part=button].center {
|
|
67
68
|
border-radius: 0;
|
|
68
69
|
margin-right: -1px;
|
|
69
70
|
}
|
|
70
71
|
|
|
71
|
-
[part=
|
|
72
|
+
[part=button].end {
|
|
72
73
|
border-top-left-radius: 0;
|
|
73
74
|
border-bottom-left-radius: 0;
|
|
74
75
|
}
|
|
75
76
|
|
|
76
|
-
[part=
|
|
77
|
+
[part=button].active {
|
|
77
78
|
box-shadow: 0 1px 0.25rem rgba(0, 0, 0, 0.5) inset;
|
|
78
79
|
background-color: rgba(69, 60, 79, 0.1);
|
|
79
80
|
color: var(--pg-button-color, #453C4F);
|
|
80
81
|
}
|
|
81
|
-
[part=
|
|
82
|
+
[part=button].active:hover {
|
|
82
83
|
box-shadow: 0 1px 0.25rem rgba(0, 0, 0, 0.5) inset;
|
|
83
84
|
background-color: var(--pg-button-color, #453C4F);
|
|
84
|
-
color: var(--pg-button-hover-color, #
|
|
85
|
+
color: var(--pg-button-hover-color, #FFFFFF);
|
|
85
86
|
}
|
|
86
87
|
|
|
87
|
-
[part=
|
|
88
|
+
[part=button].block {
|
|
88
89
|
flex: 1;
|
|
89
90
|
}
|
|
90
91
|
|
|
92
|
+
[part=button].brand {
|
|
93
|
+
--pg-button-background-color: #453C4F;
|
|
94
|
+
--pg-button-color: #FFFFFF;
|
|
95
|
+
}
|
|
96
|
+
[part=button].brand:hover {
|
|
97
|
+
--pg-button-hover-background-color: color-mix(in oklab, var(--pg-button-background-color), white 10%);
|
|
98
|
+
--pg-button-hover-border-color: color-mix(in oklab, var(--pg-button-background-color), white 10%);
|
|
99
|
+
}
|
|
100
|
+
|
|
91
101
|
::slotted {
|
|
92
102
|
align-self: center;
|
|
93
|
-
}
|
|
103
|
+
}
|
package/pg/button/button.ts
CHANGED
|
@@ -1,14 +1,17 @@
|
|
|
1
|
-
import { Component, Part, Prop, normalizeBoolean } from '@pictogrammers/element';
|
|
1
|
+
import { Component, Part, Prop, normalizeBoolean, normalizeString } from '@pictogrammers/element';
|
|
2
2
|
|
|
3
3
|
import template from './button.html';
|
|
4
4
|
import style from './button.css';
|
|
5
5
|
|
|
6
|
+
const variants = ['neutral', 'brand'];
|
|
7
|
+
|
|
6
8
|
@Component({
|
|
7
9
|
selector: 'pg-button',
|
|
8
10
|
style,
|
|
9
11
|
template
|
|
10
12
|
})
|
|
11
13
|
export default class PgButton extends HTMLElement {
|
|
14
|
+
@Prop(normalizeString) variant: string = 'neutral';
|
|
12
15
|
@Prop(normalizeBoolean) active: boolean = false;
|
|
13
16
|
@Prop(normalizeBoolean) block: boolean = false;
|
|
14
17
|
@Prop(normalizeBoolean) start: boolean = false;
|
|
@@ -27,6 +30,13 @@ export default class PgButton extends HTMLElement {
|
|
|
27
30
|
}
|
|
28
31
|
|
|
29
32
|
render(changes) {
|
|
33
|
+
if (changes.variant) {
|
|
34
|
+
if (!variants.includes(this.variant)) {
|
|
35
|
+
throw new Error(`invalid variant ${this.variant}`);
|
|
36
|
+
}
|
|
37
|
+
this.$button.classList.toggle('neutral', this.variant === 'neutral');
|
|
38
|
+
this.$button.classList.toggle('brand', this.variant === 'brand');
|
|
39
|
+
}
|
|
30
40
|
if (changes.active) {
|
|
31
41
|
this.$button.classList.toggle('active', this.active);
|
|
32
42
|
}
|
|
@@ -70,7 +70,7 @@ See usage for each method below.
|
|
|
70
70
|
| `inputModeEllipseOutline()` | - | Input Mode Ellipse Outline |
|
|
71
71
|
| `selectLayer(index)` | - | Select layer. |
|
|
72
72
|
| `getLayers()` | - | Get layer array. |
|
|
73
|
-
| `addLayer(option)` | - | Add layer. |
|
|
73
|
+
| `addLayer(option)` | - | Add layer. `name`, `type` required. |
|
|
74
74
|
| `removeLayer(index)` | - | Remove layer. |
|
|
75
75
|
| `flattenLayers(layerIndexes)` | - | Flatten layers. |
|
|
76
76
|
| `getColor()` | - | Get selected color |
|
|
@@ -23,6 +23,7 @@ import { readMetadata, textEncode, writeMetadata } from './utils/pngMetadata';
|
|
|
23
23
|
import { canvasToPngBuffer } from './utils/canvasToPngBuffer';
|
|
24
24
|
import { blobToImage } from './utils/blobToImage';
|
|
25
25
|
import { diffLeftMapPixels } from './utils/diffMap';
|
|
26
|
+
import { maskToBitmap } from './utils/maskToBitmap';
|
|
26
27
|
|
|
27
28
|
type Color = [number, number, number, number];
|
|
28
29
|
|
|
@@ -57,7 +58,7 @@ type HistoryColorUpdateType = {
|
|
|
57
58
|
}
|
|
58
59
|
|
|
59
60
|
type HistoryItem = {
|
|
60
|
-
type: HistoryType
|
|
61
|
+
type: HistoryType
|
|
61
62
|
data: HistoryGroupType | HistoryPixelType | HistoryColorUpdateType
|
|
62
63
|
}
|
|
63
64
|
|
|
@@ -1375,8 +1376,12 @@ export default class PgInputPixelEditor extends HTMLElement {
|
|
|
1375
1376
|
export: optional.exclude ?? true,
|
|
1376
1377
|
locked: optional.locked ?? false,
|
|
1377
1378
|
visible: optional.hidden ?? true,
|
|
1378
|
-
opacity: 1
|
|
1379
|
+
opacity: optional.opacity ?? 1,
|
|
1379
1380
|
});
|
|
1381
|
+
// short hand for initial data
|
|
1382
|
+
if (optional.data) {
|
|
1383
|
+
this.setData(optional.data);
|
|
1384
|
+
}
|
|
1380
1385
|
}
|
|
1381
1386
|
|
|
1382
1387
|
/**
|
|
@@ -1467,7 +1472,28 @@ export default class PgInputPixelEditor extends HTMLElement {
|
|
|
1467
1472
|
* Set data
|
|
1468
1473
|
*/
|
|
1469
1474
|
setData(data: any[]) {
|
|
1470
|
-
|
|
1475
|
+
data.forEach((layerData, layerIndex) => {
|
|
1476
|
+
const { type } = this.#layers[layerIndex];
|
|
1477
|
+
switch(type) {
|
|
1478
|
+
case 'pixel':
|
|
1479
|
+
const { color, path } = layerData;
|
|
1480
|
+
const temp = maskToBitmap(path, this.width, this.height);
|
|
1481
|
+
temp.forEach((tempY, y) => {
|
|
1482
|
+
tempY.forEach((tempX, x) => {
|
|
1483
|
+
if (tempX !== 0) {
|
|
1484
|
+
//this.#data[layerIndex][y][x] = color;
|
|
1485
|
+
this.#setPixel(x, y, color, [layerIndex]);
|
|
1486
|
+
}
|
|
1487
|
+
});
|
|
1488
|
+
});
|
|
1489
|
+
break;
|
|
1490
|
+
case 'reference':
|
|
1491
|
+
console.log('reference', layerData);
|
|
1492
|
+
break;
|
|
1493
|
+
default:
|
|
1494
|
+
throw new Error(`unknown type ${type}`);
|
|
1495
|
+
}
|
|
1496
|
+
});
|
|
1471
1497
|
}
|
|
1472
1498
|
|
|
1473
1499
|
getExportPath() {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export function maskToBitmap(pathData: string, width: number, height: number) {
|
|
1
|
+
export function maskToBitmap(pathData: string, width: number, height: number, fill: number = 1) {
|
|
2
2
|
const grid: number[][] = Array(height).fill(0).map(() => Array(width).fill(0));
|
|
3
3
|
|
|
4
4
|
// Store only the vertical edges
|
|
@@ -57,7 +57,7 @@ export function maskToBitmap(pathData: string, width: number, height: number) {
|
|
|
57
57
|
}
|
|
58
58
|
}
|
|
59
59
|
if (inside) {
|
|
60
|
-
grid[y][x] =
|
|
60
|
+
grid[y][x] = fill;
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
63
|
}
|
|
@@ -11,8 +11,8 @@
|
|
|
11
11
|
font-size: 1rem;
|
|
12
12
|
outline: none;
|
|
13
13
|
field-sizing: content;
|
|
14
|
-
min-width: calc(100% -
|
|
15
|
-
max-width: calc(var(--pg-input-text-max-width, 100%) -
|
|
14
|
+
min-width: calc(100% - 1.5rem - 2px);
|
|
15
|
+
max-width: calc(var(--pg-input-text-max-width, 100%) - 1.5rem - 2px);
|
|
16
16
|
background-color: transparent;
|
|
17
17
|
}
|
|
18
18
|
|
|
@@ -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
|
}
|
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
<div class="dialog"
|
|
3
3
|
role="dialog"
|
|
4
4
|
id="dialog1"
|
|
5
|
-
aria-labelledby="
|
|
5
|
+
aria-labelledby="dialog_label"
|
|
6
6
|
aria-modal="true">
|
|
7
7
|
<header part="header">
|
|
8
|
-
<h2 id="
|
|
8
|
+
<h2 id="dialog_label"
|
|
9
9
|
class="dialog_label"
|
|
10
10
|
part="headerText">
|
|
11
11
|
Add Delivery Address
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
</main>
|
|
17
17
|
<footer>
|
|
18
18
|
<pg-button part="no">No</pg-button>
|
|
19
|
-
<pg-button part="yes">Yes</pg-button>
|
|
19
|
+
<pg-button part="yes" variant="brand">Yes</pg-button>
|
|
20
20
|
</footer>
|
|
21
21
|
</div>
|
|
22
22
|
</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,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) => {
|