@trackunit/react-components 0.1.20 → 0.1.22

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.js CHANGED
@@ -579,11 +579,11 @@ const StyledCard$2 = tw.div `
579
579
  * @param {ContainerProps} props - The props for the DensityContainer component
580
580
  * @returns {JSX.Element} DensityContainer component
581
581
  */
582
- const DensityContainer = ({ children, className, dataTestId, $density, $disableGap, $direction, }) => {
583
- return (jsx(StyledDensityContainer$1, Object.assign({ "$disableGap": $disableGap, "$density": $density, "$direction": $direction, "data-testid": dataTestId, className: className }, { children: children })));
582
+ const DensityContainer = ({ children, className, dataTestId, density, disableGap, direction, }) => {
583
+ return (jsx(StyledDensityContainer$1, Object.assign({ "$disableGap": disableGap, "$density": density, "$direction": direction, "data-testid": dataTestId, className: className }, { children: children })));
584
584
  };
585
585
  const getDirection = () => ({ $direction }) => {
586
- $direction = $direction ? $direction : "column";
586
+ $direction = $direction !== null && $direction !== void 0 ? $direction : "column";
587
587
  const directions = {
588
588
  row: tws `flex-row`,
589
589
  "row-reverse": tws `flex-row-reverse`,
@@ -628,7 +628,7 @@ ${DensityFinder}
628
628
  * @returns {JSX.Element} CardBody component
629
629
  */
630
630
  const CardBody = ({ density = "auto", overflow = "auto", children, dataTestId, className, disableGap, }) => {
631
- return (jsx(StyledDensityContainer, Object.assign({ "$overflow": overflow, "$density": density, dataTestId: dataTestId, className: className, "$disableGap": disableGap }, { children: children })));
631
+ return (jsx(StyledDensityContainer, Object.assign({ "$overflow": overflow, density: density, dataTestId: dataTestId, className: className, disableGap: disableGap }, { children: children })));
632
632
  };
633
633
  const getOverflow = () => ({ $overflow }) => {
634
634
  if (!$overflow) {
@@ -656,14 +656,11 @@ const StyledDensityContainer = twx(DensityContainer) `
656
656
  * @returns {JSX.Element} CardFooter component
657
657
  */
658
658
  const CardFooter = ({ dataTestId, className, children, density, hideSeparator = false }) => {
659
- return (jsx(Container$7, Object.assign({ dataTestId: dataTestId, className: className, "$hideSeparator": hideSeparator, "$density": density }, { children: jsx(Body, { children: children }) })));
659
+ return (jsx(Container$7, Object.assign({ dataTestId: dataTestId, className: className, "$hideSeparator": hideSeparator, density: density, direction: "row" }, { children: children })));
660
660
  };
661
661
  const Container$7 = twx(DensityContainer) `
662
662
  tu-card__footer-density-container
663
663
  ${p => p.$hideSeparator && tws `tu-card__footer-density-container--borderless`}
664
- `;
665
- const Body = tw.div `
666
- tu-card__footer
667
664
  `;
668
665
 
669
666
  /**
@@ -708,7 +705,7 @@ const StyledHeading = tw.div `
708
705
  * @returns {JSX.Element} CardHeader component
709
706
  */
710
707
  const CardHeader = ({ heading, headingVariant = "primary", subHeading, onClose, dataTestId, className, children, accessories, density, extraClassName, hideSeparator = false, }) => {
711
- return (jsx(Root$8, Object.assign({ dataTestId: dataTestId, className: className, "$hideSeparator": hideSeparator, "$density": density }, { children: jsxs(Container$6, { children: [jsxs("div", Object.assign({ className: extraClassName }, { children: [jsxs(HeadingContainer$1, { children: [jsx(Heading$1, Object.assign({ variant: headingVariant }, { children: heading })), accessories] }), subHeading && (jsx(Heading$1, Object.assign({ subtle: true, variant: "subtitle" }, { children: subHeading }))), children] })), onClose && (jsx(IconButton, { dataTestId: "card-header-close-button", variant: "transparent", color: "secondary", onClick: onClose, icon: jsx(Icon$1, { name: "XIcon", size: "small" }) }))] }) })));
708
+ return (jsx(Root$8, Object.assign({ dataTestId: dataTestId, className: className, "$hideSeparator": hideSeparator, density: density }, { children: jsxs(Container$6, { children: [jsxs("div", Object.assign({ className: extraClassName }, { children: [jsxs(HeadingContainer$1, { children: [jsx(Heading$1, Object.assign({ variant: headingVariant }, { children: heading })), accessories] }), subHeading && (jsx(Heading$1, Object.assign({ subtle: true, variant: "subtitle" }, { children: subHeading }))), children] })), onClose && (jsx(IconButton, { dataTestId: "card-header-close-button", variant: "transparent", color: "secondary", onClick: onClose, icon: jsx(Icon$1, { name: "XIcon", size: "small" }), className: "self-start" }))] }) })));
712
709
  };
