PrimeNG Calendar - Override the default style - css

Using angular, I am using p-calendar in a component and created a CSS class that is called from my component. No matter what I do I am unable to override the style.
CSS
.ui-calendar .ui-calendar-button {
height: 34px;
border-top-left-radius: 0;
border-bottom-left-radius: 0;
width: 900em;
border-left: 0 none;
}
HTML
<div class="form-group col-xs-3 col-md-3"
[ngClass]="{
'has-error':(ersaForm.get('effectiveDt').touched || ersaForm.get('effectiveDt').dirty ) &&
!ersaForm.get('effectiveDt').valid
}">
<label for="effectiveDtId" class="control-label">Effective Date</label><br />
<p-calendar formControlName="effectiveDt" id="effectiveDtId" [showIcon]="true"
inputStyleClass="form-control "
class="ui-calendar ui-calendar-button"
[style]="{'width': '100%','display': 'inline-flex','height':'34px'}" ></p-calendar>
</div>
****************************************************UPDATE****************************************
I changed my SCSS File to
::ng-deep .only-style-this .ui-calendar .ui-calendar-button {
height: 34px !important;
border-top-left-radius: 0 !important;
}
HTML
<div class="form-group col-xs-3 col-md-3 only-style-this"
[ngClass]="{
'has-error':(ersaForm.get('effectiveDt').touched || ersaForm.get('effectiveDt').dirty ) &&
!ersaForm.get('effectiveDt').valid
}">
<label for="effectiveDtId" class="control-label">Effective Date</label><br />
<p-calendar formControlName="effectiveDt" id="effectiveDtId" [showIcon]="true"
inputStyleClass="form-control"
styleCalss=".ui-calendar .ui-calendar-button"
[style]="{'width': '100%','display': 'inline-flex','height':'34px'}" ></p-calendar>
</div>
warning
Validation (CSS 3.0): "::ng-deep" is not a valid pseudo-element.

You can't tweak a child component's css, it breaks encapsulation. This will work but is deprecated:
::ng-deep .ui-calendar .ui-calendar-button {
height: 34px;
border-top-left-radius: 0;
border-bottom-left-radius: 0;
width: 900em;
border-left: 0 none;
}
This is essentially the same as adding it to your global stylesheet. However, the global styles will be applied only when the component has loaded for the first time, making it uber crappy. For safety, you can wrap your component in an "only-style-this" class and do:
::ng-deep .only-style-this .ui-calendar .ui-calendar-button {
...
}
Alternatively, prime-ng usually allows you to pass styles in with most its components.
If you look at the docs you will find that there is a style property you can use. There are also other properties you might want to play with like inputStyle.

As in the following answer https://forum.primefaces.org/viewtopic.php?t=53756 just put your style as list item in the array of styles in the file angular.json
"styles": [
"../node_modules/primeng/resources/primeng.min.css",
"../node_modules/fullcalendar/dist/fullcalendar.min.css",
"../node_modules/quill/dist/quill.snow.css",
"../node_modules/nanoscroller/bin/css/nanoscroller.css",
"styles.css"
],
then you can use your css freely

