tremorlabs / tremor

React components to build charts and dashboards
https://tremor.so
Apache License 2.0
15.39k stars 446 forks source link

feat: compose legend labels #994

Open abdelkd opened 1 month ago

abdelkd commented 1 month ago

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)

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

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:

vercel[bot] commented 1 month ago

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 commented 1 month ago

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 commented 1 month ago

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 commented 1 month ago

@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.