Skip to content

Instantly share code, notes, and snippets.

@relyky
Last active December 16, 2020 11:15
Show Gist options
  • Save relyky/9137fa5afd699062dccfad6c616f2923 to your computer and use it in GitHub Desktop.
Save relyky/9137fa5afd699062dccfad6c616f2923 to your computer and use it in GitHub Desktop.
JavaScript, BR xsHide, with Material-UI
/**
* 範例: \<BR xsHide />
*/
import React from 'react'
import clsx from 'clsx'
import { withStyles } from '@material-ui/core/styles'
export const BR = withStyles(({ breakpoints }) => ({
xsHide: {
[breakpoints.down('xs')]: {
display: 'none'
}
}
}))((props: {
classes: Record<string, string>,
xsHide?: boolean
}) => {
return (
<br className={clsx(props.xsHide && props.classes.xsHide)} />
)
})
/**
* 範例: \<BR xsHide />
*/
import React from 'react'
import { useMediaQuery, useTheme } from '@material-ui/core'
export function BR(props: { xsHide: boolean | undefined }) {
const { breakpoints } = useTheme()
const matchXs = useMediaQuery(breakpoints.down('xs'))
// xsHide
if(props.xsHide && matchXs)
return (<></>)
// default
return (<br />)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment