Skip to content

Commit

Permalink
Reusable ImageCropper component
Browse files Browse the repository at this point in the history
  • Loading branch information
elektronaut committed Nov 17, 2021
1 parent 669bbec commit 744ea14
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 18 deletions.
18 changes: 9 additions & 9 deletions app/assets/builds/pages_core/admin-dist.js

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions app/javascript/components.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
export { default as Attachments } from "./components/Attachments";
export { default as DateRangeSelect } from "./components/DateRangeSelect";
export { default as EditableImage } from "./components/EditableImage";
export { default as ImageCropper,
useCrop,
cropParams } from "./components/ImageCropper";
export { default as ImageGrid } from "./components/ImageGrid";
export { default as ImageUploader } from "./components/ImageUploader";
export { default as Modal } from "./components/Modal";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import React, { useEffect, useRef, useState } from "react";
import PropTypes from "prop-types";

import Image from "./Image";
import Toolbar from "./Toolbar";
import Image from "./ImageCropper/Image";
import Toolbar from "./ImageCropper/Toolbar";

export { default as useCrop,
cropParams } from "./ImageCropper/useCrop";

function focalPoint(state) {
if (state.crop_gravity_x === null || state.crop_gravity_y === null) {
Expand All @@ -15,7 +18,7 @@ function focalPoint(state) {
}
}

export default function Editor(props) {
export default function ImageCropper(props) {
const containerRef = useRef();
const [containerSize, setContainerSize] = useState(null);

Expand Down Expand Up @@ -80,7 +83,7 @@ export default function Editor(props) {
);
}

Editor.propTypes = {
ImageCropper.propTypes = {
croppedImage: PropTypes.string,
cropState: PropTypes.object,
dispatch: PropTypes.func
Expand Down
9 changes: 4 additions & 5 deletions app/javascript/components/ImageEditor.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ import PropTypes from "prop-types";
import ModalStore from "./ModalStore";
import { putJson } from "../lib/request";

import useCrop, { cropParams } from "./ImageEditor/useCrop";
import Editor from "./ImageEditor/Editor";
import ImageCropper, { useCrop, cropParams } from "./ImageCropper";
import Form from "./ImageEditor/Form";

export default function ImageEditor(props) {
Expand Down Expand Up @@ -37,9 +36,9 @@ export default function ImageEditor(props) {

return (
<div className="image-editor">
<Editor croppedImage={croppedImage}
cropState={cropState}
dispatch={dispatch} />
<ImageCropper croppedImage={croppedImage}
cropState={cropState}
dispatch={dispatch} />
{!cropState.cropping &&
<Form alternative={localizations.alternative}
caption={localizations.caption}
Expand Down

0 comments on commit 744ea14

Please sign in to comment.