@jobber/components 4.59.1-st-spike-w.6 → 4.60.0

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.
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var Chip = require('../Chip-2d959a49.js');
5
+ var Chip = require('../Chip-f8b8fd89.js');
6
6
  var tslib_es6 = require('../tslib.es6-5b8768b7.js');
7
7
  var React = require('react');
8
8
  var Icon = require('../Icon-405a216c.js');
@@ -70,7 +70,6 @@ const Chip = ({ ariaLabel, disabled, heading, invalid, label, value, onClick, on
70
70
  label,
71
71
  React__default["default"].createElement("span", { ref: labelRef, className: styles.chipLabelRef })),
72
72
  !labelFullyVisible && (React__default["default"].createElement("div", { className: styles.truncateGradient, "data-testid": "ATL-Chip-Truncation-Gradient" }))),
73
- React__default["default"].createElement("span", null, "\u00A0"),
74
73
  suffix)));
75
74
  };
76
75
  function getTooltipMessage(labelFullyVisible, headingFullyVisible, label, heading) {
@@ -14,7 +14,7 @@ var useRefocusOnActivator = require('@jobber/hooks/useRefocusOnActivator');
14
14
  var useFocusTrap = require('@jobber/hooks/useFocusTrap');
15
15
  var reactPopper = require('react-popper');
16
16
  var useOnKeyDown = require('@jobber/hooks/useOnKeyDown');
17
- var Chip = require('../Chip-2d959a49.js');
17
+ var Chip = require('../Chip-f8b8fd89.js');
18
18
  require('@jobber/design');
19
19
  var useAssert = require('@jobber/hooks/useAssert');
20
20
  require('react-router-dom');
@@ -225,6 +225,10 @@ export interface DataListActionProps<T extends DataListObject> {
225
225
  * Adjust the styling of an action label and icon to be more destructive.
226
226
  */
227
227
  readonly destructive?: boolean;
228
+ /**
229
+ * Determine if the action is visible for a given item.
230
+ */
231
+ readonly visible?: (item: T) => boolean;
228
232
  /**
229
233
  * The callback function when the action is clicked.
230
234
  */
@@ -242,7 +246,7 @@ export interface DataListActionsProps<T extends DataListObject> {
242
246
  */
243
247
  readonly itemsToExpose?: number;
244
248
  }
245
- export interface DataListBulkActionProps extends DataListActionProps<DataListObject> {
249
+ export interface DataListBulkActionProps extends Omit<DataListActionProps<DataListObject>, "visible"> {
246
250
  /**
247
251
  * The callback function when the action is clicked.
248
252
  */
@@ -1,3 +1,3 @@
1
1
  /// <reference types="react" />
2
2
  import { DataListActionProps, DataListObject } from "@jobber/components/DataList/DataList.types";
3
- export declare function DataListAction<T extends DataListObject>({ label, icon, destructive, onClick, }: DataListActionProps<T>): JSX.Element;
3
+ export declare function DataListAction<T extends DataListObject>({ label, icon, destructive, visible, onClick, }: DataListActionProps<T>): JSX.Element | null;
@@ -1,4 +1,8 @@
1
- /// <reference types="react" />
2
- import { DataListItemActionsProps, DataListObject } from "../../DataList.types";
1
+ import { ReactElement } from "react";
2
+ import { DataListActionProps, DataListItemActionsProps, DataListObject } from "../../DataList.types";
3
3
  export declare function DataListItemActions<T extends DataListObject>(_: DataListItemActionsProps<T>): null;
4
- export declare function InternalDataListItemActions(): JSX.Element | null;
4
+ interface InternalDataListItemActionsProps<T extends DataListObject> {
5
+ readonly actions: ReactElement<DataListActionProps<T>>[];
6
+ }
7
+ export declare function InternalDataListItemActions<T extends DataListObject>({ actions, }: InternalDataListItemActionsProps<T>): JSX.Element;
8
+ export {};
@@ -0,0 +1,6 @@
1
+ import { ReactElement } from "react";
2
+ import { DataListActionProps, DataListObject } from "../DataList.types";
3
+ export declare function useGetItemActions<T extends DataListObject>(item: T): {
4
+ actions: ReactElement<DataListActionProps<T>, string | import("react").JSXElementConstructor<any>>[];
5
+ hasActions: boolean;
6
+ };
@@ -408,7 +408,7 @@ function DataListActionsMenu({ visible = false, position, onRequestClose, childr
408
408
  useOnKeyDown.useOnKeyDown(onRequestClose, "Escape");
409
409
  return ReactDOM.createPortal(React__default["default"].createElement(framerMotion.AnimatePresence, null, visible && (React__default["default"].createElement("div", { ref: focusTrapRef, onClick: handleClick },
410
410
  React__default["default"].createElement(framerMotion.motion.div, { role: "menu", ref: setRef, variants: variants$1, initial: "hidden", animate: "visible", exit: "hidden", transition: { duration: TRANSITION_DELAY_IN_SECONDS }, className: styles$7.menu, style: getPositionCssVars(), onClick: onRequestClose }, children),
411
- React__default["default"].createElement("button", { className: styles$7.overlay, onClick: onRequestClose, "aria-label": "Close menu" })))), document.body);
411
+ React__default["default"].createElement("button", { type: "button", className: styles$7.overlay, onClick: onRequestClose, "aria-label": "Close menu" })))), document.body);
412
412
  function handleClick(event) {
413
413
  // Prevent menu from firing the parent's onClick event when it is nested
414
414
  // within a clickable list item
@@ -466,6 +466,8 @@ function DataListActions({ children, itemsToExpose = 2, }) {
466
466
  childrenArray.splice(0, exposedActions.length);
467
467
  return (React__default["default"].createElement(DataListOverflowFade, null,
468
468
  exposedActions.map(({ props }) => {
469
+ if (props.visible && !props.visible(activeItem))
470
+ return null;
469
471
  if (!props.icon)
470
472
  return null;
471
473
  return (React__default["default"].createElement(Tooltip.Tooltip, { key: props.label, message: props.label },
@@ -492,18 +494,12 @@ const variants = {
492
494
  hidden: { opacity: 0, y: 10 },
493
495
  visible: { opacity: 1, y: 0 },
494
496
  };
495
- function InternalDataListItemActions() {
496
- const { itemActionComponent } = useDataListContext();
497
- if (!itemActionComponent)
498
- return null;
499
- const { children } = itemActionComponent.props;
500
- if (!children)
501
- return null;
497
+ function InternalDataListItemActions({ actions, }) {
502
498
  return (React__default["default"].createElement(framerMotion.motion.div, { variants: variants, initial: "hidden", animate: "visible", exit: "hidden", transition: {
503
499
  duration: TRANSITION_DURATION_IN_SECONDS,
504
500
  delay: TRANSITION_DELAY_IN_SECONDS,
505
501
  }, className: styles$c.menu, onContextMenu: handleContextMenu },
506
- React__default["default"].createElement(DataListActions, null, children)));
502
+ React__default["default"].createElement(DataListActions, null, actions)));
507
503
  }
508
504
  function handleContextMenu(event) {
509
505
  event.stopPropagation();
@@ -567,15 +563,33 @@ function DataListItemClickable({ children }) {
567
563
  return React__default["default"].createElement(React__default["default"].Fragment, null, children);
568
564
  }
569
565
 
570
- function DataListItem({ item, layout, }) {
566
+ function useGetItemActions(item) {
571
567
  const { itemActionComponent } = useDataListContext();
568
+ const itemActions = (itemActionComponent === null || itemActionComponent === void 0 ? void 0 : itemActionComponent.props.children) || [];
569
+ const actionsArray = React.Children.toArray(itemActions);
570
+ const actions = React.useMemo(() => {
571
+ return actionsArray.filter(action => {
572
+ if (React.isValidElement(action) && action.props.visible) {
573
+ return action.props.visible(item);
574
+ }
575
+ return true;
576
+ });
577
+ }, [itemActionComponent === null || itemActionComponent === void 0 ? void 0 : itemActionComponent.props.children, item]);
578
+ return {
579
+ actions: actions,
580
+ hasActions: Boolean(actions.length),
581
+ };
582
+ }
583
+
584
+ // eslint-disable-next-line max-statements
585
+ function DataListItem({ item, layout, }) {
572
586
  const { hasInLayoutActions } = useDataListLayoutContext();
573
587
  const [showMenu, setShowMenu] = React.useState(false);
574
588
  const [contextPosition, setContextPosition] = React.useState();
575
589
  const generatedItem = React.useMemo(() => generateListItemElement(item), [item]);
576
- const contextMenuActions = itemActionComponent === null || itemActionComponent === void 0 ? void 0 : itemActionComponent.props.children;
590
+ const { actions, hasActions } = useGetItemActions(item);
577
591
  const isContextMenuVisible = Boolean(contextPosition);
578
- const shouldShowContextMenu = showMenu && isContextMenuVisible && Boolean(contextMenuActions);
592
+ const shouldShowContextMenu = showMenu && isContextMenuVisible && hasActions;
579
593
  return (React__default["default"].createElement(DataListLayoutActionsContext.Provider, { value: { activeItem: item } },
580
594
  React__default["default"].createElement("div", { onMouseEnter: handleShowMenu, onMouseLeave: handleHideMenu, onFocus: handleShowMenu, onBlur: handleHideMenu, onContextMenu: handleContextMenu, className: classnames__default["default"](styles$f.listItem, {
581
595
  [styles$f.active]: showMenu && isContextMenuVisible,
@@ -583,8 +597,8 @@ function DataListItem({ item, layout, }) {
583
597
  React__default["default"].createElement(DataListItemInternal, { item: item },
584
598
  React__default["default"].createElement(DataListItemClickable, null, layout(generatedItem))),
585
599
  React__default["default"].createElement(framerMotion.AnimatePresence, null,
586
- showMenu && !hasInLayoutActions && React__default["default"].createElement(InternalDataListItemActions, null),
587
- React__default["default"].createElement(DataListActionsMenu, { key: item.id, visible: shouldShowContextMenu, position: contextPosition || { x: 0, y: 0 }, onRequestClose: () => setContextPosition(undefined) }, contextMenuActions)))));
600
+ showMenu && hasActions && !hasInLayoutActions && (React__default["default"].createElement(InternalDataListItemActions, { actions: actions })),
601
+ React__default["default"].createElement(DataListActionsMenu, { key: item.id, visible: shouldShowContextMenu, position: contextPosition || { x: 0, y: 0 }, onRequestClose: () => setContextPosition(undefined) }, actions)))));
588
602
  function handleShowMenu() {
589
603
  setShowMenu(true);
590
604
  }
@@ -592,7 +606,7 @@ function DataListItem({ item, layout, }) {
592
606
  setShowMenu(false);
593
607
  }
594
608
  function handleContextMenu(event) {
595
- if (!contextMenuActions || isContextMenuVisible)
609
+ if (!hasActions || isContextMenuVisible)
596
610
  return;
597
611
  event.preventDefault();
598
612
  setContextPosition({
@@ -944,10 +958,14 @@ var css_248z$1 = ".iyg43v-S9yU- {\n display: -ms-flexbox;\n display: flex;\n
944
958
  var styles$1 = {"action":"iyg43v-S9yU-","label":"AUJNqz93ZDA-"};
945
959
  styleInject_es.styleInject(css_248z$1);
946
960
 
947
- function DataListAction({ label, icon, destructive, onClick, }) {
961
+ function DataListAction({ label, icon, destructive, visible = () => true, onClick, }) {
948
962
  const { activeItem } = useDataListLayoutActionsContext();
963
+ // Don't render if the item is not visible
964
+ if (activeItem && !visible(activeItem)) {
965
+ return null;
966
+ }
949
967
  const color = destructive ? "critical" : "blue";
950
- return (React__default["default"].createElement("button", { className: styles$1.action, onClick: handleClick },
968
+ return (React__default["default"].createElement("button", { type: "button", className: styles$1.action, onClick: handleClick },
951
969
  icon && React__default["default"].createElement(Icon.Icon, { name: icon, color: color }),
952
970
  React__default["default"].createElement(Typography.Typography, { textColor: color },
953
971
  React__default["default"].createElement("span", { className: styles$1.label }, label))));
@@ -1,13 +1,13 @@
1
1
  /// <reference types="react" />
2
2
  import { CommonFormFieldProps, FormFieldProps } from "../FormField";
3
3
  interface InputPasswordProps extends CommonFormFieldProps, Pick<FormFieldProps, "autocomplete" | "onEnter" | "onFocus" | "onBlur" | "inputRef" | "validations" | "defaultValue"> {
4
- readonly value?: string;
4
+ value?: string;
5
5
  onChange?(newValue: string): void;
6
6
  /**
7
7
  * Display toggle to change the visibility of the password input
8
8
  * @default false
9
9
  */
10
- readonly hasVisibility?: boolean;
10
+ hasVisibility?: boolean;
11
11
  }
12
12
  export declare function InputPassword(props: InputPasswordProps): JSX.Element;
13
13
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jobber/components",
3
- "version": "4.59.1-st-spike-w.6+464eded3",
3
+ "version": "4.60.0",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -20,7 +20,7 @@
20
20
  ],
21
21
  "dependencies": {
22
22
  "@jobber/design": "^0.47.0",
23
- "@jobber/formatters": "^0.2.2",
23
+ "@jobber/formatters": "*",
24
24
  "@jobber/hooks": "^2.7.0",
25
25
  "@popperjs/core": "^2.0.6",
26
26
  "@std-proposal/temporal": "0.0.1",
@@ -41,6 +41,7 @@
41
41
  "react-countdown": "^2.3.2",
42
42
  "react-datepicker": "^4.10.0",
43
43
  "react-dropzone": "^11.0.2",
44
+ "react-hook-form": "^7.43.7",
44
45
  "react-markdown": "^8.0.3",
45
46
  "react-popper": "^2.2.5",
46
47
  "react-router-dom": "^5.3.4",
@@ -76,13 +77,12 @@
76
77
  },
77
78
  "peerDependencies": {
78
79
  "react": "^18",
79
- "react-dom": "^18",
80
- "react-hook-form": "^7.43.7"
80
+ "react-dom": "^18"
81
81
  },
82
82
  "browserslist": [
83
83
  "last 1 version",
84
84
  "> 1%",
85
85
  "IE 10"
86
86
  ],
87
- "gitHead": "464eded363bb8f2bb697e86954eb8c7808e0e033"
87
+ "gitHead": "6d278cdff3de74aca7c90d7da59ac9c365dbd69c"
88
88
  }