Angular Material Heighten Contrast Globally? - css

I am trying to put together some basic reactive forms.
The problem we have is that our compliance department is not going to let us go through because all of the contrasts for material form fields are too transparent/light.
I am looking for a way to darken up all of the form fields, outlines, disabled text etc.
I have been trying to make it global by going into my primary stylesheet. However I cannot seem to figure out how to override material in this way.
I have tried the following within the scss:
.mat-input-element:disabled .mat-form-field-type-mat-native-select.mat-form-field-disabled .mat-form-field-infix::after {
opacity: 1.0 !important;
}
.mat-input-element .mat-form-field-autofill-control .ng-tns-c161-25 .ng-untouched .ng-pristine .cdk-text-field-autofill-monitored {
opacity: 1.0 !important;
}
Or higher in the themes:
// Light Theme Text
$dark-text: #000000;
$dark-primary-text: rgba($dark-text, 1.0);
$dark-accent-text: rgba($dark-primary-text, 1.0);
$dark-disabled-text: rgba($dark-primary-text, 1.0);
$dark-dividers: rgba($dark-primary-text, 1.0);
$dark-focused: rgba($dark-primary-text, 1.0);
$mat-light-theme-foreground: ( base: black, divider: $dark-dividers, dividers: $dark-dividers, disabled: $dark-disabled-text, disabled-button: rgba($dark-text, 0.26), disabled-text: $dark-disabled-text, elevation: black, secondary-text: $dark-accent-text, hint-text: $dark-disabled-text, accent-text: $dark-accent-text, icon: $dark-accent-text, icons: $dark-accent-text, text: $dark-primary-text, slider-min: $dark-primary-text, slider-off: rgba($dark-text, 0.26), slider-off-active: $dark-disabled-text, );
// Dark Theme text
$light-text: #ffffff;
$light-primary-text: $light-text;
$light-accent-text: rgba($light-primary-text, 1.0);
$light-disabled-text: rgba($light-primary-text, 1.0);
$light-dividers: rgba($light-primary-text, 1.0);
$light-focused: rgba($light-primary-text, 1.0);
$mat-dark-theme-foreground: ( base: $light-text, divider: $light-dividers, dividers: $light-dividers, disabled: $light-disabled-text, disabled-button: rgba($light-text, 0.3), disabled-text: $light-disabled-text, elevation: black, hint-text: $light-disabled-text, secondary-text: $light-accent-text, accent-text: $light-accent-text, icon: $light-text, icons: $light-text, text: $light-text, slider-min: $light-text, slider-off: rgba($light-text, 0.3), slider-off-active: rgba($light-text, 0.3), );
Neither of these approaches seem to effect the project and components in any way.
Is there a method I can use to darken the contrast of all form fields globally? Without resorting to directives or having to include the same manual css to every component.css ?
Thanks much.
EDIT: I am trying to overcome this very transparent.

You should be able to override most of the mat-form-field rules to meet your requirements. Here are some examples you can add to your top level style sheet for the 'fill' appearance:
.mat-form-field-appearance-fill {
.mat-form-field-label {
color: rgba(0, 0, 0, 1) !important;
}
.mat-form-field-flex {
background-color: rgba(0, 0, 0, 0.08);
}
}
.mat-form-field-appearance-fill.mat-form-field-disabled {
.mat-form-field-label {
color: rgba(0, 0, 0, 0.8) !important;
}
.mat-form-field-flex {
background-color: rgba(0, 0, 0, 0.04);
}
}
https://stackblitz.com/edit/angular-a7hisy?file=src%2Fstyles.scss
For appearance="outline"
.mat-form-field-appearance-outline {
.mat-form-field-label {
color: rgba(0, 0, 0, 1) !important;
}
.mat-form-field-outline {
color: rgba(0, 0, 0, 0.4);
}
}
.mat-form-field-appearance-outline.mat-form-field-disabled {
.mat-form-field-label {
color: rgba(0, 0, 0, 0.8) !important;
}
.mat-form-field-outline {
color: rgba(0, 0, 0, 0.2);
}
}
https://stackblitz.com/edit/angular-jy3hjq?file=src%2Fapp%2Fform-field-appearance-example.html

