styled-components

How to correctly define a reference (React.RefObject<StyledComponentClass>) for styled-components (for TypeScript)?

牧云@^-^@ 提交于 2019-12-05 02:01:46
问题 How to correctly define a reference for styled-components? I wrote the following test code. This is a refined code, unlike the previous one (How to correctly define a reference (React.RefObject) for styled-components (for TypeScript)?). Added reference type StyledComponentClass< {}, any> . import React, {Component, RefObject, ReactNode} from 'react'; import styled, {StyledComponentClass} from 'styled-components'; type TModalShadowContainer = StyledComponentClass<{}, any>; const

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

浪尽此生 提交于 2019-12-04 23:47:42
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. These are tagged template literals . The part before the backpacks is a reference to a function that will be called to process the string. The function is passed the variables (the ${}

Using styled components with props and typescript

痞子三分冷 提交于 2019-12-04 09:19:40
问题 I'm trying to integrate typescript into our project and so far I stumbled upon one issue with styled-components library Consider this component import * as React from "react"; import styled from "styled-components/native"; import { TouchableOpacity } from "react-native"; // -- types ----------------------------------------------------------------- // export interface Props { onPress: any; src: any; width: string; height: string; } // -- styling ------------------------------------------------

You should not use Route or withRouter() outside a Router when using react-router 4 and styled-component in react

怎甘沉沦 提交于 2019-12-03 22:05:20
I'm trying to build my first portfolio website and got stuck in routing using react-router-dom 4.2.2 and styled-components 2.2.3. error message: You should not use Route or withRouter() outside a Router I also try using Link instead of NavLink but got error too( You should not use Link outside a Router ) Someone help me please. navigationBar.js import React, { Component } from 'react'; import { NavigationContainer, NavItem } from './navigationBar.style'; class NavigationBar extends Component { render() { return ( <NavigationContainer> <NavItem to="/">Home</NavItem> <NavItem to="/projects"

How to correctly define a reference (React.RefObject<StyledComponentClass>) for styled-components (for TypeScript)?

烂漫一生 提交于 2019-12-03 16:36:36
How to correctly define a reference for styled-components? I wrote the following test code. This is a refined code, unlike the previous one ( How to correctly define a reference (React.RefObject) for styled-components (for TypeScript)? ). Added reference type StyledComponentClass< {}, any> . import React, {Component, RefObject, ReactNode} from 'react'; import styled, {StyledComponentClass} from 'styled-components'; type TModalShadowContainer = StyledComponentClass<{}, any>; const ModalShadowContainer: TModalShadowContainer = styled.div` background-color: black; `; export default class Modal

styled-components typescript error with Material-UI component

主宰稳场 提交于 2019-12-03 14:52:55
Using typescript and want to set styling for Material UI component with styled-components. But type error happens with StyledComponent showing Type '{ children: string; }' is missing the following properties import React, { PureComponent } from 'react'; import styled from 'styled-components'; // ^4.1.3 import { Button } from '@material-ui/core'; // ^3.9.1 class TestForm extends PureComponent { render() { return ( <> <Button style={{ backgroundColor: 'red' }}>Work</Button>{/* OK */} <StyledButton>Doesn't work</StyledButton>{/* Type Error happens here <=============== */} {/** Type '{ children:

How to get the theme outside styled-components?

做~自己de王妃 提交于 2019-12-03 11:57:34
I know how to get the theme from components that are created using the styled way: const StyledView = styled.View` color: ${({ theme }) => theme.color}; `; But how to get from normal components or apply it for different properties ? Example: index.js <ThemeProvider theme={{ color: 'red' }}> <Main /> </ThemeProvider> main.js <View> <Card aCustomColorProperty={GET COLOR FROM THEME HERE} /> </View> Notice how the property that needs the theme is not called style EDIT: As of v1.2, my pull request got merged and you can use the withTheme higher order component this way: import { withTheme } from

Rollup Error: 'isValidElementType' is not exported by node_modules/react-is/index.js

风格不统一 提交于 2019-12-03 10:58:05
I'm building a bundle with rollUp using styled-components. My rollup.config.js looks like: import resolve from 'rollup-plugin-node-resolve' import babel from 'rollup-plugin-babel' import commonjs from 'rollup-plugin-commonjs' export default { input: 'src/index.js', output: { file: 'dist/bundle.js', format: 'cjs' }, external: [ 'react', 'react-proptypes' ], plugins: [ resolve({ extensions: [ '.js', '.json', '.jsx' ] }), commonjs({ include: 'node_modules/**' }), babel({ exclude: 'node_modules/**' }) ] } And I'm receiving [!] Error: 'isValidElementType' is not exported by node_modules/react-is

importing images in React.js with styled-components

可紊 提交于 2019-12-03 05:17:40
I am using styled-components and am trying to set a background image like so const HeaderImage= styled.div` background-image: url('../../assets/image.png'); '; I've also tried without the quotes, like so const HeaderImage= styled.div` background-image: url(../../assets/image.png); '; In both cases, I get the same result http://localhost:3000/assets/image.png Failed to load resource: the server responded with a status of 404 (Not Found) I am using Richard Kall's react starter The file is definitely in the specified location. Am I loading it incorrectly? I should mention, I'm very new to this

conditional rendering in styled components

半腔热情 提交于 2019-12-02 17:30:18
How can I use conditional rendering in styled-components to set my button class to active using styled-components in React? In css I would do it similarly to this: <button className={this.state.active && 'active'} onClick={ () => this.setState({active: !this.state.active}) }>Click me</button> In styled components if I try to use '&&' in the classname it doesn't like it. import React from 'react' import styled from 'styled-components' const Tab = styled.button` width: 100%; outline: 0; border: 0; height: 100%; justify-content: center; align-items: center; line-height: 0.2; ` export default