@italia/popover 0.1.0-alpha.2 → 1.0.0-alpha.10

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 CHANGED
@@ -1,19 +1,67 @@
1
- # Popover Web Component
1
+ # \<it-popover>
2
2
 
3
- Questo package contiene il web component `<it-popover>`, conforme agli standard del progetto e con stili Bootstrap Italia.
3
+ This webcomponent follows the [open-wc](https://github.com/open-wc/open-wc) recommendation.
4
4
 
5
- ## Utilizzo
5
+ ## Installation
6
6
 
7
+ ```bash
8
+ npm i @italia/popover
7
9
  ```
8
10
 
11
+ ## Usage
12
+
13
+ ```html
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
9
47
  ```
10
48
 
11
- ## Sviluppo
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
+ ```
12
62
 
13
- - Stili: solo SCSS, no CSS inline
14
- - Test: web-test-runner
15
- - Storie: Storybook
63
+ ## Tooling configs
16
64
 
17
- ## License
65
+ For most of the tools, the configuration is in the `package.json` to reduce the amount of files in your project.
18
66
 
19
- Vedi LICENSE.
67
+ If you customize the configuration a lot, you can consider moving them to individual files.
@@ -36,6 +36,15 @@
36
36
  "attribute": "open",
37
37
  "reflects": true
38
38
  },
39
+ {
40
+ "kind": "field",
41
+ "name": "controlled",
42
+ "type": {
43
+ "text": "boolean"
44
+ },
45
+ "default": "false",
46
+ "attribute": "controlled"
47
+ },
39
48
  {
40
49
  "kind": "field",
41
50
  "name": "placement",
@@ -45,6 +54,24 @@
45
54
  "default": "'bottom-start'",
46
55
  "attribute": "placement"
47
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
+ },
48
75
  {
49
76
  "kind": "field",
50
77
  "name": "_triggerSlot",
@@ -94,6 +121,11 @@
94
121
  "name": "_setChildrenProperties",
95
122
  "privacy": "private"
96
123
  },
124
+ {
125
+ "kind": "method",
126
+ "name": "setupStandardEvents",
127
+ "privacy": "protected"
128
+ },
97
129
  {
98
130
  "kind": "method",
99
131
  "name": "_createArrow",
@@ -158,6 +190,14 @@
158
190
  "default": "false",
159
191
  "fieldName": "open"
160
192
  },
193
+ {
194
+ "name": "controlled",
195
+ "type": {
196
+ "text": "boolean"
197
+ },
198
+ "default": "false",
199
+ "fieldName": "controlled"
200
+ },
161
201
  {
162
202
  "name": "placement",
163
203
  "type": {
@@ -165,6 +205,22 @@
165
205
  },
166
206
  "default": "'bottom-start'",
167
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"
168
224
  }
169
225
  ],
170
226
  "superclass": {
@@ -193,6 +249,139 @@
193
249
  }
194
250
  }
195
251
  ]
252
+ },
253
+ {
254
+ "kind": "javascript-module",
255
+ "path": "stories/it-popover.stories.ts",
256
+ "declarations": [
257
+ {
258
+ "kind": "variable",
259
+ "name": "meta",
260
+ "default": "{ title: 'Componenti/Popover', component: 'it-popover', tags: ['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', ], description: 'Posizione del Popover rispetto al suo elemento trigger', table: { defaultValue: { summary: 'bottom-start' }, }, }, }, parameters: { layout: 'padded', }, } satisfies Meta<PopoverProps>"
261
+ },
262
+ {
263
+ "kind": "variable",
264
+ "name": "Base",
265
+ "type": {
266
+ "text": "Story"
267
+ },
268
+ "default": "{ ...meta, render: (args) => html` <it-popover placement=${ifDefined(args.placement)}> <it-button slot=\"trigger\" variant=\"primary\"> Opzioni utente, clicca per aprire </it-button> <div slot=\"content\" class=\"popover\"> <h4 class=\"popover-header\">Titolo del popover</h4> <div class=\"popover-body\">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc vel finibus augue.</div> </div> </it-popover> `, tags: ['!autodocs', '!dev'], }"
269
+ },
270
+ {
271
+ "kind": "variable",
272
+ "name": "Posizione",
273
+ "type": {
274
+ "text": "Story"
275
+ },
276
+ "default": "{ ...meta, render: () => html` <it-popover placement=\"bottom-start\" style=\"grid-column:2\"> <it-button slot=\"trigger\" variant=\"primary\">Giù</it-button> <div slot=\"content\" class=\"popover\"> <h4 class=\"popover-header\">Titolo del popover</h4> <div class=\"popover-body\">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc vel finibus augue.</div> </div> </it-popover> <it-popover placement=\"top-start\" style=\"grid-row:3;grid-column:2\"> <it-button slot=\"trigger\" variant=\"primary\">Su</it-button> <div slot=\"content\" class=\"popover\"> <h4 class=\"popover-header\">Titolo del popover</h4> <div class=\"popover-body\">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc vel finibus augue.</div> </div> </it-popover> <it-popover placement=\"left\" style=\"grid-row:2;grid-column:3\"> <it-button slot=\"trigger\" variant=\"primary\">Sinistra</it-button> <div slot=\"content\" class=\"popover\"> <h4 class=\"popover-header\">Titolo del popover</h4> <div class=\"popover-body\">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc vel finibus augue.</div> </div> </it-popover> <it-popover placement=\"right\" style=\"grid-row:2;grid-column:1\"> <it-button slot=\"trigger\" variant=\"primary\">Destra</it-button> <div slot=\"content\" class=\"popover\"> <h4 class=\"popover-header\">Titolo del popover</h4> <div class=\"popover-body\">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc vel finibus augue.</div> </div> </it-popover> `, decorators: [(Story) => html`<div style=\"display:grid;gap:.5rem;grid:1fr 1fr 1fr/1fr 1fr 1fr;\">${Story()}</div>`], argTypes: { ...disabledControls() }, }"
277
+ },
278
+ {
279
+ "kind": "variable",
280
+ "name": "ConIconaELink",
281
+ "type": {
282
+ "text": "Story"
283
+ },
284
+ "default": "{ ...meta, name: 'Titolo con icona e link', render: () => { const handleLinkClick = (e: Event) => { e.preventDefault(); }; return html` <it-popover> <it-button slot=\"trigger\" variant=\"primary\"> Popover con icona e link </it-button> <div slot=\"content\" class=\"popover\"> <h4 class=\"popover-header\"> <it-icon name=\"it-help-circle\" size=\"sm\"></it-icon> Titolo con icona </h4> <div class=\"popover-body\"> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc vel finibus augue. <a href=\"#\" class=\"popover-inner-link\" @click=${handleLinkClick}> Leggi tutto <it-icon name=\"it-arrow-right\" size=\"xs\" color=\"primary\"></it-icon> </a> </div> </div> </it-popover> `; }, decorators: [(Story) => html`<div style=\"height:200px\">${Story()}</div>`], argTypes: { ...disabledControls() }, }"
285
+ },
286
+ {
287
+ "kind": "variable",
288
+ "name": "ElementiDisabilitati",
289
+ "type": {
290
+ "text": "Story"
291
+ },
292
+ "default": "{ ...meta, name: 'Elementi disabilitati', render: () => html` <it-popover placement=\"right\"> <it-button slot=\"trigger\" variant=\"primary\" disabled> Pulsante disabilitato, il popover non si apre </it-button> <div slot=\"content\" class=\"popover\"> <div class=\"popover-body\">Popover disabilitato</div> </div> </it-popover> `, argTypes: { ...disabledControls() }, }"
293
+ },
294
+ {
295
+ "kind": "variable",
296
+ "name": "ElementiDisabilitatiConHover",
297
+ "type": {
298
+ "text": "Story"
299
+ },
300
+ "default": "{ ...meta, name: 'Elementi disabilitati con hover', render: () => { const handleMouseEnter = (e: Event) => { const button = e.target as HTMLElement; const popover = button.closest('it-popover'); popover?.openPopover(); }; const handleMouseLeave = (e: Event) => { const button = e.target as HTMLElement; const popover = button.closest('it-popover'); popover?.closePopover(); }; const handleFocus = (e: Event) => { const button = e.target as HTMLElement; const popover = button.closest('it-popover'); popover?.openPopover(); }; const handleBlur = (e: FocusEvent) => { const target = e.relatedTarget as HTMLElement; if (!target?.closest?.('it-popover')) { const button = e.target as HTMLElement; const popover = button.closest('it-popover'); popover?.closePopover(); } }; return html` <it-popover placement=\"right\"> <it-button slot=\"trigger\" variant=\"primary\" disabled @mouseenter=${handleMouseEnter} @mouseleave=${handleMouseLeave} @focus=${handleFocus} @blur=${handleBlur} > Pulsante disabilitato </it-button> <div slot=\"content\" class=\"popover\" @blur=${handleBlur}> <div class=\"popover-body\">Pulsante disabilitato, qui puoi spiegare il perché</div> </div> </it-popover> `; }, argTypes: { ...disabledControls() }, }"
301
+ },
302
+ {
303
+ "kind": "variable",
304
+ "name": "AttivazioneControllata",
305
+ "type": {
306
+ "text": "Story"
307
+ },
308
+ "default": "{ ...meta, name: 'Attivazione controllata', tags: ['!dev'], render: () => html` <it-popover controlled placement=\"right\"> <it-button slot=\"trigger\" variant=\"primary\" id=\"controlled-trigger\"> Popover controllato </it-button> <div slot=\"content\" class=\"popover\"> <div class=\"popover-inner\"> <div class=\"popover-body\">Questo popover non si aprirà e questo testo non si vedrà.</div> </div> </div> </it-popover> `, argTypes: { ...disabledControls() }, }"
309
+ },
310
+ {
311
+ "kind": "variable",
312
+ "name": "Eventi",
313
+ "type": {
314
+ "text": "Story"
315
+ },
316
+ "default": "{ ...meta, render: () => { const handleOpen = (e: CustomEvent) => { console.log('Popover aperto', e); }; const handleClose = (e: CustomEvent) => { console.log('Popover chiuso', e); }; return html` <it-popover @it-popover-open=${handleOpen} @it-popover-close=${handleClose} placement=\"right\"> <it-button slot=\"trigger\" variant=\"primary\">Popover con eventi</it-button> <div slot=\"content\" class=\"popover\"> <h4 class=\"popover-header\">Eventi del Popover</h4> <div class=\"popover-body\">Apri e chiudi questo popover per vedere gli eventi nella console.</div> </div> </it-popover> `; }, argTypes: { ...disabledControls() }, }"
317
+ }
318
+ ],
319
+ "exports": [
320
+ {
321
+ "kind": "js",
322
+ "name": "default",
323
+ "declaration": {
324
+ "name": "meta",
325
+ "module": "stories/it-popover.stories.ts"
326
+ }
327
+ },
328
+ {
329
+ "kind": "js",
330
+ "name": "Base",
331
+ "declaration": {
332
+ "name": "Base",
333
+ "module": "stories/it-popover.stories.ts"
334
+ }
335
+ },
336
+ {
337
+ "kind": "js",
338
+ "name": "Posizione",
339
+ "declaration": {
340
+ "name": "Posizione",
341
+ "module": "stories/it-popover.stories.ts"
342
+ }
343
+ },
344
+ {
345
+ "kind": "js",
346
+ "name": "ConIconaELink",
347
+ "declaration": {
348
+ "name": "ConIconaELink",
349
+ "module": "stories/it-popover.stories.ts"
350
+ }
351
+ },
352
+ {
353
+ "kind": "js",
354
+ "name": "ElementiDisabilitati",
355
+ "declaration": {
356
+ "name": "ElementiDisabilitati",
357
+ "module": "stories/it-popover.stories.ts"
358
+ }
359
+ },
360
+ {
361
+ "kind": "js",
362
+ "name": "ElementiDisabilitatiConHover",
363
+ "declaration": {
364
+ "name": "ElementiDisabilitatiConHover",
365
+ "module": "stories/it-popover.stories.ts"
366
+ }
367
+ },
368
+ {
369
+ "kind": "js",
370
+ "name": "AttivazioneControllata",
371
+ "declaration": {
372
+ "name": "AttivazioneControllata",
373
+ "module": "stories/it-popover.stories.ts"
374
+ }
375
+ },
376
+ {
377
+ "kind": "js",
378
+ "name": "Eventi",
379
+ "declaration": {
380
+ "name": "Eventi",
381
+ "module": "stories/it-popover.stories.ts"
382
+ }
383
+ }
384
+ ]
196
385
  }
