Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] [RFC] feat(NcIcon): add a generic component and utils for icons #6348

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ShGKme
Copy link
Contributor

@ShGKme ShGKme commented Jan 4, 2025

☑️ Resolves

  • Fix #…

Add a generic component to display icons in all supported formats.

Designed to develop components with a single icon prop and slot, supporting all the icon types:

  • A Vue component icon like vue-material-design-icons/Account.vue
  • An SVG icon like @mdi/svg/svg/account.svg
  • A path icon like @mdi/js/account.js
  • An URL icon like https://path/to/icon.svg or data:image/svg+xml;base64,...
  • A class icon like icon-account

With NcIcon

<script setup lang="ts">
// Define a single `icon` 
defineProps<{
  icon?: IconGeneric,
}>()
</script>

<template>
  <button class="button">
    <span class="button__icon">
      <!-- Passing icons via slot is still possible -->
      <slot name="icon">
        <!-- A single node for all the cases -->
        <NcIcon v-if="icon" :icon>
      </slot>
    </span>
  </button>
</template>

Without

<script setup lang="ts">
// Many props for different icons
defineProps<{
  icon: string,
  iconPath: string,
}>()
</script>

<template>
  <button class="button">
    <span class="button__icon">
      <slot name="icon">
        <!-- Requires implementation for each case -->
        <span v-if="icon" :class="icon" />
        <NcIconSvgWrapper v-else-if="iconPath" :path="iconPath" />
      </slot>
    </span>
  </button>
</template>

Why add component icon type and not use <template #icon>?

Having icon as a prop even for a component allows passing it in 1 line instead of passing slot in 3-4 lines. Might be useful in some cases.

<script setup>
import IconAdd from 'vue-material-design-icons/Add.vue'
</script>

<template>
  <!-- before -->
  <NcButton :aria-label="t('Add')">
    <template #icon>
      <IconAdd />
    </template>
  </NcButton>

  <!-- after -->
  <NcButton :aria-label="t('Add')" :icon="IconAdd" />
</template>

🖼️ Screenshots

🏚️ Before 🏡 After
B A

🚧 Tasks

  • ...

🏁 Checklist

  • ⛑️ Tests are included or are not applicable
  • 📘 Component documentation has been extended, updated or is not applicable
  • 3️⃣ Backport to next requested with a Vue 3 upgrade

@ShGKme ShGKme added the 2. developing Work in progress label Jan 4, 2025
@ShGKme ShGKme added the enhancement New feature or request label Jan 4, 2025
@ShGKme ShGKme changed the title [RFC] feat(NcIcon): add a generic component for icons [WIP] [RFC] feat(NcIcon): add a generic component for icons Jan 4, 2025
@ShGKme ShGKme changed the title [WIP] [RFC] feat(NcIcon): add a generic component for icons [WIP] [RFC] feat(NcIcon): add a generic component and utils for icons Jan 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2. developing Work in progress enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant