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

[docs] Improve documentation of the system #23294

Merged
merged 90 commits into from
Nov 12, 2020
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
90 commits
Select commit Hold shift + click to select a range
eb5426b
wip
mnajdova Oct 28, 2020
4cc8ceb
finished doc page
mnajdova Oct 28, 2020
4ce7687
typos
mnajdova Oct 28, 2020
e99de3b
docs:i18n & docs:typescript:formatted
mnajdova Oct 28, 2020
cae9761
fixes
mnajdova Oct 28, 2020
54d8a55
Update docs/src/pages/system/sx/sx.md
mnajdova Oct 28, 2020
b8fb9dd
Update docs/src/pages/system/sx/sx.md
mnajdova Oct 28, 2020
9b56867
Update docs/src/pages.js
mnajdova Oct 28, 2020
e5978a4
Update docs/translations/translations.json
mnajdova Oct 28, 2020
d99cf00
Update docs/src/pages/system/sx/sx.md
mnajdova Oct 28, 2020
c94ca93
Update docs/src/pages/system/sx/BreakpointsAsArray.tsx
mnajdova Oct 28, 2020
79a7d8b
Update docs/src/pages/system/sx/BreakpointsAsObject.js
mnajdova Oct 28, 2020
e07060a
Update docs/src/pages/system/sx/BreakpointsAsArray.js
mnajdova Oct 28, 2020
acbc866
Update docs/src/pages/system/sx/BreakpointsAsObject.tsx
mnajdova Oct 28, 2020
e2652f9
Update docs/src/pages/system/sx/GettingStarted.js
mnajdova Oct 28, 2020
a1bafa7
Update docs/src/pages/system/sx/GettingStarted.tsx
mnajdova Oct 28, 2020
f8e965d
Update docs/src/pages/system/sx/ValueAsFunction.js
mnajdova Oct 28, 2020
aa081b8
Update docs/src/pages/system/sx/ValueAsFunction.tsx
mnajdova Oct 28, 2020
b30e24b
Update docs/src/pages/system/sx/sx.md
mnajdova Oct 28, 2020
14a908c
Update docs/src/pages/system/sx/sx.md
mnajdova Oct 28, 2020
c029718
Update docs/src/pages/system/sx/sx.md
mnajdova Oct 28, 2020
682a5a8
Update docs/src/pages/system/sx/sx.md
mnajdova Oct 28, 2020
cb867a9
Update docs/src/pages/system/sx/sx.md
mnajdova Oct 28, 2020
52720d5
Update docs/src/pages/system/sx/sx.md
mnajdova Oct 28, 2020
dbd5026
Update docs/src/pages/system/sx/sx.md
mnajdova Oct 28, 2020
35fe80e
Update docs/src/pages/system/sx/sx.md
mnajdova Oct 28, 2020
c6a8d46
converted border demos
mnajdova Nov 1, 2020
7fc6a78
Merge branch 'feat/sx-prop-docs-page' of https://github.com/mnajdova/…
mnajdova Nov 1, 2020
d909c63
displays examples converted
mnajdova Nov 2, 2020
a19edd6
Merge branch 'next' into feat/sx-prop-docs-page
mnajdova Nov 3, 2020
e28a683
addressing comments
mnajdova Nov 3, 2020
87c118e
prettier & interface
mnajdova Nov 3, 2020
b0fa09c
demo update
mnajdova Nov 5, 2020
e3808bb
wip update content
mnajdova Nov 5, 2020
01bc241
Updated docs
mnajdova Nov 5, 2020
780d5fd
Update packages/material-ui/src/Box/index.js
mnajdova Nov 5, 2020
cc5f8c7
Update docs/translations/translations.json
mnajdova Nov 5, 2020
6a9108d
Update packages/material-ui/src/Box/styleFunction.d.ts
mnajdova Nov 5, 2020
9d5bd14
Update packages/material-ui/src/Box/styleFunction.js
mnajdova Nov 5, 2020
2854661
Update packages/material-ui/src/Box/styleFunction.js
mnajdova Nov 5, 2020
8b7ea10
Update packages/material-ui/src/Box/styleFunction.js
mnajdova Nov 5, 2020
a34ae16
Update packages/material-ui/src/styles/experimentalStyled.js
mnajdova Nov 5, 2020
8c5823a
one-liner
oliviertassinari Nov 5, 2020
d50a6af
update header
oliviertassinari Nov 5, 2020
28eb893
formatted
mnajdova Nov 5, 2020
b198753
updated demo
mnajdova Nov 5, 2020
6a8b944
Update docs/src/pages/system/basics/basics.md
mnajdova Nov 5, 2020
64b51cc
Update docs/src/pages/system/basics/basics.md
mnajdova Nov 5, 2020
47af380
Update docs/src/pages/system/basics/basics.md
mnajdova Nov 5, 2020
18752f5
Update docs/src/pages/system/basics/basics.md
mnajdova Nov 5, 2020
541d0b7
polish
oliviertassinari Nov 5, 2020
af31b6c
Update docs/src/pages/system/basics/Demo.js
mnajdova Nov 6, 2020
a9ca97f
Merge pull request #14 from oliviertassinari/polish-demo
mnajdova Nov 6, 2020
dd7b9fa
Update docs/src/pages/system/basics/basics.md
mnajdova Nov 6, 2020
5796085
Update docs/src/pages/system/basics/basics.md
mnajdova Nov 6, 2020
34c4309
Update docs/src/pages/system/basics/basics.md
mnajdova Nov 6, 2020
304116c
Update docs/src/pages/system/basics/basics.md
mnajdova Nov 6, 2020
faee8de
Update docs/src/pages/system/basics/basics.md
mnajdova Nov 6, 2020
71575b8
Update docs/src/pages/system/basics/basics.md
mnajdova Nov 6, 2020
584b289
Update docs/src/pages/system/basics/basics.md
mnajdova Nov 6, 2020
602d1d7
Update docs/src/pages/system/basics/basics.md
mnajdova Nov 6, 2020
153a18d
Update docs/src/pages/system/basics/basics.md
mnajdova Nov 6, 2020
6d66c80
Update docs/src/pages/system/basics/basics.md
mnajdova Nov 6, 2020
16a1c95
Update docs/src/pages/system/basics/basics.md
mnajdova Nov 6, 2020
357f73e
switching context demo
mnajdova Nov 6, 2020
b824976
fixed duplicated section
mnajdova Nov 6, 2020
6a4630b
prettier & formatted
mnajdova Nov 6, 2020
3101abd
improve-why
oliviertassinari Nov 6, 2020
9187099
review
mbrookes Nov 7, 2020
90ba086
improve last argument wording
oliviertassinari Nov 7, 2020
0b0670c
review
mbrookes Nov 7, 2020
40fe4a7
polish
oliviertassinari Nov 7, 2020
cffb670
more polish
oliviertassinari Nov 7, 2020
725c552
prefer the object by default over array
oliviertassinari Nov 7, 2020
c0f2269
marked token are wrong, we could consider using reactjs.org approach …
oliviertassinari Nov 7, 2020
5514a6b
add a note about performance
oliviertassinari Nov 7, 2020
5e7fa1a
Update docs/src/pages/system/basics/basics.md
mnajdova Nov 7, 2020
873490d
Update docs/src/pages/system/basics/basics.md
mnajdova Nov 7, 2020
fb42502
Update docs/src/pages/system/basics/basics.md
mnajdova Nov 7, 2020
cb35c1e
comments
mnajdova Nov 9, 2020
0f9a565
Update docs/src/pages/system/basics/basics.md
mnajdova Nov 9, 2020
6d1c063
Update docs/src/pages/system/basics/basics.md
mnajdova Nov 9, 2020
05b40fd
feedback
mnajdova Nov 9, 2020
efab4f0
Merge branch 'feat/sx-prop-docs-page' of https://github.com/mnajdova/…
mnajdova Nov 9, 2020
762b4cc
make the link clear
oliviertassinari Nov 9, 2020
5924891
Merge branch 'next' into feat/sx-prop-docs-page
mnajdova Nov 11, 2020
2ad356c
typos and final fixes
mnajdova Nov 11, 2020
6007e3b
test preview
mnajdova Nov 11, 2020
da64fea
Merge remote-tracking branch 'upstream/next' into feat/sx-prop-docs-page
eps1lon Nov 12, 2020
5aa6192
Remove prettier-ignore directives from user-facing code
eps1lon Nov 12, 2020
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
20 changes: 20 additions & 0 deletions docs/pages/system/sx.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import React from 'react';
import MarkdownDocs from 'docs/src/modules/components/MarkdownDocs';
import { prepareMarkdown } from 'docs/src/modules/utils/parseMarkdown';

