How to use react-jss - 10 common examples

To help you get started, we’ve selected a few react-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 flow-typed / flow-typed / definitions / npm / react-jss_v7.x.x / test_react-jss_v7.x.x.js View on Github external
<button>{theme.primaryColor}</button>
);

class ButtonClassComponent extends React.Component {
  props: ButtonProps;

  render() {
    const { theme } = this.props;

    return (
      <button>{theme.primaryColor}</button>
    );
  }
};

const ThemedButtonFunctionalComponent = withTheme(ButtonFunctionalComponent);

// $ExpectError - missing prop "onClick"
;

// No error
 {}} /&gt;;

const ThemedButtonClassComponent = withTheme(ButtonClassComponent);

// $ExpectError - missing prop "onClick"
;

// No errors
 {}} /&gt;;

// ===================================
github flow-typed / flow-typed / definitions / npm / react-jss_v7.x.x / test_react-jss_v7.x.x.js View on Github external
return (
      <button>{theme.primaryColor}</button>
    );
  }
};

const ThemedButtonFunctionalComponent = withTheme(ButtonFunctionalComponent);

// $ExpectError - missing prop "onClick"
;

// No error
 {}} /&gt;;

const ThemedButtonClassComponent = withTheme(ButtonClassComponent);

// $ExpectError - missing prop "onClick"
;

// No errors
 {}} /&gt;;

// ===================================
// createTheming
// ===================================

createTheming('__MY_THEME__');
github flow-typed / flow-typed / definitions / npm / react-jss_v7.x.x / test_react-jss_v7.x.x.js View on Github external
// No error
 {}} /&gt;;

const ThemedButtonClassComponent = withTheme(ButtonClassComponent);

// $ExpectError - missing prop "onClick"
;

// No errors
 {}} /&gt;;

// ===================================
// createTheming
// ===================================

createTheming('__MY_THEME__');
github nordnet / nordnet-ui-kit / src / components / input / input-default.jsx View on Github external
hasWarning: PropTypes.bool,
  helpText: PropTypes.node,
  leftAddon: PropTypes.node,
  rightAddon: PropTypes.node,
  /** Only used when type === textarea */
  lineCount: PropTypes.number, // eslint-disable-line
};

InputDefault.defaultProps = {
  type: 'text',
  variant: 'primary',
  lineCount: 3,
};

export { InputDefault as Component, styles };
export default injectSheet(styles, { injectTheme: true })(InputDefault);
github SAP / ui5-webcomponents-react / packages / main / src / components / ProgressIndicator / index.tsx View on Github external
* Specified width of component
   */
  width?: string;

  /*
   * Specified height of component
   */
  height?: string;

  /*
   * State of indicator (using ValueState)
   */
  state?: ValueState;
}

const useStyles = createUseStyles&gt;(styles, { name: 'ProgressIndicator' });

const ProgressIndicator: FC = forwardRef(
  (props: ProgressIndicatorPropTypes, ref: Ref) =&gt; {
    const { percentValue, displayValue, width, height, className, style, tooltip, state, slot } = props;

    const classes = useStyles();

    // CSS classes
    const wrapperClasses = StyleClassHelper.of(classes.wrapper);
    const progressBarClasses = StyleClassHelper.of(classes.progressbar);
    const progressBarTextClasses = StyleClassHelper.of(classes.progressBarText);

    const progressBarStyle = { flexBasis: `${percentValue}%` };

    // change content density
    const theme = useTheme() as JSSTheme;
github lotas / contentful-graph-web / styles / getContext.js View on Github external
function createContext() {
  return {
    jss,
    theme,
    // This is needed in order to deduplicate the injection of CSS in the page.
    sheetsManager: new Map(),
    // This is needed in order to inject the critical CSS.
    sheetsRegistry: new SheetsRegistry(),
  };
}
github kulakowka / isomorphic-react / src / server / handleRequest.js View on Github external
export default function handleRequest (req, res, next) {
  const context = {}

  const sheets = new SheetsRegistry()

  // inside a request
  const promises = []
  // use `some` to imitate `
github daixianceng / react-universal-example / src / server.js View on Github external
const route = await router.resolve(context);

    if (route.redirect) {
      res.redirect(route.status || 302, route.redirect);
      return;
    }

    const data = { ...route };

    // Creates JSS with default presets
    // https://github.com/cssinjs/jss-preset-default
    const jss = createJss(jssPreset());
    // JSS Server side rendering
    // https://github.com/cssinjs/react-jss#server-side-rendering
    const sheets = new SheetsRegistry();
    const sheetsManager = new Map();
    const theme = getTheme(req.cookies.get('theme'));
    const rootComponent = props =&gt; (
      
        
          {route.component}
        
      
    );
    await getDataFromTree(rootComponent({ disableStylesGeneration: true }));
    // this is here because of Apollo redux APOLLO_QUERY_STOP action
    await Promise.delay(0);
    data.children = await ReactDOM.renderToString(rootComponent());
    data.styles = [
      { id: 'css', cssText: [...css].join('') },
      { id: 'jss', cssText: sheets.toString() },
github adrivelasco / graphql-pwa-workshop / server / app / renderHtml / mui-theme.js View on Github external
constructor() {
    // Create a sheetsRegistry instance.
    this.sheetsRegistry = new SheetsRegistry();

    // Create a theme instance.
    this.theme = createMuiTheme({
      palette: {
        primary: green,
        accent: red,
        type: 'light'
      }
    });

    this.generateClassName = createGenerateClassName();
    this.grabCss = this.grabCss.bind(this);
  }
github goemonjs / goemon / src / client / base / common / route.tsx View on Github external
export function renderOnServer(componant, theme, req, context, store) {

  // Create a sheetsRegistry instance.
  const sheetsRegistry = new SheetsRegistry();

  const generateClassName = createGenerateClassName();

  const html = renderToString(
    
      
        
          
            {componant}
          
        
      
    
  );

  const css = sheetsRegistry.toString();