@flightlesslabs/dodo-ui 0.11.0 → 0.12.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 (47) hide show
  1. package/dist/index.d.ts +3 -0
  2. package/dist/index.js +2 -0
  3. package/dist/stories/components/Form/Button/Button.svelte +18 -18
  4. package/dist/stories/components/Form/Button/utils/scss/mixins.scss +3 -3
  5. package/dist/stories/components/Form/DatePicker/DatePicker.svelte +1 -11
  6. package/dist/stories/components/Form/NumericInput/Roundness/Roundness.stories.svelte +20 -0
  7. package/dist/stories/components/Form/NumericInput/Roundness/Roundness.stories.svelte.d.ts +26 -0
  8. package/dist/stories/components/Form/NumericInput/Size/Size.stories.svelte +16 -0
  9. package/dist/stories/components/Form/NumericInput/Size/Size.stories.svelte.d.ts +26 -0
  10. package/dist/stories/components/Form/NumericInput/WithIcon/WithIcon.stories.svelte +31 -0
  11. package/dist/stories/components/Form/NumericInput/WithIcon/WithIcon.stories.svelte.d.ts +26 -0
  12. package/dist/stories/components/Form/RangeSlider/Color/Color.stories.svelte +19 -0
  13. package/dist/stories/components/Form/RangeSlider/Color/Color.stories.svelte.d.ts +26 -0
  14. package/dist/stories/components/Form/RangeSlider/Events/Events.stories.svelte +59 -0
  15. package/dist/stories/components/Form/RangeSlider/Events/Events.stories.svelte.d.ts +18 -0
  16. package/dist/stories/components/Form/RangeSlider/RangeSlider.stories.svelte +64 -0
  17. package/dist/stories/components/Form/RangeSlider/RangeSlider.stories.svelte.d.ts +21 -0
  18. package/dist/stories/components/Form/RangeSlider/RangeSlider.svelte +525 -0
  19. package/dist/stories/components/Form/RangeSlider/RangeSlider.svelte.d.ts +48 -0
  20. package/dist/stories/components/Form/RangeSlider/Roundness/Roundness.stories.svelte +30 -0
  21. package/dist/stories/components/Form/RangeSlider/Roundness/Roundness.stories.svelte.d.ts +26 -0
  22. package/dist/stories/components/Form/RangeSlider/Size/Size.stories.svelte +16 -0
  23. package/dist/stories/components/Form/RangeSlider/Size/Size.stories.svelte.d.ts +26 -0
  24. package/dist/stories/components/Form/RangeSlider/WithIcon/WithIcon.stories.svelte +30 -0
  25. package/dist/stories/components/Form/RangeSlider/WithIcon/WithIcon.stories.svelte.d.ts +18 -0
  26. package/dist/stories/components/Form/RangeSlider/utils/scss/mixins.scss +91 -0
  27. package/dist/stories/developer tools/components/Popper/Popper.stories.svelte +16 -0
  28. package/dist/stories/developer tools/components/Popper/Popper.svelte +10 -14
  29. package/dist/stories/developer tools/components/Popper/Popper.svelte.d.ts +2 -0
  30. package/dist/stories/developer tools/components/Popper/PopperPopup/PopperPopup.svelte +25 -11
  31. package/dist/stories/developer tools/components/Popper/PopperPopup/PopperPopup.svelte.d.ts +2 -0
  32. package/dist/stories/developer tools/components/Popper/PopperPopup/utils/getPopupPosition.d.ts +10 -8
  33. package/dist/stories/developer tools/components/Popper/PopperPopup/utils/getPopupPosition.js +40 -23
  34. package/dist/stories/developer tools/directives/drag/drag.d.ts +3 -0
  35. package/dist/stories/developer tools/directives/drag/drag.js +40 -0
  36. package/dist/styles/_components.css +5 -0
  37. package/package.json +10 -10
  38. package/src/lib/index.ts +4 -0
  39. package/src/lib/stories/components/Form/Button/utils/scss/mixins.scss +3 -3
  40. package/src/lib/stories/components/Form/DatePicker/DatePicker.svelte +1 -13
  41. package/src/lib/stories/components/Form/RangeSlider/RangeSlider.svelte +476 -0
  42. package/src/lib/stories/components/Form/RangeSlider/utils/scss/mixins.scss +91 -0
  43. package/src/lib/stories/developer tools/components/Popper/Popper.svelte +13 -14
  44. package/src/lib/stories/developer tools/components/Popper/PopperPopup/PopperPopup.svelte +36 -10
  45. package/src/lib/stories/developer tools/components/Popper/PopperPopup/utils/getPopupPosition.ts +45 -31
  46. package/src/lib/stories/developer tools/directives/drag/drag.ts +47 -0
  47. package/src/lib/styles/_components.css +5 -0
@@ -32,6 +32,8 @@
32
32
  lockPoistions?: boolean;
33
33
  /** Popper Height For Vertical Position, default 300 */
34
34
  popperHeightForVerticalPosition?: number;
35
+ /** Full width Popper? */
36
+ fullWidth?: boolean;
35
37
  }
