styled-components

React SVG component as background-image to div

女生的网名这么多〃 提交于 2019-12-10 09:23:06
问题 I am trying to get styled-components to take an SVG that is a react component and set it as a background-image but I get the error: TypeError: Cannot convert a Symbol value to a string SVG component code: import React from "react"; const testSVG = props => { return ( <svg version="1.1" id="Layer_1" x="0px" y="0px" viewBox="0 0 193.3 129.7"> <g> <g> <g> <path fill="#434343" class="st0" d="M162.4,116c-4.6,7.5-15.6,13.6-24.4,13.6H16c-8.8,0-12.3-6.2-7.7-13.7c0,0,4.6-7.7,11.1-18.4 c4.4-7.4,8.9-14

How to apply styles to react-burger-menu button with styled-components?

倾然丶 夕夏残阳落幕 提交于 2019-12-08 17:15:32
问题 I would like to use styled-components in a React app to create a menu component that contains the styles in the same file thus making it very modular. I'm using react-burger-menu for the menu. Everything works correctly if I wrap BurgerMenu in a styled div like so (styles copied from react-burger-menu README.md): import React from 'react'; import { slide as BurgerMenu } from 'react-burger-menu'; import styled from 'styled-components'; const StyledBurgerMenu = styled.div` /* Position and

Styled component with access to React component state?

丶灬走出姿态 提交于 2019-12-08 08:22:51
问题 How can I get a styled component to render different css rules depending on the state of the React component in which it is rendered? The below does not work: class Container extends React.Component<ContainerProps, ContainerState> { constructor(props: ContainerProps) { super(props); this.state = { highlight: true, dark: false }; } OuterWrapper = styled.div` display: inline-block; padding: 20px; ${this.state.dark && ` background-color: 'gray'; `}; `; return ( <this.OuterWrapper> ... </this

With Styled Components how to only apply a style to small devices?

喜欢而已 提交于 2019-12-08 05:17:38
问题 My styled components theme currently includes: const breakpoints = { medium: '640px', large: '1080px', }; const MyContainer = styled.div` // Default mobile stylings ${({ theme }) => theme.media.medium` // CSS goes here `} ${({ theme }) => theme.media.large` // CSS goes here `} `; In my react component, I need an onClick handler for an item but ONLY when the breakpoint is small, not medium or large. In my react component, for some reason, I can not figure this out... const MyC = class extends

Typescript styled-component error: “Type '{ children: string; }' has no properties in common with type 'IntrinsicAttributes'.”

风流意气都作罢 提交于 2019-12-08 05:11:29
问题 Getting a typescript error on my styled-component Type '{ children: string; }' has no properties in common with type 'IntrinsicAttributes'.ts(2559) import React from 'react' import { NotificationSuccess, NotificationError } from '../../styles' interface IProps { error?: boolean; message: string; } export const Notification = (props: IProps) => { const Note = () => props.error ? NotificationError : NotificationSuccess; // Error happens on <Note> return (<Note>{props.message}</Note>); } And the

@for loops in styled-components

谁说我不能喝 提交于 2019-12-07 04:08:19
问题 I am trying to find a method in the styled-components documentation to create a loop. For example can I achieve this scss loop in styled-components? @for $i from 0 through 20 { #loadingCheckCircleSVG-#{$i} { animation: fill-to-white 5000ms; animation-delay: ($i - 1.5) * 1s; fill: white; opacity: 0; } } Is it possible? 回答1: We don't have support for iteration syntaxes from scss at this time. However, since styled-components accepts JS interpolations, you can just write a simple JS function to

What is the purpose of template literals (backticks) following a variable definition in ES6?

只谈情不闲聊 提交于 2019-12-06 16:44:38
问题 In GraphQL you can write something like this to define a query: const USER_QUERY = gql` { user(id: 2) { name } } ` In styled components you can define a styled component like this: const Button = styled.button` background-color: papayawhip; ` What is this syntax? I know with template literals you can sub in variables with this syntax: ${foo} but I have never seen this used. Any guidance would be appreciated. 回答1: These are tagged template literals. The part before the backpacks is a reference

How to easily inspect styled-components using dev tools?

余生颓废 提交于 2019-12-05 22:08:50
问题 I am using styled-components in a React project. When the components are rendered in the browser they are assigned a randomly generated classname, for example: <div class="sc-KSdffgy oPwefl"> This class name does not help me identify from which component the <div> came from, so is there a way to do this easily? P.s. currently I am adding attrs to my styled components so that I can recognise them in dev tools, for example: const Foo = styled.div.attrs({ 'data-id': 'foo' })` ... `; 回答1: That's

React SVG component as background-image to div

痴心易碎 提交于 2019-12-05 14:40:00
I am trying to get styled-components to take an SVG that is a react component and set it as a background-image but I get the error: TypeError: Cannot convert a Symbol value to a string SVG component code: import React from "react"; const testSVG = props => { return ( <svg version="1.1" id="Layer_1" x="0px" y="0px" viewBox="0 0 193.3 129.7"> <g> <g> <g> <path fill="#434343" class="st0" d="M162.4,116c-4.6,7.5-15.6,13.6-24.4,13.6H16c-8.8,0-12.3-6.2-7.7-13.7c0,0,4.6-7.7,11.1-18.4 c4.4-7.4,8.9-14.7,13.3-22.1c1.1-1.8,6.1-7.7,6.1-10.1c0-7.3-15-24.9-18.5-30.7C13.5,23.6,8.3,14.9,8.3,14.9 C3.7,7.4,7.2,1

@for loops in styled-components

不打扰是莪最后的温柔 提交于 2019-12-05 11:44:38
I am trying to find a method in the styled-components documentation to create a loop. For example can I achieve this scss loop in styled-components? @for $i from 0 through 20 { #loadingCheckCircleSVG-#{$i} { animation: fill-to-white 5000ms; animation-delay: ($i - 1.5) * 1s; fill: white; opacity: 0; } } Is it possible? We don't have support for iteration syntaxes from scss at this time. However, since styled-components accepts JS interpolations, you can just write a simple JS function to make the desired CSS and drop it in. import styled, { css } from "styled-components"; function createCSS() {