@foodpilot/foods 2.11.25 → 2.11.30

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.
@@ -1,13 +1,29 @@
1
1
  import { jsx } from "react/jsx-runtime";
2
2
  import { TrajectoryComparison } from "./TrajectoryComparison.js";
3
3
  import { StartToCurrentArrow, CurrentToTargetArrow } from "../styles/index.js";
4
- const StartCurrentComparison = ({ currentValue, targetValue, orientation, improvement }) => /* @__PURE__ */ jsx(StartToCurrentArrow, { orientation, children: /* @__PURE__ */ jsx(TrajectoryComparison, { value: targetValue, comparedTo: currentValue, improvement }) });
4
+ const StartCurrentComparison = ({ currentValue, targetValue, orientation, improvement }) => /* @__PURE__ */ jsx(StartToCurrentArrow, { orientation, children: /* @__PURE__ */ jsx(
5
+ TrajectoryComparison,
6
+ {
7
+ value: targetValue,
8
+ comparedTo: currentValue,
9
+ improvement,
10
+ orientation
11
+ }
12
+ ) });
5
13
  const LastTargetComparison = ({
6
14
  currentValue,
7
15
  targetValue,
8
16
  orientation,
9
17
  improvement
10
- }) => /* @__PURE__ */ jsx(CurrentToTargetArrow, { orientation, children: /* @__PURE__ */ jsx(TrajectoryComparison, { value: targetValue, comparedTo: currentValue, improvement }) });
18
+ }) => /* @__PURE__ */ jsx(CurrentToTargetArrow, { orientation, children: /* @__PURE__ */ jsx(
19
+ TrajectoryComparison,
20
+ {
21
+ value: targetValue,
22
+ comparedTo: currentValue,
23
+ improvement,
24
+ orientation
25
+ }
26
+ ) });
11
27
  export {
12
28
  LastTargetComparison,
13
29
  StartCurrentComparison
@@ -1,9 +1,11 @@
1
1
  import { Improvement } from '../../../ComparisonBlock/ComparisonBlock.tsx';
2
+ import { TrajectoryPosition } from '../Blocks/types.ts';
2
3
  import { StepType } from './Step.tsx';
3
4
  type TrajectoryComparisonProps = {
4
5
  value: StepType["value"];
5
6
  comparedTo: StepType["value"];
6
7
  improvement: Improvement;
8
+ orientation: TrajectoryPosition | undefined;
7
9
  };
8
10
  export declare const TrajectoryComparison: (props: TrajectoryComparisonProps) => import("react/jsx-runtime").JSX.Element | undefined;
9
11
  export {};
@@ -1,27 +1,17 @@
1
1
  import { jsx } from "react/jsx-runtime";
2
- import { ComparisonBlock } from "../../../ComparisonBlock/ComparisonBlock.js";
2
+ import { ComparisonArrow } from "../../../ComparisonBlock/ComparisonArrow.js";
3
3
  const TrajectoryComparison = (props) => {
4
- const { value, comparedTo, improvement } = props;
4
+ const { value, comparedTo, improvement, orientation } = props;
5
5
  if (value === null || comparedTo === null) {
6
6
  return;
7
7
  }
8
8
  return /* @__PURE__ */ jsx(
9
- ComparisonBlock,
9
+ ComparisonArrow,
10
10
  {
11
- layout: {
12
- size: "M",
13
- direction: "horizontal"
14
- },
15
- disableText: true,
16
- currentValue: value,
17
- comparedTo: {
18
- value: comparedTo,
19
- unit: "",
20
- // not used
21
- label: ""
22
- // not used
23
- },
24
- improvement
11
+ value,
12
+ comparedTo,
13
+ improvement,
14
+ arrowDirection: orientation === "vertical" ? "bottom" : "right"
25
15
  }
26
16
  );
27
17
  };
@@ -0,0 +1,20 @@
1
+ import { Improvement } from './ComparisonBlock';
2
+ import { ColorSet } from './useColorAndArrow';
3
+ export type ArrowDirection = "bottom" | "right";
4
+ export type ComparisonSign = "+" | "-" | "=";
5
+ export type ComparisonArrowProps = {
6
+ value: number | string;
7
+ comparedTo: number | string;
8
+ improvement: Improvement;
9
+ arrowDirection: ArrowDirection;
10
+ locale?: string;
11
+ };
12
+ export declare const ComparisonArrow: (props: ComparisonArrowProps) => import("react/jsx-runtime").JSX.Element;
13
+ type DiffPercentageTagProps = {
14
+ value: number;
15
+ color: ColorSet;
16
+ sign: ComparisonSign;
17
+ position?: "right" | "bottom";
18
+ };
19
+ export declare const DiffPercentageTag: (props: DiffPercentageTagProps) => import("react/jsx-runtime").JSX.Element;
20
+ export {};
@@ -0,0 +1,120 @@
1
+ import { jsx, Fragment, jsxs } from "react/jsx-runtime";
2
+ import { Stack, useTheme, Box, Typography } from "@mui/material";
3
+ import { useColorAndArrowIcon } from "./useColorAndArrow.js";
4
+ const ComparisonArrow = (props) => {
5
+ const { value, comparedTo, improvement, arrowDirection } = props;
6
+ const previousValue = Number(comparedTo);
7
+ const currentValue = Number(value);
8
+ const percentageDifference = previousValue > 0 ? Math.abs(100 - currentValue / previousValue * 100) : Infinity;
9
+ const colorAndArrowIcon = useColorAndArrowIcon({
10
+ currentValue,
11
+ previousValue,
12
+ improvement,
13
+ layout: {
14
+ size: "M",
15
+ direction: "horizontal"
16
+ }
17
+ });
18
+ if (isNaN(percentageDifference) || percentageDifference === Infinity || percentageDifference === -Infinity) {
19
+ return /* @__PURE__ */ jsx(Fragment, {});
20
+ }
21
+ const positive = percentageDifference >= 0;
22
+ const isNeutral = percentageDifference === 0;
23
+ const sign = isNeutral ? "=" : positive ? "+" : "-";
24
+ return /* @__PURE__ */ jsx(Stack, { width: "60px", children: /* @__PURE__ */ jsx(
25
+ DiffPercentageTag,
26
+ {
27
+ position: arrowDirection,
28
+ value: percentageDifference,
29
+ color: colorAndArrowIcon.color,
30
+ sign
31
+ }
32
+ ) });
33
+ };
34
+ const DiffPercentageTag = (props) => {
35
+ const { value, position = "right" } = props;
36
+ const theme = useTheme();
37
+ const bgColor = props.color.secondaryColor;
38
+ const accentColor = props.color.primaryColor;
39
+ const isRight = position === "right";
40
+ return /* @__PURE__ */ jsxs(
41
+ Box,
42
+ {
43
+ sx: {
44
+ display: "inline-flex",
45
+ position: "relative",
46
+ alignItems: "center",
47
+ justifyContent: "center",
48
+ backgroundColor: bgColor,
49
+ border: `2px solid ${accentColor}`,
50
+ borderRight: isRight ? "none" : void 0,
51
+ borderRadius: theme.spacing(0.75),
52
+ padding: theme.spacing(0.25, 0.75),
53
+ paddingRight: theme.spacing(1),
54
+ height: "26px",
55
+ zIndex: 2
56
+ },
57
+ children: [
58
+ isRight ? /* @__PURE__ */ jsx(
59
+ Box,
60
+ {
61
+ sx: {
62
+ background: `linear-gradient(45deg, transparent 0%, transparent 55%, ${bgColor} 55%, ${bgColor} 100%)`,
63
+ position: "absolute",
64
+ border: `2px solid ${accentColor}`,
65
+ borderLeft: "none",
66
+ borderBottom: "none",
67
+ borderRadius: theme.spacing(0.75),
68
+ borderTopRightRadius: theme.spacing(0.5),
69
+ borderBottomRightRadius: theme.spacing(0.25),
70
+ borderTopLeftRadius: theme.spacing(0.25),
71
+ height: "18px",
72
+ width: "18px",
73
+ right: -7,
74
+ top: 2,
75
+ transform: "rotate(45deg)",
76
+ zIndex: -2
77
+ }
78
+ }
79
+ ) : /* @__PURE__ */ jsx(
80
+ Box,
81
+ {
82
+ sx: {
83
+ background: `linear-gradient(135deg, transparent 0%, transparent 45%, ${bgColor} 45%, ${bgColor} 100%)`,
84
+ position: "absolute",
85
+ border: `2px solid ${accentColor}`,
86
+ borderTop: "none",
87
+ borderLeft: "none",
88
+ borderRadius: "1.5px",
89
+ height: "12px",
90
+ width: "12px",
91
+ bottom: -7,
92
+ left: "50%",
93
+ transform: "translateX(-50%) rotate(45deg)",
94
+ zIndex: -2
95
+ }
96
+ }
97
+ ),
98
+ /* @__PURE__ */ jsxs(
99
+ Stack,
100
+ {
101
+ flexDirection: "row",
102
+ gap: theme.spacing(0.5),
103
+ sx: { lineHeight: 1, position: "relative", zIndex: 1 },
104
+ children: [
105
+ /* @__PURE__ */ jsx(Typography, { variant: "small-bold", sx: { color: accentColor }, children: props.sign }),
106
+ /* @__PURE__ */ jsxs(Typography, { variant: "small-bold", title: value.toString(), children: [
107
+ Math.round(value),
108
+ "%"
109
+ ] })
110
+ ]
111
+ }
112
+ )
113
+ ]
114
+ }
115
+ );
116
+ };
117
+ export {
118
+ ComparisonArrow,
119
+ DiffPercentageTag
120
+ };
@@ -0,0 +1,7 @@
1
+ export type ArrowDirection = "bottom" | "right" | "top" | "left";
2
+ type ArrowProps = unknown;
3
+ export declare const UpArrow: (_props: ArrowProps) => import("react/jsx-runtime").JSX.Element;
4
+ export declare const DownArrow: (_props: ArrowProps) => import("react/jsx-runtime").JSX.Element;
5
+ export declare const LeftArrow: (_props: ArrowProps) => import("react/jsx-runtime").JSX.Element;
6
+ export declare const RightArrow: (_props: ArrowProps) => import("react/jsx-runtime").JSX.Element;
7
+ export {};
@@ -1 +1,2 @@
1
1
  export { ComparisonBlock } from './ComparisonBlock.tsx';
2
+ export { ComparisonArrow } from './ComparisonArrow.tsx';
@@ -53,8 +53,12 @@ export type SidebarTexts = {
53
53
  shortenSidebar: string;
54
54
  logout: string;
55
55
  };
56
+ type OrganizationPopoverActions = {
57
+ closePopover: () => void;
58
+ };
56
59
  export type OrganizationPopover = {
57
60
  element: JSX.Element;
61
+ renderPopover?: (actions: OrganizationPopoverActions) => ReactNode;
58
62
  };
59
63
  export type Organization = {
60
64
  name: string;
@@ -76,3 +80,4 @@ export type FoodsNavbarProps = {
76
80
  onMobileDrawerClose?: () => void;
77
81
  };
78
82
  export declare const FoodsNavbar: (props: FoodsNavbarProps) => import("react/jsx-runtime").JSX.Element;
83
+ export {};
@@ -1,9 +1,10 @@
1
1
  import { SxProps } from '@mui/material';
2
+ import { ReactNode } from 'react';
2
3
  type Anchor = HTMLElement | null;
3
4
  type ButtonPopoverProps = {
4
5
  anchor: Anchor;
5
6
  setAnchor: (elementToAttachTo: Anchor) => void;
6
- children: JSX.Element | undefined;
7
+ children: ReactNode;
7
8
  paperOverrides: SxProps | undefined;
8
9
  };
9
10
  export declare const ButtonPopover: (props: ButtonPopoverProps) => import("react/jsx-runtime").JSX.Element;
@@ -7,6 +7,11 @@ const Organization = (props) => {
7
7
  const { isExtended, name, picture, popover } = props;
8
8
  const theme = useTheme();
9
9
  const [anchor, setAnchor] = useState(null);
10
+ const closePopover = () => setAnchor(null);
11
+ const actions = {
12
+ closePopover
13
+ };
14
+ const toRender = (popover == null ? void 0 : popover.renderPopover) ? popover.renderPopover(actions) : popover == null ? void 0 : popover.element;
10
15
  return /* @__PURE__ */ jsxs(Fragment, { children: [
11
16
  /* @__PURE__ */ jsxs(
12
17
  Box,
@@ -82,15 +87,7 @@ const Organization = (props) => {
82
87
  sx: {
83
88
  flex: 1
84
89
  },
85
- children: /* @__PURE__ */ jsx(
86
- ButtonPopover,
87
- {
88
- anchor,
89
- setAnchor,
90
- children: popover == null ? void 0 : popover.element,
91
- paperOverrides: void 0
92
- }
93
- )
90
+ children: /* @__PURE__ */ jsx(ButtonPopover, { anchor, setAnchor, paperOverrides: void 0, children: toRender })
94
91
  }
95
92
  )
96
93
  ] });
@@ -13,8 +13,8 @@ const UserButton = (props) => {
13
13
  const isUserPopoverOpen = Boolean(anchor);
14
14
  const onClose = () => setAnchor(null);
15
15
  const fullName = `${user.firstname} ${user.lastname}`;
16
- const firstName = user.firstname.replaceAll(" ", " ");
17
- const lastName = user.lastname.replaceAll(" ", " ");
16
+ const firstName = user.firstname.replaceAll(" ", " ");
17
+ const lastName = user.lastname.replaceAll(" ", " ");
18
18
  return /* @__PURE__ */ jsxs(
19
19
  Box,
20
20
  {
package/dist/main.js CHANGED
@@ -53,6 +53,7 @@ import { Article } from "./components/CMS/ArticleBlock/Article.js";
53
53
  import { IndicatorBlock } from "./components/CMS/IndicatorBlock/IndicatorBlock.js";
54
54
  import { LightIndicatorBlock } from "./components/CMS/IndicatorBlock/LightIndicatorBlock.js";
55
55
  import { ComparisonBlock } from "./components/ComparisonBlock/ComparisonBlock.js";
56
+ import { ComparisonArrow } from "./components/ComparisonBlock/ComparisonArrow.js";
56
57
  import { CustomTypography } from "./components/CustomTypography/CustomTypography.js";
57
58
  import { TypographyList } from "./components/CustomTypography/TypographyList.js";
58
59
  import { PrimaryDialog } from "./components/Dialog/PrimaryDialog.js";
@@ -177,6 +178,7 @@ export {
177
178
  CollectiveTheme,
178
179
  CollectiveThemeOptions,
179
180
  ComingSoonBadge,
181
+ ComparisonArrow,
180
182
  ComparisonBlock,
181
183
  ComparisonLabel,
182
184
  ContextualContentBox,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@foodpilot/foods",
3
3
  "private": false,
4
- "version": "2.11.25",
4
+ "version": "2.11.30",
5
5
  "type": "module",
6
6
  "main": "./dist/main.js",
7
7
  "module": "./dist/main.js",