-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[docs] Add AdaptingHook TypeScript demo (#16131)
* [docs] Add typescript version of AdaptingHook * [docs] Update duplicated demo
- Loading branch information
Showing
3 changed files
with
52 additions
and
8 deletions.
There are no files selected for viewing
This file contains 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 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 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,49 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { makeStyles, createStyles } from '@material-ui/styles'; | ||
import Button, { ButtonProps as MuiButtonProps } from '@material-ui/core/Button'; | ||
import { Omit } from '@material-ui/types'; | ||
|
||
interface Props { | ||
color: 'red' | 'blue'; | ||
} | ||
|
||
const useStyles = makeStyles( | ||
createStyles({ | ||
root: { | ||
background: (props: Props) => | ||
props.color === 'red' | ||
? 'linear-gradient(45deg, #FE6B8B 30%, #FF8E53 90%)' | ||
: 'linear-gradient(45deg, #2196F3 30%, #21CBF3 90%)', | ||
border: 0, | ||
borderRadius: 3, | ||
boxShadow: (props: Props) => | ||
props.color === 'red' | ||
? '0 3px 5px 2px rgba(255, 105, 135, .3)' | ||
: '0 3px 5px 2px rgba(33, 203, 243, .3)', | ||
color: 'white', | ||
height: 48, | ||
padding: '0 30px', | ||
margin: 8, | ||
}, | ||
}), | ||
); | ||
|
||
function MyButton(props: Props & Omit<MuiButtonProps, keyof Props>) { | ||
const { color, ...other } = props; | ||
const classes = useStyles(props); | ||
return <Button className={classes.root} {...other} />; | ||
} | ||
|
||
(MyButton as any).propTypes = { | ||
color: PropTypes.oneOf(['red', 'blue']).isRequired, | ||
}; | ||
|
||
export default function AdaptingHook() { | ||
return ( | ||
<React.Fragment> | ||
<MyButton color="red">Red</MyButton> | ||
<MyButton color="blue">Blue</MyButton> | ||
</React.Fragment> | ||
); | ||
} |