0.1.15 • Published 8 months ago

react-css-breakpoints v0.1.15

Weekly downloads
-
License
MIT
Repository
github
Last release
8 months ago

React CSS Breakpoints

Component style breakpoints so that you won't have to create custom components to handle responsive design.

This package uses css as breakpoints for components instead of using media queries via react hooks. This is to avoid unnecessary re-renders of components and to avoid the milliseconds of delay when using media queries.

Basis

This package is based on the breakpoints of Tailwind CSS.

  • sm: 640px
  • md: 768px
  • lg: 1024px
  • xl: 1280px
  • 2xl: 1536px

Note that this package doesn't use Tailwind's CSS declaration and contains its own media queries copies almost exactly from the tailwind css declarations.

Functions

export interface BreakpointProps extends PropsWithChildren<HTMLAttributes<HTMLDivElement>> {
  start?: 'sm' | 'md' | 'lg' | 'xl' | '2xl' | '';
  end?: 'sm' | 'md' | 'lg' | 'xl' | '2xl' | '';
  children?: React.ReactNode | React.ReactNode[];
}

Sample

Demo GIF

Import first the css of the module

// _app.tsx
import 'react-css-breakpoints/dist/index.css';
// index.tsx
import { Breakpoint } from 'react-css-breakpoints';

const app = () => {
  return (
    <div>
      <Breakpoint start="sm" end="sm">
        <p>Only on mobile</p>
      </Breakpoint>

      <Breakpoint start="md" end="md">
        <p>Only on tablet</p>
      </Breakpoint>

      <Breakpoint start="lg" end="lg">
        <p>Only on laptop</p>
      </Breakpoint>

      <Breakpoint start="xl" end="xl">
        <p>Only on desktop</p>
      </Breakpoint>

      <Breakpoint start="2xl" end="2xl">
        <p>Only on 2xl</p>
      </Breakpoint>

      <br />

      <Breakpoint start="sm">
        <p>On mobile and up</p>
      </Breakpoint>

      <Breakpoint start="md">
        <p>On tablet and up</p>
      </Breakpoint>

      <Breakpoint start="lg">
        <p>On laptop and up</p>
      </Breakpoint>

      <Breakpoint start="xl">
        <p>On desktop and up</p>
      </Breakpoint>

      <Breakpoint start="2xl">
        <p>On 2xl and up</p>
      </Breakpoint>
    </div>
  );
};

License

MIT license, Copyright (c) Leo Mark Castro. For more information see LICENSE.

0.1.15

8 months ago

0.1.14

8 months ago

0.1.13

8 months ago

0.1.12

8 months ago

0.1.11

8 months ago

0.1.7

8 months ago

0.1.6

8 months ago

0.1.5

8 months ago

0.1.3

8 months ago

0.1.2

8 months ago

0.1.0

8 months ago