Extract DurationSelector to its own component

This commit is contained in:
rui hildt 2020-06-02 11:17:10 +02:00
parent 0d6ed2accb
commit f03fc0c461
2 changed files with 38 additions and 28 deletions

View File

@ -0,0 +1,31 @@
import React, {useState} from 'react';
import { InputGroup, Icon } from 'rsuite';
import { durations } from '../../assets/data/durations';
export default function DurationSelector() {
const [durationIdx, setDurationIdx] = useState(0);
const handleIncrement = () => {
if (durationIdx <= durations.length - 2) {
setDurationIdx(durationIdx + 1);
}
};
const handleDecrement = () => {
if (durationIdx > 0) {
setDurationIdx(durationIdx - 1);
}
};
return (
<InputGroup style={{ background: 'white' }}>
<InputGroup.Button onClick={handleDecrement}>
<Icon icon='minus' />
</InputGroup.Button>
<div style={{ textAlign: 'center', paddingTop: 5 }}>
{durations[durationIdx].label}
</div>
<InputGroup.Button onClick={handleIncrement}>
<Icon icon='plus' />
</InputGroup.Button>
</InputGroup>
);
}

View File

@ -4,29 +4,17 @@ import {
Form, Form,
FormControl, FormControl,
FormGroup, FormGroup,
InputGroup,
Input, Input,
Divider,
Icon, Icon,
} from 'rsuite'; } from 'rsuite';
import { DateTime } from 'luxon';
import TimezonePicker from '../components/General/TimezonePicker'; import TimezonePicker from '../components/General/TimezonePicker';
import DaySelector from '../components/Schedule/DaySelector'; import DaySelector from '../components/Schedule/DaySelector';
import { durations } from '../assets/data/durations'; import DurationSelector from '../components/Schedule/DurationSelector';
export default function Schedule() { export default function Schedule() {
const [durationIdx, setDurationIdx] = useState(0);
const handleIncrement = () => {
if (durationIdx <= durations.length - 2) {
setDurationIdx(durationIdx + 1);
}
};
const handleDecrement = () => {
if (durationIdx > 0) {
setDurationIdx(durationIdx - 1);
}
};
return ( return (
<Container> <Container>
<h3>Schedule a meeting</h3> <h3>Schedule a meeting</h3>
@ -47,20 +35,11 @@ export default function Schedule() {
<TimezonePicker /> <TimezonePicker />
</FormGroup> </FormGroup>
<FormGroup style={{ width: 200 }}> <FormGroup style={{ width: 200 }}>
<InputGroup style={{ background: 'white' }}> <DurationSelector />
<InputGroup.Button onClick={handleDecrement}>
<Icon icon='minus' />
</InputGroup.Button>
<div style={{ textAlign: 'center', paddingTop: 5 }}>
{durations[durationIdx].label}
</div>
<InputGroup.Button onClick={handleIncrement}>
<Icon icon='plus' />
</InputGroup.Button>
</InputGroup>
</FormGroup> </FormGroup>
<FormGroup>
<DaySelector /> <DaySelector />
<FormGroup></FormGroup> </FormGroup>
</Form> </Form>
</Container> </Container>
); );