diff --git a/packages/web/components/templates/article/ArticleActionsMenu.tsx b/packages/web/components/templates/article/ArticleActionsMenu.tsx index c8e0fb9c4..e085bd42b 100644 --- a/packages/web/components/templates/article/ArticleActionsMenu.tsx +++ b/packages/web/components/templates/article/ArticleActionsMenu.tsx @@ -16,6 +16,7 @@ type ArticleActionsMenuProps = { layout: ArticleActionsMenuLayout lineHeight: number marginWidth: number + fontFamily: string showReaderDisplaySettings?: boolean articleActionHandler: (action: string, arg?: unknown) => void } @@ -81,6 +82,7 @@ export function ArticleActionsMenu(props: ArticleActionsMenuProps): JSX.Element } > ) -} \ No newline at end of file +} diff --git a/packages/web/components/templates/article/DisplaySettingsModal.tsx b/packages/web/components/templates/article/DisplaySettingsModal.tsx index 06b15a47d..e8abbec77 100644 --- a/packages/web/components/templates/article/DisplaySettingsModal.tsx +++ b/packages/web/components/templates/article/DisplaySettingsModal.tsx @@ -17,7 +17,8 @@ type DisplaySettingsModalProps = { onOpenChange: (open: boolean) => void lineHeight: number marginWidth: number - articleActionHandler: (action: string, arg?: number) => void + fontFamily: string + articleActionHandler: (action: string, arg?: number | string) => void } export function DisplaySettingsModal(props: DisplaySettingsModalProps): JSX.Element { @@ -54,6 +55,7 @@ export function DisplaySettingsModal(props: DisplaySettingsModalProps): JSX.Elem diff --git a/packages/web/components/templates/article/FontFamiliesOptions.tsx b/packages/web/components/templates/article/FontFamiliesOptions.tsx new file mode 100644 index 000000000..7ea01d8f9 --- /dev/null +++ b/packages/web/components/templates/article/FontFamiliesOptions.tsx @@ -0,0 +1,74 @@ +import { HStack, Box } from '../../elements/LayoutPrimitives' +import { StyledText } from '../../elements/StyledText' +import { theme } from '../../tokens/stitches.config' +import { CaretLeft, CheckCircle } from 'phosphor-react' + +const FONT_FAMILIES = [ + 'Inter', + 'System Default', + 'Merriweather', + 'Lora', + 'Open Sans', + 'Roboto', + 'Crimson Text', + 'Source Serif Pro' +] + +type FontFamiliesListProps = { + selected: string + setShowFontFamilies: (value: boolean) => void + onSelect: (value: string) => void +} + +type FontOptionProps = { + family: string + selected: string + onSelect: (value: string) => void +} + +function FontOption(props: FontOptionProps):JSX.Element { + const isSelected = props.selected === props.family + return ( + + props.onSelect(props.family)} + > + {props.family} + + {isSelected && ( + + )} + + ) +} + +export function FontFamiliesOptions(props: FontFamiliesListProps): JSX.Element { + return ( + <> + + + props.setShowFontFamilies(false)} + > + + + + + Back + + + {/* Select Font */} + + + + {FONT_FAMILIES.map((family) => ( + + ))} + + + ) +} diff --git a/packages/web/components/templates/article/ReaderSettingsControl.tsx b/packages/web/components/templates/article/ReaderSettingsControl.tsx index 8133d2004..6ba40114a 100644 --- a/packages/web/components/templates/article/ReaderSettingsControl.tsx +++ b/packages/web/components/templates/article/ReaderSettingsControl.tsx @@ -1,20 +1,20 @@ -import { HStack, VStack, SpanBox } from '../../elements/LayoutPrimitives' +import { HStack, VStack, SpanBox, Box } from '../../elements/LayoutPrimitives' import { Button } from '../../elements/Button' import { StyledText } from '../../elements/StyledText' import { styled, theme } from '../../tokens/stitches.config' import { useEffect, useState } from 'react' -import { AlignCenterHorizontalSimple, ArrowsInLineHorizontal, ArrowsOutLineHorizontal, Minus, Pen, Plus, Trash, X } from 'phosphor-react' -import { AIcon } from '../../elements/images/AIcon' +import { AlignCenterHorizontalSimple, ArrowsInLineHorizontal, ArrowsOutLineHorizontal, CaretRight } from 'phosphor-react' import { TickedRangeSlider } from '../../elements/TickedRangeSlider' import { showSuccessToast } from '../../../lib/toastHelpers' -import Image from 'next/image' import { FontStepperDown } from '../../elements/images/FontStepperDown' import { FontStepperUp } from '../../elements/images/FontStepperUp' +import { FontFamiliesOptions } from './FontFamiliesOptions' type ReaderSettingsProps = { marginWidth: number lineHeight: number - articleActionHandler: (action: string, arg?: number) => void + fontFamily: string + articleActionHandler: (action: string, arg?: number | string) => void } const VerticalDivider = styled(SpanBox, { @@ -23,110 +23,161 @@ const VerticalDivider = styled(SpanBox, { background: `${theme.colors.grayLine.toString()}`, }) +const HorizontalDivider = styled(SpanBox, { + width: '100%', + height: '1px', + background: `${theme.colors.grayLine.toString()}`, +}) + export function ReaderSettingsControl(props: ReaderSettingsProps): JSX.Element { const [lineHeight, setLineHeight] = useState(props.lineHeight) const [marginWidth, setMarginWidth] = useState(props.marginWidth) + const [fontFamily, setFontFamily] = useState(props.fontFamily) + + const [showFontOptions, setShowFontOptions] = useState(false) useEffect(() => { setLineHeight(props.lineHeight) setMarginWidth(props.marginWidth) - }, [props.lineHeight, props.marginWidth, setLineHeight, setMarginWidth]) + setFontFamily(props.fontFamily) + }, [props.lineHeight, props.marginWidth, props.fontFamily, setLineHeight, setMarginWidth, setFontFamily]) return ( - - - - - - { + setFontFamily(font) + props.articleActionHandler('setFontFamily', font) + }} + /> + ) : ( + <> + + + + + + + Font: + setShowFontOptions(true)} + > + + {fontFamily} + + + + + + + + + Margin: + + + { + setMarginWidth(value) + props.articleActionHandler('setMarginWidth', value) + }} /> + + + + + + + - Margin: - - - { - setMarginWidth(value) - props.articleActionHandler('setMarginWidth', value) - }} /> - + }}> + Line Spacing: + + + { + setLineHeight(value) + props.articleActionHandler('setLineHeight', value) + }} /> + + + + - - - - Line Spacing: - - - { - setLineHeight(value) - props.articleActionHandler('setLineHeight', value) - }} /> - - - - - + + )} ) } diff --git a/packages/web/lib/hooks/useReaderSettings.tsx b/packages/web/lib/hooks/useReaderSettings.tsx index d0a32492e..a6d254143 100644 --- a/packages/web/lib/hooks/useReaderSettings.tsx +++ b/packages/web/lib/hooks/useReaderSettings.tsx @@ -3,6 +3,8 @@ import { userPersonalizationMutation } from "../networking/mutations/userPersona import { useGetUserPreferences, UserPreferences } from "../networking/queries/useGetUserPreferences" import { usePersistedState } from "./usePersistedState" +const DEFAULT_FONT = 'Inter' + export type ReaderSettings = { preferencesData: UserPreferences | undefined fontSize: number @@ -20,6 +22,9 @@ export type ReaderSettings = { setShowEditDisplaySettingsModal: (showEditDisplaySettingsModal: boolean) => void actionHandler: (action: string, arg?: unknown) => void + + fontFamily: string, + setFontFamily: (newStyle: string) => void } export const useReaderSettings = (): ReaderSettings => { @@ -27,6 +32,7 @@ export const useReaderSettings = (): ReaderSettings => { const [fontSize, setFontSize] = useState(preferencesData?.fontSize ?? 20) const [lineHeight, setLineHeight] = usePersistedState({ key: 'lineHeight', initialValue: 150 }) const [marginWidth, setMarginWidth] = usePersistedState({ key: 'marginWidth', initialValue: 200 }) + const [fontFamily, setFontFamily] = usePersistedState({ key: 'fontFamily', initialValue: DEFAULT_FONT }) const [showSetLabelsModal, setShowSetLabelsModal] = useState(false) const [showEditDisplaySettingsModal, setShowEditDisplaySettingsModal] = useState(false) @@ -67,6 +73,10 @@ export const useReaderSettings = (): ReaderSettings => { setShowEditDisplaySettingsModal(true) break } + case 'setFontFamily': { + setFontFamily(arg as unknown as string) + break + } case 'setLabels': { setShowSetLabelsModal(true) break @@ -75,11 +85,12 @@ export const useReaderSettings = (): ReaderSettings => { updateFontSize(20) setMarginWidth(290) setLineHeight(150) + setFontFamily(DEFAULT_FONT) break } } - }, [fontSize, setFontSize, lineHeight, - setLineHeight, marginWidth, setMarginWidth]) + }, [fontSize, setFontSize, lineHeight, fontFamily, + setLineHeight, marginWidth, setMarginWidth, setFontFamily]) return { preferencesData, @@ -87,6 +98,6 @@ export const useReaderSettings = (): ReaderSettings => { setFontSize, setLineHeight, setMarginWidth, showSetLabelsModal, showEditDisplaySettingsModal, setShowSetLabelsModal, setShowEditDisplaySettingsModal, - actionHandler, + actionHandler, setFontFamily, fontFamily, } -} \ No newline at end of file +} diff --git a/packages/web/pages/[username]/[slug]/index.tsx b/packages/web/pages/[username]/[slug]/index.tsx index 9b756ca3c..8a8da1a92 100644 --- a/packages/web/pages/[username]/[slug]/index.tsx +++ b/packages/web/pages/[username]/[slug]/index.tsx @@ -151,6 +151,7 @@ export default function Home(): JSX.Element { readerSettings.setShowEditDisplaySettingsModal(false)} /> diff --git a/packages/web/pages/[username]/links/[id].tsx b/packages/web/pages/[username]/links/[id].tsx index 343ecf773..b5a57c2ae 100644 --- a/packages/web/pages/[username]/links/[id].tsx +++ b/packages/web/pages/[username]/links/[id].tsx @@ -33,6 +33,7 @@ export default function ArticleSavingRequestPage(): JSX.Element { = (args: any) => { return (
- { + { console.log('articleActionHandler') }} />