Skip to content

πŸ“š The open-source, offline-first Notion, Obsidian & Confluence alternative. Advanced Markdown, multi-tenant teams, OIDC/SSO, and local S3 backups. Deploy in one command.

9.7 KB
Raw Blame
<template>
  <div class="kanban-column" :class="{ 'drag-over': isDragOver }" @dragover.prevent="onDragOver" @dragleave="onDragLeave" @drop="onDrop">
    <div class="column-header">
      <div class="column-title-row">
        <button
          class="column-color-btn"
          :title="t('components.kanban.changeColor')"
          :style="{ background: `var(--${getAppAccent(column.color, true)})` }"
          @click="toggleColorPicker"
        />
        <input
          v-if="isEditing"
          ref="titleInput"
          v-model="editedTitle"
          class="column-title-input"
          @blur="saveTitle"
          @keydown.enter="saveTitle"
          @keydown.escape="cancelEdit"
        />
        <h3 v-else class="column-title" @dblclick="startEdit">{{ column.title }}</h3>

        <div class="column-actions">
          <KanbanColumnFilter :board-id="parent.id" :nodes="cards" @update:nodes="filteredNodes = $event" />
          <button class="action-btn" :title="t('components.kanban.editName')" @click="startEdit">
            <Icon name="edit" />
          </button>
          <button class="action-btn danger" :title="t('components.kanban.deleteColumn')" @click="confirmDelete">
            <Icon name="delete" />
          </button>
          <span class="column-count">{{ filteredNodes.length }}</span>
        </div>
      </div>

      <!-- Color picker dropdown -->
      <Transition name="dropdown">
        <div v-if="showColorPicker" class="color-picker">
          <button
            v-for="(_, index) in appColors"
            :key="index"
            :style="{ backgroundColor: `var(--${getAppAccent(index, true)})` }"
            :class="['color-option ', { active: column.color === index }]"
            @click="selectColor(index)"
          />
        </div>
      </Transition>
    </div>

    <div ref="contentRef" class="column-content">
      <TransitionGroup name="card-list">
        <KanbanCard
          v-for="card in filteredNodes"
          :key="card.id"
          :node="card"
          :parent="parent"
          @drag-start="$emit('cardDragStart', $event)"
          @drag-end="$emit('cardDragEnd')"
          @assign="(userId: string) => emit('assign', card.id, userId)"
          @unassign="(userId: string) => emit('unassign', card.id, userId)"
        />
      </TransitionGroup>
      <div v-if="!cards.length" class="empty-state">
        <Icon name="file" />
        <p>{{ t('components.kanban.noDocuments') }}</p>
        <span>{{ t('components.kanban.dragHere') }}</span>
      </div>
    </div>

    <button class="add-card-btn" @click="$emit('addCard', column.id)"><Icon name="plus" /> {{ t('components.kanban.addDocument') }}</button>
  </div>
</template>

<script setup lang="ts">
import DeleteColumnModal from './DeleteColumn.modal.vue';
import { appColors } from '~/helpers/constants';
import type { Node } from '~/stores';

export interface KanbanColumnData {
  id: string;
  title: string;
  color: number;
  order: number;
}

const { t } = useI18nT();
const modals = useModal();

const props = defineProps<{
  column: KanbanColumnData;
  cards: Node[];
  parent: Node;
}>();

const emit = defineEmits<{
  drop: [columnId: string, nodeId: string];
  delete: [columnId: string];
  update: [column: KanbanColumnData];
  addCard: [columnId: string];
  cardDragStart: [node: Node];
  cardDragEnd: [];
  assign: [nodeId: string, userId: string];
  unassign: [nodeId: string, userId: string];
}>();

const { getAppAccent } = useAppColors();

const isDragOver = ref(false);
const isEditing = ref(false);
const editedTitle = ref(props.column.title);
const showColorPicker = ref(false);
const titleInput = ref<HTMLInputElement | null>(null);
const filteredNodes = ref<Node[]>(props.cards);

const onDragOver = () => {
  isDragOver.value = true;
};

const onDragLeave = (e: DragEvent) => {
  // Only set false if leaving the column entirely
  const rect = (e.currentTarget as HTMLElement).getBoundingClientRect();
  if (e.clientX < rect.left || e.clientX > rect.right || e.clientY < rect.top || e.clientY > rect.bottom) {
    isDragOver.value = false;
  }
};

const onDrop = (e: DragEvent) => {
  isDragOver.value = false;
  const nodeId = e.dataTransfer?.getData('text/plain');
  if (nodeId) {
    emit('drop', props.column.id, nodeId);
  }
};

const startEdit = () => {
  showColorPicker.value = false;
  editedTitle.value = props.column.title;
  isEditing.value = true;
  nextTick(() => titleInput.value?.focus());
};

