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

Add Badge component #138

Open
tomivirkki opened this issue Aug 10, 2023 · 0 comments
Open

Add Badge component #138

tomivirkki opened this issue Aug 10, 2023 · 0 comments

Comments

@tomivirkki
Copy link
Member

Description

Using badge is currently awkward since you need to add the theme attribute to arbitrary components with the following hack:

<span {...{ theme: 'badge success' }}>Confirmed</span>

The hack, in this case, is required because "theme" is not a recognized property of a <span>.

Provide a <Badge> wrapper in the component set, which applies the required "theme" attribute internally.

Usage example

<Badge>
  <span>Pending</span>
</Badge>

<Badge theme="success">
  <Icon
    aria-label="Confirmed"
    icon="vaadin:check"
    style={{ padding: 'var(--lumo-space-xs)' }}
    title="Confirmed"
  />
</Badge>

Prototype of the <Badge> wrapper:

function Badge({ children, theme }: { children: React.ReactNode; theme?: string }) {
  return React.Children.map(children, (child) => {
    if (React.isValidElement(child)) {
      return React.cloneElement(child, { ...{ theme: `badge${theme ? ` ${theme}` : ''}` } });
    }
    return child;
  });
}
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

No branches or pull requests

1 participant