oolib 2.90.2 → 2.90.4
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.
|
@@ -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(
|
|
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
|
|
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;
|