Skip to content

Instantly share code, notes, and snippets.

@luizomf
Created February 23, 2021 15:59
Show Gist options
  • Save luizomf/0ce6c9938bccac1f4fcc1d8fc1dfc1d8 to your computer and use it in GitHub Desktop.
Save luizomf/0ce6c9938bccac1f4fcc1d8fc1dfc1d8 to your computer and use it in GitHub Desktop.
Conhecendo melhor o styled-components - Curso React
import React from 'react';
import ReactDOM from 'react-dom';
import { ThemeProvider } from 'styled-components';
import { GlobalStyles } from './styles/global-styles';
import { theme } from './styles/theme';
import Home from './templates/App';
import styled, { css } from 'styled-components';
const changeBackground = (theme, bg) => css`
background: ${bg};
color: #000;
`;
const Heading = styled.h1`
color: purple;
`;
export const Container = styled.div`
background: ${({ theme }) => theme.colors.primaryColor};
${({ theme, bg }) => css`
color: ${theme.colors.white};
${changeBackground(theme, bg)}
`}
`;
export const Container2 = styled(Container).attrs({ as: 'article' })`
background: blue;
/* article > h1 */
> ${Heading} {
color: yellow;
}
/* article.h1 */
${Heading}:hover {
color: brown;
}
/* article:hover */
&:hover {
background: pink;
}
/* article:hover */
&::after {
content: '----';
}
`;
ReactDOM.render(
<React.StrictMode>
<ThemeProvider theme={theme}>
<Container bg="red">
<Heading>OI</Heading>
</Container>
<Container2 bg="red">
<Heading>OI</Heading>
</Container2>
<Heading>OI</Heading>
<GlobalStyles />
</ThemeProvider>
</React.StrictMode>,
document.getElementById('root'),
);
@201flaviosilva
Copy link

Ótimo tutorial, mas só uma nota, o comentário está errado no Container2, deveria ser assim:

  /* article h1:hover */
  ${Heading}:hover {
    color: brown;
  }

:)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment