quantum
Lowest-level React components for responsive, accessible, cross-platform app development
Last updated 4 years ago by michaelauderer .
ISC · Repository · Bugs · Original npm · Tarball · package.json
$ npm install quantum 
SYNC missed versions from official npm registry.

🔬 Quantum

quan·tum: any of the very small increments or parcels into which many forms of energy are subdivided

Quantum contains low-level components for building cross-platform applications in React and React Native. It aims to speed up development and allow for writing concise code.

Installation

npm install quantum@latest

Usage

import { Flex, Center, Text, Spacer, Circle, Input, QuantumProvider } from 'quantum'

const theme = {
  colors: {
    primary: '#448aff',
    secondary: '#1a1a1a'
  },
  fonts: {
    mono: 'Menlo, monospace'
  }
}

const App = () => (
  <QuantumProvider theme={theme}>
    <Flex p={8}>
      <Center w={64} h={32} p={8} bg="primary" radius={4}>
        <Text size={12} color="white">
          Testing
        </Text>
      </Center>
      <Spacer h={32} />
      <Flex dir="row">
        <Circle bg="primary" />
        <Spacer w={8} />
        <Input placeholder="test" color="secondary" fontFamily="mono" />
      </Flex>
    </Flex>
  </QuantumProvider>
)

Base Props

All Quantum components inherit the following base props: (aliases displayed in parenthesis)

  • display
  • flex
  • alignSelf
  • justifySelf
  • width (w)
  • height (h)
  • maxWidth (maxW)
  • maxHeight (maxH)
  • position (pos)
  • top (t)
  • right (r)
  • bottom (b)
  • left (l)
  • margin (m)
  • marginTop (mt)
  • marginRight (mr)
  • marginBottom (mb)
  • marginLeft (ml)
  • marginHorizontal (mx)
  • marginVertical (my)
  • padding (p)
  • paddingTop (pt)
  • paddingRight (pr)
  • paddingBottom (pb)
  • paddingLeft (pl)
  • paddingHorizontal (px)
  • paddingVertical (py)
  • color
  • background (bg)
  • backgroundColor (bgColor)
  • border
  • borderColor
  • borderRadius (radius)
  • boxShadow (shadow)
  • lineHeight
  • characterSpacing (charSpacing)

Components

<Box />

The most basic component; essentially a standard div.

<Box></Box>

Defaults:

{
  display: 'block'
}

Additional props/aliases: None

<Flex />

A basic box with flexbox styling.

<Flex dir="column" align="center" justify="space-between"></Flex>

Defaults:

{
  display: 'flex'
}

Additional props/aliases:

  • flexDirection (dir)
  • alignItems (align)
  • justifyContent (justify)

<Center />

A flexbox with defaults for aligning and justifying center.

<Center>
  <Text>I'm centered!</Text>
</Center>

Defaults:

{
  display: 'flex',
  alignItems: 'center',
  justifyContent: 'center'
}

Additional props/aliases:

  • flexDirection (dir)
  • alignItems (align)
  • justifyContent (justify)

Theming

Quantum provides theming support out of the box, through React Context.

First, create a theme file like so:

// theme.js
export default {
  colors: {
    text: '#1a1a1a',
    background: '#fff',
    primary: '#07c',
    secondary: '#05a',
    accent: '#609',
    muted: '#f6f6f6',
  },
  fonts: {
    body: 'system-ui, sans-serif',
    heading: 'system-ui, sans-serif',
    monospace: 'Menlo, monospace',
  },
  fontWeights: {
    body: 400,
    heading: 700,
    bold: 700,
  },
  lineHeights: {
    body: 1.5,
    heading: 1.125,
  },
}

Next, import QuantumProvider from Quantum, along with your theme, high up in your application:

// App.jsx
import { QuantumProvider } from 'quantum'
import theme from './theme' // the theme file you created

export default function App() {
  return (
    <QuantumProvider theme={theme}>
      // The rest of your app
    </QuantumProvider>
  )
}

To use theme values in Quantum components, just use the theme item name as a style value:

<Box bg="primary">
  <Text family="body" color="secondary" weight="heading">
    Hello Quantum!
  </Text>
</Box>

You can also access the theme object directly with the useTheme hook:

import { useTheme } from 'quantum'

export default function MyComponent() {
  const theme = useTheme()

  console.log(theme)

  return (
    <Box color={theme.colors.primary} />
  )
}

Responsiveness

Quantum adds support for responsive styling out of the box. First, make sure your theme (see Theming) has a "breakpoints" array, like so:

export default {
  breakpoints: [640, 832, 1024],
  colors: {
    // .....

With breakpoints defined in the theme, you can now pass arrays as values to style props. The value displayed will match the index of the breakpoints array based on screen size.

// 64px on <640px screens,
// 128px on <832px screens,
// 256px on <1024px screens,
// 512px on >=1024px screens
<Box w={[64, 128, 256, 512]}>

Current Tags

  • 1.0.0-alpha.12                                ...           latest (4 years ago)

22 Versions

  • 1.0.0-alpha.12                                ...           4 years ago
  • 1.0.0-alpha.11                                ...           4 years ago
  • 1.0.0-alpha.10                                ...           4 years ago
  • 1.0.0-alpha.9                                ...           4 years ago
  • 1.0.0-alpha.8                                ...           4 years ago
  • 1.0.0-alpha.7                                ...           4 years ago
  • 1.0.0-alpha.6                                ...           4 years ago
  • 1.0.0-alpha.5                                ...           4 years ago
  • 0.4.0                                ...           12 years ago
  • 0.3.1                                ...           12 years ago
  • 0.3.0                                ...           12 years ago
  • 0.2.2                                ...           12 years ago
  • 0.2.1                                ...           12 years ago
  • 0.2.0                                ...           12 years ago
  • 0.1.7                                ...           12 years ago
  • 0.1.6                                ...           12 years ago
  • 0.1.5                                ...           12 years ago
  • 0.1.4                                ...           12 years ago
  • 0.1.3                                ...           13 years ago
  • 0.1.2                                ...           13 years ago
  • 0.1.1                                ...           13 years ago
  • 0.1.0                                ...           13 years ago
Maintainers (1)
Downloads
Total 15
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (1)
Dev Dependencies (4)
Dependents (1)

© 2010 - cnpmjs.org x YWFE | Home | YWFE