Skip to content

Provide "setThemeVariants" for HasThemeVariant #6887

@stefanuebe

Description

@stefanuebe

Describe your motivation

This is a pure dx improvement / core readability request.

  1. To override the current theme variants, it is necessary to remove them manually first and then add a new one (if one wants to use theme variants):
button.removeThemeNames(button.getThemeNames().toArray(String[]::new))
button.addThemeVariants(ButtonVariant.LUMO_PRIMARY);
  1. To apply/remove a theme variant to/from a component depending on a boolean, it is necessary to create an if-else like
if (someCondition) {              
    button.removeThemeVariants(ButtonVariant.LUMO_PRIMARY);
} else {
    button.addThemeVariants(ButtonVariant.LUMO_PRIMARY);
}

Both use cases add unnecessary overhead and at least the 1 case is not really intuitive.

Describe the solution you'd like

Please provide a setThemeVariants method similar to the setThemeName(String, boolean) variant,

something like setThemeVariants(Variants...) (use case 1) and setThemeVariants(boolean , Variants...) (use case 2).

Describe alternatives you've considered

See the snippets.

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    DXDeveloper experience issueenhancementNew feature or requestgood first issueGood for newcomers

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions