@trackunit/react-components 0.1.96 → 0.1.99

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/index.cjs CHANGED
@@ -1159,18 +1159,28 @@ const useClickOutside = (el, options = {}, onClick) => {
1159
1159
  *
1160
1160
  * @param {any} value The value to set
1161
1161
  * @param {number} delay The debounce time
1162
- * @returns {any} value The latest values received
1162
+ * @param {"in" | "out" | "both"} direction Considers truthiness of value. If set to "in", the value will only be debounced if it is truthy. If set to "out", the value will only be debounced if it is falsy. If set to "both" or if not defined, the value will be debounced regardless of truthiness.
1163
+ * @returns {any} The latest value received
1163
1164
  */
1164
- const useDebounce = (value, delay = 500) => {
1165
+ const useDebounce = (value, delay = 500, direction) => {
1165
1166
  const [debouncedValue, setDebouncedValue] = React.useState(value);
1166
1167
  React.useEffect(() => {
1167
- const handler = setTimeout(() => {
1168
+ let handler;
1169
+ if ((direction === "in" && !debouncedValue && value) ||
1170
+ (direction === "out" && debouncedValue && !value) ||
1171
+ direction === "both" ||
1172
+ !direction) {
1173
+ handler = setTimeout(() => {
1174
+ setDebouncedValue(value);
1175
+ }, delay);
1176
+ }
1177
+ else {
1168
1178
  setDebouncedValue(value);
1169
- }, delay);
1179
+ }
1170
1180
  return () => {
1171
1181
  clearTimeout(handler);
1172
1182
  };
1173
- }, [value, delay]);
1183
+ }, [value, delay, direction, debouncedValue]);
1174
1184
  return debouncedValue;
1175
1185
  };
1176
1186
 
@@ -1743,11 +1753,18 @@ const Space = tailwindStyledComponents.tw.div `
1743
1753
  * @param {SectionHeaderProps} props - The props for the section header component
1744
1754
  * @returns {JSX.Element} SectionHeader component
1745
1755
  */
1746
- const SectionHeader = ({ title, subtitle, dataTestId, addon }) => {
1747
- return (jsxRuntime.jsxs(SectionHeaderContainer, { children: [jsxRuntime.jsx(reactHelmetAsync.HelmetProvider, { children: jsxRuntime.jsx(reactHelmetAsync.Helmet, { title: title }) }), jsxRuntime.jsxs(StyledFlex, { children: [jsxRuntime.jsx(Heading$1, Object.assign({ variant: "secondary", dataTestId: dataTestId }, { children: title })), addon] }), subtitle && (jsxRuntime.jsx(Heading$1, Object.assign({ variant: "subtitle", subtle: true }, { children: subtitle }))), jsxRuntime.jsx(Spacer, { minHeight: "normal" })] }));
1756
+ const SectionHeader = ({ title, subtitle, dataTestId, addons }) => {
1757
+ return (jsxRuntime.jsxs(SectionHeaderContainer, { children: [jsxRuntime.jsx(reactHelmetAsync.HelmetProvider, { children: jsxRuntime.jsx(reactHelmetAsync.Helmet, { title: title }) }), jsxRuntime.jsxs(StyledFlex, Object.assign({ className: "flex-row mb-2" }, { children: [jsxRuntime.jsxs(StyledFlex, Object.assign({ className: "flex-col grow" }, { children: [jsxRuntime.jsx(Heading$1, Object.assign({ variant: "secondary", dataTestId: dataTestId }, { children: title })), subtitle && (jsxRuntime.jsx(Heading$1, Object.assign({ variant: "subtitle", subtle: true }, { children: subtitle })))] })), addons && jsxRuntime.jsx(StyledFlex, { children: addons })] })), jsxRuntime.jsx(Spacer, { minHeight: "normal" })] }));
1748
1758
  };
1749
- const SectionHeaderContainer = tailwindStyledComponents.tw.div `tu-section-header`;
1750
- const StyledFlex = tailwindStyledComponents.tw.div `tu-section-header__flex`;
1759
+ const SectionHeaderContainer = tailwindStyledComponents.tw.div `
1760
+ tu-section-header
1761
+ flex
1762
+ flex-col
1763
+ `;
1764
+ const StyledFlex = tailwindStyledComponents.tw.div `
1765
+ flex
1766
+ gap-2
1767
+ `;
1751
1768
 
1752
1769
  /**
1753
1770
  * A hook used to detect what children are overflowing a container.
package/index.css CHANGED
@@ -192,14 +192,3 @@
192
192
  hover:bg-transparent;
193
193
  }
194
194
  }
195
-
196
- .tu-section-header {
197
- @apply w-full;
198
-
199
- &__flex {
200
- @apply flex
201
- items-center
202
- flex-wrap-reverse
203
- gap-2;
204
- }
205
- }
package/index.js CHANGED
@@ -1132,18 +1132,28 @@ const useClickOutside = (el, options = {}, onClick) => {
1132
1132
  *
1133
1133
  * @param {any} value The value to set
1134
1134
  * @param {number} delay The debounce time
1135
- * @returns {any} value The latest values received
1135
+ * @param {"in" | "out" | "both"} direction Considers truthiness of value. If set to "in", the value will only be debounced if it is truthy. If set to "out", the value will only be debounced if it is falsy. If set to "both" or if not defined, the value will be debounced regardless of truthiness.
1136
+ * @returns {any} The latest value received
1136
1137
  */
1137
- const useDebounce = (value, delay = 500) => {
1138
+ const useDebounce = (value, delay = 500, direction) => {
1138
1139
  const [debouncedValue, setDebouncedValue] = useState(value);
1139
1140
  useEffect(() => {
1140
- const handler = setTimeout(() => {
1141
+ let handler;
1142
+ if ((direction === "in" && !debouncedValue && value) ||
1143
+ (direction === "out" && debouncedValue && !value) ||
1144
+ direction === "both" ||
1145
+ !direction) {
1146
+ handler = setTimeout(() => {
1147
+ setDebouncedValue(value);
1148
+ }, delay);
1149
+ }
1150
+ else {
1141
1151
  setDebouncedValue(value);
1142
- }, delay);
1152
+ }
1143
1153
  return () => {
1144
1154
  clearTimeout(handler);
1145
1155
  };
1146
- }, [value, delay]);
1156
+ }, [value, delay, direction, debouncedValue]);
1147
1157
  return debouncedValue;
1148
1158
  };
1149
1159
 
@@ -1716,11 +1726,18 @@ const Space = tw.div `
1716
1726
  * @param {SectionHeaderProps} props - The props for the section header component
