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

[Typography] Improve the upgrade story #13214

Merged
merged 3 commits into from
Oct 13, 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
4 changes: 2 additions & 2 deletions .size-limit.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ module.exports = [
name: 'The initial cost paid for using one component',
webpack: true,
path: 'packages/material-ui/build/Paper/index.js',
limit: '18.2 KB',
limit: '17.6 KB',
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

},
{
name: 'The size of all the material-ui modules.',
webpack: true,
path: 'packages/material-ui/build/index.js',
limit: '93.2 KB',
limit: '92.7 KB',
},
{
name: 'The main docs bundle',
Expand Down
2 changes: 0 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ This change updates the variant wording to match the one used in the Material De
+<Button variant="contained" />
```

You can suppress the warnings with the environment variable `MUI_SUPPRESS_DEPRECATION_WARNINGS` set to a truthy value.

#### Changes

- [TextField] Ensure labelWidth is set (#13077) @evanstern
Expand Down
8 changes: 4 additions & 4 deletions docs/scripts/buildApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { mkdir, readFileSync, writeFileSync } from 'fs';
import path from 'path';
import kebabCase from 'lodash/kebabCase';
import * as reactDocgen from 'react-docgen';
import { parse as docgenParse } from 'react-docgen';
import generateMarkdown from '../src/modules/utils/generateMarkdown';
import { findPagesMarkdown, findComponents } from '../src/modules/utils/find';
import { getHeaders } from '../src/modules/utils/parseMarkdown';
Expand Down Expand Up @@ -39,7 +39,7 @@ if (args.length < 4) {

const rootDirectory = path.resolve(__dirname, '../../');
const docsApiDirectory = path.resolve(rootDirectory, args[3]);
const theme = createMuiTheme();
const theme = createMuiTheme({ typography: { useNextVariants: true } });

const inheritedComponentRegexp = /\/\/ @inheritedComponent (.*)/;

Expand Down Expand Up @@ -123,7 +123,7 @@ function buildDocs(options) {

let reactAPI;
try {
reactAPI = reactDocgen.parse(src);
reactAPI = docgenParse(src);
} catch (err) {
console.log('Error parsing src for', componentObject.filename);
throw err;
Expand All @@ -134,7 +134,7 @@ function buildDocs(options) {
reactAPI.pagesMarkdown = pagesMarkdown;
reactAPI.src = src;

// if (reactAPI.name !== 'Snackbar') {
// if (reactAPI.name !== 'Button') {
// return;
// }

Expand Down
35 changes: 29 additions & 6 deletions docs/src/modules/utils/generateMarkdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import { parse as parseDoctrine } from 'doctrine';
import recast from 'recast';
import { parse as docgenParse } from 'react-docgen';
import { _rewriteUrlForNextExport } from 'next/router';
import { pageToTitle } from './helpers';

Expand All @@ -23,20 +24,39 @@ function generateHeader(reactAPI) {
}

function getDeprecatedInfo(type) {
const deprecatedPropType = 'deprecated(PropTypes.';

const indexStart = type.raw.indexOf(deprecatedPropType);
const marker = 'deprecated(PropTypes.';
const indexStart = type.raw.indexOf(marker);

if (indexStart !== -1) {
return {
propTypes: type.raw.substring(indexStart + deprecatedPropType.length, type.raw.indexOf(',')),
propTypes: type.raw.substring(indexStart + marker.length, type.raw.indexOf(',')),
explanation: recast.parse(type.raw).program.body[0].expression.arguments[1].value,
};
}

return false;
}

function getChained(type) {
const marker = 'chainPropTypes';
const indexStart = type.raw.indexOf(marker);

if (indexStart !== -1) {
const parsed = docgenParse(`
import PropTypes from 'prop-types';
const Foo = () => <div />
Foo.propTypes = {
bar: ${recast.print(recast.parse(type.raw).program.body[0].expression.arguments[0]).code}
}
export default Foo
`);

return parsed.props.bar.type;
}

return false;
}

function escapeCell(value) {
// As the pipe is use for the table structure
return value
Expand All @@ -50,7 +70,6 @@ function generatePropDescription(description, type) {

if (type.name === 'custom') {
const deprecatedInfo = getDeprecatedInfo(type);

if (deprecatedInfo) {
deprecated = `*Deprecated*. ${deprecatedInfo.explanation}<br><br>`;
}
Expand Down Expand Up @@ -123,13 +142,17 @@ function generatePropType(type) {
switch (type.name) {
case 'custom': {
const deprecatedInfo = getDeprecatedInfo(type);

if (deprecatedInfo !== false) {
return generatePropType({
name: deprecatedInfo.propTypes,
});
}

const chained = getChained(type);
if (chained !== false) {
return generatePropType(chained);
}

return type.raw;
}

Expand Down
3 changes: 3 additions & 0 deletions docs/src/pages/demos/buttons/CustomizedButtons.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ const theme = createMuiTheme({
palette: {
primary: green,
},
typography: {
useNextVariants: true,
},
});

function CustomizedInputs(props) {
Expand Down
2 changes: 1 addition & 1 deletion docs/src/pages/style/icons/icons.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Optionally, you can set the icon color using one of the theme color properties:
### SVG Material icons

It's interesting to have the building blocks needed to implement custom icons, but what about presets?
We provide a separate NPM package,
We provide a separate npm package,
[@material-ui/icons](https://www.npmjs.com/package/@material-ui/icons),
that includes the 1,000+ official [Material icons](https://material.io/tools/icons/?style=baseline) converted to `SvgIcon` components.

Expand Down
1 change: 0 additions & 1 deletion docs/src/pages/style/typography/DeprecatedTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ function typographyV1Theme(theme) {
return createMuiTheme({
...theme,
typography: {
suppressDeprecationWarnings: true,
useNextVariants: false,
},
});
Expand Down
34 changes: 9 additions & 25 deletions docs/src/pages/style/typography/typography.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,15 @@ Hopefully, you might be able to take advantage of the [`typography`](/customizat

## Migration to typography v2

The material design specification changed concerning variant names and styles. To allow
a smooth transition we kept old variants and restyled variants for backwards compatibility
but will log deprecation warnings. We will remove the old variants with our next
major release.
The material design specification changed concerning variant names and styles.
To allow a smooth transition we kept old variants and restyled variants for backwards compatibility but we log deprecation warnings.
We will remove the old typography variants in the next major release v4.0.0 (Q1 2019).

### Strategies

To make an immediate switch to typography v2 you can simply pass `useNextVariants: true` when
calling `createMuiTheme`:

```js
const theme = createMuiTheme({
typography: {
Expand All @@ -74,9 +74,11 @@ const theme = createMuiTheme({
});
```

or set `window.__MUI_USE_NEXT_TYPOGRAPHY_VARIANTS__ = true;` if you don't use the theme.

This will use new variants instead of old variants according to the following mapping:

```json
```sh
display4 => h1
display3 => h2
display2 => h3
Expand All @@ -88,24 +90,6 @@ body2 => body1
body1 (default) => body2 (default)
```

Please note that this will still log deprecation warnings if you use one of the variants.
Please note that this will log deprecation warnings if you use one of the old variants.
We recommend you replace those old variants with the recommended variants to be prepared
for the next major release.

See [Themes](/customization/themes/) for more information about how to use a global theme.

### Deprecation warnings for v4.0.0

Deprecation warnings are logged when:
- `NODE_ENV` is not strictly equal to `production`
- Regardless of whether you directly use the `Typography` component with a deprecated variant or another component
has a `Typography` component with a deprecated variant
- You override the style of a deprecated variant with `createMuiTheme`
- You override the style of a restyled variant without `useNextVariants` with `createMuiTheme`
- Variants are considered deprecated if:
- They will be removed in the next major release. This includes: display4, display3, display2, display1, headline, title, subheading
- They will be restyled and `useNextVariants` is falsy. This includes: body2, body1, caption, button

In some cases the deprecation warnings can break your test suite which might be inconvenient.
In those cases you can set the environment variable `MUI_SUPPRESS_DEPRECATION_WARNINGS` to a truthy value.
Passing `suppressDeprecationWarnings: true` to the typography options in `createMuiTheme` is equivalent.
for the next major release. See [Themes](/customization/themes/) for more information about how to use a global theme.
3 changes: 3 additions & 0 deletions examples/cdn/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@
dark: colors.green[700],
},
},
typography: {
useNextVariants: true,
},
});

