@yourdash/uikit 1.0.1 → 1.0.3

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 (82) hide show
  1. package/components/box/box.module.scss +1 -1
  2. package/components/box/box.tsx +3 -3
  3. package/components/button/button.module.scss +3 -3
  4. package/components/button/button.tsx +2 -1
  5. package/components/buttonLink/buttonLink.module.scss +5 -1
  6. package/components/buttonLink/buttonLink.tsx +13 -12
  7. package/components/buttonWithIcon/buttonWithIcon.module.scss +56 -0
  8. package/components/buttonWithIcon/buttonWithIcon.tsx +36 -0
  9. package/components/card/card.module.scss +6 -6
  10. package/components/card/card.tsx +23 -20
  11. package/components/container/container.module.scss +20 -0
  12. package/components/container/container.tsx +22 -0
  13. package/components/contextMenu/contextMenu.tsx +1 -1
  14. package/components/contextMenu/contextMenuRoot.module.scss +1 -1
  15. package/components/contextMenu/contextMenuRoot.tsx +83 -83
  16. package/components/flex/flex.module.scss +31 -19
  17. package/components/flex/flex.tsx +23 -2
  18. package/components/heading/heading.module.scss +1 -1
  19. package/components/heading/heading.tsx +1 -1
  20. package/components/icon/icon.tsx +1 -1
  21. package/components/iconButton/iconButton.module.scss +1 -1
  22. package/components/iconButton/iconButton.tsx +3 -3
  23. package/components/image/image.module.scss +72 -1
  24. package/components/image/image.tsx +65 -10
  25. package/components/link/link.module.scss +1 -1
  26. package/components/link/link.tsx +1 -1
  27. package/components/progressBar/progressBar.module.scss +25 -0
  28. package/components/progressBar/progressBar.tsx +21 -0
  29. package/components/redirect/redirect.tsx +1 -1
  30. package/components/separator/separator.module.scss +9 -4
  31. package/components/separator/separator.tsx +3 -3
  32. package/components/spinner/spinner.module.scss +1 -6
  33. package/components/spinner/spinner.tsx +1 -1
  34. package/components/subtext/subtext.module.scss +1 -1
  35. package/components/subtext/subtext.tsx +1 -1
  36. package/components/tag/tag.module.scss +13 -0
  37. package/components/tag/tag.tsx +21 -0
  38. package/components/text/text.module.scss +1 -1
  39. package/components/text/text.tsx +1 -1
  40. package/components/textButton/textButton.module.scss +1 -1
  41. package/components/textButton/textButton.tsx +1 -1
  42. package/components/textInput/textInput.module.scss +1 -1
  43. package/components/textInput/textInput.tsx +40 -10
  44. package/components/toast/toast.module.scss +71 -31
  45. package/components/toast/toast.ts +12 -0
  46. package/components/toast/toastAction.ts +12 -0
  47. package/components/toast/toastContext.ts +5 -3
  48. package/components/toast/toasts.tsx +99 -0
  49. package/core/decrementLevel.tsx +13 -13
  50. package/core/incrementLevel.tsx +1 -1
  51. package/core/level.tsx +1 -1
  52. package/core/remToPx.ts +8 -0
  53. package/core/root.tsx +26 -32
  54. package/core/toast.ts +18 -17
  55. package/imports.d.ts +81 -0
  56. package/package.json +9 -40
  57. package/theme/defaultTheme.module.scss +16 -4
  58. package/theme/themeValues.scss +8 -5
  59. package/tsconfig.json +19 -9
  60. package/utilityComponent/hasBeenShown/hasBeenShown.tsx +47 -0
  61. package/utilityComponent/onInView/onInView.tsx +83 -0
  62. package/views/carousel/carousel.module.scss +77 -0
  63. package/views/carousel/carousel.tsx +138 -0
  64. package/views/header/header.module.scss +16 -0
  65. package/views/header/header.tsx +28 -0
  66. package/views/infiniteScroll/infiniteScroll.module.scss +26 -0
  67. package/views/infiniteScroll/infiniteScroll.tsx +90 -0
  68. package/views/navBar/components/navImage/navImage.module.scss +7 -0
  69. package/views/navBar/components/navImage/navImage.tsx +15 -0
  70. package/views/navBar/components/navTitle/navTitle.tsx +13 -0
  71. package/views/navBar/navBar.module.scss +22 -0
  72. package/views/navBar/navBar.tsx +37 -0
  73. package/views/onBoarding/onBoarding.module.scss +84 -0
  74. package/views/onBoarding/onBoarding.tsx +138 -0
  75. package/views/panAndZoom/panAndZoom.tsx +121 -114
  76. package/views/sidebar/Sidebar.module.scss +49 -0
  77. package/views/sidebar/Sidebar.tsx +30 -0
  78. package/views/sidebar/SidebarContainer.module.scss +22 -0
  79. package/views/sidebar/SidebarContainer.tsx +38 -0
  80. package/views/sidebar/SidebarContext.tsx +15 -0
  81. package/views/sidebar/SidebarToggleButton.tsx +25 -0
  82. package/components/toast/toast.tsx +0 -65
