-
Notifications
You must be signed in to change notification settings - Fork 887
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FtRadioButton and FtCheckboxList v-model and composition API (#6463)
- Loading branch information
Showing
10 changed files
with
242 additions
and
282 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
<template> | ||
<div class="pure-checkbox filter"> | ||
<h3 class="checkboxTitle"> | ||
{{ title }} | ||
</h3> | ||
<template | ||
v-for="(label, index) in labels" | ||
> | ||
<input | ||
:id="id + values[index]" | ||
:key="index" | ||
v-model="modelValue" | ||
:name="id" | ||
:value="values[index]" | ||
:disabled="disabled" | ||
class="checkbox" | ||
type="checkbox" | ||
> | ||
<label | ||
:key="label" | ||
:for="id + values[index]" | ||
> | ||
{{ label }} | ||
</label> | ||
</template> | ||
</div> | ||
</template> | ||
|
||
<script setup> | ||
import { ref, watch } from 'vue' | ||
import { useId } from '../../composables/use-id-polyfill' | ||
const id = useId() | ||
const props = defineProps({ | ||
title: { | ||
type: String, | ||
required: true | ||
}, | ||
labels: { | ||
type: Array, | ||
required: true | ||
}, | ||
values: { | ||
type: Array, | ||
required: true | ||
}, | ||
disabled: { | ||
type: Boolean, | ||
default: false | ||
}, | ||
// Required for v-model in the parent component (https://v2.vuejs.org/v2/guide/components#Using-v-model-on-Components) | ||
// Do not rename or remove | ||
// TODO: Replace with defineModel in Vue 3 | ||
value: { | ||
type: Array, | ||
required: true | ||
} | ||
}) | ||
// Required for v-model in the parent component (https://v2.vuejs.org/v2/guide/components#Using-v-model-on-Components) | ||
// Do not rename or remove | ||
// TODO: Replace with defineModel in Vue 3 | ||
const emit = defineEmits(['input']) | ||
/** @type {import('vue').Ref<string[]>} */ | ||
const modelValue = ref(props.value) | ||
watch( | ||
modelValue, | ||
(newValue) => { | ||
emit('input', newValue) | ||
}, | ||
{ deep: true } | ||
) | ||
watch( | ||
() => props.value, | ||
(newValue) => { | ||
modelValue.value = newValue | ||
}, | ||
{ deep: true } | ||
) | ||
</script> | ||
|
||
<style scoped src="./FtCheckboxList.css" /> |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
<template> | ||
<div class="pure-radiobutton filter"> | ||
<h3 class="radioTitle"> | ||
{{ title }} | ||
</h3> | ||
<template | ||
v-for="(label, index) in labels" | ||
> | ||
<input | ||
:id="id + values[index]" | ||
:key="index" | ||
:name="id" | ||
:value="values[index]" | ||
:checked="value === values[index]" | ||
:disabled="disabled" | ||
class="radio" | ||
type="radio" | ||
@change="handleChange(values[index])" | ||
> | ||
<label | ||
:key="label" | ||
:for="id + values[index]" | ||
> | ||
{{ label }} | ||
</label> | ||
</template> | ||
</div> | ||
</template> | ||
|
||
<script setup> | ||
import { useId } from '../../composables/use-id-polyfill' | ||
const id = useId() | ||
defineProps({ | ||
title: { | ||
type: String, | ||
required: true | ||
}, | ||
labels: { | ||
type: Array, | ||
required: true | ||
}, | ||
values: { | ||
type: Array, | ||
required: true | ||
}, | ||
disabled: { | ||
type: Boolean, | ||
default: false | ||
}, | ||
// Required for v-model in the parent component (https://v2.vuejs.org/v2/guide/components#Using-v-model-on-Components) | ||
// Do not rename or remove | ||
// TODO: Replace with defineModel in Vue 3 | ||
value: { | ||
type: String, | ||
required: true | ||
} | ||
}) | ||
// Required for v-model in the parent component (https://v2.vuejs.org/v2/guide/components#Using-v-model-on-Components) | ||
// Do not rename or remove | ||
// TODO: Replace with defineModel in Vue 3 | ||
const emit = defineEmits(['input']) | ||
/** | ||
* @param {string} value | ||
*/ | ||
function handleChange(value) { | ||
emit('input', value) | ||
} | ||
</script> | ||
|
||
<style scoped src="./FtRadioButton.css" /> |
Oops, something went wrong.