Skip to content

feat(theme): allow custom icons in DocCard component#11596

Closed
jliermann wants to merge 11 commits into
facebook:mainfrom
jliermann:main
Closed

feat(theme): allow custom icons in DocCard component#11596
jliermann wants to merge 11 commits into
facebook:mainfrom
jliermann:main

Conversation

@jliermann

@jliermann jliermann commented Dec 2, 2025

Copy link
Copy Markdown

Pre-flight checklist

  • I have read the Contributing Guidelines on pull requests.
  • If this is a code change: I have written unit tests and/or added dogfooding pages to fully verify the new behavior.
  • If this is a new API or substantial change: the PR has an accompanying issue (closes #0000) and the maintainers have approved on my working plan.

Motivation

I had a project were I wanted to use the DocCard component from the theme with custom icons. I was able to swizzle it but considered that this addition might be of broader interest. The component accepts a property item.icon of type "string". It does currently not support image files but is also not broken by them.

Test Plan

I added a dogfooding doc under /tests/docs/doc-cards with different cases:

  • Custom UTF emoji icon as string prop
  • No custom icon (internal / external link)
  • Several image files passed as props (unsupported)
grafik

Test links

Deploy preview: https://deploy-preview-11596--docusaurus-2.netlify.app/

Related issues/PRs

@meta-cla meta-cla Bot added the CLA Signed Signed Facebook CLA label Dec 2, 2025
@jliermann jliermann changed the title feat(theme): Allow custom icons in DocCard component feat(theme): allow custom icons in DocCard component Dec 2, 2025
@netlify

netlify Bot commented Dec 2, 2025

Copy link
Copy Markdown

[V2]

Built without sensitive environment variables

Name Link
🔨 Latest commit 5320efc
🔍 Latest deploy log https://app.netlify.com/projects/docusaurus-2/deploys/692f18248e67d8000894447d
😎 Deploy Preview https://deploy-preview-11596--docusaurus-2.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@slorber slorber left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not super fan of the design, and using the doc card list through JSX/props is not common.

Until we design a proper feature to provide a custom icon through both sidebars.js and JSX/props, for both docs/categories, I'd rather not merge anything that would make it harder to add later. (see request in #7844)

Since you can already achieve what you need by swizzling components, I'd rather not merge this PR.

Feel free to keep working on this PR, or close it. If you want to keep working on it, we need to think globally of how to customize that icon for all users. It would be better to open a RFC or something to discuss the overall design of the feature.

const defaultIcon = isInternalUrl(item.href) ? '📄' : '🔗';

const customIcon =
typeof item.icon === 'string' && item.icon.length <= 2 ? item.icon : null;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why item.icon.length <= 2 ?

Is this an unreliable heuristic to check if the icon is an emoji?

@@ -199,6 +199,7 @@ export type PropSidebarItemCategory = Expand<
export type PropSidebarItemLink = SidebarItemLink & {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, we can customize the icon of docs/links, but not categories?

export type PropSidebarItemLink = SidebarItemLink & {
docId?: string;
unlisted?: boolean;
icon?: string;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This type describes above all the props that Docusaurus passes to the components, after transforming sidebar items to component props.

If you add it here just to enable a new component prop, this is quite odd because we still can't add an icon attribute to the actual sidebar item (how these cards are usually created), and can only pass it through JSX usage (less common).

We actually want to allow users to provide custom icons through sidebar files, and need to design that feature properly: #7844


import items from './doc-cards-items.js';

<DocCardList items={items} />

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this works for you, but is not really the most idiomatic usage of sidebar items

@slorber slorber marked this pull request as draft December 5, 2025 13:06
@slorber slorber added the pr: new feature This PR adds a new API or behavior. label Dec 5, 2025
@jliermann

jliermann commented Dec 5, 2025

Copy link
Copy Markdown
Author

Thanks, @slorber, for the detailled and very helpful comments. I do understand that the scope of this change is too limited for merging. I will put some thought into how I can contribute to the feature requested in #7844.

@slorber

slorber commented Dec 5, 2025

Copy link
Copy Markdown
Collaborator

Thanks

I think it would be better to open a RFC and once we agree on what should be done, open a new PR.

For now I'm closing this one

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

Labels

CLA Signed Signed Facebook CLA pr: new feature This PR adds a new API or behavior.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants