Skip to content

Commit

Permalink
Toggle jump links separately on mobile
Browse files Browse the repository at this point in the history
Also update styles
  • Loading branch information
alinnert committed Oct 15, 2024
1 parent a088948 commit 656c340
Show file tree
Hide file tree
Showing 13 changed files with 100 additions and 51 deletions.
11 changes: 2 additions & 9 deletions src/components/App/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ import {
mdiArrowLeft,
mdiCheck,
mdiCogOutline,
mdiDockLeft,
mdiImage,
mdiListStatus,
mdiNoteTextOutline,
mdiNoteTextOutline
} from '@mdi/js'
import { FC } from 'react'
import { useIsCurrentAppMode } from '../../stores/appMode/appModeHooks'
Expand Down Expand Up @@ -52,7 +51,7 @@ export const WebdevHome: FC = () => {
<AppLayout
sidebar={
isCurrentAppMode(AppMode.default, AppMode.customize) &&
toggleJumpLinks.showJumpLinks ? (
toggleJumpLinks.showJumpLinks || toggleJumpLinks.showJumpLinksMobile ? (
<JumpLinks />
) : null
}
Expand Down Expand Up @@ -101,12 +100,6 @@ export const WebdevHome: FC = () => {
visible={isCurrentAppMode(AppMode.default)}
/>
<AppMenuDivider />
<AppMenuItem
label="Show group list"
icon={<MdiIcon path={mdiDockLeft} />}
selected={toggleJumpLinks.showJumpLinks}
action={toggleJumpLinks.toggle}
/>
<AppMenuItem
label="Show link info"
icon={<MdiIcon path={mdiNoteTextOutline} />}
Expand Down
17 changes: 15 additions & 2 deletions src/components/App/useToggleJumpLinks.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
import { useCallback } from 'react'
import { useAppDispatch, useAppSelector } from '../../stores'
import { setDisplayJumpLinks } from '../../stores/appSettings/appSettingsActions'
import {
setDisplayJumpLinks,
setDisplayJumpLinksMobile,
} from '../../stores/appSettings/appSettingsActions'

type UseToggleJumpLinksResult = {
showJumpLinks: boolean
showJumpLinksMobile: boolean
toggle: () => void
toggleMobile: () => void
}

export function useToggleJumpLinks(): UseToggleJumpLinksResult {
Expand All @@ -14,9 +19,17 @@ export function useToggleJumpLinks(): UseToggleJumpLinksResult {
(state) => state.appSettings.showJumpLinks,
)

const showJumpLinksMobile = useAppSelector(
(state) => state.appSettings.showJumpLinksMobile,
)

const toggle = useCallback(() => {
dispatch(setDisplayJumpLinks(!showJumpLinks))
}, [dispatch, showJumpLinks])

return { showJumpLinks, toggle }
const toggleMobile = useCallback(() => {
dispatch(setDisplayJumpLinksMobile(!showJumpLinksMobile))
}, [dispatch, showJumpLinksMobile])

return { showJumpLinks, showJumpLinksMobile, toggle, toggleMobile }
}
20 changes: 12 additions & 8 deletions src/components/Header/AppAction.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ export const AppAction: FC<Props> = ({
<div
className={classNames(
'flex items-center',
'px-3 py-1.5',
'p-1.5',
{ 'sm:px-3': label !== undefined },
'rounded-md',
'select-none',
{
Expand All @@ -45,13 +46,16 @@ export const AppAction: FC<Props> = ({
onClick={action}
>
<MdiIcon path={icon} />
<div
className={classNames('ml-2 text-sm font-semibold', {
'hidden lg:block': !highlight,
})}
>
{label}
</div>

{label !== undefined ? (
<div
className={classNames('ml-2 text-sm font-semibold', {
'hidden lg:block': !highlight,
})}
>
{label}
</div>
) : null}
</div>
)
}
19 changes: 17 additions & 2 deletions src/components/Header/AppHeader.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { mdiClose, mdiMenu } from '@mdi/js'
import classNames from 'classnames'
import { FC, ReactElement } from 'react'
import { useToggleJumpLinks } from '../App/useToggleJumpLinks'
import { AppAction } from './AppAction'
import { Logo } from './Logo'

interface Props {
Expand All @@ -8,16 +11,28 @@ interface Props {
}

export const AppHeader: FC<Props> = ({ centerItems, actions }) => {
const toggleJumpLinks = useToggleJumpLinks()

function handleMenuClick() {
// TODO: if (mobile) { toggleJumpLinks.toggleMobile() } else { toggleJumpLinks.toggle() }
}

return (
<div
className={classNames(
'grid items-center',
'grid-cols-[1fr,auto] grid-rows-[auto,auto] md:grid-cols-[1fr,auto,1fr] md:grid-rows-1',
'px-page',
'bg-white/20 dark:bg-black/20',
'bg-white/30 dark:bg-black/30',
)}
>
<Logo />
<div className="flex items-center gap-x-2">
<AppAction
icon={toggleJumpLinks.showJumpLinksMobile ? mdiClose : mdiMenu}
action={handleMenuClick}
/>
<Logo />
</div>

{centerItems !== null ? (
<div className="col-span-2 row-start-2 flex items-center gap-x-1 justify-self-center py-2 md:col-span-1 md:col-start-2 md:row-start-1">
Expand Down
4 changes: 1 addition & 3 deletions src/components/Header/Logo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,13 @@ export const Logo: FC = () => {
return (
<div
className={classNames(
'font-mono text-2xl',
'font-mono text-xl',
'text-gray-400 dark:text-gray-200',
'select-none text-nowrap',
)}
>
<span>&lt;</span>
<span className="text-brand-500 dark:text-brand-300">Webdev</span>
<span className="text-brand-800 dark:text-brand-100">Home</span>
<span> /&gt;</span>
</div>
)
}
40 changes: 16 additions & 24 deletions src/components/JumpLinks/JumpLinks.tsx
Original file line number Diff line number Diff line change
@@ -1,35 +1,27 @@
import { mdiChevronDown, mdiChevronUp } from '@mdi/js'
import classNames from 'classnames'
import { FC, useState } from 'react'
import { MdiIcon } from '../Icon/MdiIcon'
import { JumpLink } from './JumpLink'
import { FC } from 'react'
import { links } from '../../links'
import { useAllLinksInGroupAreHidden } from '../../stores/hiddenLinks/hiddenLinksHooks'
import { useToggleJumpLinks } from '../App/useToggleJumpLinks'
import { JumpLink } from './JumpLink'

export const JumpLinks: FC = () => {
const allLinksInGroupAreHidden = useAllLinksInGroupAreHidden()

const [isOpen, setIsOpen] = useState(false)

function handleToggleClick() {
setIsOpen(!isOpen)
}
const toggleJumpLinks = useToggleJumpLinks()

return (
<div className="jump-links px-page w-[300px] py-4">
<div
className="flex cursor-default select-none items-center gap-x-2 dark:text-white md:hidden"
onClick={handleToggleClick}
>
<MdiIcon path={isOpen ? mdiChevronUp : mdiChevronDown}></MdiIcon>
<div>Jump to</div>
</div>
<div
className={classNames('flex flex-col gap-1 md:flex', {
hidden: !isOpen,
block: isOpen,
})}
>
<div
className={classNames(
'fixed top-10 lg:static',
'bg-white dark:bg-black lg:bg-white/20 dark:lg:bg-black/20',
'jump-links px-page w-[300px] py-4',
{
'left-0': toggleJumpLinks.showJumpLinksMobile,
'-left-full': !toggleJumpLinks.showJumpLinksMobile,
},
)}
>
<div className={classNames('flex flex-col gap-1 md:flex')}>
{links.items
.filter((group) => !allLinksInGroupAreHidden(group))
.map((linkGroup, index) => (
Expand Down
2 changes: 1 addition & 1 deletion src/components/Links/LinkGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export const LinkGroup: FC<Props> = ({ group }) => {
}

return (
<div id={slugify(group.name)} className="scroll-mt-20">
<div id={slugify(group.name)} className="scroll-mt-4">
<div className="mb-2 flex gap-x-1">
<div
className={classNames(
Expand Down
13 changes: 13 additions & 0 deletions src/stores/appSettings/appSettingsActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export const enum SettingsActions {
setTheme,
setDisplayDescription,
setDisplayJumpLinks,
setDisplayJumpLinksMobile,
setDisplayBackground,
}

Expand All @@ -22,6 +23,11 @@ type SetDisplayJumpLinksAction = {
payload: boolean
}

type SetDisplayJumpLinksMobileAction = {
type: SettingsActions.setDisplayJumpLinksMobile
payload: boolean
}

type SetDisplayBackgroundAction = {
type: SettingsActions.setDisplayBackground
payload: boolean
Expand All @@ -31,6 +37,7 @@ export type AppSettingsActions =
| SetThemeAction
| SetDisplayDescriptionAction
| SetDisplayJumpLinksAction
| SetDisplayJumpLinksMobileAction
| SetDisplayBackgroundAction

export function setTheme(payload: AppTheme): SetThemeAction {
Expand All @@ -49,6 +56,12 @@ export function setDisplayJumpLinks(
return { type: SettingsActions.setDisplayJumpLinks, payload }
}

export function setDisplayJumpLinksMobile(
payload: boolean,
): SetDisplayJumpLinksMobileAction {
return { type: SettingsActions.setDisplayJumpLinksMobile, payload }
}

export function setDisplayBackground(
payload: boolean,
): SetDisplayBackgroundAction {
Expand Down
6 changes: 6 additions & 0 deletions src/stores/appSettings/appSettingsReducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ type AppSettingsState = {
theme: AppTheme
showDescriptions: boolean
showJumpLinks: boolean
showJumpLinksMobile: boolean
showBackground: boolean
}

const initialState: AppSettingsState = {
theme: AppTheme.auto,
showDescriptions: false,
showJumpLinks: true,
showJumpLinksMobile: false,
showBackground: false,
}

Expand All @@ -37,6 +39,10 @@ export function appSettings(
return { ...state, showJumpLinks: action.payload }
}

case SettingsActions.setDisplayJumpLinksMobile: {
return { ...state, showJumpLinksMobile: action.payload }
}

case SettingsActions.setDisplayBackground: {
return { ...state, showBackground: action.payload }
}
Expand Down
3 changes: 2 additions & 1 deletion src/stores/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ export const store = createStore(rootReducer, {
theme: loadThemeSetting(),
showDescriptions: loadShowDescriptionsSetting(),
showJumpLinks: loadShowJumpLinksSetting(),
showJumpLinksMobile: false,
showBackground: loadShowBackgroundSetting(),
},
})
}, window.__REDUX_DEVTOOLS_EXTENSION__?.())

persistToLocalStorage(store)

Expand Down
4 changes: 4 additions & 0 deletions src/tailwindConfig.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import resolveConfig from 'tailwindcss/resolveConfig'
import tailwindConfig from '../tailwind.config'

export const config = resolveConfig(tailwindConfig)
9 changes: 9 additions & 0 deletions src/types.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/* eslint-disable no-var */

import { StoreEnhancer } from 'redux'

export {}

declare global {
var __REDUX_DEVTOOLS_EXTENSION__: () => StoreEnhancer
}
3 changes: 2 additions & 1 deletion tailwind.config.js → tailwind.config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import plugin from 'tailwindcss/plugin'
import type { Config } from 'tailwindcss/types/config'

export default {
content: ['./index.html', './src/**/*.{js,jsx,ts,tsx}'],
Expand Down Expand Up @@ -87,4 +88,4 @@ export default {
})
}),
],
}
} satisfies Config

0 comments on commit 656c340

Please sign in to comment.