Newer
Older
navi-1 / webclient / src / components / messages / UiComponentCard.vue
<template>
  <div class="ui-component-card">
    <div class="ui-component-header">
      <span class="ui-component-icon">🧩</span>
      <span class="ui-component-name">{{ props.component.component }}</span>
      <span class="ui-component-badge">UI</span>
    </div>
    <div class="ui-component-body">
      <component
        :is="renderer"
        v-if="renderer"
        :data="props.component.payload"
      />
      <div v-else class="ui-component-fallback">
        <div class="ui-component-fallback-title">
          Unknown UI component: {{ props.component.component ?? '?' }}
        </div>
        <pre class="ui-component-fallback-json">{{ JSON.stringify(props.component.payload, null, 2) }}</pre>
      </div>
    </div>
  </div>
</template>

<script setup>
import { computed } from 'vue'
import { resolve } from '@/components/ui/registry.js'

const props = defineProps({
  component: { type: Object, required: true }
})

const renderer = computed(() => {
  const name = props.component.component ?? ''
  return resolve(name)
})
</script>

<style scoped>
.ui-component-card {
  margin: 8px 0;
  background: var(--surface, #1e1e2e);
  border: 1px solid var(--border, #2a2a3e);
  overflow: hidden;
}

.ui-component-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border, #2a2a3e);
  user-select: none;
}

.ui-component-icon {
  font-size: 1.2em;
  line-height: 1;
}

.ui-component-name {
  flex: 1;
  font-size: 0.9em;
  font-weight: 500;
  color: var(--text, #cdd6f4);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ui-component-badge {
  font-size: 0.7em;
  text-transform: uppercase;
  padding: 2px 8px;
  background: var(--accent-muted, #313244);
  color: var(--accent, #4ec9b0);
}

.ui-component-body {
  padding: 12px 14px;
}

.ui-component-fallback {
  color: var(--text-muted, #6c7086);
}

.ui-component-fallback-title {
  font-size: 0.8rem;
  margin-bottom: 8px;
  font-weight: 500;
}

.ui-component-fallback-json {
  margin: 0;
  font-family: monospace;
  font-size: 0.8rem;
  white-space: pre-wrap;
}
</style>