const saveTitle = () => {
  if (editedTitle.value.trim()) {
    emit('update', { ...props.column, title: editedTitle.value.trim() });
  }
  isEditing.value = false;
};

const cancelEdit = () => {
  editedTitle.value = props.column.title;
  isEditing.value = false;
};

const toggleColorPicker = () => {
  showColorPicker.value = !showColorPicker.value;
};

const selectColor = (color: number) => {
  emit('update', { ...props.column, color });
  showColorPicker.value = false;
};

const confirmDelete = () => {
  modals.add(
    new Modal(shallowRef(DeleteColumnModal), {
      props: {
        columnTitle: props.column.title,
        cardCount: props.cards.length,
        onConfirm: () => emit('delete', props.column.id),
      },
      size: 'small',
    }),
  );
};

function handleClickOutside(e: MouseEvent) {
  const target = e.target as HTMLElement;
  if (!target.closest('.column-header')) {
    showColorPicker.value = false;
  }
}
onMounted(() => {
  document.addEventListener('click', handleClickOutside);
});

onUnmounted(() => {
  document.removeEventListener('click', handleClickOutside);
});
</script>

<style scoped lang="scss">
.kanban-column {
  display: flex;
  flex-direction: column;
  min-width: 300px;
  max-width: 320px;
  padding: 12px;
  border-radius: var(--radius-lg);
  background: var(--surface-raised);

  &.drag-over {
    background: rgb(57 86 231 / 6%);
    box-shadow: inset 0 0 0 2px var(--primary);
  }
}

.column-header {
  position: relative;
  margin-bottom: 12px;
}

.column-title-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}

.column-color-btn {
  flex-shrink: 0;
  width: 14px;
  height: 14px;
  padding: 0;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  transition: transform $transition-base;

  &:hover {
    transform: scale(1.2);
  }
}

.column-title {
  flex: 1;
  margin: 0;
  padding: 2px 0;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  cursor: pointer;
  transition: color $transition-base;

  &:hover {
    color: var(--primary);
  }
}

.column-title-input {
  flex: 1;
  padding: 4px 8px;
  border: 1px solid var(--primary);
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  background: var(--surface-base);
  box-shadow: 0 0 0 3px rgb(57 86 231 / 10%);
  outline: none;
}

.column-count {
  height: fit-content;
  padding: 2px 8px;
  border-radius: 16px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  background: var(--surface-base);
}

.column-actions {
  display: flex;
  gap: 2px;
}

.action-btn {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border: none;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  background: transparent;
  cursor: pointer;

  &:hover {
    color: var(--text-body);
    background: var(--surface-base);
  }

  &.danger:hover {
    color: var(--red);
    background: var(--red-bg);
  }

  :deep(svg) {
    width: 16px;
    height: 16px;
    fill: currentcolor;
  }
}

.color-picker {
  position: absolute;
  top: 100%;
  left: 0;
  z-index: 10;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  max-width: 180px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface-base);
  box-shadow: var(--shadow-sm-md);
}

.color-option {
  width: 26px;
  height: 26px;
  padding: 0;
  border: 2px solid transparent;
  border-radius: 50%;
  cursor: pointer;

  &:hover {
    transform: scale(1.15);
  }

  &.active {
    border-color: var(--text-primary);
    box-shadow: 0 0 0 2px var(--surface-base);
  }
}

.column-content {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 8px;
  min-height: 120px;
  max-height: 70vh;
  margin: -4px;
  padding: 4px;
  overflow-y: auto;
}

.empty-state {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 32px 16px;
  border: 2px dashed var(--border);
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  text-align: center;

  :deep(svg) {
    width: 24px;
    height: 24px;
    margin-bottom: 8px;
    opacity: 0.5;
    fill: currentcolor;
  }

  p {
    margin: 0 0 2px;
    font-size: 13px;
    font-weight: 500;
  }

  span {
    font-size: 11px;
    opacity: 0.7;
  }
}

.add-card-btn {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 6px;
  width: 100%;
  margin-top: 12px;
  padding: 10px;
  border: none;
  border-radius: var(--radius-md);
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  background: var(--surface-base);
  cursor: pointer;

  &:hover {
    color: var(--primary);
    background: rgb(57 86 231 / 8%);
  }

  :deep(svg) {
    width: 16px;
    height: 16px;
    fill: currentcolor;
  }
}

// Transitions
.dropdown-enter-active,
.dropdown-leave-active {
  transition:
    opacity 0.15s ease,
    transform 0.15s ease;
}

.dropdown-enter-from,
.dropdown-leave-to {
  opacity: 0;
  transform: translateY(-8px);
}

.card-list-enter-active,
.card-list-leave-active {
  transition:
    opacity $transition-base ease,
    transform $transition-base ease;
}

.card-list-enter-from,
.card-list-leave-to {
  opacity: 0;
  transform: translateY(-10px);
}

.card-list-move {
  transition: transform $transition-base ease;
}
</style>