Related

Can't use tailwind with next.js in sub folders

I have a project using next.js and tailwind v2.2. When I installed tailwind and imported to _app.tsx, everything was ok and it works in _app.tsx and components which is in components folder. But when I try to use tailwind custom classes in sub folder of components folder, It doesn't work!
For example it works in footer.tsx component but doesn't work in files that are indexComponents (Picture below)
tailwind.confing.js:
// tailwind.config.js
module.exports = {
mode: "jit",
purge: ['./pages/**/*.{js,ts,jsx,tsx}','./components/**/*.{js,ts,jsx,tsx}','./components/indexComponents/*.{js,ts,jsx,tsx}'] ,
darkMode: false, // or 'media' or 'class'
theme: {
colors: {
// blue-mode
// "color-50": "#eff6ff",
// "color-100": "#dbeafe",
// "color-200": "#bfdbfe",
// "color-300": "#93c5fd",
// "color-400": "#60a5fa",
// "color-500": "#3b82f6",
// "color-600": "#2563eb",
// "color-650": "#086ad8",
// "color-700": "#1d4ed8",
// "color-800": "#1e40af",
// "color-900": "#1e3a8a",
// purple mode
"color-50": "#faf5ff",
"color-100": "#f3e8ff",
"color-200": "#e9d5ff",
"color-300": "#d8b4fe",
"color-400": "#c084fc",
"color-500": "#a855f7",
"color-600": "#9333ea",
"color-650": "#9333ea",
"color-700": "#7e22ce",
"color-800": "#6b21a8",
"color-900": "#581c87"
},
screens: {
sm: "640px",
md: "768px",
lg: "1024px",
xl: "1200px",
"2xl": "1200px"
},
container: {
center: true,
padding: "1rem"
},
fontFamily: {
heading: ["Poppins, sans-serif"],
body: ["Montserrat, sans-serif"]
},
boxShadow: {
sm: "0 1px 2px 0 rgba(0, 0, 0, 0.05)",
DEFAULT: "0px 2px 4px rgba(148, 163, 184, 0.05), 0px 6px 24px rgba(235, 238, 251, 0.4)",
md: "0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06)",
lg: "0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05)",
xl: "0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04)",
"2xl": "0 25px 50px -12px rgba(0, 0, 0, 0.25)",
"3xl": "0 35px 60px -15px rgba(0, 0, 0, 0.3)",
inner: "inset 0 2px 4px 0 rgba(0, 0, 0, 0.06)",
none: "none"
},
fontSize: {
xs: ".75rem",
sm: ".875rem",
tiny: ".875rem",
base: "1rem",
lg: "1.125rem",
xl: "1.25rem",
"2xl": "1.5rem",
"3xl": "1.875rem",
"4xl": ["2.25rem", "3.2rem"],
"5xl": ["3rem", "4rem"],
"6xl": ["4rem", "1rem"],
"7xl": ["5rem", "1rem"],
"10xl":"6rem"
},
extend: {
keyframes:{
modalDown:{
'0%,50%':{marginTop:-300},
'50%,100%':{marginTop:0}
}
},
animation:{
modalDown:'modalDown 0.5s linear'
},
width: {
'3/4': '75%',
},
colors: {
white: "#ffffff",
body: "#1e293b",
//blue-mode
// "colorGray-50": "#f8fafc",
// "colorGray-100": "#f1f5f9",
// "colorGray-200": "#e2e8f0",
// "colorGray-300": "#cbd5e1",
// "colorGray-400": "#94a3b8",
// "colorGray-500": "#64748b",
// "colorGray-600": "#475569",
// "colorGray-700": "#334155",
// "colorGray-800": "#1e293b",
// "colorGray-900": "#0f172a",
// "primary": "rgb(96,165,250)",
// //purple mode
"colorGray-50": "#f5f3ff",
"colorGray-100": "#ede9fe",
"colorGray-200": "#ddd6fe",
"colorGray-300": "#cbd5e1",
"colorGray-400": "#a78bfa",
"colorGray-500": "#64748b",
"colorGray-600": "#475569",
"colorGray-700": "#6d28d9",
"colorGray-800": "#5b21b6",
"colorGray-900": "#4c1d95",
"primary":"rgb(96,165,250)",
},
height: {
"128": "32rem"
},
}
},
important: true,
variants: {
extend: {}
},
plugins: []
};
For example I have 'text-color-400' custom class that works in _app.tsx and doesn't work in the components of indexComponents.When I inspect the element don't see anything from globals.css
globals.css:
/*tailwindcss utility classes*/
#tailwind base;
#tailwind components;
#tailwind utilities;
I tried change the purge to:
['./pages/**/*.{js,ts,jsx,tsx}','../public/components/**/*.{js,ts,jsx,tsx}','../public/components/indexComponents/*.{js,ts,jsx,tsx}']
But I have the same problem!

Custom boxshadow not showing

I'm trying to add a custom shadow to my theme but it's not working, am I missing something? I'm on Svelte. I also added colors which are working fine.
tailwind.config.cjs
/** #type {import('tailwindcss').Config} */
module.exports = {
content: ['./src/**/*.{html,js,svelte,ts}'],
theme: {
colors: {
'dark-purple':'#453F70',
'darker-purple':'#353157',
'light-purple':'#9B22DA',
'medium-purple':'#6721DC',
},
extend: {
boxShadow: {
'neumorphic':"1px 1px 1px 0 rgba(255, 255, 255, 0.3) inset, -2px -2px 2px 0 rgba(0, 0, 0, .4) inset"
}
}
},
plugins: []
};
Everything is looking fine in config file.
You have to use the custom shadow like with this class shadow-neumorphic. Please verify this.
You can see the working code here

CSS Variables are not being applied

I am trying to use CSS variables but something weird is going on.
I declared the variables like this:
:root {
--primary: '#fff';
--black: '#1b1f23';
--gray: '#586069';
--orange: '#f9826c';
--logo: '#fff';
--header: '#24292e';
--search: 'rgba(255; 255; 255; 0.13)';
}
Then I used them like this:
input {
background: var(--search);
}
But for some reason the style is not being applied.
When I hover the mouse over the variable in Chrome Devtools it shows me the correct value, but it doesn't apply.
I'm pretty lost on how to make it work.
Edit:
I'm using React, so this is the render <input />
There are a few problems with your code. The variable values don't need to be a string. And rgba(255; 255; 255; 0.13) should be separated with commas, not semicolons. So that would be rgba(255, 255, 255, 0.13). And the style is being applied; you just can't notice the difference because rgba(255, 255, 255, 0.13) is still white. So the correct CSS for :root would be this:
:root {
--primary: #fff;
--black: #1b1f23;
--gray: #586069;
--orange: #f9826c;
--logo: #fff;
--header: #24292e;
--search: rgba(255, 255, 255, 1);
}
Example:
:root {
--primary: #fff;
--black: #1b1f23;
--gray: #586069;
--orange: #f9826c;
--logo: #fff;
--header: #24292e;
--search: rgba(255, 25, 255, 0.5); /* The color is pink so we can actually see it working */
}
input {
background: var(--search);
}
<input placeholder='Enter Username or Repo...'>

How to render multiple shadows on one element?

