Skip to content

Commit 74fdbbb

Browse files
committedAug 29, 2021
feat(website): update code according to react-markdown API changes
1 parent 5ba75a9 commit 74fdbbb

12 files changed

+85
-90
lines changed
 

‎website/src/components/Header.js

+6-8
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
import React from 'react'
22
import styled from 'styled-components'
3-
import HeaderNav from './HeaderNav'
3+
import { HeaderNav } from './HeaderNav'
44

5-
const Header = () => {
6-
return (
7-
<Container>
8-
<HeaderNav />
9-
</Container>
10-
)
11-
}
5+
const Header = () => (
6+
<Container>
7+
<HeaderNav />
8+
</Container>
9+
)
1210

1311
export default Header
1412

‎website/src/components/HeaderNav.js ‎website/src/components/HeaderNav.tsx

+1-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import media from '../theming/mediaQueries'
66
import * as nav from '../data/nav'
77
import ThemeSelector from './ThemeSelector'
88

9-
const HeaderNav = () => {
9+
export const HeaderNav = () => {
1010
return (
1111
<Container>
1212
<HeaderInternalLink to="/about">About</HeaderInternalLink>
@@ -58,8 +58,6 @@ const HeaderNav = () => {
5858
)
5959
}
6060

61-
export default HeaderNav
62-
6361
const Container = styled.nav`
6462
position: absolute;
6563
top: 0;

‎website/src/components/Markdown.js

+6-8
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { Link } from 'gatsby'
44
import ReactMarkdown from 'react-markdown'
55
import config from '../data/config'
66

7-
const linkRenderer = ({ href, children }) => {
7+
const link = ({ href, children }) => {
88
if (href.indexOf('self:') === 0) {
99
return <Link to={href.replace('self:', '')}>{children}</Link>
1010
}
@@ -24,15 +24,13 @@ const linkRenderer = ({ href, children }) => {
2424
)
2525
}
2626

27+
const customComponents = { a: link }
28+
2729
const Markdown = memo(({ source }) => {
2830
return (
29-
<ReactMarkdown
30-
source={source}
31-
transformLinkUri={u => u}
32-
renderers={{
33-
link: linkRenderer,
34-
}}
35-
/>
31+
<ReactMarkdown transformLinkUri={u => u} components={customComponents}>
32+
{source}
33+
</ReactMarkdown>
3634
)
3735
})
3836

‎website/src/components/ThemeSelector.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React, { useCallback, useMemo } from 'react'
22
import styled from 'styled-components'
33
import { useTheme } from '../theming/context'
44
import { useGlobalDispatch, useGlobalState } from './state'
5-
import Switch from './controls/Switch'
5+
import { Switch } from './controls/Switch'
66
// import useLocalStorage from '../lib/useLocalStorage'
77

88
const ThemeSelector = () => {
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import React, { memo, useCallback } from 'react'
2-
import PropTypes from 'prop-types'
32
import styled from 'styled-components'
43
import Control from './Control'
54
import PropertyHeader from './PropertyHeader'
@@ -10,30 +9,23 @@ const size = 36
109
const center = size / 2
1110
const markerSize = 6
1211

13-
const Row = styled.div`
14-
display: grid;
15-
grid-template-columns: 60px ${size}px auto;
16-
grid-column-gap: 9px;
17-
align-items: center;
18-
max-width: 240px;
19-
margin-bottom: 5px;
20-
`
21-
22-
const Circle = styled.circle`
23-
fill: ${({ theme }) => theme.colors.background};
24-
strokewidth: 1px;
25-
stroke: ${({ theme }) => theme.colors.border};
26-
`
27-
28-
const Line = styled.line`
29-
stroke: ${({ theme }) => theme.colors.accent};
30-
`
31-
32-
const Marker = styled.circle`
33-
fill: ${({ theme }) => theme.colors.accent};
34-
`
12+
interface AngleControlProps {
13+
id: string
14+
property: {
15+
description?: string
16+
}
17+
flavors: ('svg' | 'html' | 'canvas' | 'api')[]
18+
currentFlavor: 'svg' | 'html' | 'canvas' | 'api'
19+
value: number
20+
options: {
21+
start?: number
22+
min?: number
23+
max?: number
24+
}
25+
onChange: (v: number) => void
26+
}
3527

36-
const AngleControl = memo(({ id, property, flavors, currentFlavor, value, options, onChange }) => {
28+
export const AngleControl = memo(({ id, property, flavors, currentFlavor, value, options, onChange }: AngleControlProps) => {
3729
const start = options.start || 0
3830
const min = options.min || 0
3931
const max = options.max || 360
@@ -73,18 +65,25 @@ const AngleControl = memo(({ id, property, flavors, currentFlavor, value, option
7365
)
7466
})
7567

76-
AngleControl.propTypes = {
77-
id: PropTypes.string.isRequired,
78-
property: PropTypes.object.isRequired,
79-
flavors: PropTypes.arrayOf(PropTypes.oneOf(['svg', 'html', 'canvas', 'api'])).isRequired,
80-
currentFlavor: PropTypes.oneOf(['svg', 'html', 'canvas', 'api']).isRequired,
81-
value: PropTypes.number.isRequired,
82-
options: PropTypes.shape({
83-
start: PropTypes.number,
84-
min: PropTypes.number,
85-
max: PropTypes.number,
86-
}).isRequired,
87-
onChange: PropTypes.func.isRequired,
88-
}
68+
const Row = styled.div`
69+
display: grid;
70+
grid-template-columns: 60px ${size}px auto;
71+
grid-column-gap: 9px;
72+
align-items: center;
73+
max-width: 240px;
74+
margin-bottom: 5px;
75+
`
8976

90-
export default AngleControl
77+
const Circle = styled.circle`
78+
fill: ${({ theme }) => theme.colors.background};
79+
stroke-width: 1px;
80+
stroke: ${({ theme }) => theme.colors.border};
81+
`
82+
83+
const Line = styled.line`
84+
stroke: ${({ theme }) => theme.colors.accent};
85+
`
86+
87+
const Marker = styled.circle`
88+
fill: ${({ theme }) => theme.colors.accent};
89+
`

‎website/src/components/controls/ControlsGroup.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import OpacityControl from './OpacityControl'
1919
import LineWidthControl from './LineWidthControl'
2020
import MotionConfigControl from './MotionConfigControl'
2121
import NumberArrayControl from './NumberArrayControl'
22-
import AngleControl from './AngleControl'
22+
import { AngleControl } from './AngleControl'
2323
import OrdinalColorsControl from './OrdinalColorsControl'
2424
import InheritedColorControl from './InheritedColorControl'
2525
import BlendModeControl from './BlendModeControl'

‎website/src/components/controls/Help.js ‎website/src/components/controls/Help.tsx

+14-10
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,20 @@ import styled from 'styled-components'
33
import dedent from 'dedent-js'
44
import Markdown from '../Markdown'
55

6+
interface HelpProps {
7+
children?: string | undefined
8+
}
9+
10+
export const Help = ({ children }: HelpProps) => {
11+
if (!children) return null
12+
13+
return (
14+
<Container>
15+
<Markdown source={dedent(children)} />
16+
</Container>
17+
)
18+
}
19+
620
export const Container = styled.div`
721
display: inline;
822
font-size: 0.8rem;
@@ -16,13 +30,3 @@ export const Container = styled.div`
1630
color: ${({ theme }) => theme.colors.text};
1731
}
1832
`
19-
20-
export const Help = ({ children }) => {
21-
if (!children) return null
22-
23-
return (
24-
<Container>
25-
<Markdown source={dedent(children)} />
26-
</Container>
27-
)
28-
}

‎website/src/components/controls/MotionConfigControl.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import Control from './Control'
66
import PropertyHeader from './PropertyHeader'
77
import Radio from './Radio'
88
import Select from './Select'
9-
import Switch from './Switch'
9+
import { Switch } from './Switch'
1010
import { Help } from './Help'
1111

1212
const Row = styled.div`

‎website/src/components/controls/Switch.js ‎website/src/components/controls/Switch.tsx

+15-17
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,18 @@
11
import React, { memo, useCallback } from 'react'
2-
import PropTypes from 'prop-types'
32
import styled from 'styled-components'
43

5-
const Switch = memo(({ id, value, onChange, colors = {} }) => {
4+
interface SwitchProps {
5+
id: string
6+
value: boolean
7+
onChange: (v: boolean) => void
8+
colors?: {
9+
on?: string
10+
off?: string
11+
dot?: string
12+
}
13+
}
14+
15+
export const Switch = memo(({ id, value, onChange, colors = {} }: SwitchProps) => {
616
const handleChange = useCallback(event => onChange(event.target.checked), [onChange])
717

818
return (
@@ -19,27 +29,15 @@ const Switch = memo(({ id, value, onChange, colors = {} }) => {
1929
)
2030
})
2131

22-
Switch.displayName = 'Switch'
23-
Switch.propTypes = {
24-
id: PropTypes.string.isRequired,
25-
value: PropTypes.bool.isRequired,
26-
onChange: PropTypes.func.isRequired,
27-
colors: PropTypes.shape({
28-
on: PropTypes.string,
29-
off: PropTypes.string,
30-
dot: PropTypes.string,
31-
}),
32-
}
33-
34-
export default Switch
35-
3632
const Wrapper = styled.span`
3733
display: inline-block;
3834
vertical-align: text-bottom;
3935
margin: 0;
4036
`
4137

42-
const Input = styled.input`
38+
const Input = styled.input<{
39+
colors: SwitchProps['colors']
40+
}>`
4341
position: absolute;
4442
margin-left: -9999px;
4543
visibility: hidden;

‎website/src/components/controls/SwitchControl.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import PropTypes from 'prop-types'
33
import Control from './Control'
44
import PropertyHeader from './PropertyHeader'
55
import { Help } from './Help'
6-
import Switch from './Switch'
6+
import { Switch } from './Switch'
77

88
const SwitchControl = memo(({ id, property, flavors, currentFlavor, value, onChange }) => {
99
return (

‎website/src/components/controls/SwitchableRangeControl.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import Control from './Control'
66
import PropertyHeader from './PropertyHeader'
77
import { Help } from './Help'
88
import TextInput from './TextInput'
9-
import Switch from './Switch'
9+
import { Switch } from './Switch'
1010

1111
const SwitchRow = styled.div`
1212
display: flex;

‎website/src/components/controls/ValueFormatControl.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { components } from 'react-select'
55
import Control from './Control'
66
import PropertyHeader from './PropertyHeader'
77
import TextInput from './TextInput'
8-
import Switch from './Switch'
8+
import { Switch } from './Switch'
99
import Select from './Select'
1010
import { Help } from './Help'
1111
import { FaChevronUp, FaChevronDown } from 'react-icons/fa'

0 commit comments

Comments
 (0)
Please sign in to comment.