Angular Material Theme in not being applied on mtx-datetimepicker - css

Scenario:
I'm using directives from ng-matero for DateTime and using Angular Material for overall designing my application. Overall the functionality works fine. However angular material theme doesn't get apply on the dateTimepicker element as shown
Code
My app.module.ts file looks like this
import { HttpClientModule } from '#angular/common/http';
import { NgModule } from '#angular/core';
import { FormsModule, ReactiveFormsModule } from '#angular/forms';
import { BrowserModule } from '#angular/platform-browser';
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { MaterialModule } from './material.module';
import { SearchComponent } from './components/search/search.component';
import { JourneysListComponent } from './components/journeys-list/journeys-list.component';
import { FlexLayoutModule } from '#angular/flex-layout';
import { BrowserAnimationsModule } from '#angular/platform-browser/animations';
import { MtxDatetimepickerModule } from '#ng-matero/extensions/datetimepicker';
import { MtxNativeDatetimeModule } from '#ng-matero/extensions/core';
#NgModule({
declarations: [
AppComponent,
SearchComponent,
JourneysListComponent,
],
imports: [
BrowserModule,
AppRoutingModule,
FormsModule,
ReactiveFormsModule,
HttpClientModule,
MaterialModule,
FlexLayoutModule,
BrowserAnimationsModule,
MtxDatetimepickerModule,
MtxNativeDatetimeModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
HTML
<div class="login-wrapper" fxLayout="row" fxLayoutAlign="center center">
<mat-card class="box">
<mat-card-header>
<mat-card-title>Planner</mat-card-title>
</mat-card-header>
<form class="example-form">
<mat-card-content>
<mat-form-field class="example-full-width">
<input matInput placeholder="Origin" matInput required>
</mat-form-field>
<mat-form-field class="example-full-width">
<input matInput placeholder="Destination" matInput required>
</mat-form-field>
<mat-form-field class="example-full-width">
<mat-placeholder>Date & Time</mat-placeholder>
<mtx-datetimepicker #datetimePicker
[type]="type"
[mode]="mode"
[multiYearSelector]="multiYearSelector"
[startView]="startView"
[twelvehour]="twelvehour"
[timeInterval]="timeInterval"
[touchUi]="touchUi"
[timeInput]="timeInput"></mtx-datetimepicker>
<input [mtxDatetimepicker]="datetimePicker" [formControl]="datetime" matInput required>
<mtx-datetimepicker-toggle [for]="datetimePicker" matSuffix></mtx-datetimepicker-toggle>
</mat-form-field>
</mat-card-content>
<button mat-stroked-button color="accent" class="btn-block">Search</button>
</form>
</mat-card>
</div>
TS
import { Component, OnInit } from '#angular/core';
import {MtxCalendarView,MtxDatetimepickerMode,MtxDatetimepickerType} from '#ng-matero/extensions/datetimepicker';
import { MTX_DATETIME_FORMATS } from '#ng-matero/extensions/core';
import { UntypedFormControl } from '#angular/forms';
#Component({
selector: 'app-search',
templateUrl: './search.component.html',
styleUrls: ['./search.component.scss'],
providers: [
{
provide: MTX_DATETIME_FORMATS,
useValue: {
parse: {
dateInput: 'YYYY-MM-DD',
monthInput: 'MMMM',
yearInput: 'YYYY',
timeInput: 'HH:mm',
datetimeInput: 'YYYY-MM-DD HH:mm',
},
display: {
dateInput: 'YYYY-MM-DD',
monthInput: 'MMMM',
yearInput: 'YYYY',
timeInput: 'HH:mm',
datetimeInput: 'YYYY-MM-DD HH:mm',
monthYearLabel: 'YYYY MMMM',
dateA11yLabel: 'LL',
monthYearA11yLabel: 'MMMM YYYY',
popupHeaderDateLabel: 'MMM DD, ddd',
},
},
},
],
})
export class SearchComponent implements OnInit {
type: MtxDatetimepickerType = 'datetime';
mode: MtxDatetimepickerMode = 'auto';
startView: MtxCalendarView = 'month';
multiYearSelector = false;
touchUi = false;
twelvehour = false;
timeInterval = 1;
timeInput = true;
datetime = new UntypedFormControl();
constructor() { }
ngOnInit(): void {
}
}
Question
Do I need to set theme exclusively for mtx-datetimepicker? if yes, How could I do that?

After import modules, you must define a theme.
#use '#ng-matero/extensions' as mtx;
#include mtx.all-component-themes($theme);

Related

Svelte + Tailwind: "Semicolon or block is expected"

