Skip to content

Commit 6af6028

Browse files
HsharmaCodingayushishahh
authored andcommitted
Added Styled Component
1 parent 9a314be commit 6af6028

File tree

5 files changed

+142
-2
lines changed

5 files changed

+142
-2
lines changed

information

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
1. CSS Stylesheet Regular css stylesheet
44
2. Inline Styling
55
3. CSS Modules
6-
4. CSS in js Libraries (Styled Components)
7-
> Here we will cover only first three approaches.
6+
4. Styled Components (CSS using Libraries)
7+
> Install the package: npm install --save styled-components
8+
> For Typescript: npm i --save-dev @types/styled-components
89

910
1. CSS Stylesheet (Regular css stylesheet)
1011
> src/Components/Stylesheet.tsx
@@ -39,6 +40,10 @@
3940
> Similar we have imported applyStyle.module.css file in parent component (App.tsx). But
4041
We can not use it's classes in child component, because to use module.css we have to
4142
import styles attribute then we can access it's classes.
43+
44+
4. Styled Components
45+
> Components/StyledComponent.tsx file has been created to utilize the styled component
46+
styling. This file has been calling from the App.tsx.
4247

4348

4449

react-css-basic-app/package-lock.json

Lines changed: 111 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

react-css-basic-app/package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"react": "^18.2.0",
1414
"react-dom": "^18.2.0",
1515
"react-scripts": "5.0.1",
16+
"styled-components": "^5.3.5",
1617
"typescript": "^4.7.4",
1718
"web-vitals": "^2.1.4"
1819
},
@@ -39,5 +40,8 @@
3940
"last 1 firefox version",
4041
"last 1 safari version"
4142
]
43+
},
44+
"devDependencies": {
45+
"@types/styled-components": "^5.1.26"
4246
}
4347
}

react-css-basic-app/src/App.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import logo from './logo.svg';
33
import './App.css';
44
import {Stylesheet} from './Components/Stylesheet';
55
import {Inline} from './Components/Inline';
6+
import {StyledComponent} from './Components/StyledComponent';
67
import '../src/applyStyle.css'
78
import styles from '../src/applyStyle.module.css'
89

@@ -12,6 +13,7 @@ function App() {
1213
<header className="App-header">
1314
<Stylesheet primary={true}/>
1415
<Inline/>
16+
<StyledComponent/>
1517
{/* use class from the appStyles.css */}
1618
<h1 className='error'>Error</h1>
1719
{/* use class from the appStyles.module.css */}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import * as React from 'react';
2+
import styled from "styled-components";
3+
4+
// Styled component named StyledButton
5+
const StyledButton = styled.button`
6+
background-color: black;
7+
font-size: 32px;
8+
color: white;
9+
`;
10+
11+
export const StyledComponent=()=>{
12+
return(
13+
<div>
14+
{/* Use it like any other component. */}
15+
<StyledButton> Login </StyledButton>
16+
</div>
17+
)
18+
}

0 commit comments

Comments
 (0)