Repository URL to install this package:
|
Version:
3.12.20 ▾
|
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
import { InputGroup, Label, TooltipV2, MenuItem } from '@scaleflex/ui/core';
import { useTheme } from '@scaleflex/ui/theme/hooks';
import { InfoOutline } from '@scaleflex/icons';
import generateI18nKeyFromString from '@filerobot/utils/lib/generateI18nKeyFromString';
import { PC } from '@filerobot/common';
import { useExplorer } from '../../hooks';
import { DEFAULT_CROP_TYPE, INVALID_INPUT_CHARS } from './CropPanel.constants';
import Styled from './CropPanel.styled';
import { jsx as _jsx } from "react/jsx-runtime";
import { jsxs as _jsxs } from "react/jsx-runtime";
var Option = function Option(_ref) {
var label = _ref.label,
value = _ref.value,
onChange = _ref.onChange,
options = _ref.options,
styles = _ref.styles,
_ref$block = _ref.block,
block = _ref$block === void 0 ? true : _ref$block,
_ref$type = _ref.type,
type = _ref$type === void 0 ? 'select' : _ref$type,
_ref$tooltipMessageKe = _ref.tooltipMessageKey,
tooltipMessageKey = _ref$tooltipMessageKe === void 0 ? '' : _ref$tooltipMessageKe,
_ref$noOptionsTransla = _ref.noOptionsTranslations,
noOptionsTranslations = _ref$noOptionsTransla === void 0 ? false : _ref$noOptionsTransla,
_ref$i18nKeyPrefix = _ref.i18nKeyPrefix,
i18nKeyPrefix = _ref$i18nKeyPrefix === void 0 ? 'exportOptions' : _ref$i18nKeyPrefix,
_ref$isPdfModalPageEr = _ref.isPdfModalPageError,
isPdfModalPageError = _ref$isPdfModalPageEr === void 0 ? false : _ref$isPdfModalPageEr;
var theme = useTheme();
var _useExplorer = useExplorer(),
i18n = _useExplorer.i18n;
var iconsSecondaryColor = theme.palette[PC.IconsSecondary];
var checkInputHandler = function checkInputHandler(event) {
if (INVALID_INPUT_CHARS.includes(event.key)) {
event.preventDefault();
}
};
return /*#__PURE__*/_jsxs(Styled.OptionGroup, {
style: styles,
children: [block && /*#__PURE__*/_jsx(Label, {
iconEnd: function iconEnd() {
return tooltipMessageKey && /*#__PURE__*/_jsx(TooltipV2, {
appendTo: document.body,
arrow: true,
position: "top",
size: "md",
title: tooltipMessageKey,
children: /*#__PURE__*/_jsx(InfoOutline, {
color: iconsSecondaryColor,
size: 14
})
});
},
children: label
}), type === 'input' ? /*#__PURE__*/_jsx("div", {
className: "filerobot-Explorer-ImageOptions-options-input",
children: /*#__PURE__*/_jsx(InputGroup, {
style: {
width: '100%'
},
inputProps: {
type: 'number',
min: 1
},
value: value,
onKeyDown: function onKeyDown(event) {
return checkInputHandler(event);
},
onChange: onChange,
error: isPdfModalPageError,
hint: isPdfModalPageError ? i18n('pdfModelContentNotFoundLabel') : ''
})
}) : /*#__PURE__*/_jsx(Styled.SelectGroup, {
value: value,
label: !block ? label : '',
LabelProps: {
iconEnd: function iconEnd(props) {
return !block && /*#__PURE__*/_jsx(TooltipV2, {
arrow: true,
position: "top",
size: "md",
title: i18n('imageOptionFormatTooltip'),
children: /*#__PURE__*/_jsx(InfoOutline, _objectSpread(_objectSpread({}, props), {}, {
color: iconsSecondaryColor,
size: 14
}))
});
}
},
fullWidth: true,
onChange: onChange,
SelectProps: {
MenuProps: {
hideScroll: false
}
},
children: options.map(function (option) {
var _ref2, _option$label, _option$value, _option$value2;
var unTranslatedLabel = (_ref2 = (_option$label = option.label) !== null && _option$label !== void 0 ? _option$label : option.value) !== null && _ref2 !== void 0 ? _ref2 : option;
var alreadyUseTranslationKey = unTranslatedLabel === DEFAULT_CROP_TYPE; // Hack: To not add prefix for already generated translation key
var i18nKey = noOptionsTranslations ? null : alreadyUseTranslationKey ? unTranslatedLabel : generateI18nKeyFromString(i18nKeyPrefix ? "".concat(i18nKeyPrefix, " ").concat(unTranslatedLabel) : unTranslatedLabel);
var optionLabel = noOptionsTranslations ? unTranslatedLabel : i18n(i18nKey, {
defaultValue: unTranslatedLabel
}) || unTranslatedLabel;
return /*#__PURE__*/_jsx(MenuItem, {
value: (_option$value2 = option.value) !== null && _option$value2 !== void 0 ? _option$value2 : option,
primary: optionLabel,
style: {
textTransform: 'capitalize'
},
children: optionLabel
}, (_option$value = option.value) !== null && _option$value !== void 0 ? _option$value : option);
})
})]
});
};
export default Option;