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

feat(icon): icon name extendable type #4045

Draft
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

m0ksem
Copy link
Contributor

@m0ksem m0ksem commented Nov 29, 2023

image

Right now, I made types for our Vuestic default aliases.

The main idea here is to allow user to extend VaIconName interface and add custom icon names.

declare module 'vuestic-ui' {
  // eslint-disable-next-line @typescript-eslint/no-empty-interface
  export interface VaIconName extends MaterialIconsName {}
}

I'm using custom icon font in my project and I hate searching for correct icon name every time. I also use FontAwesome or MaterialIcons sometimes with Vuestic. Having an IDE suggestion will prevent me from spending time on searching correct icon name on docs site.


We can extend it feature with docs page.

MaterialIconsName is actually easy to make:

import type * as mdiIcons from '@mdi/js'

type KebabCase<T extends string> = T extends `${infer A}${infer B}`
  ? B extends Uncapitalize<B>
    ? `${Uncapitalize<A>}-${KebabCase<B>}`
    : `${Uncapitalize<A>}${KebabCase<B>}`
  : T
  
type RemoveMDIPrefix<T> = T extends `mdi${infer U}` ? U : T

type MaterialIconsName = KebabCase<RemoveMDIPrefix<keyof typeof mdiIcons>>

For FontAwesome we can use https://www.npmjs.com/package/@fortawesome/fontawesome-common-types?activeTab=code

@asvae
Copy link
Contributor

asvae commented Dec 6, 2023

Can we plan follow up on this before we merge?

The problem I see is that while this could be useful - right now we will probably solely use it for internal vuestic types.

It could also be confusing for contributors to understand what this code accomplishes due to absence of docs and even comments.

@asvae
Copy link
Contributor

asvae commented Dec 6, 2023

My concerns:

  • We want this typing system to work out of the box for new vuestic-ui users with material symbols outline.
  • We want some kind of introduction for other icon-fonts. I.e. tabs wiht mso/fa, under each tab - you have instruction on how to integrate font fully with your system.

@m0ksem m0ksem marked this pull request as draft December 7, 2023 18:19
@m0ksem
Copy link
Contributor Author

m0ksem commented Jan 16, 2024

In new types icon name for some reason is extract form VaIconName type. We'll need to rework this:
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants