1
1
mirror of https://github.com/jxnblk/mdx-deck.git synced 2024-11-26 00:35:02 +03:00
mdx-deck/docs/Counter.js
2019-03-03 17:29:04 -05:00

64 lines
1.1 KiB
JavaScript

import React from 'react'
import styled from '@emotion/styled'
import { space, color } from 'styled-system'
const Root = styled.div({
display: 'flex',
alignItems: 'center',
})
const Button = styled.button(
{
appearance: 'none',
fontFamily: 'inherit',
fontSize: 'inherit',
fontWeight: 'bold',
borderRadius: '4px',
border: 'none',
width: '2em',
'&:focus': {
outline: 'none',
boxShadow: '0 0 0 2px magenta',
},
},
space,
color
)
Button.defaultProps = {
m: 0,
px: 3,
py: 2,
color: 'background',
bg: 'text',
}
const Samp = styled.samp(space)
export default class Counter extends React.Component {
state = {
count: 0,
}
inc = () => {
this.setState(state => ({ count: state.count + 1 }))
}
dec = () => {
this.setState(state => ({ count: state.count - 1 }))
}
render() {
return (
<Root>
<Button ml="auto" onClick={this.dec}>
-
</Button>
<Samp mx={3}>{this.state.count}</Samp>
<Button mr="auto" onClick={this.inc}>
+
</Button>
</Root>
)
}
}