You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

button-choice.vue 1.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <template lang="pug">
  2. .form--step.button-choice
  3. header
  4. p selections {{selected}} {{opts}}
  5. main(:class="{ 'f-row': opts.length > 2, 'f-col': opts.length <= 2 }")
  6. button(v-for="op in opts" :class="isSelected(op)" @mouseover="hoverOption(op)" @click="selectOption(op)") {{ op }}
  7. </template>
  8. <script setup>
  9. import { ref } from 'vue'
  10. const emit = defineEmits(['selected', 'hovered'])
  11. const props = defineProps({
  12. opts: {
  13. required: true,
  14. type: Array,
  15. default: () => ['up', 'down'],
  16. // default: () => ['up', 'left', 'right', 'down'],
  17. },
  18. prompt: {
  19. required: true,
  20. type: String,
  21. },
  22. })
  23. const selected = ref([])
  24. const isSelected = val => {
  25. return selected.value.includes(val) ? 'selected' : ''
  26. }
  27. const selectOption = optionVal => {
  28. if (!selected.value.includes(optionVal)) {
  29. selected.value.push(optionVal)
  30. } else {
  31. selected.value = selected.value.filter(val => val != optionVal)
  32. }
  33. const sel = {}
  34. sel[props.prompt] = selected.value[0]
  35. emit('selected', sel)
  36. }
  37. const hoverOption = optionVal => {
  38. emit('hovered', props.prompt, optionVal)
  39. }
  40. </script>
  41. <style lang="postcss">
  42. // prettier-ignore
  43. @import '@/sss/theme.sss'
  44. .button-choice
  45. color: white
  46. main
  47. flex-wrap: wrap
  48. button
  49. padding: 1em
  50. border: 2px teal solid
  51. border-radius: 4px
  52. &.selected
  53. border: 2px teal dotted
  54. </style>