const styles = theme => ({
Expand Down
3 changes: 3 additions & 0 deletions examples/create-react-app-with-flow/src/withRoot.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ const theme = createMuiTheme({
dark: green[700],
},
},
typography: {
useNextVariants: true,
},
});

function withRoot(Component: ComponentType<*>) {
Expand Down
3 changes: 3 additions & 0 deletions examples/create-react-app-with-jss/src/withRoot.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ const theme = createMuiTheme({
primary: purple,
secondary: green,
},
typography: {
useNextVariants: true,
},
});

// Create a JSS instance with the default preset of plugins.
Expand Down
3 changes: 3 additions & 0 deletions examples/create-react-app-with-typescript/src/withRoot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ const theme = createMuiTheme({
primary: purple,
secondary: green,
},
typography: {
useNextVariants: true,
},
});

function withRoot<P>(Component: React.ComponentType<P>) {
Expand Down
3 changes: 3 additions & 0 deletions examples/create-react-app/src/withRoot.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ const theme = createMuiTheme({
dark: green[700],
},
},
typography: {
useNextVariants: true,
},
});

function withRoot(Component) {
Expand Down
3 changes: 3 additions & 0 deletions examples/gatsby/src/getPageContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ const theme = createMuiTheme({
dark: green[700],
},
},
typography: {
useNextVariants: true,
},
});

