There can be more than Notion and Miro. AFFiNE(pronounced [ə‘fain]) is a next-gen knowledge base that brings planning, sorting and creating all together. Privacy first, open-source, customizable and ready to use.
TypeScript appcrdteditorelectronknowledge-basemarkdownmironotesnotionnotion-alternativerustrust-langrust-languagetabletableviewwhiteboardwikiworkspace
feat: add block card component (#2398)
Whitewater017b9c86153e
diff --git a/packages/component/src/components/card/block-card/index.tsx b/packages/component/src/components/card/block-card/index.tsxnew file mode 100644index 0000000000..ffdc614209--- /dev/null+++ b/packages/component/src/components/card/block-card/index.tsx@@ -0,0 +1,25 @@+import { forwardRef, type HTMLAttributes, type ReactNode } from 'react';++import * as styles from './styles.css';++export const BlockCard = forwardRef<+ HTMLDivElement,+ {+ left?: ReactNode;+ title: string;+ desc?: string;+ right?: ReactNode;+ } & HTMLAttributes<HTMLDivElement>+>(({ left, title, desc, right, ...props }, ref) => {+ return (+ <div ref={ref} className={styles.blockCard} {...props}>+ {left && <div className={styles.blockCardAround}>{left}</div>}+ <div className={styles.blockCardContent}>+ <div>{title}</div>+ <div className={styles.blockCardDesc}>{desc}</div>+ </div>+ {right && <div className={styles.blockCardAround}>{right}</div>}+ </div>+ );+});+BlockCard.displayName = 'BlockCard';diff --git a/packages/component/src/components/card/block-card/styles.css.ts b/packages/component/src/components/card/block-card/styles.css.tsnew file mode 100644index 0000000000..04e238d4f8--- /dev/null+++ b/packages/component/src/components/card/block-card/styles.css.ts@@ -0,0 +1,35 @@+import { style } from '@vanilla-extract/css';++export const blockCard = style({+ display: 'flex',+ gap: '12px',+ padding: '8px 12px',+ color: 'var(--affine-text-primary-color)',+ backgroundColor: 'var(--affine-background-primary-color)',+ borderRadius: '4px',+ userSelect: 'none',+ cursor: 'pointer',+ selectors: {+ '&:hover': {+ boxShadow: 'var(--affine-shadow-1)',+ },+ // TODO active styles+ },+});++export const blockCardAround = style({+ display: 'flex',+ justifyContent: 'center',+ alignItems: 'center',+});++export const blockCardContent = style({+ display: 'flex',+ flexDirection: 'column',+ flex: 1,+});++export const blockCardDesc = style({+ color: 'var(--affine-text-secondary-color)',+ fontSize: 'var(--affine-font-xs)',+});diff --git a/packages/component/src/components/workspace-card/index.tsx b/packages/component/src/components/card/workspace-card/index.tsxsimilarity index 98%rename from packages/component/src/components/workspace-card/index.tsxrename to packages/component/src/components/card/workspace-card/index.tsxindex d545603c49..3b2e80bf99 100644--- a/packages/component/src/components/workspace-card/index.tsx+++ b/packages/component/src/components/card/workspace-card/index.tsx@@ -10,7 +10,7 @@ import { useBlockSuiteWorkspaceName } from '@toeverything/hooks/use-block-suite-import type { FC } from 'react';import { useCallback } from 'react';-import { WorkspaceAvatar } from '../workspace-avatar';+import { WorkspaceAvatar } from '../../workspace-avatar';import {StyledCard,StyledSettingLink,diff --git a/packages/component/src/components/workspace-card/styles.ts b/packages/component/src/components/card/workspace-card/styles.tssimilarity index 94%rename from packages/component/src/components/workspace-card/styles.tsrename to packages/component/src/components/card/workspace-card/styles.tsindex ea995ec9a0..7b32c78b5e 100644--- a/packages/component/src/components/workspace-card/styles.ts+++ b/packages/component/src/components/card/workspace-card/styles.ts@@ -1,5 +1,5 @@-import { displayFlex, styled, textEllipsis } from '../..';-import { IconButton } from '../..';+import { displayFlex, styled, textEllipsis } from '../../../styles';+import { IconButton } from '../../../ui/button/icon-button';export const StyleWorkspaceInfo = styled('div')(() => {return {diff --git a/packages/component/src/components/share-menu/share-menu.tsx b/packages/component/src/components/share-menu/share-menu.tsxindex 99e0b729a7..10e493f05f 100644--- a/packages/component/src/components/share-menu/share-menu.tsx+++ b/packages/component/src/components/share-menu/share-menu.tsx@@ -9,7 +9,7 @@ import type { FC } from 'react';import { useRef } from 'react';import { useCallback, useState } from 'react';-import { Menu } from '../..';+import { Menu } from '../../ui/menu/menu';import { Export } from './export';import { containerStyle, indicatorContainerStyle, tabStyle } from './index.css';import { SharePage } from './share-page';diff --git a/packages/component/src/components/workspace-list/index.tsx b/packages/component/src/components/workspace-list/index.tsxindex 5730bb89ab..3e69dd03e1 100644--- a/packages/component/src/components/workspace-list/index.tsx+++ b/packages/component/src/components/workspace-list/index.tsx@@ -12,7 +12,7 @@ import {import { SortableContext, useSortable } from '@dnd-kit/sortable';import type { FC } from 'react';-import { WorkspaceCard } from '../workspace-card';+import { WorkspaceCard } from '../../components/card/workspace-card';import { workspaceItemStyle } from './index.css';export type WorkspaceListProps = {diff --git a/packages/component/src/stories/card.stories.tsx b/packages/component/src/stories/card.stories.tsxnew file mode 100644index 0000000000..f3d838ed51--- /dev/null+++ b/packages/component/src/stories/card.stories.tsx@@ -0,0 +1,55 @@+import { BlockCard } from '@affine/component/card/block-card';+import { WorkspaceFlavour } from '@affine/workspace/type';+import { EdgelessIcon, PageIcon } from '@blocksuite/icons';+import { Workspace } from '@blocksuite/store';++import { WorkspaceCard } from '../components/card/workspace-card';+import { toast } from '../ui/toast';++export default {+ title: 'AFFiNE/Card',+ component: WorkspaceCard,+};++const blockSuiteWorkspace = new Workspace({+ id: 'blocksuite-local',+});++blockSuiteWorkspace.meta.setName('Hello World');++export const AffineWorkspaceCard = () => {+ return (+ <WorkspaceCard+ workspace={{+ flavour: WorkspaceFlavour.LOCAL,+ id: 'local',+ blockSuiteWorkspace,+ providers: [],+ }}+ onClick={() => {}}+ onSettingClick={() => {}}+ currentWorkspaceId={null}+ />+ );+};++export const AffineBlockCard = () => {+ return (+ <div style={{ display: 'flex', flexDirection: 'column', gap: '4px' }}>+ <BlockCard title={'New Page'} onClick={() => toast('clicked')} />+ <BlockCard+ title={'New Page'}+ desc={'Write with a blank page'}+ right={<PageIcon width={20} height={20} />}+ onClick={() => toast('clicked page')}+ />+ <BlockCard+ title={'New Edgeless'}+ desc={'Draw with a blank whiteboard'}+ left={<PageIcon width={20} height={20} />}+ right={<EdgelessIcon width={20} height={20} />}+ onClick={() => toast('clicked edgeless')}+ />+ </div>+ );+};diff --git a/packages/component/src/stories/workspace-card.stories.tsx b/packages/component/src/stories/workspace-card.stories.tsxdeleted file mode 100644index cba0427952..0000000000--- a/packages/component/src/stories/workspace-card.stories.tsx+++ /dev/null@@ -1,31 +0,0 @@-import { WorkspaceFlavour } from '@affine/workspace/type';-import { Workspace } from '@blocksuite/store';--import { WorkspaceCard } from '../components/workspace-card';--export default {- title: 'AFFiNE/WorkspaceCard',- component: WorkspaceCard,-};--const blockSuiteWorkspace = new Workspace({- id: 'blocksuite-local',-});--blockSuiteWorkspace.meta.setName('Hello World');--export const Basic = () => {- return (- <WorkspaceCard- workspace={{- flavour: WorkspaceFlavour.LOCAL,- id: 'local',- blockSuiteWorkspace,- providers: [],- }}- onClick={() => {}}- onSettingClick={() => {}}- currentWorkspaceId={null}- />- );-};