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

create-typestyle

v1.0.4-2.2

Published

creates a boxed, independent instance of typestyle

Downloads

2

Readme

create-typeStyle

creates a boxed, independent instance of typestyle, with some additional goodies. This is useful if you need to create typestyles on the fly, or in different context simultaneously.

createTypeStyle also embeds csx, so there's no need to add it to your dependencies; it also duplicates some of the basic functionality offered by cssTips

It makes creating styles and working with both React and Typestyle a little bit nicer, at the price of some boilerplate written once per project

Quick Example

import { createTypeStyle } from '../createtypestyle' 
import * as React from 'react'
import { render } from 'react-dom'

const { 
  cssRule, 
  cssRaw,
  style,
  prepare,
  googleFont, 
  setupMount
} = createTypeStyle(React.createElement) // you can pass also Preact, Inferno, etc 

// creates a function that will serve to 
// mount the react element and the style later
const mount = setupMount(render)

// normalizes and sets best practices for
// the main style, with optional additional css
prepare('root', { fontSize:px(10) })

// adds a google font
googleFont('Montserrat:600|Lora:400')

const appClassName = style({ textAlign: "center" })

export const App = () =>
  <div className={appClassName}>
    <h2>Start editing to see some magic happen {"\u2728"}</h2>
  </div>

// mounts the app in the element with id 'root'
// and the style in the element with id 'style'
mount(App, 'root', 'style')

You'll find a demo in the src/demo directory

Check a live demo on codesandbox

Usage

npm install --save create-typestyle

then create a boxed typestyle:

import { createTypeStyle } from 'create-typestyle'
const { 
  cssRule,
  cssRaw,
  style,
  keyframes,
  getStyles,
  setStylesTarget,
  setupPage,
  normalize,
  prepare,
  mergeStyles,
  googleFont,
  mount, // only if you pass React.createElement
  makeComponent // only if you pass React.createElement
} = createTypeStyle()

Then use those functions exactly as you would when using regular typestyle.

create-typestyle exports everything typestyle and csx export.

Here's the complete list:

import {
  // typestyle exports
  // if you're using create-typestyle, you probably
  // don't want to use those, but they are here
  createTypeStyle,
  media,
  // csx exports
  color,
  hsl,
  hsla,
  rgb,
  rgba,
  spin,
  em,
  percent,
  px,
  rad,
  rem,
  viewHeight,
  viewWidth,
  turn,
  important,
  quote,
  url,
  red, green, blue, white//, ...other colors
} from 'create-typestyle'

API

For regular typestyle functions, check out the official doc.

All of them are included as methods of the object returned by createTypeStyle().

The complete list of methods:

const {
  // regular typestyle methods:
  cssRule,
  cssRaw,
  style,
  keyframes,
  getStyles,
  setStylesTarget,
  // additional (taken from cssTips):
  setupPage,
  normalize,
  // create-typestyle exclusive:
  prepare,
  mergeStyles,
  googleFont,
  // for usage with React/Preact/Inferno and other React-compatible libraries
  mount,
  makeComponent
} = createTypeStyle()

create-typestyle specific methods include:

setupPage

(selector: string, style?: {}) => true

Recommended Page setup, taken straight from cssTips

  • Sets up the body to be full size
  • Sets up box sizing to be border box

rootSelector The main wrapper for the whole page additionalStyle any additional global style you want to apply (e.g, fonts)

const { setupPage } = createStyle();
setupPage('root',{fontSize:'10px'})

normalize

(prefix?:string) => true

Adds the rules from the normalize stylesheet Optionally, you may include a prefix to namespace all the adjustments

const { normalize } = createStyle();
normalize('root')

prepare

(selector: string, style?: {}) => true

Just a shortcut to run both setupPage and normalize

googleFont

(font:string) => true

adds an @import rule for a specified google font

const { googleFont } = createStyle();
googleFont('Montserrat:600|Lora:400');

mount

(render:Function) => (ReactElement,root_id,style_id) => true

Mounts a react app and their styles

import React from 'react';
import ReactDOM from  'react-dom';
// provided the App is to be in an element <div id='root'/>
// and the styles in a style element <style id='styles'/>
// You must pass a `React.createElement`-compatible function to `createStyle`
const { mount } = createStyle(React.createElement);
mount(ReactDOM.render)(App,'root','styles');

makeComponent

(tagName:string) => (style:object) => Component

Very simple styled component kinda thing.

import React from 'react'
// must pass a React.createElement-compatible function
const {makeComponent} = createTypeStyle(React.createElement)
const Div = makeComponent('div')
const El = Div({color:'red'})
// use it:
<El>some text</El>

note: calling makeComponent("div") a second time will return the same instance, so there's no need for an intermediary variable

License

MIT