const pageFilename = 'system/sx';
const requireDemo = require.context('docs/src/pages/system/sx', false, /\.(js|tsx)$/);
const requireRaw = require.context(
'!raw-loader!../../src/pages/system/sx',
false,
/\.(js|md|tsx)$/,
);

export default function Page({ demos, docs }) {
return <MarkdownDocs demos={demos} docs={docs} requireDemo={requireDemo} />;
}

Page.getInitialProps = () => {
const { demos, docs } = prepareMarkdown({ pageFilename, requireRaw });
return { demos, docs };
};
1 change: 1 addition & 0 deletions docs/src/pages.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ const pages = [
pathname: '/system',
children: [
{ pathname: '/system/basics' },
{ pathname: '/system/sx', title: 'sx' },
{ pathname: '/system/borders' },
{ pathname: '/system/display' },
{ pathname: '/system/flexbox' },
Expand Down
14 changes: 14 additions & 0 deletions docs/src/pages/system/sx/BreakpointsAsArray.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import * as React from 'react';
import Box from '@material-ui/core/Box';

export default function BreakpointsAsArray() {
return (
<Box
sx={{
width: [100, 200, 300, 400, 500],
}}
>
This box has a responsive width
mnajdova marked this conversation as resolved.
Show resolved Hide resolved
</Box>
);
}
14 changes: 14 additions & 0 deletions docs/src/pages/system/sx/BreakpointsAsArray.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import * as React from 'react';
import Box from '@material-ui/core/Box';

export default function BreakpointsAsArray() {
return (
<Box
sx={{
width: [100, 200, 300, 400, 500],
}}
>
This box has a responsive width
mnajdova marked this conversation as resolved.
Show resolved Hide resolved
</Box>
);
}
20 changes: 20 additions & 0 deletions docs/src/pages/system/sx/BreakpointsAsObject.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import * as React from 'react';
import Box from '@material-ui/core/Box';

export default function BreakpointsAsObject() {
return (
<Box
sx={{
width: {
sx: 100,
sm: 200,
md: 300,
lg: 400,
xl: 500,
},
}}
>
This box has a responsive width
mnajdova marked this conversation as resolved.
Show resolved Hide resolved
</Box>
);
}
20 changes: 20 additions & 0 deletions docs/src/pages/system/sx/BreakpointsAsObject.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import * as React from 'react';
import Box from '@material-ui/core/Box';

export default function BreakpointsAsObject() {
return (
<Box
sx={{
width: {
sx: 100,
sm: 200,
md: 300,
lg: 400,
xl: 500,
},
}}
>
This box has a responsive width
mnajdova marked this conversation as resolved.
Show resolved Hide resolved
</Box>
);
}
20 changes: 20 additions & 0 deletions docs/src/pages/system/sx/GettingStarted.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import * as React from 'react';
import Box from '@material-ui/core/Box';

export default function GettingStarted() {
return (
<Box
sx={{
p: 3,
color: 'primary.main',
boxShadow: 3,
':hover': {
backgroundColor: 'primary.light',
color: 'white',
},
}}
>
How to use the sx prop
mnajdova marked this conversation as resolved.
Show resolved Hide resolved
</Box>
);
}
20 changes: 20 additions & 0 deletions docs/src/pages/system/sx/GettingStarted.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import * as React from 'react';
import Box from '@material-ui/core/Box';

export default function GettingStarted() {
return (
<Box
sx={{
p: 3,
color: 'primary.main',
boxShadow: 3,
':hover': {
backgroundColor: 'primary.light',
color: 'white',
},
}}
>
How to use the sx prop
mnajdova marked this conversation as resolved.
Show resolved Hide resolved
</Box>
);
}
16 changes: 16 additions & 0 deletions docs/src/pages/system/sx/ValueAsFunction.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import * as React from 'react';
import Box from '@material-ui/core/Box';

export default function ValueAsFunction() {
return (
<Box
sx={{
p: 1,
border: 1,
borderColor: (theme) => theme.palette.primary.main,
}}
>
Border color with theme value
mnajdova marked this conversation as resolved.
Show resolved Hide resolved
</Box>
);
}
17 changes: 17 additions & 0 deletions docs/src/pages/system/sx/ValueAsFunction.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import * as React from 'react';
import Box from '@material-ui/core/Box';
import { Theme } from '@material-ui/core/styles';

export default function ValueAsFunction() {
return (
<Box
sx={{
p: 1,
border: 1,
borderColor: (theme: Theme) => theme.palette.primary.main,
}}
>
Border color with theme value
mnajdova marked this conversation as resolved.
Show resolved Hide resolved
</Box>
);
}
92 changes: 92 additions & 0 deletions docs/src/pages/system/sx/sx.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
# The `sx` prop

<p class="description">Utility for styling elements inline, using the theme values.</p>

## Getting started

Each `@material-ui/core` component supports the `sx` prop. The prop is a superset of CSS, that let's you add any CSS to the underlaying component, while mapping values to different theme keys. This should help you to keep your application look consistent.
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure I would start with mentioning @material-ui/core.

Copy link
Member Author

Choose a reason for hiding this comment

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

What do you think of this:

The sx prop is a superset of CSS, that let's you add any CSS to the underlaying component, while mapping values to different theme keys. This should help you to keep your application look consistent. The prop is available in all @material-ui/core components.

Later when we support this on all primitives, we can add that here too. Or at least, we can export the styleFunctionSx and add something like:

You can include this prop on your own components too by using the styleFunctionSx style function from @material-ui/core/Box, or you can automatically add it to your component by using the experimentalStyled from @material-ui/core/styles.

import { styleFunctionSx } from '@material-ui/core/Box';
import styled from '@emotion/styled';

const Div = styled('div')(styleFunctionSx);

or

import { experimentalStyled as styled } from '@material-ui/core/styles';

const Div = styled('div')``;

Copy link
Member

Choose a reason for hiding this comment

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

I'l wait for it to be updated before correcting this.

Copy link
Member

Choose a reason for hiding this comment

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

We haven't decided on adding sx to every component nor have we released it. We shouldn't document something before.

Copy link
Member

@oliviertassinari oliviertassinari Oct 29, 2020

Choose a reason for hiding this comment

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

We haven't decided on adding sx to every component nor have we released it. We shouldn't document something before.

The Slider is meant to be a projection of how all the other components will be architectured. Slider now supports the sx prop and was released. So I think that in theory, this decision and release event has already happened. I would argue that the decision started 2 years ago with

In the future, we will look into using it directly in the core components.

https://medium.com/material-ui/introducing-material-ui-design-system-93e921beb8df

"look into" as how can we make it fast enough. Then about a year ago with #15561.

Having a look at all the issues that where closed linking to this issue (#15561) is interesting to gauge the pain.

Copy link
Member

Choose a reason for hiding this comment

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

So I think that in theory, this decision and release event has already happened.

That is not how an alpha works. Its goal is to give us freedom to add and remove things without having to release a major version every time. If you're now flipped to "everything released in alpha is stable" then you should've told us that before we started working on v5. That's a pretty fundamental change to the alpha process especially if it involves decisions we haven't discussed.

As ususal: something existing is in no way shape or form under any circumstance and argument for its existence. Slider with sx is not a good API just because it shipped with it. The original PR still doesn't include a real world use case and just some toying around.

I would argue that the decision started 2 years ago with

A decision isn't a process. Could you link me the conclusion of the discussion with having widgets with system props that just affect the root container?

Copy link
Member

Choose a reason for hiding this comment

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

Its goal is to give us freedom to add and remove things without having to release a major version every time.

Agree, the objective of pre-releases is to allow a short feedback loop. It allows us to validate ideas directly with developers. On this one, we are waiting to get insight from developers after having released it. It seems that the trend of improvement is toward supporting sx everywhere: #23220. The value of the prop increases the more it can be used in a systematic manner.


I don't understand the concern with the sx prop, the value proposition started to be discussed in #22819, then #23053, e.g. #23053 (comment).

Copy link
Member

Choose a reason for hiding this comment

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

I don't understand the concern with the sx prop

It's JavaScript. JavaScript is only good if it solves a problem. On the flipside: I do not understand how you don't see a problem with adding features after maintaining open-source for 3+ years.

Copy link
Member

Choose a reason for hiding this comment

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

Ok, it makes sense, so I would summarize the concern into: is this going in the right direction, and is the opportunity cost right? From my perspective, the answer is yes to both of these questions. I would personally use it over what we have now in future projects. It's really meant to be Bootstrap's utility equivalent (but covering more use cases).

I guess we can keep it in the alpha state longer to make sure we don't regret it?


We recommend you use this prop whenever you need to add one-of style overrides on the Material-UI components. If you repetedly add the same styles on some component, than the `styled()` is better alternative, as it allows you to specify the overrides only ones and reuse them in all component instances.
oliviertassinari marked this conversation as resolved.
Show resolved Hide resolved
mnajdova marked this conversation as resolved.
Show resolved Hide resolved

{{"demo": "pages/system/sx/GettingStarted.js", "defaultCodeOpen": true}}

# Property to theme key mapping

You can explore the [System API](/system/api/) page to discover how the different css (and custom) properties are mapped to the theme keys.
mnajdova marked this conversation as resolved.
Show resolved Hide resolved

## Value as a function

If you wish to use the theme for some css property that is not supported by the system, you can use function as a value, where you can have access to the theme object.
mnajdova marked this conversation as resolved.
Show resolved Hide resolved

{{"demo": "pages/system/sx/ValueAsFunction.js", "defaultCodeOpen": true}}

# Breakpoints

If you would like to have responsive values for some CSS property, you may use the breakpoints shorthand syntax. We offer two ways of defining the breakpoints:
mnajdova marked this conversation as resolved.
Show resolved Hide resolved

## Breakpoints as array
mnajdova marked this conversation as resolved.
Show resolved Hide resolved

The first option is to define your breakpoints as an array, from the smallest to the largest breakpoint.

{{"demo": "pages/system/sx/BreakpointsAsArray.js", "defaultCodeOpen": true}}

## Breakpoints as object
mnajdova marked this conversation as resolved.
Show resolved Hide resolved

The second option for defining breakpoints is to define them as object, using the breakpoints as keys. Here is an example of how you may define the previous example by using the object syntax.
mnajdova marked this conversation as resolved.
Show resolved Hide resolved

{{"demo": "pages/system/sx/BreakpointsAsObject.js", "defaultCodeOpen": true}}

## Custom breakpoints

You can also specify your own custom breakpoints and use them as keys when defining the breakpoints object. Here is an example of how to do that.
mnajdova marked this conversation as resolved.
Show resolved Hide resolved

```jsx
import * as React from 'react';
import Box from '@material-ui/core/Box';
import { createMuiTheme, ThemeProvider } from '@material-ui/core/styles';

const theme = createMuiTheme({
breakpoints: {
values: {
tablet: 640,
laptop: 1024,
desktop: 1280,
},
},
});

export default function CustomBreakpoints() {
return (
<ThemeProvider theme={theme}>
<Box
sx={{
width: {
tablet: 100,
laptop: 300,
desktop: 500,
},
}}
>
This box has a responsive width
</Box>
</ThemeProvider>
);
}
```

If you are using TypeScript, you would also need to use [module augmentation](/guides/typescript/#customization-of-theme) for the theme to accept the above values.

```ts
declare module '@material-ui/core/styles/createBreakpoints' {
interface BreakpointOverrides {
xs: false; // removes the `xs` breakpoint
sm: false;
md: false;
lg: false;
xl: false;
tablet: true; // adds the `tablet` breakpoint
laptop: true;
desktop: true;
}
}
```
1 change: 1 addition & 0 deletions docs/translations/translations.json
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@
"/styles/basics": "Basics",
"/styles/advanced": "Advanced",
"/system": "System",
"/system/sx": "sx",
mnajdova marked this conversation as resolved.
Show resolved Hide resolved
"/system/basics": "Basics",
"/system/borders": "Borders",
"/system/display": "Display",
Expand Down