@trackunit/react-components 0.1.253 → 0.1.254

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.js CHANGED
@@ -1182,145 +1182,6 @@ const DayPicker = ({ onDaySelect, disabledDays, selectedDays, language, classNam
1182
1182
  return (jsxRuntime.jsx(reactDayPicker.DayPicker, { onDayClick: onDaySelect, selected: selectedDays, locale: locale, disabled: disabledDays, className: `custom-day-picker ${className !== null && className !== void 0 ? className : ""}`, max: max, footer: jsxRuntime.jsx("div", { "data-testid": dataTestId }) }));
1183
1183
  };
1184
1184
 
1185
- /**
1186
- * The hook that powers the Popover component.
1187
- * It should not be used directly, but rather through the Popover component.
1188
- *
1189
- * @param {PopoverProps} options The options for the popover
1190
- * @returns {ReturnType<usePopover>} The data for the popover
1191
- */
1192
- const usePopover = (_a) => {
1193
- var { initialOpen = false, placement = "bottom", isModal, isOpen: controlledIsOpen, activation = { click: true, hover: false }, dismissal, onOpenStateChange } = _a, restOptions = __rest(_a, ["initialOpen", "placement", "isModal", "isOpen", "activation", "dismissal", "onOpenStateChange"]);
1194
- const [uncontrolledIsOpen, setUncontrolledIsOpen] = React.useState(initialOpen);
1195
- const [labelId, setLabelId] = React.useState();
1196
- const [descriptionId, setDescriptionId] = React.useState();
1197
- const isOpen = controlledIsOpen !== null && controlledIsOpen !== void 0 ? controlledIsOpen : uncontrolledIsOpen;
1198
- const popoverData = react.useFloating({
1199
- placement,
1200
- open: isOpen,
1201
- onOpenChange: open => {
1202
- setUncontrolledIsOpen(open);
1203
- onOpenStateChange === null || onOpenStateChange === void 0 ? void 0 : onOpenStateChange(open);
1204
- },
1205
- whileElementsMounted: react.autoUpdate,
1206
- middleware: [
1207
- react.offset(8),
1208
- react.flip({ fallbackPlacements: ["top", "bottom", "right", "left"] }),
1209
- react.shift(),
1210
- react.size({
1211
- apply({ availableWidth, availableHeight, elements }) {
1212
- Object.assign(elements.floating.style, {
1213
- maxWidth: `${availableWidth}px`,
1214
- maxHeight: `${availableHeight}px`,
1215
- });
1216
- },
1217
- }),
1218
- ],
1219
- });
1220
- const popoverContext = popoverData.context;
1221
- const clickInteraction = react.useClick(popoverContext, { enabled: activation.click, ignoreMouse: activation.hover });
1222
- const dismissInteraction = react.useDismiss(popoverContext, dismissal);
1223
- const hoverInteraction = react.useHover(popoverContext, { enabled: activation.hover });
1224
- const roleInteraction = react.useRole(popoverContext);
1225
- const combinedInteractions = react.useInteractions([
1226
- clickInteraction,
1227
- hoverInteraction,
1228
- dismissInteraction,
1229
- roleInteraction,
1230
- ]);
1231
- return React.useMemo(() => (Object.assign(Object.assign(Object.assign(Object.assign({ isOpen, setIsOpen: setUncontrolledIsOpen }, lodash.omit(popoverData, "middlewareData", "floatingStyles", "elements")), { x: popoverData.x, y: popoverData.y, isPositioned: popoverData.isPositioned, refs: popoverData.refs, update: popoverData.update, placement: popoverData.placement, strategy: popoverData.strategy }), combinedInteractions), { isModal,
1232
- labelId,
1233
- descriptionId,
1234
- setLabelId,
1235
- setDescriptionId, customProps: restOptions })), [isOpen, setUncontrolledIsOpen, combinedInteractions, popoverData, isModal, labelId, descriptionId, restOptions]);
1236
- };
1237
-
1238
- const PopoverContext = React.createContext(null);
1239
- /**
1240
- * A hook to get the popover context.
1241
- * It should only be used by the Popover components.
1242
- *
1243
- * @returns {ContextType} The popover context
1244
- */
1245
- const usePopoverContext = () => {
1246
- const context = React.useContext(PopoverContext);
1247
- if (context === null) {
1248
- throw new Error("Popover components must be wrapped in <Popover />");
1249
- }
1250
- return context;
1251
- };
1252
- /**
1253
- * The popover component.
1254
- * - This component should wrap all the popover components.
1255
- * - It returns a context that is used by the popover components.
1256
- * - The context is used to share the state of the popover, such as the open state and the reference element.
1257
- *
1258
- * To open the popover, use the `<PopoverTrigger />` component.
1259
- *
1260
- * To render the content of the popover, use the `<PopoverContent />` component.
1261
- *
1262
- * @param {PopoverProps} props The props for the popover
1263
- * @returns {JSX.Element} A Popover Context Provider containing the children
1264
- */
1265
- const Popover = (_a) => {
1266
- var { children, isModal = false } = _a, restOptions = __rest(_a, ["children", "isModal"]);
1267
- const popover = usePopover(Object.assign({ isModal }, restOptions));
1268
- return jsxRuntime.jsx(PopoverContext.Provider, { value: popover, children: children });
1269
- };
1270
-
1271
- const cvaPopoverContainer = cssClassVarianceUtilities.cvaMerge(["component-popover-border", "z-popover", "animate-fade-in-fast"]);
1272
- const cvaPopoverTitleContainer = cssClassVarianceUtilities.cvaMerge(["flex", "items-center", "px-2", "py-1"], {
1273
- variants: {
1274
- divider: {
1275
- true: ["border-b", "border-solid", "border-b-neutral-100", "mb-1"],
1276
- false: "",
1277
- },
1278
- },
1279
- });
1280
- const cvaPopoverTitleText = cssClassVarianceUtilities.cvaMerge(["flex-1", "text-neutral-500"]);
1281
-
1282
- const PopoverContent = React__default["default"].forwardRef(function PopoverContent(_a, propRef) {
1283
- var _b;
1284
- var { className, dataTestId, children, portalId } = _a, props = __rest(_a, ["className", "dataTestId", "children", "portalId"]);
1285
- const _c = usePopoverContext(), { context: floatingContext, customProps } = _c, context = __rest(_c, ["context", "customProps"]);
1286
- const ref = react.useMergeRefs([context.refs.setFloating, propRef]);
1287
- return (jsxRuntime.jsx(react.FloatingPortal, { id: portalId !== null && portalId !== void 0 ? portalId : "tu-floating-ui", children: context.isOpen ? (jsxRuntime.jsx(react.FloatingFocusManager, { guards: false, context: floatingContext, modal: context.isModal, closeOnFocusOut: false, order: ["reference", "content"], returnFocus: false, children: jsxRuntime.jsx("div", Object.assign({ ref: ref, className: cvaPopoverContainer({ className: className !== null && className !== void 0 ? className : customProps.className }), "data-testid": (_b = dataTestId !== null && dataTestId !== void 0 ? dataTestId : customProps.dataTestId) !== null && _b !== void 0 ? _b : "popover-content", style: Object.assign({ position: context.strategy, top: context.y, left: context.x, width: "max-content" }, props.style), "aria-labelledby": context.labelId, "aria-describedby": context.descriptionId }, context.getFloatingProps(props), { children: typeof children === "function" ? children(() => context.setIsOpen(false)) : children })) })) : null }));
1288
- });
1289
-
1290
- /**
1291
- * The PopoverTitle component.
1292
-
1293
- * @param {PopoverTitleProps} props - The props for the PopoverTitle component
1294
- * @returns {JSX.Element} PopoverTitle component
1295
- */
1296
- const PopoverTitle = ({ children, action, divider = false, className, dataTestId }) => {
1297
- return (jsxRuntime.jsxs("div", { className: cvaPopoverTitleContainer({ divider, className }), "data-testid": dataTestId, children: [jsxRuntime.jsx(Text, { className: cvaPopoverTitleText(), type: "div", subtle: true, size: "small", weight: "bold", uppercase: true, children: children }), action] }));
1298
- };
1299
-
1300
- const PopoverTrigger = React.forwardRef(function PopoverTrigger(_a, propRef) {
1301
- var { children, renderButton } = _a, props = __rest(_a, ["children", "renderButton"]);
1302
- const context = usePopoverContext();
1303
- // eslint-disable-next-line @typescript-eslint/no-explicit-any, local-rules/no-typescript-assertion
1304
- const childrenRef = children.ref;
1305
- const ref = react.useMergeRefs([context.refs.setReference, propRef, childrenRef]);
1306
- if (!renderButton && React.isValidElement(children)) {
1307
- return React.cloneElement(children, context.getReferenceProps(Object.assign(Object.assign(Object.assign({ ref }, props), children.props), { "data-state": context.isOpen ? "open" : "closed" })));
1308
- }
1309
- else {
1310
- return (jsxRuntime.jsx(Button, Object.assign({ ref: ref, type: "button", "data-state": context.isOpen ? "open" : "closed" }, context.getReferenceProps(props), { children: children })));
1311
- }
1312
- });
1313
-
1314
- /**
1315
- * The DayPickerPopover component returns a button which when clicked shows the daypicker.
1316
-
1317
- * @param {DayPickerPopoverProps} props - The props for the DayPickerPopover component
1318
- * @returns {JSX.Element} DayPickerPopover component
1319
- */
1320
- const DayPickerPopover = ({ disabledDays, className, dataTestId, selectedDay, onDaySelect, color = "secondary", placement, size = "small", buttonContent, language, }) => {
1321
- return (jsxRuntime.jsxs(Popover, { placement: placement, children: [jsxRuntime.jsx(PopoverTrigger, { children: jsxRuntime.jsx(Button, { variant: color, size: size, className: className, prefix: jsxRuntime.jsx(Icon, { name: "Calendar", size: "small" }), dataTestId: dataTestId !== null && dataTestId !== void 0 ? dataTestId : "show-day-picker", children: buttonContent }) }), jsxRuntime.jsx(PopoverContent, { children: jsxRuntime.jsx(Card, { children: jsxRuntime.jsx(DayPicker, { disabledDays: disabledDays, onDaySelect: onDaySelect, selectedDays: selectedDay, language: language }) }) })] }));
1322
- };
1323
-
1324
1185
  /**
1325
1186
  * The DayRangePicker component should be used when the user needs to select a range of dates.
1326
1187
 
@@ -1508,6 +1369,135 @@ const ExternalLink = ({ rel = "noreferrer", target = "_blank", href, className,
1508
1369
  return (jsxRuntime.jsx("a", { onClick: onClick, "data-testid": dataTestId, className: cvaExternalLink({ className }), title: title, href: href, rel: rel, target: target, children: children }));
1509
1370
  };
1510
1371
 
1372
+ /**
1373
+ * The hook that powers the Popover component.
1374
+ * It should not be used directly, but rather through the Popover component.
1375
+ *
1376
+ * @param {PopoverProps} options The options for the popover
1377
+ * @returns {ReturnType<usePopover>} The data for the popover
1378
+ */
1379
+ const usePopover = (_a) => {
1380
+ var { initialOpen = false, placement = "bottom", isModal, isOpen: controlledIsOpen, activation = { click: true, hover: false }, dismissal, onOpenStateChange } = _a, restOptions = __rest(_a, ["initialOpen", "placement", "isModal", "isOpen", "activation", "dismissal", "onOpenStateChange"]);
1381
+ const [uncontrolledIsOpen, setUncontrolledIsOpen] = React.useState(initialOpen);
1382
+ const [labelId, setLabelId] = React.useState();
1383
+ const [descriptionId, setDescriptionId] = React.useState();
1384
+ const isOpen = controlledIsOpen !== null && controlledIsOpen !== void 0 ? controlledIsOpen : uncontrolledIsOpen;
1385
+ const popoverData = react.useFloating({
1386
+ placement,
1387
+ open: isOpen,
1388
+ onOpenChange: open => {
1389
+ setUncontrolledIsOpen(open);
1390
+ onOpenStateChange === null || onOpenStateChange === void 0 ? void 0 : onOpenStateChange(open);
1391
+ },
1392
+ whileElementsMounted: react.autoUpdate,
1393
+ middleware: [
1394
+ react.offset(8),
1395
+ react.flip({ fallbackPlacements: ["top", "bottom", "right", "left"] }),
1396
+ react.shift(),
1397
+ react.size({
1398
+ apply({ availableWidth, availableHeight, elements }) {
1399
+ Object.assign(elements.floating.style, {
1400
+ maxWidth: `${availableWidth}px`,
1401
+ maxHeight: `${availableHeight}px`,
1402
+ });
1403
+ },
1404
+ }),
1405
+ ],
1406
+ });
1407
+ const popoverContext = popoverData.context;
1408
+ const clickInteraction = react.useClick(popoverContext, { enabled: activation.click, ignoreMouse: activation.hover });
1409
+ const dismissInteraction = react.useDismiss(popoverContext, dismissal);
1410
+ const hoverInteraction = react.useHover(popoverContext, { enabled: activation.hover });
1411
+ const roleInteraction = react.useRole(popoverContext);
1412
+ const combinedInteractions = react.useInteractions([
1413
+ clickInteraction,
1414
+ hoverInteraction,
1415
+ dismissInteraction,
1416
+ roleInteraction,
1417
+ ]);
1418
+ return React.useMemo(() => (Object.assign(Object.assign(Object.assign(Object.assign({ isOpen, setIsOpen: setUncontrolledIsOpen }, lodash.omit(popoverData, "middlewareData", "floatingStyles", "elements")), { x: popoverData.x, y: popoverData.y, isPositioned: popoverData.isPositioned, refs: popoverData.refs, update: popoverData.update, placement: popoverData.placement, strategy: popoverData.strategy }), combinedInteractions), { isModal,
1419
+ labelId,
1420
+ descriptionId,
1421
+ setLabelId,
1422
+ setDescriptionId, customProps: restOptions })), [isOpen, setUncontrolledIsOpen, combinedInteractions, popoverData, isModal, labelId, descriptionId, restOptions]);
1423
+ };
1424
+
1425
+ const PopoverContext = React.createContext(null);
1426
+ /**
1427
+ * A hook to get the popover context.
1428
+ * It should only be used by the Popover components.
1429
+ *
1430
+ * @returns {ContextType} The popover context
1431
+ */
1432
+ const usePopoverContext = () => {
1433
+ const context = React.useContext(PopoverContext);
1434
+ if (context === null) {
1435
+ throw new Error("Popover components must be wrapped in <Popover />");
1436
+ }
1437
+ return context;
1438
+ };
1439
+ /**
1440
+ * The popover component.
1441
+ * - This component should wrap all the popover components.
1442
+ * - It returns a context that is used by the popover components.
1443
+ * - The context is used to share the state of the popover, such as the open state and the reference element.
1444
+ *
1445
+ * To open the popover, use the `<PopoverTrigger />` component.
1446
+ *
1447
+ * To render the content of the popover, use the `<PopoverContent />` component.
1448
+ *
1449
+ * @param {PopoverProps} props The props for the popover
1450
+ * @returns {JSX.Element} A Popover Context Provider containing the children
1451
+ */
1452
+ const Popover = (_a) => {
1453
+ var { children, isModal = false } = _a, restOptions = __rest(_a, ["children", "isModal"]);
1454
+ const popover = usePopover(Object.assign({ isModal }, restOptions));
1455
+ return jsxRuntime.jsx(PopoverContext.Provider, { value: popover, children: children });
1456
+ };
1457
+
1458
+ const cvaPopoverContainer = cssClassVarianceUtilities.cvaMerge(["component-popover-border", "z-popover", "animate-fade-in-fast"]);
1459
+ const cvaPopoverTitleContainer = cssClassVarianceUtilities.cvaMerge(["flex", "items-center", "px-2", "py-1"], {
1460
+ variants: {
1461
+ divider: {
1462
+ true: ["border-b", "border-solid", "border-b-neutral-100", "mb-1"],
1463
+ false: "",
1464
+ },
1465
+ },
1466
+ });
1467
+ const cvaPopoverTitleText = cssClassVarianceUtilities.cvaMerge(["flex-1", "text-neutral-500"]);
1468
+
1469
+ const PopoverContent = React__default["default"].forwardRef(function PopoverContent(_a, propRef) {
1470
+ var _b;
1471
+ var { className, dataTestId, children, portalId } = _a, props = __rest(_a, ["className", "dataTestId", "children", "portalId"]);
1472
+ const _c = usePopoverContext(), { context: floatingContext, customProps } = _c, context = __rest(_c, ["context", "customProps"]);
1473
+ const ref = react.useMergeRefs([context.refs.setFloating, propRef]);
1474
+ return (jsxRuntime.jsx(react.FloatingPortal, { id: portalId !== null && portalId !== void 0 ? portalId : "tu-floating-ui", children: context.isOpen ? (jsxRuntime.jsx(react.FloatingFocusManager, { guards: false, context: floatingContext, modal: context.isModal, closeOnFocusOut: false, order: ["reference", "content"], returnFocus: false, children: jsxRuntime.jsx("div", Object.assign({ ref: ref, className: cvaPopoverContainer({ className: className !== null && className !== void 0 ? className : customProps.className }), "data-testid": (_b = dataTestId !== null && dataTestId !== void 0 ? dataTestId : customProps.dataTestId) !== null && _b !== void 0 ? _b : "popover-content", style: Object.assign({ position: context.strategy, top: context.y, left: context.x, width: "max-content" }, props.style), "aria-labelledby": context.labelId, "aria-describedby": context.descriptionId }, context.getFloatingProps(props), { children: typeof children === "function" ? children(() => context.setIsOpen(false)) : children })) })) : null }));
1475
+ });
1476
+
1477
+ /**
1478
+ * The PopoverTitle component.
1479
+
1480
+ * @param {PopoverTitleProps} props - The props for the PopoverTitle component
1481
+ * @returns {JSX.Element} PopoverTitle component
1482
+ */
1483
+ const PopoverTitle = ({ children, action, divider = false, className, dataTestId }) => {
1484
+ return (jsxRuntime.jsxs("div", { className: cvaPopoverTitleContainer({ divider, className }), "data-testid": dataTestId, children: [jsxRuntime.jsx(Text, { className: cvaPopoverTitleText(), type: "div", subtle: true, size: "small", weight: "bold", uppercase: true, children: children }), action] }));
1485
+ };
1486
+
1487
+ const PopoverTrigger = React.forwardRef(function PopoverTrigger(_a, propRef) {
1488
+ var { children, renderButton } = _a, props = __rest(_a, ["children", "renderButton"]);
1489
+ const context = usePopoverContext();
1490
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any, local-rules/no-typescript-assertion
1491
+ const childrenRef = children.ref;
1492
+ const ref = react.useMergeRefs([context.refs.setReference, propRef, childrenRef]);
1493
+ if (!renderButton && React.isValidElement(children)) {
1494
+ return React.cloneElement(children, context.getReferenceProps(Object.assign(Object.assign(Object.assign({ ref }, props), children.props), { "data-state": context.isOpen ? "open" : "closed" })));
1495
+ }
1496
+ else {
1497
+ return (jsxRuntime.jsx(Button, Object.assign({ ref: ref, type: "button", "data-state": context.isOpen ? "open" : "closed" }, context.getReferenceProps(props), { children: children })));
1498
+ }
1499
+ });
1500
+
1511
1501
  const cvaTooltipFlexContainer = cssClassVarianceUtilities.cvaMerge(["inline-flex", "hover:cursor-pointer"]);
1512
1502
  const cvaTooltipIcon = cssClassVarianceUtilities.cvaMerge(["flex", "h-max", "w-fit", "text-slate-300", "transition", "hover:cursor-pointer", "hover:text-slate-400"], {
1513
1503
  variants: {
@@ -3074,7 +3064,6 @@ exports.CardHeader = CardHeader;
3074
3064
  exports.Collapse = Collapse;
3075
3065
  exports.CopyableText = CopyableText;
3076
3066
  exports.DayPicker = DayPicker;
3077
- exports.DayPickerPopover = DayPickerPopover;
3078
3067
  exports.DayRangePicker = DayRangePicker;
3079
3068
  exports.Drawer = Drawer;
3080
3069
  exports.EmptyState = EmptyState;
package/index.esm.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
2
2
  import * as React from 'react';
3
- import React__default, { useRef, useMemo, useEffect, useState, createContext, useContext, forwardRef, isValidElement, cloneElement, useCallback, memo, Children, useReducer } from 'react';
3
+ import React__default, { useRef, useMemo, useEffect, useState, useCallback, memo, createContext, useContext, forwardRef, isValidElement, cloneElement, Children, useReducer } from 'react';
4
4
  import { rentalStatusPalette, intentPalette, generalPalette, criticalityPalette, activityPalette, utilizationPalette, sitesPalette, color } from '@trackunit/ui-design-tokens';
5
5
  import { iconNames } from '@trackunit/ui-icons';
6
6
  import IconSpriteMini from '@trackunit/ui-icons/icons-sprite-mini.svg';
@@ -10,7 +10,7 @@ import { cvaMerge } from '@trackunit/css-class-variance-utilities';
10
10
  import { useMeasure, useCopyToClipboard, usePrevious } from 'react-use';
11
11
  import { DayPicker as DayPicker$1 } from 'react-day-picker';
12
12
  import { enGB, enUS, da, de, cs, nl, fr, fi, hu, it, nb, pl, pt, ru, ro, es, sv, ja, th } from 'date-fns/locale';
13
- import { useFloating, autoUpdate, offset, flip, shift, size, useClick, useDismiss, useHover as useHover$1, useRole, useInteractions, useMergeRefs, FloatingPortal, FloatingFocusManager, arrow, useTransitionStatus, FloatingArrow } from '@floating-ui/react';
13
+ import { useFloating, FloatingFocusManager, autoUpdate, offset, flip, shift, size, useClick, useDismiss, useHover as useHover$1, useRole, useInteractions, useMergeRefs, FloatingPortal, arrow, useTransitionStatus, FloatingArrow } from '@floating-ui/react';
14
14
  import { omit } from 'lodash';
15
15
  import usePortal from 'react-useportal';
16
16
  import { Link, UNSAFE_NavigationContext } from 'react-router-dom';
@@ -1151,145 +1151,6 @@ const DayPicker = ({ onDaySelect, disabledDays, selectedDays, language, classNam
1151
1151
  return (jsx(DayPicker$1, { onDayClick: onDaySelect, selected: selectedDays, locale: locale, disabled: disabledDays, className: `custom-day-picker ${className !== null && className !== void 0 ? className : ""}`, max: max, footer: jsx("div", { "data-testid": dataTestId }) }));
1152
1152
  };
1153
1153
 
1154
- /**
1155
- * The hook that powers the Popover component.
1156
- * It should not be used directly, but rather through the Popover component.
1157
- *
1158
- * @param {PopoverProps} options The options for the popover
1159
- * @returns {ReturnType<usePopover>} The data for the popover
1160
- */
1161
- const usePopover = (_a) => {
1162
- var { initialOpen = false, placement = "bottom", isModal, isOpen: controlledIsOpen, activation = { click: true, hover: false }, dismissal, onOpenStateChange } = _a, restOptions = __rest(_a, ["initialOpen", "placement", "isModal", "isOpen", "activation", "dismissal", "onOpenStateChange"]);
1163
- const [uncontrolledIsOpen, setUncontrolledIsOpen] = useState(initialOpen);
1164
- const [labelId, setLabelId] = useState();
1165
- const [descriptionId, setDescriptionId] = useState();
1166
- const isOpen = controlledIsOpen !== null && controlledIsOpen !== void 0 ? controlledIsOpen : uncontrolledIsOpen;
1167
- const popoverData = useFloating({
1168
- placement,
1169
- open: isOpen,
1170
- onOpenChange: open => {
1171
- setUncontrolledIsOpen(open);
1172
- onOpenStateChange === null || onOpenStateChange === void 0 ? void 0 : onOpenStateChange(open);
1173
- },
1174
- whileElementsMounted: autoUpdate,
1175
- middleware: [
1176
- offset(8),
1177
- flip({ fallbackPlacements: ["top", "bottom", "right", "left"] }),
1178
- shift(),
1179
- size({
1180
- apply({ availableWidth, availableHeight, elements }) {
1181
- Object.assign(elements.floating.style, {
1182
- maxWidth: `${availableWidth}px`,
1183
- maxHeight: `${availableHeight}px`,
1184
- });
1185
- },
1186
- }),
1187
- ],
1188
- });
1189
- const popoverContext = popoverData.context;
1190
- const clickInteraction = useClick(popoverContext, { enabled: activation.click, ignoreMouse: activation.hover });
1191
- const dismissInteraction = useDismiss(popoverContext, dismissal);
1192
- const hoverInteraction = useHover$1(popoverContext, { enabled: activation.hover });
1193
- const roleInteraction = useRole(popoverContext);
1194
- const combinedInteractions = useInteractions([
1195
- clickInteraction,
1196
- hoverInteraction,
1197
- dismissInteraction,
1198
- roleInteraction,
1199
- ]);
1200
- return useMemo(() => (Object.assign(Object.assign(Object.assign(Object.assign({ isOpen, setIsOpen: setUncontrolledIsOpen }, omit(popoverData, "middlewareData", "floatingStyles", "elements")), { x: popoverData.x, y: popoverData.y, isPositioned: popoverData.isPositioned, refs: popoverData.refs, update: popoverData.update, placement: popoverData.placement, strategy: popoverData.strategy }), combinedInteractions), { isModal,
1201
- labelId,
1202
- descriptionId,
1203
- setLabelId,
1204
- setDescriptionId, customProps: restOptions })), [isOpen, setUncontrolledIsOpen, combinedInteractions, popoverData, isModal, labelId, descriptionId, restOptions]);
1205
- };
1206
-
1207
- const PopoverContext = createContext(null);
1208
- /**
1209
- * A hook to get the popover context.
1210
- * It should only be used by the Popover components.
1211
- *
1212
- * @returns {ContextType} The popover context
1213
- */
1214
- const usePopoverContext = () => {
1215
- const context = useContext(PopoverContext);
1216
- if (context === null) {
1217
- throw new Error("Popover components must be wrapped in <Popover />");
1218
- }
1219
- return context;
1220
- };
1221
- /**
1222
- * The popover component.
1223
- * - This component should wrap all the popover components.
1224
- * - It returns a context that is used by the popover components.
1225
- * - The context is used to share the state of the popover, such as the open state and the reference element.
1226
- *
1227
- * To open the popover, use the `<PopoverTrigger />` component.
1228
- *
1229
- * To render the content of the popover, use the `<PopoverContent />` component.
1230
- *
1231
- * @param {PopoverProps} props The props for the popover
1232
- * @returns {JSX.Element} A Popover Context Provider containing the children
1233
- */
1234
- const Popover = (_a) => {
1235
- var { children, isModal = false } = _a, restOptions = __rest(_a, ["children", "isModal"]);
1236
- const popover = usePopover(Object.assign({ isModal }, restOptions));
1237
- return jsx(PopoverContext.Provider, { value: popover, children: children });
1238
- };
1239
-
1240
- const cvaPopoverContainer = cvaMerge(["component-popover-border", "z-popover", "animate-fade-in-fast"]);
1241
- const cvaPopoverTitleContainer = cvaMerge(["flex", "items-center", "px-2", "py-1"], {
1242
- variants: {
1243
- divider: {
1244
- true: ["border-b", "border-solid", "border-b-neutral-100", "mb-1"],
1245
- false: "",
1246
- },
1247
- },
1248
- });
1249
- const cvaPopoverTitleText = cvaMerge(["flex-1", "text-neutral-500"]);
1250
-
1251
- const PopoverContent = React__default.forwardRef(function PopoverContent(_a, propRef) {
1252
- var _b;
1253
- var { className, dataTestId, children, portalId } = _a, props = __rest(_a, ["className", "dataTestId", "children", "portalId"]);
1254
- const _c = usePopoverContext(), { context: floatingContext, customProps } = _c, context = __rest(_c, ["context", "customProps"]);
1255
- const ref = useMergeRefs([context.refs.setFloating, propRef]);
1256
- return (jsx(FloatingPortal, { id: portalId !== null && portalId !== void 0 ? portalId : "tu-floating-ui", children: context.isOpen ? (jsx(FloatingFocusManager, { guards: false, context: floatingContext, modal: context.isModal, closeOnFocusOut: false, order: ["reference", "content"], returnFocus: false, children: jsx("div", Object.assign({ ref: ref, className: cvaPopoverContainer({ className: className !== null && className !== void 0 ? className : customProps.className }), "data-testid": (_b = dataTestId !== null && dataTestId !== void 0 ? dataTestId : customProps.dataTestId) !== null && _b !== void 0 ? _b : "popover-content", style: Object.assign({ position: context.strategy, top: context.y, left: context.x, width: "max-content" }, props.style), "aria-labelledby": context.labelId, "aria-describedby": context.descriptionId }, context.getFloatingProps(props), { children: typeof children === "function" ? children(() => context.setIsOpen(false)) : children })) })) : null }));
1257
- });
1258
-
1259
- /**
1260
- * The PopoverTitle component.
1261
-
1262
- * @param {PopoverTitleProps} props - The props for the PopoverTitle component
1263
- * @returns {JSX.Element} PopoverTitle component
1264
- */
1265
- const PopoverTitle = ({ children, action, divider = false, className, dataTestId }) => {
1266
- return (jsxs("div", { className: cvaPopoverTitleContainer({ divider, className }), "data-testid": dataTestId, children: [jsx(Text, { className: cvaPopoverTitleText(), type: "div", subtle: true, size: "small", weight: "bold", uppercase: true, children: children }), action] }));
1267
- };
1268
-
1269
- const PopoverTrigger = forwardRef(function PopoverTrigger(_a, propRef) {
1270
- var { children, renderButton } = _a, props = __rest(_a, ["children", "renderButton"]);
1271
- const context = usePopoverContext();
1272
- // eslint-disable-next-line @typescript-eslint/no-explicit-any, local-rules/no-typescript-assertion
1273
- const childrenRef = children.ref;
1274
- const ref = useMergeRefs([context.refs.setReference, propRef, childrenRef]);
1275
- if (!renderButton && isValidElement(children)) {
1276
- return cloneElement(children, context.getReferenceProps(Object.assign(Object.assign(Object.assign({ ref }, props), children.props), { "data-state": context.isOpen ? "open" : "closed" })));
1277
- }
1278
- else {
1279
- return (jsx(Button, Object.assign({ ref: ref, type: "button", "data-state": context.isOpen ? "open" : "closed" }, context.getReferenceProps(props), { children: children })));
1280
- }
1281
- });
1282
-
1283
- /**
1284
- * The DayPickerPopover component returns a button which when clicked shows the daypicker.
1285
-
1286
- * @param {DayPickerPopoverProps} props - The props for the DayPickerPopover component
1287
- * @returns {JSX.Element} DayPickerPopover component
1288
- */
1289
- const DayPickerPopover = ({ disabledDays, className, dataTestId, selectedDay, onDaySelect, color = "secondary", placement, size = "small", buttonContent, language, }) => {
1290
- return (jsxs(Popover, { placement: placement, children: [jsx(PopoverTrigger, { children: jsx(Button, { variant: color, size: size, className: className, prefix: jsx(Icon, { name: "Calendar", size: "small" }), dataTestId: dataTestId !== null && dataTestId !== void 0 ? dataTestId : "show-day-picker", children: buttonContent }) }), jsx(PopoverContent, { children: jsx(Card, { children: jsx(DayPicker, { disabledDays: disabledDays, onDaySelect: onDaySelect, selectedDays: selectedDay, language: language }) }) })] }));
1291
- };
1292
-
1293
1154
  /**
1294
1155
  * The DayRangePicker component should be used when the user needs to select a range of dates.
1295
1156
 
@@ -1477,6 +1338,135 @@ const ExternalLink = ({ rel = "noreferrer", target = "_blank", href, className,
1477
1338
  return (jsx("a", { onClick: onClick, "data-testid": dataTestId, className: cvaExternalLink({ className }), title: title, href: href, rel: rel, target: target, children: children }));
1478
1339
  };
1479
1340
 
1341
+ /**
1342
+ * The hook that powers the Popover component.
1343
+ * It should not be used directly, but rather through the Popover component.
1344
+ *
1345
+ * @param {PopoverProps} options The options for the popover
1346
+ * @returns {ReturnType<usePopover>} The data for the popover
1347
+ */
1348
+ const usePopover = (_a) => {
1349
+ var { initialOpen = false, placement = "bottom", isModal, isOpen: controlledIsOpen, activation = { click: true, hover: false }, dismissal, onOpenStateChange } = _a, restOptions = __rest(_a, ["initialOpen", "placement", "isModal", "isOpen", "activation", "dismissal", "onOpenStateChange"]);
1350
+ const [uncontrolledIsOpen, setUncontrolledIsOpen] = useState(initialOpen);
1351
+ const [labelId, setLabelId] = useState();
1352
+ const [descriptionId, setDescriptionId] = useState();
1353
+ const isOpen = controlledIsOpen !== null && controlledIsOpen !== void 0 ? controlledIsOpen : uncontrolledIsOpen;
1354
+ const popoverData = useFloating({
1355
+ placement,
1356
+ open: isOpen,
1357
+ onOpenChange: open => {
1358
+ setUncontrolledIsOpen(open);
1359
+ onOpenStateChange === null || onOpenStateChange === void 0 ? void 0 : onOpenStateChange(open);
1360
+ },
1361
+ whileElementsMounted: autoUpdate,
1362
+ middleware: [
1363
+ offset(8),
1364
+ flip({ fallbackPlacements: ["top", "bottom", "right", "left"] }),
1365
+ shift(),
1366
+ size({
1367
+ apply({ availableWidth, availableHeight, elements }) {
1368
+ Object.assign(elements.floating.style, {
1369
+ maxWidth: `${availableWidth}px`,
1370
+ maxHeight: `${availableHeight}px`,
1371
+ });
1372
+ },
1373
+ }),
1374
+ ],
1375
+ });
1376
+ const popoverContext = popoverData.context;
1377
+ const clickInteraction = useClick(popoverContext, { enabled: activation.click, ignoreMouse: activation.hover });
1378
+ const dismissInteraction = useDismiss(popoverContext, dismissal);
1379
+ const hoverInteraction = useHover$1(popoverContext, { enabled: activation.hover });
1380
+ const roleInteraction = useRole(popoverContext);
1381
+ const combinedInteractions = useInteractions([
1382
+ clickInteraction,
1383
+ hoverInteraction,
1384
+ dismissInteraction,
1385
+ roleInteraction,
1386
+ ]);
1387
+ return useMemo(() => (Object.assign(Object.assign(Object.assign(Object.assign({ isOpen, setIsOpen: setUncontrolledIsOpen }, omit(popoverData, "middlewareData", "floatingStyles", "elements")), { x: popoverData.x, y: popoverData.y, isPositioned: popoverData.isPositioned, refs: popoverData.refs, update: popoverData.update, placement: popoverData.placement, strategy: popoverData.strategy }), combinedInteractions), { isModal,
1388
+ labelId,
1389
+ descriptionId,
1390
+ setLabelId,
1391
+ setDescriptionId, customProps: restOptions })), [isOpen, setUncontrolledIsOpen, combinedInteractions, popoverData, isModal, labelId, descriptionId, restOptions]);
1392
+ };
1393
+
1394
+ const PopoverContext = createContext(null);
1395
+ /**
1396
+ * A hook to get the popover context.
1397
+ * It should only be used by the Popover components.
1398
+ *
1399
+ * @returns {ContextType} The popover context
1400
+ */
1401
+ const usePopoverContext = () => {
1402
+ const context = useContext(PopoverContext);
1403
+ if (context === null) {
1404
+ throw new Error("Popover components must be wrapped in <Popover />");
1405
+ }
1406
+ return context;
1407
+ };
1408
+ /**
1409
+ * The popover component.
1410
+ * - This component should wrap all the popover components.
1411
+ * - It returns a context that is used by the popover components.
1412
+ * - The context is used to share the state of the popover, such as the open state and the reference element.
1413
+ *
1414
+ * To open the popover, use the `<PopoverTrigger />` component.
1415
+ *
1416
+ * To render the content of the popover, use the `<PopoverContent />` component.
1417
+ *
1418
+ * @param {PopoverProps} props The props for the popover
1419
+ * @returns {JSX.Element} A Popover Context Provider containing the children
1420
+ */
1421
+ const Popover = (_a) => {
1422
+ var { children, isModal = false } = _a, restOptions = __rest(_a, ["children", "isModal"]);
1423
+ const popover = usePopover(Object.assign({ isModal }, restOptions));
1424
+ return jsx(PopoverContext.Provider, { value: popover, children: children });
1425
+ };
1426
+
1427
+ const cvaPopoverContainer = cvaMerge(["component-popover-border", "z-popover", "animate-fade-in-fast"]);
1428
+ const cvaPopoverTitleContainer = cvaMerge(["flex", "items-center", "px-2", "py-1"], {
1429
+ variants: {
1430
+ divider: {
1431
+ true: ["border-b", "border-solid", "border-b-neutral-100", "mb-1"],
1432
+ false: "",
1433
+ },
1434
+ },
1435
+ });
1436
+ const cvaPopoverTitleText = cvaMerge(["flex-1", "text-neutral-500"]);
1437
+
1438
+ const PopoverContent = React__default.forwardRef(function PopoverContent(_a, propRef) {
1439
+ var _b;
1440
+ var { className, dataTestId, children, portalId } = _a, props = __rest(_a, ["className", "dataTestId", "children", "portalId"]);
1441
+ const _c = usePopoverContext(), { context: floatingContext, customProps } = _c, context = __rest(_c, ["context", "customProps"]);
1442
+ const ref = useMergeRefs([context.refs.setFloating, propRef]);
1443
+ return (jsx(FloatingPortal, { id: portalId !== null && portalId !== void 0 ? portalId : "tu-floating-ui", children: context.isOpen ? (jsx(FloatingFocusManager, { guards: false, context: floatingContext, modal: context.isModal, closeOnFocusOut: false, order: ["reference", "content"], returnFocus: false, children: jsx("div", Object.assign({ ref: ref, className: cvaPopoverContainer({ className: className !== null && className !== void 0 ? className : customProps.className }), "data-testid": (_b = dataTestId !== null && dataTestId !== void 0 ? dataTestId : customProps.dataTestId) !== null && _b !== void 0 ? _b : "popover-content", style: Object.assign({ position: context.strategy, top: context.y, left: context.x, width: "max-content" }, props.style), "aria-labelledby": context.labelId, "aria-describedby": context.descriptionId }, context.getFloatingProps(props), { children: typeof children === "function" ? children(() => context.setIsOpen(false)) : children })) })) : null }));
1444
+ });
1445
+
1446
+ /**
1447
+ * The PopoverTitle component.
1448
+
1449
+ * @param {PopoverTitleProps} props - The props for the PopoverTitle component
1450
+ * @returns {JSX.Element} PopoverTitle component
1451
+ */
1452
+ const PopoverTitle = ({ children, action, divider = false, className, dataTestId }) => {
1453
+ return (jsxs("div", { className: cvaPopoverTitleContainer({ divider, className }), "data-testid": dataTestId, children: [jsx(Text, { className: cvaPopoverTitleText(), type: "div", subtle: true, size: "small", weight: "bold", uppercase: true, children: children }), action] }));
1454
+ };
1455
+
1456
+ const PopoverTrigger = forwardRef(function PopoverTrigger(_a, propRef) {
1457
+ var { children, renderButton } = _a, props = __rest(_a, ["children", "renderButton"]);
1458
+ const context = usePopoverContext();
1459
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any, local-rules/no-typescript-assertion
1460
+ const childrenRef = children.ref;
1461
+ const ref = useMergeRefs([context.refs.setReference, propRef, childrenRef]);
1462
+ if (!renderButton && isValidElement(children)) {
1463
+ return cloneElement(children, context.getReferenceProps(Object.assign(Object.assign(Object.assign({ ref }, props), children.props), { "data-state": context.isOpen ? "open" : "closed" })));
1464
+ }
1465
+ else {
1466
+ return (jsx(Button, Object.assign({ ref: ref, type: "button", "data-state": context.isOpen ? "open" : "closed" }, context.getReferenceProps(props), { children: children })));
1467
+ }
1468
+ });
1469
+
1480
1470
  const cvaTooltipFlexContainer = cvaMerge(["inline-flex", "hover:cursor-pointer"]);
1481
1471
  const cvaTooltipIcon = cvaMerge(["flex", "h-max", "w-fit", "text-slate-300", "transition", "hover:cursor-pointer", "hover:text-slate-400"], {
1482
1472
  variants: {
@@ -3033,4 +3023,4 @@ const useVisibilityChange = ({ onChange, targetState = "hidden" }) => {
3033
3023
  }, [onChange, targetState]);
3034
3024
  };
3035
3025
 
3036
- export { Alert, Badge, Button, Card, CardBody, CardFooter, CardHeader, Collapse, CopyableText, DayPicker, DayPickerPopover, DayRangePicker, Drawer, EmptyState, ExternalLink, Heading, Icon, IconButton, Indicator, MenuItem, MenuList, Modal, ModalBackdrop, MoreMenu, PackageNameStoryComponent, PageHeader, Pagination, Popover, PopoverContent, PopoverTitle, PopoverTrigger, Prompt, ROLE_CARD, SectionHeader, Sidebar, SkeletonLines, Spacer, Spinner, StarButton, Tab, TabContent, TabList, Tabs, Tag, Text, Timeline, TimelineElement, Tooltip, ValueBar, WidgetBody, cvaButton, cvaButtonPrefixSuffix, cvaButtonSpinner, cvaButtonSpinnerContainer, cvaClickable, cvaIconButton, cvaIndicator, cvaIndicatorIcon, cvaIndicatorIconBackground, cvaIndicatorLabel, cvaIndicatorPing, cvaMenuItem, cvaMenuItemLabel, cvaMenuItemPrefix, cvaMenuItemSuffix, docs, getDevicePixelRatio, getValueBarColorByValue, iconColorNames, iconPalette, setLocalStorage, useClickOutside, useContainerProps, useContinuousTimeout, useDebounce, useDevicePixelRatio, useGeometry, useHover, useIsFirstRender, useIsFullscreen, useIsTextCutOff, useLocalStorage, useLocalStorageReducer, useModal, useOptionallyElevatedState, useOverflowItems, usePopoverContext, usePrompt, useResize, useSelfUpdatingRef, useTimeout, useVisibilityChange };
3026
+ export { Alert, Badge, Button, Card, CardBody, CardFooter, CardHeader, Collapse, CopyableText, DayPicker, DayRangePicker, Drawer, EmptyState, ExternalLink, Heading, Icon, IconButton, Indicator, MenuItem, MenuList, Modal, ModalBackdrop, MoreMenu, PackageNameStoryComponent, PageHeader, Pagination, Popover, PopoverContent, PopoverTitle, PopoverTrigger, Prompt, ROLE_CARD, SectionHeader, Sidebar, SkeletonLines, Spacer, Spinner, StarButton, Tab, TabContent, TabList, Tabs, Tag, Text, Timeline, TimelineElement, Tooltip, ValueBar, WidgetBody, cvaButton, cvaButtonPrefixSuffix, cvaButtonSpinner, cvaButtonSpinnerContainer, cvaClickable, cvaIconButton, cvaIndicator, cvaIndicatorIcon, cvaIndicatorIconBackground, cvaIndicatorLabel, cvaIndicatorPing, cvaMenuItem, cvaMenuItemLabel, cvaMenuItemPrefix, cvaMenuItemSuffix, docs, getDevicePixelRatio, getValueBarColorByValue, iconColorNames, iconPalette, setLocalStorage, useClickOutside, useContainerProps, useContinuousTimeout, useDebounce, useDevicePixelRatio, useGeometry, useHover, useIsFirstRender, useIsFullscreen, useIsTextCutOff, useLocalStorage, useLocalStorageReducer, useModal, useOptionallyElevatedState, useOverflowItems, usePopoverContext, usePrompt, useResize, useSelfUpdatingRef, useTimeout, useVisibilityChange };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trackunit/react-components",
3
- "version": "0.1.253",
3
+ "version": "0.1.254",
4
4
  "repository": "https://github.com/Trackunit/manager",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "engines": {
@@ -17,5 +17,4 @@ export interface TimeZone {
17
17
  offset: string;
18
18
  }
19
19
  export * from "./DayPicker";
20
- export * from "./DayPickerPopover";
21
20
  export * from "./DayRangePicker";
@@ -1,22 +0,0 @@
1
- /// <reference types="react" />
2
- import { Matcher } from "react-day-picker";
3
- import { CommonProps, Size } from "../../common/CommonProps";
4
- import { PopoverPlacement } from "../Popover";
5
- import { ButtonVariant } from "../buttons";
6
- export interface DayPickerPopoverProps extends CommonProps {
7
- disabledDays?: Matcher | Matcher[] | undefined;
8
- onDaySelect: (day: Date) => void;
9
- selectedDay?: Date;
10
- color?: ButtonVariant;
11
- size?: Size;
12
- placement?: PopoverPlacement;
13
- buttonContent: JSX.Element;
14
- language: string;
15
- }
16
- /**
17
- * The DayPickerPopover component returns a button which when clicked shows the daypicker.
18
-
19
- * @param {DayPickerPopoverProps} props - The props for the DayPickerPopover component
20
- * @returns {JSX.Element} DayPickerPopover component
21
- */
22
- export declare const DayPickerPopover: ({ disabledDays, className, dataTestId, selectedDay, onDaySelect, color, placement, size, buttonContent, language, }: DayPickerPopoverProps) => JSX.Element;