Questions tagged [styled-components]

styled-components is a JavaScript library for styling React applications. It removes the mapping between styles and components, and lets you write actual CSS augmented with JavaScript.

styled-components is an open source project developed by Glen Maddern and Max Stoiber that aims to make styling component-based systems, right now solely focussed on React, easier.


This is what using styled-components looks like:

import React from 'react';
import styled from 'styled-components';

// Create a <Title> react component that renders an <h1> which is
// centered, palevioletred and sized at 1.5em
const Title = styled.h1`
  font-size: 1.5em;
  text-align: center;
  color: palevioletred;
`;

// Create a <Wrapper> react component that renders a <section> with
// some padding and a papayawhip background
const Wrapper = styled.section`
  padding: 4em;
  background: papayawhip;
`;

These two variables, Title and Wrapper, are now a React components you can render like any other React component:

<Wrapper>
  <Title>Hello World, this is my first styled component!</Title>
</Wrapper>

The above code rendered in the browser(Live demo)

For more information and examples see the official documentation!

4586 questions
1
vote
1 answer

No files matching the pattern were found with STYLELINT

I just installed STYLELINT and I'm following the documentation, but I encountered the following problem: $ npx stylelint --config ./stylelintrc './**/*.tsx' Error: No files matching the pattern "'./src/**/*.tsx'" were found. at standalone…
THIAGO DE BONIS
  • 760
  • 7
  • 22
1
vote
0 answers

Why is my styled component no longer accepting children?

I have a StyledGrid component declared as follows: import PropTypes from 'prop-types'; import styled from "styled-components"; import { Grid, GridColumn, GridToolbar } from '@progress/kendo-react-grid'; import { colors, Theme } from…
1
vote
0 answers

Animation with styled-components in react

I want to run the animation in the last ten seconds of a timer.First, I tried with keyframes and it was how I wanted but this time if I do not refresh the page animation did not work. I commented it and tried another way which is below: useEffect(()…
1
vote
1 answer

Does a component created with styled-components destroy the component when its style changes, rather than just modifying the component's style?

I have created two boxes, one with the css module scheme and the other with styled-components. However, the transition will fail on the box created with styled-components, but not on the box created with the css modules scheme. I have added a button…
bearbaba
  • 23
  • 3
1
vote
1 answer

How to change styles of react component using styled components

I have this React component which is a simple button component: const Button = ({ children }) => ; I tried to pass the above component inside a styled in order to try to change its styles like this: const StyledButton =…
Why u do dis
  • 418
  • 4
  • 15
1
vote
2 answers

Typescript and defaultProps on a styled component

I have the following styled component: import styled from "styled-components" import { rem } from 'polished'; import theme from '../../theme'; type ButtonType = { intent?: keyof typeof theme.button; }; const Button =…
JoeTidee
  • 24,754
  • 25
  • 104
  • 149
1
vote
1 answer

Getting "at-rule or selector expectedts-styled-plugin(9999)" error in style component with two interpolation strings

I keep getting this error on styled components at-rule or selector expectedts-styled-plugin(9999), I looked on the internet and can't find any fix that's not a workaround. anyone had the same problem and managed to solve it?
giosan
  • 291
  • 1
  • 4
  • 15
1
vote
0 answers

React Native Gradient Background on Condition

Using: React Native - Styled Components - Linear Gradient Hi so normally this is what I do for gradient backgrounds: import Gradient from 'react-native-linear-gradient'; export const GradientBGNormal = styled(Gradient).attrs({ colors:…
Parsa
  • 111
  • 3
  • 14
1
vote
1 answer

transition effect is not working for mobile menu in react js with styled components

I am trying to build a mobile menu with the effect that it slides in from the right side when the button is clicked. The sliding is working fine but it opens abruptly and closes too as the transition is not having any effect on it. In the inspect…
1
vote
0 answers

Style-editable for selected box of text on webpage?

I'm building a web app that should have a place to allow users to directly edit the style of the text area they selected For example: When a user select a text area, a small box of style options need to appear on the top-bottom, and user can use it…
Tobey Tran
  • 61
  • 1
  • 4
1
vote
1 answer

styled-components doesn't work with material-ui

my question is what is the different between this two { styled }?? import { styled } from "@mui/system"; and import styled from "styled-components"; --------------------------- hi friends, i am using material-ui with reactjs to create a website,…
Alan Hasan
  • 15
  • 1
  • 6
1
vote
0 answers

Adding transform property to background-image in Styled Component

Using Styled Components with React - I'm using props to update my properties based on their boolean values. props.isEnabled && css` display: inline-block; vertical-align: middle; background-image:…
cts
  • 908
  • 1
  • 9
  • 30
1
vote
1 answer

Reusable styled components (pseudo element) with logic

I've written some shared style to be used across different components, how can I change the value of left or width based a passed value or boolean logic so the values can be more dynamic? And if possible, I don't want it passed as a prop in the…
calebo
  • 3,312
  • 10
  • 44
  • 66
1
vote
2 answers

React Material UI v5 styled with TypeScript

Styled typography accepts all the default typography props. When I add between styled() and the style, it also accepts extra props. const StyledTypography = styled(Typography)({}) My question is: when I render the styled…
1
vote
0 answers

What's the benefit of using StyledComponent in React-Native?

I have seen in many projects that people use StyledComponet for RN, and to be honest, I can't see any benefit of using StyledComponent over StyleSheet for RN. These are the main pains that devs can face while using StyledComponent in RN: You use…
Hamid
  • 1,948
  • 4
  • 25
  • 38