Skip to content

Commit

Permalink
feat(core): add template mark on detail page header (#9764)
Browse files Browse the repository at this point in the history
close AF-2136
  • Loading branch information
CatsJuice committed Jan 18, 2025
1 parent f8abe99 commit 9d61b41
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ export const header = style({
width: '100%',
alignItems: 'center',
gap: 12,
containerName: 'detail-page-header',
containerType: 'inline-size',
});
export const spacer = style({
flexGrow: 1,
Expand Down Expand Up @@ -56,3 +58,21 @@ export const dragPreview = style({
backgroundColor: cssVarV2('layer/background/primary'),
borderRadius: '12px',
});

export const templateMark = style({
backgroundColor: cssVarV2.button.templateLabelBackground,
color: cssVarV2.button.primary,
borderRadius: 4,
padding: '2px 8px',
fontSize: 12,
fontWeight: 500,
lineHeight: '20px',
});

export const journalTemplateMark = style({
'@container': {
'(width <= 400px)': {
display: 'none',
},
},
});
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,28 @@ import { BlocksuiteHeaderTitle } from '@affine/core/components/blocksuite/block-
import { EditorModeSwitch } from '@affine/core/components/blocksuite/block-suite-mode-switch';
import { useRegisterCopyLinkCommands } from '@affine/core/components/hooks/affine/use-register-copy-link-commands';
import { HeaderDivider } from '@affine/core/components/pure/header';
import { DocService } from '@affine/core/modules/doc';
import { DocDisplayMetaService } from '@affine/core/modules/doc-display-meta';
import { EditorService } from '@affine/core/modules/editor';
import { JournalService } from '@affine/core/modules/journal';
import { TemplateDocService } from '@affine/core/modules/template-doc';
import { ViewIcon, ViewTitle } from '@affine/core/modules/workbench';
import type { Workspace } from '@affine/core/modules/workspace';
import type { AffineDNDData } from '@affine/core/types/dnd';
import { useI18n } from '@affine/i18n';
import { track } from '@affine/track';
import type { Store } from '@blocksuite/affine/store';
import { useLiveData, useService } from '@toeverything/infra';
import { forwardRef, useCallback, useEffect, useRef, useState } from 'react';
import clsx from 'clsx';
import {
forwardRef,
type HTMLAttributes,
memo,
useCallback,
useEffect,
useRef,
useState,
} from 'react';

import * as styles from './detail-page-header.css';
import { useDetailPageHeaderResponsive } from './use-header-responsive';
Expand All @@ -48,6 +59,24 @@ const Header = forwardRef<

Header.displayName = 'forwardRef(Header)';

const TemplateMark = memo(function TemplateMark({
className,
...props
}: HTMLAttributes<HTMLDivElement>) {
const t = useI18n();
const doc = useService(DocService).doc;
const templateDocService = useService(TemplateDocService);
const isTemplate = useLiveData(templateDocService.list.isTemplate$(doc.id));

if (!isTemplate) return null;

return (
<div className={clsx(styles.templateMark, className)} {...props}>
{t['Template']()}
</div>
);
});

interface PageHeaderProps {
page: Store;
workspace: Workspace;
Expand Down Expand Up @@ -79,6 +108,7 @@ export function JournalPageHeader({ page, workspace }: PageHeaderProps) {
<div className={styles.journalWeekPicker}>
<JournalWeekDatePicker page={page} />
</div>
<TemplateMark className={styles.journalTemplateMark} />
{hideToday ? null : <JournalTodayButton />}
<HeaderDivider />
<PageHeaderMenuButton
Expand Down Expand Up @@ -132,6 +162,7 @@ export function NormalPageHeader({ page, workspace }: PageHeaderProps) {
docId={page.id}
inputHandleRef={titleInputHandleRef}
/>
<TemplateMark />
<div className={styles.iconButtonContainer}>
{hideCollect ? null : (
<>
Expand Down

0 comments on commit 9d61b41

Please sign in to comment.