Skip to content

Commit 05a1764

Browse files
committed
feat: fix dozens
- simplifies most components - insert proptypes and defines some shapes - transforms all components into stateless and functional components - wraps components with proppy to give them state management and more - adds proppy and proppy react to the common fragment
1 parent 280e3ca commit 05a1764

File tree

22 files changed

+3044
-941
lines changed

22 files changed

+3044
-941
lines changed
+14-24
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,20 @@
1-
import React, { Component } from 'react'
1+
import React from 'react'
2+
import PropTypes from 'prop-types'
23
import classNames from 'classnames'
3-
import './styles.scss'
4-
5-
class Chat extends Component {
64

7-
constructor(props) {
8-
super(props)
9-
this.state ={
10-
isExpanded: false
11-
}
12-
}
5+
import Toggle from '../Toggle'
136

14-
toggleExpansion() {
15-
this.setState({ isExpanded: !this.state.isExpanded })
16-
}
17-
18-
render() {
19-
const classes = classNames({
20-
chat: true,
21-
expanded: this.state.isExpanded
22-
})
23-
return(
24-
<div onClick={() => this.toggleExpansion() } className={classes}></div>
25-
)
26-
}
7+
import './styles.scss'
278

28-
}
9+
const Chat = () => (
10+
<Toggle>
11+
{({ on, toggle }) => (
12+
<div
13+
className={classNames('chat', { expanded: on })}
14+
onClick={toggle}
15+
/>
16+
)}
17+
</Toggle>
18+
)
2919

3020
export default Chat
+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { Component } from 'react'
2+
import PropTypes from 'prop-types'
3+
4+
class Toggle extends Component {
5+
constructor(props) {
6+
super(props)
7+
this.state = { on: false }
8+
this.toggle = this.toggle.bind(this)
9+
}
10+
11+
toggle() {
12+
this.setState(prevState => ({ on: !prevState.on }))
13+
}
14+
15+
render() {
16+
return this.props.children({
17+
on: this.state.on,
18+
toggle: this.toggle
19+
})
20+
}
21+
}
22+
23+
Toggle.propTypes = {
24+
children: PropTypes.func.isRequired
25+
}
26+
27+
export default Toggle

0 commit comments

Comments
 (0)