-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): add page group and display properties (#6228)
close TOV-23 https://github.com/toeverything/AFFiNE/assets/102217452/c05474de-b73c-40ab-9f18-cc43bb9fd828
- Loading branch information
Showing
30 changed files
with
742 additions
and
154 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
packages/frontend/core/src/components/page-list/components/page-display-menu.css.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import { cssVar } from '@toeverything/theme'; | ||
import { style } from '@vanilla-extract/css'; | ||
|
||
export const menu = style({ | ||
minWidth: '220px', | ||
}); | ||
|
||
export const arrowDownSmallIcon = style({ | ||
width: '16px', | ||
height: '16px', | ||
color: cssVar('iconColor'), | ||
}); | ||
|
||
export const headerDisplayButton = style({ | ||
marginLeft: '16px', | ||
['WebkitAppRegion' as string]: 'no-drag', | ||
}); | ||
|
||
export const subMenuTrigger = style({ | ||
paddingRight: '8px', | ||
}); | ||
|
||
export const subMenuItem = style({ | ||
fontSize: cssVar('fontXs'), | ||
flexWrap: 'nowrap', | ||
selectors: { | ||
'&[data-active="true"]': { | ||
color: cssVar('primaryColor'), | ||
}, | ||
}, | ||
}); | ||
|
||
export const subMenuTriggerContent = style({ | ||
display: 'flex', | ||
alignItems: 'center', | ||
justifyContent: 'space-between', | ||
gap: '8px', | ||
fontWeight: 500, | ||
fontSize: cssVar('fontXs'), | ||
}); | ||
|
||
export const currentGroupType = style({ | ||
fontWeight: 400, | ||
color: cssVar('textSecondaryColor'), | ||
}); | ||
|
||
export const listOption = style({ | ||
padding: '4px 12px', | ||
height: '28px', | ||
fontSize: cssVar('fontXs'), | ||
fontWeight: 500, | ||
color: cssVar('textSecondaryColor'), | ||
marginBottom: '4px', | ||
}); | ||
export const properties = style({ | ||
padding: '4px 12px', | ||
height: '28px', | ||
fontSize: cssVar('fontXs'), | ||
}); | ||
export const propertiesWrapper = style({ | ||
display: 'flex', | ||
flexWrap: 'wrap', | ||
maxWidth: '200px', | ||
gap: '8px', | ||
padding: '4px 12px', | ||
}); | ||
|
||
export const propertyButton = style({ | ||
color: cssVar('textDisableColor'), | ||
selectors: { | ||
'&[data-active="true"]': { | ||
color: cssVar('textPrimaryColor'), | ||
}, | ||
}, | ||
}); |
163 changes: 163 additions & 0 deletions
163
packages/frontend/core/src/components/page-list/components/page-display-menu.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,163 @@ | ||
import { | ||
Button, | ||
Menu, | ||
MenuItem, | ||
MenuSeparator, | ||
MenuSub, | ||
} from '@affine/component'; | ||
import { useAFFiNEI18N } from '@affine/i18n/hooks'; | ||
import { ArrowDownSmallIcon, DoneIcon } from '@blocksuite/icons'; | ||
import { useAtom } from 'jotai'; | ||
import { useCallback, useMemo } from 'react'; | ||
|
||
import { pageGroupByTypeAtom } from '../group-definitions'; | ||
import type { PageDisplayProperties, PageGroupByType } from '../types'; | ||
import { usePageDisplayProperties } from '../use-page-display-properties'; | ||
import * as styles from './page-display-menu.css'; | ||
|
||
type GroupOption = { | ||
value: PageGroupByType; | ||
label: string; | ||
}; | ||
|
||
export const PageDisplayMenu = () => { | ||
const t = useAFFiNEI18N(); | ||
const [group, setGroup] = useAtom(pageGroupByTypeAtom); | ||
const [properties, setProperties] = usePageDisplayProperties(); | ||
const handleSelect = useCallback( | ||
(value: PageGroupByType) => { | ||
setGroup(value); | ||
}, | ||
[setGroup] | ||
); | ||
const propertyOptions: Array<{ | ||
key: keyof PageDisplayProperties; | ||
onClick: () => void; | ||
label: string; | ||
}> = useMemo(() => { | ||
return [ | ||
{ | ||
key: 'bodyNotes', | ||
onClick: () => setProperties('bodyNotes', !properties['bodyNotes']), | ||
label: t['com.affine.page.display.display-properties.body-notes'](), | ||
}, | ||
{ | ||
key: 'tags', | ||
onClick: () => setProperties('tags', !properties['tags']), | ||
label: t['Tags'](), | ||
}, | ||
{ | ||
key: 'createDate', | ||
onClick: () => setProperties('createDate', !properties['createDate']), | ||
label: t['Created'](), | ||
}, | ||
{ | ||
key: 'updatedDate', | ||
onClick: () => setProperties('updatedDate', !properties['updatedDate']), | ||
label: t['Updated'](), | ||
}, | ||
]; | ||
}, [properties, setProperties, t]); | ||
|
||
const items = useMemo(() => { | ||
const groupOptions: GroupOption[] = [ | ||
{ | ||
value: 'createDate', | ||
label: t['Created'](), | ||
}, | ||
{ | ||
value: 'updatedDate', | ||
label: t['Updated'](), | ||
}, | ||
{ | ||
value: 'tag', | ||
label: t['com.affine.page.display.grouping.group-by-tag'](), | ||
}, | ||
{ | ||
value: 'favourites', | ||
label: t['com.affine.page.display.grouping.group-by-favourites'](), | ||
}, | ||
{ | ||
value: 'none', | ||
label: t['com.affine.page.display.grouping.no-grouping'](), | ||
}, | ||
]; | ||
|
||
const subItems = groupOptions.map(option => ( | ||
<MenuItem | ||
key={option.value} | ||
onSelect={() => handleSelect(option.value)} | ||
data-active={group === option.value} | ||
endFix={group === option.value ? <DoneIcon fontSize={'20px'} /> : null} | ||
className={styles.subMenuItem} | ||
data-testid={`group-by-${option.value}`} | ||
> | ||
<span>{option.label}</span> | ||
</MenuItem> | ||
)); | ||
|
||
const currentGroupType = groupOptions.find( | ||
option => option.value === group | ||
)?.label; | ||
|
||
return ( | ||
<> | ||
<MenuSub | ||
subContentOptions={{ | ||
alignOffset: -8, | ||
sideOffset: 12, | ||
}} | ||
triggerOptions={{ className: styles.subMenuTrigger }} | ||
items={subItems} | ||
> | ||
<div | ||
className={styles.subMenuTriggerContent} | ||
data-testid="page-display-grouping-menuItem" | ||
> | ||
<span>{t['com.affine.page.display.grouping']()}</span> | ||
<span className={styles.currentGroupType}>{currentGroupType}</span> | ||
</div> | ||
</MenuSub> | ||
<MenuSeparator /> | ||
<div className={styles.listOption}> | ||
{t['com.affine.page.display.list-option']()} | ||
</div> | ||
<div className={styles.properties}> | ||
{t['com.affine.page.display.display-properties']()} | ||
</div> | ||
<div className={styles.propertiesWrapper}> | ||
{propertyOptions.map(option => ( | ||
<Button | ||
key={option.label} | ||
className={styles.propertyButton} | ||
onClick={option.onClick} | ||
data-active={properties[option.key]} | ||
data-testid={`property-${option.key}`} | ||
> | ||
{option.label} | ||
</Button> | ||
))} | ||
</div> | ||
</> | ||
); | ||
}, [group, handleSelect, properties, propertyOptions, t]); | ||
return ( | ||
<Menu | ||
items={items} | ||
contentOptions={{ | ||
className: styles.menu, | ||
|
||
align: 'end', | ||
}} | ||
> | ||
<Button | ||
iconPosition="end" | ||
icon={<ArrowDownSmallIcon className={styles.arrowDownSmallIcon} />} | ||
className={styles.headerDisplayButton} | ||
data-testid="page-display-menu-button" | ||
> | ||
{t['com.affine.page.display']()} | ||
</Button> | ||
</Menu> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.