We're a place where coders share, stay up-to-date and grow their careers.
I'm trying to use component selectors in my emotion styles. Did you have any luck doing so?
For example, I have this OnOffSwitch component which has some child elements:
OnOffSwitch
const OnOffWrapper = styled.div` display: inline-block; ${props => props.isChecked ? ` ${OnOffTrack} { background-color: ${props.color}; border: 1px solid ${props.color}; } ${OnOffHandle} { transform: none; background-color: ${props.color}; } ` : ` ${OnOffTrack} { background-color: transparent; border: 1px solid ${colors.silver}; } ${OnOffHandle} { transform: translateX(-100%); background-color: ${colors.silver}; } `} `;
These styles (anything below display: inline-block;) are being ignored now.
display: inline-block;
I've found this, but there's no mention of how to achieve this with Vite: github.com/emotion-js/emotion/issu... Also this, which throws an error immediately ("Uncaught SyntaxError: missing ) after argument list"): stackoverflow.com/questions/614352...
Here's my full vite.config.js (I use Vite in a Rails app):
vite.config.js
import react from '@vitejs/plugin-react'; // import ViteReact from '@vitejs/plugin-react-refresh'; import { defineConfig } from 'vite'; import Environment from 'vite-plugin-environment'; // import eslintPlugin from 'vite-plugin-eslint'; import FullReload from 'vite-plugin-full-reload'; import RubyPlugin from 'vite-plugin-ruby'; export default defineConfig({ esbuild: { jsxFactory: 'jsx', jsxInject: `import { jsx } from '@emotion/react'`, }, plugins: [ // eslintPlugin(), react({ jsxImportSource: '@emotion/react', babel: { plugins: ['@emotion/babel-plugin'], }, }), Environment({ CLOUDINARY_API_KEY: null, CLOUDINARY_CLOUD_NAME: null, GOOGLE_MAP_API_KEY: null, INTERCOM_APP_ID: null, MAPBOX_API_KEY: null, STRIPE_PUBLISHABLE_KEY: null, }), RubyPlugin(), FullReload(['config/routes.rb', 'app/views/**/*'], { delay: 200 }), // ViteReact(), ], resolve: { alias: [ { find: /^react-mapbox-gl/, replacement: 'react-mapbox-gl/lib', }, ], }, });
@vfonic I just spent the last few hours trying to debug this exact scenario! Did you ever find a solution?
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
I'm trying to use component selectors in my emotion styles. Did you have any luck doing so?
For example, I have this
OnOffSwitch
component which has some child elements:These styles (anything below
display: inline-block;
) are being ignored now.I've found this, but there's no mention of how to achieve this with Vite: github.com/emotion-js/emotion/issu...
Also this, which throws an error immediately ("Uncaught SyntaxError: missing ) after argument list"):
stackoverflow.com/questions/614352...
Here's my full
vite.config.js
(I use Vite in a Rails app):@vfonic I just spent the last few hours trying to debug this exact scenario! Did you ever find a solution?