Code Monkey home page Code Monkey logo

react-jigsaw-puzzle's Introduction

Demo NPM GLP-3.0 License GitHub Repo stars GitHub Repo stars

react-jigsaw-puzzle

Simple plug-and-play React component for jigsaw puzzles.

It supports resizing and can be fed with any image URL without the need to "tile" the image first.

Check out the Demo to see if it fits your needs.

Usage

// Minimal usage

import {JigsawPuzzle} from "react-jigsaw-puzzle/lib";
import "react-jigsaw-puzzle/lib/jigsaw-puzzle.css";

<JigsawPuzzle imageSrc="https://any.image/url.jpg" />;
// With custom amount of rows and columns

import {JigsawPuzzle} from "react-jigsaw-puzzle/lib";
import "react-jigsaw-puzzle/lib/jigsaw-puzzle.css";

<JigsawPuzzle
  imageSrc="https://any.image/url.jpg"
  rows={4}
  columns={6}
  onSolved={() => alert("Solved!")}
/>;

Properties

Name Type Purpose Default
imageSrc string Source of the image. Can be any URL or relative path. required
rows number The amount of rows the puzzle will have. 3
columns number The amount of columns the puzzle with have. 4
onSolved function Called when the puzzle is solved. () => {}

Styling

You can simply override or add styles via plain CSS.

The following style classes are used:

  • .jigsaw-puzzle - The container for the puzzle pieces
  • .jigsaw-puzzle__piece - Puzzle piece/tile
  • .jigsaw-puzzle__piece--solved - Puzzle piece in the correct position
  • .jigsaw-puzzle__piece--dragging - Puzzle piece that is being dragged

Drawbacks

  • The component adjusts its height according to the image's aspect ratio. That means if the image has a 2:1 aspect ratio and the width is set or calculated to 800px, the puzzle will be 400px high.
    That is probably what you'll want for landscape images, but portrait or square images can easily expand out of the viewport on desktop screens.
    You can work around this by setting either a fixed width or a width dependent on the viewport height (vh).
  • While in theory you can make a 100x100 puzzle, a large tile amount will result in poor render performance.
    This is because each tile is basically rendering the whole image but "zooms in".
    If you want to make really large puzzles, this is probably not for you. Still, I decided to not limit the tile amount because computers and phones are getting faster by the day.
  • I built this for a very specific use-case. If you find bugs or want features added, feel free to either create an issue or make a PR.
  • Touch scrolling is disabled while moving a tile by temporarily setting overflow:hidden on the <html> element.
    Keep in mind that this does not prevent the navigation bar from moving in and out on mobile phones if the site is larger than the viewport.

Contributing

Since I am not actively working on this component, I really appreciate any contribution.

Feel free to create issues for bugs and feature requests and I will see what I can do.

I also highly encourage you to open pull requests for bugfixes, updates and improvements.

react-jigsaw-puzzle's People

Contributors

yuri-becker avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

react-jigsaw-puzzle's Issues

tiles not always sticking to the right position

Hi! Does someone have a problem with the tiles not sticking exactly where the are supposed to be? In the screenshot provided, both of the tiles are considered as being at their correct position, but you will easily notice that one of them is not perfectly correct. Any clues?
image

InternalError Metro has encountered an error: Indeed, none of these files exist:

I just added this package to my project but it's returning this error upon running my application.

[Error: InternalError Metro has encountered an error: While trying to resolve module react-jigsaw-puzzle from file C:\Users\dell\Desktop\jigsaw\App.js, the package C:\Users\dell\Desktop\jigsaw\node_modules\react-jigsaw-puzzle\package.json was successfully found. However, this package itself specifies a main module field that could not be resolved (C:\Users\dell\Desktop\jigsaw\node_modules\react-jigsaw-puzzle\lib\src\index.js. Indeed, none of these files exist:

I checked this folder: node_modules\react-jigsaw-puzzle\lib\src\index.js and discovered that it does not exist.
Please I need help on how to resolve this issue.

Thank you in advance.

ResizeObserver loop completed with undelivered notifications error

Hi, I really like your library, but I'm facing a problem. When I ran your project locally, no errors appeared, but when I tried to integrate the library into my project I received an error. When resizing the browser window, the following errors are displayed in the console:

ResizeObserver loop completed with undelivered notifications.
at handleError (http://localhost:3001/static/js/bundle.js:349867:58)
at http://localhost:3001/static/js/bundle.js:349886:7.

Has anyone encountered something similar?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.