I have got my themes all working perfectly, but for some reason my mat-menu will only get themed on whatever default is called and not otherwise.
So for its theme to not be broken I have to call
#include angular-material-theme($dark-theme);
right at the top of my styles.scss and then have my custom classes that I set, which my light is loaded by default as shown here:
import {OverlayContainer} from "#angular/cdk/overlay";
#Component({
selector: 'app-navbar',
templateUrl: './navbar.component.html',
styleUrls: ['./navbar.component.scss']
})
export class NavbarComponent implements OnInit, AfterViewInit {
title:string = "Callum.Tech";
themeClass: string = "light-theme";
overlay;
constructor(
private overlayContainer: OverlayContainer
) {
this.overlay = overlayContainer;
}
setDarkTheme(): void {
this.themeClass = "dark-theme";
}
setLightTheme(): void {
this.themeClass = "light-theme";
}
ngOnInit() {
this.overlay.themeClass = this.themeClass;
}
}
Everything else will re-theme and work fine without calling the start include I mentioned but mat-menu will throw a fit and only use the first theme its fed on the site launching, and doesnt change with the rest of the theme.
Here is what it looks like with the dark theme called at the start of styles.scss and the light theme loaded like normal
And here is the dark theme chosen, but the dark theme not called at the start of styles.scss:
In the breaking changes for 2.0.0-beta.11:
overlay: Now that the Overlay is part of the cdk rather than Angular Material directly, the themeClass property has been removed. To add a class to the overlay for theming, you can do
overlayContainer.getContainerElement().classList.add('my-theme-class');
So, you can change your code as follows:
constructor(
private overlayContainer: OverlayContainer
) {
this.overlay = overlayContainer.getContainerElement();
}
toggleTheme(): void {
if (this.overlay.classList.contains("dark-theme") {
this.overlay.classList.remove("dark-theme");
this.overlay.classList.add("light-theme");
} else if (this.overlay.classList.contains("light-theme") {
this.overlay.classList.remove("light-theme");
this.overlay.classList.add("dark-theme");
} else {
this.overlay.classList.add("light-theme");
}
}
ngOnInit() {
this.toggleTheme();
}
Related
I have created a directive and using HostListner , want to add a CSS style on Click event on the tag.Also remove on the click again.I have the following CSS .
CSS
.strikethrough { text-decoration: line-through;}
HTML
<p optionalIngredient>ABCD</p>
Directive
constructor(private elRef: ElementRef ,private renderer: Renderer2)
{ }
#HostListener('mouseenter') onMouseEnter() {
this.renderer.addClass(this.elRef.nativeElement, 'strikethrough');
}
#HostListener('mouseleave') onMouseLeave() {
this.renderer.removeClass(this.elRef.nativeElement,strikethrough');
}
You can use a boolean to keep track of whether the style is applied.
styled = false;
#HostListener('click')
onClick(){
if (!styled) this.renderer.addClass(this.elRef.nativeElement, 'strikethrough');
else this.renderer.removeClass(this.elRef.nativeElement, 'strikethrough');
this.styled = !this.styled;
}
I have a boolean column in my grid which is currently displaying 'true' or 'false' but I want it to show a checkbox instead.
How should I do this.
We are using ag-grid 25 with Angular and Adaptable.
You can write your own cell renderer that renders a checkbox instead of a string. Below is an example:
import { Component, OnDestroy } from '#angular/core';
import { ICellRendererAngularComp } from '#ag-grid-community/angular';
#Component({
selector: 'checkbox-renderer',
template: `
<input
type="checkbox"
(click)="checkedHandler($event)"
[checked]="params.value"
/>
`,
})
export class CheckboxRenderer implements ICellRendererAngularComp, OnDestroy {
private params: any;
agInit(params: any): void {
this.params = params;
}
checkedHandler(event) {
let checked = event.target.checked;
let colId = this.params.column.colId;
this.params.node.setDataValue(colId, checked);
}
}
import { CheckboxRenderer } from "./checkbox-renderer.component";
this.frameworkComponents = {
checkboxRenderer: CheckboxRenderer
};
Live Demo
Resource
https://blog.ag-grid.com/binding-boolean-values-to-checkboxes-in-ag-grid
As you say that you are using AdapTable then you can just add the name of the column to the CheckBoxColumns list in PredefinedConfig / UserInterface
See: https://docs.adaptabletools.com/docs/predefined-config/user-interface-config#checkboxcolumns
So something like:
export default {
UserInterface: {
CheckboxColumns: ['myBooleanColumn'],
},
} as PredefinedConfig;
That will dynamically create a CellRenderer very similar to the one which NearHuscarl suggests.
If the column is ReadOnly the checkboxes will be disabled.
Its worth noting that the CheckboxColumnClickedEvent will fire each time a cell in the column is clicked.
TLDR; When trying to change the background color of a listview using inline CSS with style { ... } it works but addClass using a copy-pasted CSS does nothing.
The following code (using inline CSS) works:
listview(monsterController.monsters) {
vgrow = Priority.ALWAYS
cellFormat {
// addClass(StatBlockStyles.monsterListCell)
style {
backgroundColor += Color.color(253.0 / 255.0, 241.0 / 255.0, 220.0 / 255.0)
}
graphic = label(it.name)
}
But if I comment the style { ... } and uncomment the addClass(...) it seems to have no effect.
The CSS class is a literaly copy-paste of the inline CSS:
import javafx.scene.paint.Color
import tornadofx.*
class StatBlockStyles: Stylesheet() {
companion object {
val monsterListCell by cssclass()
}
init {
monsterListCell {
backgroundColor += Color.color(253.0 / 255.0, 241.0 / 255.0, 220.0 / 255.0)
}
}
}
Why does this happen and what should I do to be able to actually separate the styling from the rest of the code?
Try adding this to your init section of the view/fragment containing your listview:
init {
importStylesheet(StatBlockStyles::class)
}
Note: You only need to use the import function once. The styling will remain for the rest of the program, even in other windows/views/fragments.
I am trying to add a CSS class to a component immediately after I create it using ViewContainerRef and ComponentFactoryResolver. I want to be able to set the class based on what other Components have already been added to myViewContainerRef.
export class ContainerComponent {
#ViewChild('myContainerRef') myContainerRef: ViewContainerRef
constructor(private factoryResolver: ComponentFactoryResolver,
private renderer: Renderer2) {}
addComponent() {
const componentFactory = this.factoryResolver.resolveComponentFactory(SomeBaseComponent)
const newComponent = this.myContainerRef.createComponent(componentFactory)
// SomeBaseComponent has been added successfully to myContainerRef
// Want to add CSS class to the newComponent
// None of the following statements are adding any styles
if( someLogic()) {
this.renderer.addClass(newComponent.location.nativeElement, 'my-css-class')
this.renderer.addClass(newComponent.el.nativeElement, 'my-css-class')
this.renderer.setStyle(newComponent.el.nativeElement, 'background', 'yellow')
}
}
}
export class SomeBaseComponent {
constructor(public el: ElementRef) {}
}
Is there a better way to go about trying to add the style programmatically? Is there something else I can inject into SomeBaseComponent to be able to add the styles I want at this point, or should I set flags on the newComponent.instance and have the base component be in control of what styles to set on itself?
You should add another #ViewChild which will have a read of ElementRef type.
#ViewChild("myContainerRef", {read: ElementRef}) elementRef: ElementRef;
To set the class attribute, you should use the following.
this.elementRef.nativeElement.setAttribute("class", "test")
Note: I will advised putting the creation logic inside an ngOnInit() method, inside of a custom addComponent().
My Class extends gxt button and I would like to add a checkBox in the button
but there is no method for the addition of a component in button.
import com.extjs.gxt.ui.client.widget.button.Button;
import com.extjs.gxt.ui.client.widget.form.CheckBox;
public class ButtonCheckBox extends Button {
private CheckBox checkBox;
public ButtonCheckBox() {
checkBox = new CheckBox();
checkBox.setBoxLabel("CheckBox");
setWidth(200);
}
}
How can I, if possible, add a chckbox in my button?
Thanks Eliran Malka and i done this using below code
import com.dips.pei.client.view.resources.Icons;
import com.extjs.gxt.ui.client.event.ComponentEvent;
import com.extjs.gxt.ui.client.widget.button.ToggleButton;
import com.google.gwt.user.client.ui.AbstractImagePrototype;
public class CheckBoxButton extends ToggleButton {
public CheckBoxButton() {
setIcon(AbstractImagePrototype.create(Icons.INSTANCE.notcheckedIcon()));
setId("checkBoxButton");
}
#Override
protected void onClick(ComponentEvent ce) {
super.onClick(ce);
if(isPressed()){
setIcon(AbstractImagePrototype.create(Icons.INSTANCE.checkedIcon()));
}else{
setIcon(AbstractImagePrototype.create(Icons.INSTANCE.notcheckedIcon()));
}
}
}
It doesn't seem to be possible using the GXT 2.x standard API, but may be achieved using an HTML Template.
Assuming the purpose of the checkbox is to serve as an indicator for the button state, i suggest you use a ToggleButton instead and modify its appearance. You can assign a CSS classname to it and apply differing background images according to its varying states:
.my-toggle-button .x-btn-mc {
background-image: url('images/toggle-button/checkbox-off.png');
}
.my-toggle-button.x-btn-pressed .x-btn-mc {
background-image: url('images/toggle-button/checkbox-on.png');
}
References (on the GXT 2.2.5 API)
Template
ToggleButton