oolib 2.90.3 → 2.91.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.
@@ -1,4 +1,4 @@
1
- export function ActionMenu({ icon, invert, actions, align, iconSize, M, ButtonComp: _ButtonComp, setShowActions: setShowActionsInParent, popOutOfOverflowHiddenParent, CustomSelectComp, storybookPreview, useLightboxPortal, }: {
1
+ export function ActionMenu({ icon, invert, actions, align, iconSize, M, ButtonComp: _ButtonComp, setShowActions: setShowActionsInParent, popOutOfOverflowHiddenParent, CustomSelectComp, storybookPreview, }: {
2
2
  icon?: string;
3
3
  invert: any;
4
4
  actions: any;
@@ -10,6 +10,5 @@ export function ActionMenu({ icon, invert, actions, align, iconSize, M, ButtonCo
10
10
  popOutOfOverflowHiddenParent?: boolean;
11
11
  CustomSelectComp: any;
12
12
  storybookPreview: any;
13
- useLightboxPortal: any;
14
13
  }): React.JSX.Element;
15
14
  import React from "react";
@@ -47,12 +47,13 @@ var react_dom_1 = require("react-dom");
47
47
  //
48
48
  var ActionMenu = function (_a) {
49
49
  var _b = _a.icon, icon = _b === void 0 ? "DotsThree" : _b, //most likely will never change
50
- invert = _a.invert, actions = _a.actions, _c = _a.align, align = _c === void 0 ? "right" : _c, _d = _a.iconSize, iconSize = _d === void 0 ? "S" : _d, M = _a.M, _e = _a.ButtonComp, _ButtonComp = _e === void 0 ? "ButtonGhost" : _e, setShowActionsInParent = _a.setShowActions, _f = _a.popOutOfOverflowHiddenParent, popOutOfOverflowHiddenParent = _f === void 0 ? false : _f, CustomSelectComp = _a.CustomSelectComp, storybookPreview = _a.storybookPreview, //for storybook purposes
51
- useLightboxPortal = _a.useLightboxPortal;
50
+ invert = _a.invert, actions = _a.actions, _c = _a.align, align = _c === void 0 ? "right" : _c, _d = _a.iconSize, iconSize = _d === void 0 ? "S" : _d, M = _a.M, _e = _a.ButtonComp, _ButtonComp = _e === void 0 ? "ButtonGhost" : _e, setShowActionsInParent = _a.setShowActions, _f = _a.popOutOfOverflowHiddenParent, popOutOfOverflowHiddenParent = _f === void 0 ? false : _f, CustomSelectComp = _a.CustomSelectComp, storybookPreview = _a.storybookPreview;
52
51
  var actionMenuRef = (0, react_1.useRef)(null);
53
52
  var optionsWrapperRef = (0, react_1.useRef)(null);
54
53
  var _g = (0, react_1.useState)(false), showActions = _g[0], setShowActions = _g[1];
55
- (0, useHandleClickOutside_1.useHandleClickOutside)(actionMenuRef, setShowActions);
54
+ (0, useHandleClickOutside_1.useHandleClickOutside)(popOutOfOverflowHiddenParent
55
+ ? [actionMenuRef, optionsWrapperRef] //cuz in popOut case, options are rendered in a portal, which means the 'options' are no longer a child on acitonMenuRef. Hence we need to track click outside optionsWrapperRef as well.
56
+ : actionMenuRef, setShowActions);
56
57
  if (!actions || actions.length === 0)
57
58
  return null;
58
59
  var getOpsRect = function () { var _a; return (_a = optionsWrapperRef.current) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect(); };
@@ -21,6 +21,7 @@ var _EXPORTS_1 = require("../../utils/_EXPORTS");
21
21
  var BlockLabel_1 = require("../BlockLabel");
22
22
  var styled_1 = require("./styled");
23
23
  var Tooltip_1 = require("../Tooltip");
24
+ var utilsOolib_1 = require("../../utilsOolib");
24
25
  var greyColor40 = themes_1.colors.greyColor40, greyColor100 = themes_1.colors.greyColor100, white = themes_1.colors.white;
25
26
  function SwitchDouble(_a) {
26
27
  var id = _a.id, valueProp = _a.value, options = _a.options, onChange = _a.onChange, invert = _a.invert, saveValueAsString = _a.saveValueAsString, _b = _a.disabled, disabled = _b === void 0 ? false : _b;
@@ -36,7 +37,7 @@ function SwitchDouble(_a) {
36
37
  var props = arguments[0];
37
38
  var isLeftOptionActive = value === undefined || options[0].value === (value === null || value === void 0 ? void 0 : value.value);
38
39
  if (value === undefined)
39
- throw new Error('You need to pass a value prop to make SwitchDouble work');
40
+ throw new Error("You need to pass a value prop to make SwitchDouble work");
40
41
  return (react_1.default.createElement("div", null,
41
42
  react_1.default.createElement(BlockLabel_1.BlockLabel, __assign({}, (0, _EXPORTS_1.getBlockLabelProps)(props))),
42
43
  react_1.default.createElement(styled_1.StyledSwitchWrapperStyle1, null,
@@ -58,6 +59,7 @@ exports.SwitchDouble = SwitchDouble;
58
59
  function SwitchSingle(_a) {
59
60
  var id = _a.id, value = _a.value, option = _a.option, onChange = _a.onChange, _b = _a.disabled, disabled = _b === void 0 ? false : _b, invert = _a.invert, saveValueAsString = _a.saveValueAsString, _c = _a.layoutStyle, layoutStyle = _c === void 0 ? "style1" : _c, infoTooltip = _a.infoTooltip;
60
61
  var props = arguments[0];
62
+ var localize = (0, utilsOolib_1.useLocale)();
61
63
  /**
62
64
  * very important that we check this way,
63
65
  * as opposed to checking as 'value === undefined'
@@ -76,18 +78,32 @@ function SwitchSingle(_a) {
76
78
  var genSwitch = function () { return (react_1.default.createElement(styled_1.StyledButtonSlider, { inactive: isInactive, disabled: disabled, invert: invert, onClick: handleClick },
77
79
  react_1.default.createElement(styled_1.StyledSwitch, { className: "StyledSwitch" //read in styled.js why we are using an okf-anti-pattern
78
80
  , direction: isInactive ? "left" : "right", inactive: isInactive, disabled: disabled, invert: invert }))); };
79
- var genDisplayText = function () { return react_1.default.createElement(styled_1.STYLED_SANS_3, __assign({}, { invert: invert, lineHeight: 1, semibold: isInactive ? false : true }), option.display); };
81
+ var injectOptionalLabelIntoDisplayText = function (_a) {
82
+ var label = _a.label, display = _a.display, isRequired = _a.isRequired;
83
+ if (!!label)
84
+ return display; //if label exists, we do nothing, cuz optional label in that case, would be shown next to the label
85
+ //else
86
+ if (isRequired === false)
87
+ return display + " (".concat(localize('optional'), ")");
88
+ //else
89
+ return display; //cuz ofcourse its not optional, so no need to show optional label
90
+ };
91
+ var genDisplayText = function () { return (react_1.default.createElement(styled_1.STYLED_SANS_3, __assign({}, { invert: invert, lineHeight: 1, semibold: isInactive ? false : true }), injectOptionalLabelIntoDisplayText({
92
+ display: option.display,
93
+ label: props.label,
94
+ isRequired: props.isRequired
95
+ }))); };
80
96
  var genSwitchDisplay = function () {
81
97
  return infoTooltip ? (react_1.default.createElement("div", { style: { display: "flex", gap: ".5rem", alignItems: "center" } },
82
98
  genDisplayText(),
83
- react_1.default.createElement(Tooltip_1.Tooltip, __assign({ presetTarget: "infoIcon" }, infoTooltip)))) : genDisplayText();
99
+ react_1.default.createElement(Tooltip_1.Tooltip, __assign({ presetTarget: "infoIcon" }, infoTooltip)))) : (genDisplayText());
84
100
  };
85
101
  return (react_1.default.createElement("div", null,
86
- react_1.default.createElement(BlockLabel_1.BlockLabel, __assign({}, (0, _EXPORTS_1.getBlockLabelProps)(props))),
102
+ react_1.default.createElement(BlockLabel_1.BlockLabel, __assign({ hideOptionalLabel: !!props.label === false }, (0, _EXPORTS_1.getBlockLabelProps)(props))),
87
103
  layoutStyle === "style1" ? (react_1.default.createElement(styled_1.StyledSwitchWrapperStyle1, null,
88
104
  genSwitch(),
89
- genSwitchDisplay())) : layoutStyle === "style2" && (react_1.default.createElement(styled_1.StyledSwitchWrapperStyle2, null,
105
+ genSwitchDisplay())) : (layoutStyle === "style2" && (react_1.default.createElement(styled_1.StyledSwitchWrapperStyle2, null,
90
106
  genSwitchDisplay(),
91
- genSwitch()))));
107
+ genSwitch())))));
92
108
  }
93
109
  exports.SwitchSingle = SwitchSingle;
@@ -1 +1 @@
1
- export function useHandleClickOutside(ref: any, setShowOptions: any, options?: {}): void;
1
+ export function useHandleClickOutside(ref: any, setShowOptions: any, options?: any): void;
@@ -2,13 +2,20 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.useHandleClickOutside = void 0;
4
4
  var react_1 = require("react");
5
+ var toArray_1 = require("../toArray");
6
+ /**
7
+ *
8
+ * @param {*} ref can be a ref or an array of refs
9
+ * @param {*} setShowOptions
10
+ * @param {*} options
11
+ */
5
12
  var useHandleClickOutside = function (ref, setShowOptions, options) {
6
13
  if (options === void 0) { options = {}; }
7
14
  var _a = options.enabled, enabled = _a === void 0 ? true : _a;
8
15
  var handleClickOutside = function (event) {
9
16
  if (!enabled)
10
17
  return;
11
- if (ref.current && !ref.current.contains(event.target)) {
18
+ if ((0, toArray_1.toArray)(ref).every(function (refD) { return refD.current && !refD.current.contains(event.target); })) {
12
19
  //clicked outside editor
13
20
  setShowOptions(false);
14
21
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oolib",
3
- "version": "2.90.3",
3
+ "version": "2.91.0",
4
4
  "description": " OKE Component Library",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",