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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@mujo/box

v5.0.2

Published

A React utility to add a style guide to primative components

Downloads

40

Readme

Box

This is a common component in React style guides like gestalt. It gives a general primitive component that you can pass a bunch of css props to it. What makes this version of box different then other implementations is the ability to extend the box without modifying the core code. Box is a single element component meaning that the box component is very flexible with its implementation.

Technology

You will need to install these packages since they are peerDependencies.

Install

npm install @mujo/box --save

and if you do not have React or emotion.

npm install react emotion --save

Usage

Using the exported Box

The out of the box Box component, is very limited. It currently only supports a handful of flex properties. The expectation you will want to extend Box right away.

import { Box } from '@mujo/box'

export const MyComponent = () => (
  <Box display="flex" flex={0} flexWrap="nowrap">
    A Box with some flex
  </Box>
)

Boxes built in props

Box has only a few props that the internal component cares about: Component, and css. These two props allow you to "on the fly" change out styles, and functionality of the component.

<Box Component="a" href="/foo" css={{ textDecoration: 'underline' }}>
  Go to foo
</Box>

Component can take a string for built in components in react-dom or custom components. This functionality allows for things like usage of Box with react-native (see more in extending the box).

css is a css object that contains any css properties that you would like to apply to component.

Extending the Box

Box is implemented in a way to be able to easily make variants of Box using the withBox higher order component. You can pass in a style guide into the withBox function, and also a default component. This allows the Box component to be transformed into a primitive component that exposes props of your style guide.

import { withBox } from '@mujo/box'

const Box = withBox({
  styleGuide: {
    foo: {
      bar: { color: 'red' },
      baz: { color: 'blue' },
    },
  },
  defaultComponent: 'span',
})

export const MyComponent = () => (
  <>
    <Box foo="bar">Some red text</Box>
    <Box foo="baz">Some blue text</Box>
  </>
)

Typescript support

Box is also written in Typescript so we are able to add those props in a ways that makes it pretty easy to see the type hinting for each prop.

const styleGuide = {
  foo: {
    bar: { color: 'red' },
    baz: { color: 'blue' },
  },
}
const Box = withBox<typeof styleGuide>({
  styleGuide,
  defaultComponent: 'div',
})

In this example here would be what the props of the component looks like.

interface BoxProps extends ExistingProps {
  foo: 'bar' | 'baz'
}
// ExistingProps are HTMLElement props, Component prop, and css prop.

Extending for React Native

Box supports react native but only if you extend it to pass in react native primitives.

import { View } from 'react-native'

const Box = withBox({
  styleGuide: {
    foo: {
      bar: { color: 'red' },
      baz: { color: 'blue' },
    },
  },
  defaultComponent: View,
})

Building a style guide

A style guide should be rigid enough to support a teams need for consistency and also flexible enough that designs do not want to exit the system. For this reason the boxes style guide implementation is just JSON with some CSS properties.

interface StyleGuide {
  [propName: string]: {
    [propValue: string]: CSSObject
  }
}

Note: please do not type your style guide or it will break inference.

Colors example

Your team has a couple colors you want to use. Box can make it easy for the team to apply those colors to a component.

const styleGuide = {
  color: {
    red: { color: '#ED6173' },
    blue: { color: '#6761ED' },
  },
  backgroundColor: {
    red: { backgroundColor: '#ED6173' },
    blue: { backgroundColor: '#6761ED' },
  },
}

const Box = withBox({
  styleGuide,
  defaultComponent: 'div',
})

<Box color="red" backgroundColor="blue">My text is #ED6173</Box>
Using makeStyles

We also expose a utility called makeStyles to stream line this.

import { makeStyles } from '@mujo/box'

const colors = {
  red: '#ED6173',
  blue: '#6761ED',
}
const styleGuide = {
  color: makeStyles('color', colors),
  backgroundColor: makeStyles('backgroundColor', colors),
}
// its still type safe!
Extending existing flex styles

We will be supporting more styles in the future, and potentially even some themes. To be able to reuse some of the current built in styles you can just spread them into your custom styles.

import { flexStyles } from '@mujo/box'

const styleGuide = {
  ...myCustomStyles,
  ...flexStyles,
}