36
38
  </script>
37
39
 
@@ -50,9 +52,15 @@
50
52
  popupOffsetY: offsetY = 12,
51
53
  popperHeightForVerticalPosition = 100,
52
54
  lockPoistions = false,
55
+ fullWidth = false,
53
56
  }: PopperPopupProps = $props();
54
57
 
55
- const popperWidth = $derived(width || '100%');
58
+ let popupLocation = $state<DOMRect>();
59
+
60
+ const fullWidthInPixels = $derived(
61
+ fullWidth && popperLocation?.width ? `${popperLocation?.width}px` : '',
62
+ );
63
+ const popperWidth = $derived(width || fullWidthInPixels);
56
64
  const popupMaxHeight = $derived(maxHeight || '400px');
57
65
 
58
66
  let left = $state<number | null>(null);
@@ -60,20 +68,39 @@
60
68
  let top = $state<number | null>(null);
61
69
  let bottom = $state<number | null>(null);
62
70
 
71
+ function capturePopupLocation() {
72
+ if (!ref) {
73
+ return;
74
+ }
75
+
76
+ popupLocation = ref.getBoundingClientRect();
77
+ }
78
+
79
+ $effect(() => {
80
+ if (!ref) {
81
+ return;
82
+ }
83
+
84
+ capturePopupLocation();
85
+
86
+ window.addEventListener('resize', capturePopupLocation);
87
+
88
+ return () => {
89
+ window.removeEventListener('resize', capturePopupLocation);
90
+ };
91
+ });
92
+
63
93
  $effect(() => {
64
94
  const values = getPopupPosition({
65
95
  positionX,
66
96
  positionY,
67
- height: popperLocation?.height || 0,
68
- width: popperLocation?.width || 0,
69
- top: popperLocation?.top || 0,
70
- bottom: popperLocation?.bottom || 0,
71
- left: popperLocation?.left || 0,
72
- right: popperLocation?.right || 0,
73
97
  offsetX: offsetX,
74
98
  offsetY: offsetY,
75
99
  popperHeight: popperHeightForVerticalPosition,
76
100
  lockPoistions,
101
+ popperLocation,
102
+ popupLocation,
103
+ fullWidth,
77
104
  });
78
105
 
79
106
  left = values.left;
@@ -91,12 +118,11 @@
91
118
  className,
92
119
  ].join(' ')}
93
120
  bind:this={ref}
