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

milligram-js

v0.1.0

Published

css-in-js port of milligram.io

Downloads

3

Readme

milligram-js

milligram-js.now.sh

Css-in-js port of milligram.io.

Because Sass is cool and css-in-js is cool, but mixing those technologies in tiny projects is an overkill.

Overview

! alpha stage - ok for quick demos :)

  • no dependencies, lightweight, tree-shakeable
  • fully tested 1:1 style parity with milligram
  • nice system for extending theme and component styles
  • created with emotion in mind but should work with most css-in-js (or can be used to generate static css sheet)

Usage

// styles are function of theme
type Styles = (theme: Theme) => string

Exports

// all global styles
import { milligramStyles } from 'milligram-js'

// `componentStyles`
// styles with selector/class e.g. `button { color: red; }`
import { buttonStyles } from 'milligram-js'

// `componentBase`
// styles without selector/class e.g. `color: red`
import { buttonBase } from 'milligram-js'

// `component`
// all styles and variants
import { button } from 'milligram-js'

const {
  base,
  styles,
  variant: { active },
} = button

// css tag helper for syntax highlighting
import { css } from 'milligram-js'

const styles: string = css`
  color: red;
`

Global

import {
  milligramStyles,
  buttonStyles,
  typographyStyles,
  baseStyles,
  bodyStyles,
} from 'milligram-js'

// use all styles
const globalStyles = milligramStyles(theme)

// or just selected few
const selectedGlobalStyles = css`
  ${baseStyles()}
  ${bodyStyles()}
  ${buttonStyles()}
`

Scoped with react & emotion

import { button } from 'milligram-js'
import styled from '@emotion/styled'
import { css } from '@emotion/core'

const StyledButton = styled.button(
  ({ theme }) => css`
    ${button.base(theme)}
    /* add more styles */
  `,
)

export const MyComponent: React.FC = () => {
  const theme = useTheme()

  const styles = css`
    ${button.styles(theme)}
    /* add more styles */
  `

  return (
    <>
      <div css={styles}>
        <button>Styles</button>
      </div>

      <button css={button.base(theme)}>Base</button>

      <StyledButton>Styled Component</button>
    </>
  )
}

// or even simpler with emotion css props
// css={(theme) => styles}
export const MyComponent: React.FC = () => {
  return (
    <>
      <div css={button.styles}>
        <button>Styles</button>
      </div>

      <button css={button.base}>Base</button>
    </>
  )
}

Theming

Dynamic theming is main advantage over sass :)

import { theme, css } from 'milligram-js'

const defaultTheme = theme

// `createTheme` will deep merge customizations with defaultTheme
const customTheme = createTheme({
  color: {
    // default variables
    primary: 'hotpink',
    // add custom ones
    extra: 'red',
  },
})

Extend

Instead of adding custom styles traditionally - you can use theme.extend.

It allows for customizations without thinking too long about specific selectors.

import { createTheme, extendTheme, css } from 'milligram-js'

// extend element styles with in `extend` key
const customTheme = createTheme({
  color: { background: 'yellow' },
  extend: {
    header: css`
      font-size: 10rem;
    `
  }
})

// or with extendTheme helper
const extendedTheme = extendTheme(customTheme, {
  // `t` will be typed with your custom theme
  paragraph: (t) =>
    css`
      color: ${t.color.background};
    `,
 }
})