You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add an additional api to widgets that is structured like themes to allow for extra classes to be added
to a nested widget structure.
As a consumer applying extra classes to a widget is possible by passing an extraClasses property to the widget with the class name mapped to the widget's class that the the extra classes should be applied.
This simple API solves adding an extra class to a widget that is directly used but doesn't allow for extraClasses to be passed to child widgets that are used by the widget. Consider the following widget:
There is no way that a consumer can pass extra classes to the ChildWidget rendered by MyWidget, even if MyWidget passed on extraClasses to ChildWidget there is no way to determine which of the extra classes should be applied to MyWidget or ChildWidget (as class names can clash, and often do with classes like .root).
With theming this is solved by widget classes being keyed by an identifier unique to the widget, such as:
Adopting an approach for passing extra classes would allow a consumer to create an extra classes object that could be passed to all child widgets and identify which classes should be applied to each widget:
// example widgets
@theme(childWidgetCss)classChildWidgetextendsThemed(WidgetBase){protectedrender(){returnv('div',{classes: [this.theme(childWidgetCss.root)]});}}
@theme(myWidgetCss)classMyWidgetextendsThemed(WidgetBase){protectedrender(){const{ classes }=this.properties;returnv('div',{classes: [this.theme(myWidgetCss.root)]},[// passing classes through to the child widget allows the consumer to // apply extra classes.w(ChildWidget,{ classes })]);}}// usagerender(){constclasses={'widget-package-name/MyWidget': {root: 'extra-root-class-for-my-widget'},'widget-package-name/ChildWidget': {root: 'extra-root-class-for-child-widget'}}returnw(MyWidget,{ classes });}
This would enable all widgets to have extra classes applied to them as along as the widget author passed the classes object to any child widgets used.
The text was updated successfully, but these errors were encountered:
Enhancement
Add an additional api to widgets that is structured like themes to allow for extra classes to be added
to a nested widget structure.
As a consumer applying extra classes to a widget is possible by passing an
extraClasses
property to the widget with the class name mapped to the widget's class that the the extra classes should be applied.This simple API solves adding an extra class to a widget that is directly used but doesn't allow for
extraClasses
to be passed to child widgets that are used by the widget. Consider the following widget:There is no way that a consumer can pass extra classes to the
ChildWidget
rendered byMyWidget
, even ifMyWidget
passed onextraClasses
toChildWidget
there is no way to determine which of the extra classes should be applied toMyWidget
orChildWidget
(as class names can clash, and often do with classes like.root
).With theming this is solved by widget classes being keyed by an identifier unique to the widget, such as:
Adopting an approach for passing extra classes would allow a consumer to create an extra classes object that could be passed to all child widgets and identify which classes should be applied to each widget:
This would enable all widgets to have extra classes applied to them as along as the widget author passed the
classes
object to any child widgets used.The text was updated successfully, but these errors were encountered: