@@ -19,7 +19,13 @@ export const CollectionCard: React.FC<CollectionCardProps> = ({
19
19
...rest
20
20
} ) => {
21
21
const ctx = useNotionContext ( )
22
- const { components, recordMap, mapPageUrl, mapImageUrl } = ctx
22
+ const {
23
+ components,
24
+ recordMap,
25
+ mapPageUrl,
26
+ mapImageUrl,
27
+ isLinkCollectionToUrlProperty
28
+ } = ctx
23
29
let coverContent = null
24
30
25
31
const { page_cover_position = 0.5 } = block . format || { }
@@ -110,6 +116,76 @@ export const CollectionCard: React.FC<CollectionCardProps> = ({
110
116
}
111
117
}
112
118
}
119
+ let linkProperties = [ ]
120
+ //check if a visible property has a url and we settings are for linking to it for the card
121
+ if ( isLinkCollectionToUrlProperty ) {
122
+ linkProperties = properties
123
+ ?. filter (
124
+ ( p ) =>
125
+ p . visible && p . property !== 'title' && collection . schema [ p . property ]
126
+ )
127
+ . filter ( ( p ) => {
128
+ if ( ! block . properties ) return null
129
+ const schema = collection . schema [ p . property ]
130
+
131
+ return schema . type == 'url'
132
+ } )
133
+ . map ( ( p ) => {
134
+ return block . properties [ p . property ]
135
+ } )
136
+ }
137
+ let url = null
138
+ if (
139
+ linkProperties . length > 0 &&
140
+ linkProperties [ 0 ] . length > 0 &&
141
+ linkProperties [ 0 ] [ 0 ] . length > 0
142
+ ) {
143
+ url = linkProperties [ 0 ] [ 0 ] [ 0 ]
144
+ }
145
+
146
+ const innerCard = (
147
+ < >
148
+ { ( coverContent || cover ?. type !== 'none' ) && (
149
+ < div className = 'notion-collection-card-cover' > { coverContent } </ div >
150
+ ) }
151
+
152
+ < div className = 'notion-collection-card-body' >
153
+ < div className = 'notion-collection-card-property' >
154
+ < Property
155
+ schema = { collection . schema . title }
156
+ data = { block ?. properties ?. title }
157
+ block = { block }
158
+ collection = { collection }
159
+ />
160
+ </ div >
161
+
162
+ { properties
163
+ ?. filter (
164
+ ( p ) =>
165
+ p . visible &&
166
+ p . property !== 'title' &&
167
+ collection . schema [ p . property ]
168
+ )
169
+ . map ( ( p ) => {
170
+ if ( ! block . properties ) return null
171
+ const schema = collection . schema [ p . property ]
172
+ const data = block . properties [ p . property ]
173
+
174
+ return (
175
+ < div className = 'notion-collection-card-property' key = { p . property } >
176
+ < Property
177
+ schema = { schema }
178
+ data = { data }
179
+ block = { block }
180
+ collection = { collection }
181
+ inline
182
+ />
183
+ </ div >
184
+ )
185
+ } ) }
186
+ </ div >
187
+ </ >
188
+ )
113
189
114
190
return (
115
191
< NotionContextProvider
@@ -118,61 +194,45 @@ export const CollectionCard: React.FC<CollectionCardProps> = ({
118
194
...ctx . components ,
119
195
// Disable <a> tabs in all child components so we don't create invalid DOM
120
196
// trees with stacked <a> tags.
197
+ Link : ( props ) => {
198
+ return (
199
+ < form action = { props . href } target = '_blank' >
200
+ < input
201
+ type = 'submit'
202
+ value = { props ?. children ?. props ?. children ?? props . href }
203
+ className = 'nested-form-link notion-link'
204
+ />
205
+ </ form >
206
+ )
207
+ } ,
121
208
PageLink : dummyLink
122
209
} }
123
210
>
124
- < components . PageLink
125
- className = { cs (
126
- 'notion-collection-card' ,
127
- `notion-collection-card-size-${ coverSize } ` ,
128
- className
129
- ) }
130
- href = { mapPageUrl ( block . id ) }
131
- { ...rest }
132
- >
133
- { ( coverContent || cover ?. type !== 'none' ) && (
134
- < div className = 'notion-collection-card-cover' > { coverContent } </ div >
135
- ) }
136
-
137
- < div className = 'notion-collection-card-body' >
138
- < div className = 'notion-collection-card-property' >
139
- < Property
140
- schema = { collection . schema . title }
141
- data = { block ?. properties ?. title }
142
- block = { block }
143
- collection = { collection }
144
- />
145
- </ div >
146
-
147
- { properties
148
- ?. filter (
149
- ( p ) =>
150
- p . visible &&
151
- p . property !== 'title' &&
152
- collection . schema [ p . property ]
153
- )
154
- . map ( ( p ) => {
155
- if ( ! block . properties ) return null
156
- const schema = collection . schema [ p . property ]
157
- const data = block . properties [ p . property ]
158
-
159
- return (
160
- < div
161
- className = 'notion-collection-card-property'
162
- key = { p . property }
163
- >
164
- < Property
165
- schema = { schema }
166
- data = { data }
167
- block = { block }
168
- collection = { collection }
169
- inline
170
- />
171
- </ div >
172
- )
173
- } ) }
174
- </ div >
175
- </ components . PageLink >
211
+ { isLinkCollectionToUrlProperty && url ? (
212
+ < components . Link
213
+ className = { cs (
214
+ 'notion-collection-card' ,
215
+ `notion-collection-card-size-${ coverSize } ` ,
216
+ className
217
+ ) }
218
+ href = { url }
219
+ { ...rest }
220
+ >
221
+ { innerCard }
222
+ </ components . Link >
223
+ ) : (
224
+ < components . PageLink
225
+ className = { cs (
226
+ 'notion-collection-card' ,
227
+ `notion-collection-card-size-${ coverSize } ` ,
228
+ className
229
+ ) }
230
+ href = { mapPageUrl ( block . id ) }
231
+ { ...rest }
232
+ >
233
+ { innerCard }
234
+ </ components . PageLink >
235
+ ) }
176
236
</ NotionContextProvider >
177
237
)
178
238
}
0 commit comments