How to use styletron - 4 common examples

To help you get started, we’ve selected a few styletron examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jxnblk / axs / src / cx.js View on Github external
// import StyletronClient from 'styletron/lib/client'
import addPx from 'add-px-to-style'

// Remove
import { createRenderer } from 'fela'
export const renderer = createRenderer()

const styletronOptions = {
  prefix: '_axs-'
}
const isClient = typeof document !== 'undefined'
const styleTags = isClient ? document.getElementsByTagName('style') : null

// export const styletron = isClient ? new StyletronClient(styleTags, styletronOptions) : new Styletron(styletronOptions)

export const styletron = new Styletron(styletronOptions)

export const cx = (styles) => {
  const sx = formatStyles(styles)

  return injectStyle(styletron, sx)

  // return renderer.renderRule(() => sx)
}

const formatStyles = (styles) => {
  const formatted = toArr(styles)
    .map(style => {
      if (typeof style.value !== 'number') {
        return style
      }
      return ({
github egoist / styletron-vue / example / index.js View on Github external
background: 'red'
  }
})

const StyledAnchor = styled('a', {
  color: 'pink'
})

const App = {
  name: 'app',
  data() {
    return {
      fontSize: 12
    }
  },
  styletron: new Styletron(),
  provide: {
    theme: 'green'
  },
  methods: {
    handleFontSize(e) {
      this.fontSize = e.target.value
    }
  },
  render() {
    return (
      <div>
        
        <label>
          Font Size:{' '}
          </label></div>
github styletron / styletron / packages / demos / react-demo-legacy / src / server.js View on Github external
function generateHydrationScriptSrc(keys) {
  var sanitizedKeys = safeString(JSON.stringify(keys));
  return [
    ';try{',
      '(function(){',
        'window["', StyletronLegacy.constants.HYDRATE_KEY, '"]=', sanitizedKeys, ';',
      '})();',
    '}catch(e){};',
  ].join('');
}
github styletron / styletron / packages / demo-fixtures / legacy.js View on Github external
function LegacyComponent(props) {
  styletron.injectOnce('.legacyStyle { color: magenta }', '__legacy_style__');
  return React.createElement('div',
    {className: 'legacyStyle'}, 'I am a legacy component');
}

styletron

Universal, high-performance JavaScript styles

MIT
Latest version published 6 years ago

Package Health Score

53 / 100
Full package analysis

Similar packages