@infonomic/uikit 7.0.0 → 7.1.0

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.
Files changed (56) hide show
  1. package/README.md +19 -1
  2. package/dist/components/accordion/accordion.contract.d.ts +2 -2
  3. package/dist/components/accordion/accordion.contract.d.ts.map +1 -1
  4. package/dist/components/accordion/accordion.contract.js +2 -2
  5. package/dist/components/accordion/accordion.module.css +16 -5
  6. package/dist/components/accordion/accordion_module.css +4 -6
  7. package/dist/components/button/button.astro +14 -8
  8. package/dist/components/button/button.d.ts.map +1 -1
  9. package/dist/components/button/button.js +2 -1
  10. package/dist/components/dropdown/dropdown.contract.d.ts +2 -2
  11. package/dist/components/dropdown/dropdown.contract.d.ts.map +1 -1
  12. package/dist/components/dropdown/dropdown.contract.js +3 -2
  13. package/dist/components/dropdown/dropdown.module.css +11 -0
  14. package/dist/components/dropdown/dropdown_module.css +5 -0
  15. package/dist/components/inputs/checkbox.contract.d.ts +4 -4
  16. package/dist/components/inputs/checkbox.contract.d.ts.map +1 -1
  17. package/dist/components/inputs/checkbox.contract.js +5 -3
  18. package/dist/components/inputs/checkbox.d.ts +6 -0
  19. package/dist/components/inputs/checkbox.d.ts.map +1 -1
  20. package/dist/components/inputs/checkbox.module.css +29 -3
  21. package/dist/components/inputs/checkbox_module.css +25 -3
  22. package/dist/components/tabs/tabs.contract.d.ts +2 -2
  23. package/dist/components/tabs/tabs.contract.d.ts.map +1 -1
  24. package/dist/components/tabs/tabs.contract.js +3 -2
  25. package/dist/components/tabs/tabs.module.css +9 -0
  26. package/dist/components/tabs/tabs_module.css +1 -1
  27. package/dist/css/accordion.css +4 -6
  28. package/dist/css/checkbox.css +25 -3
  29. package/dist/css/dropdown.css +5 -0
  30. package/dist/css/tabs.css +1 -1
  31. package/dist/lib/ripple.d.ts +55 -6
  32. package/dist/lib/ripple.d.ts.map +1 -1
  33. package/dist/lib/ripple.js +61 -10
  34. package/dist/styles/components-vanilla.css +1 -1
  35. package/dist/styles/styles.css +1 -1
  36. package/dist/widgets/drawer/drawer.contract.d.ts +1 -1
  37. package/dist/widgets/drawer/drawer.contract.d.ts.map +1 -1
  38. package/dist/widgets/drawer/drawer.contract.js +1 -1
  39. package/package.json +6 -1
  40. package/src/components/accordion/accordion.contract.ts +2 -2
  41. package/src/components/accordion/accordion.module.css +16 -5
  42. package/src/components/button/button.astro +14 -8
  43. package/src/components/button/button.tsx +4 -0
  44. package/src/components/dropdown/dropdown.contract.ts +2 -2
  45. package/src/components/dropdown/dropdown.module.css +11 -0
  46. package/src/components/dropdown/dropdown.stories.tsx +6 -0
  47. package/src/components/inputs/checkbox.contract.ts +6 -4
  48. package/src/components/inputs/checkbox.module.css +29 -3
  49. package/src/components/inputs/checkbox.stories.tsx +43 -0
  50. package/src/components/inputs/checkbox.tsx +6 -0
  51. package/src/components/tabs/tabs.contract.ts +3 -2
  52. package/src/components/tabs/tabs.module.css +9 -0
  53. package/src/lib/ripple.ts +136 -13
  54. package/src/styles/theme/defaults.css +3 -2
  55. package/src/styles/utils/utility-classes.css +3 -2
  56. package/src/widgets/drawer/drawer.contract.ts +1 -1
@@ -5,9 +5,34 @@
5
5
  * Original work licensed under the MIT License.
6
6
  * Copyright (c) 2021 Sajad Ahmad Nawabi
7
7
  *
8
- * Adapted for use as an internal ESM/TypeScript module with minor improvements.
8
+ * Adapted for use as an ESM/TypeScript module with minor improvements. It uses
9
+ * the DOM only, so any framework can import it.
9
10
  */
10
11
  export type RippleColor = 'light' | 'dark';
