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

@qc/react-block

v0.2.2

Published

A React component that renders a div with the semantics of representing a block structure or region.

Downloads

6

Readme

@qc/react-block

Build Status Coverage Status License Downloads

npm badge

A React component that renders a div with the semantics of representing a block structure or region.

A div is a block-level element but by default it does not create a block formatting context (BFC). Certain CSS properties can be applied to elements to give it a BFC. Some of the methods are listed below.

  1. Block elements where overflow has a value other than visible.
  2. Elements with contain set to layout, content, or strict.
  3. Elements with display's inside value set to flow-root.

A BFC provides the following benefits, among others:

  • Prevents top and bottom margin bleedthrough.
  • Lets the background fill the entire area behind an element's content.

See this Block Formatting Context for Block-Level Elements Codepen to see BFC in action.

Note: Included with the BFC CSS is box-sizing: border-box since this is the box-sizing most sensible for a block.

One of the most common use cases is to use Block as the root of a custom React component or as representing different regions within a component. See the examples below.

Installation

npm install --save @qc/react-block

or

yarn add @qc/react-block

Example Usage

As the Root

import React from 'react'

import Block from '@qc/react-block'

import '@qc/react-block/dist/styles/Block.css'


export default function MyBlockComponent(props) {
  return (
    <Block className="My" style={{ backgroundColor: '#bedfed' }}>
      <h1>My Block Component</h1>
      {/*
      Note: The margins of the `h1` and `p` won't bleed-through
      like they would with default styled `div`s.  Also, the
      background color will fill the area behind the margins.
      */}
      <p>My component demo'ing the Block component.</p>
    </Block>
  )
}

Component Regions

import React from 'react'

import Block from '@qc/react-block'

import '@qc/react-block/dist/styles/Block.css'


export default function Panel(props) {
  return (
    <Block className="Panel">
      <Block className="Panel-Head">
        <Title>Panel's Title</Title>
      </Block>
      <Block className="Panel-Body">
        <h1>...</h1>
        <p>...</p>
        <h2>...</h2>
        <p>...</p>
      </Block>
      <Block className="Panel-Foot">
        <button>...</button>
      </Block>
    </Block>
  )
}

Custom Component Type

divs are not the only element supported. Any one of the following elements may be used by setting the compType property.

  • address
  • article
  • aside
  • blockquote
  • details
  • div
  • dl
  • fieldset
  • figcaption
  • figure
  • footer
  • form
  • header
  • main
  • nav
  • section
import React from 'react'

import Block from '@qc/react-block'

import '@qc/react-block/dist/styles/Block.css'


export default function SiteFooter(props) {
  return (
    <Block compType="footer">
      ...
    </Block>
  )
}

Just Using Block CSS

The key to the Block component is in the CSS — not the JavaScript. All that needs to be done is to include the Block CSS class in any component.

import React from 'react'

import '@qc/react-block/dist/styles/Block.css'


export default function SiteFooter(props) {
  return (
    <footer className="Block">
      ...
    </footer>
  )
}

Excluding replaced elements.

Use ES Modules

This package also comes with the source and an ES variation. Instead of

import Block from '@qc/react-block'

use

import Block from '@qc/react-block/es/Block'

or

import Block from '@qc/react-block/src/Block'

to import the component.

If you do this, then you will need to be sure to transpile the code to a syntax compatible with the browsers you plan to support.

The source is using object spread syntax. In order to transpile it with babel, you must include the object spread transform plugin.

Why Multiple BFC Methods?

Why are multiple BFC methods employed in the included CSS?

This is to help ensure the block is still given a BFC if in the event that the CSS is overridden in a way that would have removed the BFC. For instance, in browsers that support contain: layout or display: flow-root, the following will still have a BFC.

<Block style={{overflow: 'visible'}}>
  ...
</Block>

Other Packages from QC

Maintainers

License

ISC