Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Tooltip] Add default css max-width and customization demo #12338

Merged
merged 3 commits into from
Jul 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions docs/src/pages/demos/tooltips/CustomizedTooltips.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ const styles = theme => ({
borderStyle: 'solid',
},
},
button: {
margin: theme.spacing.unit,
},
});

class CustomizedTooltips extends React.Component {
Expand All @@ -88,10 +91,10 @@ class CustomizedTooltips extends React.Component {
return (
<div>
<Tooltip title="Add">
<Button>Default</Button>
<Button className={classes.button}>Default</Button>
</Tooltip>
<Tooltip title="Add" classes={{ tooltip: classes.lightTooltip }}>
<Button>Light</Button>
<Button className={classes.button}>Light</Button>
</Tooltip>
<Tooltip
title={
Expand All @@ -112,7 +115,7 @@ class CustomizedTooltips extends React.Component {
},
}}
>
<Button>Arrow</Button>
<Button className={classes.button}>Arrow</Button>
</Tooltip>
</div>
);
Expand Down
45 changes: 45 additions & 0 deletions docs/src/pages/demos/tooltips/VariableWidth.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import React from 'react';
import PropTypes from 'prop-types';
import { withStyles } from '@material-ui/core/styles';
import Button from '@material-ui/core/Button';
import Tooltip from '@material-ui/core/Tooltip';

const styles = theme => ({
button: {
margin: theme.spacing.unit,
},
customWidth: {
maxWidth: 500,
},
noMaxWidth: {
maxWidth: 'none',
},
});

const longText = `
Aliquam eget finibus ante, non facilisis lectus. Sed vitae dignissim est, vel aliquam tellus.
Praesent non nunc mollis, fermentum neque at, semper arcu.
Nullam eget est sed sem iaculis gravida eget vitae justo.
`;

function VariableWidth({ classes }) {
return (
<div>
<Tooltip title={longText}>
<Button className={classes.button}>Default Width [300px]</Button>
</Tooltip>
<Tooltip title={longText} classes={{ tooltip: classes.customWidth }}>
<Button className={classes.button}>Custom Width [500px]</Button>
</Tooltip>
<Tooltip title={longText} classes={{ tooltip: classes.noMaxWidth }}>
<Button className={classes.button}>No wrapping</Button>
</Tooltip>
</div>
);
}

VariableWidth.propTypes = {
classes: PropTypes.object.isRequired,
};

export default withStyles(styles)(VariableWidth);
6 changes: 6 additions & 0 deletions docs/src/pages/demos/tooltips/tooltips.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,9 @@ By default disabled elements like `Button` do not trigger user interactions so a
## Customized Tooltips

{{"demo": "pages/demos/tooltips/CustomizedTooltips.js"}}

## Variable Width

The `Tooltip` wraps long text by default to make it readable.

{{"demo": "pages/demos/tooltips/VariableWidth.js"}}
1 change: 1 addition & 0 deletions packages/material-ui/src/Tooltip/Tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export const styles = theme => ({
padding: '4px 8px',
fontSize: theme.typography.pxToRem(10),
lineHeight: `${theme.typography.round(14 / 10)}em`,
maxWidth: 300,
},
/* Styles applied to the tooltip (label wrapper) element if the tooltip is opened by touch. */
touch: {
Expand Down
7 changes: 7 additions & 0 deletions pages/demos/tooltips.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ module.exports = require('fs')
raw: preval`
module.exports = require('fs')
.readFileSync(require.resolve('docs/src/pages/demos/tooltips/PositionedTooltips'), 'utf8')
`,
},
'pages/demos/tooltips/VariableWidth.js': {
js: require('docs/src/pages/demos/tooltips/VariableWidth').default,
raw: preval`
module.exports = require('fs')
.readFileSync(require.resolve('docs/src/pages/demos/tooltips/VariableWidth'), 'utf8')
`,
},
'pages/demos/tooltips/ControlledTooltips.js': {
Expand Down