Skip to content

How to use it in react? #405

@execriss

Description

@execriss

Hello, I love miniPaint.
It's just what I was needing for my project, but I'm having a hard time integrating it into React.

Do you have any guide or example using it in React js?
I can now render the Iframe within a modal, but I am having a hard time understanding how I can send two images to the iframe, so that it can paint them one on top of the other, and I would also like to know how I can save the final image.
If anyone has an example using it in React js, it would do me a great favor.

import React, { useEffect, useCallback, useRef } from "react";
import { ENV } from "../utils/constants";

export default function ModalEditTemplate({
  showModal,
  setShowModal,

}) {
  return (
    <div>
      {showModal && (
        <div
          id="default-modal"
          tabIndex="1"
          aria-hidden="true"
          className="fixed inset-0 overflow-y-auto overflow-x-hidden z-50 flex items-center justify-center bg-black bg-opacity-50"
        >
          <div className="relative">
            <div className="relative bg-gray-700 rounded-lg shadow dark:bg-gray-700">
              <div className="flex items-center justify-between md:p-2 border-b rounded-t dark:border-gray-600">
                <h3 className="text-xl font-semibold text-gray-900 dark:text-white">
                  Editar Plantilla
                </h3>
                <button
                  type="button"
                  className="text-gray-400 bg-transparent hover:bg-gray-200 hover:text-gray-900 rounded-lg text-sm w-8 h-8 ms-auto inline-flex justify-center items-center dark:hover:bg-gray-600 dark:hover:text-white"
                  data-modal-hide="default-modal"
                  onClick={() => setShowModal(false)}
                >
                  <svg
                    className="w-3 h-3"
                    aria-hidden="true"
                    xmlns="http://www.w3.org/2000/svg"
                    fill="none"
                    viewBox="0 0 14 14"
                  >
                    <path
                      stroke="currentColor"
                      strokeLinecap="round"
                      strokeLinejoin="round"
                      strokeWidth="2"
                      d="m1 1 6 6m0 0 6 6M7 7l6-6M7 7l-6 6"
                    />
                  </svg>
                  <span className="sr-only">Cerrar modal</span>
                </button>
              </div>
              <div className="p-1 px-5">
                <iframe
                  style={{ width: "70vw", height: "70vh" }}
                  id="miniPaint"
                  src={`https://viliusle.github.io/miniPaint/?image=${ENV.SERVER_HOST}/uploads/amex_67402d8f7e.png`}
                  allow="camera"
                ></iframe>
                <button
                  className="mt-4 bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded"
                  onClick={() => {}}
                >
                  Guardar Plantilla
                </button>
              </div>
            </div>
          </div>
        </div>
      )}
    </div>
  );
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions