import { HStack, VStack, SpanBox } from '../../elements/LayoutPrimitives'
import { Button } from '../../elements/Button'
import { StyledText } from '../../elements/StyledText'
import { styled, theme, ThemeId } from '../../tokens/stitches.config'
import {
ArrowsHorizontal,
ArrowsInLineHorizontal,
CaretLeft,
CaretRight,
Check,
} from '@phosphor-icons/react'
import { TickedRangeSlider } from '../../elements/TickedRangeSlider'
import { showSuccessToast } from '../../../lib/toastHelpers'
import { ReaderSettings } from '../../../lib/hooks/useReaderSettings'
import { useCallback, useState } from 'react'
import { updateTheme } from '../../../lib/themeUpdater'
import { LineHeightIncreaseIcon } from '../../elements/images/LineHeightIncreaseIconProps'
import { LineHeightDecreaseIcon } from '../../elements/images/LineHeightDecreaseIcon'
import * as Switch from '@radix-ui/react-switch'
import { useCurrentTheme } from '../../../lib/hooks/useCurrentTheme'
import { useDarkModeListener } from '../../../lib/hooks/useDarkModeListener'
type ReaderSettingsProps = {
readerSettings: ReaderSettings
}
const HorizontalDivider = styled(SpanBox, {
width: '100%',
height: '1px',
background: `${theme.colors.grayLine.toString()}`,
})
const FONT_FAMILIES = [
'Inter',
'System Default',
'Merriweather',
'Lora',
'Open Sans',
'Roboto',
'Newsreader',
'Lexend',
'Montserrat',
'Crimson Text',
'OpenDyslexic',
'Source Serif Pro',
'LXGWWenKai',
'AtkinsonHyperlegible',
'IBMPlexSans',
'Fraunces',
'Literata',
'SuperNotesPro',
]
type SettingsProps = {
readerSettings: ReaderSettings
setShowAdvanced: (show: boolean) => void
}
export function ReaderSettingsControl(props: ReaderSettingsProps): JSX.Element {
const [showAdvanced, setShowAdvanced] = useState(false)
return (
<>
{showAdvanced ? (
) : (
)}
>
)
}
function AdvancedSettings(props: SettingsProps): JSX.Element {
const { readerSettings } = props
return (
{
readerSettings.setJustifyText(checked)
}}
>
{
readerSettings.setHighContrastText(checked)
}}
>
{
readerSettings.setTextDirection(checked ? 'RTL' : 'LTR')
}}
>
{
readerSettings.setHighlightOnRelease(checked)
}}
>
)
}
const SwitchRoot = styled(Switch.Root, {
all: 'unset',
width: 42,
height: 25,
backgroundColor: '$thBorderColor',
borderRadius: '9999px',
position: 'relative',
WebkitTapHighlightColor: 'rgba(0, 0, 0, 0)',
'&:focus': { boxShadow: `0 0 0 2px $thBorderColor` },
'&[data-state="checked"]': { backgroundColor: '$thBorderColor' },
})
const SwitchThumb = styled(Switch.Thumb, {
display: 'block',
width: 21,
height: 21,
backgroundColor: '$thTextContrast2',
borderRadius: '9999px',
transition: 'transform 100ms',
transform: 'translateX(2px)',
willChange: 'transform',
'&[data-state="checked"]': { transform: 'translateX(19px)' },
})
const Label = styled('label', {
color: 'white',
fontSize: 15,
lineHeight: 1,
})
function BasicSettings(props: SettingsProps): JSX.Element {
const { readerSettings } = props
return (
)
}
type FontControlsProps = {
readerSettings: ReaderSettings
}
function FontControls(props: FontControlsProps): JSX.Element {
const { readerSettings } = props
const FontSelect = styled('select', {
pl: '5px',
height: '30px',
minWidth: '100px',
display: 'flex',
alignItems: 'center',
fontSize: '12px',
background: '$thBackground',
border: '1px solid $thBorderColor',
fontFamily: readerSettings.fontFamily,
textTransform: 'capitalize',
borderRadius: '4px',
})
const handleFontSizeChange = useCallback(
(value: number) => {
readerSettings.actionHandler('setFontSize', value)
},
[readerSettings]
)
return (
Font
) => {
const font = e.currentTarget.value
if (FONT_FAMILIES.indexOf(font) < 0) {
return
}
readerSettings.setFontFamily(font)
}}
>
{FONT_FAMILIES.map((family) => (
))}
)
}
type LayoutControlsProps = {
readerSettings: ReaderSettings
}
function LayoutControls(props: LayoutControlsProps): JSX.Element {
const { readerSettings } = props
const handleMarginWidthChange = useCallback(
(value: number) => {
readerSettings.setMarginWidth(value)
},
[readerSettings]
)
return (
<>
Margin
Line Height
{
props.readerSettings.setLineHeight(value)
}}
/>
>
)
}
export function ThemeSelector(): JSX.Element {
useDarkModeListener()
const { currentTheme, setCurrentTheme, resetSystemTheme } = useCurrentTheme()
return (
Themes
{
console.log('clicked use system')
updateTheme(ThemeId.System)
}}
>
{
if (event.target.checked) {
setCurrentTheme(ThemeId.System)
} else {
resetSystemTheme()
}
event.stopPropagation()
}}
>
)
}