Skip to content

Instantly share code, notes, and snippets.

@masahirompp
Last active November 16, 2018 10:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save masahirompp/a48dbeff36319e868d1196dab5d704e1 to your computer and use it in GitHub Desktop.
Save masahirompp/a48dbeff36319e868d1196dab5d704e1 to your computer and use it in GitHub Desktop.
Material-UI Definition List. https://codesandbox.io/s/y2mjwnwj49
import withStyles, { WithStyles } from '@material-ui/core/styles/withStyles'
import TableCell from '@material-ui/core/TableCell'
import TableRow from '@material-ui/core/TableRow'
import * as React from 'react'
interface Props {
term: string
}
type ClassKey = 'term' | 'description'
const DefinitionItem: React.SFC<Props & WithStyles<ClassKey>> = ({ term, classes, children }) => (
<TableRow>
<TableCell component="th" scope="row" className={classes.term}>
{term}
</TableCell>
<TableCell className={classes.description}>{children}</TableCell>
</TableRow>
)
export default withStyles<ClassKey>(theme => ({
term: {
backgroundColor: theme.palette.background.default,
whiteSpace: 'nowrap',
wordBreak: 'keep-all'
},
description: {
width: '100%'
}
}))(DefinitionItem)
import withStyles, { WithStyles } from '@material-ui/core/styles/withStyles'
import Table from '@material-ui/core/Table'
import TableBody from '@material-ui/core/TableBody'
import * as React from 'react'
type ClassKey = 'root'
const DefinitionList: React.SFC<WithStyles<ClassKey>> = ({ children, classes }) => (
<Table>
<TableBody className={classes.root}>{children}</TableBody>
</Table>
)
export default withStyles<ClassKey>(theme => ({
root: {
'& tr:first-child': {
borderTopColor: theme.palette.divider,
borderTopStyle: 'solid',
borderTopWidth: '1px'
}
}
}))(DefinitionList)
import * as React from "react";
import DefinitionList from "./DefinitionList";
import DefinitionItem from "./DefinitionItem";
const Usage = () => (
<DefinitionList>
<DefinitionItem term="SGML">The Standard Generalized Markup Language</DefinitionItem>
<DefinitionItem term="HTML">The Hypertext Markup Language</DefinitionItem>
<DefinitionItem term="XML">The Extensible Markup Language</DefinitionItem>
</DefinitionList>
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment