@italia/popover 1.0.0-alpha.5 → 1.0.0-alpha.7

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.
@@ -54,6 +54,24 @@
54
54
  "default": "'bottom-start'",
55
55
  "attribute": "placement"
56
56
  },
57
+ {
58
+ "kind": "field",
59
+ "name": "offset",
60
+ "type": {
61
+ "text": "number"
62
+ },
63
+ "default": "12",
64
+ "attribute": "offset"
65
+ },
66
+ {
67
+ "kind": "field",
68
+ "name": "noFlip",
69
+ "type": {
70
+ "text": "boolean"
71
+ },
72
+ "default": "false",
73
+ "attribute": "no-flip"
74
+ },
57
75
  {
58
76
  "kind": "field",
59
77
  "name": "_triggerSlot",
@@ -187,6 +205,22 @@
187
205
  },
188
206
  "default": "'bottom-start'",
189
207
  "fieldName": "placement"
208
+ },
209
+ {
210
+ "name": "offset",
211
+ "type": {
212
+ "text": "number"
213
+ },
214
+ "default": "12",
215
+ "fieldName": "offset"
216
+ },
217
+ {
218
+ "name": "no-flip",
219
+ "type": {
220
+ "text": "boolean"
221
+ },
222
+ "default": "false",
223
+ "fieldName": "noFlip"
190
224
  }
191
225
  ],
