|
@@ -1,11 +1,45 @@
|
|
|
import clsx from "clsx";
|
|
import clsx from "clsx";
|
|
|
|
|
+import SliderUnstyled, {
|
|
|
|
|
+ sliderUnstyledClasses,
|
|
|
|
|
+} from "@mui/base/SliderUnstyled";
|
|
|
|
|
|
|
|
import toggleTheme from "../../../libs/toggleTheme";
|
|
import toggleTheme from "../../../libs/toggleTheme";
|
|
|
|
|
|
|
|
import styles from "../../../styles/chapter.module.scss";
|
|
import styles from "../../../styles/chapter.module.scss";
|
|
|
|
|
+import { useCallback } from "react";
|
|
|
|
|
|
|
|
-type FontSize = 1 | 2 | 3 | 4 | 5;
|
|
|
|
|
-const fontSizes: FontSize[] = [1, 2, 3, 4, 5];
|
|
|
|
|
|
|
+type FontSize = 12 | 14 | 16 | 18 | 20 | 24;
|
|
|
|
|
+const fontSizes: FontSize[] = [12, 14, 16, 18, 20, 24];
|
|
|
|
|
+
|
|
|
|
|
+const max = Math.max(...fontSizes);
|
|
|
|
|
+const min = Math.min(...fontSizes);
|
|
|
|
|
+
|
|
|
|
|
+const marks = [
|
|
|
|
|
+ {
|
|
|
|
|
+ value: 12,
|
|
|
|
|
+ label: "12px",
|
|
|
|
|
+ },
|
|
|
|
|
+ {
|
|
|
|
|
+ value: 14,
|
|
|
|
|
+ label: "14px",
|
|
|
|
|
+ },
|
|
|
|
|
+ {
|
|
|
|
|
+ value: 16,
|
|
|
|
|
+ label: "16px",
|
|
|
|
|
+ },
|
|
|
|
|
+ {
|
|
|
|
|
+ value: 18,
|
|
|
|
|
+ label: "18px",
|
|
|
|
|
+ },
|
|
|
|
|
+ {
|
|
|
|
|
+ value: 20,
|
|
|
|
|
+ label: "20px",
|
|
|
|
|
+ },
|
|
|
|
|
+ {
|
|
|
|
|
+ value: 24,
|
|
|
|
|
+ label: "24px",
|
|
|
|
|
+ },
|
|
|
|
|
+];
|
|
|
|
|
|
|
|
interface SettingsProps {
|
|
interface SettingsProps {
|
|
|
isSerif: boolean;
|
|
isSerif: boolean;
|
|
@@ -14,9 +48,23 @@ interface SettingsProps {
|
|
|
changeFontSize: (fontSize: FontSize) => void;
|
|
changeFontSize: (fontSize: FontSize) => void;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+function valuetext(value: number) {
|
|
|
|
|
+ return `${value}px`;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
const Settings = (props: SettingsProps) => {
|
|
const Settings = (props: SettingsProps) => {
|
|
|
const { isSerif, fontSize, changeIsSerif, changeFontSize } = props;
|
|
const { isSerif, fontSize, changeIsSerif, changeFontSize } = props;
|
|
|
|
|
|
|
|
|
|
+ const handleChangeFontSize = useCallback(
|
|
|
|
|
+ (add = 1) => {
|
|
|
|
|
+ const idx = fontSizes.findIndex((fs) => fs === fontSize);
|
|
|
|
|
+ changeFontSize(
|
|
|
|
|
+ fontSizes[Math.max(0, Math.min(fontSizes.length - 1, idx + add))]
|
|
|
|
|
+ );
|
|
|
|
|
+ },
|
|
|
|
|
+ [changeFontSize, fontSize]
|
|
|
|
|
+ );
|
|
|
|
|
+
|
|
|
return (
|
|
return (
|
|
|
<div className={styles["toolbar-inner"]}>
|
|
<div className={styles["toolbar-inner"]}>
|
|
|
<div className={styles["toolbar-display-title"]}>Display Options</div>
|
|
<div className={styles["toolbar-display-title"]}>Display Options</div>
|
|
@@ -61,44 +109,25 @@ const Settings = (props: SettingsProps) => {
|
|
|
</button>
|
|
</button>
|
|
|
</div>
|
|
</div>
|
|
|
<div className={styles["toolbar-display-label"]}>Sizes</div>
|
|
<div className={styles["toolbar-display-label"]}>Sizes</div>
|
|
|
- <div className="flex">
|
|
|
|
|
- <button
|
|
|
|
|
- className="mr-4"
|
|
|
|
|
- onClick={() =>
|
|
|
|
|
- changeFontSize(
|
|
|
|
|
- Math.max(Math.min(...fontSizes), fontSize - 1) as FontSize
|
|
|
|
|
- )
|
|
|
|
|
- }
|
|
|
|
|
- >
|
|
|
|
|
|
|
+ <div className="flex items-center">
|
|
|
|
|
+ <button className="mr-4" onClick={() => handleChangeFontSize(-1)}>
|
|
|
<svg className="w-5 h-5" viewBox="0 0 16 16">
|
|
<svg className="w-5 h-5" viewBox="0 0 16 16">
|
|
|
<use href="/icons.svg#font-dn"></use>
|
|
<use href="/icons.svg#font-dn"></use>
|
|
|
</svg>
|
|
</svg>
|
|
|
</button>
|
|
</button>
|
|
|
- <input
|
|
|
|
|
- className="w-0 flex-1"
|
|
|
|
|
- type="range"
|
|
|
|
|
- list="tickmarks"
|
|
|
|
|
|
|
+ <SliderUnstyled
|
|
|
|
|
+ aria-label="Font Size"
|
|
|
value={fontSize}
|
|
value={fontSize}
|
|
|
- min={1}
|
|
|
|
|
- max={5}
|
|
|
|
|
- step={1}
|
|
|
|
|
- onChange={(e) => changeFontSize(Number(e.target.value) as FontSize)}
|
|
|
|
|
|
|
+ getAriaValueText={valuetext}
|
|
|
|
|
+ step={null}
|
|
|
|
|
+ marks={marks}
|
|
|
|
|
+ min={min}
|
|
|
|
|
+ max={max}
|
|
|
|
|
+ className="w-0 flex-1"
|
|
|
|
|
+ classes={{ ...styles, root: styles.slider }}
|
|
|
|
|
+ onChange={(e, value) => changeFontSize(value as FontSize)}
|
|
|
/>
|
|
/>
|
|
|
- <datalist id="tickmarks">
|
|
|
|
|
- {fontSizes.map((fs) => (
|
|
|
|
|
- <option key={fs} value={fs}>
|
|
|
|
|
- {fs}
|
|
|
|
|
- </option>
|
|
|
|
|
- ))}
|
|
|
|
|
- </datalist>
|
|
|
|
|
- <button
|
|
|
|
|
- className="ml-4"
|
|
|
|
|
- onClick={() =>
|
|
|
|
|
- changeFontSize(
|
|
|
|
|
- Math.min(Math.max(...fontSizes), fontSize + 1) as FontSize
|
|
|
|
|
- )
|
|
|
|
|
- }
|
|
|
|
|
- >
|
|
|
|
|
|
|
+ <button className="ml-4" onClick={() => handleChangeFontSize(1)}>
|
|
|
<svg className="w-5 h-5" viewBox="0 0 16 16">
|
|
<svg className="w-5 h-5" viewBox="0 0 16 16">
|
|
|
<use href="/icons.svg#font-up"></use>
|
|
<use href="/icons.svg#font-up"></use>
|
|
|
</svg>
|
|
</svg>
|