{"id":330959,"date":"2022-03-23T03:00:08","date_gmt":"2022-03-23T03:00:08","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=330959"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=330959","title":{"rendered":"<span>\u0422\u0451\u043c\u043d\u0430\u044f \u0442\u0435\u043c\u0430 \u0432 React \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c css \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0432 scss<\/span>"},"content":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/c6a\/e44\/c92\/c6ae44c92240b354fbfdf18768f09963.png\" width=\"2024\" height=\"1076\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/c6a\/e44\/c92\/c6ae44c92240b354fbfdf18768f09963.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0422\u0435\u043c\u043d\u0430\u044f \u0442\u0435\u043c\u0430 \u0441\u0442\u0430\u043b\u0430 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043e\u043c \u0434\u0435-\u0444\u0430\u043a\u0442\u043e. \u0415\u0435 \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u0435 \u043c\u043e\u0436\u0435\u0442 \u0441\u0442\u0430\u0442\u044c \u043f\u0440\u0438\u0447\u0438\u043d\u043e\u0439 \u043e\u0442\u043a\u0430\u0437\u0430 \u043e\u0442 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0441\u0430\u0439\u0442\u043e\u043c. \u041e\u0441\u043e\u0431\u0435\u043d\u043d\u043e \u0435\u0441\u043b\u0438 \u043d\u0430 \u043d\u0435\u0433\u043e \u0437\u0430\u0445\u043e\u0434\u044f\u0442 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0441\u043f\u043b\u043e\u0448\u044c \u0438 \u0440\u044f\u0434\u043e\u043c \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0442 \u0432 \u0442\u0451\u043c\u043d\u043e\u0439 \u0442\u0435\u043c\u0435.<\/p>\n<p>\u042f \u043f\u043e\u043a\u0430\u0436\u0443, \u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0442\u0435\u043c\u043d\u0443\u044e \u0442\u0435\u043c\u0443 \u0432 React \u043f\u0440\u043e\u0435\u043a\u0442. \u0420\u0430\u0437\u0431\u0435\u0440\u0435\u043c \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \u043c\u043e\u043c\u0435\u043d\u0442\u044b \u0438 \u0441\u0434\u0435\u043b\u0430\u0435\u043c \u0432\u0441\u0451 \u043a\u0440\u0430\u0441\u0438\u0432\u043e. \u0414\u043b\u044f \u0442\u0435\u0445, \u043a\u0442\u043e \u0445\u043e\u0447\u0435\u0442 \u0432\u0441\u0435 \u0441\u0440\u0430\u0437\u0443:<\/p>\n<p>&#8212; [\u0420\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0439](<a href=\"https:\/\/github.com\/walborn\/with-dark-theme\" rel=\"noopener noreferrer nofollow\"><u>https:\/\/github.com\/walborn\/with-dark-theme<\/u><\/a>)<\/p>\n<p>&#8212; [\u0414\u0435\u043c\u043e](<a href=\"https:\/\/with-dark-theme-4ypv8vyi9-walborn.vercel.app\/\" rel=\"noopener noreferrer nofollow\"><u>https:\/\/with-dark-theme-4ypv8vyi9-walborn.vercel.app\/<\/u><\/a>)<\/p>\n<h3>Roadmap<\/h3>\n<p>\u0428\u0430\u0433\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u044b \u043f\u0440\u043e\u0434\u0435\u043b\u0430\u0435\u043c \u0434\u0430\u043b\u044c\u0448\u0435:<\/p>\n<p>1. \u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c <code>create-react-app<\/code> \u043f\u0440\u043e\u0435\u043a\u0442<br \/>2. \u0414\u043e\u0431\u0430\u0432\u0438\u043c \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0431\u0443\u0434\u0435\u043c \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0442\u0435\u043a\u0443\u0449\u0443\u044e \u0442\u0435\u043c\u0443<br \/>3. \u041d\u0430\u043f\u0438\u0448\u0435\u043c \u043f\u0435\u0440\u0435\u043a\u043b\u044e\u0447\u0430\u0442\u0435\u043b\u044c \u0434\u043b\u044f \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0442\u0435\u043c\u044b<br \/>4. \u041e\u0431\u044a\u044f\u0432\u0438\u043c \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u0442\u0435\u043c\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0431\u0443\u0434\u0443\u0442 \u0432\u043b\u0438\u044f\u0442\u044c \u043d\u0430 \u0441\u0442\u0438\u043b\u0438 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u0432<\/p>\n<h3>\u041f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043a\u0430<\/h3>\n<p>1. \u0421 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <code>cra<\/code> \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u043f\u0440\u043e\u0435\u043a\u0442 \u0438 \u0441\u0440\u0430\u0437\u0443 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c <code>sass<\/code> \u0434\u043b\u044f \u0443\u0434\u043e\u0431\u0441\u0442\u0432\u0430 \u0440\u0430\u0431\u043e\u0442\u044b \u0441\u043e \u0441\u0442\u0438\u043b\u044f\u043c\u0438<\/p>\n<pre><code class=\"bash\">> npx create-react-app with-dark-theme > cd with-dark-theme > npm i sass -S<\/code><\/pre>\n<p>2. \u0423\u0434\u0430\u043b\u0438\u043c \u043d\u0435\u043d\u0443\u0436\u043d\u044b\u0435 \u0444\u0430\u0439\u043b\u044b<\/p>\n<pre><code class=\"bash\">> cd src > rm App.css App.js App.test.js index.css logo.svg<\/code><\/pre>\n<p>3. \u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0443\u0434\u043e\u0431\u043d\u0443\u044e \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440<\/p>\n<pre><code class=\"bash\"># \u0432\u043d\u0443\u0442\u0440\u0438 src\/ > mkdir -p components\/{Root,Toggle} contexts providers > touch index.scss components\/Root\/index.js components\/Toggle\/{index.js,index.module.scss} contexts\/ThemeContext.js providers\/ThemeProvider.js<\/code><\/pre>\n<p>\u0414\u043e\u043b\u0436\u043d\u0430 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c\u0441\u044f \u0442\u0430\u043a\u0430\u044f \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u0432\u043d\u0443\u0442\u0440\u0438 <code>src\/<\/code><\/p>\n<pre><code class=\"bash\">src \u251c\u2500\u2500 components \u2502\u00a0\u00a0 \u251c\u2500\u2500 Root \u2502\u00a0\u00a0 \u2502\u00a0\u00a0 \u2514\u2500\u2500 index.js \u2502\u00a0\u00a0 \u2514\u2500\u2500 Toggle \u2502\u00a0\u00a0     \u251c\u2500\u2500 index.js \u2502\u00a0\u00a0     \u2514\u2500\u2500 index.module.scss \u251c\u2500\u2500 contexts \u2502\u00a0\u00a0 \u2514\u2500\u2500 ThemeContext.js \u251c\u2500\u2500 providers \u2502\u00a0\u00a0 \u2514\u2500\u2500 ThemeProvider.js \u251c\u2500\u2500 index.js \u251c\u2500\u2500 index.scss \u2514\u2500\u2500 ...<\/code><\/pre>\n<p>\u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043c\u044b \u0432\u043d\u0435\u0441\u043b\u0438 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0432 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443, \u0442\u043e \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0438\u0437\u043c\u0435\u043d\u0438\u043c <code>index.js<\/code><\/p>\n<pre><code class=\"javascript\">\/\/ src\/index.js import React from 'react' import ReactDOM from 'react-dom' import reportWebVitals from '.\/reportWebVitals'  \/\/ \u0442\u0435\u043f\u0435\u0440\u044c \u043a\u043e\u0440\u043d\u0435\u0432\u043e\u0439 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u0443 \u043d\u0430\u0441 \u043d\u0435 App, \u0430 Root import Root from '.\/components\/Root'   \/\/ \u043f\u043e\u043c\u0435\u043d\u044f\u043b\u0438 css \u043d\u0430 scss import '.\/index.scss'  ReactDOM.render(   &lt;React.StrictMode>     &lt;Root \/>   &lt;\/React.StrictMode>,   document.getElementById('root') )<\/code><\/pre>\n<pre><code class=\"javascript\">\/\/ src\/components\/Root\/index.js import React from 'react'  const Root = () => ( &lt;div>There are will be Dark Theme&lt;\/div> )  export default Root<\/code><\/pre>\n<p>\u041f\u0440\u043e\u0435\u043a\u0442 \u0443\u0436\u0435 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442\u0441\u044f, \u043d\u043e \u043d\u0438\u043a\u0430\u043a\u043e\u0439 \u0442\u0435\u043c\u043d\u043e\u0439 \u0442\u0435\u043c\u044b \u043f\u043e\u043a\u0430 \u0435\u0449\u0435 \u043d\u0435\u0442.<br \/>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0435\u0435!<\/p>\n<h3>\u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442<\/h3>\n<p>\u041d\u0430\u043f\u043e\u043b\u043d\u0438\u043c \u043a\u043e\u0434\u043e\u043c \u043d\u0430\u0448\u0438 \u0444\u0430\u0439\u043b\u044b <code>ThemeContext.js<\/code> \u0438 <code>ThemeProvider.js<\/code> <\/p>\n<p>\u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442<\/p>\n<pre><code class=\"javascript\">\/\/ src\/components\/Root\/index.js import React from 'react'  const Root = () => ( &lt;div>There are will be Dark Theme&lt;\/div> )  export default Root<\/code><\/pre>\n<p>\u0410 \u0442\u0435\u043f\u0435\u0440\u044c \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043f\u0440\u043e\u0432\u043e\u0434\u043d\u0438\u043a \u043d\u0430\u0448\u0435\u0433\u043e \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u0442\u0435\u043a\u0443\u0449\u0435\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0442\u0435\u043c\u044b, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0445\u0440\u0430\u043d\u0438\u0442\u0441\u044f \u0432 <code>localStorage<\/code> . \u0415\u0441\u043b\u0438 \u0442\u0430\u043c \u0435\u0449\u0435 \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435\u0442,  \u0442\u043e \u0431\u0435\u0440\u0435\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0438\u0437 \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u043e\u0439 \u0442\u0435\u043c\u044b. \u0415\u0441\u043b\u0438 \u0438 \u044d\u0442\u043e\u0433\u043e \u043d\u0435\u0442 (\u043f\u0440\u0438\u0432\u0435\u0442 \u0438\u0437 \u0432\u0438\u043d\u0434\u043e\u0432\u0441 xp) &#8212; \u0442\u043e \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u0442\u0435\u043c\u043d\u0443\u044e \u0442\u0435\u043c\u0443 (\u0410 \u0447\u0442\u043e?! \u041c\u043e\u0436\u0435\u043c \u0441\u0435\u0431\u0435 \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u0442\u044c)<\/p>\n<p>\u041f\u0440\u0438 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0438 \u0442\u0435\u043c\u044b &#8212; \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c \u0435\u0435 \u0432 <code>localStorage<\/code><\/p>\n<pre><code class=\"javascript\">\/\/ src\/providers\/ThemeProvider.js import React from 'react' import { ThemeContext, themes } from 'src\/contexts\/ThemeContext'  const getTheme = () => {   const theme = `${window?.localStorage?.getItem('theme')}`   if (Object.values(themes).includes(theme)) return theme    const userMedia = window.matchMedia('(prefers-color-scheme: light)')   if (userMedia.matches) return themes.light    return themes.dark }  const ThemeProvider = ({ children }) => {   const [ theme, setTheme ] = React.useState(getTheme)    React.useEffect(() => {     document.documentElement.dataset.theme = theme     localStorage.setItem('theme', theme)   }, [ theme ])    return (     &lt;ThemeContext.Provider value={{ theme, setTheme }}>       {children}     &lt;\/ThemeContext.Provider>   ) }  export default ThemeProvider<\/code><\/pre>\n<p>\u0418 \u0442\u0435\u043f\u0435\u0440\u044c \u0437\u0430\u0439\u0434\u0435\u043c \u0432 \u043a\u043e\u0440\u043d\u0435\u0432\u043e\u0439 \u0444\u0430\u0439\u043b <code>index.js<\/code>. \u0422\u0443\u0442 \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u0442\u044c \u043d\u0430\u0448 <code>ThemeProvider<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u043e\u0431\u043e\u0440\u0430\u0447\u0438\u0432\u0430\u0435\u043c <code>Root<\/code>, \u0447\u0442\u043e\u0431\u044b \u0432\u0441\u0435, \u0447\u0442\u043e \u0432\u043d\u0443\u0442\u0440\u0438 \u0438\u043c\u0435\u043b\u043e \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u0442\u0435\u043c\u044b<\/p>\n<pre><code class=\"javascript\">\/\/ src\/index.js import React from 'react' import ReactDOM from 'react-dom' import reportWebVitals from '.\/reportWebVitals'  import ThemeProvider from '.\/providers\/ThemeProvider' \/\/ + import Root from '.\/components\/Root'  import '.\/index.scss'  ReactDOM.render(   &lt;React.StrictMode>     &lt;ThemeProvider>       &lt;Root \/>     &lt;\/ThemeProvider>   &lt;\/React.StrictMode>,   document.getElementById('root') ) ...<\/code><\/pre>\n<h3>\u041f\u0438\u0448\u0435\u043c \u043f\u0435\u0440\u0435\u043a\u043b\u044e\u0447\u0430\u0442\u0435\u043b\u044c<\/h3>\n<p>\u041e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043f\u0435\u0440\u0435\u043a\u043b\u044e\u0447\u0430\u0442\u0435\u043b\u044c \u0434\u043b\u044f \u0442\u0435\u043c\u044b. \u0412 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u044d\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0439 \u0442\u043e\u0433\u0433\u043b\u0435\u0440. \u041d\u0443 \u043f\u043e\u0447\u0442\u0438 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0439, \u043c\u044b \u0435\u0433\u043e \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0443\u043b\u0443\u0447\u0448\u0438\u043c, \u0447\u0442\u043e\u0431\u044b \u043d\u0435 \u0441\u043e\u0432\u0441\u0435\u043c \u0433\u0440\u0443\u0441\u0442\u043d\u043e \u0431\u044b\u043b\u043e.<\/p>\n<pre><code class=\"javascript\">\/\/ src\/components\/Toggle\/index.js import React from 'react' import styles from '.\/index.module.scss'  const Toggle = ({ value, onChange }) => (   &lt;label className={styles.switch} htmlFor=\"toggler\">     &lt;input       id=\"toggler\"       type=\"checkbox\"       onClick={onChange}       checked={value}       readOnly     \/>     &lt;span className={styles.slider} \/>     &lt;span className={styles.wave} \/>   &lt;\/label> )  export default Toggle<\/code><\/pre>\n<pre><code class=\"css\">\/\/ src\/components\/Toggle\/index.module.scss .root {   position: absolute;   top: 50%;   left: 50%;   width: 120px;   height: 50px;   transform: translate(-50%, -50%);   input {     display: none;   }   .slider {     position: absolute;     top: 0;     right: 0;     bottom: 0;     left: 0;     z-index: 1;     overflow: hidden;     background-color: #e74a42;     border-radius: 50px;     cursor: pointer;     transition: all 1.4s;     &amp;:before,     &amp;:after {       content: \"\";       position: absolute;       bottom: 5px;       left: 5px;       width: 40px;       height: 40px;       background-color: #ffffff;       border-radius: 30px;     }     &amp;:before {       transition: 0.4s;     }     &amp;:after {       transition: 0.5s;     }   }   .wave {     position: absolute;     top: 0;     left: 0;     width: 120px;     height: 50px;     border-radius: 40px;     transition: all 1.4s;     &amp;:after {       content: \"\";       position: absolute;       top: 3px;       left: 20%;       width: 60px;       height: 3px;       background: #ffffff;       border-radius: 100%;       opacity: 0.4;     }     &amp;:before {       content: \"\";       position: absolute;       top: 10px;       left: 30%;       width: 35px;       height: 2px;       background: #ffffff;       border-radius: 100%;       opacity: 0.3;     }   }   input:checked + .slider {     background-color: transparent;     &amp;:before,     &amp;:after {       transform: translateX(70px);     }   }   input:checked ~ .wave {     display: block;     background-color: #3398d9;   } }<\/code><\/pre>\n<p>\u041f\u043e\u0447\u0442\u0438 \u0432\u0441\u0435! \u041e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c  \u043d\u0430\u0448 <code>Toggle<\/code> \u043d\u0430 \u0433\u043b\u0430\u0432\u043d\u0443\u044e \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0443<\/p>\n<pre><code class=\"javascript\">\/\/ src\/components\/Root\/index.js import React from 'react' import { ThemeContext, themes } from '..\/..\/contexts\/ThemeContext' import Toggle from '..\/Toggle'  const Root = () => (   &lt;ThemeContext.Consumer>     {({ theme, setTheme }) => (       &lt;Toggle         onChange={() => {           if (theme === themes.light) setTheme(themes.dark)           if (theme === themes.dark) setTheme(themes.light)         }}         value={theme === themes.dark}       \/>     )}   &lt;\/ThemeContext.Consumer> )  export default Root<\/code><\/pre>\n<pre><code class=\"css\">\/\/ src\/index.scss :root[data-theme=\"light\"] {   --background-color: #fafafa; }  :root[data-theme=\"dark\"] {   --background-color: #2b3e51; }  body {   background: var(--background-color); }<\/code><\/pre>\n<p>\u0418 \u0447\u0442\u043e\u0431\u044b \u0432\u0441\u0435 \u0437\u0430\u0440\u0430\u0431\u043e\u0442\u0430\u043b\u043e \u043a\u0430\u043a \u043d\u0430\u0434\u043e, \u043d\u0443\u0436\u043d\u043e \u0437\u0430\u0434\u0430\u0442\u044c \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u0442\u0435\u043c\u044b. \u0417\u0430\u0434\u0430\u0432\u0430\u0442\u044c \u043c\u044b \u0438\u0445 \u0431\u0443\u0434\u0435\u043c \u0447\u0435\u0440\u0435\u0437 <code>css<\/code> \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0442\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u0432 <code>scss<\/code> \u043d\u0430\u043c \u043d\u0435 \u043f\u043e\u0434\u043e\u0439\u0434\u0443\u0442. <code>scss<\/code>  \u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0442\u0441\u044f \u0432 <code>css<\/code> \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0433\u043b\u0443\u043f\u043e, \u043e\u043d \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u043e\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0432\u043e \u0432\u0441\u0435\u0445 \u043c\u0435\u0441\u0442\u0430\u0445, \u0433\u0434\u0435 \u043e\u043d\u0438 \u0444\u0438\u0433\u0443\u0440\u0438\u0440\u0443\u044e\u0442.<\/p>\n<h3>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h3>\n<p>\u0412\u043d\u0435\u0434\u0440\u0438\u0442\u044c \u0442\u0435\u043c\u043d\u0443\u044e \u0442\u0435\u043c\u0443 \u0432 React \u043e\u043a\u0430\u0437\u0430\u043b\u043e\u0441\u044c \u043d\u0435 \u0442\u0430\u043a \u0443\u0436 \u0438 \u0441\u043b\u043e\u0436\u043d\u043e. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043c\u044b \u043f\u0440\u043e\u043a\u0438\u0434\u044b\u0432\u0430\u043b\u0438 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e \u0442\u0435\u043c\u0435 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c\u0430 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0435\u0441\u0442\u044c \u0432 <code>React<\/code>. \u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u0435\u0440\u0435\u043a\u043b\u044e\u0447\u0430\u0442\u0435\u043b\u044f \u043c\u043e\u0436\u043d\u043e \u0432\u0437\u044f\u0442\u044c \u0447\u0442\u043e \u0443\u0433\u043e\u0434\u043d\u043e, \u0434\u0435\u043b\u0438\u0442\u0435\u0441\u044c \u0441\u0432\u043e\u0438\u043c\u0438 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430\u043c\u0438 \u0432 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f\u0445! \u0416\u0434\u0443 \u043e\u0442 \u0432\u0430\u0441 \u0432\u0430\u0448\u0435\u0433\u043e \u043c\u043d\u0435\u043d\u0438\u044f \u043e \u0441\u0442\u0430\u0442\u044c\u0435 \u0438 \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u043e\u0432 \u043e \u0432\u0430\u0448\u0435\u043c \u043e\u043f\u044b\u0442\u0435 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0442\u0451\u043c\u043d\u043e\u0439 \u0442\u0435\u043c\u044b! <\/p>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"v-portal\" style=\"display:none;\"><\/div>\n<\/div>\n<p> <!----> <!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/656995\/\"> https:\/\/habr.com\/ru\/post\/656995\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u0422\u0435\u043c\u043d\u0430\u044f \u0442\u0435\u043c\u0430 \u0441\u0442\u0430\u043b\u0430 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043e\u043c \u0434\u0435-\u0444\u0430\u043a\u0442\u043e. \u0415\u0435 \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u0435 \u043c\u043e\u0436\u0435\u0442 \u0441\u0442\u0430\u0442\u044c \u043f\u0440\u0438\u0447\u0438\u043d\u043e\u0439 \u043e\u0442\u043a\u0430\u0437\u0430 \u043e\u0442 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0441\u0430\u0439\u0442\u043e\u043c. \u041e\u0441\u043e\u0431\u0435\u043d\u043d\u043e \u0435\u0441\u043b\u0438 \u043d\u0430 \u043d\u0435\u0433\u043e \u0437\u0430\u0445\u043e\u0434\u044f\u0442 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0441\u043f\u043b\u043e\u0448\u044c \u0438 \u0440\u044f\u0434\u043e\u043c \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0442 \u0432 \u0442\u0451\u043c\u043d\u043e\u0439 \u0442\u0435\u043c\u0435.<\/p>\n<p>\u042f \u043f\u043e\u043a\u0430\u0436\u0443, \u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0442\u0435\u043c\u043d\u0443\u044e \u0442\u0435\u043c\u0443 \u0432 React \u043f\u0440\u043e\u0435\u043a\u0442. \u0420\u0430\u0437\u0431\u0435\u0440\u0435\u043c \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \u043c\u043e\u043c\u0435\u043d\u0442\u044b \u0438 \u0441\u0434\u0435\u043b\u0430\u0435\u043c \u0432\u0441\u0451 \u043a\u0440\u0430\u0441\u0438\u0432\u043e. \u0414\u043b\u044f \u0442\u0435\u0445, \u043a\u0442\u043e \u0445\u043e\u0447\u0435\u0442 \u0432\u0441\u0435 \u0441\u0440\u0430\u0437\u0443:<\/p>\n<p>&#8212; [\u0420\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0439](<a href=\"https:\/\/github.com\/walborn\/with-dark-theme\" rel=\"noopener noreferrer nofollow\"><u>https:\/\/github.com\/walborn\/with-dark-theme<\/u><\/a>)<\/p>\n<p>&#8212; [\u0414\u0435\u043c\u043e](<a href=\"https:\/\/with-dark-theme-4ypv8vyi9-walborn.vercel.app\/\" rel=\"noopener noreferrer nofollow\"><u>https:\/\/with-dark-theme-4ypv8vyi9-walborn.vercel.app\/<\/u><\/a>)<\/p>\n<h3>Roadmap<\/h3>\n<p>\u0428\u0430\u0433\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u044b \u043f\u0440\u043e\u0434\u0435\u043b\u0430\u0435\u043c \u0434\u0430\u043b\u044c\u0448\u0435:<\/p>\n<p>1. \u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c <code>create-react-app<\/code> \u043f\u0440\u043e\u0435\u043a\u0442<br \/>2. \u0414\u043e\u0431\u0430\u0432\u0438\u043c \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0431\u0443\u0434\u0435\u043c \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0442\u0435\u043a\u0443\u0449\u0443\u044e \u0442\u0435\u043c\u0443<br \/>3. \u041d\u0430\u043f\u0438\u0448\u0435\u043c \u043f\u0435\u0440\u0435\u043a\u043b\u044e\u0447\u0430\u0442\u0435\u043b\u044c \u0434\u043b\u044f \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0442\u0435\u043c\u044b<br \/>4. \u041e\u0431\u044a\u044f\u0432\u0438\u043c \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u0442\u0435\u043c\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0431\u0443\u0434\u0443\u0442 \u0432\u043b\u0438\u044f\u0442\u044c \u043d\u0430 \u0441\u0442\u0438\u043b\u0438 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u0432<\/p>\n<h3>\u041f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043a\u0430<\/h3>\n<p>1. \u0421 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <code>cra<\/code> \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u043f\u0440\u043e\u0435\u043a\u0442 \u0438 \u0441\u0440\u0430\u0437\u0443 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c <code>sass<\/code> \u0434\u043b\u044f \u0443\u0434\u043e\u0431\u0441\u0442\u0432\u0430 \u0440\u0430\u0431\u043e\u0442\u044b \u0441\u043e \u0441\u0442\u0438\u043b\u044f\u043c\u0438<\/p>\n<pre><code class=\"bash\">> npx create-react-app with-dark-theme > cd with-dark-theme > npm i sass -S<\/code><\/pre>\n<p>2. \u0423\u0434\u0430\u043b\u0438\u043c \u043d\u0435\u043d\u0443\u0436\u043d\u044b\u0435 \u0444\u0430\u0439\u043b\u044b<\/p>\n<pre><code class=\"bash\">> cd src > rm App.css App.js App.test.js index.css logo.svg<\/code><\/pre>\n<p>3. \u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0443\u0434\u043e\u0431\u043d\u0443\u044e \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440<\/p>\n<pre><code class=\"bash\"># \u0432\u043d\u0443\u0442\u0440\u0438 src\/ > mkdir -p components\/{Root,Toggle} contexts providers > touch index.scss components\/Root\/index.js components\/Toggle\/{index.js,index.module.scss} contexts\/ThemeContext.js providers\/ThemeProvider.js<\/code><\/pre>\n<p>\u0414\u043e\u043b\u0436\u043d\u0430 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c\u0441\u044f \u0442\u0430\u043a\u0430\u044f \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u0432\u043d\u0443\u0442\u0440\u0438 <code>src\/<\/code><\/p>\n<pre><code class=\"bash\">src \u251c\u2500\u2500 components \u2502\u00a0\u00a0 \u251c\u2500\u2500 Root \u2502\u00a0\u00a0 \u2502\u00a0\u00a0 \u2514\u2500\u2500 index.js \u2502\u00a0\u00a0 \u2514\u2500\u2500 Toggle \u2502\u00a0\u00a0     \u251c\u2500\u2500 index.js \u2502\u00a0\u00a0     \u2514\u2500\u2500 index.module.scss \u251c\u2500\u2500 contexts \u2502\u00a0\u00a0 \u2514\u2500\u2500 ThemeContext.js \u251c\u2500\u2500 providers \u2502\u00a0\u00a0 \u2514\u2500\u2500 ThemeProvider.js \u251c\u2500\u2500 index.js \u251c\u2500\u2500 index.scss \u2514\u2500\u2500 ...<\/code><\/pre>\n<p>\u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043c\u044b \u0432\u043d\u0435\u0441\u043b\u0438 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0432 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443, \u0442\u043e \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0438\u0437\u043c\u0435\u043d\u0438\u043c <code>index.js<\/code><\/p>\n<pre><code class=\"javascript\">\/\/ src\/index.js import React from 'react' import ReactDOM from 'react-dom' import reportWebVitals from '.\/reportWebVitals'  \/\/ \u0442\u0435\u043f\u0435\u0440\u044c \u043a\u043e\u0440\u043d\u0435\u0432\u043e\u0439 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u0443 \u043d\u0430\u0441 \u043d\u0435 App, \u0430 Root import Root from '.\/components\/Root'   \/\/ \u043f\u043e\u043c\u0435\u043d\u044f\u043b\u0438 css \u043d\u0430 scss import '.\/index.scss'  ReactDOM.render(   &lt;React.StrictMode>     &lt;Root \/>   &lt;\/React.StrictMode>,   document.getElementById('root') )<\/code><\/pre>\n<pre><code class=\"javascript\">\/\/ src\/components\/Root\/index.js import React from 'react'  const Root = () => ( &lt;div>There are will be Dark Theme&lt;\/div> )  export default Root<\/code><\/pre>\n<p>\u041f\u0440\u043e\u0435\u043a\u0442 \u0443\u0436\u0435 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442\u0441\u044f, \u043d\u043e \u043d\u0438\u043a\u0430\u043a\u043e\u0439 \u0442\u0435\u043c\u043d\u043e\u0439 \u0442\u0435\u043c\u044b \u043f\u043e\u043a\u0430 \u0435\u0449\u0435 \u043d\u0435\u0442.<br \/>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0435\u0435!<\/p>\n<h3>\u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442<\/h3>\n<p>\u041d\u0430\u043f\u043e\u043b\u043d\u0438\u043c \u043a\u043e\u0434\u043e\u043c \u043d\u0430\u0448\u0438 \u0444\u0430\u0439\u043b\u044b <code>ThemeContext.js<\/code> \u0438 <code>ThemeProvider.js<\/code> <\/p>\n<p>\u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442<\/p>\n<pre><code class=\"javascript\">\/\/ src\/components\/Root\/index.js import React from 'react'  const Root = () => ( &lt;div>There are will be Dark Theme&lt;\/div> )  export default Root<\/code><\/pre>\n<p>\u0410 \u0442\u0435\u043f\u0435\u0440\u044c \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043f\u0440\u043e\u0432\u043e\u0434\u043d\u0438\u043a \u043d\u0430\u0448\u0435\u0433\u043e \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u0442\u0435\u043a\u0443\u0449\u0435\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0442\u0435\u043c\u044b, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0445\u0440\u0430\u043d\u0438\u0442\u0441\u044f \u0432 <code>localStorage<\/code> . \u0415\u0441\u043b\u0438 \u0442\u0430\u043c \u0435\u0449\u0435 \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435\u0442,  \u0442\u043e \u0431\u0435\u0440\u0435\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0438\u0437 \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u043e\u0439 \u0442\u0435\u043c\u044b. \u0415\u0441\u043b\u0438 \u0438 \u044d\u0442\u043e\u0433\u043e \u043d\u0435\u0442 (\u043f\u0440\u0438\u0432\u0435\u0442 \u0438\u0437 \u0432\u0438\u043d\u0434\u043e\u0432\u0441 xp) &#8212; \u0442\u043e \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u0442\u0435\u043c\u043d\u0443\u044e \u0442\u0435\u043c\u0443 (\u0410 \u0447\u0442\u043e?! \u041c\u043e\u0436\u0435\u043c \u0441\u0435\u0431\u0435 \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u0442\u044c)<\/p>\n<p>\u041f\u0440\u0438 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0438 \u0442\u0435\u043c\u044b &#8212; \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c \u0435\u0435 \u0432 <code>localStorage<\/code><\/p>\n<pre><code class=\"javascript\">\/\/ src\/providers\/ThemeProvider.js import React from 'react' import { ThemeContext, themes } from 'src\/contexts\/ThemeContext'  const getTheme = () => {   const theme = `${window?.localStorage?.getItem('theme')}`   if (Object.values(themes).includes(theme)) return theme    const userMedia = window.matchMedia('(prefers-color-scheme: light)')   if (userMedia.matches) return themes.light    return themes.dark }  const ThemeProvider = ({ children }) => {   const [ theme, setTheme ] = React.useState(getTheme)    React.useEffect(() => {     document.documentElement.dataset.theme = theme     localStorage.setItem('theme', theme)   }, [ theme ])    return (     &lt;ThemeContext.Provider value={{ theme, setTheme }}>       {children}     &lt;\/ThemeContext.Provider>   ) }  export default ThemeProvider<\/code><\/pre>\n<p>\u0418 \u0442\u0435\u043f\u0435\u0440\u044c \u0437\u0430\u0439\u0434\u0435\u043c \u0432 \u043a\u043e\u0440\u043d\u0435\u0432\u043e\u0439 \u0444\u0430\u0439\u043b <code>index.js<\/code>. \u0422\u0443\u0442 \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u0442\u044c \u043d\u0430\u0448 <code>ThemeProvider<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u043e\u0431\u043e\u0440\u0430\u0447\u0438\u0432\u0430\u0435\u043c <code>Root<\/code>, \u0447\u0442\u043e\u0431\u044b \u0432\u0441\u0435, \u0447\u0442\u043e \u0432\u043d\u0443\u0442\u0440\u0438 \u0438\u043c\u0435\u043b\u043e \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u0442\u0435\u043c\u044b<\/p>\n<pre><code class=\"javascript\">\/\/ src\/index.js import React from 'react' import ReactDOM from 'react-dom' import reportWebVitals from '.\/reportWebVitals'  import ThemeProvider from '.\/providers\/ThemeProvider' \/\/ + import Root from '.\/components\/Root'  import '.\/index.scss'  ReactDOM.render(   &lt;React.StrictMode>     &lt;ThemeProvider>       &lt;Root \/>     &lt;\/ThemeProvider>   &lt;\/React.StrictMode>,   document.getElementById('root') ) ...<\/code><\/pre>\n<h3>\u041f\u0438\u0448\u0435\u043c \u043f\u0435\u0440\u0435\u043a\u043b\u044e\u0447\u0430\u0442\u0435\u043b\u044c<\/h3>\n<p>\u041e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043f\u0435\u0440\u0435\u043a\u043b\u044e\u0447\u0430\u0442\u0435\u043b\u044c \u0434\u043b\u044f \u0442\u0435\u043c\u044b. \u0412 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u044d\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0439 \u0442\u043e\u0433\u0433\u043b\u0435\u0440. \u041d\u0443 \u043f\u043e\u0447\u0442\u0438 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0439, \u043c\u044b \u0435\u0433\u043e \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0443\u043b\u0443\u0447\u0448\u0438\u043c, \u0447\u0442\u043e\u0431\u044b \u043d\u0435 \u0441\u043e\u0432\u0441\u0435\u043c \u0433\u0440\u0443\u0441\u0442\u043d\u043e \u0431\u044b\u043b\u043e.<\/p>\n<pre><code class=\"javascript\">\/\/ src\/components\/Toggle\/index.js import React from 'react' import styles from '.\/index.module.scss'  const Toggle = ({ value, onChange }) => (   &lt;label className={styles.switch} htmlFor=\"toggler\">     &lt;input       id=\"toggler\"       type=\"checkbox\"       onClick={onChange}       checked={value}       readOnly     \/>     &lt;span className={styles.slider} \/>     &lt;span className={styles.wave} \/>   &lt;\/label> )  export default Toggle<\/code><\/pre>\n<pre><code class=\"css\">\/\/ src\/components\/Toggle\/index.module.scss .root {   position: absolute;   top: 50%;   left: 50%;   width: 120px;   height: 50px;   transform: translate(-50%, -50%);   input {     display: none;   }   .slider {     position: absolute;     top: 0;     right: 0;     bottom: 0;     left: 0;     z-index: 1;     overflow: hidden;     background-color: #e74a42;     border-radius: 50px;     cursor: pointer;     transition: all 1.4s;     &amp;:before,     &amp;:after {       content: \"\";       position: absolute;       bottom: 5px;       left: 5px;       width: 40px;       height: 40px;       background-color: #ffffff;       border-radius: 30px;     }     &amp;:before {       transition: 0.4s;     }     &amp;:after {       transition: 0.5s;     }   }   .wave {     position: absolute;     top: 0;     left: 0;     width: 120px;     height: 50px;     border-radius: 40px;     transition: all 1.4s;     &amp;:after {       content: \"\";       position: absolute;       top: 3px;       left: 20%;       width: 60px;       height: 3px;       background: #ffffff;       border-radius: 100%;       opacity: 0.4;     }     &amp;:before {       content: \"\";       position: absolute;       top: 10px;       left: 30%;       width: 35px;       height: 2px;       background: #ffffff;       border-radius: 100%;       opacity: 0.3;     }   }   input:checked + .slider {     background-color: transparent;     &amp;:before,     &amp;:after {       transform: translateX(70px);     }   }   input:checked ~ .wave {     display: block;     background-color: #3398d9;   } }<\/code><\/pre>\n<p>\u041f\u043e\u0447\u0442\u0438 \u0432\u0441\u0435! \u041e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c  \u043d\u0430\u0448 <code>Toggle<\/code> \u043d\u0430 \u0433\u043b\u0430\u0432\u043d\u0443\u044e \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0443<\/p>\n<pre><code class=\"javascript\">\/\/ src\/components\/Root\/index.js import React from 'react' import { ThemeContext, themes } from '..\/..\/contexts\/ThemeContext' import Toggle from '..\/Toggle'  const Root = () => (   &lt;ThemeContext.Consumer>     {({ theme, setTheme }) => (       &lt;Toggle         onChange={() => {           if (theme === themes.light) setTheme(themes.dark)           if (theme === themes.dark) setTheme(themes.light)         }}         value={theme === themes.dark}       \/>     )}   &lt;\/ThemeContext.Consumer> )  export default Root<\/code><\/pre>\n<pre><code class=\"css\">\/\/ src\/index.scss :root[data-theme=\"light\"] {   --background-color: #fafafa; }  :root[data-theme=\"dark\"] {   --background-color: #2b3e51; }  body {   background: var(--background-color); }<\/code><\/pre>\n<p>\u0418 \u0447\u0442\u043e\u0431\u044b \u0432\u0441\u0435 \u0437\u0430\u0440\u0430\u0431\u043e\u0442\u0430\u043b\u043e \u043a\u0430\u043a \u043d\u0430\u0434\u043e, \u043d\u0443\u0436\u043d\u043e \u0437\u0430\u0434\u0430\u0442\u044c \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u0442\u0435\u043c\u044b. \u0417\u0430\u0434\u0430\u0432\u0430\u0442\u044c \u043c\u044b \u0438\u0445 \u0431\u0443\u0434\u0435\u043c \u0447\u0435\u0440\u0435\u0437 <code>css<\/code> \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0442\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u0432 <code>scss<\/code> \u043d\u0430\u043c \u043d\u0435 \u043f\u043e\u0434\u043e\u0439\u0434\u0443\u0442. <code>scss<\/code>  \u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0442\u0441\u044f \u0432 <code>css<\/code> \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0433\u043b\u0443\u043f\u043e, \u043e\u043d \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u043e\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0432\u043e \u0432\u0441\u0435\u0445 \u043c\u0435\u0441\u0442\u0430\u0445, \u0433\u0434\u0435 \u043e\u043d\u0438 \u0444\u0438\u0433\u0443\u0440\u0438\u0440\u0443\u044e\u0442.<\/p>\n<h3>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h3>\n<p>\u0412\u043d\u0435\u0434\u0440\u0438\u0442\u044c \u0442\u0435\u043c\u043d\u0443\u044e \u0442\u0435\u043c\u0443 \u0432 React \u043e\u043a\u0430\u0437\u0430\u043b\u043e\u0441\u044c \u043d\u0435 \u0442\u0430\u043a \u0443\u0436 \u0438 \u0441\u043b\u043e\u0436\u043d\u043e. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043c\u044b \u043f\u0440\u043e\u043a\u0438\u0434\u044b\u0432\u0430\u043b\u0438 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e \u0442\u0435\u043c\u0435 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c\u0430 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0435\u0441\u0442\u044c \u0432 <code>React<\/code>. \u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u0435\u0440\u0435\u043a\u043b\u044e\u0447\u0430\u0442\u0435\u043b\u044f \u043c\u043e\u0436\u043d\u043e \u0432\u0437\u044f\u0442\u044c \u0447\u0442\u043e \u0443\u0433\u043e\u0434\u043d\u043e, \u0434\u0435\u043b\u0438\u0442\u0435\u0441\u044c \u0441\u0432\u043e\u0438\u043c\u0438 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430\u043c\u0438 \u0432 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f\u0445! \u0416\u0434\u0443 \u043e\u0442 \u0432\u0430\u0441 \u0432\u0430\u0448\u0435\u0433\u043e \u043c\u043d\u0435\u043d\u0438\u044f \u043e \u0441\u0442\u0430\u0442\u044c\u0435 \u0438 \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u043e\u0432 \u043e \u0432\u0430\u0448\u0435\u043c \u043e\u043f\u044b\u0442\u0435 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0442\u0451\u043c\u043d\u043e\u0439 \u0442\u0435\u043c\u044b! <\/p>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"v-portal\" style=\"display:none;\"><\/div>\n<\/div>\n<p> <!----> <!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/656995\/\"> https:\/\/habr.com\/ru\/post\/656995\/<\/a><br \/><\/br><\/br><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-330959","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/330959","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=330959"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/330959\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=330959"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=330959"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=330959"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}