#### UX/UI Spike :art: --- #### React styled components :nail_care: --- #### What is it? * A react library which lets you manage your css alongside react components. --- #### Where did it come from? * The result of wondering how we could enhance CSS for styling React component systems. * At present in react we use global and module.css files to apply styles. * Issues: big code base/overiding css/class-names --- #### Install ```# with npm npm install --save styled-components ``` --- #### Add to package JSON ``` { "resolutions": { "styled-components": "^5" } } ``` --- How to use? ``` import styled from "styled-components"; ``` --- #### React component:sparkles: ![](https://i.imgur.com/S3Yenbw.png) --- #### Apply styles :star-struck: ![](https://i.imgur.com/Eamkoiw.png) --- #### Ta-daaaaa :female-artist: ![](https://i.imgur.com/seMNDSA.png) --- #### Adapting based on props * You can pass a function ("interpolations") to a styled component's template literal to adapt it based on its props. --- #### React component :sparkles: ![](https://i.imgur.com/ceqIA5Q.png) --- #### Apply styles :star-struck: ![](https://i.imgur.com/4sVcIzj.png) --- #### Ta-daaaaa :female-artist: ![](https://i.imgur.com/ZJua9Mp.png) --- #### Extending Styles * Quite frequently you might want to use a component, but change it slightly for a single case. * To easily make a new component that inherits the styling of another, wrap it in the styled() constructor. --- #### React component :sparkles: ![](https://i.imgur.com/Abwx6DH.png) --- #### Apply styles :star-struck: ![](https://i.imgur.com/CuQOvVW.png) --- #### Ta-daaaaa :female-artist: ![](https://i.imgur.com/2gsqXo5.png) --- #### Aims to improve: * :heavy_check_mark: Automatic critical CSS. * :heavy_check_mark: No class name bugs. * :heavy_check_mark: Easier deletion of CSS. * :heavy_check_mark: Simple dynamic styling. * :heavy_check_mark: Painless maintenance. * :heavy_check_mark: Automatic vendor prefixing. --- *[Link to the docs](https://styled-components.com/docs/basics)*
{"metaMigratedAt":"2023-06-16T20:10:03.945Z","metaMigratedFrom":"Content","title":"Untitled","breaks":true,"contributors":"[{\"id\":\"5fc58879-82a7-42a5-adb7-d717c9b3063b\",\"add\":3597,\"del\":1492}]"}
    149 views