94
- style={`width: ${popperWidth};
121
+ style={`${popperWidth ? `width: ${popperWidth};` : ''}
95
122
  ${left !== null ? `left: ${left}px;` : ''}
96
123
  ${right !== null ? `right: ${right}px;` : ''}
97
124
  ${top !== null ? `top: ${top}px;` : ''}
98
125
  ${bottom !== null ? `bottom: ${bottom}px;` : ''}
99
- ${positionX === 'center' ? `margin: auto;` : ''}
100
126
  `}
101
127
  >
102
128
  <Paper shadow={3} {...paperProps}>
@@ -110,7 +136,7 @@
110
136
 
111
137
  <style lang="scss">
112
138
  .dodo-ui-PopperPopup {
113
- position: absolute;
139
+ position: fixed;
114
140
  z-index: var(--dodo-ui-z-index-4);
115
141
 
116
142
  section {
@@ -4,16 +4,13 @@ import type { PositionX, PositionY } from '$lib/types/position.js';
4
4
  export interface GetPopupPositionProps {
5
5
  positionX: PositionX;
6
6
  positionY: PositionY;
7
- height: number;
8
- width: number;
9
- top: number;
10
- bottom: number;
11
- left: number;
12
- right: number;
13
7
  offsetX?: number;
14
8
  offsetY?: number;
15
9
  popperHeight: number;
16
10
  lockPoistions: boolean;
11
+ popperLocation?: DOMRect;
12
+ popupLocation?: DOMRect;
13
+ fullWidth?: boolean;
17
14
  }
18
15
 
19
16
  export function getPopupPosition(props: GetPopupPositionProps) {
@@ -32,52 +29,69 @@ export function getPopupPosition(props: GetPopupPositionProps) {
32
29
  };
33
30
  }
34
31
 
35
- const innerHeight = window.innerHeight;
36
-
37
- const gapBottom = innerHeight - props.bottom;
38
- const popperHeight = props.popperHeight;
32
+ const POPPER_LEFT = props.popperLocation?.left || 0;
33
+ const POPPER_TOP = props.popperLocation?.top || 0;
34
+ const POPPER_BOTTOM = props.popperLocation?.bottom || 0;
35
+ const POPPER_HEIGHT = props.popperLocation?.height || 0;
36
+ const POPPER_WIDTH = props.popperLocation?.width || 0;
39
37
 
40
38
  const offsetX = props.offsetX ? props.offsetX : 0;
41
39
  const offsetY = props.offsetY ? props.offsetY : 0;
42
40
 
43
- const positionX = props.positionX;
41
+ const POPUP_WIDTH = props.popupLocation?.width || 0;
42
+
43
+ const WIDTH_DIFF = POPPER_WIDTH - POPUP_WIDTH;
44
+
45
+ const innerHeight = window.innerHeight;
46
+ const gapBottom = innerHeight - POPPER_BOTTOM;
47
+
44
48
  let positionY = props.positionY;
45
49
 
50
+ // Adjust position if there is not enough space to draw it.
46
51
  if (!props.lockPoistions) {
47
- if (positionY === 'top' && props.top < popperHeight + offsetY) {
52
+ if (positionY === 'top' && POPPER_TOP < POPPER_HEIGHT + offsetY) {
48
53
  positionY = 'bottom';
49
- } else if (positionY === 'bottom' && gapBottom < popperHeight + offsetY) {
54
+ } else if (positionY === 'bottom' && gapBottom < POPPER_HEIGHT + offsetY) {
50
55
  positionY = 'top';
51
56
  }
52
57
  }
53
58
 
54
- switch (positionX) {
55
- case 'left':
56
- left = offsetX;
57
- right = null;
58
- break;
59
- case 'center':
60
- left = 0;
61
- right = 0;
62
- break;
63
- case 'right':
64
- left = null;
65
- right = offsetX;
66
- break;
67
- }
68
-
69
59
  switch (positionY) {
70
60
  case 'top':
71
- case 'middle':
72
61
  top = null;
73
- bottom = props.height + offsetY;
62
+ bottom = POPPER_TOP + POPPER_HEIGHT + offsetY;
74
63
  break;
75
64
  case 'bottom':
76
- top = props.height + offsetY;
65
+ top = POPPER_TOP + POPPER_HEIGHT + offsetY;
77
66
  bottom = null;
78
67
  break;
79
68
  }
80
69
 
70
+ if (props.fullWidth) {
71
+ // If Full Width
72
+ left = POPPER_LEFT;
73
+ right = null;
74
+ } else if (WIDTH_DIFF < 0) {
75
+ // If Popup is bigger than the Popper Container
76
+ left = POPPER_LEFT;
77
+ right = null;
78
+ } else {
79
+ switch (props.positionX) {
80
+ case 'left':
81
+ left = POPPER_LEFT + offsetX;
82
+ right = null;
83
+ break;
84
+ case 'center':
85
+ left = POPPER_LEFT + offsetX + WIDTH_DIFF / 2;
86
+ right = null;
87
+ break;
88
+ case 'right':
89
+ left = POPPER_LEFT + offsetX + WIDTH_DIFF;
90
+ right = null;
91
+ break;
92
+ }
93
+ }
94
+
81
95
  return {
82
96
  left,
83
97
  right,
@@ -0,0 +1,47 @@
1
+ export function drag(node: HTMLElement) {
2
+ let dragging = false;
3
+
4
+ function getX(e: MouseEvent | TouchEvent): number {
5
+ return 'touches' in e ? e.touches[0].clientX : e.clientX;
6
+ }
7
+
8
+ function handleStart(e: MouseEvent | TouchEvent) {
9
+ dragging = true;
10
+ const x = getX(e);
11
+ node.dispatchEvent(new CustomEvent('dragstart', { detail: { x } }));
12
+
13
+ window.addEventListener('mousemove', handleMove);
14
+ window.addEventListener('mouseup', handleEnd);
15
+ window.addEventListener('touchmove', handleMove);
16
+ window.addEventListener('touchend', handleEnd);
17
+ }
18
+
19
+ function handleMove(e: MouseEvent | TouchEvent) {
20
+ if (!dragging) return;
21
+ const x = getX(e);
22
+
23
+ node.dispatchEvent(new CustomEvent('dragging', { detail: { x } }));
24
+ }
25
+
26
+ function handleEnd(e: MouseEvent | TouchEvent) {
27
+ if (!dragging) return;
28
+ dragging = false;
29
+ const x = getX(e);
30
+ node.dispatchEvent(new CustomEvent('dragend', { detail: { x } }));
31
+
32
+ window.removeEventListener('mousemove', handleMove);
33
+ window.removeEventListener('mouseup', handleEnd);
34
+ window.removeEventListener('touchmove', handleMove);
35
+ window.removeEventListener('touchend', handleEnd);
36
+ }
37
+
38
+ node.addEventListener('mousedown', handleStart);
39
+ node.addEventListener('touchstart', handleStart, { passive: true });
40
+
41
+ return {
42
+ destroy() {
43
+ node.removeEventListener('mousedown', handleStart);
44
+ node.removeEventListener('touchstart', handleStart);
45
+ },
46
+ };
47
+ }
@@ -4,6 +4,11 @@
4
4
  --dodo-ui-element-height-normal: 40px;
5
5
  --dodo-ui-element-height-large: 50px;
6
6
 
7
+ /* Size Thin elements */
8
+ --dodo-ui-track-element-height-small: 6px;
9
+ --dodo-ui-track-element-height-normal: 8px;
10
+ --dodo-ui-track-element-height-large: 10px;
11
+
7
12
  /* Roundness */
8
13
  --dodo-ui-element-roundness-1: 0.4375em;
9
14
  --dodo-ui-element-roundness-2: 0.8125em;