Tailwind space-x-# does not apply any styles - tailwind-css

I have the following:
<div class="flex flex-row items-center justify-start flex-nowrap space-x-6">
<div>hello</div>
<div>world</div>
</div>
Now the there is no space-x-6 applied between the items. However when I try this in the Tailwind playground it works. Any ideas?
tailwind.config.js:
const defaultTheme = require('tailwindcss/defaultTheme');
module.exports = {
content: ['./src/**/*.{js,ts,jsx,tsx}'],
theme: {
extend: {
animation: {
blob: 'blob 7s infinite',
},
keyframes: {
blob: {
'0%': {
transform: 'translate(0px, 0px) scale(1)',
},
'33%': {
transform: 'translate(30px, -50px) scale(1.1)',
},
'66%': {
transform: 'translate(-20px, 20px) scale(0.9)',
},
'100%': {
transform: 'tranlate(0px, 0px) scale(1)',
},
},
},
fontFamily: {
sans: ['Inter', ...defaultTheme.fontFamily.sans],
mono: ['iAWriter Mono', ...defaultTheme.fontFamily.mono],
},
boxShadow: {
card: '0 0 0.5rem rgba(0, 0, 0, 0.075)',
},
typography: (theme) => ({
DEFAULT: {
css: {
whiteSpace: 'pre-wrap',
figcaption: {
textAlign: 'center',
},
strong: {
fontWeight: theme('fontWeight.medium'),
},
// Image margin is handled by `figure`
img: {
marginTop: null,
marginBottom: null,
borderRadius: theme('borderRadius.lg'),
},
blockquote: {
borderLeftWidth: '2px',
fontStyle: null,
fontWeight: theme('fontWeight.normal'),
borderColor: theme('colors.blue.600'),
},
hr: {
borderTopWidth: '2px',
maxWidth: '12rem',
marginLeft: 'auto',
marginRight: 'auto',
},
'blockquote p:first-of-type::before, blockquote p:last-of-type::after': {
content: 'unset !important',
},
a: {
color: theme('colors.blue.600'),
wordWrap: 'break-word',
fontWeight: theme('fontWeight.normal'),
textDecoration: 'none',
textUnderlineOffset: '0.2em',
'&:hover': {
textDecoration: 'underline',
},
},
'ol > li::before': {
fontFamily: theme('fontFamily.mono').join(', '),
color: theme('colors.gray.400'),
},
'ul > li::before': {
backgroundColor: theme('colors.gray.400'),
},
'.twitter-tweet': {
marginLeft: 'auto',
marginRight: 'auto',
},
code: {
fontWeight: theme('fontWeight.normal'),
background: theme('colors.gray.200'),
color: theme('colors.gray.600'),
borderRadius: theme('borderRadius.lg'),
padding: `0.125rem ${theme('padding.1')}`,
'&::before, &::after': {
content: 'unset !important',
},
},
'[data-nft] *, .opengraph *, .opengraph *:hover': {
margin: '0',
textDecoration: 'none',
borderRadius: 'unset',
},
},
},
lg: {
css: {
'ol > li, ul > li': {
marginTop: '0',
marginBottom: '0',
},
// Image margin is handled by `figure`
img: {
marginTop: null,
marginBottom: null,
},
},
},
}),
},
},
plugins: [require('#tailwindcss/typography'), require('#tailwindcss/line-clamp'), require('#tailwindcss/forms')],
};
UPDATE:
So for the space-x-# class I do a little fancyness:
export function getSpacing(spacing, direction) {
const spacingTailwindClasses = [];
if (typeof direction === 'string') {
spacingTailwindClasses.push(getTailwindSpacingClassname(spacing, direction));
} else {
spacingTailwindClasses.push(getTailwindSpacingClassname(spacing, direction.sOnly || direction.sUp));
if (direction.sUp) {
spacingTailwindClasses.push(`sm:${getTailwindSpacingClassname(spacing, direction.sUp)}`);
if (direction.sOnly) {
spacingTailwindClasses.push(`sm:${getTailwindSpacingClassname('none', direction.sOnly)}`);
}
}
}
const spacingObject = {};
const classes = spacingTailwindClasses.join(' ');
spacingObject[classes] = true;
return spacingObject;
}

Related

customize mui muiCssBaseline with my class

