Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
@filerobot/explorer / lib / components / Modals / LabelModal / LabelModalContent.js
Size: Mime:
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
import { useState } from 'react';
import { InputGroup, CheckBoxGroup // SelectGroup, MenuItem
} from '@scaleflex/ui/core';
import deepMerge from '@filerobot/utils/lib/deepMerge';
import { ColorPickerModal } from '@filerobot/common';
import CustomColorIcon from './CustomColorIcon';
import { DEFAULT_COLORS } from './LabelModal.constants';
import Styled from './LabelModal.styled';
import { jsx as _jsx } from "react/jsx-runtime";
import { jsxs as _jsxs } from "react/jsx-runtime";
import { Fragment as _Fragment } from "react/jsx-runtime";
function LabelModalContent(_ref) {
  var i18n = _ref.i18n,
    _ref$data = _ref.data,
    data = _ref$data === void 0 ? {
      label: {}
    } : _ref$data,
    updateLabel = _ref.updateLabel;
  var _useState = useState(false),
    _useState2 = _slicedToArray(_useState, 2),
    isColorPickerModalVisible = _useState2[0],
    setIsColorPickerModalVisible = _useState2[1];
  var updateLabelState = function updateLabelState() {
    var updates = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
    return updateLabel(function (_state) {
      return deepMerge(_state, updates);
    });
  };
  var _ref2 = data || {},
    _ref2$label = _ref2.label,
    label = _ref2$label === void 0 ? {} : _ref2$label,
    _ref2$isSubmitted = _ref2.isSubmitted,
    isSubmitted = _ref2$isSubmitted === void 0 ? false : _ref2$isSubmitted;
  return /*#__PURE__*/_jsxs(_Fragment, {
    children: [/*#__PURE__*/_jsxs(Styled.Container, {
      children: [/*#__PURE__*/_jsx(InputGroup, {
        label: i18n('labelModalLabelTitleInput'),
        onChange: function onChange(_ref3) {
          var value = _ref3.target.value;
          return updateLabelState({
            name: value
          });
        },
        value: label.name || '',
        error: Boolean(isSubmitted && !label.name),
        fullWidth: true,
        autoFocus: true,
        "data-testid": "labelModalTitleInput"
      }), /*#__PURE__*/_jsxs(Styled.ColorsContainer, {
        "data-testid": "labelModalColorsContainer",
        children: [/*#__PURE__*/_jsxs(Styled.Colors, {
          children: [DEFAULT_COLORS.map(function (itemColor) {
            return /*#__PURE__*/_jsx(Styled.ColorItem, {
              $bgColor: itemColor,
              $active: label.color === itemColor,
              onClick: function onClick() {
                return updateLabelState({
                  color: itemColor
                });
              }
            }, itemColor);
          }), /*#__PURE__*/_jsx(CustomColorIcon, {
            onClick: function onClick() {
              return setIsColorPickerModalVisible(true);
            }
          })]
        }), /*#__PURE__*/_jsx(InputGroup, {
          onChange: function onChange(_ref4) {
            var value = _ref4.target.value;
            return updateLabelState({
              color: value
            });
          },
          value: label.color || '',
          fullWidth: true
        }), /*#__PURE__*/_jsx(CheckBoxGroup, {
          checked: label.is_pinned,
          label: i18n('labelModalPinnedLabel'),
          labelPosition: "after",
          onChange: function onChange(_ref5) {
            var checked = _ref5.target.checked;
            return updateLabelState({
              is_pinned: checked
            });
          },
          size: "md"
        })]
      })]
    }), /*#__PURE__*/_jsx(ColorPickerModal, {
      open: isColorPickerModalVisible,
      onClose: function onClose() {
        return setIsColorPickerModalVisible(false);
      },
      defaultColor: label.color,
      colors: DEFAULT_COLORS,
      onChange: function onChange(hexColor) {
        return updateLabelState({
          color: hexColor
        });
      },
      i18n: i18n
    })]
  });
}
export default LabelModalContent;