"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

var _typeof = require("@babel/runtime/helpers/typeof");

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.Advanced = exports.Regular = exports.default = void 0;

var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));

var _react = _interopRequireWildcard(require("react"));

var _README = _interopRequireDefault(require("./README.mdx"));

var _List = require("../List");

var _reactDropzone = _interopRequireWildcard(require("react-dropzone"));

var _iconsReact = require("@wfp/icons-react");

var _classnames = _interopRequireDefault(require("classnames"));

function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }

function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }

var _default = {
  title: 'Components/Forms/FileUploader (react-dropzone)',
  parameters: {
    componentSubtitle: 'Component',
    status: 'released',
    mdx: _README.default,
    introText: "[react-dropzone](https://github.com/react-dropzone/react-dropzone) for handling file uploads. It allows using simple react hooks to create a HTML5-compliant drag'n'drop zone for files."
  }
};
exports.default = _default;

var Regular = function Regular(args) {
  var _useState = (0, _react.useState)([]),
      _useState2 = (0, _slicedToArray2.default)(_useState, 2),
      file = _useState2[0],
      setfile = _useState2[1];

  var files = file.map(function (file) {
    return /*#__PURE__*/_react.default.createElement(_List.ListItem, {
      key: file.path
    }, file.path, " - ", Math.round(file.size / 1000), " kB");
  });
  return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_reactDropzone.default, {
    onDrop: function onDrop(acceptedFiles) {
      return setfile(acceptedFiles);
    }
  }, function (_ref) {
    var getRootProps = _ref.getRootProps,
        getInputProps = _ref.getInputProps;
    return /*#__PURE__*/_react.default.createElement("section", {
      className: "wfp--dropzone"
    }, /*#__PURE__*/_react.default.createElement("div", getRootProps({
      className: 'wfp--dropzone__input'
    }), /*#__PURE__*/_react.default.createElement("input", getInputProps()), /*#__PURE__*/_react.default.createElement("div", null, "Drag 'n' drop some files here, or click to select files")));
  }), file.length > 0 && /*#__PURE__*/_react.default.createElement("aside", {
    className: "wfp--dropzone__file-list"
  }, /*#__PURE__*/_react.default.createElement("h4", null, "Files"), /*#__PURE__*/_react.default.createElement(_List.List, null, files)));
};

exports.Regular = Regular;
Regular.parameters = {
  html: false,
  docs: {
    source: {
      code: " import Dropzone from 'react-dropzone';\n\n      export const Regular = (args) => {\n        const [file, setfile] = useState([])\n      \n        const files = file.map((file) => (\n          <ListItem key={file.path}>\n            {file.path} - {Math.round(file.size / 1000)} kB\n          </ListItem>\n        ));\n      \n        return(\n        <>\n        <Dropzone onDrop={(acceptedFiles) => setfile(acceptedFiles)}>\n          {({ getRootProps, getInputProps }) => (\n            <section className=\"wfp--dropzone\">\n              <div {...getRootProps({ className: 'wfp--dropzone__input' })}>\n                <input {...getInputProps()} />\n                <div>Drag 'n' drop some files here, or click to select files</div>\n              </div>\n            </section>\n          )}\n        </Dropzone>\n        <aside className=\"wfp--dropzone__file-list\">\n              <h4>Files</h4>\n              <List>{files}</List>\n        </aside>\n        </>\n        \n      )\n      };"
    }
  }
};

var Advanced = function Advanced(args) {
  var _useDropzone = (0, _reactDropzone.useDropzone)(),
      acceptedFiles = _useDropzone.acceptedFiles,
      getRootProps = _useDropzone.getRootProps,
      getInputProps = _useDropzone.getInputProps,
      isDragActive = _useDropzone.isDragActive;

  var files = acceptedFiles.map(function (file) {
    return /*#__PURE__*/_react.default.createElement(_List.ListItem, {
      key: file.path
    }, file.path, " - ", Math.round(file.size / 1000), " kB");
  });
  var wrapperClassNames = (0, _classnames.default)('wfp--dropzone__input', {
    'wfp--dropzone__input--drag-active': isDragActive
  });
  return /*#__PURE__*/_react.default.createElement("section", {
    className: "wfp--dropzone"
  }, /*#__PURE__*/_react.default.createElement("div", getRootProps({
    isDragActive: isDragActive,
    className: wrapperClassNames
  }), /*#__PURE__*/_react.default.createElement("input", getInputProps()), /*#__PURE__*/_react.default.createElement(_iconsReact.UploadGlyph, {
    className: "wfp--dropzone__icon"
  }), /*#__PURE__*/_react.default.createElement("div", null, "Drop files or click here to upload")), files.length > 0 && /*#__PURE__*/_react.default.createElement("aside", {
    className: "wfp--dropzone__file-list"
  }, /*#__PURE__*/_react.default.createElement("h4", null, "Files"), /*#__PURE__*/_react.default.createElement(_List.List, null, files)));
};

exports.Advanced = Advanced;
Advanced.parameters = {
  html: false,
  docs: {
    source: {
      code: "\nimport Dropzone, { useDropzone } from 'react-dropzone';\nimport { Icon, List, ListItem } from '@wfp/ui';\nimport { Upload16 } from '@wfp/icons-react';\nimport classNames from 'classnames';\n\nexport const Advanced = (args) => {\n  const {\n    acceptedFiles,\n    getRootProps,\n    getInputProps,\n    isDragActive,\n  } = useDropzone();\n\n  const files = acceptedFiles.map((file) => (\n    <ListItem key={file.path}>\n      {file.path} - {Math.round(file.size / 1000)} kB\n    </ListItem>\n  ));\n\n  const wrapperClassNames = classNames('wfp--dropzone__input', {\n    'wfp--dropzone__input--drag-active': isDragActive\n  });\n\n  return (\n    <section className=\"wfp--dropzone\">\n      <div {...getRootProps({ isDragActive, className: wrapperClassNames })}>\n        <input {...getInputProps()} />\n        <Upload16 className=\"wfp--dropzone__icon\" />\n        <div>Drop files or click here to upload</div>\n      </div>\n      <aside className=\"wfp--dropzone__file-list\">\n        <h4>Files</h4>\n        <List>{files}</List>\n      </aside>\n    </section>\n  );\n}"
    }
  }
};