For example, how to accomplish
box-shadow: 2px 2px 4px rgba(0, 0, 0, .05), -2px -2px 4px rgba(0, 0, 0, .05);
in react native stylesheet?
I don't think you can, but the hack of wrapping your component with another just for another layer of shadow is the worst hack of the century either:
<div style={{ boxShadow: "2px 2px 4px rgba(0, 0, 0, .05)"}}>
<div style={{ boxShadow: "-2px -2px 4px rgba(0, 0, 0, .05)"}}>
{ content }
</div>
</div>
I created a react component that automatically creates multiple View components for every shadow you need. It is likely to have some quirks, but it worked fine for my situation.
import React from 'react';
import PropTypes from 'prop-types';
import { View } from 'react-native';
import * as _ from 'lodash';
const partitionByKeys = (keys, obj) => {
let pass = {};
let fail = {};
for (const key of Object.keys(obj)) {
if (keys.includes(key)) {
pass[key] = obj[key];
} else {
fail[key] = obj[key];
}
}
return [pass, fail];
};
const innerStyleKeys = [
'padding', 'paddingTop', 'paddingBottom', 'paddingLeft', 'paddingRight',
'paddingHorizontal', 'paddingVertical',
'backgroundColor', 'flexDirection', 'justifyContent', 'alignItems',
'minHeight', 'minHeight',
];
const ShadowView = ({ level = 0, shadows, children, style, ...props }) => {
const shadow = _.head(shadows);
const [innerStyle, outerStyle] = style ? partitionByKeys(innerStyleKeys, style) : [{}, {}];
return (
<View
{...props}
style={{
shadowColor: shadow.color,
shadowOffset: shadow.offset,
shadowOpacity: shadow.opacity,
shadowRadius: shadow.radius,
...(level === 0 ? outerStyle : {}),
...(shadows.length === 1 ? innerStyle : {}),
}}
>
{ shadows.length === 1 ?
children :
<ShadowView level={level + 1} shadows={_.tail(shadows)} style={style}>{children}</ShadowView>
}
</View>
);
};
export default ShadowView;
Usage:
<ShadowView shadows={[{
color: '#FF0000',
opacity: 0.5,
offset: {
width: 0,
height: 10,
},
radius: 60,
}, {
color: '#00FF00',
opacity: 0.5,
offset: {
width: 0,
height: 3,
},
radius: 20,
}]}>...</ShadowView>

Qt Custom User Theming

I am trying to set up a method for theming with external files. Currently, I have a file being read and put into a QString, then being placed inside of "qApp->setStyleSheet(string);, this seems to work,however, when i color the background of a button it doesn't seem to work. The same css works directly inside of qt designer too.
Function:
void SeniorProject::themer(QString theme_name)
{
qDebug() << theme_name;
QString file = QCoreApplication::applicationDirPath()
+ "/themes/" + "default" + "/theme.style";
qDebug() << "file = " + file;
QFile themeFile(file);
QString themeStyle;
if (themeFile.open(QIODevice::ReadOnly))
{
QTextStream in (&themeFile);
themeStyle = in.readAll();
themeFile.close();
}
else
{
qDebug() << "error";
}
qApp->setStyleSheet(themeStyle);
update();
}
CSS File
QPushButton#exit {
color: rgb(220, 0, 0);
border: none;
outline: none;
}
QPushButton#exit:hover {
color: rgb(255, 8, 0);
}
QPushButton#exit:Pressed {
color: rgb(150, 0, 0);
}
QFrame#mainbox QPushButton {
background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 rgba(122,188,255,1), stop: 0.44 rgba(96,171,248,1), stop: 1 rgba(64,150,238,1));
border: .1px outset rgb(122, 188, 255);
border-radius:4px;
}
QFrame#mainbox QPushButton:hover {
background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 rgba(147,201,255,1), stop: 0.44 rgba(133,190,247,1), stop: 1 rgba(90,163,237,1));
border: .1px outset rgb(122, 188, 255);
border-radius:4px;
}
QFrame#mainbox QPushButton:pressed {
background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 rgba(84,169,255,1), stop: 0.44 rgba(66,155,244,1), stop: 1 rgba(45,141,237,1));
border: .1px outset rgb(122, 188, 255);
border-radius:4px;
}
The background in the QPushButtons is my currently problem, the stylesheet loads correctly and updates (I can tell because the borders on the buttons actually change to what I want), but the background does not seem to be working. Can anyone help me? Thanks.
I figured out why the background was not working. If you have the background previously set of the entire widget that is the parent of the item you are trying to style through QT Designer will not be able to have a background when it is not set with QT Designer.

Resources