A React component for positioning elements mathematically based on plane bounds.
Install directly from the GitHub repository:
npm install github:lscherrer2/react-planeFor a specific version or tag (e.g., v1.0.0):
npm install github:lscherrer2/react-plane@v1.0.0For a specific branch or commit:
npm install github:lscherrer2/react-plane#branch-namePeer Dependencies
This library requires React and React DOM. Install them separately:
npm install react@^18.0.0 || ^19.0.0 react-dom@^18.0.0 || ^19.0.0Import the components and use them in your React app:
import React from 'react';
import { createRoot } from 'react-dom/client';
import { Plane, PlaneChild } from 'react-plane';
function App() {
return (
<div style={{ width: '100vw', height: '100vh' }}>
<Plane bounds={{ x: { min: 0, max: 100 }, y: { min: 0, max: 100 } }}>
<PlaneChild
position={{
method: 'center',
x: 50,
y: 50,
width: 20,
height: 20
}}
>
<div style={{ background: 'red', width: '100%', height: '100%' }} />
</PlaneChild>
</Plane>
</div>
);
}
createRoot(document.getElementById('root')!).render(<App />);- bounds: Define the mathematical plane (x/y ranges).
- position: Specify child coords in plane units (method: 'center' | 'top-left' etc.; width/height scale to pixels).
- Elements position and size based on container dimensions and bounds.
npm run build: Build the library (generatesdist/).npm run dev:demo: Run the examples demo in browser.npm run build:demo: Build static examples.
To contribute: Fork the repo, make changes, submit a PR.
- Build Fails on Install: Ensure Node.js >=18, run
npm run buildlocally if needed. - Import Errors: Verify peers installed; use ES modules for modern bundlers (Vite/Webpack).
- Types Not Found:
.d.tsfiles are auto-generated indist/.
MIT