Code Monkey home page Code Monkey logo

pop's Introduction

Popup Component for React

A versatile and reusable React component for displaying contextual information or actions triggered by user interactions, such as clicks or hovers. This component is ideal for tooltips, dropdowns, and other similar UI patterns.

Components

The Popup module includes three main components:

  1. Popup: The main container that manages visibility and positioning.
  2. PopupContent: The content container that adjusts its position based on available space and user-defined preferences.
  3. PopupHandle: The trigger element that initiates the popup display.

Usage

Popup Component

Props

action (optional):

Specifies the trigger action ('click' or 'hover'). Default is 'hover'.

children:

A ReactNode or a function that returns a ReactNode. If a function, it receives an object with a close method to programmatically close the popup. className (optional): Additional CSS classes for custom styling. Example

import { Popup, PopupContent, PopupHandle } from '@your-org/popup-component';

function App() {
  return (
    <div className="app">
      <Popup action="click" className="custom-popup">
        {({ close }) => (
          <>
            <PopupHandle>
              <button>Click Me</button>
            </PopupHandle>
            <PopupContent position="below">
              <div>
                <p>This is the popup content.</p>
                <button onClick={close}>Close</button>
              </div>
            </PopupContent>
          </>
        )}
      </Popup>
    </div>
  );
}

export default App;

PopupContent Component

Props

position (optional):

Defines the preferred position ('above' or 'below') of the content relative to the handle. children: The content to be displayed inside the popup.

Example

<PopupContent position="below">
  <div>
    <p>This is dynamically positioned content.</p>
  </div>
</PopupContent>

PopupHandle Component

Props

children: The interactive element (e.g., button) that triggers the popup.

Example

<PopupHandle>
  <button>Hover or Click Me</button>
</PopupHandle>


<PopupHandle>
  <button>Hover or Click Me</button>
</PopupHandle>

Technical Considerations

Dynamic Positioning:

The component ensures the popup content stays within the viewport by calculating the optimal left position based on the handle's position and the content's width.

Event Handling:

The component distinguishes between click and hover actions using conditional event handlers, ensuring appropriate behavior for different interaction types.

Focus Management:

By handling onBlur and onFocus events, the popup remains open when interacting with its children, enhancing accessibility and user experience.

Contributing

We welcome contributions to improve this component. Please open an issue or submit a pull request on GitHub.

License

This project is licensed under the MIT License. See the LICENSE file for details.

pop's People

Contributors

monijaman avatar

Watchers

 avatar

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.