I'm using MUI version 5 and in particular I would like to use, in createTheme, the muiCssBaseLine customization part
createTheme({
palette: {
...
},
...,
MuiCssBaseline: {
styleOverrides: {
... my code
}
},
});
and apply some style to a generic class that I can apply to any mui component.
Therefore I can't be specific and use it under (for example) MuiChip, but it must be generic for any component.
MuiChip: {
// too specific
styleOverrides: {
myClass: {
marginLeft: '1px solid black',
boxShadow: 'none'
}
}
}
I figured this might work, but it doesn't work:
MuiCssBaseline: {
styleOverrides: {
'&.myClass': {
marginLeft: '1px solid black',
boxShadow: 'none',
},
}
},
I also tried
MuiCssBaseline: {
styleOverrides: {
root: {
'&.myClass': {
marginLeft: '1px solid black',
boxShadow: 'none',
},
}
}
},
I also tried some variations:
'& .myClass': {
marginLeft: '1px solid black',
boxShadow: 'none',
},
'myClass': {
marginLeft: '1px solid black',
boxShadow: 'none',
},
myClass: {
marginLeft: '1px solid black',
boxShadow: 'none',
},
but nothing works

Tailwindcss nextjs JIT mode compile error

We are making a project with tailwindcss and it was going good until the clients wanted a "pixel perfect" design which meant that we needed to set every single thing in pixels instead of rem. So instead of adding 1 gajillon classes like h-1px, h-2px ... h-100px, etc. I desided to enable JIT mode and use h-[100px] instead.
The problem is that the compiler keeps compiling, even tough i've changed nothing, and continues to do so, even when i stop the dev server, a process is running on port 3000 (i cannot start the server again, until i stop it).
So.. the question is how to stop this infinite loop of recompialtion
im using:
tailwindcss 2.1.2
tailwindcss/jit 0.1.18
my tw config is this for now, there might be something that is triggering the loop:
const colors = require("tailwindcss/colors");
const defaultTheme = require("tailwindcss/defaultTheme");
module.exports = {
important: true,
mode: "jit",
//content: ["./src/**/*.{js,ts,jsx,tsx,liquid}"],
purge: {
enabled: false,
content: [
"./src/components/**/*.{js,ts,jsx,tsx,html}",
"./src/pages/**/*.{js,ts,jsx,tsx,html}",
"./src/components/*.{js,ts,jsx,tsx,html}",
"./src/pages/*.{js,ts,jsx,tsx,html}",
"./src/**/*.{js,ts,jsx,tsx,html}",
"./src/*.{js,ts,jsx,tsx,html}",
"./**/*.{js,ts,jsx,tsx,html}",
"./*.{js,ts,jsx,tsx,html}",
],
options: {
safelist: {
deep: [/bg$/, /col$/, /row$/, /text$/],
greedy: [/bg$/, /col$/, /row$/, /text$/],
},
},
},
darkMode: false, // or 'media' or 'class'
theme: {
extend: {
opacity: { 13: "0.13" },
boxShadow: {
head: "0 0 6px 0 rgba(0, 0, 0, 0.36)",
search: "0 9px 34px 0 rgba(0, 0, 0, 0.19)",
},
gridTemplateRows: {
// Simple 8 row grid
"8-em": "repeat(8, minmax(0, 5em))",
8: "repeat(8, minmax(0, 1fr))",
},
backgroundImage: {
"gradient-radial": "radial-gradient(var(--gradient-color-stops))",
},
fontFamily: {
sans: ["Stolzl", ...defaultTheme.fontFamily.sans],
},
fontSize: {
"2.5xl": "1.6rem",
0.8: "0.8rem",
xxs: "0.6rem",
micro: "0.4rem",
nano: "0.2rem",
},
zIndex: {
0: 0,
10: 10,
20: 20,
30: 30,
40: 40,
50: 50,
25: 25,
50: 50,
60: 60,
75: 75,
100: 100,
200: 200,
auto: "auto",
},
colors: {
// old primary blue #005a94
// old lightblue #f4f7fd
//TODO change colors
primaryLightBlue: "#f1f7fb",
primaryBlue: process.env.NEXT_PUBLIC_PRIMARY || "#1579B9",
primaryYellow: process.env.NEXT_PUBLIC_ACCENT || "#FDC607",
},
radialGradientColors: {
// defaults to {}
"blue-blue": ["#0171BA", "#005a94"],
"lb-lb": ["#3776dd", "#215dc0"],
},
animation: {
spin3d: "spin3d 6s linear infinite ",
},
keyframes: {
spin3d: {
"0%": {
transform: "perspective(1000px) rotateY(0deg)",
filter: "brightness(100%)",
},
"25%": { filter: "brightness(60%)" },
"50%": {
filter: "brightness(100%)",
},
"75%": { filter: "brightness(60%)" },
"100% ": {
transform: "perspective(1000px) rotateY(360deg)",
filter: "brightness(100%)",
},
},
},
},
},
plugins: [
require("tailwindcss-gradients"),
require("#tailwindcss/line-clamp"),
function ({ addComponents }) {
addComponents({
".container": {
maxWidth: "100%",
//640
"#screen sm": {
maxWidth: "640px",
},
//768
"#screen md": {
maxWidth: "768px",
},
//1024
"#screen lg": {
maxWidth: "1024px",
},
//1280
"#screen xl": {
maxWidth: "1280px",
},
//1280
"#screen 2xl": {
maxWidth: "1280px",
},
},
".container2": {
maxWidth: "100%",
//640
"#screen sm": {
maxWidth: "640px",
},
//768
"#screen md": {
maxWidth: "640px",
},
//1024
"#screen lg": {
maxWidth: "768px",
},
//1280
"#screen xl": {
maxWidth: "1118px",
},
//1280
"#screen 2xl": {
maxWidth: "1118px",
},
},
});
},
],
variants: {
display: ["group-hover"],
extend: {
backgroundColor: ["odd"],
borderColor: ["odd", "even", "active"],
borderOpacity: ["odd", "even", "active"],
borderWidth: ["odd", "even", "active"],
borderStyle: ["odd", "even", "active"],
display: ["disabled", "responsive"],
opacity: ["disabled"],
cursor: ["disabled", "hover"],
backgroundColor: ["disabled"],
borderWidth: ["hover,focus"],
transform: ["hover", "focus", "group-hover"],
scale: ["hover", "focus", "group-hover"],
width: ["hover", "group-hover"],
height: ["hover", "group-hover"],
padding: ["hover", "focus"],
},
},
};
I solved it, for anyone who has the same problem
first i had to uninstall #tailwindcss/jit dependency, as it is included in tailwind css v2.2.7+
then i had to configure postcss to use 'tailwindcss' instead of '#tailwindcss/jit',
then i changed my script to include TAILWIND_MODE=watch before my tailwind build script, and added --watch to the end
"tailwind:build": "TAILWIND_MODE=watch tailwind build -i ./src/styles/tailwind.css -o ./src/styles/styles.css --watch ",
and everything started working, no infinite loops!

