Svelte + Tailwind: "Semicolon or block is expected" - tailwind-css

I have a Svelte project using Tailwind, with this style in a component:
<style global lang="postcss">
input {
#apply block border-black border-2 mb-4 p-2 outline-none focus:border-blue-500;
}
</style>
The error that I'm getting, caused by the focus: class:
Semicolon or block is expected
My postcss.config.cjs file:
import tailwind from 'tailwindcss'
import tailwindConfig from './tailwind.config.cjs'
import autoprefixer from 'autoprefixer'
export default {
plugins: [tailwind(tailwindConfig), autoprefixer]
}
tailwind.config.cjs:
/** #type {import('tailwindcss').Config} */
module.exports = {
theme: {
extend: {},
},
plugins: [],
content: ["./index.html", './src/**/*.{svelte,js,ts}'], // for unused CSS
variants: {
extend: {},
},
darkMode: 'media', // or 'media' or 'class'
}
vite.config.js:
import postcss from './postcss.config.cjs'
import { defineConfig } from 'vite'
import { svelte } from '#sveltejs/vite-plugin-svelte'
// https://vitejs.dev/config/
export default defineConfig({
plugins: [svelte()],
css: {
postcss
}
})

Related

The dark: class does not exist. If dark: is a custom class, make sure it is defined within a #layer directive

I am using tailwindcss version 3.2.6.
I tried this in different ways but it didn't work.
After trying it in VScode I'm getting an error like this-
The `dark:` class does not exist. If `dark:` is a custom class, make sure it is defined within a `#layer` directive.
When I try to add this in global.css
#tailwind base;
#tailwind components;
#tailwind utilities;
#layer base {
body {
#apply max-w-2xl mx-auto px-4 bg-white text-black;
#apply dark: bg-black dark:text-white
}
}
tailwind.config.js
/** #type {import('tailwindcss').Config} */
module.exports = {
content: [
"./src/**/*.{js,ts,jsx,tsx}"
],
darkMode: "class",
theme: {
extend: {
fontFamily: {
"sans": ['var(--font-rubik)']
}
}
},
plugins: [require("daisyui")],
}
app.tsx
import "#/styles/globals.css"
import type { AppProps } from "next/app";
import { ThemeProvider } from "next-themes";
import { rubik } from "#/Fonts";
export default function App({ Component, pageProps }: AppProps) {
return (
<ThemeProvider attribute="class">
<main className={`${rubik.variable} font-sans`}>
<Component {...pageProps} />
</main>
</ThemeProvider>
)
}
Why I am facing that error?
dark: bg-black is invalid. It should be dark:bg-black without the space.

Tailwind: modify classes dynamically for Vue app

I have a Vue3 application with Tailwinds configured in tailwind.config.js
Is it possible to dynamically change the value of a preconfigured class from tailwind.config.js ?
For example:
tailwind.config.js:
const defaultTheme = require("tailwindcss/defaultTheme");
module.exports = {
purge: ["./index.html", "./src/**/*.{vue,js,ts,jsx,tsx}"],
darkMode: false, // or 'media' or 'class'
theme: {
extend: {
colors: {
base: {
DEFAULT: "#6e0147",
},
},
fontFamily: {
sans: ["Interstate", "Inter var", ...defaultTheme.fontFamily.sans],
},
},
},
variants: {
extend: {
ringWidth: ["hover", "active"],
ringColor: ["hover", "active"],
ringOpacity: ["hover", "active"],
ringOffsetWidth: ["hover", "active"],
ringOffsetColor: ["hover", "active"],
},
},
plugins: [],
};
VueComponent.vue :
<template>
<div class="text-base">text here</div>
</template>
<script>
export default {
.....
mounted(){
tailwind.config.colors.base = "#00000" // change tailwind color of class somehow
}
}
</script>
In your tailwind.css add a CSS variable called --text-color-base (you could add multiple) in the base theme and also in theme-1:
#tailwind base;
#tailwind components;
#tailwind utilities;
#layer base{
:root{
--text-color-base:#6e0147;
}
.theme-1{
--text-color-base:#000000;
}
}
in tailwind.config.js extend the textColor field in the theme option with skin key which will contain the different variable for your text color :
theme: {
extend: {
textColor:{
skin:{
base:"var(--text-color-base)"
}
},
colors: {
base: {
DEFAULT: "#6e0147",
},
},
fontFamily: {
sans: ["Interstate", "Inter var", ...defaultTheme.fontFamily.sans],
},
},
then you could use it like class="text-skin-base", to apply the theme-1 add the class theme-1 to the root element like :
<div class="theme-1">
<h1 class="text-skin-base">text here</h1>
...
</div>
then in your script you could bind the root class to a property and you update in the script :
<div :class="myTheme">
<h1 class="text-skin-base">text here</h1>
...
</div>
<script>
export default {
.....
data(){
return{
myTheme:''
}
},
mounted(){
this.myTheme="theme-1"
}
}
</script>

Style root element using css file, but not working

I have the entry component in reactjs:
import React from "react"
import ReactDOM from 'react-dom';
import App from "./js/components/App.js"
import './index.css';
ReactDOM.render(<App />, document.getElementById('root'));
I am trying to style in the root element inside of my css file, index.css:
#root {
background-color: brown;
height:100vh;
width:100vh;
}
The background though is not brown. When looking at the styling the browser renders I cannot see any of these attributes being applied to the root element.
This is my webpack config:
const HtmlWebPackPlugin = require("html-webpack-plugin");
module.exports = {
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
use: {
loader: "babel-loader"
}
},
{
test: /\.html$/,
use: [
{
loader: "html-loader"
}
]
},
{
test: /\.css$/,
use: ['css-loader'],
},
]
},
plugins: [
new HtmlWebPackPlugin({
template: "./src/index.html",
filename: "./index.html"
})
]
};
It is as if it is not loading the index.css file at all.
You cannot style the #root of your app. Just style the className of <App /> component, for example:
const App = () => (
<div className="app>
// ...
</div>
)
css file:
.app {
background-color: #ffffff;
background-color: brown;
height:100vh;
width:100vh;
}
When using webpack, i think you have to specify your entry points of your css/js files like this...
entry: [
"./src/js/index.js",
"./src/sass/style.scss",
],
output: {
filename: "bundle.js",
path: path.resolve(__dirname, 'assets/js')
},
module: {
rules: [
/* you code here */
...
...

css modules not working even after ejecting create-react-app

I ejected my create-react-app in order to use css modules. I modified my webpack.config.dev.js from
{
test: /\.css$/,
use: [
require.resolve('style-loader'),
{
loader: require.resolve('css-loader'),
options: {
importLoaders: 1,
modules: true, //added this
localIdentName: "[name]__[local]___[hash:base64:5]" //added this
},
},
{
loader: require.resolve('postcss-loader'),
options: {
// Necessary for external CSS imports to work
// https://github.com/facebookincubator/create-react-app/issues/2677
ident: 'postcss',
plugins: () => [
require('postcss-flexbugs-fixes'),
autoprefixer({
browsers: [
'>1%',
'last 4 versions',
'Firefox ESR',
'not ie < 9', // React doesn't support IE8 anyway
],
flexbox: 'no-2009',
}),
],
},
},
],
}
Then I tried to uss css modules in one of my components
import React, { Component } from 'react';
import styles from './sidebar.css';
class MenuPanel extends Component {
render() {
return (
<div>
<div className={styles.navbarSide}>
<div className="tessact-logo"></div>
<div className="navbar-item active">
<a className="navbar-item-link"><span className="fa fa-comment"></span> TRIVIA</a>
</div>
But className navbarSide didn't get applied to div. I see no className for that particular div. What am I doing wrong? Ideally that div should have got className navbarSide.
just add import { StyleSheet } from 'react-native';
import React, { Component } from 'react';
import { StyleSheet } from 'react-native';
import styles from './sidebar.css';
class MenuPanel extends Component {
render() {
return (
<div>
<div className={styles.navbarSide}>
<div className="tessact-logo"></div>
<div className="navbar-item active">
<a className="navbar-item-link"><span className="fa fa-comment"></span> TRIVIA</a>
</div>

React css not loading properly

I used create-react-app to create a very simple app. But the css is not working for me. Here's my code
# Test.css
.h1 {
color: white;
}
# Test.jsx
import React, { Component } from 'react';
import styles from './Test.css';
class Test extends Component {
render() {
return (
<div>
<h1 className={styles.h1}>Test!</h1>
</div>
)
}
}
export default Test;
The color of my h1 is still black not white. Any help will be appreciated!
# Test.css
.h1 {
color: white;
}
# Test.jsx
import React, { Component } from 'react';
import styles from './Test.css';
class Test extends Component {
render() {
return (
<div>
<h1 className={styles.h1}>Test!</h1>
</div>
)
}
}
export default Test;
In the project that I’m adding CSS Modules to we already have one loader defined for our JavaScript:
module: {
loaders: [{
test: /\.js$/,
loaders: ['react-hot', 'babel'],
include: path.join(__dirname, 'src')
}`enter code here`
}
webpack config
{
test: /\.css$/,
loader: 'style-loader'
}, {
test: /\.css$/,
loader: 'css-loader',
query: {
modules: true,
localIdentName: '[name]__[local]___[hash:base64:5]'
}
}

Resources