I have a Svelte project using Tailwind, with this style in a component:
<style global lang="postcss">
input {
#apply block border-black border-2 mb-4 p-2 outline-none focus:border-blue-500;
}
</style>
The error that I'm getting, caused by the focus: class:
Semicolon or block is expected
My postcss.config.cjs file:
import tailwind from 'tailwindcss'
import tailwindConfig from './tailwind.config.cjs'
import autoprefixer from 'autoprefixer'
export default {
plugins: [tailwind(tailwindConfig), autoprefixer]
}
tailwind.config.cjs:
/** #type {import('tailwindcss').Config} */
module.exports = {
theme: {
extend: {},
},
plugins: [],
content: ["./index.html", './src/**/*.{svelte,js,ts}'], // for unused CSS
variants: {
extend: {},
},
darkMode: 'media', // or 'media' or 'class'
}
vite.config.js:
import postcss from './postcss.config.cjs'
import { defineConfig } from 'vite'
import { svelte } from '#sveltejs/vite-plugin-svelte'
// https://vitejs.dev/config/
export default defineConfig({
plugins: [svelte()],
css: {
postcss
}
})

Material Angular - button style not rendering

I'm not sure if I found a bug or if my configuration is off. My other components render and look like they're supposed to. But material angular's button styles are not loading right.
I'm using material angular and the issue is with the raised button from here https://material.angular.io/components/button/overview
Here is my markup
<div class="nav-item">
<button class="mat-raised-button"
(click)="navToCreate()">
New Post
</button>
</div>
<div class="nav-item">
<button class="mat-raised-button" *ngIf="isLoggedIn === false" (click)="navToLogin()">
<i class="material-icons md-48">account_box</i>
<span>Login</span>
</button>
</div>
<div class="nav-item">
<button class="mat-raised-button" *ngIf="isLoggedIn === true" (click)="logOut()">
<i class="material-icons md-48">account_box</i>
<span>Logout</span>
</button>
</div>
And here is what they render as
Pic of buttons
My app.module is the following
import { BrowserModule } from '#angular/platform-browser';
import { HttpClientModule } from '#angular/common/http';
import { NgModule } from '#angular/core';
import { ReactiveFormsModule } from '#angular/forms';
import { FormsModule } from '#angular/forms';
import { AppRoutingModule } from './app-routing.module';
// Material components
import { MatFormFieldModule } from '#angular/material/form-field';
import { MatInputModule } from '#angular/material/input';
import { MatCardModule } from '#angular/material/card';
import { MatSnackBarModule } from '#angular/material/snack-bar';
import { MatSidenavModule } from '#angular/material/sidenav';
import { MatToolbarModule } from '#angular/material/toolbar';
import { MatTabsModule } from '#angular/material/tabs';
import { MatListModule } from '#angular/material/list';
import { MatButtonModule } from '#angular/material/button';
// Components
import { AppComponent } from './app.component';
import { HomeComponent } from './components/home/home.component';
import { DiscussionCardComponent } from './components/discussion-card/discussion-card.component';
import { LoginComponent } from './components/login/login.component';
import { DiscussionDetailComponent } from './components/discussion-detail/discussion-detail.component';
import { SideMenuComponent } from './components/side-menu/side-menu.component';
import { DiscussionCreateComponent } from './components/discussion-create/discussion-create.component';
import { DiscussionDetailPageComponent } from './components/discussion-detail-page/discussion-detail-page.component';
import { TruncatePipe } from './pipes/truncate.pipe';
import { BrowserAnimationsModule } from '#angular/platform-browser/animations';
#NgModule({
declarations: [
AppComponent,
HomeComponent,
DiscussionCardComponent,
LoginComponent,
DiscussionDetailComponent,
TruncatePipe,
SideMenuComponent,
DiscussionCreateComponent,
DiscussionDetailPageComponent,
],
imports: [
BrowserModule,
HttpClientModule,
AppRoutingModule,
ReactiveFormsModule,
FormsModule,
BrowserAnimationsModule,
MatFormFieldModule,
MatInputModule,
MatCardModule,
MatSnackBarModule,
MatSidenavModule,
MatToolbarModule,
MatTabsModule,
MatListModule,
MatButtonModule,
],
exports: [],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
Any help is appreciated. Thank you
your error is the mat-raised-button part. It is not a class, it is a property of the button.
<button mat-raised-button> is correct, <button class="mat-raised-button"> is using a class

FontAwesome Icons Not showing up when used with PrimeNg Module

