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

feat: compose legend labels #994

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

abdelkd
Copy link
Contributor

@abdelkd abdelkd commented Mar 21, 2024

Description
This PR adds the ability to customize legend labels through custom prop. The prop is renderItem and it takes a function or a component, renderItem provides an item string, a Circle component and index. item is the label that would be used in a normal legend while the Circle is the component that would typically render in the legend. the index is self-explanatory.

Related issue(s)

#978

What kind of change does this PR introduce? (check at least one)

  • Bug fix (non-breaking change which fixes an issue)
  • New Feature (non-breaking change which adds functionality)
  • New Feature (BREAKING CHANGE which adds functionality)
  • Refactor
  • Build-related changes
  • Other, please describe:

Does this PR introduce a breaking change? (check one)

  • Yes
  • No

If yes, please describe the impact and migration path for existing applications:

How has this been tested?

Screenshots (if appropriate):
Screenshot 2024-03-21 at 15-45-39 UI _ Text _ Legend - Custom Item ⋅ Storybook

The PR fulfils these requirements:

  • It's submitted to the main branch
  • When resolving a specific issue, it's referenced in the related issue section above
  • My change requires a change to the documentation. (Managed by Tremor Team)
  • I have added tests to cover my changes
  • Check the "Allow edits from maintainers" option while creating your PR.
  • Add refs #XXX or fixes #XXX to the related issue section if your PR refers to or fixes an issue.
  • By contributing to Tremor, you confirm that you have read and agreed to Tremor's CONTRIBUTING.md guideline. You also agree that your contributions will be licensed under the Apache License 2.0 license.

Copy link

vercel bot commented Mar 21, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
tremor-storybook ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 21, 2024 3:01pm

@abdelkd
Copy link
Contributor Author

abdelkd commented Mar 21, 2024

Hey @severinlandolt do you think exporting a new CustomLegendLabel interface for using in other components with typescript?
for example:

import { Legend, CustomLegendLabel } from '@tremor/react'

const MyCustomLabel = ({ item, index }: CustomLegendLabel) => {
  return <p>{index} - {item}</p>
}

const App = () => {
  return <Legend categories={["One", "Two", "Three"]} renderItem={MyCustomLabel} />
}

here the developer won't need to define props or use any

@nicostombros
Copy link

Wondering if having a Circle is the best naming here? May want to allow the dev to create a square or some other shape to as their legend

@abdelkd
Copy link
Contributor Author

abdelkd commented Apr 11, 2024

@nicostombros The Circle component is just a wrapper around the actual colored dot that you find in legends, maybe Dot or ColoredDot.
Hello @severinlandolt , May I get your opinion.

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.

2 participants