-
-
Notifications
You must be signed in to change notification settings - Fork 32.6k
[docs] Migrate batch of demos to hooks/typescript #16334
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
Merged
Merged
Changes from all commits
Commits
Show all changes
45 commits
Select commit
Hold shift + click to select a range
09c6651
customization/themes/CustomStyles
merceyz 7c3aa08
customization/themes/ThemeNesting
merceyz e174eca
customization/themes/ThemeNestingExtend
merceyz ddbad2a
customization/themes/WithTheme
merceyz 9fe3c29
customization/typography/FontSizeTheme
merceyz 97bb4b5
guides/composition/Composition
merceyz 7f0f153
guides/right-to-left/Direction
merceyz 7bb7350
styles/advanced/GlobalClassName
merceyz 844c9f6
styles/advanced/GlobalCss
merceyz a450b9c
styles/advanced/HybridGlobalCss
merceyz b8b3307
styles/advanced/ThemeNesting
merceyz 23c84df
styles/advanced/Theming
merceyz 6b06d02
styles/advanced/UseTheme
merceyz 5ac8911
styles/basics/HigherOrderComponent
merceyz 2e9867f
styles/basics/Hook
merceyz 5d6e594
styles/basics/StressTest
merceyz 0cc49ea
system/display/Block
merceyz e6bd917
system/display/Hiding
merceyz 2ec3786
system/display/Inline
merceyz 4baa830
system/display/Print
merceyz b27b2f4
system/display/Overflow
merceyz b4ceefb
system/display/TextOverflow
merceyz b8d845e
system/display/Visibility
merceyz d206421
system/display/WhiteSpace
merceyz 5be88b0
system/flexbox/AlignContent
merceyz 5f73a5c
system/flexbox/AlignItems
merceyz 4c8e278
system/flexbox/AlignSelf
merceyz 56971f3
system/flexbox/Display
merceyz d9fd29b
system/flexbox/FlexDirection
merceyz b1eb5a1
system/flexbox/FlexGrow
merceyz 9e45a3b
system/flexbox/FlexShrink
merceyz fd068d2
system/flexbox/FlexWrap
merceyz 83221df
system/flexbox/JustifyContent
merceyz d3801bc
system/flexbox/Order
merceyz f1eef8a
system/palette/BackgroundColor
merceyz e4c3624
system/palette/Color
merceyz 20faa0c
system/positions/ZIndex
merceyz 2167dcc
system/shadows/Demo
merceyz 9dd9f28
system/sizing/Height
merceyz 4bfd6e0
system/sizing/Values
merceyz 5cbd38c
system/sizing/Width
merceyz e3e0423
system/spacing/Demo
merceyz 9493f7c
system/spacing/HorizontalCentering
merceyz db5c04a
customization/themes/CustomStyles - Alias to AugmentedTheme
merceyz e0810a6
Prefer ThemeProvider<ThemeType>
eps1lon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,43 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import Checkbox from '@material-ui/core/Checkbox'; | ||
import { createMuiTheme, withStyles } from '@material-ui/core/styles'; | ||
import { createMuiTheme, makeStyles } from '@material-ui/core/styles'; | ||
import { ThemeProvider } from '@material-ui/styles'; | ||
import { orange } from '@material-ui/core/colors'; | ||
|
||
const styles = theme => ({ | ||
const useStyles = makeStyles(theme => ({ | ||
root: { | ||
color: theme.status.danger, | ||
'&$checked': { | ||
color: theme.status.danger, | ||
}, | ||
}, | ||
checked: {}, | ||
}); | ||
|
||
let CustomCheckbox = props => ( | ||
<Checkbox | ||
defaultChecked | ||
classes={{ | ||
root: props.classes.root, | ||
checked: props.classes.checked, | ||
}} | ||
/> | ||
); | ||
})); | ||
|
||
CustomCheckbox.propTypes = { | ||
classes: PropTypes.object.isRequired, | ||
}; | ||
function CustomCheckbox() { | ||
const classes = useStyles(); | ||
|
||
CustomCheckbox = withStyles(styles)(CustomCheckbox); | ||
return ( | ||
<Checkbox | ||
defaultChecked | ||
classes={{ | ||
root: classes.root, | ||
checked: classes.checked, | ||
}} | ||
/> | ||
); | ||
} | ||
|
||
const theme = createMuiTheme({ | ||
status: { | ||
// My business variables | ||
danger: orange[500], | ||
}, | ||
}); | ||
|
||
function CustomStyles() { | ||
export default function CustomStyles() { | ||
return ( | ||
<ThemeProvider theme={theme}> | ||
<CustomCheckbox /> | ||
</ThemeProvider> | ||
); | ||
} | ||
|
||
export default CustomStyles; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import React from 'react'; | ||
import Checkbox from '@material-ui/core/Checkbox'; | ||
import { | ||
createMuiTheme, | ||
makeStyles, | ||
createStyles, | ||
Theme as AugmentedTheme, | ||
} from '@material-ui/core/styles'; | ||
import { ThemeProvider } from '@material-ui/styles'; | ||
import { orange } from '@material-ui/core/colors'; | ||
|
||
declare module '@material-ui/core/styles/createMuiTheme' { | ||
interface Theme { | ||
status: { | ||
danger: string; | ||
}; | ||
} | ||
// allow configuration using `createMuiTheme` | ||
interface ThemeOptions { | ||
status?: { | ||
danger?: string; | ||
}; | ||
} | ||
} | ||
|
||
const useStyles = makeStyles((theme: AugmentedTheme) => | ||
createStyles({ | ||
root: { | ||
color: theme.status.danger, | ||
'&$checked': { | ||
color: theme.status.danger, | ||
}, | ||
}, | ||
checked: {}, | ||
}), | ||
); | ||
|
||
function CustomCheckbox() { | ||
const classes = useStyles(); | ||
merceyz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
return ( | ||
<Checkbox | ||
defaultChecked | ||
classes={{ | ||
root: classes.root, | ||
checked: classes.checked, | ||
}} | ||
/> | ||
); | ||
} | ||
|
||
const theme = createMuiTheme({ | ||
status: { | ||
danger: orange[500], | ||
}, | ||
}); | ||
|
||
export default function CustomStyles() { | ||
return ( | ||
<ThemeProvider theme={theme}> | ||
<CustomCheckbox /> | ||
</ThemeProvider> | ||
); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import React from 'react'; | ||
import { createMuiTheme } from '@material-ui/core/styles'; | ||
import { ThemeProvider } from '@material-ui/styles'; | ||
import Checkbox from '@material-ui/core/Checkbox'; | ||
import { green, orange } from '@material-ui/core/colors'; | ||
|
||
const outerTheme = createMuiTheme({ | ||
palette: { | ||
secondary: { | ||
main: orange[500], | ||
}, | ||
}, | ||
}); | ||
|
||
const innerTheme = createMuiTheme({ | ||
palette: { | ||
secondary: { | ||
main: green[500], | ||
}, | ||
}, | ||
}); | ||
|
||
export default function ThemeNesting() { | ||
return ( | ||
<ThemeProvider theme={outerTheme}> | ||
<Checkbox defaultChecked /> | ||
<ThemeProvider theme={innerTheme}> | ||
<Checkbox defaultChecked /> | ||
</ThemeProvider> | ||
</ThemeProvider> | ||
); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
docs/src/pages/customization/themes/ThemeNestingExtend.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import React from 'react'; | ||
import { createMuiTheme, Theme } from '@material-ui/core/styles'; | ||
import { ThemeProvider } from '@material-ui/styles'; | ||
import Checkbox from '@material-ui/core/Checkbox'; | ||
import { green, orange } from '@material-ui/core/colors'; | ||
|
||
const outerTheme = createMuiTheme({ | ||
palette: { | ||
secondary: { | ||
main: orange[500], | ||
}, | ||
}, | ||
}); | ||
|
||
export default function ThemeNestingExtend() { | ||
return ( | ||
<ThemeProvider theme={outerTheme}> | ||
<Checkbox defaultChecked /> | ||
<ThemeProvider | ||
theme={(theme: Theme) => | ||
createMuiTheme({ | ||
...theme, | ||
palette: { | ||
...theme.palette, | ||
primary: { | ||
main: green[500], | ||
}, | ||
}, | ||
}) | ||
} | ||
> | ||
<Checkbox defaultChecked color="primary" /> | ||
<Checkbox defaultChecked color="secondary" /> | ||
</ThemeProvider> | ||
</ThemeProvider> | ||
); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import Typography from '@material-ui/core/Typography'; | ||
import { withTheme, Theme } from '@material-ui/core/styles'; | ||
|
||
function WithTheme(props: { theme: Theme }) { | ||
oliviertassinari marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const { theme } = props; | ||
const primaryText = theme.palette.text.primary; | ||
const primaryColor = theme.palette.primary.main; | ||
|
||
const styles = { | ||
primaryText: { | ||
backgroundColor: theme.palette.background.default, | ||
padding: theme.spacing(1, 2), | ||
color: primaryText, | ||
}, | ||
primaryColor: { | ||
backgroundColor: primaryColor, | ||
padding: theme.spacing(1, 2), | ||
color: theme.palette.common.white, | ||
}, | ||
}; | ||
|
||
return ( | ||
<div style={{ width: 300 }}> | ||
<Typography style={styles.primaryColor}>{`Primary color ${primaryColor}`}</Typography> | ||
<Typography style={styles.primaryText}>{`Primary text ${primaryText}`}</Typography> | ||
</div> | ||
); | ||
} | ||
|
||
(WithTheme as any).propTypes = { | ||
theme: PropTypes.object.isRequired, | ||
}; | ||
|
||
export default withTheme(WithTheme); // Let's get the theme as a property |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import React from 'react'; | ||
import { createMuiTheme } from '@material-ui/core/styles'; | ||
import { ThemeProvider } from '@material-ui/styles'; | ||
import Typography from '@material-ui/core/Typography'; | ||
|
||
const theme = createMuiTheme({ | ||
typography: { | ||
// Tell Material-UI what the font-size on the html element is. | ||
htmlFontSize: 10, | ||
}, | ||
}); | ||
|
||
export default function FontSizeTheme() { | ||
return ( | ||
<ThemeProvider theme={theme}> | ||
<Typography>body1</Typography> | ||
</ThemeProvider> | ||
); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import React from 'react'; | ||
import IconButton from '@material-ui/core/IconButton'; | ||
import Icon, { IconProps } from '@material-ui/core/Icon'; | ||
|
||
const WrappedIcon = (props: IconProps) => <Icon {...props} />; | ||
WrappedIcon.muiName = 'Icon'; | ||
|
||
export default function Composition() { | ||
return ( | ||
<div> | ||
<IconButton> | ||
<Icon>alarm</Icon> | ||
</IconButton> | ||
<IconButton> | ||
<WrappedIcon>alarm</WrappedIcon> | ||
</IconButton> | ||
</div> | ||
); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import React from 'react'; | ||
import { createMuiTheme } from '@material-ui/core/styles'; | ||
import { ThemeProvider } from '@material-ui/styles'; | ||
import TextField from '@material-ui/core/TextField'; | ||
|
||
const theme = createMuiTheme({ | ||
direction: 'rtl', // Both here and <body dir="rtl"> | ||
}); | ||
|
||
export default function Direction() { | ||
return ( | ||
<ThemeProvider theme={theme}> | ||
<div dir="rtl"> | ||
<TextField placeholder="Name" /> | ||
<input type="text" placeholder="Name" /> | ||
</div> | ||
</ThemeProvider> | ||
); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import React from 'react'; | ||
import styled from 'styled-components'; | ||
import { TextField, NoSsr } from '@material-ui/core'; | ||
|
||
const StyledTextField = styled(TextField)` | ||
label.Mui-focused { | ||
color: green; | ||
} | ||
.MuiOutlinedInput-root { | ||
fieldset { | ||
border-color: red; | ||
} | ||
&:hover fieldset { | ||
border-color: yellow; | ||
} | ||
&.Mui-focused fieldset { | ||
border-color: green; | ||
} | ||
} | ||
`; | ||
|
||
export default function GlobalClassName() { | ||
return ( | ||
<NoSsr> | ||
<StyledTextField label="Deterministic" variant="outlined" id="deterministic-outlined-input" /> | ||
</NoSsr> | ||
); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.