I have installed angular-fontawesome using the instructions here:
https://www.npmjs.com/package/#fortawesome/angular-fontawesome
The icons show up when used in this fashion (app.component.html):
<div style="text-align:center">
<!-- simple name only that assumes the 'fas' prefix -->
<fa-icon icon="coffee"></fa-icon>
<!-- ['fas', 'coffee'] is an array that indicates the [prefix, iconName] -->
<fa-icon [icon]="['fas', 'coffee']"></fa-icon>
<fa-icon [icon]="['fa', 'fa-fw', 'fa-book']"></fa-icon>
</div>
My app.module.ts
import { BrowserModule } from '#angular/platform-browser';
import {BrowserAnimationsModule} from '#angular/platform-browser/animations';
import { NgModule } from '#angular/core';
import { HttpClientModule } from '#angular/common/http';
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { ButtonModule } from 'primeng/button';
import { MenuModule } from 'primeng/menu';
import { TabMenuModule } from 'primeng/tabmenu';
import { FontAwesomeModule } from '#fortawesome/angular-fontawesome';
import { library } from '#fortawesome/fontawesome-svg-core';
import { fas } from '#fortawesome/free-solid-svg-icons';
import { far } from '#fortawesome/free-regular-svg-icons';
import { TestcomponentComponent } from './testcomponent/testcomponent.component';
#NgModule({
declarations: [
AppComponent,
TestcomponentComponent
],
imports: [
BrowserModule,
BrowserAnimationsModule,
AppRoutingModule,
HttpClientModule,
ButtonModule,
MenuModule,
TabMenuModule,
FontAwesomeModule,
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule {
constructor() {
// Add an icon to the library for convenient access in other components
library.add(fas, far);
}
}
However, I get no icons when integrating it with a PrimeNg Module (in this case their TabMenuModule). Not doing anything unusual, just following the instructions here:
https://www.primefaces.org/primeng/#/tabmenu
app.component.ts
export class AppComponent {
title = 'ClientApp';
private items: MenuItem[];
ngOnInit() {
this.items = [
{label: 'Overview', icon: 'fa fa-fw fa-bar-chart'},
{label: 'Schedule', icon: 'fa fa-fw fa-calendar'},
{label: 'Documentation', icon: 'fa-coffee'},
{label: 'Support', icon: 'fa fa-fw fa-support'},
{label: 'Discussion', icon: 'fa fa-fw fa-twitter'}
];
}
I add these lines to top of the html:
<h3 class="first">Default</h3>
<p-tabMenu [model]="items1" [activeItem]="items1[0]"></p-tabMenu>
<h3>Templating</h3>
<p-tabMenu [model]="items2" [activeItem]="activeItem">
<ng-template pTemplate="item" let-item let-i="index">
<div style="position: relative; text-align: center; min-width: 10em">
<div class="ui-menuitem-icon" [ngClass]="item.icon" *ngIf="item.icon" style="font-size: 2em"></div>
<div class="ui-menuitem-text">
{{item.label}}
</div>
<a tabindex="0" class="ui-menuitem-icon" (click)="closeItem($event, i)" style="position: absolute; right: -1em; top: -.5em; padding: 0" *ngIf="i !== 0">
<span class="pi pi-times"></span>
</a>
</div>
</ng-template>
</p-tabMenu>
<p-tabMenu [model]="items"></p-tabMenu>
<i class="far fa-chart-bar"></i>
angular.json:
"build": {
"builder": "#angular-devkit/build-angular:browser",
"options": {
"outputPath": "dist/ClientApp",
"index": "src/index.html",
"main": "src/main.ts",
"polyfills": "src/polyfills.ts",
"tsConfig": "src/tsconfig.app.json",
"assets": [
"src/favicon.ico",
"src/assets"
],
"styles": [
"node_modules/primeicons/primeicons.css",
"node_modules/primeng/resources/themes/nova-light/theme.css",
"node_modules/primeng/resources/primeng.min.css",
"src/styles.css"
],
I am using:
Angular CLI: 8.0.2
Node: 10.15.3
OS: win32 x64
Angular: 8.0.0
angular-fontawesome#0.4.0
free-solid-svg-icons#5.9.0
free-regular-svg-icons#5.9.0
Try adding these css entries into your styles.scss file, that is what it took in my case.
#import "~primeicons/primeicons.css";
#import "~primeng/resources/themes/saga-blue/theme.css";
#import "~primeng/resources/primeng.min.css";
#import "~primeflex/primeflex.css";

How to retrieve plain CSS from inline style in ReactJS?

I'm using inline style to style the HTML DOM element. I want to display converted plain CSS. I'm changing the inline style using component state.
I do the following. It prints the style objects. e.g.,
{"display":"flex","flexDirection":"column"}
import React, {Component} from 'react';
class Sample extends Component {
constructor(props) {
super(props);
this.state = {
style: {
display: "flex",
flexDirection: "column"
},
}
}
render() {
const {style} = this.state;
return (
<div>
<div style={style}>
<div id={1}>1</div>
<div id={2}>2</div>
<div id={3}>3</div>
<div id={4}>4</div>
</div>
<div>{JSON.stringify(style)}</div>
</div>
);
}
}
export default Sample;
I expect the output as plain CSS instead of inline style object. e.g., "display: flex; flex-direction: column;"
This is some hack, but it will fulfil your requirement.
import React, {Component} from 'react';
class Sample extends Component {
constructor(props) {
super(props);
this.state = {
style: {
display: "flex",
flexDirection: "column"
},
}
}
getStyle(){
let styled = '{';
Object.keys(this.state.style).forEach(e => {
let key = e.split(/(?=[A-Z])/).join('-').toLowerCase()
styled += `${key}:${this.state.style[e]};`
});
styled += '}'
return styled;
}
render() {
const {style} = this.state;
return (
<div>
<div style={style}>
<div id={1}>1</div>
<div id={2}>2</div>
<div id={3}>3</div>
<div id={4}>4</div>
</div>
<div>{this.getStyle()}</div>
</div>
);
}
}
export default Sample;
Demo
Best way would be configure webpack to extract css to a new file.
npm install extract-text-webpack-plugin --save-dev
npm install style-loader css-loader --save-dev
const ExtractTextPlugin = require("extract-text-webpack-plugin");
module.exports = {
module: {
rules: [
{
test: /\.css$/,
use: ExtractTextPlugin.extract({
fallback: "style-loader",
use: "css-loader"
})
}
]
},
plugins: [
new ExtractTextPlugin("styles.css"),
]
}
I come across ReactJS ref document. And I tried the below way. It works as I was expecting. Demo
import React, { Component } from "react";
class Sample extends Component {
constructor(props) {
super(props);
this.itemContainerRef = React.createRef();
this.state = {
style: {
display: "flex",
flexDirection: "column"
},
itemContainerCSS: {}
};
}
componentDidMount() {
this.setState({
itemContainerCSS: this.itemContainerRef.current.style.cssText || {}
});
}
render() {
const { style, itemContainerCSS } = this.state;
return (
<div>
<div style={style} ref={this.itemContainerRef}>
<div id={1}>1</div>
<div id={2}>2</div>
<div id={3}>3</div>
<div id={4}>4</div>
</div>
<div>{JSON.stringify(itemContainerCSS)}</div>
</div>
);
}
}
export default Sample;

Modal teamplate as directive and use in parent component in angular 2

in Util - I am having
modal-dialog.component.ts
import {Component, Input, ViewChild, ViewContainerRef} from "#angular/core";
import {ModalDirective} from 'ng2-bootstrap/ng2-bootstrap';
#Component({
selector: 'custom-modal',
templateUrl: 'modules/util/template/modal-dialog.html',
exportAs: 'child' }) export class ModalDialogComponent {
#ViewChild('childModal') public childModal: ModalDirective;
public show(variant): void {
debugger
console.log(this.childModal);
this.childModal.show();
} }
modal-dialog.html
<div bsModal #childModal="bs-modal" class="modal fade" tabindex="-1"
role="dialog" aria-labelledby="myLargeModalLabel"
aria-hidden="true">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title">Large modal</h4>
</div>
<div class="modal-body">
...
</div>
</div>
</div> </div>
Util.module.ts
import { NgModule } from '#angular/core';
import { CommonModule } from '#angular/common';
import { HttpModule, Http } from '#angular/http';
import { ModalDialogComponent } from '../../util/components/modal-dialog.component';
#NgModule({
imports: [
CommonModule,
HttpModule,
ModalModule
],
exports: [
CommonModule,
],
providers: [
],
declarations: [
ModalDialogComponent
] }) export class UtilModule {
static forRoot(): ModuleWithProviders {
return {
ngModule: UtilModule
};
} }
app.module.ts
import UtilModule.forRoot()
test.component.html
<div>
<custom-modal></custom-modal>
<button type="button" class="btn btn-primary (click)="c.show(variant)">open</button>
</div>
and in test.component.ts /* system-defined */
import { Component, OnInit, OnDestroy, ViewChild, Directive, NgModule, ViewContainerRef} from '#angular/core';
import { Router, ActivatedRoute, Params } from '#angular/router';
#Component({
templateUrl: 'modules/sample/template/sample-test.component.html' })
export class SampleTestComponent {
}
I am unable to load child html on parent (test)
Unhandled Promise
rejection: Template parse errors: 'custom-modal' is not a known
element:
1. If 'custom-modal' is an Angular component, then verify that it is part of this module.
2. If 'custom-modal' is a Web Component then add "CUSTOM_ELEMENTS_SCHEMA" to the '#NgModule.schemas' of this
component to suppress this message. ("

Resources