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]: Way to compose the Legend labels? #978

Open
nicostombros opened this issue Feb 21, 2024 · 7 comments
Open

[Feature]: Way to compose the Legend labels? #978

nicostombros opened this issue Feb 21, 2024 · 7 comments
Labels
Type: Enhancement Small enhancement to existing component or feature

Comments

@nicostombros
Copy link

nicostombros commented Feb 21, 2024

What problem does this feature solve?

It would be great to be able to pass children into Legend component such that we can create our own labels.
At the moment, I use Legend like the following

<Legend
   categories={data.map((d) => d.name)}
   colors={data.map((d) => d.color)}
   className='h-auto flex flex-col'
/>

However, there are cases where I'd want to greatly customise the Legend labels.
For instance, I'd like to be able to include icons for each of my labels, or to use a Tailwind gradient as the label color.
Example of how this might work from a dev standpoint is:

<Legend
   className='h-auto flex flex-col'
>
  {data.map(d => (
    <LegendLabel color="green" className="...">{d.icon}{d.title}</LegendLabel>
  ))}
</Legend>

If this is actually possible then please let me know, as I couldn't find documentation for that.

What does the proposed API look like?

No response

@abdelkd
Copy link
Contributor

abdelkd commented Feb 28, 2024

<Legend
   className='h-auto flex flex-col'
>
  {({ data }) => (
    data.map(d => (
      <LegendLabel color="green" className="...">{d.icon}{d.title}</LegendLabel>
    ))}
  )}
</Legend>

I think this might be a good API
or a renderItem prop that would give item as an argument. something like this

<Legend
   className='h-auto flex flex-col'
   categories={categories}
   colors={colors}
   renderItem={(item) => <LegendLabel color="green" className="...">{d.icon}{d.title}</LegendLabel>}
/>

@christopherkindl christopherkindl added the Type: Enhancement Small enhancement to existing component or feature label Feb 28, 2024
@ctwillie
Copy link

+1

@severinlandolt
Copy link
Member

Interesting idea, will be taking a look at it for one of our next releases.

@abdelkd
Copy link
Contributor

abdelkd commented Mar 18, 2024

@severinlandolt I would love to work on it once it's decided to be implemented

@severinlandolt
Copy link
Member

@abdelkd Sounds cool, I would definitely go down the suggested the route of using an optional render prop. Happy to have working on a PR :)

@abdelkd
Copy link
Contributor

abdelkd commented Mar 19, 2024

@severinlandolt I've added a renderItem prop which takes a function that has two parameters name and Circle, the latter is a component that renders the circle found in legend, so users can manipulate text without loosing circle if it's wanted. do you have other things to sugges?

@severinlandolt
Copy link
Member

Thanks, will be taking a look at it for v3.16 :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Enhancement Small enhancement to existing component or feature
Projects
None yet
Development

No branches or pull requests

5 participants