-
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
Styling a Widget Instance #270
Comments
The options currently available to change a widget instance's style are:
I'm almost never in favor of inline styles, especially when mixed with stylesheets. For CustomButton.ts export interface CustomButtonProperties extends ButtonProperties {
appearance?: 'small' | 'large' | 'confirm' | 'cancel';
}
@theme(css)
export default class CustomButton extends Button<CustomButtonProperties> {
getRootClasses() {
const {
appearance = 'small',
disabled,
popup,
pressed
} = this.properties;
return this.classes(
css.root,
appearance === 'small' ? css.small : css.large,
disabled ? css.disabled : null,
popup ? css.popup : null,
pressed ? css.pressed : null
);
}
} Usage w(CustomButton, {
appearance: 'large'
}, [ 'foo' ]), This doesn't work with the current Button widget, but it should if we implement some changes to all widgets to allow better extensibility. |
As @agubler pointed out, there's also the possibility of extending Button for each separate "appearance": @theme(smallButtonCss)
export class SmallButton extends Button { }
@theme(largeButtonCss)
export class LargeButton extends Button { }
@theme(confirmButtonCss)
export class ConfirmButton extends Button { }
@theme(cancelButtonCss)
export class CancelButton extends Button { } |
Nice concise writeup @smhigley. Now that we have #314 and #316 to help with general component extensibility, the first Action items:
|
Just reading this now... Thanks, this seems to be a great logical way of doing this! In fact, I am just going to try this pattern now on web-editor. |
I am trying the second solution, as when "binding" to a particular sub-widget I am using in a contained widget: @theme(smallButtonCss)
export class SmallButton extends Button { } And while it appears to work, I get the warning in the console of:
|
Cool! 👍 |
User Story
As a developer of Dojo 2, I need to be able to modify the styling of individual instances.
Specific Use Case
I have created an instance of
@dojo/widgets/Button
in my application, I am using the base Dojo 2 theme, but I need to change the style of this instance of the button, making the font bold and changing the background colour to #FFCCED.The text was updated successfully, but these errors were encountered: