forked from proteye/keystone-cms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcomponent-blocks.tsx
82 lines (81 loc) · 2.28 KB
/
component-blocks.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import React from 'react'
import { NotEditable, component, fields } from '@keystone-6/fields-document/component-blocks'
import { ImageUploader } from './components/ImageUploader'
import { image } from './document-fields'
export const componentBlocks = {
/** Image */
image: component({
preview: ({ fields }) => (
<NotEditable>
<ImageUploader
listKey={fields.image.options.listKey}
defaultValue={fields.imageRel.value?.data}
imageAlt={fields.imageAlt.value}
onChange={fields.image.onChange}
onImageAltChange={fields.imageAlt.onChange}
onRelationChange={fields.imageRel.onChange}
/>
</NotEditable>
),
label: 'Image',
schema: {
imageAlt: fields.text({
label: 'Image Alt',
defaultValue: '',
}),
imageRel: fields.relationship({
listKey: 'Image',
label: 'Image Relation',
selection: 'id, image { width, height, url }',
}),
image: image({
listKey: 'Image',
}),
},
chromeless: true,
}),
/** YouTube Video */
youtube: component({
preview: ({ fields }) => (
<NotEditable>
<div>
{fields.url.value ? (
<iframe
style={{
maxWidth: '100%',
width: fields.width.value
? `${fields.width.value}${fields.width.value.includes('%') ? '' : 'px'}`
: 'auto',
height: fields.height.value ? `${fields.height.value}px` : '100%',
}}
src={fields.url.value}
title="YouTube video player"
frameBorder="0"
scrolling="no"
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope"
allowFullScreen
/>
) : (
<span>Please, edit video URL...</span>
)}
</div>
</NotEditable>
),
label: 'Youtube',
schema: {
url: fields.url({
label: 'Youtube embed URL',
defaultValue: '',
}),
width: fields.text({
label: 'Video player width',
defaultValue: '',
}),
height: fields.text({
label: 'Video player height',
defaultValue: '',
}),
},
chromeless: false,
}),
}