-
Notifications
You must be signed in to change notification settings - Fork 65
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
Theming/Styling contained Widgets #274
Comments
It seems like the way we’re moving towards for pretty much any style change for an existing widget is extension with a new Solution 1, multiple widgets:Buttons: @theme(css)
export class RedButton extends Button { }
@theme(css)
export class BlueButton extends Button { } Usage in Container: render() {
const { buttonType } = this.properties;
return v(‘div’, [
w(buttonType === ‘red’ ? RedButton : BlueButton, [ ‘ Button Text ’ ])
]);
} Solution 2, property controlling appearance:Button: export interface MyButtonProperties extends ButtonProperties {
appearance: ‘default’ | ‘alternate’;
}
@theme(css)
export class MyButton extends Button<MyButtonProperties> {
getModifierClasses() {
const { disabled, appearance } = this.properties;
return this.classes(
disabled ? css.disabled : null,
appearance === ‘default’ ? css.red : css.blue
);
}
} Usage in Container: render() {
const { buttonType } = this.properties;
return v(‘div’, [
w(MyButton, {
appearance: buttonType
}, [ ‘Button Text’ ])
]);
} The first solution looks cleaner at first, but I’m worried that a larger number of variations will result in an explosion of different widgets and CSS module files. There’s also the problem that simple variations like red vs. blue are easy, but what about cases where you might have two different types of variation, e.g. color and size. With the first solution you would need RedButton, LargeRedButton, BlueButton, LargeBlueButton, etc., whereas for the second you would only need to add There’s also the CSS organization issue. If we approach this by suggesting separate modules for each slight variation in styling, each module will need to duplicate multiple styles like We could somewhat mitigate the duplication issue with |
This is directly related to #270, since as @smhigley pointed out, it's not extremely relevant if a component is contained or not. This boils down to styling a component instance based on properties, which lends itself perfectly to an extended component using an extended properties interface as captured by #314. Action items:
|
User Story
As a developer, when creating a contained themed widget, I want to be able to influence the theme and styling of the contained widgets.
Specific Use Case
I have created a re-usable panel, which has a border and contains a button and a slider. Based on the configuration of the panel, I want to change the background colour of the button and the thumbnail colour of the the slider.
The text was updated successfully, but these errors were encountered: