From 82065ed701eccacff20a4a9cfa5ae767c2ddfc9e Mon Sep 17 00:00:00 2001 From: Tommaso Bailetti Date: Thu, 7 Nov 2024 14:46:02 +0100 Subject: [PATCH] fix!: enforcing types on parent projects Due to an issue with the `@` import helper the typescript declarations were not honoured correctly. This revamp allows the correct definitions to be consumed on parent projects and enforce typings correctly. --- src/components/NeCombobox.vue | 29 ++++---- src/components/NeExpandable.vue | 2 +- src/components/NeFileInput.vue | 10 +-- src/components/NeModal.vue | 2 +- src/components/NePaginator.vue | 2 +- src/components/NeRadioSelection.vue | 26 ++++---- src/composables/useItemPagination.ts | 2 +- src/composables/useSort.ts | 5 +- src/main.ts | 98 ++++++++++++++-------------- tsconfig.app.json | 5 +- vite.config.ts | 9 +-- 11 files changed, 92 insertions(+), 98 deletions(-) diff --git a/src/components/NeCombobox.vue b/src/components/NeCombobox.vue index 5a6f51f..beccdf7 100644 --- a/src/components/NeCombobox.vue +++ b/src/components/NeCombobox.vue @@ -34,7 +34,6 @@ export interface NeComboboxOption { } export interface Props { - modelValue: string | Array options: NeComboboxOption[] label?: string placeholder?: string @@ -44,20 +43,19 @@ export interface Props { maxOptionsShown?: number multiple?: boolean disabled?: boolean - showOptionsType: boolean + showOptionsType?: boolean optional?: boolean - selectedLabel: string + selectedLabel?: string showSelectedLabel?: boolean noResultsLabel: string - limitedOptionsLabel: string + limitedOptionsLabel?: string noOptionsLabel: string acceptUserInput?: boolean - userInputLabel: string + userInputLabel?: string optionalLabel: string } const props = withDefaults(defineProps(), { - options: () => [], label: '', placeholder: '', helperText: '', @@ -68,9 +66,14 @@ const props = withDefaults(defineProps(), { showOptionsType: true, optional: false, showSelectedLabel: true, - acceptUserInput: false + acceptUserInput: false, + selectedLabel: 'Selected', + limitedOptionsLabel: 'Continue typing to show more options', + userInputLabel: 'User input' }) +const model = defineModel>() + const emit = defineEmits(['update:modelValue']) // expose focus function @@ -174,7 +177,7 @@ onMounted(() => { }) watch( - () => props.modelValue, + () => model, () => { if (props.multiple) { selectMultipleOptionsFromModelValue() @@ -255,14 +258,14 @@ function onOptionSelected(selectedOption: NeComboboxOption) { } function selectSingleOptionFromModelValue() { - const optionFound = allOptions.value.find((option) => option.id === props.modelValue) + const optionFound = allOptions.value.find((option) => option.id === model.value) if (optionFound) { selected.value = optionFound - } else if (props.acceptUserInput && props.modelValue) { + } else if (props.acceptUserInput && model.value) { const userInputOption = { - id: props.modelValue as string, - label: props.modelValue as string, + id: model.value as string, + label: model.value as string, description: props.userInputLabel } userInputOptions.value.push(userInputOption) @@ -273,7 +276,7 @@ function selectSingleOptionFromModelValue() { function selectMultipleOptionsFromModelValue() { const selectedList: NeComboboxOption[] = [] - for (const selectedOption of props.modelValue as NeComboboxOption[]) { + for (const selectedOption of model.value as NeComboboxOption[]) { const optionFound = allOptions.value.find((option) => option.id === selectedOption.id) if (optionFound) { diff --git a/src/components/NeExpandable.vue b/src/components/NeExpandable.vue index 91d2090..b8a4420 100644 --- a/src/components/NeExpandable.vue +++ b/src/components/NeExpandable.vue @@ -7,7 +7,7 @@ import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome' import { faChevronDown, faChevronUp } from '@fortawesome/free-solid-svg-icons' import { onMounted, ref, watch } from 'vue' -import { NeButton } from '@/main' +import NeButton from './NeButton.vue' const props = defineProps({ label: { diff --git a/src/components/NeFileInput.vue b/src/components/NeFileInput.vue index e7a0c88..012bcaa 100644 --- a/src/components/NeFileInput.vue +++ b/src/components/NeFileInput.vue @@ -7,15 +7,15 @@ import { computed } from 'vue' import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome' import { faFileArrowUp } from '@fortawesome/free-solid-svg-icons' -import NeProgressBar from '@/components/NeProgressBar.vue' +import NeProgressBar from './NeProgressBar.vue' interface FileInputProps { modelValue?: File | File[] | null label?: string - invalidMessage: string - dropzoneLabel: string - progress: number - showProgress: boolean + invalidMessage?: string + dropzoneLabel?: string + progress?: number + showProgress?: boolean accept?: string | undefined } diff --git a/src/components/NeModal.vue b/src/components/NeModal.vue index cbaecef..eba81ba 100644 --- a/src/components/NeModal.vue +++ b/src/components/NeModal.vue @@ -12,7 +12,7 @@ import NeButton, { type ButtonKind } from './NeButton.vue' import NeRoundedIcon from './NeRoundedIcon.vue' import type { PropType } from 'vue' -type ModalKind = 'neutral' | 'info' | 'warning' | 'error' | 'success' +export type ModalKind = 'neutral' | 'info' | 'warning' | 'error' | 'success' type PrimaryButtonKind = 'primary' | 'danger' type ModalSize = 'md' | 'lg' | 'xl' | 'xxl' diff --git a/src/components/NePaginator.vue b/src/components/NePaginator.vue index 931fa51..67d044d 100644 --- a/src/components/NePaginator.vue +++ b/src/components/NePaginator.vue @@ -9,7 +9,7 @@ import { range } from 'lodash-es' import { faChevronLeft as fasChevronLeft } from '@fortawesome/free-solid-svg-icons' import { faChevronRight as fasChevronRight } from '@fortawesome/free-solid-svg-icons' import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome' -import { NeListbox } from '@/main' +import NeListbox from './NeListbox.vue' const props = defineProps({ currentPage: { diff --git a/src/components/NeRadioSelection.vue b/src/components/NeRadioSelection.vue index 2cf23f3..064410e 100644 --- a/src/components/NeRadioSelection.vue +++ b/src/components/NeRadioSelection.vue @@ -3,17 +3,8 @@ SPDX-License-Identifier: GPL-3.0-or-later --> - + +