Skip to content

Commit 75d089e

Browse files
committed
[docs] Add typescript version of AdaptingStyledComponents
1 parent 06ea15d commit 75d089e

File tree

4 files changed

+41
-9
lines changed

4 files changed

+41
-9
lines changed

docs/src/pages/styles/basics/AdaptingStyledComponents.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,11 @@ const MyButton = styled(({ color, ...other }) => <Button {...other} />)({
1919
margin: 8,
2020
});
2121

22-
function AdaptingStyledComponents() {
22+
export default function AdaptingStyledComponents() {
2323
return (
2424
<React.Fragment>
2525
<MyButton color="red">Red</MyButton>
2626
<MyButton color="blue">Blue</MyButton>
2727
</React.Fragment>
2828
);
2929
}
30-
31-
export default AdaptingStyledComponents;
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import React from 'react';
2+
import { styled } from '@material-ui/styles';
3+
import Button, { ButtonProps } from '@material-ui/core/Button';
4+
import { Omit } from '@material-ui/types';
5+
6+
interface MyButtonProps {
7+
color: 'red' | 'blue';
8+
}
9+
10+
const MyButton = styled(
11+
({ color, ...other }: MyButtonProps & Omit<ButtonProps, keyof MyButtonProps>) => (
12+
<Button {...other} />
13+
),
14+
)({
15+
background: (props: MyButtonProps) =>
16+
props.color === 'red'
17+
? 'linear-gradient(45deg, #FE6B8B 30%, #FF8E53 90%)'
18+
: 'linear-gradient(45deg, #2196F3 30%, #21CBF3 90%)',
19+
border: 0,
20+
borderRadius: 3,
21+
boxShadow: (props: MyButtonProps) =>
22+
props.color === 'red'
23+
? '0 3px 5px 2px rgba(255, 105, 135, .3)'
24+
: '0 3px 5px 2px rgba(33, 203, 243, .3)',
25+
color: 'white',
26+
height: 48,
27+
padding: '0 30px',
28+
margin: 8,
29+
});
30+
31+
export default function AdaptingStyledComponents() {
32+
return (
33+
<React.Fragment>
34+
<MyButton color="red">Red</MyButton>
35+
<MyButton color="blue">Blue</MyButton>
36+
</React.Fragment>
37+
);
38+
}

docs/src/pages/system/basics/JSS.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,10 @@ const Box = styled('div')(
99
),
1010
);
1111

12-
function JSS() {
12+
export default function JSS() {
1313
return (
1414
<Box color="white" bgcolor="palevioletred" p={1}>
1515
JSS
1616
</Box>
1717
);
1818
}
19-
20-
export default JSS;

docs/src/pages/system/basics/JSS.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,10 @@ const Box = styled('div')(
99
),
1010
);
1111

12-
function JSS() {
12+
export default function JSS() {
1313
return (
1414
<Box color="white" bgcolor="palevioletred" p={1}>
1515
JSS
1616
</Box>
1717
);
1818
}
19-
20-
export default JSS;

0 commit comments

Comments
 (0)