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

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!

Related

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

Angular Material Heighten Contrast Globally?

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

PostCSS nesting with CSS variables isn't working in Tailwind CSS & Next.js

I am trying to use PostCSS nesting with CSS variables but it doesn't convert CSS variables at all.
Instead it shows Invalid property value in the DOM for CSS Variables.
My tailwind.css file contains a bunch of CSS variables:
tailwind.css
#import 'tailwindcss/base';
#import 'tailwindcss/components';
#import 'tailwindcss/utilities';
#layer base {
:root {
--font-mono: 'Fira Mono, monospace';
--text-1: '12px';
--text-2: '14px';
--colors-black: 'rgba(19, 19, 21, 1)';
--colors-white: 'rgba(255, 255, 255, 1)';
--colors-gray: 'rgba(128, 128, 128, 1)';
--colors-blue: 'rgba(3, 136, 252, 1)';
--colors-red: 'rgba(249, 16, 74, 1)';
--colors-yellow: 'rgba(255, 221, 0, 1)';
--colors-pink: 'rgba(232, 141, 163, 1)';
--colors-turq: 'rgba(0, 245, 196, 1)';
--colors-orange: 'rgba(255, 135, 31, 1)';
--space-1: '4px';
--space-2: '8px';
--space-3: '16px';
--radii-1: '2px';
--radii-2: '4px';
}
pre {
--background: 'hsla(206 12% 89.5% / 5%)';
--text: var('--colors-white');
--syntax1: var('--colors-orange');
--syntax2: var('--colors-turq');
--syntax3: var('--colors-pink');
--syntax4: var('--colors-pink');
--comment: var('--colors-gray');
--removed: var('--colors-red');
--added: var('--colors-turq');
box-sizing: 'border-box';
padding: var('--space-3');
overflow: 'auto';
font-family: var('--font-mono');
font-size: var('--text-2');
line-height: var('--space-3');
whitespace: 'pre';
background-color: var('--background');
color: var('--text');
'& > code': {
display: 'block';
}
'.token.parameter': {
color: var('--text');
}
'.token.tag, .token.class-name, .token.selector, .token.selector .class, .token.function': {
color: var('--syntax1');
}
'.token.attr-value, .token.class, .token.string, .token.number, .token.unit, .token.color': {
color: var('--syntax2');
}
'.token.attr-name, .token.keyword, .token.rule, .token.operator, .token.pseudo-class, .token.important': {
color: var('--syntax3');
}
'.token.punctuation, .token.module, .token.property': {
color: var('--syntax4');
}
'.token.comment': {
color: var('--comment');
}
'.token.atapply .token:not(.rule):not(.important)': {
color: 'inherit';
}
'.language-shell .token:not(.comment)': {
color: 'inherit';
}
'.language-css .token.function': {
color: 'inherit';
}
'.token.deleted:not(.prefix), .token.inserted:not(.prefix)': {
display: 'block';
px: '$4';
mx: '-$4';
}
'.token.deleted:not(.prefix)': {
color: var('--removed');
}
'.token.inserted:not(.prefix)': {
color: var('--added');
}
'.token.deleted.prefix, .token.inserted.prefix': {
userselect: 'none';
}
}
}
My PostCSS Config contains postcss-preset-env already which should support for CSS nesting. I also installed postcss-nested & postcss-css-variables, just in case.
postcss.config.js
module.exports = {
plugins: [
'postcss-import',
'tailwindcss',
'postcss-flexbugs-fixes',
'postcss-nested',
'postcss-css-variables',
[
'postcss-preset-env',
{
autoprefixer: {
flexbox: 'no-2009',
},
stage: 3,
features: {
'custom-properties': false,
'nesting-rules': true,
},
},
],
],
}
Reproduction here → https://github.com/deadcoder0904/postcss-tailwind-next-bug
Run the app & check the DOM to see the CSS variables in the Styles panel which shows Invalid property value.
How can I get CSS variables to work with Tailwind CSS?
The complete solution was to remove quotes & object notation in CSS. I copied the whole thing from CSS-in-JS but forgot to remove quotes & object notation aka :
tailwind.css
#import 'tailwindcss/base';
#import 'tailwindcss/components';
#import 'tailwindcss/utilities';
#layer base {
:root {
--font-mono: 'Fira Mono, monospace';
--text-1: 12px;
--text-2: 14px;
--colors-black: rgba(19, 19, 21, 1);
--colors-white: rgba(255, 255, 255, 1);
--colors-gray: rgba(128, 128, 128, 1);
--colors-blue: rgba(3, 136, 252, 1);
--colors-red: rgba(249, 16, 74, 1);
--colors-yellow: rgba(255, 221, 0, 1);
--colors-pink: rgba(232, 141, 163, 1);
--colors-turq: rgba(0, 245, 196, 1);
--colors-orange: rgba(255, 135, 31, 1);
--space-1: 4px;
--space-2: 8px;
--space-3: 16px;
--radii-1: 2px;
--radii-2: 4px;
}
pre {
--background: hsla(206 12% 89.5% / 5%);
--text: var(--colors-white);
--syntax1: var(--colors-orange);
--syntax2: var(--colors-turq);
--syntax3: var(--colors-pink);
--syntax4: var(--colors-pink);
--comment: var(--colors-gray);
--removed: var(--colors-red);
--added: var(--colors-turq);
box-sizing: border-box;
padding: var(--space-3);
overflow: auto;
font-family: var(--font-mono);
font-size: var(--text-2);
line-height: var(--space-3);
white-space: pre;
background-color: var(--background);
color: var(--text);
& > code {
display: block;
}
.token.parameter {
color: var(--text);
}
.token.tag,
.token.class-name,
.token.selector,
.token.selector .class,
.token.function {
color: var(--syntax1);
}
.token.attr-value,
.token.class,
.token.string,
.token.number,
.token.unit,
.token.color {
color: var(--syntax2);
}
.token.attr-name,
.token.keyword,
.token.rule,
.token.operator,
.token.pseudo-class,
.token.important {
color: var(--syntax3);
}
.token.punctuation,
.token.module,
.token.property {
color: var(--syntax4);
}
.token.comment {
color: var(--comment);
}
.token.atapply .token:not(.rule):not(.important) {
color: inherit;
}
.language-shell .token:not(.comment) {
color: inherit;
}
.language-css .token.function {
color: inherit;
}
.token.deleted:not(.prefix),
.token.inserted:not(.prefix) {
display: block;
px: $4;
mx: -$4;
}
.token.deleted:not(.prefix) {
color: var(--removed);
}
.token.inserted:not(.prefix) {
color: var(--added);
}
.token.deleted.prefix,
.token.inserted.prefix {
userselect: none;
}
}
}
And for some reason, in one of my projects, postcss-preset-env didn't work so I had to use postcss-nested & postcss-css-variables in postcss.config.js.
postcss.config.js
module.exports = {
plugins: [
'postcss-import',
'tailwindcss',
'postcss-flexbugs-fixes',
'postcss-nested',
'postcss-custom-properties',
'autoprefixer',
// [
// 'postcss-preset-env',
// {
// autoprefixer: {
// flexbox: 'no-2009',
// },
// stage: 3,
// features: {
// 'custom-properties': true,
// 'nesting-rules': true,
// },
// },
// ],
],
}
But postcss-preset-env worked in another project with the same config. I have tested it multiple times by cleaning cache, reinstalling dependencies & copy-pasted the same config so I'm pretty sure it's not my project's problem.

