diff --git a/apps/web/src/components/default-font/index.tsx b/apps/web/src/components/default-font/index.tsx new file mode 100644 index 000000000..0a909d18f --- /dev/null +++ b/apps/web/src/components/default-font/index.tsx @@ -0,0 +1,92 @@ +/* +This file is part of the Notesnook project (https://notesnook.com/) + +Copyright (C) 2022 Streetwriters (Private) Limited + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +*/ + +import { Flex, Slider, Text } from "@theme-ui/components"; +import { useEffect, useState } from "react"; +import Config from "../../utils/config"; +import DropdownButton from "../dropdown-button"; + +export function DefaultFont() { + const fonts = ["sans-serif", "serif", "monoSpace"]; + const getOptions = () => + Config.get("fontFamily", fonts).map((font) => ({ + title: () => capitalizeFirstLetter(font), + onClick: () => { + const newFonts = [font]; + for (const item of fonts) { + if (item !== font) { + newFonts.push(item); + } + } + Config.set("fontFamily", newFonts); + setOptions(getOptions()); + }, + key: font + })); + const [fontSize, setFontSize] = useState(Config.get("fontSize", 16)); + const [options, setOptions] = useState(getOptions()); + useEffect(() => { + console.log("options changed"); + }, [options]); + + return ( + + + { + setFontSize(parseInt(e.target.value)); + Config.set("fontSize", parseInt(e.target.value)); + }} + sx={{ width: "75%" }} + /> + + {`${fontSize}px`} + + + + + ); +} + +function capitalizeFirstLetter(string: string) { + return string.charAt(0).toUpperCase() + string.slice(1); +} diff --git a/apps/web/src/components/dropdown-button/index.js b/apps/web/src/components/dropdown-button/index.js index 98c56d51b..49e9099f4 100644 --- a/apps/web/src/components/dropdown-button/index.js +++ b/apps/web/src/components/dropdown-button/index.js @@ -21,14 +21,19 @@ import { Button, Flex } from "@theme-ui/components"; import { useMenuTrigger } from "../../hooks/use-menu"; import { ChevronDown } from "../icons"; -export default function DropdownButton({ title, options }) { +export default function DropdownButton(props) { const { openMenu } = useMenuTrigger(); + const { options, title, sx, buttonStyle, chevronStyle } = props; if (!options || !options.length) return null; return ( - +