192
226
  "superclass": {
@@ -223,7 +257,7 @@
223
257
  {
224
258
  "kind": "variable",
225
259
  "name": "meta",
226
- "default": "{ title: 'Componenti/Popover', component: 'it-popover', tags: ['alpha', 'web-component', 'a11y-ok'], args: { placement: 'right', }, argTypes: { placement: { control: 'select', options: [ 'top', 'right', 'bottom', 'left', 'top-start', 'top-end', 'right-start', 'right-end', 'bottom-start', 'bottom-end', 'left-start', 'left-end', ], table: { defaultValue: { summary: 'bottom-start' }, }, }, }, parameters: { layout: 'padded', docs: { source: { excludeDecorators: true }, }, }, } satisfies Meta<PopoverProps>"
260
+ "default": "{ title: 'Componenti/Popover', component: 'it-popover', tags: ['new', 'web-component', 'a11y-ok'], args: { placement: 'right', }, argTypes: { placement: { control: 'select', options: [ 'top', 'right', 'bottom', 'left', 'top-start', 'top-end', 'right-start', 'right-end', 'bottom-start', 'bottom-end', 'left-start', 'left-end', ], table: { defaultValue: { summary: 'bottom-start' }, }, }, }, parameters: { layout: 'padded', }, } satisfies Meta<PopoverProps>"
227
261
  },
228
262
  {
229
263
  "kind": "variable",
@@ -7,6 +7,8 @@ export declare class ItPopover extends BaseComponent {
7
7
  open: boolean;
8
8
  controlled: boolean;
9
9
  placement: PopoverPlacement;
10
+ offset: number;
11
+ noFlip: boolean;
10
12
  private _triggerSlot;
11
13
  private _contentSlot;
12
14
  private get _triggerElement();
@@ -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,EAAQ,MAAM,kBAAkB,CAAC;AAGjH,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;IAE1C,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;IAUpB,OAAO,CAAC,KAAK;IAuDb,OAAO,C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M;IAIN,WAAW;IAIX,YAAY;IAInB,MAAM;CAMP;AAED,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,qBAAqB;QAC7B,YAAY,EAAE,SAAS,CAAC;KACzB;CACF"}
@@ -459,6 +459,7 @@ class FormControlController {
459
459
  }
460
460
  break;
461
461
  case 'it-checkbox':
462
+ case 'it-toggle':
462
463
  if (this.host.checked) {
463
464
  if (event.formData.getAll(name).indexOf(value) < 0) {
464
465
  // handle group checkbox
@@ -467,6 +468,7 @@ class FormControlController {
467
468
  }
468
469
  break;
469
470
  case 'it-checkbox-group':
471
+ case 'it-toggle-group':
470
472
  // non settare valori in formData, perchè ogni singola checkbox setta il suo valore
471
473
  break;
472
474
  default:
@@ -1078,7 +1080,7 @@ if (typeof window !== 'undefined') {
1078
1080
  window._itAnalytics = window._itAnalytics || {};
1079
1081
  window._itAnalytics = {
1080
1082
  ...window._itAnalytics,
1081
- version: '1.0.0-alpha.5',
1083
+ version: '1.0.0-alpha.7',
1082
1084
  };
1083
1085
  }
1084
1086
 
@@ -1273,6 +1275,71 @@ function computeCoordsFromPlacement(_ref, placement, rtl) {
1273
1275
  return coords;
1274
1276
  }
1275
1277
 
1278
+ /**
1279
+ * Resolves with an object of overflow side offsets that determine how much the
1280
+ * element is overflowing a given clipping boundary on each side.
1281
+ * - positive = overflowing the boundary by that number of pixels
1282
+ * - negative = how many pixels left before it will overflow
1283
+ * - 0 = lies flush with the boundary
1284
+ * @see https://floating-ui.com/docs/detectOverflow
1285
+ */
1286
+ async function detectOverflow(state, options) {
1287
+ var _await$platform$isEle;
1288
+ if (options === void 0) {
1289
+ options = {};
1290
+ }
1291
+ const {
1292
+ x,
1293
+ y,
1294
+ platform,
1295
+ rects,
1296
+ elements,
1297
+ strategy
1298
+ } = state;
1299
+ const {
1300
+ boundary = 'clippingAncestors',
1301
+ rootBoundary = 'viewport',
1302
+ elementContext = 'floating',
1303
+ altBoundary = false,
1304
+ padding = 0
1305
+ } = evaluate(options, state);
1306
+ const paddingObject = getPaddingObject(padding);
1307
+ const altContext = elementContext === 'floating' ? 'reference' : 'floating';
1308
+ const element = elements[altBoundary ? altContext : elementContext];
1309
+ const clippingClientRect = rectToClientRect(await platform.getClippingRect({
1310
+ element: ((_await$platform$isEle = await (platform.isElement == null ? void 0 : platform.isElement(element))) != null ? _await$platform$isEle : true) ? element : element.contextElement || (await (platform.getDocumentElement == null ? void 0 : platform.getDocumentElement(elements.floating))),
1311
+ boundary,
1312
+ rootBoundary,
1313
+ strategy
1314
+ }));
1315
+ const rect = elementContext === 'floating' ? {
1316
+ x,
1317
+ y,
1318
+ width: rects.floating.width,
1319
+ height: rects.floating.height
1320
+ } : rects.reference;
1321
+ const offsetParent = await (platform.getOffsetParent == null ? void 0 : platform.getOffsetParent(elements.floating));
1322
+ const offsetScale = (await (platform.isElement == null ? void 0 : platform.isElement(offsetParent))) ? (await (platform.getScale == null ? void 0 : platform.getScale(offsetParent))) || {
1323
+ x: 1,
1324
+ y: 1
1325
+ } : {
1326
+ x: 1,
1327
+ y: 1
1328
+ };
1329
+ const elementClientRect = rectToClientRect(platform.convertOffsetParentRelativeRectToViewportRelativeRect ? await platform.convertOffsetParentRelativeRectToViewportRelativeRect({
1330
+ elements,
1331
+ rect,
1332
+ offsetParent,
1333
+ strategy
1334
+ }) : rect);
1335
+ return {
1336
+ top: (clippingClientRect.top - elementClientRect.top + paddingObject.top) / offsetScale.y,
1337
+ bottom: (elementClientRect.bottom - clippingClientRect.bottom + paddingObject.bottom) / offsetScale.y,
1338
+ left: (clippingClientRect.left - elementClientRect.left + paddingObject.left) / offsetScale.x,
1339
+ right: (elementClientRect.right - clippingClientRect.right + paddingObject.right) / offsetScale.x
1340
+ };
1341
+ }
1342
+
1276
1343
  /**
1277
1344
  * Computes the `x` and `y` coordinates that will place the floating element
1278
1345
  * next to a given reference element.
@@ -1302,6 +1369,7 @@ const computePosition$1 = async (reference, floating, config) => {
1302
1369
  let middlewareData = {};
1303
1370
  let resetCount = 0;
1304
1371
  for (let i = 0; i < validMiddleware.length; i++) {
1372
+ var _platform$detectOverf;
1305
1373
  const {
1306
1374
  name,
1307
1375
  fn
@@ -1319,7 +1387,10 @@ const computePosition$1 = async (reference, floating, config) => {
1319
1387
  strategy,
1320
1388
  middlewareData,
1321
1389
  rects,
1322
- platform,
1390
+ platform: {
1391
+ ...platform,
1392
+ detectOverflow: (_platform$detectOverf = platform.detectOverflow) != null ? _platform$detectOverf : detectOverflow
1393
+ },
1323
1394
  elements: {
1324
1395
  reference,
1325
1396
  floating
@@ -1364,71 +1435,6 @@ const computePosition$1 = async (reference, floating, config) => {
1364
1435
  };
1365
1436
  };
1366
1437
 
1367
- /**
1368
- * Resolves with an object of overflow side offsets that determine how much the
1369
- * element is overflowing a given clipping boundary on each side.
1370
- * - positive = overflowing the boundary by that number of pixels
1371
- * - negative = how many pixels left before it will overflow
1372
- * - 0 = lies flush with the boundary
1373
- * @see https://floating-ui.com/docs/detectOverflow
1374
- */
1375
- async function detectOverflow(state, options) {
1376
- var _await$platform$isEle;
1377
- if (options === void 0) {
1378
- options = {};
1379
- }
1380
- const {
1381
- x,
1382
- y,
1383
- platform,
1384
- rects,
1385
- elements,
1386
- strategy
1387
- } = state;
1388
- const {
1389
- boundary = 'clippingAncestors',
1390
- rootBoundary = 'viewport',
1391
- elementContext = 'floating',
1392
- altBoundary = false,
1393
- padding = 0
1394
- } = evaluate(options, state);
1395
- const paddingObject = getPaddingObject(padding);
1396
- const altContext = elementContext === 'floating' ? 'reference' : 'floating';
1397
- const element = elements[altBoundary ? altContext : elementContext];
1398
- const clippingClientRect = rectToClientRect(await platform.getClippingRect({
1399
- element: ((_await$platform$isEle = await (platform.isElement == null ? void 0 : platform.isElement(element))) != null ? _await$platform$isEle : true) ? element : element.contextElement || (await (platform.getDocumentElement == null ? void 0 : platform.getDocumentElement(elements.floating))),
1400
- boundary,
1401
- rootBoundary,
1402
- strategy
1403
- }));
1404
- const rect = elementContext === 'floating' ? {
1405
- x,
1406
- y,
1407
- width: rects.floating.width,
1408
- height: rects.floating.height
1409
- } : rects.reference;
1410
- const offsetParent = await (platform.getOffsetParent == null ? void 0 : platform.getOffsetParent(elements.floating));
1411
- const offsetScale = (await (platform.isElement == null ? void 0 : platform.isElement(offsetParent))) ? (await (platform.getScale == null ? void 0 : platform.getScale(offsetParent))) || {
1412
- x: 1,
1413
- y: 1
1414
- } : {
1415
- x: 1,
1416
- y: 1
1417
- };
1418
- const elementClientRect = rectToClientRect(platform.convertOffsetParentRelativeRectToViewportRelativeRect ? await platform.convertOffsetParentRelativeRectToViewportRelativeRect({
1419
- elements,
1420
- rect,
1421
- offsetParent,
1422
- strategy
1423
- }) : rect);
1424
- return {
1425
- top: (clippingClientRect.top - elementClientRect.top + paddingObject.top) / offsetScale.y,
1426
- bottom: (elementClientRect.bottom - clippingClientRect.bottom + paddingObject.bottom) / offsetScale.y,
1427
- left: (clippingClientRect.left - elementClientRect.left + paddingObject.left) / offsetScale.x,
1428
- right: (elementClientRect.right - clippingClientRect.right + paddingObject.right) / offsetScale.x
1429
- };
1430
- }
1431
-
1432
1438
  /**
1433
1439
  * Provides data to position an inner element of the floating element so that it
1434
1440
  * appears centered to the reference element.
@@ -1561,7 +1567,7 @@ const flip$1 = function (options) {
1561
1567
  fallbackPlacements.push(...getOppositeAxisPlacements(initialPlacement, flipAlignment, fallbackAxisSideDirection, rtl));
1562
1568
  }
1563
1569
  const placements = [initialPlacement, ...fallbackPlacements];
1564
- const overflow = await detectOverflow(state, detectOverflowOptions);
1570
+ const overflow = await platform.detectOverflow(state, detectOverflowOptions);
1565
1571
  const overflows = [];
1566
1572
  let overflowsData = ((_middlewareData$flip = middlewareData.flip) == null ? void 0 : _middlewareData$flip.overflows) || [];
1567
1573
  if (checkMainAxis) {
@@ -1745,7 +1751,8 @@ const shift$1 = function (options) {
1745
1751
  const {
1746
1752
  x,
1747
1753
  y,
1748
- placement
1754
+ placement,
1755
+ platform
1749
1756
  } = state;
1750
1757
  const {
1751
1758
  mainAxis: checkMainAxis = true,
@@ -1768,7 +1775,7 @@ const shift$1 = function (options) {
1768
1775
  x,
1769
1776
  y
1770
1777
  };
1771
- const overflow = await detectOverflow(state, detectOverflowOptions);
1778
+ const overflow = await platform.detectOverflow(state, detectOverflowOptions);
1772
1779
  const crossAxis = getSideAxis(getSide(placement));
1773
1780
  const mainAxis = getOppositeAxis(crossAxis);
1774
1781
  let mainAxisCoord = coords[mainAxis];
@@ -1832,7 +1839,7 @@ const size$1 = function (options) {
1832
1839
  apply = () => {},
1833
1840
  ...detectOverflowOptions
1834
1841
  } = evaluate(options, state);
1835
- const overflow = await detectOverflow(state, detectOverflowOptions);
1842
+ const overflow = await platform.detectOverflow(state, detectOverflowOptions);
1836
1843
  const side = getSide(placement);
1837
1844
  const alignment = getAlignment(placement);
1838
1845
  const isYAxis = getSideAxis(placement) === 'y';
@@ -2808,6 +2815,8 @@ let ItPopover = class ItPopover extends BaseComponent {
2808
2815
  this.open = false;
2809
2816
  this.controlled = false;
2810
2817
  this.placement = 'bottom-start';
2818
+ this.offset = 12;
2819
+ this.noFlip = false;
2811
2820
  this._onDocumentClick = (event) => {
2812
2821
  if (!this.open)
2813
2822
  return;
@@ -2908,8 +2917,8 @@ let ItPopover = class ItPopover extends BaseComponent {
2908
2917
  computePosition(this._triggerElement, this._contentElement, {
2909
2918
  placement: this.placement,
2910
2919
  middleware: [
2911
- offset(12),
2912
- flip(),
2920
+ offset(this.offset),
2921
+ flip({ mainAxis: !this.noFlip, crossAxis: !this.noFlip }),
2913
2922
  shift({ padding: 8 }),
2914
2923
  size({
2915
2924
  apply({ rects, elements }) {
@@ -2933,8 +2942,12 @@ let ItPopover = class ItPopover extends BaseComponent {
2933
2942
  bottom: 'top',
2934
2943
  left: 'right',
2935
2944
  }[placement.split('-')[0]];
2945
+ const triggerRect = this._triggerElement.getBoundingClientRect();
2946
+ const contentRect = this._contentElement.getBoundingClientRect();
2947
+ const triggerCenter = triggerRect.left + triggerRect.width / 2;
2948
+ const arrowLeft = triggerCenter - contentRect.left - this._triggerElement.offsetWidth / 2 + 20;
2936
2949
  Object.assign(this._arrowElement.style, {
2937
- left: arrowX != null ? '20px' : '',
2950
+ left: arrowX != null ? `${arrowLeft}px` : '',
2938
2951
  top: arrowY != null ? `${arrowY}px` : '',
2939
2952
  right: '',
2940
2953
  bottom: '',
@@ -2983,6 +2996,14 @@ __decorate([
2983
2996
  property({ type: String }),
2984
2997
  __metadata("design:type", String)
2985
2998
  ], ItPopover.prototype, "placement", void 0);
2999
+ __decorate([
3000
+ property({ type: Number }),
3001
+ __metadata("design:type", Number)
3002
+ ], ItPopover.prototype, "offset", void 0);
3003
+ __decorate([
3004
+ property({ type: Boolean, attribute: 'no-flip' }),
3005
+ __metadata("design:type", Boolean)
3006
+ ], ItPopover.prototype, "noFlip", void 0);
2986
3007
  __decorate([
2987
3008
  query('slot[name="trigger"]'),
2988
3009
  __metadata("design:type", HTMLSlotElement)