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 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-clickable-post-wrapper

v1.1.0

Published

React Post Wrapper is a flexible and versatile npm package that allows you to wrap any post element within an interactive container. The container, when clicked, navigates to a designated URL while also allowing for any links inside the wrapper to be clic

Downloads

34

Readme

React Clickable Post Wrapper

React Clickable Post Wrapper is a flexible and versatile npm package that allows you to wrap any post element within an interactive container. The container, when clicked, navigates to a designated URL while also allowing for any links inside the wrapper to be clickable. Furthermore, it provides the ability to select text within the wrapper without triggering the link redirection.

This component is ideal for developers seeking to increase interactivity and user experience in their React applications, particularly in scenarios where posts or feed items are used.

hackernoon article about creating this component https://hackernoon.com/building-a-post-component-with-links-onclick-handling-text-selection-and-clickability-anywhere

Features

  1. Flexible and versatile: Wrap any post element within an interactive container, providing enhanced functionality.
  2. Clickable links: Navigate to a designated URL when the container is clicked, using the link prop.
  3. Child elements: Render child elements within the wrapper for seamless integration with your content.
  4. Customizable styling: Apply custom CSS classes using the className prop to match your project's styling.
  5. Target options: Define the target window for the link using the target prop (_blank, _self, _parent, _top).
  6. Advanced event handling: Intelligently handle click events to avoid triggering link navigation in specific scenarios.
  7. Efficient event management: Use useRef and useEffect hooks for efficient event listener management.
  8. TypeScript support: Written in TypeScript for type safety and improved developer experience.

These features make the React Clickable Post Wrapper a powerful tool for creating interactive and clickable post elements within your React applications. It provides enhanced control over link behavior while maintaining a user-friendly and customizable interface.

Demo

https://codesandbox.io/p/sandbox/gifted-http-wlh3yg?welcome=true

Installation

npm install react-clickable-post-wrapper

Usage

Here is an example of how you can use the React Clickable Post Wrapper component:

import React from "react";
import PostWrapper from "react-clickable-post-wrapper";

const MyComponent = () => {
  return (
    <PostWrapper
      className="post-wrapper"
      link="https://example.com"
      target="_blank"
      onClick={(event) => {
        console.log("Clicked!", event);
      }}
    >
      <div>
        <h1>My Post</h1>
        <p>This is the content of my post.</p>
        <a href="https://inner-link-example.com">This is a link inside your post</a>
        <button onClick={() => console.log("Button clicked!")}>
          Click me
        </button>
      </div>
    </PostWrapper>
  );
};

export default MyComponent;

Props

The PostWrapper component accepts the following props:

  1. className (optional): A string representing the CSS class name for the wrapper container.
  2. children (optional): React nodes to be wrapped inside the container.
  3. link (optional): The URL to navigate to when the container is clicked.
  4. target (optional): The target attribute for the link. Can be one of "_blank", "_self", "_parent", or "_top". Default is "_self".
  5. onClick (optional): A function that will be called when the container is clicked. It receives the MouseEvent object as an argument.

Note: If both onClick and individual click handlers are defined on child elements, the onClick prop takes precedence and prevents the default link navigation when handled.

License

React Clickable Post Wrapper is released under the MIT License.