@@ -6,53 +6,72 @@ import {
66 Component ,
77 DiscriminatedBlocks ,
88 Field ,
9+ FieldView ,
910 HasOne ,
1011 SelectField ,
12+ Stack ,
1113 TextField ,
1214 useEntity ,
1315} from '@contember/admin'
16+ import { Gap } from '../../gap/admin'
1417
1518export interface LinkFieldProps {
1619 field : string
1720 label ?: string
1821 titleField ?: boolean
1922 allowDisconnect ?: boolean
2023 allowTargetBlank ?: boolean
24+ compact ?: boolean
2125}
2226
2327export const LinkField = Component < LinkFieldProps > (
24- ( { field, label, titleField = true , allowDisconnect = false , allowTargetBlank = false } ) => {
28+ ( { field, label, titleField = true , allowDisconnect = false , allowTargetBlank = false , compact = true } ) => {
2529 const rootEntity = useEntity ( )
2630
2731 const insideContent = (
2832 < HasOne field = { field } >
2933 { titleField && < TextField field = "title" label = "Title" /> }
30- < DiscriminatedBlocks field = "type" label = "Type" >
31- < Block discriminateBy = "internal" label = "Internal" >
32- < SelectField field = "internalLink" label = "URL" options = "Linkable.url" />
33- </ Block >
34- < Block discriminateBy = "external" label = "External" >
35- < TextField field = "externalLink" label = "URL" />
36- </ Block >
37- </ DiscriminatedBlocks >
34+ < Stack direction = { compact ? 'horizontal' : 'vertical' } >
35+ < DiscriminatedBlocks field = "type" label = "Type" >
36+ < Block discriminateBy = "internal" label = "Internal" >
37+ < SelectField field = "internalLink" label = "URL" options = "Linkable.url" />
38+ </ Block >
39+ < Block discriminateBy = "external" label = "External" >
40+ < TextField field = "externalLink" label = "URL" />
41+ </ Block >
42+ </ DiscriminatedBlocks >
43+ </ Stack >
3844 { allowTargetBlank && (
39- < CheckboxField
40- field = "isTargetBlank"
41- label = "Target blank"
42- defaultValue = { false }
43- labelDescription = {
44- < >
45- Force link to open in new tab.{ ' ' }
46- < span style = { { color : 'red' } } >
47- This feature is highly discouraged.{ ' ' }
48- < a href = "https://css-tricks.com/use-target_blank/" target = "_blank" rel = "noreferrer" >
49- Read more
50- </ a >
51- .
52- </ span >
53- </ >
54- }
55- />
45+ < >
46+ < Gap />
47+ < CheckboxField
48+ field = "isTargetBlank"
49+ label = "Target blank"
50+ defaultValue = { false }
51+ labelDescription = {
52+ < FieldView < boolean >
53+ field = "isTargetBlank"
54+ render = { field => (
55+ < >
56+ Force link to open in new tab.
57+ { field . value && (
58+ < >
59+ { ' ' }
60+ < span style = { { color : 'red' } } >
61+ This feature is highly discouraged.{ ' ' }
62+ < a href = "https://css-tricks.com/use-target_blank/" target = "_blank" rel = "noreferrer" >
63+ Read more
64+ </ a >
65+ .
66+ </ span >
67+ </ >
68+ ) }
69+ </ >
70+ ) }
71+ />
72+ }
73+ />
74+ </ >
5675 ) }
5776 </ HasOne >
5877 )
0 commit comments