12
+ /** The part of a mouse or pointer event that a ripple needs. */
13
+ export interface RipplePress {
14
+ clientX: number;
15
+ clientY: number;
16
+ currentTarget: EventTarget | null;
17
+ /** The mouse button, where the event has one. Only the main button ripples. */
18
+ button?: number;
19
+ }
20
+ /**
21
+ * Whether a press on `element` may draw a ripple. Every ripple goes through
22
+ * this, whichever listener asked for it, so the rules are the same for a React
23
+ * Button, an Astro Button and a button drawn by any other framework.
24
+ *
25
+ * No ripple for: any mouse button but the main one, a disabled element
26
+ * (`disabled`, `data-disabled` or `aria-disabled="true"`), an element with
27
+ * `data-ripple="false"` or inside one, and a user who has asked for reduced
28
+ * motion.
29
+ *
30
+ * It asks the element's own document and window, not the globals, so it works
31
+ * for an element inside an iframe.
32
+ */
33
+ export declare function canRipple(event: {
34
+ button?: number;
35
+ }, element: Element): boolean;
11
36
  export declare class Ripple {
12
37
  private x;
13
38
  private y;
@@ -15,11 +40,35 @@ export declare class Ripple {
15
40
  private findFurthestPoint;
16
41
  private applyStyles;
17
42
  private applyAnimation;
18
- create(event: MouseEvent | {
19
- clientX: number;
20
- clientY: number;
21
- currentTarget: EventTarget | null;
22
- }, color?: RippleColor): void;
43
+ /**
44
+ * Draws one ripple from the point of the press.
45
+ *
46
+ * The ripple is drawn in `target`, or in the event's `currentTarget` when no
47
+ * target is given. Pass the target when the listener is on an ancestor, where
48
+ * `currentTarget` is that ancestor and not the element pressed.
49
+ *
50
+ * Nothing is drawn when `canRipple` says no: see the rules there.
51
+ */
52
+ create(event: RipplePress, color?: RippleColor, target?: HTMLElement): void;
23
53
  }
54
+ /**
55
+ * Gives every kit button inside `root` a ripple, with one listener on `root`.
56
+ *
57
+ * A press on an element with the `infonomic-button` class, or on anything
58
+ * inside one, draws a ripple in that button: light on a filled or gradient
59
+ * button, dark on the others. Buttons added later are covered too.
60
+ *
61
+ * No ripple is drawn where `canRipple` says no, or for a button that makes its
62
+ * own ripple (`data-ripple="self"`).
63
+ *
64
+ * Returns a function that removes the ripple from `root`. A press draws one
65
+ * ripple however many roots it passes through: attaching to the same root more
66
+ * than once, or to a container inside an attached document, changes nothing.
67
+ * Each attachment is removed on its own, and a root's listener stays until
68
+ * every caller for that root has detached.
69
+ *
70
+ * `root` may belong to another window, such as an iframe's document.
71
+ */
72
+ export declare function attachRipple(root: Document | Element): () => void;
24
73
  export default Ripple;
25
74
  //# sourceMappingURL=ripple.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ripple.d.ts","sourceRoot":"","sources":["../../src/lib/ripple.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,MAAM,MAAM,WAAW,GAAG,OAAO,GAAG,MAAM,CAAA;AAE1C,qBAAa,MAAM;IACjB,OAAO,CAAC,CAAC,CAAI;IACb,OAAO,CAAC,CAAC,CAAI;IACb,OAAO,CAAC,CAAC,CAAI;IAEb,OAAO,CAAC,iBAAiB;IAezB,OAAO,CAAC,WAAW;IAkBnB,OAAO,CAAC,cAAc;IAatB,MAAM,CACJ,KAAK,EAAE,UAAU,GAAG;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAC;QAAC,aAAa,EAAE,WAAW,GAAG,IAAI,CAAA;KAAE,EAC3F,KAAK,GAAE,WAAqB,GAC3B,IAAI,CAyBN;CACF;eAEc,MAAM"}
1
+ {"version":3,"file":"ripple.d.ts","sourceRoot":"","sources":["../../src/lib/ripple.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,MAAM,MAAM,WAAW,GAAG,OAAO,GAAG,MAAM,CAAA;AAE1C,gEAAgE;AAChE,MAAM,WAAW,WAAW;IAC1B,OAAO,EAAE,MAAM,CAAA;IACf,OAAO,EAAE,MAAM,CAAA;IACf,aAAa,EAAE,WAAW,GAAG,IAAI,CAAA;IACjC,+EAA+E;IAC/E,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB;AAMD;;;;;;;;;;;;GAYG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE;IAAE,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAK/E;AAED,qBAAa,MAAM;IACjB,OAAO,CAAC,CAAC,CAAI;IACb,OAAO,CAAC,CAAC,CAAI;IACb,OAAO,CAAC,CAAC,CAAI;IAEb,OAAO,CAAC,iBAAiB;IAezB,OAAO,CAAC,WAAW;IAkBnB,OAAO,CAAC,cAAc;IAatB;;;;;;;;OAQG;IACH,MAAM,CAAC,KAAK,EAAE,WAAW,EAAE,KAAK,GAAE,WAAqB,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,IAAI,CA+BnF;CACF;AAuBD;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,QAAQ,GAAG,OAAO,GAAG,MAAM,IAAI,CAoCjE;eAEc,MAAM"}
@@ -1,3 +1,11 @@
1
+ const optOutSelector = '[data-ripple="false"]';
2
+ const disabledSelector = ':disabled, [data-disabled], [aria-disabled="true"]';
3
+ function canRipple(event, element) {
4
+ if (null != event.button && 0 !== event.button) return false;
5
+ if (element.matches(disabledSelector) || null != element.closest(optOutSelector)) return false;
6
+ const view = element.ownerDocument.defaultView;
7
+ return view?.matchMedia?.('(prefers-reduced-motion: reduce)').matches !== true;
8
+ }
1
9
  class Ripple {
2
10
  findFurthestPoint(clickPointX, elementWidth, offsetX, clickPointY, elementHeight, offsetY) {
3
11
  this.x = clickPointX - offsetX > elementWidth / 2 ? 0 : elementWidth;
@@ -16,7 +24,7 @@ class Ripple {
16
24
  element.style.width = element.style.height = `${2 * radius}px`;
17
25
  }
18
26
  applyAnimation(element) {
19
- element.animate([
27
+ return element.animate([
20
28
  {
21
29
  transform: 'scale(0)',
22
30
  opacity: 1
@@ -30,17 +38,20 @@ class Ripple {
30
38
  easing: 'linear'
31
39
  });
32
40
  }
33
- create(event, color = 'light') {
34
- const element = event.currentTarget;
35
- element.style.position = 'relative';
41
+ create(event, color = 'light', target) {
42
+ const element = target ?? event.currentTarget;
43
+ if (null == element || !canRipple(event, element)) return;
44
+ const view = element.ownerDocument.defaultView;
45
+ if (null == view) return;
46
+ if ('static' === view.getComputedStyle(element).position) element.style.position = 'relative';
36
47
  element.style.overflow = 'hidden';
37
48
  const rect = element.getBoundingClientRect();
38
49
  const radius = this.findFurthestPoint(event.clientX, element.offsetWidth, rect.left, event.clientY, element.offsetHeight, rect.top);
39
- const circle = document.createElement('span');
50
+ const circle = element.ownerDocument.createElement('span');
40
51
  this.applyStyles(circle, color, rect, radius, event.clientX, event.clientY);
41
- this.applyAnimation(circle);
42
52
  element.appendChild(circle);
43
- setTimeout(()=>circle.remove(), 500);
53
+ const remove = ()=>circle.remove();
54
+ this.applyAnimation(circle).finished.then(remove, remove);
44
55
  }
45
56
  constructor(){
46
57
  this.x = 0;
@@ -48,6 +59,46 @@ class Ripple {
48
59
  this.z = 0;
49
60
  }
50
61
  }
51
- const ripple = Ripple;
52
- export default ripple;
53
- export { Ripple };
62
+ const buttonSelector = '.infonomic-button';
63
+ const lightSelector = '.infonomic-button-filled, .infonomic-button-gradient';
64
+ const ownRippleSelector = '[data-ripple="self"]';
65
+ const attachments = new WeakMap();
66
+ const answered = new WeakSet();
67
+ const isElement = (node)=>null != node && 1 === node.nodeType && 'function' == typeof node.closest;
68
+ function attachRipple(root) {
69
+ let attachment = attachments.get(root);
70
+ if (null == attachment) {
71
+ const ripple = new Ripple();
72
+ const onPointerDown = (event)=>{
73
+ const press = event;
74
+ if (answered.has(press) || !isElement(press.target)) return;
75
+ const button = press.target.closest(buttonSelector);
76
+ if (null == button || !root.contains(button)) return;
77
+ answered.add(press);
78
+ if (button.matches(ownRippleSelector)) return;
79
+ ripple.create(press, button.matches(lightSelector) ? 'light' : 'dark', button);
80
+ };
81
+ root.addEventListener('pointerdown', onPointerDown);
82
+ const created = {
83
+ count: 0,
84
+ detach: ()=>root.removeEventListener('pointerdown', onPointerDown)
85
+ };
86
+ attachments.set(root, created);
87
+ attachment = created;
88
+ }
89
+ const current = attachment;
90
+ current.count += 1;
91
+ let detached = false;
92
+ return ()=>{
93
+ if (detached) return;
94
+ detached = true;
95
+ current.count -= 1;
96
+ if (0 === current.count) {
97
+ current.detach();
98
+ attachments.delete(root);
99
+ }
100
+ };
101
+ }
102
+ const lib_ripple = Ripple;
103
+ export default lib_ripple;
104
+ export { Ripple, attachRipple, canRipple };