christopherafbjur / sanity-plugin-icon-picker

MIT License
30 stars 27 forks source link

Feature request: access to icons from Sanity or other React project #8

Closed fabien closed 3 years ago

fabien commented 3 years ago

Hi, thanks for this plugin!

I was thinking of using the selected icon as a media item in the preview of a Sanity document.

However, in order to retrieve the icon I would need to have access to your getIcons utility method (or even better, a dedicated helper function). It should return the React component based on the data stored as the field value.

Could you please export such a function for external use?

fabien commented 3 years ago

Thanks @christopherafbjur - this is really helpful!

I see that the integration with Sanity is really straightforward now. What about other React apps like a front-end/website? I presume I can simply import preview from 'sanity-plugin-icon-picker/dist/utils/public/preview'? Would you consider adding an export in https://github.com/christopherafbjur/sanity-plugin-icon-picker/blob/main/src/index.js for that?

christopherafbjur commented 3 years ago

This plugin is intended for sanity only but I guess it wouldn't hurt to expose the preview function so it could be used in external apps/projects aswell. Will have a look at it asap @fabien

christopherafbjur commented 3 years ago

Had a look at this and it does not seem optimal to add a exported preview function (for usage from external react projects) like you request since we're importing components in index.js from the Sanity scope etc using the parts system (these will not be available outside the scope of a sanity project)

Since the provider and name are stored in the icon object, this data can be used in your front-end/website together with some logic (if using multiple providers) to render the correct component from the icon libraries you're using. How ever I agree that it would be optimal to have a function such as the preview function do that for you automatically, just not sure if that is the responsibility of this plugin @fabien

fabien commented 3 years ago

Hi @christopherafbjur. I understand, when it comes to the dependency on the parts system, it doesn't make much sense. Although it is probably also possible to pull those Sanity-specific icons in using a normal dependency.

Not a big issue though, thanks for having a look at this!

christopherafbjur commented 3 years ago

Hi @fabien ! Hmm I think what you mean is pull the Sanity-specific "parts" using a normal dependency? If that's what you mean that would require us to add sanity as an extra dependency of this project, which would not be optimal for external usage nor "internal".

Let me know if you have any ideas on how to get around this in some other way though @fabien and I'll have a look. Closing for now