christopherafbjur / sanity-plugin-icon-picker

MIT License
30 stars 27 forks source link

Preview module does not work with custom providers #54

Closed azzlack closed 1 year ago

azzlack commented 1 year ago

The preview function uses the static src/configurations/index.ts array. It should load any custom providers as well

azzlack commented 1 year ago

I solved it temporarily by creating my own preview method

export const preview = ({
  provider,
  name,
}: Pick<IconObject, 'provider' | 'name'>): ReactElement | null => {
  if (!provider) return null;

  // NOTE: References my own custom ProviderConfiguration objects instead of the static configurations file
  const configurations = [provider1, provider2];

  const icons = configurations.find(
    (config) => config.provider === provider
  )?.icons();
  const found = icons?.find((icon) => icon.tags.some((tag) => tag === name));
  return found?.component() || null;
};

I can try to make a PR for this, but I am in the middle a few very busy weeks. So it will take some time unless someone else fix it first :-)

christopherafbjur commented 1 year ago

Thanks for reporting this. I'll push a fix during this week