styled-components

how to use css in JS for nested hover styles, Material UI

≡放荡痞女 提交于 2019-12-02 09:56:00
问题 I'm using Material UI and trying to convert normal css classes into js file. .nav { list-style-type: none; margin: 0; padding: 0; overflow: hidden; } .navItem { float: left; flex: 1; } .navLink { color: white; text-decoration: none; display: block; font-size: '1 rem'; font-weight: 500; line-height: 1.6; letter-spacing: '0.0075em'; opacity: 1; text-transform: 'none'; min-width: 0; padding: 10px; margin-left: 10px; margin-right: 10px; } .navLink-static { color: white; text-decoration: none;

how to use css in JS for nested hover styles, Material UI

↘锁芯ラ 提交于 2019-12-02 05:02:06
I'm using Material UI and trying to convert normal css classes into js file. .nav { list-style-type: none; margin: 0; padding: 0; overflow: hidden; } .navItem { float: left; flex: 1; } .navLink { color: white; text-decoration: none; display: block; font-size: '1 rem'; font-weight: 500; line-height: 1.6; letter-spacing: '0.0075em'; opacity: 1; text-transform: 'none'; min-width: 0; padding: 10px; margin-left: 10px; margin-right: 10px; } .navLink-static { color: white; text-decoration: none; display: block; font-size: '1rem'; font-weight: 500; line-height: 1.6; letter-spacing: '0.0075em'; opacity

Passing further arguments with tagged template literals

本秂侑毒 提交于 2019-12-01 16:56:38
I'm working with styled-components and generating components using their tagged template literal syntax such as: const Button = styled.button` background-color: papayawhip; border-radius: 3px; color: palevioletred; ` In one case I need to call a function that generates a media query based on a breakpoint and passes the tagged template literal of css to be included within. for example: media(12)` background-color: papayawhip; ` The media function might look something like this: const media = mapValues(width => ({ css: (...args) => css` @media (min-width: ${width}rem) { ${css(...args)} } `}));

target child element styled components

僤鯓⒐⒋嵵緔 提交于 2019-12-01 01:15:47
问题 I'm trying to change the nth-child(2) background color of the ColorBox element by targeting it as a child of ImgGrid but I just can't seem to get it to work, I have tried multiple variations with different elements and nothing seems to be working This will change the background color if I don't try to target an nth-child element const ImgGrid = styled.div` display: flex; flex-wrap: wrap; flex-direction: row; ${ColorBox} { background: #ff00ff; } ` How can I target the nth-child(2) of the

Before and After pseudo classes used with styled-components

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-30 13:42:46
问题 What is the proper way to apply :before and :after pseudo classes to styled components? I know that you can use &:hover {} to apply the :hover pseudo class to a styled-component. Does this work for All pseudo elements like before and after? I have tried using the &:before and &:after strategy with some rather complex examples and i'm not sure if my attempts are not working because i've got something wrong with my example or it just doesn't work like that. Does someone have some insight on

Using Javascript Variables with styled-components

让人想犯罪 __ 提交于 2019-11-30 03:18:59
I'm using styled-components to build my components. All style properties which accept custom values are reused throughout my components (as it should be). With that in mind, I'd like to use some sort of global variables so that updates will propagate to all components without needing to update each style individually. Something like this: // Variables.js var fontSizeMedium = 16px; // Section.js const Section = styled.section` font-size: ${fontSizeMedium}; `; // Button.js const Button = styled.button` font-size: ${fontSizeMedium}; `; // Label.js const Label = styled.span` font-size: $

Target another styled component on hover

家住魔仙堡 提交于 2019-11-29 19:56:40
What is the best way to handle hovers in styled-components. I have a wrapping element that when hovered will reveal a button. I could implement some state on the component and toggle a property on hover but was wondering if there is a better way to do this with styled-cmponents. Something like the following doesn't work but would be ideal: const Wrapper = styled.div` border-radius: 0.25rem; overflow: hidden; box-shadow: 0 3px 10px -3px rgba(0, 0, 0, 0.25); &:not(:last-child) { margin-bottom: 2rem; } &:hover { .button { display: none; } } ` mxstbr As of styled-components v2 you can interpolate

Using Javascript Variables with styled-components

半世苍凉 提交于 2019-11-29 00:55:52
问题 I'm using styled-components to build my components. All style properties which accept custom values are reused throughout my components (as it should be). With that in mind, I'd like to use some sort of global variables so that updates will propagate to all components without needing to update each style individually. Something like this: // Variables.js var fontSizeMedium = 16px; // Section.js const Section = styled.section` font-size: ${fontSizeMedium}; `; // Button.js const Button = styled

Styled component input loses focus onChange

左心房为你撑大大i 提交于 2019-11-28 10:55:43
问题 When using an html input with styled-components and saving the value to react state with onChange, the component appears to be re-rendering on every state change and causing the input to lose focus. Is there any way to prevent the input from losing focus? Why is this occurring? Here is an example. class MyComponent extends React.Component { state = { val: "" }; render() { const Input = styled.input` border-radius: 6px; `; return ( <Input value={this.state.val} onChange={e => this.setState({

How can I override ExpansionPanelSummary deep elements with styled-components?

纵然是瞬间 提交于 2019-11-28 09:59:18
问题 Using the docs/examples for overriding Material UI styling with styled-components, I've managed to style the root and "deeper elements" within an ExpansionPanel and ExpansionPanelDetails . However, when I use the same technique to return an overridden ExpansionPanelSummary from a function passed to styled() , the ExpansionPanelSummary moves in the DOM and the whole ExpansionPanel no longer renders correctly. The technique in question, as applied to ExpansionPanel (this works as expected, on