@@ -1,114 +1,121 @@
1
- /*
2
- * Copyright ©2024 Ewsgit<https://github.com/ewsgit> and YourDash<https://github.com/yourdash> contributors.
3
- * YourDash is licensed under the MIT License. (https://ewsgit.mit-license.org)
4
- */
5
-
6
- import React, { FC, useRef, useState } from "react";
7
-
8
- const PanAndZoom: FC<{ children: React.ReactNode; minZoom?: number; maxZoom?: number }> = ({
9
- children,
10
- minZoom,
11
- maxZoom,
12
- }) => {
13
- const containerRef = useRef<HTMLDivElement>(null);
14
- const [translateX, setTranslateX] = useState(0);
15
- const [translateY, setTranslateY] = useState(0);
16
- const [scale, setScale] = useState(1);
17
-
18
- const handleWheel = (event: WheelEvent) => {
19
- event.stopPropagation();
20
- const delta = event.deltaY;
21
- const newScale = scale + delta / 1000;
22
- setScale(Math.min(Math.max(newScale, minZoom ?? 0.1), maxZoom ?? 10));
23
- };
24
-
25
- const handleMouseDown = (event: React.MouseEvent<HTMLDivElement>) => {
26
- event.stopPropagation();
27
- const startX = event.clientX;
28
- const startY = event.clientY;
29
- const startTranslateX = translateX;
30
- const startTranslateY = translateY;
31
-
32
- // eslint-disable-next-line @typescript-eslint/no-shadow
33
- const handleMouseMove = (event: MouseEvent) => {
34
- event.stopPropagation();
35
- const deltaX = event.clientX - startX;
36
- const deltaY = event.clientY - startY;
37
- setTranslateX(startTranslateX + deltaX);
38
- setTranslateY(startTranslateY + deltaY);
39
- };
40
-
41
- const handleMouseUp = () => {
42
- event.stopPropagation();
43
- document.removeEventListener("mousemove", handleMouseMove);
44
- document.removeEventListener("mouseup", handleMouseUp);
45
- };
46
-
47
- document.addEventListener("mousemove", handleMouseMove);
48
- document.addEventListener("mouseup", handleMouseUp);
49
- };
50
-
51
- const handleTouchStart = (event: React.TouchEvent<HTMLDivElement>) => {
52
- event.stopPropagation();
53
- const startTouches = event.touches;
54
- const startTranslateX = translateX;
55
- const startTranslateY = translateY;
56
-
57
- // eslint-disable-next-line @typescript-eslint/no-shadow
58
- const handleTouchMove = (event: TouchEvent) => {
59
- event.stopPropagation();
60
- const currentTouches = event.touches;
61
- const deltaX = currentTouches[0].clientX - startTouches[0].clientX;
62
- const deltaY = currentTouches[0].clientY - startTouches[0].clientY;
63
- setTranslateX(startTranslateX + deltaX);
64
- setTranslateY(startTranslateY + deltaY);
65
- };
66
-
67
- const handleTouchEnd = () => {
68
- event.stopPropagation();
69
- document.removeEventListener("touchmove", handleTouchMove);
70
- document.removeEventListener("touchend", handleTouchEnd);
71
- };
72
-
73
- document.addEventListener("touchmove", handleTouchMove);
74
- document.addEventListener("touchend", handleTouchEnd);
75
- };
76
-
77
- return (
78
- <div
79
- ref={containerRef}
80
- style={{
81
- width: "100%",
82
- height: "100%",
83
- overflow: "hidden",
84
- display: "flex",
85
- alignItems: "center",
86
- justifyContent: "center",
87
- }}
88
- onWheel={handleWheel as unknown as React.WheelEventHandler<HTMLDivElement>}
89
- onMouseDown={handleMouseDown}
90
- onTouchStart={handleTouchStart}
91
- onDragStart={(event) => {
92
- event.stopPropagation();
93
- event.preventDefault();
94
- }}
95
- onContextMenu={(event) => {
96
- event.preventDefault();
97
- event.stopPropagation();
98
- }}
99
- >
100
- <div
101
- style={{
102
- transform: `translate(${translateX}px, ${translateY}px) scale(${scale})`,
103
- transformOrigin: "center center",
104
- maxWidth: "max-content",
105
- pointerEvents: "none",
106
- }}
107
- >
108
- {children}
109
- </div>
110
- </div>
111
- );
112
- };
113
-
114
- export default PanAndZoom;
1
+ /*
2
+ * Copyright ©2024 Ewsgit<https://github.com/ewsgit> and YourDash<https://github.com/yourdash> contributors.
3
+ * YourDash is licensed under the MIT License. (https://ewsgit.mit-license.org)
4
+ */
5
+
6
+ import React, { FC, useEffect, useRef, useState } from "react";
7
+
8
+ const PanAndZoom: FC<{ children: React.ReactNode; minZoom?: number; maxZoom?: number; onScaleChange?: (scale: number) => void }> = ({
9
+ children,
10
+ minZoom,
11
+ maxZoom,
12
+ onScaleChange,
13
+ }) => {
14
+ const containerRef = useRef<HTMLDivElement>(null);
15
+ const [translateX, setTranslateX] = useState(0);
16
+ const [translateY, setTranslateY] = useState(0);
17
+ const [scale, setScale] = useState(1);
18
+
19
+ if (onScaleChange) {
20
+ useEffect(() => {
21
+ onScaleChange(scale);
22
+ }, [scale]);
23
+ }
24
+
25
+ const handleWheel = (event: WheelEvent) => {
26
+ event.stopPropagation();
27
+ const delta = event.deltaY;
28
+ const newScale = scale + delta / 1000;
29
+ setScale(Math.min(Math.max(newScale, minZoom ?? 0.1), maxZoom ?? 10));
30
+ };
31
+
32
+ const handleMouseDown = (event: React.MouseEvent<HTMLDivElement>) => {
33
+ event.stopPropagation();
34
+ const startX = event.clientX;
35
+ const startY = event.clientY;
36
+ const startTranslateX = translateX;
37
+ const startTranslateY = translateY;
38
+
39
+ // eslint-disable-next-line @typescript-eslint/no-shadow
40
+ const handleMouseMove = (event: MouseEvent) => {
41
+ event.stopPropagation();
42
+ const deltaX = event.clientX - startX;
43
+ const deltaY = event.clientY - startY;
44
+ setTranslateX(startTranslateX + deltaX);
45
+ setTranslateY(startTranslateY + deltaY);
46
+ };
47
+
48
+ const handleMouseUp = () => {
49
+ event.stopPropagation();
50
+ document.removeEventListener("mousemove", handleMouseMove);
51
+ document.removeEventListener("mouseup", handleMouseUp);
52
+ };
53
+
54
+ document.addEventListener("mousemove", handleMouseMove);
55
+ document.addEventListener("mouseup", handleMouseUp);
56
+ };
57
+
58
+ const handleTouchStart = (event: React.TouchEvent<HTMLDivElement>) => {
59
+ event.stopPropagation();
60
+ const startTouches = event.touches;
61
+ const startTranslateX = translateX;
62
+ const startTranslateY = translateY;
63
+
64
+ // eslint-disable-next-line @typescript-eslint/no-shadow
65
+ const handleTouchMove = (event: TouchEvent) => {
66
+ event.stopPropagation();
67
+ const currentTouches = event.touches;
68
+ const deltaX = currentTouches[0].clientX - startTouches[0].clientX;
69
+ const deltaY = currentTouches[0].clientY - startTouches[0].clientY;
70
+ setTranslateX(startTranslateX + deltaX);
71
+ setTranslateY(startTranslateY + deltaY);
72
+ };
73
+
74
+ const handleTouchEnd = () => {
75
+ event.stopPropagation();
76
+ document.removeEventListener("touchmove", handleTouchMove);
77
+ document.removeEventListener("touchend", handleTouchEnd);
78
+ };
79
+
80
+ document.addEventListener("touchmove", handleTouchMove);
81
+ document.addEventListener("touchend", handleTouchEnd);
82
+ };
83
+
84
+ return (
85
+ <div
86
+ ref={containerRef}
87
+ style={{
88
+ width: "100%",
89
+ height: "100%",
90
+ overflow: "hidden",
91
+ display: "flex",
92
+ alignItems: "center",
93
+ justifyContent: "center",
94
+ }}
95
+ onWheel={handleWheel as unknown as React.WheelEventHandler<HTMLDivElement>}
96
+ onMouseDown={handleMouseDown}
97
+ onTouchStart={handleTouchStart}
98
+ onDragStart={(event) => {
99
+ event.stopPropagation();
100
+ event.preventDefault();
101
+ }}
102
+ onContextMenu={(event) => {
103
+ event.preventDefault();
104
+ event.stopPropagation();
105
+ }}
106
+ >
107
+ <div
108
+ style={{
109
+ transform: `translate(${translateX}px, ${translateY}px) scale(${scale})`,
110
+ transformOrigin: "center center",
111
+ maxWidth: "max-content",
112
+ pointerEvents: "none",
113
+ }}
114
+ >
115
+ {children}
116
+ </div>
117
+ </div>
118
+ );
119
+ };
120
+
121
+ export default PanAndZoom;
@@ -0,0 +1,49 @@
1
+ /*!
2
+ * Copyright ©2024 Ewsgit<https://github.com/ewsgit> and YourDash<https://github.com/yourdash> contributors.
3
+ * YourDash is licensed under the MIT License. (https://ewsgit.mit-license.org)
4
+ */
5
+
6
+ @use "@yourdash/uikit/theme/themeValues" as *;
7
+
8
+ .component {
9
+ height: 100%;
10
+ background: var(#{$theme+$background});
11
+ pointer-events: none;
12
+ opacity: 0;
13
+ border: var(#{$theme+$border});
14
+ border-top: 0;
15
+ border-bottom: 0;
16
+ border-left: 0;
17
+ flex-direction: column;
18
+ max-height: 100%;
19
+ max-width: 0;
20
+ transition: transform var(#{$theme+$transition+$transition}), max-height var(#{$theme+$transition+$transition});
21
+ transform: translateX(-100%);
22
+ visibility: hidden;
23
+ padding: 0;
24
+
25
+ @media (max-width: $sizeTablet) {
26
+ max-width: 100%;
27
+ max-height: 0;
28
+ height: max-content;
29
+ border-right: 0;
30
+ border-bottom: unset;
31
+ }
32
+
33
+ >*[type="button"] {
34
+ min-width: 100%;
35
+ }
36
+ }
37
+
38
+ .open {
39
+ pointer-events: all;
40
+ opacity: 1;
41
+ transform: translateX(0);
42
+ visibility: visible;
43
+ max-width: 32rem;
44
+ padding: var(#{$theme+$padding});
45
+
46
+ @media (max-width: $sizeTablet) {
47
+ height: max-content;
48
+ }
49
+ }
@@ -0,0 +1,30 @@
1
+ /*
2
+ * Copyright ©2024 Ewsgit<https://github.com/ewsgit> and YourDash<https://github.com/yourdash> contributors.
3
+ * YourDash is licensed under the MIT License. (https://ewsgit.mit-license.org)
4
+ */
5
+
6
+ import clippy from "@yourdash/shared/web/helpers/clippy.ts";
7
+ import Flex from "../../components/flex/flex.tsx";
8
+ import IncrementLevel from "../../core/incrementLevel.tsx";
9
+ import { useLevel, useLevelClass } from "../../core/level.tsx";
10
+ import styles from "./Sidebar.module.scss";
11
+ import SidebarContext from "./SidebarContext.tsx";
12
+ import { FC, useContext } from "react";
13
+
14
+ const Sidebar: FC<{ children: React.ReactNode | React.ReactNode[] }> = ({ children }) => {
15
+ const sidebarContext = useContext(SidebarContext);
16
+ const level = useLevel();
17
+
18
+ return (
19
+ <IncrementLevel>
20
+ <Flex
21
+ direction={"column"}
22
+ className={clippy(styles.component, sidebarContext.isOpen && styles.open, useLevelClass(level + 1))}
23
+ >
24
+ {children}
25
+ </Flex>
26
+ </IncrementLevel>
27
+ );
28
+ };
29
+
30
+ export default Sidebar;
@@ -0,0 +1,22 @@
1
+ /*!
2
+ * Copyright ©2024 Ewsgit<https://github.com/ewsgit> and YourDash<https://github.com/yourdash> contributors.
3
+ * YourDash is licensed under the MIT License. (https://ewsgit.mit-license.org)
4
+ */
5
+
6
+ @import '@yourdash/uikit/theme/themeValues';
7
+
8
+ .component {
9
+ display: flex;
10
+ flex-direction: row;
11
+ width: 100%;
12
+ height: 100%;
13
+ overflow: hidden;
14
+
15
+ &[dir=rtl] {
16
+ flex-direction: row-reverse;
17
+ }
18
+
19
+ @media (max-width: $sizeTablet) {
20
+ flex-direction: column;
21
+ }
22
+ }
@@ -0,0 +1,38 @@
1
+ /*
2
+ * Copyright ©2024 Ewsgit<https://github.com/ewsgit> and YourDash<https://github.com/yourdash> contributors.
3
+ * YourDash is licensed under the MIT License. (https://ewsgit.mit-license.org)
4
+ */
5
+
6
+ import React, { FC, useState } from "react";
7
+ import SidebarContext from "./SidebarContext.tsx";
8
+ import styles from "./SidebarContainer.module.scss";
9
+ import clippy from "@yourdash/shared/web/helpers/clippy.ts";
10
+
11
+ const SidebarContainer: FC<{ children: React.ReactNode | React.ReactNode[]; showSidebarByDefault?: boolean; className?: string }> = ({
12
+ children,
13
+ showSidebarByDefault,
14
+ className,
15
+ }) => {
16
+ const [showSidebar, setShowSidebar] = useState<boolean>(showSidebarByDefault || true);
17
+
18
+ return (
19
+ <SidebarContext.Provider
20
+ value={{
21
+ closeSidebar: () => {
22
+ setShowSidebar(false);
23
+ },
24
+ toggleSidebar: () => {
25
+ setShowSidebar(!showSidebar);
26
+ },
27
+ openSidebar: () => {
28
+ setShowSidebar(true);
29
+ },
30
+ isOpen: showSidebar,
31
+ }}
32
+ >
33
+ <div className={clippy(styles.component, className)}>{children}</div>
34
+ </SidebarContext.Provider>
35
+ );
36
+ };
37
+
38
+ export default SidebarContainer;
@@ -0,0 +1,15 @@
1
+ /*
2
+ * Copyright ©2024 Ewsgit<https://github.com/ewsgit> and YourDash<https://github.com/yourdash> contributors.
3
+ * YourDash is licensed under the MIT License. (https://ewsgit.mit-license.org)
4
+ */
5
+
6
+ import { createContext } from "react";
7
+
8
+ const SidebarContext = createContext({
9
+ openSidebar: () => {},
10
+ closeSidebar: () => {},
11
+ toggleSidebar: () => {},
12
+ isOpen: true,
13
+ });
14
+
15
+ export default SidebarContext;
@@ -0,0 +1,25 @@
1
+ /*
2
+ * Copyright ©2024 Ewsgit<https://github.com/ewsgit> and YourDash<https://github.com/yourdash> contributors.
3
+ * YourDash is licensed under the MIT License. (https://ewsgit.mit-license.org)
4
+ */
5
+
6
+ import { FC, useContext } from "react";
7
+ import { UKIcon } from "../../components/icon/iconDictionary.ts";
8
+ import SidebarContext from "./SidebarContext.tsx";
9
+ import IconButton from "../../components/iconButton/iconButton.tsx";
10
+
11
+ const SidebarToggleButton: FC = () => {
12
+ const sidebarContext = useContext(SidebarContext);
13
+
14
+ return (
15
+ <IconButton
16
+ accessibleLabel={sidebarContext.isOpen ? "Collapse Sidebar" : "Expand Sidebar"}
17
+ icon={sidebarContext.isOpen ? UKIcon.SidebarCollapse : UKIcon.SidebarExpand}
18
+ onClick={() => {
19
+ sidebarContext.toggleSidebar();
20
+ }}
21
+ />
22
+ );
23
+ };
24
+
25
+ export default SidebarToggleButton;
@@ -1,65 +0,0 @@
1
- /*
2
- * Copyright ©2024 Ewsgit<https://github.com/ewsgit> and YourDash<https://github.com/yourdash> contributors.
3
- * YourDash is licensed under the MIT License. (https://ewsgit.mit-license.org)
4
- */
5
-
6
- import clippy from "@yourdash/shared/web/helpers/clippy.js";
7
- import { FC, useState } from "react";
8
- import Card from "../card/card.js";
9
- import { UKIcon } from "../icon/iconDictionary.js";
10
- import IconButton from "../iconButton/iconButton.js";
11
- import Text from "../text/text.js";
12
- import ToastContext from "./toastContext.js";
13
- import React from "react";
14
- import styles from "./toast.module.scss";
15
-
16
- const Toast: FC<{ children: React.ReactNode | React.ReactNode[] }> = ({ children }) => {
17
- const [toasts, setToasts] = useState<
18
- { type: "success" | "error" | "warning" | "info"; content: string; persist?: boolean; timestamp: number }[]
19
- >([]);
20
-
21
- return (
22
- <>
23
- <ToastContext.Provider
24
- value={{
25
- showToast: (data: { type: "success" | "error" | "warning" | "info"; content: string; persist?: boolean }) => {
26
- const timestamp = Date.now();
27
-
28
- setToasts([...toasts, { ...data, timestamp: timestamp }]);
29
-
30
- if (!data.persist) {
31
- setTimeout(() => {
32
- setToasts(toasts.filter((t) => t.timestamp !== timestamp));
33
- }, 5000);
34
- }
35
- },
36
- }}
37
- >
38
- <div className={styles.container}>
39
- {toasts.map((t) => {
40
- return (
41
- <Card
42
- key={t.timestamp}
43
- actions={
44
- t.persist ? (
45
- <IconButton
46
- accessibleLabel={"Close toast"}
47
- icon={UKIcon.X}
48
- onClick={() => setToasts(toasts.filter((x) => x.timestamp !== t.timestamp))}
49
- />
50
- ) : null
51
- }
52
- containerClassName={clippy(styles.component, t.type && styles[t.type])}
53
- >
54
- <Text text={t.content} />
55
- </Card>
56
- );
57
- })}
58
- </div>
59
- {children}
60
- </ToastContext.Provider>
61
- </>
62
- );
63
- };
64
-
65
- export default Toast;