React Material-UI Table how to set "border-spacing" for Table to have separated rows

I need separate Material-UI Collapsi Table Rows
https://material-ui.com/components/tables/#CollapsibleTable.tsx
const theme = createMuiTheme({
overrides: {
MuiTable: {
root: {
borderCollapse: "separate",
borderSpacing: "0 10px",
marginTop: "-10px"
}
},
MuiTableRow: {
root: {
borderRadius: 40,
border: "2px solid",
backgroundColor: "green",
},
},
},
});
To be something like this with spacing in between.
Best way is by setting the Theme, but Ill be glad for any advice.
It is useless to set borderRadius to MuiTableRow it is needed to use first-child last-child and MuiTableCell.
MuiTableCell: {
root: {
backgroundColor: "#fff",
paddingTop: 0,
paddingBottom: 0,
paddingLeft: "0.2rem",
paddingRight: "0.2rem",
borderBottom: 0,
overflow: "hidden",
textOverflow: "ellipsis",
"&:first-child": {
borderTopLeftRadius: "0.7rem",
borderBottomLeftRadius: "0.7rem"
},
"&:last-child": {
borderTopRightRadius: "0.7rem",
borderBottomRightRadius: "0.7rem"
}
}
},

Material-UI change margin of FormHelperText when FormControl only for Select

I currently need to add marginLeft of 8px to FormHelperText. But havent been able to do it on the MuiInput formControl rule or in MuiSelect.
This is the React code:
<FormControl error className={classes.margin} fullWidth>
<InputLabel className={classes.label} id="demo-error-select-label">
Error select
</InputLabel>
<Select
labelId="demo-error-select-label"
id="demo-error-select"
value={option}
onChange={handleChange}
IconComponent={() => <Icon24UtilityChevron component="select" height="20px" />}>
<MenuItem value="">Select</MenuItem>
<MenuItem value={1}>Option1</MenuItem>
<MenuItem value={2}>Option2</MenuItem>
<MenuItem value={3}>Option3</MenuItem>
</Select>
<FormHelperText>Error</FormHelperText>
</FormControl>
This is the MuiSelect object that override default styles with createMuiTheme (ommited for briefly explanation):
const MuiSelect = {
select: {
backgroundColor: selectColors.background,
padding: '12px 16px 12px 16px !important',
fontSize: '18px',
borderRadius: 12,
borderWidth: '1px',
borderStyle: 'solid',
borderColor: selectColors.border,
'&:focus': {
borderRadius: 12,
borderWidth: '2px',
borderStyle: 'solid',
borderColor: selectColors.borderFocus,
},
},
selectMenu: {
'&:hover:not(.Mui-disabled):not(.Mui-error)': {
backgroundColor: selectColors.hoverBackground,
},
},
};
This is the MuiInput object that override default styles with createMuiTheme (ommited for briefly explanation):
This is an example of the FormControl being created (need to move the Error label 8px to the left):
[![enter image description here][1]][1]
const MuiInput = {
formControl: {
'label + &': {
marginTop: '2px',
},
},
root: {
borderRadius: '12px',
borderColor: inputColors.inputBorder,
borderWidth: '1px',
borderStyle: 'solid',
'&$error': {
borderColor: inputColors.inputError,
},
'&:focus-within': {
borderColor: inputColors.inputBorderFocus,
},
'& svg': {
marginRight: '16px',
},
},
input: {
backgroundColor: inputColors.inputBackground,
caretColor: inputColors.inputCaret,
paddingLeft: '8px',
paddingRight: '8px',
color: inputColors.inputText,
borderRadius: '12px',
},
multiline: {
paddingTop: '0px',
paddingBottom: '0px',
},
underline: {
'&:hover:not(.Mui-disabled):before': { borderBottomWidth: '0px' },
'&:before': { borderBottomWidth: '0px' },
'&:after': { borderBottomWidth: '0px' },
},
};
Take a look at the visual example of the code (the lower error text is the one that needs to be moved):
I could solve it by using ~ selector. Code:
const MuiInput = {
formControl: {
'label + &': {
marginTop: '2px',
},
'& ~ p': {
marginTop: '4px',
marginLeft: '8px',
},
},
...

Override of Button component doesn't change the hover color

I am trying to change the color of the all the Button's in the project by overriding the theme css. The color of the button has changed but hover color is still transparent, how can I override it ?
Is there any other way to this apart from adding a class to each of my buttons.
Also shouldn't all the variants of a button follow the css of the root?
const theme = createMuiTheme({
palette: {
primary: {
light: '#35C37D',
main: '#35C37D',
dark: '#35C37D',
// contrastText: will be calculated to contrast with palette.primary.main
},
secondary: {
light: '#35C37D',
main: '#35C37D',
// dark: will be calculated from palette.secondary.main,
contrastText: '#35C37D',
},
// error: will use the default color
},
overrides: {
MuiButton: {
// Name of the rule
root: {
// Some CSS
background: 'rgba(53, 195, 125, 100)',
borderRadius: 0,
border: 0,
colorInherit: '#fff',
color: 'white',
height: 40,
padding: '0 30px',
boxShadow: '4px 9px 26px 0 rgba(16,124,71,0.10)',
'&:hover': {
textDecoration: 'none',
backgroundColor: '#35C37D',
// Reset on touch devices, it doesn't add specificity
'#media (hover: none)': {
backgroundColor: '#35C37D',
},
},
},
textPrimary: {
color: '#fff',
},
textSecondary: {
color: '#fff',
},
contained: {
color: '#fff',
},
containedPrimary: {
color: '#fff',
},
containedSecondary: {
color: '#fff',
},
raised: {
color: '#fff',
},
colorInherit: {
color: '#fff',
},
},
},
typography: {
fontFamily: 'azo-sans-web',
// The default font size of the Material Specification.
fontSize: 14, // px
fontWeightLight: 300,
fontWeightRegular: 400,
fontWeightMedium: 500,
// Tell Material-UI what's the font-size on the html element.
// 16px is the default font-size used by browsers.
htmlFontSize: 16,
},
});
I figured it out.
Here is the code sandbox if anyone cares https://codesandbox.io/s/y2qyk9rn4x
Just need to add this for each variant:
outlined: {
"&:hover": {
backgroundColor: "#35C37D"
}
},

Resources