Change default border color of outline textfield

I want to change the default border color of an outlined textfield from gray to a darker blue.
<TextField
variant={"outlined"}
placeholder={t('landing_page.code.placeholder')}
onChange={this.onCodeChanged}
value={code}
fullWidth={true}
className={classes.codeInput}
error={code ? code.length < 10 : false}
/>
This is the codeInputclass:
codeInput: {
marginTop: theme.spacing.unit,
},
I have tried overriding the color via theme, but it does not work:
overrides: {
MuiOutlinedInput: {
root: {
borderColor: "#2b303e"
},
notchedOutline: {
borderRadius: "0",
borderWidth: "2px",
borderColor: "#2b303e"
},
},
}
It is still gray as you can see in the image.
I have identified the following css rules as the problem. With disabling this, everything looks fine. I just don't know how to do this
.MuiOutlinedInput-root-148 .MuiOutlinedInput-notchedOutline-155 {
border-color: rgba(0, 0, 0, 0.23);
}
Create a new css class for example:
// app.css
.blueBorder {
}
Add in the border you want and add !important; to overwrite.
// app.css
.blueBorder{
border-radius: 0px!important;
border: 2px solid #2b303e!important;
}
Assign it to your component:
// js / react component
<TextField
variant={"outlined"}
placeholder={t('landing_page.code.placeholder')}
onChange={this.onCodeChanged}
value={code}
fullWidth={true}
className={`blueBorder ${classes.codeInput}`}
/>
Update to show error class
// app.css
.blueBorder{
border-radius: 0px!important;
border: 2px solid #2b303e!important;
}
// Red border to denote error
.blueBorder-error {
border-radius: 0px!important;
border: 2px solid red!important;
}
Use the error class in the components className
condition ? true : false
// js / component
<TextField
variant={"outlined"}
placeholder={t('landing_page.code.placeholder')}
onChange={this.onCodeChanged}
value={code}
fullWidth={true}
className={code.length < 10 ? `blueBorder-error ${classes.codeInput}` : `blueBorder ${classes.codeInput}}
/>

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>

Resources