713
710
  const Root$8 = twx(DensityContainer) `
714
711
  tu-card__header-density-container
@@ -1485,25 +1482,13 @@ const Backdrop = tw.div `
1485
1482
  * - Modals interrupt a user's workflow by design.
1486
1483
  * - The modal component provides a foundation for creating dialogs, lightboxes, etc.
1487
1484
  */
1488
- const Modal = React.forwardRef(({ isOpen, children, maxWidth = "full", dataTestId, className, onDismissClick = () => {
1485
+ const Modal = React.forwardRef(({ isOpen, children, dataTestId, className, onDismissClick = () => {
1489
1486
  return;
1490
1487
  }, }, ref) => {
1491
- return (jsx(ModalBackdrop, Object.assign({ isVisible: isOpen, onClick: onDismissClick }, { children: isOpen && (jsx(StyledDiv, Object.assign({ ref: ref }, { children: jsx(StyledCard, Object.assign({ dataTestId: dataTestId, className: className, "$maxWidth": maxWidth }, { children: children })) }))) })));
1488
+ return (jsx(ModalBackdrop, Object.assign({ isVisible: isOpen, onClick: onDismissClick }, { children: isOpen && (jsx(StyledDiv, Object.assign({ ref: ref }, { children: jsx(StyledCard, Object.assign({ dataTestId: dataTestId, className: className }, { children: children })) }))) })));
1492
1489
  });
1493
- const getCardMaxWidth = ($maxWidth) => {
1494
- $maxWidth = $maxWidth ? $maxWidth : "full";
1495
- const widths = {
1496
- slim: tws `tu-modal__card--slim`,
1497
- narrow: tws `tu-modal__card--narrow`,
1498
- wide: tws `tu-modal__card--wide`,
1499
- normal: tws `tu-modal__card--normal`,
1500
- full: "",
1501
- };
1502
- return widths[$maxWidth];
1503
- };
1504
1490
  const StyledCard = twx(Card) `
1505
1491
  tu-modal__card
1506
- ${({ $maxWidth }) => getCardMaxWidth($maxWidth)}
1507
1492
  `;
1508
1493
  const StyledDiv = tw.div `
1509
1494
  tu-modal__container
@@ -2805,6 +2790,57 @@ const useDebounce = (value, delay = 500) => {
2805
2790
  return debouncedValue;
2806
2791
  };
2807
2792
 
2793
+ // Copied from https://github.com/rexxars/use-device-pixel-ratio
2794
+ /**
2795
+ * Get the device pixel ratio, potentially rounded and capped.
2796
+ * Will emit new values if it changes.
2797
+ *
2798
+ * @param {DevicePixelRatioOptions} options the options object
2799
+ * @returns { number } The current device pixel ratio, or the default if none can be resolved
2800
+ */
2801
+ function useDevicePixelRatio(options) {
2802
+ const dpr = getDevicePixelRatio(options);
2803
+ const [currentDpr, setCurrentDpr] = useState(dpr);
2804
+ const { defaultDpr, maxDpr, round } = options || {};
2805
+ useEffect(() => {
2806
+ const canListen = typeof window !== "undefined" && "matchMedia" in window;
2807
+ if (!canListen) {
2808
+ return;
2809
+ }
2810
+ const updateDpr = () => setCurrentDpr(getDevicePixelRatio({ defaultDpr, maxDpr, round }));
2811
+ const mediaMatcher = window.matchMedia(`screen and (resolution: ${currentDpr}dppx)`);
2812
+ // Safari 13.1 does not have `addEventListener`, but does have `addListener`
2813
+ if (mediaMatcher.addEventListener) {
2814
+ mediaMatcher.addEventListener("change", updateDpr);
2815
+ }
2816
+ else {
2817
+ mediaMatcher.addListener(updateDpr);
2818
+ }
2819
+ return () => {
2820
+ if (mediaMatcher.removeEventListener) {
2821
+ mediaMatcher.removeEventListener("change", updateDpr);
2822
+ }
2823
+ else {
2824
+ mediaMatcher.removeListener(updateDpr);
2825
+ }
2826
+ };
2827
+ }, [currentDpr, defaultDpr, maxDpr, round]);
2828
+ return currentDpr;
2829
+ }
2830
+ /**
2831
+ * Returns the current device pixel ratio (DPR) given the passed options
2832
+ *
2833
+ * @param { DevicePixelRatioOptions } options the options object
2834
+ * @returns { number } current device pixel ratio
2835
+ */
2836
+ function getDevicePixelRatio(options) {
2837
+ const { defaultDpr = 1, maxDpr = 3, round = true } = options || {};
2838
+ const hasDprProp = typeof window !== "undefined" && typeof window.devicePixelRatio === "number";
2839
+ const dpr = hasDprProp ? window.devicePixelRatio : defaultDpr;
2840
+ const rounded = Math.min(Math.max(1, round ? Math.floor(dpr) : dpr), maxDpr);
2841
+ return rounded;
2842
+ }
2843
+
2808
2844
  /**
2809
2845
  * The useLocalStorage hook works like useState, but saves to localstorage.
2810
2846
  *
@@ -3071,4 +3107,4 @@ const Layout = tw.div `
3071
3107
  tu-layout-TwoColumnLayout
3072
3108
  `;
3073
3109
 
3074
- export { ActionButton, Alert, Badge, BaseInput, Button, Card, CardBody, CardFooter, CardHeader, Chart, Checkbox, Collapse, ContentGridArea, CopyableText, CreatableSelect, DateField, DateInput, DayPicker, DayPickerPopover, DayRangePicker, DensityContainer, Drawer, ExternalLink, FilterListMapLayout, FormGroup, FullWidthRepeatingLayout, GridArea, Heading$1 as Heading, Icon$1 as Icon, IconButton, Indicator$1 as Indicator, IntrinsicallyResponsiveGrid, Label$2 as Label, LegendItem, MenuItem, MenuList, MinTopFullContentLayout, Modal, ModalBackdrop, MoreMenu, MultiSelectMenuItem, NavGridArea, NumberField, NumberInput, PageHeader, Pagination, PieChart, Popover, PopoverList, PopoverListItem, PopoverTitle, Prompt, ROLE_CARD, RadioGroup, RadioItem, Search, SectionHeader, Select, SelectPrefix, Sidebar, SingleSelectMenuItem, SkeletonLines, Spacer, Spinner, StarButton, Tag, Text$1 as Text, TextArea, TextAreaField, TextField, TextInput, Timeline, TimelineElement, Tip, TitleGridArea, TitleNavContentLayout, Toggle, Tooltip, TwoColumnLayout, ValueBar, docs, getOrderedOptions, getValueBarColorByValue, isMultiValue, useContainerProps, useCustomComponents, useDebounce, useLocalStorage, useModal, usePrompt, useTimeout };
3110
+ export { ActionButton, Alert, Badge, BaseInput, Button, Card, CardBody, CardFooter, CardHeader, Chart, Checkbox, Collapse, ContentGridArea, CopyableText, CreatableSelect, DateField, DateInput, DayPicker, DayPickerPopover, DayRangePicker, DensityContainer, Drawer, ExternalLink, FilterListMapLayout, FormGroup, FullWidthRepeatingLayout, GridArea, Heading$1 as Heading, Icon$1 as Icon, IconButton, Indicator$1 as Indicator, IntrinsicallyResponsiveGrid, Label$2 as Label, LegendItem, MenuItem, MenuList, MinTopFullContentLayout, Modal, ModalBackdrop, MoreMenu, MultiSelectMenuItem, NavGridArea, NumberField, NumberInput, PageHeader, Pagination, PieChart, Popover, PopoverList, PopoverListItem, PopoverTitle, Prompt, ROLE_CARD, RadioGroup, RadioItem, Search, SectionHeader, Select, SelectPrefix, Sidebar, SingleSelectMenuItem, SkeletonLines, Spacer, Spinner, StarButton, Tag, Text$1 as Text, TextArea, TextAreaField, TextField, TextInput, Timeline, TimelineElement, Tip, TitleGridArea, TitleNavContentLayout, Toggle, Tooltip, TwoColumnLayout, ValueBar, docs, getDevicePixelRatio, getOrderedOptions, getValueBarColorByValue, isMultiValue, useContainerProps, useCustomComponents, useDebounce, useDevicePixelRatio, useLocalStorage, useModal, usePrompt, useTimeout };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trackunit/react-components",
3
- "version": "0.1.20",
3
+ "version": "0.1.22",
4
4
  "repository": "https://github.com/Trackunit/manager",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "dependencies": {
@@ -23,6 +23,7 @@
23
23
  "react-router-dom": "6.4.5",
24
24
  "react-helmet-async": "1.3.0",
25
25
  "react-select": "5.7.0",
26
+ "react-dom": "18.2.0",
26
27
  "jest-canvas-mock": "2.4.0"
27
28
  },
28
29
  "module": "./index.js",
@@ -7,15 +7,15 @@ interface ContainerProps extends CommonProps {
7
7
  * "comfortable" = 16px gap and padding.
8
8
  * "spacious" = 16px gap, 26px padding.
9
9
  */
10
- $density?: Density;
10
+ density?: Density;
11
11
  /**
12
12
  * Set gap to be 0px (not preferable)
13
13
  */
14
- $disableGap?: boolean;
14
+ disableGap?: boolean;
15
15
  /**
16
16
  * The flex direction of the Card. Defaults to "column".
17
17
  */
18
- $direction?: "row" | "row-reverse" | "column" | "column-reverse";
18
+ direction?: "row" | "row-reverse" | "column" | "column-reverse";
19
19
  children?: React.ReactNode;
20
20
  }
21
21
  /**
@@ -26,5 +26,5 @@ interface ContainerProps extends CommonProps {
26
26
  * @param {ContainerProps} props - The props for the DensityContainer component
27
27
  * @returns {JSX.Element} DensityContainer component
28
28
  */
29
- export declare const DensityContainer: ({ children, className, dataTestId, $density, $disableGap, $direction, }: ContainerProps) => JSX.Element;
29
+ export declare const DensityContainer: ({ children, className, dataTestId, density, disableGap, direction, }: ContainerProps) => JSX.Element;
30
30
  export {};
@@ -1,6 +1,5 @@
1
1
  import * as React from "react";
2
2
  import { CommonProps } from "../../common/CommonProps";
3
- type ModalWidth = "slim" | "narrow" | "normal" | "wide" | "full";
4
3
  export interface ModalProps extends CommonProps {
5
4
  /**
6
5
  * Whether modal is open or not.
@@ -18,10 +17,6 @@ export interface ModalProps extends CommonProps {
18
17
  * Test id to be applied to the modal.
19
18
  */
20
19
  dataTestId?: string;
21
- /**
22
- * Maximum width of the modal.
23
- */
24
- maxWidth?: ModalWidth;
25
20
  }
26
21
  /**
27
22
  * - Modals are used to present critical information or request user input needed to complete a user's workflow.
@@ -29,4 +24,3 @@ export interface ModalProps extends CommonProps {
29
24
  * - The modal component provides a foundation for creating dialogs, lightboxes, etc.
30
25
  */
31
26
  export declare const Modal: React.ForwardRefExoticComponent<ModalProps & React.RefAttributes<HTMLDivElement>>;
32
- export {};
@@ -1,3 +1,4 @@
1
1
  export * from "./useDebounce";
2
+ export * from "./useDevicePixelRatio";
2
3
  export * from "./useLocalStorage";
3
4
  export * from "./useTimeout";
@@ -0,0 +1,37 @@
1
+ export interface DevicePixelRatioOptions {
2
+ /**
3
+ * Default DPR to use if browser does not support the `devicePixelRatio`
4
+ * property, or when rendering on server
5
+ *
6
+ * @default `1`
7
+ * @returns DPR
8
+ */
9
+ defaultDpr?: number;
10
+ /**
11
+ * Whether or not to round the number down to the closest integer
12
+ *
13
+ * @default `true`
14
+ */
15
+ round?: boolean;
16
+ /**
17
+ * Maximum DPR to return (set to `2` to only generate 1 and 2)
18
+ *
19
+ * @default `3`
20
+ */
21
+ maxDpr?: number;
22
+ }
23
+ /**
24
+ * Get the device pixel ratio, potentially rounded and capped.
25
+ * Will emit new values if it changes.
26
+ *
27
+ * @param {DevicePixelRatioOptions} options the options object
28
+ * @returns { number } The current device pixel ratio, or the default if none can be resolved
29
+ */
30
+ export declare function useDevicePixelRatio(options?: DevicePixelRatioOptions): number;
31
+ /**
32
+ * Returns the current device pixel ratio (DPR) given the passed options
33
+ *
34
+ * @param { DevicePixelRatioOptions } options the options object
35
+ * @returns { number } current device pixel ratio
36
+ */
37
+ export declare function getDevicePixelRatio(options?: DevicePixelRatioOptions): number;