New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

github.com/vscodeshift/material-ui-codemorphs

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/vscodeshift/material-ui-codemorphs

  • v1.5.0
  • Source
  • Go
  • Socket score

Version published
Created
Source

@vscodeshift/material-ui-codemorphs

CircleCI Coverage Status semantic-release Commitizen friendly Visual Studio Marketplace Version

sweet codemod commands for everyday work with Material UI ✨

Commands

Add useStyles hook

Position the cursor inside a funcitonal component before running this command.

Wraps the functional component in withStyles, adds a const styles = (theme: Theme) => ({ }) declaration, and adds a classes type annotation and prop destructuring if possible.

Supports Flow, TypeScript, and plain JS!

Configuration

You can override where the Theme type is imported from by adding the following to your package.json:

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

You can override where makeStyles is imported from by adding the following to your package.json:

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

Example

import * as React from 'react'

interface Props {
  text: string
}

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

addStyles command

import * as React from 'react'

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

interface Props {
  text: string
}

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

- export const Test = ({ text }: Props): React.ReactNode => (
-   <div>{text}</div>
- )
+ export const Test = ({ text }: Props): React.ReactNode => {
+   const classes = useStyles()
+   return <div>{text}</div>
+ }

Wrap in withStyles

Position the cursor inside a component before running this command.

Wraps the component in withStyles, adds a const styles = (theme: Theme) => ({ }) declaration, and adds a classes type annotation and prop destructuring if possible.

Supports Flow, TypeScript, and plain JS!

Configuration

You can override where the Theme type is imported from by adding the following to your package.json:

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

You can override where withStyles is imported from by adding the following to your package.json:

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

Example

import * as React from 'react'

interface Props {
  text: string
}

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

withStyles command

import * as React from 'react'

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

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

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

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

+ const Test = withStyles(styles)(TestWithStyles)

Box (Set up @material-ui/system)

Creates/updates the declaration for Box based upon which props you pass to <Box> elements in your code.

Example

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

box command

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} />

FAQs

Package last updated on 25 Mar 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc