Skip to content

Commit 7aa5d0e

Browse files
author
J
committed
fix: mention-preview-card
1 parent 7c5253e commit 7aa5d0e

File tree

3 files changed

+121
-5
lines changed

3 files changed

+121
-5
lines changed

packages/react-notion-x/src/components/eoi.tsx

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { Block } from 'notion-types'
55
import { useNotionContext } from '../context'
66
import SvgTypeGitHub from '../icons/type-github'
77
import { cs, formatNotionDateTime } from '../utils'
8+
import { MentionPreviewCard } from './mention-preview-card'
89

910
// External Object Instance
1011
export const EOI: React.FC<{
@@ -64,11 +65,13 @@ export const EOI: React.FC<{
6465
<div className='notion-external-title'>{title}</div>
6566

6667
{(owner || lastUpdated) && (
67-
<div className='notion-external-subtitle'>
68-
{owner && <span>{owner}</span>}
69-
{owner && lastUpdated && <span></span>}
70-
{lastUpdated && <span>Updated {lastUpdated}</span>}
71-
</div>
68+
<MentionPreviewCard
69+
title={title}
70+
owner={owner}
71+
lastUpdated={lastUpdated}
72+
domain={domain}
73+
externalImage={externalImage}
74+
/>
7275
)}
7376
</div>
7477
</components.Link>
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import React from 'react'
2+
3+
function capitalizeFirstLetter(str) {
4+
return str.charAt(0).toUpperCase() + str.slice(1)
5+
}
6+
7+
export const MentionPreviewCard: React.FC<{
8+
owner?: string
9+
lastUpdated?: string
10+
title: string
11+
domain: string
12+
externalImage?: React.ReactNode
13+
}> = ({ owner, lastUpdated, externalImage, title, domain }) => {
14+
return (
15+
<div className='notion-external-subtitle'>
16+
{externalImage && (
17+
<div className='notion-preview-card-domain-warp'>
18+
<div className='notion-preview-card-logo'>{externalImage}</div>
19+
<div className='notion-preview-card-domain'>
20+
{capitalizeFirstLetter(domain.split('.')[0])}
21+
</div>
22+
</div>
23+
)}
24+
<div className='notion-preview-card-title'>{title}</div>
25+
{owner && (
26+
<div className='notion-external-subtitle-item'>
27+
<div className='notion-external-subtitle-item-name'>Owner</div>
28+
<span className='notion-external-subtitle-item-desc'>{owner}</span>
29+
</div>
30+
)}
31+
{lastUpdated && (
32+
<div className='notion-external-subtitle-item'>
33+
<div className='notion-external-subtitle-item-name'>Updated</div>
34+
<span className='notion-external-subtitle-item-desc'>
35+
{lastUpdated}
36+
</span>
37+
</div>
38+
)}
39+
{domain === 'github.com' && (
40+
<div className='notion-preview-card-github-shields'>
41+
<img
42+
src={`https://img.shields.io/github/stars/${owner}/${title}?logo=github`}
43+
alt=''
44+
/>
45+
<img
46+
src={`https://img.shields.io/github/last-commit/${owner}/${title}`}
47+
alt=''
48+
/>
49+
</div>
50+
)}
51+
</div>
52+
)
53+
}

packages/react-notion-x/src/styles.css

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2658,6 +2658,66 @@ svg.notion-page-icon {
26582658

26592659
.notion-external-mention .notion-external-subtitle {
26602660
display: none;
2661+
position: absolute;
2662+
top: 28px;
2663+
left: 0;
2664+
width: 260px;
2665+
background: var(--bg-color);
2666+
z-index: 999;
2667+
padding: 8px;
2668+
box-shadow: rgba(15, 15, 15, 0.1) 0 0 0 1px, rgba(15, 15, 15, 0.1) 0 2px 4px;
2669+
}
2670+
2671+
.notion-external-mention .notion-external-subtitle-item{
2672+
display: flex;
2673+
flex-direction: row;
2674+
justify-content: flex-start;
2675+
align-items: center;
2676+
line-height: 1.5;
2677+
padding: 4px 0;
2678+
}
2679+
2680+
.notion-external-mention .notion-external-subtitle-item-name{
2681+
flex: none;
2682+
width: 70px;
2683+
font-weight: 500;
2684+
}
2685+
2686+
.notion-external-mention .notion-external-subtitle-item-desc{
2687+
flex: 1
2688+
}
2689+
2690+
.notion-external-description:hover .notion-external-subtitle {
2691+
display: block;
2692+
}
2693+
2694+
.notion-preview-card-domain-warp{
2695+
display: flex;
2696+
flex-direction: row;
2697+
justify-content: flex-start;
2698+
align-items: center;
2699+
}
2700+
2701+
.notion-preview-card-domain-warp .notion-preview-card-domain{
2702+
padding-left: 4px;
2703+
2704+
}
2705+
.notion-preview-card-domain-warp .notion-preview-card-logo{
2706+
width: 14px;
2707+
height: 14px;
2708+
}
2709+
2710+
.notion-preview-card-title{
2711+
font-size: 16px;
2712+
line-height: 1.5;
2713+
padding: 4px 0;
2714+
font-weight: 500;
2715+
color: var(--fg-color-4);
2716+
}
2717+
2718+
.notion-preview-card-github-shields img {
2719+
margin-right: 4px;
2720+
padding: 4px 0;
26612721
}
26622722

26632723
.notion-yt-lite {

0 commit comments

Comments
 (0)