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

yzhan-react-responsive-content

v1.0.1

Published

A React component for creating responsive content with automatic media query generation

Downloads

12

Readme

yzhan-react-responsive-content

npm npm bundle size npm GitHub license ie10+

A powerful and flexible React component for creating responsive content with automatic media query generation.
为响应式内容自动生成媒体查询.

Demo

GIF animation
Demo Link

Features

  • Server-side rendering: Works out of the box with SSR, no client-side rendering required.
  • Flexible content definition: Accept a set prop similar to srcSet, allowing you to define content for different breakpoints easily.
  • Versatile content types: Supports various content types including strings, HTML tags, React components, null values, and even lists of React nodes.
  • Performance optimized: Uses pure CSS for control, automatically generating and removing media queries without global CSS pollution.
  • Customizable display property: Set the display property to match your layout needs (block, flex, grid, inline, inline-block, etc.).
  • SEO-friendly: Allows web crawlers to index content for both desktop and mobile versions simultaneously.
  • Smart wrapper handling: Reuses existing wrapper layers when present, avoiding unnecessary DOM nesting and preserving existing style selectors.

Installation

Install the package using npm:

npm install yzhan-react-responsive-content

Or using yarn:

yarn add yzhan-react-responsive-content

Usage

Here's a basic example of how to use the ResponsiveContent component:

import ResponsiveContent from "yzhan-react-responsive-content";

function MyComponent() {
  return (
    <ResponsiveContent
      set={[
        ["Mobile Content", 320],
        ["Tablet Content", 768],
        ["Desktop Content"],
      ]}
      display="block"
    />
  );
}

In this example:

  • Content will display as follows:
    • 'Mobile Content' for screen widths up to 320px
    • 'Tablet Content' for screen widths between 321px and 768px
    • 'Desktop Content' for screen widths above 768px

Advanced Usage

You can use more complex content types, including React components. When using React components or elements, remember to provide a unique key prop to each one:

import ResponsiveContent from "yzhan-react-responsive-content";

function MyComponent() {
  return (
    <ResponsiveContent
      set={[
        [
          <MobileLayout key="mobile">Mobile specific content</MobileLayout>,
          320,
        ],
        [<TabletLayout key="tablet">Tablet optimized view</TabletLayout>, 768],
        [
          <React.Fragment key="desktop">
            <DesktopHeader />
            <DesktopContent />
            <DesktopFooter />
          </React.Fragment>,
        ],
      ]}
      display="flex"
    />
  );
}

Note: When using React components or elements in the set prop, always provide a unique key prop to each one. This helps React efficiently update and re-render the content.

API

Props

  • set: Array<[ReactNode | null, number?]>: An array of tuples. Each tuple contains the content to display and an optional breakpoint width. When using React components or elements as content, remember to provide a unique key prop to each one.
  • display?: 'block' | 'flex' | 'grid' | 'inline' | 'inline-block': The CSS display property to use for the content. Defaults to 'block'.

Contributing

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

License

This project is licensed under the MIT License.