Skip to content

Sharing my collection of styled component configurations and reusable components, so you can use them in your web apps and personalize them as per need.

Notifications You must be signed in to change notification settings

AbdulBasit313/styled-components-react

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Styled Components with React and Typescript

React styled components ui components

This guide provides an overview of using Styled Components with React and Typescript to create reusable and easily manageable CSS-in-JS code. Styled Components is a powerful tool that allows you to write styling directly within your React components, providing a more modular and organized approach to styling.

Getting Started

To get started with Styled Components in your project, follow these steps:

  1. Clone the repository to your local machine.
  2. Run npm install to install the necessary dependencies.

Folder Structure

The recommended folder structure for Styled Components in React projects follows the best practices:

src/
  styles/
    Theme.ts
    Global.ts
    Breakpoints.ts
    Fonts.module.css

The styles folder contains four main files that are essential for organizing your Styled Components.

Theme.ts

The Theme.ts file is used for theming in Styled Components. It allows you to define colors, fonts, padding, margins, and other configurations that can be used throughout your application. Using TypeScript with Styled Components provides the advantage of IntelliSense for theming.

Global.ts

The Global.ts file contains global styles for your application. It is where you can reset default styling and define font, color, and background properties. This file ensures consistency in styling across your entire application.

Breakpoints.ts

The Breakpoints.ts file is used to handle responsive design using media queries. It defines different breakpoints for various screen sizes, allowing your application to adapt and provide the best layout to users. By using media queries in Styled Components, you can easily adjust styles based on the device width.

Read the article "Styled Components Media Queries for Responsive Styling" to learn about media queries in detail.

Fonts.module.css

The Fonts.module.css file is used to import and define font styles for your Styled Components. It includes font-face declarations for different font weights and allows you to use custom fonts in your application.

Usage

To use Styled Components in your React components, follow these steps:

  1. Import the necessary components from styled-components.
  2. Use the ThemeProvider component to wrap your application and provide the theme.
  3. Define your styled components using the styled function and pass in the desired HTML element or component.
  4. Use the theme variables and breakpoints defined in the Theme.ts and Breakpoints.ts files to style your components.

Top UI Components Built with React and Styled Components

Here are the top 5 widely-used React components crafted using TypeScript and Styled Components:

  1. Navbar
  2. Button
  3. Input
  4. Radio Button
  5. Progress Steps

Further Resources

For more detailed information and examples, refer to the React Styled Components Folder Structure Best Practices. The article provides a comprehensive guide and code examples for using Styled Components in React projects.

Moreover, if you like the information provided in the repository. consider giving it a star. 😉

Enjoy using Styled Components to create beautiful and maintainable CSS-in-JS code in your React and Typescript projects!

About

Sharing my collection of styled component configurations and reusable components, so you can use them in your web apps and personalize them as per need.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published