-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b894056
commit ecd4dc9
Showing
3 changed files
with
115 additions
and
58 deletions.
There are no files selected for viewing
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
95 changes: 95 additions & 0 deletions
95
packages/kotti-ui/source/kotti-field-select/components/Options.vue
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,95 @@ | ||
<template> | ||
<div class="kt-field-select__options"> | ||
<IconTextItem | ||
v-for="(option, index) in modifiedOptions" | ||
:key="index" | ||
:isDisabled="option.isDisabled" | ||
:isSelected="option.isSelected" | ||
:label="option.label" | ||
@click.stop="() => selectOption(option)" | ||
/> | ||
</div> | ||
</template> | ||
|
||
<script lang="ts"> | ||
import { computed, defineComponent } from '@vue/composition-api' | ||
import { z } from 'zod' | ||
import { useTranslationNamespace } from '../../kotti-i18n/hooks' | ||
import IconTextItem from '../../kotti-popover/components/IconTextItem.vue' | ||
import { makeProps } from '../../make-props' | ||
// type ModifiedOption = | ||
// KottiFieldSingleSelectRemote.Props['options'][number] & { | ||
// isSelected: boolean | ||
// } | ||
const NO_DATA = Symbol('NO_DATA') | ||
const propsSchema = z.object({ | ||
isDisabled: z.boolean().default(false), | ||
isMultiple: z.boolean().default(false), | ||
options: z.array(z.any()), // FIXME | ||
value: z.array(z.unknown()), // FIXME | ||
}) | ||
export default defineComponent<z.output<typeof propsSchema>>({ | ||
name: 'FieldSelectOptions', | ||
components: { | ||
IconTextItem, | ||
}, | ||
props: makeProps(propsSchema), | ||
setup(props, { emit }) { | ||
const translations = useTranslationNamespace('KtFieldSelects') | ||
return { | ||
modifiedOptions: computed(() => | ||
props.options.length > 0 | ||
? props.options.map((option) => ({ | ||
...option, | ||
isDisabled: (props.isDisabled || option.isDisabled) ?? false, | ||
isSelected: props.value.includes(option.value), | ||
})) | ||
: [ | ||
{ | ||
label: translations.value.noDataText, | ||
isDisabled: true, | ||
isSelected: false, | ||
value: NO_DATA, | ||
}, | ||
], | ||
), | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
selectOption: (option: any /* FIXME */) => { | ||
if (option.isDisabled) return | ||
if (props.isMultiple) | ||
emit( | ||
'input', | ||
props.value.includes(option.value) | ||
? props.value.filter((v) => v !== option.value) | ||
: [...props.value, option.value], | ||
) | ||
else | ||
emit( | ||
'input', | ||
props.value.includes(option.value) ? [] : [option.value], | ||
) | ||
}, | ||
} | ||
}, | ||
}) | ||
</script> | ||
|
||
<style lang="scss" scoped> | ||
.kt-field-select__options { | ||
max-height: 40vh; | ||
/* | ||
undo padding from theme, | ||
alternatively fork theme and remove the left/right padding | ||
*/ | ||
margin-right: -9px; | ||
margin-left: -9px; | ||
overflow-y: auto; | ||
} | ||
</style> |
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 @@ | ||
option and field level support for data test |