197
386
  ]
198
387
  }
@@ -1,10 +1,14 @@
1
1
  import { BaseComponent } from '@italia/globals';
2
+ import { PropertyValues } from 'lit';
2
3
  import { type Placement } from '@floating-ui/dom';
3
4
  type PopoverPlacement = Placement;
4
5
  export declare class ItPopover extends BaseComponent {
5
6
  static styles: import("lit").CSSResultGroup;
6
7
  open: boolean;
8
+ controlled: boolean;
7
9
  placement: PopoverPlacement;
10
+ offset: number;
11
+ noFlip: boolean;
8
12
  private _triggerSlot;
9
13
  private _contentSlot;
10
14
  private get _triggerElement();
@@ -12,8 +16,9 @@ export declare class ItPopover extends BaseComponent {
12
16
  private _arrowElement?;
13
17
  private _cleanup?;
14
18
  private _setChildrenProperties;
15
- connectedCallback(): void;
19
+ protected setupStandardEvents(): void;
16
20
  disconnectedCallback(): void;
21
+ protected firstUpdated(_changedProperties: PropertyValues): void;
17
22
  updated(changedProps: Map<string, any>): void;
18
23
  private _createArrow;
19
24
  private _show;
@@ -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;AAGhD,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;IAE7B,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,CAA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