mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-01-04 01:42:42 +00:00
Changing input type to text removes the "spinner" controls from within the text box. The spinner buttons are an accessibility issue (the tiny buttons are tiny), and we already have better buttons for incrementing/decrementing page number. Text box only accepts numbers.
111 lines
2.4 KiB
JavaScript
111 lines
2.4 KiB
JavaScript
require('./toolBar.less');
|
|
const React = require('react');
|
|
const { useState, useEffect } = React;
|
|
const _ = require('lodash')
|
|
|
|
const MAX_ZOOM = 300;
|
|
const MIN_ZOOM = 10;
|
|
|
|
const ToolBar = ({ onZoomChange, currentPage, onPageChange, totalPages })=>{
|
|
|
|
const [zoomLevel, setZoomLevel] = useState(100);
|
|
const [pageInput, setPageInput] = useState(currentPage);
|
|
|
|
useEffect(()=>{
|
|
onZoomChange(zoomLevel);
|
|
}, [zoomLevel]);
|
|
|
|
useEffect(()=>{
|
|
setPageInput(currentPage);
|
|
}, [currentPage])
|
|
|
|
const handleZoomChange = (delta)=>{
|
|
const zoomChange = _.clamp(zoomLevel + delta, MIN_ZOOM, MAX_ZOOM);
|
|
|
|
setZoomLevel(zoomChange);
|
|
};
|
|
|
|
const handlePageChange = (page)=>{
|
|
setPageInput((page));
|
|
}
|
|
|
|
return (
|
|
<div className='toolBar'>
|
|
<div className='tool'>
|
|
<button
|
|
onClick={()=>handleZoomChange(-20)}
|
|
disabled={zoomLevel <= MIN_ZOOM}
|
|
>
|
|
<i className='fas fa-magnifying-glass-minus' />
|
|
</button>
|
|
</div>
|
|
<div className='tool'>
|
|
<input
|
|
className='slider'
|
|
type='range'
|
|
name='zoom'
|
|
list='zoomLevels'
|
|
min={MIN_ZOOM}
|
|
max={MAX_ZOOM}
|
|
step='1'
|
|
value={zoomLevel}
|
|
onChange={(e)=>{setZoomLevel(parseInt(e.target.value));}}
|
|
/>
|
|
<datalist id='zoomLevels'>
|
|
<option value='100' />
|
|
</datalist>
|
|
</div>
|
|
|
|
<div className='tool'>
|
|
<button
|
|
onClick={()=>handleZoomChange(20)}
|
|
disabled={zoomLevel >= MAX_ZOOM}
|
|
>
|
|
<i className='fas fa-magnifying-glass-plus' />
|
|
</button>
|
|
</div>
|
|
<div className='tool'>
|
|
<button
|
|
className='previousPage'
|
|
onClick={()=>{
|
|
console.log(`page is ${state.currentPage}`);
|
|
onPageChange(state.currentPage - 2);
|
|
}}
|
|
disabled={state.currentPage <= 1}
|
|
>
|
|
<i className='fas fa-arrow-left'></i>
|
|
</button>
|
|
</div>
|
|
|
|
<input
|
|
type='text'
|
|
name='page'
|
|
inputMode='numeric'
|
|
pattern='[0-9]'
|
|
id='pageInput'
|
|
value={pageInput}
|
|
onChange={(e)=>{
|
|
handlePageChange(e.target.value == false ? e.target.value : parseInt(e.target.value));}}
|
|
onBlur={()=>onPageChange(pageInput)}
|
|
/>
|
|
|
|
<div className='tool'>
|
|
<button
|
|
className='nextPage'
|
|
onClick={()=>{
|
|
console.log(
|
|
`page is ${state.currentPage} and i move to ${state.currentPage}`
|
|
);
|
|
onPageChange(state.currentPage);
|
|
}}
|
|
disabled={state.currentPage >= state.totalPages}
|
|
>
|
|
<i className='fas fa-arrow-right'></i>
|
|
</button>
|
|
</div>
|
|
</div>
|
|
);
|
|
};
|
|
|
|
module.exports = ToolBar;
|