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.

3.8 KB
Raw Blame
<template>
  <div v-for="(section, i) in options" :key="i" class="section">
    <h3>{{ section.label }}</h3>

    <div v-for="opt in section.options" :key="opt.key" :class="['form-group', opt.type === 'textarea' ? 'form-group--vertical' : '']">
      <div>
        <label>
          {{ opt.label }} <tag v-if="opt.tag && displayFeatureTags" blue>{{ opt.tag }}</tag>
        </label>

        <p class="description">{{ opt.description }}</p>
      </div>
      <!-- Toggle -->
      <AppToggle v-if="opt.type === 'toggle'" v-model="p(opt.key).value" class="entry" @update:model-value="opt.onChange?.(p(opt.key).value)" />

      <!-- Select -->
      <AppSelect
        v-else-if="opt.type === 'select'"
        v-model="p(opt.key).value"
        :items="opt.choices!"
        size="40%"
        class="entry"
        :searchable="false"
        @update:model-value="opt.onChange?.(p(opt.key).value)"
      />

      <!-- Radio -->
      <AppRadio
        v-else-if="opt.type === 'radio'"
        v-model="p(opt.key).value"
        :items="opt.choices!"
        class="entry"
        @update:model-value="opt.onChange?.(p(opt.key).value)"
      />

      <!-- Color -->
      <AppColorPicker v-else-if="opt.type === 'color'" v-model="p(opt.key).value" class="entry" @update:model-value="opt.onChange?.(p(opt.key).value)" />

      <!-- Group Checkbox -->
      <div v-else-if="opt.type === 'groupCheckbox'" class="group-checkbox">
        <div class="checkbox-grid">
          <label v-for="[key, label] of Object.entries(opt.items)" :key="key">
            <AppCheck
              :model-value="p(opt.key).value[key]"
              @change="opt.onChange?.(p(opt.key).value)"
              @update:model-value="
                value => {
                  p(opt.key).value = {
                    ...p(opt.key).value,
                    [key]: value,
                  };
                }
              "
            >
              {{ label }}
            </AppCheck>
          </label>
        </div>
      </div>

      <!-- Textarea -->
      <textarea
        v-else-if="opt.type === 'textarea'"
        v-model="p(opt.key).value"
        class="entry textarea-entry"
        :placeholder="opt.placeholder || ''"
        :rows="opt.rows || 6"
        spellcheck="false"
        @input="opt.onChange?.(p(opt.key).value)"
      />

      <!-- Number -->
      <input
        v-else-if="opt.type === 'number'"
        v-model.number="p(opt.key).value"
        type="number"
        class="entry number-entry"
        :min="opt.min"
        :max="opt.max"
        :step="opt.step"
      />
    </div>
  </div>
</template>

<script setup lang="ts">
defineProps<{
  options: Array<{ label: string; options: Option[] }>;
}>();

const preferencesStore = usePreferencesStore();
const displayFeatureTags = preferencesStore.get('displayFeatureTags');

// @ts-expect-error unknown type
const p = preferencesStore.get as <K extends PreferenceKey>(key: K) => ReturnType<unknown>;
</script>

<style lang="scss" scoped>
.section {
  width: 100%;
  margin-bottom: 2rem;
}

.form-group {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  width: 100%;
  margin: 2rem 0;

  &--vertical {
    flex-direction: column;
  }
}

label {
  flex: 1;
  font-size: 1rem;
  font-weight: 400;
}

.description {
  margin-top: 0.25rem;
  font-size: 0.9rem;
  color: var(--text-secondary);
}

h3 {
  margin: 3rem 0 0.5rem;
  font-weight: 500;
}

.entry {
  max-width: 400px;
  margin-left: auto;
}

.group-checkbox {
  .checkbox-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.5rem 3rem;
  }
}

.textarea-entry {
  width: 100%;
  max-width: 100%;
  font-size: 0.8rem;
  line-height: 1.5;
  resize: vertical;
  tab-size: 2;

  &::placeholder {
    color: var(--text-secondary);
    opacity: 0.7;
  }
}

.number-entry {
  width: 40%;
}
</style>