How to use the jss.create function in jss

To help you get started, we’ve selected a few jss 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 cssinjs / jss / packages / css-jss / src / createCss.js View on Github external
// @flow
import {create as createJss} from 'jss'
import preset from 'jss-preset-default'
import type {Jss} from 'jss'
// eslint-disable-next-line no-unused-vars
import type {Css, StyleArg} from './types'

// I have been trying to benchmark and I have seen a slow down after about 10k rules.
// Since we are in a single sheet mode, user shouldn't care about this.
const MAX_RULES_PER_SHEET = 10000

const defaultJss = createJss(preset())

const createCss = (jss: Jss = defaultJss): Css => {
  const cache = new Map()
  let ruleIndex = 0
  let sheet

  const getSheet = () => {
    if (!sheet || sheet.rules.index.length > MAX_RULES_PER_SHEET) {
      sheet = jss.createStyleSheet().attach()
    }
    return sheet
  }

  function css(/* :: ..._: StyleArg[] */): string {
    // eslint-disable-next-line prefer-rest-params
    const args = arguments
github iodide-project / iodide / src / shared / components / css-cascade-provider.jsx View on Github external
import React from "react";
import PropTypes from "prop-types";
import { create } from "jss";
import JssProvider from "react-jss/lib/JssProvider";
import { createGenerateClassName, jssPreset } from "@material-ui/styles";

const styleNode = document.createElement("style");
styleNode.id = "insertion-point-jss";
document.head.insertBefore(styleNode, document.head.firstChild);

// Configure JSS
const jss = create(jssPreset());
jss.options.createGenerateClassName = createGenerateClassName;
jss.options.insertionPoint = document.getElementById("insertion-point-jss");

const CSSCascadeProvider = ({ children }) => {
  return {children};
};
CSSCascadeProvider.propTypes = {
  children: PropTypes.element
};
export default CSSCascadeProvider;
github codeamp / panel / src / index.js View on Github external
// Apollo
import { ApolloProvider } from 'react-apollo';
import makeClient from 'lib/apollo';

// MUI
import { MuiThemeProvider, createMuiTheme } from 'material-ui/styles';
import createPalette from 'material-ui/styles/createPalette';
import { blue, pink } from 'material-ui/colors';
import JssProvider from 'react-jss/lib/JssProvider';
import { create } from 'jss';
import preset from 'jss-preset-default';
import { createGenerateClassName } from 'material-ui/styles';

const generateClassName = createGenerateClassName();
const jss = create(preset());
jss.options.insertionPoint = document.getElementById('jss-insertion-point');

const client = makeClient(process.env.REACT_APP_CIRCUIT_URI + '/query');
const theme = createMuiTheme({
  palette: createPalette({
    primary: blue,
    secondary: pink,
    type: 'light',
  }),
});

ReactDOM.render(
github cboard-org / cboard / src / providers / ThemeProvider / RTLSupport.js View on Github external
import React from 'react';

import { create } from 'jss';
import rtl from 'jss-rtl';
import JssProvider from 'react-jss/lib/JssProvider';
import { createGenerateClassName, jssPreset } from '@material-ui/core/styles';

// Configure JSS
const jss = create({
  plugins: [...jssPreset().plugins, rtl()]
});

// Custom Material-UI class name generator.
const generateClassName = createGenerateClassName();

export function RTLSupport({ children }) {
  return (
    
      {React.Children.only(children)}
    
  );
}

export default RTLSupport;
github notadd / next / src / styles / createContext.ts View on Github external
import { create, SheetsRegistry } from 'jss';
import preset from 'jss-preset-default';
import { createMuiTheme } from 'material-ui/styles';
import { indigo, green } from 'material-ui/colors';
import createGenerateClassName from 'material-ui/styles/createGenerateClassName';

const theme = createMuiTheme({
  palette: {
    primary: indigo['A500'],
    secondary: green,
  },
});

// Configure JSS
const jss = create(preset());
jss.options.createGenerateClassName = createGenerateClassName;

export const sheetsManager = new Map();

export default function createContext() {
  return {
    jss,
    theme,
    // This is needed in order to deduplicate the injection of CSS in the page.
    sheetsManager,
    // This is needed in order to inject the critical CSS.
    sheetsRegistry: new SheetsRegistry(),
  };
}
github arakat-community / arakat / app.tsx View on Github external
import { IApplicationState } from "./arakat-frontend/src/store";
import { IAuthenticationState } from "./arakat-frontend/src/store/authentication/types";
import LoginView from "./arakat-frontend/src/views/login";
import MainView from "./arakat-frontend/src/views/main";



export interface IAppState {
  location: Location;
  locale: ILocalizationLanguage;
  authentication?: IAuthenticationState;
}

type AllTypes = IAppState & RouteComponentProps;
const test: any = jssPreset().plugins;
const jss: any = create({ plugins: [...test, rtl()] });

const generateClassName: any = createGenerateClassName();

const getTheme: (locale: ILocalizationLanguage) => Theme = (
  locale: ILocalizationLanguage,
) => {
  const theme: Theme = createMuiTheme({
    direction: locale.rtl ? "rtl" : "ltr",
    overrides: {
      MuiAppBar: {
        colorPrimary: {
          backgroundColor: "#fafafa",
        },
        root: {
          padding: 0,
        },
github cssinjs / jss / packages / jss-plugin-expand / benchmark / integration / bootstrap.js View on Github external
benchmark('JSS + Plugin', () => {
    const jss = create()
    jss.use(jssExpand())
    jss.createStyleSheet(styles, {named: false}).toString()
  })
})
github mui-org / material-ui / docs / src / modules / components / DemoSandboxed.js View on Github external
const onContentDidMount = () => {
    setState({
      ready: true,
      jss: create({
        plugins: [...jssPreset().plugins, rtl()],
        insertionPoint: instanceRef.current.contentWindow['demo-frame-jss'],
      }),
      sheetsManager: new Map(),
      container: instanceRef.current.contentDocument.body,
      window: () => instanceRef.current.contentWindow,
    });
  };
github andywer / react-usestyles / packages / style-api-jss / src / index.jsx View on Github external
export function JssProvider (props) {
  const [{ jss, manager }] = useState({
    jss: create(defaultPreset()),
    manager: new SheetsManager()
  })

  const createSheet = (styles, themeID, theme, inputs) => {
    const sheetMeta = createSheetMeta(styles, themeID, inputs)
    return createUnifiedSheet(sheetMeta, jss, manager, props.registry, styles, theme, props.sheetOptions || {})
  }

  return (
    
      {props.children}
    
  )
}
github siriwatknp / mui-treasury / src / components / atoms / DemoFrame.js View on Github external
onContentDidMount = () => {
    this.setState({
      ready: true,
      jss: create({
        plugins: jssPreset().plugins,
        insertionPoint: this.contentWindow['demo-frame-jss'],
      }),
      sheetsManager: new Map(),
      container: this.contentDocument.body,
      window: () => this.contentWindow,
    });
  };