Skip to content

Conversation

@Shane98c
Copy link
Member

This adds an id to the Figure component by looking for child table/figure caption components and using their number prop to create an id that can be used for linking to them, e.g.,
carbonplan.org/research/cdr-counterfactual-accounting#figure-1 or
carbonplan.org/research/cdr-counterfactual-accounting#table-1

@Shane98c Shane98c requested a review from katamartin March 21, 2025 17:19

const elementNumber = captionElement?.props?.number
const elementType =
captionElement?.type?.displayName === 'TableCaption' ? 'table' : 'figure'
Copy link
Member

Choose a reason for hiding this comment

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

Would it be possible to infer the elementType by inspecting the label prop passed to Caption? That way, we could handle other caption labels automatically if they ever arose. Or is inspecting a grandchild's props tricky?

Copy link
Member Author

Choose a reason for hiding this comment

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

Unfortunately, I haven't found a clean way to access Caption's props from Figure. We could potentially remove the FigureCaption and TableCaption components and just use Caption with a required label prop, but that's a bigger change than I want to do here.

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.

3 participants