Skip to content

Commit

Permalink
add Vue component, create php method.
Browse files Browse the repository at this point in the history
  • Loading branch information
PrestaSafe committed Jun 25, 2024
1 parent d5d5c63 commit b6c6853
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 861 deletions.
7 changes: 6 additions & 1 deletion _dev/src/components/FieldRepeater.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import Button from './Button.vue'
import FileUpload from './form/FileUpload.vue'
import Choices from './form/Choices.vue'
import Icon from './Icon.vue'
// import Slider from './Slider.vue'
import Slider from './Slider.vue'
// tinyMCE
import Editor from '@tinymce/tinymce-vue'
Expand Down Expand Up @@ -146,6 +146,11 @@ const toolbarOptions = [
<VueDatePicker :model-value="formatDateFromString(f.value)" :enable-time-picker="false" @update:modelValue="f.value = $event" />
</div>

<div class="my-4" v-if="f.type == 'slider'">
<Title :title="f.label" />
<Slider v-model="f.value" v-bind="f.options" />
</div>

</div>
</template>

57 changes: 39 additions & 18 deletions _dev/src/components/Slider.vue
Original file line number Diff line number Diff line change
@@ -1,36 +1,57 @@
<script setup>
import { ref } from 'vue'
import { ref, defineProps, defineEmits, watch } from 'vue'
const emit = defineEmits(['update:modelValue'])
let value = ref(50)
const updateValue = (event) => {
value.value = event.target.value
}
let type = ref('int')
let step = ref(1)
const props = defineProps({
value: {
type: Number,
required: true
},
type: {
type: String,
default: 'int',
validator: (value) => ['int', 'step'].includes(value)
modelValue: {
type: [Number, String],
required: true,
default: 0
},
step: {
type: Number,
default: 1
},
min: {
type: Number,
default: 0
},
max: {
type: Number,
default: 100
}
})
const localValue = ref(props.modelValue)
watch(() => props.modelValue, (newValue) => {
localValue.value = newValue
})
// Mettez à jour la valeur et émettez le changement
const updateValue = (event) => {
const newValue = parseInt(event.target.value)
localValue.value = newValue
emit('update:modelValue', newValue)
}
</script>

<template>
<div class="slider">
<input class="bg-indigo" type="range" step="2" min="4" max="8" v-model="value" @input="updateValue" />
<span>{{ value }}</span>
<div class="slider flex">
<input class="bg-indigo-500" type="range"
:step="props.step"
:min="props.min"
:max="props.max"
:value="localValue"
@input="updateValue"
/>

<span class="pl-4">
{{ props.modelValue }}
</span>
</div>
</template>

Expand Down
20 changes: 20 additions & 0 deletions classes/prettyblocks/core/FieldCore.php
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,26 @@ public function formatForFront()
|
*/


/**
* formatFieldSlider
* use for display field type slider in PrettyBlocks
* @return Integer
*/
public function formatFieldSlider()
{
// if value exists in DB and new_value is empty
if (!is_null($this->value) && is_null($this->new_value)) {
return (int) $this->value;
}
// if value doesn't exists in DB and new value is set
if ($this->force_default_value && is_null($this->new_value)) {
return (int) $this->default;
}

return (int) $this->new_value;
}

/**
* formatFieldDatePicker
*
Expand Down
Loading

0 comments on commit b6c6853

Please sign in to comment.