Skip to content

Commit

Permalink
fix(mobile): adjust mobile ui (toeverything#8112)
Browse files Browse the repository at this point in the history
close AF-1274, AF-1320, AF-1333
  • Loading branch information
CatsJuice committed Sep 6, 2024
1 parent 4de9d94 commit 87ed358
Show file tree
Hide file tree
Showing 12 changed files with 84 additions and 34 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import clsx from 'clsx';
import dayjs from 'dayjs';
import { memo, useCallback, useEffect, useMemo, useRef } from 'react';

Expand All @@ -23,6 +24,8 @@ export const DayPicker = memo(function DayPicker(
onChange,
onCursorChange,
onModeChange,
monthHeaderCellClassName,
monthBodyCellClassName,
} = props;

const matrix = useMemo(() => {
Expand Down Expand Up @@ -170,18 +173,27 @@ export const DayPicker = memo(function DayPicker(
{/* weekDays */}
<div className={styles.monthViewRow}>
{weekDays.split(',').map(day => (
<div key={day} className={styles.monthViewHeaderCell}>
<div
key={day}
className={clsx(
styles.monthViewHeaderCell,
monthHeaderCellClassName
)}
>
{day}
</div>
))}
</div>
{/* Weeks in month */}
{matrix.map((week, i) => {
return (
<div key={i} className={styles.monthViewRow}>
<div key={i} className={clsx(styles.monthViewRow)}>
{week.map((cell, j) => (
<div
className={styles.monthViewBodyCell}
className={clsx(
styles.monthViewBodyCell,
monthBodyCellClassName
)}
key={j}
onClick={() => onChange?.(cell.date.format(format))}
>
Expand All @@ -197,7 +209,15 @@ export const DayPicker = memo(function DayPicker(
})}
</main>
),
[customDayRenderer, format, matrix, onChange, weekDays]
[
customDayRenderer,
format,
matrix,
monthBodyCellClassName,
monthHeaderCellClassName,
onChange,
weekDays,
]
);

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ export interface DatePickerProps {
* when date is clicked
*/
onChange?: (value: string) => void;

// style customizations
monthHeaderCellClassName?: string;
monthBodyCellClassName?: string;
}

/**
Expand Down
7 changes: 5 additions & 2 deletions packages/frontend/component/src/ui/menu/menu.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,18 @@ export interface MenuProps {
export interface MenuItemProps
extends Omit<MenuItemPropsPrimitive, 'asChild' | 'textValue' | 'prefix'> {
type?: 'default' | 'warning' | 'danger';
// preFix?: React.ReactNode;
// endFix?: React.ReactNode;
prefix?: ReactNode;
suffix?: ReactNode;
prefixIcon?: ReactNode;
suffixIcon?: ReactNode;
checked?: boolean;
selected?: boolean;
block?: boolean;
/**
* add divider after item (if not last one)
* - Mobile only for now
*/
divide?: boolean;
}
export interface MenuSubProps {
children: ReactNode;
Expand Down
3 changes: 2 additions & 1 deletion packages/frontend/component/src/ui/menu/mobile/item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const preventDefault = () => {
export const MobileMenuItem = (props: MenuItemProps) => {
const { setOpen } = useContext(MobileMenuContext);
const { className, children, otherProps } = useMenuItem(props);
const { onSelect, onClick, ...restProps } = otherProps;
const { onSelect, onClick, divide, ...restProps } = otherProps;

const onItemClick = useCallback(
(e: any) => {
Expand All @@ -32,6 +32,7 @@ export const MobileMenuItem = (props: MenuItemProps) => {
role="menuitem"
onClick={onItemClick}
className={className}
data-divider={divide}
{...restProps}
>
{children}
Expand Down
20 changes: 20 additions & 0 deletions packages/frontend/component/src/ui/menu/mobile/styles.css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export const menuContent = style({
export const mobileMenuItem = style({
padding: '10px 20px',
borderRadius: 0,

':hover': {
vars: {
[bgColor]: 'transparent',
Expand All @@ -66,6 +67,25 @@ export const mobileMenuItem = style({
'&.warning:active': {
vars: { [bgColor]: cssVar('backgroundWarningColor') },
},
// divider hack
'&[data-divider=true]': {
marginBottom: 16,
position: 'relative',
},
'&[data-divider=true]::after': {
content: '""',
position: 'absolute',
bottom: -8,
left: 0,
width: '100%',
borderBottom: `0.5px solid ${cssVarV2('layer/insideBorder/border')}`,
},
'&[data-divider=true]:last-child': {
marginBottom: 0,
},
'&[data-divider=true]:last-child::after': {
display: 'none',
},
},
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ const interactive = style({
});
export const calendar = style({
padding: '16px',
selectors: {
'&[data-mobile=true]': {
padding: '8px 16px',
},
},
});
export const journalPanel = style({
width: '100%',
Expand Down Expand Up @@ -212,6 +217,13 @@ export const journalDateCell = style([
fontWeight: 500,
border: `1px solid ${cssVar('primaryColor')}`,
},

'&[data-mobile=true]': {
width: 34,
height: 34,
fontSize: 15,
fontWeight: 400,
},
},
},
]);
Expand All @@ -225,3 +237,7 @@ export const journalDateCellDot = style({
left: '50%',
transform: 'translateX(-50%)',
});

export const journalDateCellWrapper = style({
height: 34,
});
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ interface JournalBlockProps {
date: dayjs.Dayjs;
}

const mobile = environment.isMobile;
export const EditorJournalPanel = () => {
const t = useI18n();
const doc = useService(DocService).doc;
Expand Down Expand Up @@ -129,6 +130,7 @@ export const EditorJournalPanel = () => {
data-selected={cell.selected}
data-is-journal={isJournal}
data-has-journal={hasJournal}
data-mobile={mobile}
>
{cell.label}
{hasJournal && !cell.selected ? (
Expand All @@ -142,14 +144,16 @@ export const EditorJournalPanel = () => {

return (
<div className={styles.journalPanel} data-is-journal={isJournal}>
<div className={styles.calendar}>
<div data-mobile={mobile} className={styles.calendar}>
<DatePicker
weekDays={t['com.affine.calendar-date-picker.week-days']()}
monthNames={t['com.affine.calendar-date-picker.month-names']()}
todayLabel={t['com.affine.calendar-date-picker.today']()}
customDayRenderer={customDayRenderer}
value={date}
onChange={onDateSelect}
monthHeaderCellClassName={styles.journalDateCellWrapper}
monthBodyCellClassName={styles.journalDateCellWrapper}
/>
</div>
<JournalConflictBlock date={dayjs(date)} />
Expand Down
21 changes: 0 additions & 21 deletions packages/frontend/mobile/src/components/app-tabs/home-icon.tsx

This file was deleted.

5 changes: 2 additions & 3 deletions packages/frontend/mobile/src/components/app-tabs/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ import {
WorkbenchLink,
WorkbenchService,
} from '@affine/core/modules/workbench';
import { AllDocsIcon, SearchIcon } from '@blocksuite/icons/rc';
import { AllDocsIcon, MobileHomeIcon, SearchIcon } from '@blocksuite/icons/rc';
import { useLiveData, useService } from '@toeverything/infra';
import type { Location } from 'react-router-dom';

import { HomeIcon } from './home-icon';
import * as styles from './styles.css';

interface Route {
Expand All @@ -19,7 +18,7 @@ interface Route {
const routes: Route[] = [
{
to: '/home',
Icon: HomeIcon,
Icon: MobileHomeIcon,
},
{
to: '/all',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@ export const appTabs = style({
borderTop: `1px solid ${cssVarV2('layer/insideBorder/border')}`,

width: '100dvw',
height: globalVars.appTabHeight,
height: `calc(${globalVars.appTabHeight} + 2px)`,
padding: 16,
gap: 15.5,

position: 'fixed',
bottom: 0,
paddingBottom: 18,
bottom: -2,
zIndex: 1,
});
export const tabItem = style({
Expand All @@ -30,6 +31,7 @@ export const tabItem = style({
padding: 3,
fontSize: 30,
color: cssVarV2('icon/primary'),
lineHeight: 0,

selectors: {
'&[data-active="true"]': {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ export const SelectorMenu = ({ onClose }: { onClose?: () => void }) => {
title="Cloud Sync"
list={cloudWorkspaces}
/>
<div className={styles.divider} />
<WorkspaceList
onClose={onClose}
title="Local Storage"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export const SettingDropdownSelect = <
<MobileMenu
items={options.map(opt => (
<MobileMenuItem
divide
key={opt.value}
selected={value === opt.value}
data-testid={opt.testId}
Expand Down

0 comments on commit 87ed358

Please sign in to comment.