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

material-ui-codemorphs

v3.2.4

Published

smart codemod scripts for day-to-day work with Material UI

Downloads

70

Readme

material-ui-codemorphs

CircleCI Coverage Status semantic-release Commitizen friendly npm version

Smart codemod scripts for day-to-day work with Material UI

Table of Contents

useStyles

A jscodeshift transform that adds a makeStyles declaration and useStyles hook to a function component.

Supports Flow, TypeScript, and plain JS. It's freakin great.

Special options

selectionStart (optional)

The start of the selection (e.g. in a text editor) within the source code. This is used to determine which component(s) to add styles to. Without this option, styles will be added to all components in the file. If selectionEnd is not given, styles will only be added to the component that contains selectionStart.

selectionEnd (optional)

The end of the selection (e.g. in a text editor) within the source code. This is used to determine which component(s) to add styles to.

themeImport (optional)

Overrides the import statement added by useStyles for importing the Theme type definition. You can also configure this by adding the following to your package.json:

{
  "material-ui-codemorphs": {
    "themeImport": "import { type Theme } from './src/universal/theme'"
  }
}

makeStylesImport (optional)

Overrides the import statement added by useStyles for importing makeStyles. You can also configure this by adding the following to your package.json:

{
  "material-ui-codemorphs": {
    "makeStylesImport": "import { makeStyles } from '@material-ui/core'"
  }
}

Flow Example

Before

// @flow

import * as React from 'react'

const Test = props => (
  // position
  <div>{props.text}</div>
)

Transform

jscodeshift path/to/material-ui-codemorphs/useStyles.js src/Test.js \
  --parser=babylon \
  --selectionStart=95

After

// @flow

import * as React from 'react'

import { makeStyles } from '@material-ui/core/styles'
import { type Theme } from '../../src/universal/theme'

const useStyles = makeStyles((theme: Theme) => ({}))

const Test = props => {
  const classes = useStyles(props)
  return <div>{props.text}</div>
}

TypeScript example

Before

import * as React from 'react'

const Test = ({ text }) => (
  // position
  <div>{text}</div>
)

Transform

jscodeshift path/to/material-ui-codemorphs/useStyles.js src/Test.tsx \
  --parser=tsx \
  --selectionStart=95

After

import * as React from 'react'

import { makeStyles, Theme } from '@material-ui/core/styles'

const useStyles = makeStyles((theme: Theme) => ({}))

const Test = ({ text }) => {
  const classes = useStyles()
  return <div>{text}</div>
}

withStyles

A jscodeshift transform that wraps a component with withStyles, adds the const styles = (theme: Theme) => ({ }) declaration, and adds a classes type annotation and prop destructuring if possible.

Supports Flow, TypeScript, and plain JS. It's freakin great.

Special options

selectionStart (optional)

The start of the selection (e.g. in a text editor) within the source code. This is used to determine which component(s) to add styles to. Without this option, styles will be added to all components in the file. If selectionEnd is not given, styles will only be added to the component that contains selectionStart.

selectionEnd (optional)

The end of the selection (e.g. in a text editor) within the source code. This is used to determine which component(s) to add styles to.

themeImport (optional)

Overrides the import statement added by withStyles for importing the Theme type definition. You can also configure this by adding the following to your package.json:

{
  "material-ui-codemorphs": {
    "themeImport": "import { type Theme } from './src/universal/theme'"
  }
}

withStylesImport (optional)

Overrides the import statement added by useStyles for importing withStyles. You can also configure this by adding the following to your package.json:

{
  "material-ui-codemorphs": {
    "withStylesImport": "import { withStyles } from '@material-ui/core'"
  }
}

Flow example

Before

// @flow

type Props = {
  +text: string,
}

export const Test = ({ text }: Props): React.Node => (
  // position
  <div>{text}</div>
)

Transform

jscodeshift path/to/material-ui-codemorphs/withStyles.js src/Test.js \
  --parser=babylon \
  --selectionStart=95 \
  --themeImport='import {type Theme} from "./src/universal/theme"'

After

// @flow
import { withStyles } from '@material-ui/core/styles'

import { type Theme } from '../theme'

type Classes<Styles> = $Call<<T>((any) => T) => { [$Keys<T>]: string }, Styles>

const styles = (theme: Theme) => ({})

type Props = {
  +text: string,
  +classes: Classes<typeof styles>,
}

const TestWithStyles = ({ text, classes }: Props): React.Node => (
  <div>{text}</div>
)

const Test = withStyles(styles)(TestWithStyles)

export { Test }

TypeScript example

Before

import * as React from 'react'

interface Props {
  text: string
}

export const Test = ({ text }: Props): React.ReactNode => (
  // position
  <div>{text}</div>
)

Transform

jscodeshift path/to/material-ui-codemorphs/withStyles.js src/Test.tsx \
  --parser=tsx \
  --selectionStart=95

After

import * as React from 'react'

import { withStyles, Theme, WithStyles } from '@material-ui/core/styles'

interface Props extends WithStyles<typeof styles> {
  text: string
}

const styles = (theme: Theme) => ({})

const TestWithStyles = ({ text, classes }: Props): React.ReactNode => (
  <div>{text}</div>
)

const Test = withStyles(styles)(TestWithStyles)

export { Test }

setupSystem

A jscodeshift transform that creates or updates the declaration for Box and corresponding imports based upon the JSX attributes you use on it.

Example

Before

import * as React from 'react'
const Foo = () => (
  <Box
    sm={{ marginLeft: 2, fontSize: 12 }}
    md={{ marginLeft: 3, fontSize: 16 }}
  />
)
const Bar = () => <Box boxShadow={1} />

Transform

jscodeshift -t path/to/material-ui-codemorphs/setupSystem.js test.js

After

import * as React from 'react'
import { styled } from '@material-ui/styles'
import {
  spacing,
  typography,
  shadows,
  breakpoints,
  compose,
} from '@material-ui/system'
const Box = styled('div')(breakpoints(compose(shadows, spacing, typography)))
const Foo = () => (
  <Box
    sm={{ marginLeft: 2, fontSize: 12 }}
    md={{ marginLeft: 3, fontSize: 16 }}
  />
)
const Bar = () => <Box boxShadow={1} />