function createPageContext() {
Expand Down
3 changes: 3 additions & 0 deletions examples/nextjs/src/getPageContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ const theme = createMuiTheme({
dark: green[700],
},
},
typography: {
useNextVariants: true,
},
});

function createPageContext() {
Expand Down
3 changes: 3 additions & 0 deletions examples/parcel/src/withRoot.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ const theme = createMuiTheme({
dark: green[700],
},
},
typography: {
useNextVariants: true,
},
});

function withRoot(Component) {
Expand Down
3 changes: 3 additions & 0 deletions examples/ssr/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ const theme = createMuiTheme({
accent: red,
type: 'light',
},
typography: {
useNextVariants: true,
},
});

// Create a new class name generator.
Expand Down
3 changes: 3 additions & 0 deletions examples/ssr/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ function handleRender(req, res) {
accent: red,
type: 'light',
},
typography: {
useNextVariants: true,
},
});

// Create a new class name generator.
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@
"size:why": "size-limit --why packages/material-ui/build/index.js",
"size:overhead:why": "size-limit --why ./test/size/overhead.js",
"test": "yarn lint && yarn typescript && yarn test:coverage",
"test:unit": "cross-env NODE_ENV=test MUI_SUPPRESS_DEPRECATION_WARNINGS=true mocha packages/material-ui/test/**/*.test.js packages/material-ui/src/{,**/}*.test.js docs/src/**/*.test.js",
"test:unit": "cross-env NODE_ENV=test mocha packages/material-ui/test/**/*.test.js packages/material-ui/src/{,**/}*.test.js docs/src/**/*.test.js",
"test:watch": "yarn test:unit --watch",
"test:coverage": "cross-env NODE_ENV=test BABEL_ENV=coverage MUI_SUPPRESS_DEPRECATION_WARNINGS=true nyc mocha packages/material-ui/test/**/*.test.js packages/material-ui/src/{,**/}*.test.js && nyc report -r lcovonly",
"test:coverage:html": "cross-env NODE_ENV=test BABEL_ENV=coverage MUI_SUPPRESS_DEPRECATION_WARNINGS=true nyc mocha packages/material-ui/test/**/*.test.js packages/material-ui/src/{,**/}*.test.js && nyc report --reporter=html",
"test:coverage": "cross-env NODE_ENV=test BABEL_ENV=coverage nyc mocha packages/material-ui/test/**/*.test.js packages/material-ui/src/{,**/}*.test.js && nyc report -r lcovonly",
"test:coverage:html": "cross-env NODE_ENV=test BABEL_ENV=coverage nyc mocha packages/material-ui/test/**/*.test.js packages/material-ui/src/{,**/}*.test.js && nyc report --reporter=html",
"test:karma": "cross-env NODE_ENV=test karma start test/karma.conf.js --single-run",
"test:regressions": "webpack --config test/regressions/webpack.config.js && rimraf test/regressions/screenshots/chrome/* && vrtest run --config test/vrtest.config.js --record",
"typescript": "tslint -p tsconfig.json \"packages/*/{src,test}/**/*.{ts,tsx}\"",
Expand Down
Loading