I use prime ng ver 12.xx
override this ok for me on file style.css (Angular cli
.p-datepicker table td{ padding: 0px; }
.p-datepicker table td > span { height: 45px;width: 50px; }

Related

How to remove padding in antd form label

I have a Form control, rendering an Antd Form.Item:
const FormEditData: React.FC<FormEditDataProps> = ({ label, name, field, rules, customProps, children }) => {
const namePath = [name].concat('value')
const isEditable = field?.fieldAccess > 0
if (isEditable) {
return (
<Form.Item
label={label}
name={namePath}
className={css.FormEditItem}
rules={rules}
{...customProps}
>
{ children}
</Form.Item >
)
}
return null
}
export { FormEditData }
This is rendering as:
<div class="ant-row ant-form-item FormEditItem___2R86H">
<div class="ant-col ant-form-item-label">
<label for="form-2_employeeLastName_value" class="ant-form-item-required" title="Nachname">Nachname</label>
</div>
<div class="ant-col ant-form-item-control">
<div class="ant-form-item-control-input">
<div class="ant-form-item-control-input-content">
<input type="text" id="form-2_employeeLastName_value" class="ant-input" value="Bar">
</div>
</div>
</div>
</div>
With a css module defined as:
.FormEditItem {
margin-bottom: 0.5em;
margin-top: 0.5em;
}
.FormEditItem div {padding: 0;}
The margin to the .FormEditItem is applied correctly, but I want the padding of the child div with the class annotation ant-col ant-form-item-label changed from 0 0 8px to 0
However I seem to be unable to find a suitable path to that element, so that it gets styled properly.
Tested paths:
.FormEditItem div {padding: 0;} //not specified enough
.FormEditItem div.ant-col {padding: 0;} // not applied
.FormEditItem div.ant-col.ant-form-item-label {padding: 0;} // not applied
.FormEditItem .ant-col {padding: 0;} // not applied
.FormEditItem .ant-col.ant-form-item-label {padding: 0;} // not applied
To apply this change on a global level, we can resolve this by editing a less-variable and apply a custom theme.
The corresponding variable is defined here: https://github.com/ant-design/ant-design/blob/ea2545fbc7d02df4efa1b77467672a681158fec0/components/style/themes/default.less#L373
#form-vertical-label-padding: 0;
Using css
I tried this in my custom style.css file
.ant-col.ant-form-item-label {
padding: 0 !important;
}
NOTE:
Your custom css file should be imported after all other third-party css flies
try this,
add property requiredMark and set value to false like this : requiredMark={false}
in Form.Item component
<Form.Item
label={label}
name={namePath}
rules={rules}
requiredMark={false} //add this
{...customProps}
>
{ children}
</Form.Item >

PrimeNG p-dataview hide header

I am writing a PrimeNG application which includes a "p-dataview" element. I am trying to hide the header using the component CSS as shown below.
HTML SNIPPET
<p-dataView [value]="cbItems" layout="grid">
<ng-template let-item pTemplate="gridItem">
<div class="ui-g-12 ui-md-6" >
<p-checkbox label={{item.value}}></p-checkbox>
</div>
</ng-template>
</p-dataView>
CSS SNIPPET
.ui-dataview .ui-dataview-header {
display: none;
}
If I "inspect" the p-dataview header element in Chrome (Styles) i can see an entry for .ui-dataview .ui-dataview-header {}. If edit this in the CHROME and add "display:none", it works.
.ui-dataview .ui-dataview-header {
border-bottom: 0 none;
display: none;
}
I just can't figure out how to do the same in my source file(s). I'm sure this is more a reflection of my novice CSS skills. Any help would be appreciated.
if you put the custom style in global style file will work
style.css
.ui-dataview .ui-dataview-header {
border-bottom: 0 none;
display: none;
}
but the problem with the solution above 👆 is going to apply to p-dataview component in the whole project , primeng provide a solution by add a custome class then apply the stlye as the custom class is the parent class like this
template
<p-dataView styleClass="dataview-grid" [value]="cars" layout="grid">
<ng-template let-item pTemplate="gridItem">
<div class="ui-g-12 ui-md-6" >
<p-checkbox label={{item.value}}></p-checkbox> {{item.brand}} , {{item.year}}
</div>
</ng-template>
</p-dataView>
style.css
.dataview-grid.ui-dataview .ui-dataview-header {
border-bottom: 0 none;
display: none;
}
demo 🚀🚀

How can I overrule a LESS variable within a mixin?

I'm using LESS in one of my projects right now and I need to create some colour-schemes for different users. I'm building a portal and based on what kind of user logs in, the colour-scheme needs to change.
So in my mixins.less (which I can't modify) file I have:
#color-button-bg: #333;
#color-button-txt: #fff;
#color-button-fs: 1.5rem;
#color-button-fw: 500;
#color-button-hover-pct: 10%;
.base-btn-default(#type: button) {
background: ~"#{color-button-bg}";
border: 1px solid ~"#{color-button-bg}";
color: ~"#{color-button-txt}";
font-size: ~"#{color-button-fs}";
font-weight: ~"#{color-button-fw}";
&:hover, &:focus {
#color-btn-hover: ~"color-button-bg";
#color-btn-hover-pct: ~"color-button-hover-pct";
background: darken(##color-btn-hover,##color-btn-hover-pct);
border-color: darken(##color-btn-hover,##color-btn-hover-pct);
color: ~"#{color-button-txt}";
}
}
And in a separate file with client-specific mixins I tried the following:
/* Override default color with theme-color */
.theme-styling() {
#color-button-bg: #main-theme-color;
}
Then finally I wanted to add a class to my <body> tag and style the colour-scheme based on that classname:
body.theme-a {
#main-theme-color: teal;
.theme-styling();
}
However, this doesn't seem to work. I think it has something to do with scoping / Lazy evaluation, but I'm not that experienced in LESS yet, to see where my error is.
I created a Codepen for it, without the separate files and in a bit of a simplified form:
https://codepen.io/jewwy0211/pen/JVNZPv
I've just played around with your codepen a bit. When you define the variable in your mixin, it does work, the problem is that you then don't use that variable in the mixin or in the class that contains the mixin.
So, if you've got 2 buttons like this:
<div class="wrapper one">
<button>Theme 1</button>
</div>
<div class="wrapper two">
<button>Theme 2</button>
</div>
You can call their theme-specific variable mixins in their respective classes to get the vars set, but you then must use the vars within the same class:
.wrapper.one {
.theme-styling-1();
background-color: #color-button-bg;
}
.wrapper.two {
.theme-styling-2();
background-color: #color-button-bg;
}
/* Theme Vars */
.theme-styling-1() {
#color-button-bg: teal;
}
.theme-styling-2() {
#color-button-bg: red;
}
EDIT: Here's a codepen: https://codepen.io/mmshr/pen/OGZEPy

How to remove the default padding in antd

I created collapsible sidebar.In side the sidebar that content automatically taken ant design padding value(16px)at the top,right,bottom and left .I need to remove this automatic padding
render() {
return (
<div className="common-coll-bar">
<Collapse >
<Panel header="Present Staffs" style={customPanelStyle}>
<p style={{ height: 550, color: '#131D43', background: '#607B7E', padding: 0 , margin: 0 }}> {text}</p>
</Panel>
</Collapse>
</div>
);
}
Can you help me?
You would have to manually overwrite the styling.
You can add a custom class to panel:
<Panel header="This is panel header 1" key="1" className="custom">
and Add less:
.custom {
.ant-collapse-content-box {
padding: 0;
}
}
https://codepen.io/kossel/pen/gooQqv
You need to theme antd. Doing the proposed solution by Yichaoz will just work for element that holds that class. Which will be harder to maintain, will require extra work, as you need to add that class to every element.
You need to read this https://ant.design/docs/react/customize-theme for a proper solution.
Using CSS modules:
.collapsePanel {
:global(.ant-collapse-content-box) {
padding: 0 !important;
}
}
import the file and use like:
<Collapse className={css["collapsePanel"]}>
...
For me worked only like this with antd#v5.x

How to change CSS when it's ng-disabled?

I have this button:
<input type="submit" value="#Translator.Translate("PAYOUT")"
class="btn-block secondary-button save-changes padding-8"
ng-disabled="PayoutEnabled==false" ng-click="PayOut()" />
But even when it's disabled it has the same class as it's enabled, just not clickable. I want to change background when it's disabled so that user can see that button, is disabled. How can I do that? Do I need some ng-disabled CSS class or there is some other way?
What Toress answered should work fine but you don't need the help of AngularJS here at all (a native implementation & usage is always best).
You can make use of CSS3 since you already have a class on it. Example:
input.save-changes {
/* some style when the element is active */
}
input.save-changes[disabled] {
/* styles when the element is disabled */
background-color: #ddd;
}
Edit: You can immediately test it on this page of StackOverflow. Just inspect the blue button element and put the disabled attribute and see it's CSS.
.save-changes {
background-color: red;
padding: 7px 13px;
color: white;
border: 1px solid red;
font-weight: bold;
}
.save-changes[disabled] {
background-color: #FF85A1
}
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app ng-init="PayoutEnabled = true">
<a href="#" ng-click="PayoutEnabled = !PayoutEnabled">
{{PayoutEnabled ? 'Disable' : 'Enable'}} the below button</a>
<br>
<br>
<input class="save-changes" type="submit" value="PAYOUT" ng-disabled="PayoutEnabled == false" />
</div>
use ng-class
<input type="submit" value="#Translator.Translate("PAYOUT")" class="btn-block
secondary-button save-changes padding-8" ng-disabled="PayoutEnabled==false"
ng-click="PayOut()" ng-class="{'diabled-class': !PayoutEnabled}" />
this will add css class diabled-class to the input when PayoutEnabled is false (!PayoutEnabled is true).
AngularJS adds pseudo-class disabled when ng-disabled is false so i think here is the simplest solution to refer to disabled button :
button:disabled {
color:#717782;
}
In case you are using Bootstrap and a more recent Angular version than AngularJs you can ovverride the default style adding this to the styles.css file
.btn.disabled, .btn:disabled {
opacity: .35 !important;
background-color: gray !important;
}
The higher the opacity the darker or more solid the color will be.

Resources