@italia/popover 1.0.0-beta.0 → 1.0.0-beta.2
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/README.md +6 -62
- package/custom-elements.json +15 -0
- package/dist/src/it-popover.d.ts +1 -0
- package/dist/src/it-popover.d.ts.map +1 -1
- package/dist/src/it-popover.js +17 -6
- package/dist/src/it-popover.js.map +1 -1
- package/package.json +8 -8
package/README.md
CHANGED
|
@@ -1,67 +1,11 @@
|
|
|
1
|
-
#
|
|
1
|
+
# <it-popover>
|
|
2
2
|
|
|
3
|
-
This
|
|
3
|
+
This package is part of [dev-kit-italia](https://italia.github.io/dev-kit-italia), a Web Components kit for the **.italia** design-system.
|
|
4
4
|
|
|
5
|
-
## Installation
|
|
5
|
+
## Installation and usage
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
npm i @italia/popover
|
|
9
|
-
```
|
|
7
|
+
Most users want to install the full kit by installing [`@italia/dev-kit-italia`](https://npmjs.com/package/@italia/dev-kit-italia), but you have the option of installing this single Web Component separately if needed. Please find detailed installation and usage instructions in the [official documentation](https://italia.github.io/dev-kit-italia/?path=/docs/introduzione--documentazione).
|
|
10
8
|
|
|
11
|
-
##
|
|
9
|
+
## Documentation
|
|
12
10
|
|
|
13
|
-
|
|
14
|
-
<script type="module">
|
|
15
|
-
import '@italia/popover';
|
|
16
|
-
</script>
|
|
17
|
-
|
|
18
|
-
<it-popover></it-popover>
|
|
19
|
-
```
|
|
20
|
-
|
|
21
|
-
## Linting and formatting
|
|
22
|
-
|
|
23
|
-
To scan the project for linting and formatting errors, run
|
|
24
|
-
|
|
25
|
-
```bash
|
|
26
|
-
npm run lint
|
|
27
|
-
```
|
|
28
|
-
|
|
29
|
-
To automatically fix linting and formatting errors, run
|
|
30
|
-
|
|
31
|
-
```bash
|
|
32
|
-
npm run format
|
|
33
|
-
```
|
|
34
|
-
|
|
35
|
-
## Testing with Web Test Runner
|
|
36
|
-
|
|
37
|
-
To execute a single test run:
|
|
38
|
-
|
|
39
|
-
```bash
|
|
40
|
-
npm run test
|
|
41
|
-
```
|
|
42
|
-
|
|
43
|
-
To run the tests in interactive watch mode run:
|
|
44
|
-
|
|
45
|
-
```bash
|
|
46
|
-
npm run test:watch
|
|
47
|
-
```
|
|
48
|
-
|
|
49
|
-
## Demoing with Storybook
|
|
50
|
-
|
|
51
|
-
To run a local instance of Storybook for your component, run
|
|
52
|
-
|
|
53
|
-
```bash
|
|
54
|
-
npm run storybook
|
|
55
|
-
```
|
|
56
|
-
|
|
57
|
-
To build a production version of Storybook, run
|
|
58
|
-
|
|
59
|
-
```bash
|
|
60
|
-
npm run storybook:build
|
|
61
|
-
```
|
|
62
|
-
|
|
63
|
-
## Tooling configs
|
|
64
|
-
|
|
65
|
-
For most of the tools, the configuration is in the `package.json` to reduce the amount of files in your project.
|
|
66
|
-
|
|
67
|
-
If you customize the configuration a lot, you can consider moving them to individual files.
|
|
11
|
+
Find the usage instructions for this specific component in its [dedicated documentation page](https://italia.github.io/dev-kit-italia/?path=/docs/componenti-popover--documentazione).
|
package/custom-elements.json
CHANGED
|
@@ -63,6 +63,14 @@
|
|
|
63
63
|
"default": "12",
|
|
64
64
|
"attribute": "offset"
|
|
65
65
|
},
|
|
66
|
+
{
|
|
67
|
+
"kind": "field",
|
|
68
|
+
"name": "crossAxisOffset",
|
|
69
|
+
"type": {
|
|
70
|
+
"text": "number | undefined"
|
|
71
|
+
},
|
|
72
|
+
"attribute": "cross-axis-offset"
|
|
73
|
+
},
|
|
66
74
|
{
|
|
67
75
|
"kind": "field",
|
|
68
76
|
"name": "noFlip",
|
|
@@ -224,6 +232,13 @@
|
|
|
224
232
|
"default": "12",
|
|
225
233
|
"fieldName": "offset"
|
|
226
234
|
},
|
|
235
|
+
{
|
|
236
|
+
"name": "cross-axis-offset",
|
|
237
|
+
"type": {
|
|
238
|
+
"text": "number | undefined"
|
|
239
|
+
},
|
|
240
|
+
"fieldName": "crossAxisOffset"
|
|
241
|
+
},
|
|
227
242
|
{
|
|
228
243
|
"name": "no-flip",
|
|
229
244
|
"type": {
|
package/dist/src/it-popover.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ export declare class ItPopover extends BaseComponent {
|
|
|
8
8
|
controlled: boolean;
|
|
9
9
|
placement: PopoverPlacement;
|
|
10
10
|
offset: number;
|
|
11
|
+
crossAxisOffset?: number;
|
|
11
12
|
noFlip: boolean;
|
|
12
13
|
/** Centre the arrow on the trigger instead of the fixed notch position. Used by avatar dropdowns. */
|
|
13
14
|
centerArrow: boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"it-popover.d.ts","sourceRoot":"","sources":["../../src/it-popover.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD,OAAO,EAAQ,cAAc,EAAE,MAAM,KAAK,CAAC;AAC3C,OAAO,EAA2D,KAAK,SAAS,EAAe,MAAM,kBAAkB,CAAC;AAGxH,KAAK,gBAAgB,GAAG,SAAS,CAAC;AAElC,qBACa,SAAU,SAAQ,aAAa;IAC1C,MAAM,CAAC,MAAM,+BAAU;IAEqB,IAAI,UAAS;IAE5B,UAAU,UAAS;IAEpB,SAAS,EAAE,gBAAgB,CAAkB;IAE7C,MAAM,EAAE,MAAM,CAAM;
|
|
1
|
+
{"version":3,"file":"it-popover.d.ts","sourceRoot":"","sources":["../../src/it-popover.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD,OAAO,EAAQ,cAAc,EAAE,MAAM,KAAK,CAAC;AAC3C,OAAO,EAA2D,KAAK,SAAS,EAAe,MAAM,kBAAkB,CAAC;AAGxH,KAAK,gBAAgB,GAAG,SAAS,CAAC;AAElC,qBACa,SAAU,SAAQ,aAAa;IAC1C,MAAM,CAAC,MAAM,+BAAU;IAEqB,IAAI,UAAS;IAE5B,UAAU,UAAS;IAEpB,SAAS,EAAE,gBAAgB,CAAkB;IAE7C,MAAM,EAAE,MAAM,CAAM;IAEY,eAAe,CAAC,EAAE,MAAM,CAAC;IAElC,MAAM,EAAE,OAAO,CAAS;IAE3E,qGAAqG;IAC7C,WAAW,EAAE,OAAO,CAAS;IAEtD,OAAO,CAAC,YAAY,CAAmB;IAEvC,OAAO,CAAC,YAAY,CAAmB;IAEtE,OAAO,KAAK,eAAe,GAE1B;IAED,OAAO,KAAK,eAAe,GAE1B;IAED,OAAO,CAAC,aAAa,CAAC,CAAc;IAEpC,OAAO,CAAC,QAAQ,CAAC,CAAa;IAE9B,OAAO,CAAC,sBAAsB;IAwB9B,SAAS,CAAC,mBAAmB;IAoB7B,oBAAoB;IAMpB,SAAS,CAAC,YAAY,CAAC,kBAAkB,EAAE,cAAc,GAAG,IAAI;IAKhE,OAAO,CAAC,YAAY,EAAE,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC;IAatC,OAAO,CAAC,YAAY;IAWpB,OAAO,CAAC,KAAK;IA0Eb,OAAO,CAAC,KAAK;IAKb,OAAO,CAAC,gBAAgB,CAQtB;IAEF,OAAO,CAAC,aAAa;IAId,MAAM;IAIN,WAAW;IAIX,YAAY;IAInB,MAAM;CAMP;AAED,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,qBAAqB;QAC7B,YAAY,EAAE,SAAS,CAAC;KACzB;CACF"}
|
package/dist/src/it-popover.js
CHANGED
|
@@ -1176,7 +1176,7 @@ if (typeof window !== 'undefined') {
|
|
|
1176
1176
|
window._itAnalytics = window._itAnalytics || {};
|
|
1177
1177
|
window._itAnalytics = {
|
|
1178
1178
|
...window._itAnalytics,
|
|
1179
|
-
version: '1.0.0-beta.
|
|
1179
|
+
version: '1.0.0-beta.2',
|
|
1180
1180
|
};
|
|
1181
1181
|
}
|
|
1182
1182
|
|
|
@@ -2905,6 +2905,7 @@ let ItPopover = class ItPopover extends BaseComponent {
|
|
|
2905
2905
|
if (!this._arrowElement) {
|
|
2906
2906
|
this._arrowElement = document.createElement('div');
|
|
2907
2907
|
this._arrowElement.className = 'arrow';
|
|
2908
|
+
this._arrowElement.part = 'popover-arrow';
|
|
2908
2909
|
this._contentElement.prepend(this._arrowElement);
|
|
2909
2910
|
}
|
|
2910
2911
|
}
|
|
@@ -2918,10 +2919,13 @@ let ItPopover = class ItPopover extends BaseComponent {
|
|
|
2918
2919
|
computePosition(this._triggerElement, this._contentElement, {
|
|
2919
2920
|
placement: this.placement,
|
|
2920
2921
|
middleware: [
|
|
2921
|
-
offset(
|
|
2922
|
+
offset({
|
|
2923
|
+
mainAxis: this.offset,
|
|
2924
|
+
crossAxis: this.crossAxisOffset,
|
|
2925
|
+
}),
|
|
2922
2926
|
flip({ mainAxis: !this.noFlip, crossAxis: !this.noFlip }),
|
|
2923
2927
|
shift({ padding: 8 }),
|
|
2924
|
-
// Commentato perchè nella toolbar con dropdown che ha position absolute, vogliamo il min-width impostato da css con var(
|
|
2928
|
+
// Commentato perchè nella toolbar con dropdown che ha position absolute, vogliamo il min-width impostato da css con var(--<prefix>dropdown-min-width)
|
|
2925
2929
|
// size({
|
|
2926
2930
|
// apply({ rects, elements }) {
|
|
2927
2931
|
// Object.assign(elements.floating.style, {
|
|
@@ -2938,12 +2942,13 @@ let ItPopover = class ItPopover extends BaseComponent {
|
|
|
2938
2942
|
});
|
|
2939
2943
|
if (middlewareData.arrow) {
|
|
2940
2944
|
const { x: arrowX, y: arrowY } = middlewareData.arrow;
|
|
2945
|
+
const placementSide = placement.split('-')[0];
|
|
2941
2946
|
const staticSide = {
|
|
2942
2947
|
top: 'bottom',
|
|
2943
2948
|
right: 'left',
|
|
2944
2949
|
bottom: 'top',
|
|
2945
2950
|
left: 'right',
|
|
2946
|
-
}[
|
|
2951
|
+
}[placementSide];
|
|
2947
2952
|
const triggerRect = this._triggerElement.getBoundingClientRect();
|
|
2948
2953
|
const contentRect = this._contentElement.getBoundingClientRect();
|
|
2949
2954
|
const triggerCenter = triggerRect.left + triggerRect.width / 2;
|
|
@@ -2951,10 +2956,12 @@ let ItPopover = class ItPopover extends BaseComponent {
|
|
|
2951
2956
|
// When `centerArrow` is set (e.g. avatar dropdowns), centre the arrow
|
|
2952
2957
|
// on the trigger using Floating UI's computed offset. Otherwise keep
|
|
2953
2958
|
// the fixed notch position relied on by standard dropdowns.
|
|
2954
|
-
const left = this.centerArrow ? arrowX : arrowLeft;
|
|
2959
|
+
const left = this.centerArrow ? arrowX : arrowLeft + (this.crossAxisOffset ?? 0);
|
|
2960
|
+
const isLeftOrRight = ['left', 'right'].includes(placementSide);
|
|
2961
|
+
const additionalOffsetTop = isLeftOrRight ? (this.crossAxisOffset ?? 0) : 0;
|
|
2955
2962
|
Object.assign(this._arrowElement.style, {
|
|
2956
2963
|
left: arrowX != null ? `${left}px` : '',
|
|
2957
|
-
top: arrowY != null ? `${arrowY}px` : '',
|
|
2964
|
+
top: arrowY != null ? `${arrowY + additionalOffsetTop}px` : '',
|
|
2958
2965
|
right: '',
|
|
2959
2966
|
bottom: '',
|
|
2960
2967
|
[staticSide]: `-8px`,
|
|
@@ -3006,6 +3013,10 @@ __decorate([
|
|
|
3006
3013
|
property({ type: Number }),
|
|
3007
3014
|
__metadata("design:type", Number)
|
|
3008
3015
|
], ItPopover.prototype, "offset", void 0);
|
|
3016
|
+
__decorate([
|
|
3017
|
+
property({ type: Number, attribute: 'cross-axis-offset' }),
|
|
3018
|
+
__metadata("design:type", Number)
|
|
3019
|
+
], ItPopover.prototype, "crossAxisOffset", void 0);
|
|
3009
3020
|
__decorate([
|
|
3010
3021
|
property({ type: Boolean, attribute: 'no-flip' }),
|
|
3011
3022
|
__metadata("design:type", Boolean)
|