|
1 | 1 | <template>
|
2 |
| - <span>CustomSelect</span> |
| 2 | + <span class="vcron-p-select"> |
| 3 | + <!-- HACK: load style of PrimeVue Listbox --> |
| 4 | + <Listbox v-show="false"></Listbox> |
| 5 | + <p-button :disabled="disabled" v-bind="buttonProps" @click="toggle"> |
| 6 | + {{ selection ?? selectedStr |
| 7 | + }}<i class="pi pi-times" v-if="clearable && !isEmpty" @click="clear()" @click.stop="" /> |
| 8 | + </p-button> |
| 9 | + |
| 10 | + <p-popover v-bind="popoverProps" ref="popover"> |
| 11 | + <div class="vcron-p-row" v-for="(itemRow, i) in itemRows" :key="i"> |
| 12 | + <div |
| 13 | + :class="[has(item) ? 'vcron-p-col-selected' : '']" |
| 14 | + class="vcron-p-col" |
| 15 | + :flex="1" |
| 16 | + v-for="(item, j) in itemRow" |
| 17 | + :key="j" |
| 18 | + @click=" |
| 19 | + (evt) => { |
| 20 | + if (!item) return |
| 21 | + select(evt, item) |
| 22 | + } |
| 23 | + " |
| 24 | + > |
| 25 | + <template v-if="item"> |
| 26 | + {{ item.text }} |
| 27 | + </template> |
| 28 | + </div> |
| 29 | + </div> |
| 30 | + </p-popover> |
| 31 | + </span> |
3 | 32 | </template>
|
4 | 33 |
|
5 | 34 | <script lang="ts">
|
6 |
| -import { defineComponent } from 'vue' |
| 35 | +import { selectProps, setupSelect } from '@vue-js-cron/core' |
| 36 | +import { default as PButton, type ButtonProps } from 'primevue/button' |
| 37 | +import { usePrimeVue } from 'primevue/config' |
| 38 | +import Listbox from 'primevue/listbox' |
| 39 | +import { default as PPopover, type PopoverProps } from 'primevue/popover' |
| 40 | +import { defineComponent, ref, type PropType } from 'vue' |
7 | 41 |
|
8 | 42 | export default defineComponent({
|
| 43 | + inheritAttrs: false, |
9 | 44 | name: 'CustomSelect',
|
10 |
| - // This component will be implemented in the next step |
| 45 | + components: { |
| 46 | + PButton, |
| 47 | + PPopover, |
| 48 | + Listbox, |
| 49 | + }, |
| 50 | + props: { |
| 51 | + ...selectProps<any, string | number>(), |
| 52 | + buttonProps: { |
| 53 | + type: Object as PropType<ButtonProps>, |
| 54 | + default: () => {}, |
| 55 | + }, |
| 56 | + popoverProps: { |
| 57 | + type: Object as PropType<PopoverProps>, |
| 58 | + default: () => {}, |
| 59 | + }, |
| 60 | + hideOnClick: { |
| 61 | + type: Boolean, |
| 62 | + default: true, |
| 63 | + }, |
| 64 | + }, |
| 65 | + emits: ['update:model-value'], |
| 66 | + setup(props, ctx) { |
| 67 | + const s = setupSelect(props, () => props.modelValue, ctx) |
| 68 | + const popover = ref() |
| 69 | + const primevue = usePrimeVue() |
| 70 | + const prefix: string = primevue.config.theme?.options?.prefix + '-' ?? '' |
| 71 | +
|
| 72 | + const cx = (name: string) => { |
| 73 | + return prefix + name |
| 74 | + } |
| 75 | +
|
| 76 | + const toggle = (evt: Event) => { |
| 77 | + popover.value.toggle(evt) |
| 78 | + } |
| 79 | +
|
| 80 | + const select = (evt: Event, item: any) => { |
| 81 | + if (!item) return |
| 82 | + s.select(item) |
| 83 | + if (props.hideOnClick) { |
| 84 | + toggle(evt) |
| 85 | + } |
| 86 | + } |
| 87 | +
|
| 88 | + return { |
| 89 | + ...s, |
| 90 | + popover, |
| 91 | + toggle, |
| 92 | + cx, |
| 93 | + select, |
| 94 | + } |
| 95 | + }, |
11 | 96 | })
|
12 | 97 | </script>
|
| 98 | + |
| 99 | +<style> |
| 100 | +.vcron-p-row { |
| 101 | + display: flex; |
| 102 | + flex-wrap: nowrap; |
| 103 | + border: 0px !important; |
| 104 | + box-shadow: none !important; |
| 105 | +} |
| 106 | +
|
| 107 | +.vcron-p-col { |
| 108 | + flex-basis: 100%; |
| 109 | + min-width: 0; |
| 110 | + text-align: center; |
| 111 | + cursor: pointer; |
| 112 | + overflow: hidden; |
| 113 | + padding: var(--p-listbox-option-padding); |
| 114 | + border: 0 none; |
| 115 | + border-radius: var(--p-listbox-option-border-radius); |
| 116 | + color: var(--p-listbox-option-color); |
| 117 | + transition: |
| 118 | + background var(--p-listbox-transition-duration), |
| 119 | + color var(--p-listbox-transition-duration), |
| 120 | + border-color var(--p-listbox-transition-duration), |
| 121 | + box-shadow var(--p-listbox-transition-duration), |
| 122 | + outline-color var(--p-listbox-transition-duration); |
| 123 | +} |
| 124 | +
|
| 125 | +.vcron-p-col:not(.vcron-p-col-selected):hover { |
| 126 | + background: var(--p-listbox-option-focus-background); |
| 127 | + color: var(--p-listbox-option-focus-color); |
| 128 | +} |
| 129 | +
|
| 130 | +.vcron-p-col-selected { |
| 131 | + background: var(--p-listbox-option-selected-background); |
| 132 | + color: var(--p-listbox-option-selected-color); |
| 133 | +} |
| 134 | +</style> |
0 commit comments