How to use TextPrimary, TextSecondary color values in MudBlazor theme Palette - mudblazor

I am using MudBlazor and it provides a way to manage themes by defining the MudTheme.
e.g
MudTheme MyCustomTheme = new MudTheme()
{
Palette = new Palette()
{
Primary = Colors.Blue.Default,
Secondary = Colors.Blue.Default,
AppbarBackground = "#FFFFFF",
TextPrimary = "#000000",
TextSecondary = "#FFFFFF",
}
};
Setting TextPrimary color will set the provided value to scss variable --mud-palette-text-primary but not apply it to MudText component.
Problem: I am setting TextPrimary and TextSecondary in Palette but when I use the MudBlazor text component it doesn't apply the colors I provided.
<MudText Typo="Typo.h5">Application</MudText>
Note: MudText has a property Color which takes Color enum value but Color enum does't have a TextPrimary Value.
Color enum provided by MudBlazor
public enum Color
{
Default = 0,
Primary = 1,
Secondary = 2,
Tertiary = 3,
Info = 4,
Success = 5,
Warning = 6,
Error = 7,
Dark = 8,
Transparent = 9,
Inherit = 10,
Surface = 11
}
also if I set Color to primary like this
<MudText Typo="Typo.h5" Color="Color.Primary">Application</MudText>
it applies a css class .mud-primary-text or .mud-secondary-text based on parameter i passed, but inside these class they use --mud-palette-primary or --mud-palette-secondary scss variable instead of --mud-palette-primary-textor--mud-palette-secondary-text`
.mud-primary-text {
color: var(--mud-palette-primary) !important; // it should use --mud-palette-primary-text
}
.mud-secondary-text {
color: var(--mud-palette-secondary) !important; // it should use --mud-palette-secondary-text
}
At first, I thought by setting Color field to Primary MudText component will use TextPrimary value and other component will use Primary Value so I created a PR with a possible fix but they rejected it that it is like this by design. you can check it here https://github.com/MudBlazor/MudBlazor/pull/4451.
For now I have solved the problem by overriding the classes.
.mud-primary-text {
color: var(--mud-palette-text-primary) !important;
}
.mud-secondary-text {
color: var(--mud-palette-text-secondary) !important;
}
now is it a bug or my misunderstanding? looks like a bug to me.
Note After debugging I found out that if you use HTML headings or paragraph tags it'll apply colors define in Palette but if use MudText component it'll not work because it applies .mud-primary-text class which set color to --mud-palette-primary so the way to solve this problem is to override the classes and set color to right scss variables, like i have showed above.

For now, I have solved it by the below line of css
.mud-primary-text {
color: var(--mud-palette-text-primary) !important;
}
.mud-secondary-text {
color: var(--mud-palette-text-secondary) !important;
}

Related

How to handle multiple color schemes

I have a quasar project with a dark theme switch.
But I want to change the whole color scheme when if using the dark mode.
I don't know anything about sass, and I wonder that it can be done by updating sass variables when the user changes the theme.
Here's the actual sass variables defined in src/css/quasar.variables.sass (light theme):
// Quasar Sass (& SCSS) Variables
// --------------------------------------------------
// To customize the look and feel of this app, you can override
// the Sass/SCSS variables found in Quasar's source Sass/SCSS files.
// Check documentation for full list of Quasar variables
// Your own variables (that are declared here) and Quasar's own
// ones will be available out of the box in your .vue/.scss/.sass files
// It's highly recommended to change the default colors
// to match your app's branding.
// Tip: Use the "Theme Builder" on Quasar's documentation website.
$primary : #1976D2
$secondary : #26A69A
$accent : #9C27B0
$dark : #1D1D1D
$positive : #21BA45
$negative : #C10015
$info : #31CCEC
$warning : #F2C037
And when the dark theme is enabled I want to have something like :
$primary : red
$secondary : blue
$accent : green
$dark : #1D1D1D
$positive : #21BA45
$negative : #C10015
$info : #31CCEC
$warning : #F2C037
Is there a way to achieve this ? Can I put some logic in a .sass file ?
You can programmatically change the brand colors using setCssVar like this:
import { setCssVar } from 'quasar';
//...
setup() {
// Setup theme
setCssVar('primary', '#1976d2');
setCssVar('secondary', '#26A69A');
setCssVar('accent', '#9C27B0');
setCssVar('dark', '#1d1d1d');
setCssVar('positive', '#21BA45');
setCssVar('negative', '#C10015');
setCssVar('info', '#31CCEC');
setCssVar('warning', '#F2C037');
// ...
}
Quasar V1 solution
Finally found it in the docs.
import { colors } from 'quasar'
colors.setBrand('light', '#DDD')
colors.setBrand('primary', '#33F')
colors.setBrand('primary', '#F33', document.getElementById('rebranded-section-id'))
I have done this with pure CSS. There are two ways:
First:
.body--light {
--q-primary: #244156;
--q-secondary: #...;
--q-accent: #...;
}
.body--dark {
--q-primary: #1D3549;
--q-secondary: #...;
--q-accent: #...;
}
.body--light .drawer {background: #E9F1F7;}
.body--dark .drawer {background: #112330;}
.body--light .loginbtn {background: #7F8F82;}
.body--dark .loginbtn {background: #364D3B;}
Second (with vars).
First you define all you colors, both light and dark and then use it in classes:
.body--light {
--red: red;
--blue: blue;
--green: green;
}
.body--dark {
--red: darkred;
--blue: darkblue;
--green: darkgreen;
}
.drawer {
background: var(--blue)
}
.loginbtn {
background: var(--red)
}

How to change an attribute of a button without invalidating

I want to change the color of a button in R/Shiny without invalidating it.
Specifically, I want the button to be red if the parameters for the execution changed but only execute if the button is pressed.
I have isolated the parameters in the reactive and only react to the change of the button:
# react on button pressed (unfortunately also if color is changed
input$Button
# don't react on parameters changes
paramet <- isolate(input$parameter)
In an observer I check the parameters and change the color:
if (!modified) {
# cat(file = stderr(), "\n\ntsne not modified\n\n\n")
actionButton(name, "apply changes", width = '80%',
style = "color: #fff; background-color: #00b300; border-color: #2e6da4")
} else {
# cat(file = stderr(), "\n\ntsne modified\n\n\n")
actionButton(name, "apply changes", width = '80%',
style = "color: #fff; background-color: #cc0000; border-color: #2e6da4")
}
But somehow this triggers the button.
The only thing I can think of is creating a new reactive that only changed only if the button is pressed. I.e. in my observer I would change a reactive value if the button value is increased, meaning, I will have to store the old value in a project-specific variable. I was hoping that there would be an easier way to accomplish this.
Thanks for your help.
using shinyjs with addClass(ButtonName, cssElement) , removeClass(ButtonName, cssElement), [cssElement = 'red' | 'green'] and in the UI:
shinydashboard::dashboardBody(
shinyjs::useShinyjs(debug = TRUE),
inlineCSS(list(.red = "background: red")),
inlineCSS(list(.green = "background: green")),
...
In fact, I was using actionButton and not updateActionButton, which was reinitialziing the actionButton, causing some unwanted side-effects, and updateActionButton doesn't allow changing the color.

Vuetify input color property works only when focused

I'm trying to understand how Vuetify's input color property is working and I can't find it in documentation, which simply states:
color
Applies specified color to the control - it can be the name of material color (for example success or purple) or css color (#033 or rgba(255, 0, 0, 0.5)). You can find list of built in classes on the colors page.
What I'm observing is that the color has effect only when the control has focus [LIVE DEMO], and goes back to default color when the control loses focus.
<v-text-field color="orange" label="label" />
Focused:
Not focused:
Is this by design, and is it specified anywhere?
Most importantly, how to affect the color of the not-focused state (preferably without custom CSS)?
To set the default color to v-text-field use the following css
-- #ff9800 (equivalenyt to orange color)
Working codepen is here https://codepen.io/chansv/pen/ZEEOXKN
.theme--light.v-text-field>.v-input__control>.v-input__slot:before {
border-color: #ff9800;
}
.theme--light.v-label {
color: #ff9800;
}
.theme--light.v-input:not(.v-input--is-disabled) input, .theme--light.v-input:not(.v-input--is-disabled) textarea {
color: #ff9800;
}
Github issue in vuetify https://github.com/vuetifyjs/vuetify/issues/3430

Keep background color on highlighted cells

Handsontable overrides a cell's background color when the highlighting plugin is activated, as this image shows.
Is there a way to keep the background color when highlighting?
Example result
Without code it's a little hard to see what you're doing, but essentially, you will have to use the !important tag on your css rule. For example, if you had a rule on your td's that turned the background pink, you'd do the following:
td.pinkCell {
background-color:pink!important;
}
This will ensure the highlighting does not override your property.
.handsontable .currentRow {
background-color: rgba(225, 250, 255, 1);
}
.handsontable .currentCol {
background-color: rgba(225, 250, 255, 1);
}
The purpose was able to be accomplished in this. Thank you for an answer.

Custom color of selected row in angular-ui-grid

I want to change the cell/row colors of an angular-ui-grid. From the documentation it seems I should use the cellClass for this. I want two colors for a striped look and another color for the currently selected row.
In my columnDefs I use a function to determine the proper cellClass. This works perfect on first load.
$scope.getCellClass = function (grid, row, col, rowRenderIndex, colRenderIndex) {
if (row.isSelected)
return 'my-grid-cell-selected';
if ((rowRenderIndex % 2) == 0) {
return 'my-grid-cell1';
}
else {
return 'my-grid-cell2';
}
}
$scope.gridOptions = {
enableRowSelection: true,
enableRowHeaderSelection: false,
multiSelect: false,
columnDefs: [
{ field: 'EventDate', cellClass: $scope.getCellClass },
...
]
};
I don't know, however, how to update the cellClass of all cells of the selected row.
I have the following code that I thought would update the selected row but nothing happens although I can see that it is called.
$scope.gridOptions.onRegisterApi = function (gridApi) {
$scope.gridApi = gridApi;
gridApi.selection.on.rowSelectionChanged($scope, function(row){
//??????
gridApi.core.notifyDataChange(uiGridConstants.dataChange.ROW);
});
};
Without my cellClasses the selected row gets colored differently.
Any idea how to achieve a customized color for the selected row?
Here's the way to do it with CSS:
.ui-grid-row-selected.ui-grid-row:nth-child(odd) .ui-grid-cell,
.ui-grid-row-selected.ui-grid-row:nth-child(even) .ui-grid-cell {
color: #fff;
background-color: blue;
}
.ui-grid-row-selected.ui-grid-row:nth-child(odd) .ui-grid-cell.ui-grid-cell-focus,
.ui-grid-row-selected.ui-grid-row:nth-child(even) .ui-grid-cell.ui-grid-cell-focus {
outline: 0;
background-color: blue;
}
.ui-grid-row-selected.ui-grid-row:nth-child(odd):hover .ui-grid-cell,
.ui-grid-row-selected.ui-grid-row:nth-child(even):hover .ui-grid-cell {
color: #fff;
background-color: blue;
}
The best and easiest way to do this in my opinion is use the provided ui-grid customizer!
Specifically what you're looking for to change the background color for odd vs even rows is to change the #rowcoloreven and #rowcolorodd fields.
To change the color of the currently selected row, update in the customizer the #focusedcell property and in addition follow this tutorial and/or look at the second controller in this plunker to extend your selection from a single cell to the entire row.
I have also created a new plunker which shows how to implement row selection as well as how to change the row color defaults. Yes I know it's truly garish coloring - I thought it would help to really get the point across :). You can see in custom.css what is actually different from the uncustomized ui-grid css is
.ui-grid-row:nth-child(odd) .ui-grid-cell {
background-color: #ffff33;
}
.ui-grid-row:nth-child(even) .ui-grid-cell {
background-color: #ff22ff;
}
.ui-grid-cell-focus {
outline: 0;
background-color: #b3c4c7;
}
If you need more direction let me know :)

Resources