npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@designedhead/react-focus-point

v0.1.8

Published

A React component for setting focal points on images for responsive cropping

Downloads

32

Readme

React Focus Point

React Focus Point Demo

A React component that helps maintain the focus point of images across different viewport sizes and aspect ratios. Perfect for ensuring that important elements within your images remain centered and visible regardless of how the image is cropped or resized.

Features

  • 🎯 Maintain image focus points across different viewport sizes
  • 📱 Responsive and mobile-friendly
  • ⚡ Lightweight and performant
  • 🎨 Customizable focus point positioning
  • 🔄 Smooth transitions during resizing
  • 🎮 Interactive focus point selection
  • 🖌️ Customizable focus point indicator styling

Installation

npm install react-focus-point
# or
yarn add react-focus-point

Usage

import { FocusPoint } from 'react-focus-point';
import { useState } from 'react';

function App() {
  const [focusPoint, setFocusPoint] = useState({
    x: 50, // Percentage from left (0-100)
    y: 50 // Percentage from top (0-100)
  });

  const handleFocusChange = (focusX, focusY) => {
    setFocusPoint({ x: focusX, y: focusY });
    console.log(`Focus point changed to: X: ${focusX}%, Y: ${focusY}%`);
  };

  return (
    <FocusPoint
      src='path/to/your/image.jpg'
      focusX={focusPoint.x}
      focusY={focusPoint.y}
      alt='Description of image'
      onChange={handleFocusChange}
    />
  );
}

Props

| Prop | Type | Default | Description | | -------------------- | -------------------- | -------- | ----------------------------------------------------- | | src | string | required | Source URL of the image | | focusX | number | 50 | X coordinate of focus point (0-100) | | focusY | number | 50 | Y coordinate of focus point (0-100) | | alt | string | '' | Alt text for the image | | className | string | '' | Additional CSS classes | | style | object | {} | Additional inline styles | | onChange | function | - | Callback when focus point changes (x, y) => {} | | indicatorSize | 'sm' | 'md' | 'lg' | 'md' | Size of the focus point indicator | | indicatorClassName | string | - | Custom Tailwind classes for the focus point indicator |

Examples

Basic Usage with Focus Point Tracking

<FocusPoint
  src='/images/hero.jpg'
  focusX={30} // 30% from the left
  focusY={70} // 70% from the top
  alt='Hero image'
  onChange={(x, y) => {
    // Store focus point in state or database
    console.log(`New focus point: ${x}%, ${y}%`);
  }}
/>

With Custom Styling and Focus Point Management

function ImageEditor() {
  const [focusPoint, setFocusPoint] = useState({ x: 50, y: 50 });

  return (
    <FocusPoint
      src='/images/hero.jpg'
      focusX={focusPoint.x}
      focusY={focusPoint.y}
      alt='Hero image'
      className='my-custom-class'
      style={{ maxHeight: '500px' }}
      onChange={(x, y) => setFocusPoint({ x, y })}
    />
  );
}

Customizing the Focus Point Indicator

You can customize the appearance of the focus point indicator using Tailwind classes:

<FocusPoint
  src='/images/hero.jpg'
  focusX={50}
  focusY={50}
  alt='Hero image'
  indicatorClassName='bg-red-500/50 border-yellow-400 border-3 shadow-lg'
  onChange={(x, y) => console.log(`New focus point: ${x}%, ${y}%`)}
/>

You can also change the size of the indicator using the indicatorSize prop:

<FocusPoint
  src='/images/hero.jpg'
  focusX={50}
  focusY={50}
  alt='Hero image'
  indicatorSize='lg' // Options: 'sm', 'md', 'lg'
  onChange={(x, y) => console.log(`New focus point: ${x}%, ${y}%`)}
/>

Storing and Applying Focus Points

Once you've captured the focus points for your images, you can store them in your database or state management system and apply them to any image component. Here's how you can use the focus points with a regular image:

// Example of storing focus points in a database
const saveFocusPoint = async (imageId, focusPoint) => {
  await db.images.update(imageId, {
    focusPoint: {
      x: focusPoint.x, // Already a percentage (0-100)
      y: focusPoint.y
    }
  });
};

// Example of applying focus points to an image
function ImageWithFocus({ image, ...props }) {
  const [error, setError] = useState(false);

  return (
    <img
      onError={() => setError(true)}
      {...props}
      alt={props.alt || ''}
      style={{
        ...(props.style || {}),
        objectFit: 'cover',
        ...(image?.focusPoint?.x && {
          objectPosition: `${image.focusPoint.x}% ${image.focusPoint.y}%`
        })
      }}
    />
  );
}

// Usage example
function Gallery() {
  const [images, setImages] = useState([]);

  return (
    <div className='gallery'>
      {images.map(image => (
        <ImageWithFocus
          key={image.id}
          image={image}
          src={image.url}
          alt={image.alt}
          style={{ width: '100%', height: '300px' }}
        />
      ))}
    </div>
  );
}

This approach allows you to:

  1. Store focus points alongside your image metadata
  2. Apply the same focus points consistently across different viewport sizes
  3. Maintain the visual integrity of your images in responsive layouts
  4. Create a consistent cropping experience across your application

How It Works

React Focus Point uses CSS object-fit and object-position properties to maintain the focus point of your images. When the viewport size changes, the component automatically adjusts the image position to keep your specified focus point centered. The onChange handler allows you to track and persist these focus points for consistent image cropping across different viewport sizes.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

MIT © Rafael Mendes