Material UI Styling Best Practices - material-ui

I'm using Material-UI with React. I have the following approach:
For global styles I'm using the ThemeProvider
palette: {
type: 'dark',
primary: {
main: '#123',
},
secondary: {
main: '#456',
},
For local styles (in components) I'm using withStyles:
const styles = (theme: any) => ({ ... });
export default withStyles(styles)(UperNavigationBar);
Question 1:
My basic idea is to separate colors, fonts etc. (= global styles) etc. from stuff like spacing, alignment etc. (local styles). This way I can easily switch from a light theme to a dark. What do you think about this approach?
Question 2:
I have several background colors (default background color, navigation elements have other background color also grids) Then there are hover effects with different background colors etc.
But theme.pallette.backgroundColor has only two properties. What's the best way to define further background colors for several components?

I hope it's still relevant.
When it comes to best practices and approaches - I tend to stick to the newest API which is useStyles. About the separation of concerns for styling- in my opinion, it might be very confusing unless it's a global setting. In that case you may want to override it in whatever way explained in the documentation.
I suggest you to first explore the default theme as it really does answer most of your concerns. When changing theme type, you can see that values in the palette will change.
You can override many properties using the theme, and you can also add custom variables. This will help you follow all the specific background colors you have. If you wish these custom colors to match the theme type - simply conditionally apply them.

Related

Is there a way to force "Categorized" symbolization to use attributes in the table for e.g. color definition?

I have a map with a couple of dozen of different "categories" of polygons and would like to symbolize them using the "Categorized" symbolization in QGIS. Every category already has its color defined in a "fill_color" attribute within the table.
I would like the symbolization to honor that color definition instead of assigning some color of its own to the categories.
Is there a way to do this, without manually going through every category and changing its color?
I'm not a Python programmer, so if there is a possibility of programming this, it's beyond me.
The software itself does not offer the option to do what I need in "Categorized" symbolization, although you can do it in "Single Symbol". If you try it in "Categorized" it will let you do the same steps, but the program will nevertheless use colors of its own choosing.
Of course, if I go the "Single Symbol" way, I can't generate a proper legend of map units in Layout.

How can I set primaryContainer color with ColorScheme.fromSwatch() in Material Theme

colorScheme offers in general the primaryContainer parameter. However, when I use `colorScheme.fromSwatch' this is no longer available such as many other parameters.
My understanding of fromSwatch is, I create a standard theme based on the key colors that I define within the color.Scheme. At least this is what I am aiming to do.
So how can I adapt the primaryContainer without defining every mandatory parameter of a scheme?
You can use copyWith method.
ColorScheme.fromSwatch().copyWith(
primaryContainer: Colors.red,
),
More about ColorScheme

Is it a good practice to use Material Ui and tailwind in a same project

I am using next.js with tailwind css and i somehow need some of the ready to use components in my project so i can save my time, for that i have used material-ui. My application works fine but i have got a warning message. Is is possible to use both technologies (material-ui and tailwind css) at same project, if "yes"(means if the combination of both wont effect the performance of the project or any other issue in future ) Is there is any way to remove the warning message it am showing you below
Is it good practice ?
Absolutely Not, You'll face many naming conflicts and it causes many confusions to the compiler and the precedence will be unusual
But can you achieve this ?
Yes, you can !!
To avoid the naming conflicts use the prefix option in your tailwind.config.js file
// tailwind.config.js
module.exports = {
prefix: 'tw-', 👈 Use your desired prefix
}
So now you can use the prefix tw- before the class name of tailwind-css which wont break any of your existing styles.
Note
If you want tailwind classes to get more precedence than any other css styles , you can set the important option to true on tailwind.config.js
module.exports = {
important: true,
}
Extra
To understand the css precedence follow this What is the order of precedence for CSS?

Change default group colors in Zeppelin visualizations

I have a bunch of data that I'm putting into a scatter plot, but the default color ordering is "blue", "lighter blue", and then finally "orange". My data comes in two groups, with constant group names, and no mater what I do, they're always the blue and lighter blue. Which does NOT make for a good visualization.
So far, I haven't found a way to modify the color ordering, or to set specific colors for the known groups. I also haven't been able to change the colors by adding a dummy group (of one element) and playing with the ordering in the SQL statement.
Any help?
Here's a workaround/hack for that missing Zeppelin feature.
Charting in Zeppelin is based on nvd3 (which in turn uses the D3 library). As Zeppelin simply doesn't care about colors yet, it'll always use the nvd3 default, which is defined in the utils.js function nv.utils.defaultColor.
So, to change the color scheme, you can simply override this function. Try out the following JavaScript code in your browser's console. For available color schemes, see the API documentation (note, that Zeppelin still uses the old 3.x version of D3).
nv.utils.defaultColor = function() {
return nv.utils.getColor(d3.scale.category10().range());
}
The remaining problem is, how to permanently add this to your Zeppelin instance, which depends on your environment. It is sufficient to add the above code to the end of your index.html, however this involves modifying the zeppelin-web-x.y.z.war file.
In the end, with above code, you get something like this.

Purpose of secondary dependent styles?

I'm just going through the GWT Tutorial and one point which just don't understand is when and why to use dependent secondary styles. If I define a style in the .css stylesheet, and use the addStyleName method it seems to have the same effect.
E.g. applying a secondary dependent style to a button or applying the it as a non-dependant style seems to yield the exact same results.
Basically the dependent name is more general, since it's calculated at runtime. You can add a dependent name of "highlighted" to any Widget without knowing what it is, and GWT will come up with the appropriate css class name for you. You don't have to hard code button-highlighted, select-highlighted, mycustomthing-highlighted in GWT this way (you do still need to create them all in your css code).