From 2295685590a2101d9ec6c440237e658c62af4b48 Mon Sep 17 00:00:00 2001 From: Peng Xiao Date: Mon, 26 Feb 2024 14:11:24 +0000 Subject: [PATCH] fix: page info styles (#5910) fix inconsistent styles compared to the one defined in figma fix https://github.com/toeverything/AFFiNE/issues/5904 fix https://github.com/toeverything/AFFiNE/issues/5903 --- .../affine/page-properties/common.ts | 2 - .../property-row-value-renderer.tsx | 85 ++++++++++++++++--- .../affine/page-properties/styles.css.ts | 46 +++++++++- .../affine/page-properties/table.tsx | 67 +++++++++------ .../page-properties/tags-inline-editor.css.ts | 20 ++++- .../page-properties/tags-inline-editor.tsx | 8 +- .../page-list/docs/page-tags.css.ts | 2 +- .../affine-local/e2e/page-properties.spec.ts | 3 + tests/kit/utils/filter.ts | 1 + tests/kit/utils/properties.ts | 13 +++ 10 files changed, 194 insertions(+), 53 deletions(-) diff --git a/packages/frontend/core/src/components/affine/page-properties/common.ts b/packages/frontend/core/src/components/affine/page-properties/common.ts index 298220150b..466b4254e0 100644 --- a/packages/frontend/core/src/components/affine/page-properties/common.ts +++ b/packages/frontend/core/src/components/affine/page-properties/common.ts @@ -1,12 +1,10 @@ import { cssVar } from '@toeverything/theme'; -import { atom } from 'jotai'; import { createContext } from 'react'; import type { PagePropertiesManager } from './page-properties-manager'; // @ts-expect-error this should always be set export const managerContext = createContext(); -export const pageInfoCollapsedAtom = atom(false); type TagColorHelper = T extends `paletteLine${infer Color}` ? Color : never; type TagColorName = TagColorHelper[0]>; diff --git a/packages/frontend/core/src/components/affine/page-properties/property-row-value-renderer.tsx b/packages/frontend/core/src/components/affine/page-properties/property-row-value-renderer.tsx index ecee734ff9..045afef37d 100644 --- a/packages/frontend/core/src/components/affine/page-properties/property-row-value-renderer.tsx +++ b/packages/frontend/core/src/components/affine/page-properties/property-row-value-renderer.tsx @@ -11,7 +11,13 @@ import { useAFFiNEI18N } from '@affine/i18n/hooks'; import { assertExists } from '@blocksuite/global/utils'; import { Page, useLiveData, useService, Workspace } from '@toeverything/infra'; import { noop } from 'lodash-es'; -import { type ChangeEventHandler, useCallback, useContext } from 'react'; +import { + type ChangeEventHandler, + useCallback, + useContext, + useEffect, + useState, +} from 'react'; import { managerContext } from './common'; import * as styles from './styles.css'; @@ -84,30 +90,85 @@ export const CheckboxValue = ({ property }: PropertyRowValueProps) => { ); }; -export const TextValue = ({ property, meta }: PropertyRowValueProps) => { +export const TextValue = ({ property }: PropertyRowValueProps) => { const manager = useContext(managerContext); + const [value, setValue] = useState(property.value); const handleClick = useCallback((e: React.MouseEvent) => { e.stopPropagation(); - // todo: show edit popup }, []); - const handleOnChange: ChangeEventHandler = useCallback( - e => { + const handleBlur = useCallback( + (e: React.ChangeEvent) => { manager.updateCustomProperty(property.id, { - value: e.target.value, + value: e.target.value.trim(), }); }, [manager, property.id] ); + const handleOnChange: ChangeEventHandler = useCallback( + e => { + setValue(e.target.value); + }, + [] + ); const t = useAFFiNEI18N(); - const isNumber = meta.type === 'number'; + useEffect(() => { + setValue(property.value); + }, [property.value]); + + return ( +
+