-
-
Notifications
You must be signed in to change notification settings - Fork 32.8k
[docs] Improve documentation of the system #23294
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
Changes from 5 commits
eb5426b
4cc8ceb
4ce7687
e99de3b
cae9761
54d8a55
b8fb9dd
9b56867
e5978a4
d99cf00
c94ca93
79a7d8b
e07060a
acbc866
e2652f9
a1bafa7
f8e965d
aa081b8
b30e24b
14a908c
c029718
682a5a8
cb867a9
52720d5
dbd5026
35fe80e
c6a8d46
7fc6a78
d909c63
a19edd6
e28a683
87c118e
b0fa09c
e3808bb
01bc241
780d5fd
cc5f8c7
6a9108d
9d5bd14
2854661
8b7ea10
a34ae16
8c5823a
d50a6af
28eb893
b198753
6a8b944
64b51cc
47af380
18752f5
541d0b7
af31b6c
a9ca97f
dd7b9fa
5796085
34c4309
304116c
faee8de
71575b8
584b289
602d1d7
153a18d
6d66c80
16a1c95
357f73e
b824976
6a4630b
3101abd
9187099
90ba086
0b0670c
40fe4a7
cffb670
725c552
c0f2269
5514a6b
5e7fa1a
873490d
fb42502
cb35c1e
0f9a565
6d1c063
05b40fd
efab4f0
762b4cc
5924891
2ad356c
6007e3b
da64fea
5aa6192
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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 }; | ||
| }; |
| 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.
Outdated
Show resolved
Hide resolved
|
||
| </Box> | ||
| ); | ||
| } | ||
| 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.
Outdated
Show resolved
Hide resolved
|
||
| </Box> | ||
| ); | ||
| } | ||
| 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.
Outdated
Show resolved
Hide resolved
|
||
| </Box> | ||
| ); | ||
| } | ||
| 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.
Outdated
Show resolved
Hide resolved
|
||
| </Box> | ||
| ); | ||
| } | ||
| 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.
Outdated
Show resolved
Hide resolved
|
||
| </Box> | ||
| ); | ||
| } | ||
| 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.
Outdated
Show resolved
Hide resolved
|
||
| </Box> | ||
| ); | ||
| } | ||
| 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.
Outdated
Show resolved
Hide resolved
|
||
| </Box> | ||
| ); | ||
| } | ||
| 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.
Outdated
Show resolved
Hide resolved
|
||
| </Box> | ||
| ); | ||
| } | ||
| 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 | ||
mnajdova marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| 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. | ||
|
||
|
|
||
| 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.
Outdated
Show resolved
Hide resolved
mnajdova marked this conversation as resolved.
Outdated
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.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| # Value as function | ||
mnajdova marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| 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.
Outdated
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.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ## Breakpoints as array | ||
mnajdova marked this conversation as resolved.
Outdated
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.
Outdated
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.
Outdated
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.
Outdated
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; | ||
| } | ||
| } | ||
| ``` | ||
Uh oh!
There was an error while loading. Please reload this page.