1717
1727
  * @returns {JSX.Element} SectionHeader component
1718
1728
  */
1719
- const SectionHeader = ({ title, subtitle, dataTestId, addon }) => {
1720
- return (jsxs(SectionHeaderContainer, { children: [jsx(HelmetProvider, { children: jsx(Helmet, { title: title }) }), jsxs(StyledFlex, { children: [jsx(Heading$1, Object.assign({ variant: "secondary", dataTestId: dataTestId }, { children: title })), addon] }), subtitle && (jsx(Heading$1, Object.assign({ variant: "subtitle", subtle: true }, { children: subtitle }))), jsx(Spacer, { minHeight: "normal" })] }));
1729
+ const SectionHeader = ({ title, subtitle, dataTestId, addons }) => {
1730
+ return (jsxs(SectionHeaderContainer, { children: [jsx(HelmetProvider, { children: jsx(Helmet, { title: title }) }), jsxs(StyledFlex, Object.assign({ className: "flex-row mb-2" }, { children: [jsxs(StyledFlex, Object.assign({ className: "flex-col grow" }, { children: [jsx(Heading$1, Object.assign({ variant: "secondary", dataTestId: dataTestId }, { children: title })), subtitle && (jsx(Heading$1, Object.assign({ variant: "subtitle", subtle: true }, { children: subtitle })))] })), addons && jsx(StyledFlex, { children: addons })] })), jsx(Spacer, { minHeight: "normal" })] }));
1721
1731
  };
1722
- const SectionHeaderContainer = tw.div `tu-section-header`;
1723
- const StyledFlex = tw.div `tu-section-header__flex`;
1732
+ const SectionHeaderContainer = tw.div `
1733
+ tu-section-header
1734
+ flex
1735
+ flex-col
1736
+ `;
1737
+ const StyledFlex = tw.div `
1738
+ flex
1739
+ gap-2
1740
+ `;
1724
1741
 
1725
1742
  /**
1726
1743
  * A hook used to detect what children are overflowing a container.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trackunit/react-components",
3
- "version": "0.1.96",
3
+ "version": "0.1.99",
4
4
  "repository": "https://github.com/Trackunit/manager",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "dependencies": {
@@ -1,6 +1,5 @@
1
1
  import { ReactNode } from "react";
2
2
  import { CommonProps } from "../../common/CommonProps";
3
- import "./SectionHeader.css";
4
3
  export interface SectionHeaderProps extends CommonProps {
5
4
  /**
6
5
  * The title of the section.
@@ -13,7 +12,7 @@ export interface SectionHeaderProps extends CommonProps {
13
12
  /**
14
13
  * The addon could be used to tell the state of a section header.
15
14
  */
16
- addon?: ReactNode;
15
+ addons?: ReactNode;
17
16
  }
18
17
  /**
19
18
  * The SectionHeader component is used on sections to set the section title.
@@ -21,4 +20,4 @@ export interface SectionHeaderProps extends CommonProps {
21
20
  * @param {SectionHeaderProps} props - The props for the section header component
22
21
  * @returns {JSX.Element} SectionHeader component
23
22
  */
24
- export declare const SectionHeader: ({ title, subtitle, dataTestId, addon }: SectionHeaderProps) => JSX.Element;
23
+ export declare const SectionHeader: ({ title, subtitle, dataTestId, addons }: SectionHeaderProps) => JSX.Element;
@@ -0,0 +1,14 @@
1
+ import { CommonProps, Size } from "../../../common";
2
+ export type BackToTopColor = "primary" | "secondary";
3
+ export interface StyledBackToTopProps {
4
+ $color?: BackToTopColor;
5
+ }
6
+ export interface BackToTopProps extends CommonProps {
7
+ color?: BackToTopColor;
8
+ size?: Size;
9
+ }
10
+ /**
11
+ * BackToTopButton appears at the bottom-right corner of the screen when the user scrolls down the page. When clicked, the page scrolls smoothly to the top.
12
+ *
13
+ */
14
+ export declare const BackToTopButton: ({ color, size, dataTestId }: BackToTopProps) => JSX.Element;
@@ -3,6 +3,7 @@
3
3
  *
4
4
  * @param {any} value The value to set
5
5
  * @param {number} delay The debounce time
6
- * @returns {any} value The latest values received
6
+ * @param {"in" | "out" | "both"} direction Considers truthiness of value. If set to "in", the value will only be debounced if it is truthy. If set to "out", the value will only be debounced if it is falsy. If set to "both" or if not defined, the value will be debounced regardless of truthiness.
7
+ * @returns {any} The latest value received
7
8
  */
8
- export declare const useDebounce: <T>(value: T, delay?: number) => T;
9
+ export declare const useDebounce: <T>(value: T, delay?: number, direction?: "in" | "out" | "both") => T;