π₯ π₯ π₯ A Free & Self-hostable Airtable Alternative
TypeScript airtableairtable-alternativeautomatic-apihacktoberfestlow-codeno-codeno-code-databaseno-code-platformpostgresqlrest-apirestful-apispreadsheetsqliteswagger
fix(nc-gui): use reusable ncListItem component in ncList
Ramesh Mane362717598f31
diff --git a/packages/nc-gui/components/nc/List/Item.vue b/packages/nc-gui/components/nc/List/Item.vuenew file mode 100644index 0000000000..92a4ec0ad3--- /dev/null+++ b/packages/nc-gui/components/nc/List/Item.vue@@ -0,0 +1,125 @@+<script lang="ts" setup>+import type { NcListItemProps } from '#imports'++/**+ * NcListItem β standalone list-row component.+ *+ * Encapsulates all state-based styling (selected, active, disabled, locked,+ * variant padding, group-header, itemFullWidth) that was previously inlined+ * inside NcList. Can be used:+ *+ * 1. Inside NcList β NcList drives isSelected / isActive via its own state.+ * 2. Standalone β caller passes isSelected / isActive / isDisabled directly+ * and handles the `click` / `mouseover` emits itself.+ *+ * Slots mirror NcList's named slots so NcList can forward them unchanged:+ * - listItemGroupHeader { option }+ * - listItem { option, isSelected }+ * - listItemExtraLeft { option, isSelected, searchBasisInfo }+ * - listItemContent { option, isSelected, searchBasisInfo }+ * - listItemExtraRight { option, isSelected, searchBasisInfo }+ * - listItemSelectedIcon { option, isSelected }+ */++const props = withDefaults(defineProps<NcListItemProps>(), {+ variant: 'default',+ index: -1,+ optionLabelKey: 'label',+ isSelected: false,+ isActive: false,+ showSelectedOption: true,+ showHoverEffect: true,+ isLocked: false,+ itemFullWidth: false,+ itemClassName: '',+ groupHeaderClassName: '',+ itemTooltipPlacement: 'right',+ groupHeaderHeight: 28,+})++const emits = defineEmits<{+ (e: 'click', option: NcListItemType, index: number, event: MouseEvent): void+ (e: 'mouseover'): void+}>()++const handleClick = (event: MouseEvent) => {+ if (props.option.ncGroupHeader || props.option.ncItemDisabled || props.isLocked) return+ emits('click', props.option, props.index, event)+}++const handleMouseover = () => {+ if (props.option.ncGroupHeader) return+ emits('mouseover')+}+</script>++<template>+ <NcTooltip+ class="flex items-center gap-2 nc-list-item w-full px-2 my-[2px] first-of-type:mt-0 last-of-type:mb-0"+ :class="[+ `nc-list-option-${index}`,+ {+ 'nc-list-group-header text-nc-content-gray-muted text-bodySmBold border-t !border-t-nc-border-gray-medium !first-of-type:border-t-transparent flex items-center':+ option.ncGroupHeader,+ 'rounded-md': !itemFullWidth && !option.ncGroupHeader,+ 'nc-list-option-selected': isSelected,+ 'bg-nc-bg-gray-light': !option?.ncItemDisabled && showHoverEffect && isSelected,+ 'bg-nc-bg-gray-light nc-list-option-active': !option?.ncItemDisabled && isActive && !option.ncGroupHeader,+ 'opacity-60 cursor-not-allowed': option?.ncItemDisabled && !option?.ncGroupHeader,+ 'hover:bg-nc-bg-gray-light cursor-pointer': !option?.ncItemDisabled && !option?.ncGroupHeader,+ 'py-2': variant === 'default' && !option.ncGroupHeader,+ 'py-[5px]': variant === 'medium' && !option.ncGroupHeader,+ 'py-[3px]': variant === 'small' && !option.ncGroupHeader,+ '-mx-1 px-3 w-[calc(100%_+_8px)]': variant === 'small' && option.ncGroupHeader,+ '-mx-2 px-4 w-[calc(100%_+_16px)]': variant !== 'small' && option.ncGroupHeader,+ 'pointer-events-none': isLocked,+ },+ itemClassName,+ option.ncGroupHeader ? groupHeaderClassName : '',+ ]"+ :style="{+ minHeight: `${groupHeaderHeight}px`,+ }"+ :placement="itemTooltipPlacement"+ :disabled="!option?.ncItemTooltip"+ :attrs="{+ onMouseover: () => handleMouseover(),+ }"+ @click="handleClick"+ >+ <template #title>{{ option.ncItemTooltip }}</template>++ <!-- Group header row -->+ <slot v-if="option.ncGroupHeader" name="listItemGroupHeader" :option="option">+ <div>{{ option.ncGroupHeaderLabel }}</div>+ </slot>++ <!-- Regular item row -->+ <slot v-else name="listItem" :option="option" :is-selected="isSelected">+ <slot name="listItemExtraLeft" :option="option" :is-selected="isSelected" :search-basis-info="searchBasisInfo" />++ <slot name="listItemContent" :option="option" :is-selected="isSelected" :search-basis-info="searchBasisInfo">+ <NcTooltip class="truncate" :class="{ 'flex-1': !searchBasisInfo }" show-on-truncate-only>+ <template #title>{{ option[optionLabelKey] }}</template>+ {{ option[optionLabelKey] }}+ </NcTooltip>+ <div v-if="searchBasisInfo" class="flex-1 flex">+ <NcTooltip :title="searchBasisInfo" class="flex cursor-help">+ <GeneralIcon icon="info" class="flex-none h-3.5 w-3.5 text-nc-content-gray-muted" />+ </NcTooltip>+ </div>+ </slot>++ <slot name="listItemExtraRight" :option="option" :is-selected="isSelected" :search-basis-info="searchBasisInfo" />++ <slot name="listItemSelectedIcon" :option="option" :is-selected="isSelected">+ <GeneralIcon+ v-if="showSelectedOption && isSelected"+ id="nc-selected-item-icon"+ icon="check"+ class="flex-none text-nc-content-brand w-4 h-4"+ />+ </slot>+ </slot>+ </NcTooltip>+</template>diff --git a/packages/nc-gui/components/nc/List/index.vue b/packages/nc-gui/components/nc/List/index.vueindex 68437d359b..c9ce7973a5 100644--- a/packages/nc-gui/components/nc/List/index.vue+++ b/packages/nc-gui/components/nc/List/index.vue@@ -525,114 +525,46 @@ const handleEscape = (event: KeyboardEvent) => {]"><div v-bind="revisedWrapperProps" :class="wrapperClassName">- <NcTooltip+ <NcListItemv-for="{ data: option, index: idx } in virtualList":key="idx"- class="flex items-center gap-2 nc-list-item w-full px-2 my-[2px] first-of-type:mt-0 last-of-type:mb-0"- :class="[- `nc-list-option-${idx}`,- {- 'nc-list-group-header text-nc-content-gray-muted text-bodySmBold border-t !border-t-nc-border-gray-medium !first-of-type:border-t-transparent flex items-center':- option.ncGroupHeader,- 'rounded-md': !itemFullWidth && !option.ncGroupHeader,- 'nc-list-option-selected': compareVModel(option[optionValueKey], option.ncGroupHeader),- 'bg-nc-bg-gray-light ':- !option?.ncItemDisabled &&- showHoverEffectOnSelectedOption &&- compareVModel(option[optionValueKey], option.ncGroupHeader),- 'bg-nc-bg-gray-light nc-list-option-active':- !option?.ncItemDisabled && activeOptionIndex === idx && !option.ncGroupHeader,- 'opacity-60 cursor-not-allowed': option?.ncItemDisabled && !option?.ncGroupHeader,- 'hover:bg-nc-bg-gray-light cursor-pointer': !option?.ncItemDisabled && !option?.ncGroupHeader,- 'py-2': variant === 'default' && !option.ncGroupHeader,- 'py-[5px]': variant === 'medium' && !option.ncGroupHeader,- 'py-[3px]': variant === 'small' && !option.ncGroupHeader,- '-mx-1 px-3 w-[calc(100%_+_8px)]': variant === 'small' && option.ncGroupHeader,- '-mx-2 px-4 w-[calc(100%_+_16px)]': variant !== 'small' && option.ncGroupHeader,- 'pointer-events-none': isLocked,- },- `${itemClassName}`,- `${option.ncGroupHeader ? groupHeaderClassName : ''}`,- ]"- :style="{- minHeight: `${groupHeaderHeight}px`,- }"- :placement="itemTooltipPlacement"- :disabled="!option?.ncItemTooltip"- :attrs="{- onMouseover: () => !option.ncGroupHeader && handleResetHoverEffect(true, idx),- }"- @click="handleSelectOption(option, idx, $event)"+ :option="option"+ :variant="variant"+ :index="idx"+ :option-label-key="optionLabelKey"+ :is-selected="compareVModel(option[optionValueKey], option.ncGroupHeader)"+ :is-active="activeOptionIndex === idx"+ :show-selected-option="showSelectedOption"+ :show-hover-effect="showHoverEffectOnSelectedOption"+ :is-locked="isLocked"+ :item-full-width="itemFullWidth"+ :item-class-name="itemClassName"+ :group-header-class-name="groupHeaderClassName"+ :item-tooltip-placement="itemTooltipPlacement"+ :search-basis-info="searchBasisInfoMap[option[optionValueKey]]"+ :group-header-height="groupHeaderHeight"+ @click="handleSelectOption"+ @mouseover="handleResetHoverEffect(true, idx)">- <template #title>{{ option.ncItemTooltip }} </template>- <slot v-if="option.ncGroupHeader" name="listItemGroupHeader" :option="option">- <div>- {{ option.ncGroupHeaderLabel }}- </div>- </slot>- <slot- v-else- name="listItem"- :option="option"- :is-selected="compareVModel(option[optionValueKey], option.ncGroupHeader)"- :index="idx"- :search-basis-info="searchBasisInfoMap[option[optionValueKey]]"- >- <slot- name="listItemExtraLeft"- :option="option"- :is-selected="compareVModel(option[optionValueKey], option.ncGroupHeader)"- :search-basis-info="searchBasisInfoMap[option[optionValueKey]]"- >- </slot>-- <slot- name="listItemContent"- :option="option"- :is-selected="compareVModel(option[optionValueKey], option.ncGroupHeader)"- :search-basis-info="searchBasisInfoMap[option[optionValueKey]]"- >- <NcTooltip- class="truncate"- :class="{- 'flex-1': !searchBasisInfoMap[option[optionValueKey]],- }"- show-on-truncate-only- >- <template #title>- {{ option[optionLabelKey] }}- </template>- {{ option[optionLabelKey] }}- </NcTooltip>- <div v-if="!option?.ncGroupHeader && searchBasisInfoMap[option[optionValueKey]]" class="flex-1 flex">- <NcTooltip :title="searchBasisInfoMap[option[optionValueKey]]" class="flex cursor-help">- <GeneralIcon icon="info" class="flex-none h-3.5 w-3.5 text-nc-content-gray-muted" />- </NcTooltip>- </div>- </slot>-- <slot- name="listItemExtraRight"- :option="option"- :is-selected="compareVModel(option[optionValueKey], option.ncGroupHeader)"- :search-basis-info="searchBasisInfoMap[option[optionValueKey]]"- >- </slot>-- <slot- name="listItemSelectedIcon"- :option="option"- :is-selected="compareVModel(option[optionValueKey], option.ncGroupHeader)"- >- <GeneralIcon- v-if="showSelectedOption && compareVModel(option[optionValueKey], option.ncGroupHeader)"- id="nc-selected-item-icon"- icon="check"- class="flex-none text-nc-content-brand w-4 h-4"- />- </slot>- </slot>- </NcTooltip>+ <template #listItemGroupHeader="slotProps">+ <slot name="listItemGroupHeader" v-bind="slotProps" />+ </template>+ <template #listItem="slotProps">+ <slot name="listItem" v-bind="slotProps" :index="idx" />+ </template>+ <template #listItemExtraLeft="slotProps">+ <slot name="listItemExtraLeft" v-bind="slotProps" />+ </template>+ <template #listItemContent="slotProps">+ <slot name="listItemContent" v-bind="slotProps" />+ </template>+ <template #listItemExtraRight="slotProps">+ <slot name="listItemExtraRight" v-bind="slotProps" />+ </template>+ <template #listItemSelectedIcon="slotProps">+ <slot name="listItemSelectedIcon" v-bind="slotProps" />+ </template>+ </NcListItem></div></div></div>diff --git a/packages/nc-gui/lib/types.ts b/packages/nc-gui/lib/types.tsindex 93afda0078..58c271f7a8 100644--- a/packages/nc-gui/lib/types.ts+++ b/packages/nc-gui/lib/types.ts@@ -774,6 +774,51 @@ interface NcListSearchBasisOptionType {filterCallback: (input: string, option: NcListItemType, index: Number) => boolean}+/**+ * Props interface for a standalone NcListItem component.+ * Used both by NcList internally and anywhere an individual list-item+ * with consistent variant / state styling is needed.+ */+interface NcListItemProps {+ /** The list item data object */+ option: NcListItemType+ /** Size variant β controls padding and min-height */+ variant?: 'default' | 'small' | 'medium'+ /** Index within the parent list (used for keyboard-active CSS class) */+ index?: number+ /** Key for reading the label from the option object */+ optionLabelKey?: string+ /** Whether this item is currently selected */+ isSelected?: boolean+ /** Whether this item is currently active / keyboard-focused */+ isActive?: boolean+ /** Show a checkmark icon when the item is selected */+ showSelectedOption?: boolean+ /**+ * Whether to render the selected-item background highlight.+ * NcList sets this to false while the user is moving with the keyboard+ * so the hover effect doesn't compete with the keyboard-active highlight.+ */+ showHoverEffect?: boolean+ /** Disable all pointer interaction (locked view) */+ isLocked?: boolean+ /** Remove horizontal padding and rounded corners (full-width mode) */+ itemFullWidth?: boolean+ /** Extra CSS classes forwarded to the item root element */+ itemClassName?: string+ /** Extra CSS classes forwarded to group-header items */+ groupHeaderClassName?: string+ /** Placement for the item-level tooltip (ncItemTooltip) */+ itemTooltipPlacement?: TooltipPlacement+ /**+ * Secondary info shown next to the label when the item was matched via+ * a search-basis option rather than by label text.+ */+ searchBasisInfo?: string+ /** Min-height of group header rows in pixels */+ groupHeaderHeight?: number+}+/*** Props interface for the List component*/@@ -1077,6 +1122,7 @@ export type {PermissionConfig,PermissionSelectorUser,NcListProps,+ NcListItemProps,NcListItemType,NcListSearchBasisOptionType,MultiSelectRawValueType,