Skip to content

Commit 972c184

Browse files
committed
address comment, update epub settings menu and icon sizes
1 parent 6925fde commit 972c184

File tree

16 files changed

+190
-65
lines changed

16 files changed

+190
-65
lines changed

src/PdfReader/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ export default function usePdfReader(args: PdfReaderArguments): ReaderReturn {
267267
}, [state.scale]);
268268

269269
const rotateLeft = React.useCallback(async () => {
270-
dispatch({ type: 'ROTATE_LEFT' });
270+
dispatch({ type: 'ROTATE_COUNTER_CLOCKWISE' });
271271
}, []);
272272

273273
const goToPage = React.useCallback(async (href: string) => {

src/PdfReader/reducer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ export function makePdfReducer(
229229
case 'SET_FIT_MODE':
230230
return { ...state, fitMode: action.fitMode, scale: 1 };
231231

232-
case 'ROTATE_LEFT':
232+
case 'ROTATE_COUNTER_CLOCKWISE':
233233
return {
234234
...state,
235235
rotation: ((state.rotation ?? 0) - 90 + 360) % 360,

src/PdfReader/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,5 +64,5 @@ export type PdfReaderAction =
6464
width: number | undefined;
6565
}
6666
| { type: 'SET_FIT_MODE'; fitMode: FitMode }
67-
| { type: 'ROTATE_LEFT' }
67+
| { type: 'ROTATE_COUNTER_CLOCKWISE' }
6868
| { type: 'BOOK_BOUNDARY_CHANGED'; atStart: boolean; atEnd: boolean };

src/ui/Button.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@ const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
2929
height: '2rem',
3030
width: '2rem',
3131
}
32-
: {};
32+
: {
33+
border: '1px solid',
34+
borderColor: 'ui.typography.body',
35+
};
3336

3437
return <ChakraButton ref={ref} variant="solid" {...iconProps} {...props} />;
3538
}

src/ui/Header.tsx

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ import HtmlFontSizeControls from './HtmlFontSizeControls';
88
import {
99
PageDown,
1010
PageUp,
11-
Reset,
12-
Search,
11+
Rotate,
1312
ToggleFullScreen,
1413
ToggleFullScreenExit,
1514
} from './icons';
@@ -123,15 +122,15 @@ export default function Header(
123122
<Icon
124123
as={FitHeightWidth}
125124
fitMode={fitMode === 'width' ? 'width' : 'height'}
126-
w={6}
127-
h={6}
125+
w={18}
126+
h={18}
128127
/>
129128
</Button>
130129
</Tooltip>
131130
{type === 'PDF' && (
132131
<Tooltip content="Rotate left">
133132
<Button isIcon onClick={navigator.rotateLeft}>
134-
<Icon as={Reset} w={6} h={6} />
133+
<Icon as={Rotate} w={18} h={18} />
135134
</Button>
136135
</Tooltip>
137136
)}
@@ -144,7 +143,7 @@ export default function Header(
144143
isDisabled={currentPage <= 1}
145144
isIcon
146145
>
147-
<Icon as={PageUp} w={6} h={6} />
146+
<Icon as={PageUp} w={18} h={18} />
148147
</Button>
149148
</Tooltip>
150149
<HStack color="ui.white" spacing={2} fontSize="sm" alignItems="center">
@@ -176,16 +175,11 @@ export default function Header(
176175
isDisabled={currentPage >= totalPages}
177176
isIcon
178177
>
179-
<Icon as={PageDown} w={6} h={6} />
178+
<Icon as={PageDown} w={18} h={18} />
180179
</Button>
181180
</Tooltip>
182181
</HStack>
183182
<HStack ml="auto" spacing={2}>
184-
<Tooltip content="Search inside">
185-
<Button isIcon>
186-
<Icon as={Search} w={6} h={6} />
187-
</Button>
188-
</Tooltip>
189183
<TableOfContent
190184
containerRef={containerRef}
191185
navigator={navigator}
@@ -208,8 +202,8 @@ export default function Header(
208202
>
209203
<Icon
210204
as={isFullscreen ? ToggleFullScreenExit : ToggleFullScreen}
211-
w={6}
212-
h={6}
205+
w={18}
206+
h={18}
213207
/>
214208
</Button>
215209
</Tooltip>

src/ui/HtmlFontSizeControls.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export default function HtmlFontSizeControls(
2828
onClick={increaseFontSize}
2929
isIcon
3030
>
31-
<Icon as={ZoomIn} w={6} h={6} />
31+
<Icon as={ZoomIn} w={18} h={18} />
3232
</Button>
3333
</Tooltip>
3434
<Tooltip content="Decrease font size">
@@ -37,7 +37,7 @@ export default function HtmlFontSizeControls(
3737
onClick={decreaseFontSize}
3838
isIcon
3939
>
40-
<Icon as={ZoomOut} w={6} h={6} />
40+
<Icon as={ZoomOut} w={18} h={18} />
4141
</Button>
4242
</Tooltip>
4343
</ButtonGroup>

src/ui/HtmlSettings.tsx

Lines changed: 92 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
import { Box, Heading, Text } from '@chakra-ui/react';
1+
import { Box, ButtonGroup, Heading, Icon, Text } from '@chakra-ui/react';
22
import * as React from 'react';
3-
import { FONT_DETAILS } from '../constants';
4-
import { HtmlNavigator, ReaderState } from '../types';
3+
import { DEFAULT_SETTINGS, FONT_DETAILS } from '../constants';
4+
import { HtmlNavigator, ReaderSettings, ReaderState } from '../types';
5+
import Button from './Button';
56
import useColorModeValue from './hooks/useColorModeValue';
6-
import { Day, Night, Sepia } from './icons';
7+
import { Day, Night, Reset, Sepia, ZoomIn, ZoomOut } from './icons';
78
import Tabs from './Tabs';
89
import { ColorModeToggleButton } from './ToggleButton';
910
import ToggleGroup from './ToggleGroup';
@@ -30,7 +31,13 @@ export default function HtmlSettings(
3031
if (!readerState.settings) return null;
3132
const { colorMode, fontFamily } = readerState.settings;
3233

33-
const { setFontFamily, setColorMode } = navigator;
34+
const {
35+
decreaseFontSize,
36+
increaseFontSize,
37+
resetSettings,
38+
setFontFamily,
39+
setColorMode,
40+
} = navigator;
3441

3542
return (
3643
<>
@@ -66,6 +73,7 @@ export default function HtmlSettings(
6673
display="flex"
6774
flexDirection="column"
6875
p={4}
76+
gap={4}
6977
>
7078
<Heading
7179
as="h3"
@@ -116,7 +124,86 @@ export default function HtmlSettings(
116124
textColor="ui.black"
117125
/>
118126
</ToggleGroup>
127+
<ButtonGroup display="flex" spacing={4}>
128+
<Button
129+
onClick={resetSettings}
130+
aria-label="Reset settings"
131+
bgColor="ui.white"
132+
width="150px"
133+
>
134+
<Icon
135+
as={Reset}
136+
w={18}
137+
h={18}
138+
mr={1.5}
139+
sx={{
140+
path: { stroke: 'ui.typography.body' },
141+
}}
142+
/>
143+
Reset all
144+
</Button>
145+
<Button
146+
onClick={decreaseFontSize}
147+
aria-label="Increase text"
148+
bgColor="ui.white"
149+
width="150px"
150+
sx={{
151+
_active: {
152+
bgColor: checkedButtonBgColor,
153+
},
154+
}}
155+
>
156+
<Icon
157+
as={ZoomIn}
158+
w={18}
159+
h={18}
160+
mr={1.5}
161+
sx={{
162+
path: { stroke: 'ui.typography.body' },
163+
}}
164+
/>
165+
Increase text
166+
</Button>
167+
<Button
168+
onClick={increaseFontSize}
169+
aria-label="decrease text"
170+
bgColor="ui.white"
171+
width="150px"
172+
sx={{
173+
_active: {
174+
bgColor: checkedButtonBgColor,
175+
},
176+
}}
177+
>
178+
<Icon
179+
as={ZoomOut}
180+
w={18}
181+
h={18}
182+
mr={1.5}
183+
sx={{
184+
path: { stroke: 'ui.typography.body' },
185+
}}
186+
/>
187+
Decrease text
188+
</Button>
189+
</ButtonGroup>
119190
</Box>
120191
</>
121192
);
122193
}
194+
195+
// Returns true if the reader's settings match the default settings
196+
const areSettingsDefault = (readerSettings: ReaderSettings) => {
197+
if (!readerSettings) {
198+
return false;
199+
}
200+
201+
let setting: keyof ReaderSettings;
202+
203+
for (setting in DEFAULT_SETTINGS) {
204+
if (readerSettings[setting] !== DEFAULT_SETTINGS[setting]) {
205+
return false;
206+
}
207+
}
208+
return true;
209+
};

src/ui/PdfZoomControls.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ export default function PdfZoomControls(
2020
<ButtonGroup display="flex" spacing={2}>
2121
<Tooltip content="Zoom in">
2222
<Button aria-label="Zoom in" onClick={zoomIn} isIcon>
23-
<Icon as={ZoomIn} w={6} h={6} />
23+
<Icon as={ZoomIn} w={18} h={18} />
2424
</Button>
2525
</Tooltip>
2626
<Tooltip content="Zoom out">
2727
<Button aria-label="Zoom out" onClick={zoomOut} isIcon>
28-
<Icon as={ZoomOut} w={6} h={6} />
28+
<Icon as={ZoomOut} w={18} h={18} />
2929
</Button>
3030
</Tooltip>
3131
</ButtonGroup>

src/ui/SettingsButton.tsx

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {
2+
Box,
23
Icon,
34
Popover,
45
PopoverBody,
@@ -12,6 +13,7 @@ import Button from './Button';
1213
import useColorModeValue from './hooks/useColorModeValue';
1314
import HtmlSettings from './HtmlSettings';
1415
import { ReaderSettings } from './icons';
16+
import Tooltip from './Tooltip';
1517

1618
type SettingsCardProps =
1719
| Pick<PDFActiveReader, 'navigator' | 'state' | 'type'>
@@ -53,29 +55,33 @@ export default function SettingsCard(
5355
preventOverflow
5456
strategy="fixed"
5557
>
56-
<PopoverTrigger>
57-
<Button
58-
aria-label="Settings"
59-
onClick={open}
60-
/**
61-
* preventDefault fixes a Chakra bug where in Safari,
62-
* the PopoverTrigger will not close the Popover.
63-
* The issue is described in
64-
* https://github.com/chakra-ui/chakra-ui/issues/3461
65-
* and the workaround can be found in
66-
* https://github.com/chakra-ui/chakra-ui/issues/587.
67-
* */
68-
onMouseDown={(e: React.MouseEvent<HTMLButtonElement>) =>
69-
e.preventDefault()
70-
}
71-
bg={mainBgColor}
72-
border="none"
73-
gap={[0, 0, 2]}
74-
isIcon
75-
>
76-
<Icon as={ReaderSettings} w={6} h={6} />
77-
</Button>
78-
</PopoverTrigger>
58+
<Tooltip content="Settings">
59+
<Box display="inline-block">
60+
<PopoverTrigger>
61+
<Button
62+
aria-label="Settings"
63+
onClick={open}
64+
/**
65+
* preventDefault fixes a Chakra bug where in Safari,
66+
* the PopoverTrigger will not close the Popover.
67+
* The issue is described in
68+
* https://github.com/chakra-ui/chakra-ui/issues/3461
69+
* and the workaround can be found in
70+
* https://github.com/chakra-ui/chakra-ui/issues/587.
71+
* */
72+
onMouseDown={(e: React.MouseEvent<HTMLButtonElement>) =>
73+
e.preventDefault()
74+
}
75+
bg={mainBgColor}
76+
border="none"
77+
gap={[0, 0, 2]}
78+
isIcon
79+
>
80+
<Icon as={ReaderSettings} w={18} h={18} />
81+
</Button>
82+
</PopoverTrigger>
83+
</Box>
84+
</Tooltip>
7985
<PopoverContent
8086
overflow="hidden"
8187
bgColor={contentBgColor}

src/ui/TableOfContent.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export default function TableOfContent({
4646
me={0}
4747
isIcon
4848
>
49-
<Icon as={TableOfContents} w={6} h={6} />
49+
<Icon as={TableOfContents} w={18} h={18} />
5050
</MenuButton>
5151
</Tooltip>
5252
<Portal containerRef={containerRef}>

0 commit comments

Comments
 (0)