Skip to content

Commit 07f6cad

Browse files
committed
Add preview for structure field
1 parent e53fb8b commit 07f6cad

File tree

6 files changed

+85
-5
lines changed

6 files changed

+85
-5
lines changed

index.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
$color-light: #efefef;
2+
$color-background: $color-light;
3+
$color-border: #ccc;
4+
$box-shadow-card: rgba($color-dark, 0.05) 0 2px 5px;
5+
6+
.k-locator-field-preview {
7+
padding: 0 .75rem;
8+
.locator-preview, {
9+
display: flex;
10+
figcaption {
11+
box-shadow: $box-shadow-card;
12+
background: $color-background;
13+
line-height: 1.5em;
14+
padding: 0 .5rem;
15+
border: 1px solid $color-border;
16+
border-left: 0;
17+
border-radius: 1px;
18+
white-space: nowrap;
19+
overflow: hidden;
20+
text-overflow: ellipsis;
21+
}
22+
}
23+
}

src/assets/css/styles.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
@import
55
'vendors/_leaflet.scss';
66
@import
7+
'components/_preview.scss',
78
'components/_map.scss';
89

910

1011
.k-locator-field {
1112

12-
1313
.k-field-header {
1414
.k-button + .k-button {
1515
margin-left: 1.5rem;

src/components/LocatorPreview.vue

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<template>
2+
<div class="k-locator-field-preview">
3+
<figure class="locator-preview">
4+
<k-icon type="locatorMarker" back="pattern" class="k-pages-field-preview-image" />
5+
<figcaption v-html="location"></figcaption>
6+
</figure>
7+
</div>
8+
</template>
9+
10+
<script>
11+
export default {
12+
props: {
13+
value: [Object, String],
14+
},
15+
computed: {
16+
locationString() {
17+
let number = this.value.number ? this.value.number + ' ' : ''
18+
let address = this.value.address ? this.value.address + ', ' : ''
19+
let postcode = this.value.postcode ? this.value.postcode + ' ' : ''
20+
let city = this.value.city ? this.value.city + ', ' : ''
21+
let country = this.value.country ? this.value.country : ''
22+
23+
return number + address + postcode + city + country
24+
},
25+
latLonString() {
26+
if(this.value.lat && this.value.lon) {
27+
let lat = typeof this.value.lat === 'string' ? parseFloat(this.value.lat) : this.value.lat
28+
lat = lat.toFixed(5)
29+
let lon = typeof this.value.lon === 'string' ? parseFloat(this.value.lon) : this.value.lon
30+
lon = lon.toFixed(5)
31+
32+
return lat + ', ' + lon
33+
}
34+
else {
35+
return false
36+
}
37+
},
38+
location() {
39+
if(this.locationString != '') return this.locationString
40+
else if(this.latLonString) {
41+
return '<span class="locator-latlon-preview">'+ this.latLonString +'</span>'
42+
}
43+
else {
44+
return ''
45+
}
46+
}
47+
}
48+
};
49+
</script>

src/index.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
1-
import Locator from './field/Locator.vue'
1+
import Locator from './field/Locator.vue'
2+
import LocatorPreview from './components/LocatorPreview.vue'
3+
24
import './assets/svg/icons.js'
35

46
panel.plugin('sylvainjule/locator', {
57
fields: {
68
locator: Locator,
79
},
8-
});
10+
components: {
11+
'k-locator-field-preview': LocatorPreview,
12+
},
13+
icons: {
14+
locatorMarker: '<g><circle cx="8" cy="6.99" r="2"/><path d="M7.3,15.68c-.1-.1-4.19-3.7-4.19-3.8A6.34,6.34,0,0,1,1,7,7,7,0,0,1,7.9,0H8a7,7,0,0,1,7,6.9V7a6.72,6.72,0,0,1-2.1,5l-4.2,3.8A1.07,1.07,0,0,1,7.3,15.68Zm-2.7-5,3.4,3,3.39-3h0A5,5,0,0,0,13,7.09a5,5,0,0,0-4.89-5H8A4.88,4.88,0,0,0,3,7a5.22,5.22,0,0,0,1.6,3.69Z"/></g>'
15+
}
16+
});

0 commit comments

Comments
 (0)