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

Feature: generate static css icon #88

Closed
husayt opened this issue Oct 9, 2021 · 11 comments
Closed

Feature: generate static css icon #88

husayt opened this issue Oct 9, 2021 · 11 comments

Comments

@husayt
Copy link

husayt commented Oct 9, 2021

Sometimes especially when working with non vue components one needs to have icons defined at css level e.g.

.my-icon-stats {
    background: transparent        url(data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTYiIGhlaWdodD0iMTYiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+PGcgc3Ryb2tlPSIjN0Y4QzhEIiBmaWxsPSJub25lIiBmaWxsLXJ1bGU9ImV2ZW5vZGQiPjxwYXRoIGQ9Ik0xMC41IDZWNC41aC01di41MzJhMSAxIDAgMCAwIC4zNi43NjhsMS43MTggMS40MzJhMSAxIDAgMCAxIDAgMS41MzZMNS44NiAxMC4yYTEgMSAwIDAgMC0uMzYuNzY4di41MzJoNVYxMCIvPjxyZWN0IHg9IjEuNSIgeT0iMS41IiB3aWR0aD0iMTMiIGhlaWdodD0iMTMiIHJ4PSIyIi8+PC9nPjwvc3ZnPg==)
        no-repeat center;
    background-size: 16px 16px;
    height: 16px;
    opacity: 0.87;
    width: 16px;
    max-width: 16px;
    display: inline-block;
}

then it can be used as <span class="my-icon-stats"></span> even without Vue or other framework. This will not be useful for every framework combination but will also allow for this library to be used with no framework as well.

I guess this might be possible with unplugin-icons on demand via special command or syntax, especially since most of the svg extraction is done.

@husayt husayt changed the title generate static css icon Feature: generate static css icon Oct 9, 2021
@antfu
Copy link
Member

antfu commented Oct 9, 2021

Would you expect this as a dedicated mode or do you want to use this solution as a complement of the component solution?

I guess we could have something like

import "~icons/mdi/alarm.css"

to generate the corresponding CSS for each component.

Don't have the bandwidth right now but PR welcome.

@husayt
Copy link
Author

husayt commented Oct 9, 2021

Yes, that would be a nice framework agnostic way to use that. I guess this could be independent/complementing mode to the component mode.

@userquin
Copy link
Member

userquin commented Oct 9, 2021

Yes, that would be a nice framework agnostic way to use that. I guess this could be independent/complementing mode to the component mode.

I'll take a look

@userquin
Copy link
Member

userquin commented Oct 9, 2021

@husayt Here is the result (you can see the branch an the new css options, you will also be able to add default styles to all css icons):

imagen

On vite we have free HMR on dev:

imagen

@userquin
Copy link
Member

userquin commented Oct 9, 2021

And here the code:

imagen

@userquin
Copy link
Member

userquin commented Oct 9, 2021

@husayt you can also use custom loader (from svg files for example) to display it as css icon instead svg/component.

@husayt
Copy link
Author

husayt commented Oct 10, 2021

@userquin excellent stuff. Thanks

@userquin
Copy link
Member

userquin commented Dec 1, 2021

@husayt closing this since it has been included on unocss, if you want still this behavior open a new one issue.

@userquin userquin closed this as completed Dec 1, 2021
@Akryum
Copy link
Contributor

Akryum commented Oct 3, 2023

Maybe it can be useful for vitepress (which doesn't use uno nor tailwind by default)?

@luna-lee
Copy link

how can i add defaultClass or otherClass

@luna-lee
Copy link

Now I can only add css attributes, but I need to add a class to each icon

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

Successfully merging a pull request may close this issue.

5 participants