<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Angel on Medium]]></title>
        <description><![CDATA[Stories by Angel on Medium]]></description>
        <link>https://medium.com/@_angel.ho?source=rss-a91baa2a5e38------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*i9XOlW3gNLXe97RstBmktw@2x.jpeg</url>
            <title>Stories by Angel on Medium</title>
            <link>https://medium.com/@_angel.ho?source=rss-a91baa2a5e38------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 16 Nov 2026 05:57:58 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@_angel.ho/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[免費開源的超齊全 React SVG Icon 圖庫 — React Icons]]></title>
            <link>https://medium.com/itsoktomakemistakes/react-icons-svg-a5716db50590?source=rss-a91baa2a5e38------2</link>
            <guid isPermaLink="false">https://medium.com/p/a5716db50590</guid>
            <category><![CDATA[svg]]></category>
            <category><![CDATA[svg-icon]]></category>
            <category><![CDATA[react-icon]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[front-end-development]]></category>
            <dc:creator><![CDATA[Angel]]></dc:creator>
            <pubDate>Tue, 20 Apr 2021 02:02:32 GMT</pubDate>
            <atom:updated>2021-04-20T02:02:32.484Z</atom:updated>
            <content:encoded><![CDATA[<h3>免費開源的超齊全 React SVG Icon 圖庫 — React Icons</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/347/0*RC4s6uN9qdj5QZgC" /></figure><p>React Icons 囊括了目前最受歡迎的的各家主流 Icons，包括 Ant Design Icons、Bootstrap Icons、Font Awesome、Material Design Icons 等等，將各家 SVG 圖檔轉換為 React Component 的形式以 ES6 導入，可以任意搭配 Css 或 Styled Components 調整樣式。</p><ul><li>建立新的 Create React App</li></ul><pre>$ npx create-react-app my-app<br>$ cd my-app<br>$ yarn start</pre><ul><li>安裝 React Icons</li></ul><pre>$ npm install react-icons --save</pre><ul><li>進入 <a href="https://react-icons.github.io/react-icons/"><strong>React Icons 官網</strong></a><strong> </strong>查詢要引用的 Icons</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DorSPrkpWgyNPMku7sje3Q.png" /></figure><ul><li>以 React 的 Logo 為舉例</li></ul><pre>import { FaReact } from &quot;react-icons/fa&quot;;</pre><ul><li>直接將已經轉換成 React Component 的 SVG 圖檔加入即可, 調整 Style 的方式與 React Components 相同。</li></ul><pre>&lt;FaReact className=&quot;App-logo&quot; /&gt;</pre><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodesandbox.io%2Fembed%2F0jqmh&amp;display_name=CodeSandbox&amp;url=https%3A%2F%2Fcodesandbox.io%2Fs%2F0jqmh&amp;image=https%3A%2F%2Fcodesandbox.io%2Fapi%2Fv1%2Fsandboxes%2F0jqmh%2Fscreenshot.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=codesandbox" width="1000" height="500" frameborder="0" scrolling="no"><a href="https://medium.com/media/da359ed89ff21146db8094b3a1f595fc/href">https://medium.com/media/da359ed89ff21146db8094b3a1f595fc/href</a></iframe><blockquote>參考資料:<a href="https://react-icons.github.io/react-icons"> https://react-icons.github.io/react-icons</a></blockquote><pre>Say hello! 我是 Angel,</pre><pre>這裏的內容如果有幫到你，希望能獲得一些拍手作為鼓勵<br>工作上的合作歡迎隨時透過 Mail 聯繫我 contact@aneglho.design</pre><pre>– <br>Thanks for watching!</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a5716db50590" width="1" height="1" alt=""><hr><p><a href="https://medium.com/itsoktomakemistakes/react-icons-svg-a5716db50590">免費開源的超齊全 React SVG Icon 圖庫 — React Icons</a> was originally published in <a href="https://medium.com/itsoktomakemistakes">Its Ok to Make Mistakes</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[使用 React Intl 在 Create React App 建立多國語系靜態網頁]]></title>
            <link>https://medium.com/itsoktomakemistakes/react-intl-create-react-app-21d271df8056?source=rss-a91baa2a5e38------2</link>
            <guid isPermaLink="false">https://medium.com/p/21d271df8056</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[create-react-app]]></category>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[react-i18n]]></category>
            <category><![CDATA[react-intl]]></category>
            <dc:creator><![CDATA[Angel]]></dc:creator>
            <pubDate>Tue, 13 Apr 2021 02:01:17 GMT</pubDate>
            <atom:updated>2021-04-13T03:32:32.437Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9MHHtfdInmclAAOHXlWpCg.png" /></figure><p>React Intl 使用 React components 的方式來實踐 i18n context，可以輕易透過切換語言包來實作多語系網頁，並依據瀏覽器所在地顯示當地時間日期的格式。</p><blockquote><a href="#8a70">安裝 react-intl</a><em>：</em>在 Create React App 專案安裝 react-intl<br><a href="#98af">多語系文字</a><em>：</em>透過語言包更換<br><a href="#9421">多語系時間</a><em>：</em>根據 Browser 所在地語言切換</blockquote><h3>新專案安裝 react-intl</h3><ul><li>建立新的 Create React App</li></ul><pre>$ npx create-react-app my-app<br>$ cd my-app<br>$ yarn start</pre><ul><li>安裝 react-intl</li></ul><pre>$ npm i react-intl</pre><h3>多語系文字</h3><ul><li>在 App.js 引入 FormattedMessage 和 IntlProvider</li></ul><pre>import { FormattedMessage, IntlProvider } from &quot;react-intl&quot;;</pre><ul><li>將 IntlProvider 包在最外層，把要更改的文字使用FormattedMessage 編輯</li></ul><pre>import logo from &quot;./logo.svg&quot;;<br>import &quot;./App.css&quot;;<br>import { FormattedMessage, IntlProvider } from &quot;react-intl&quot;;</pre><pre>function App() {<br>  return (<br>    &lt;IntlProvider&gt;<br>      &lt;div className=&quot;App&quot;&gt;<br>        &lt;header className=&quot;App-header&quot;&gt;<br>          &lt;img src={logo} className=&quot;App-logo&quot; alt=&quot;logo&quot; /&gt;<br>          &lt;p&gt;<br>            &lt;FormattedMessage<br>              id=&quot;app.header&quot;<br>              defaultMessage=&quot;Edit src/App.js and save to reload.&quot;<br>            /&gt;<br>          &lt;/p&gt;<br>          &lt;a<br>            className=&quot;App-link&quot;<br>            href=&quot;https://reactjs.org&quot;<br>            target=&quot;_blank&quot;<br>            rel=&quot;noopener noreferrer&quot;<br>          &gt;<br>            &lt;FormattedMessage id=&quot;app.content&quot; defaultMessage=&quot;Learn React&quot; /&gt;<br>          &lt;/a&gt;<br>        &lt;/header&gt;<br>      &lt;/div&gt;<br>    &lt;/IntlProvider&gt;<br>  );<br>}</pre><pre>export default App;</pre><ul><li>產出正式環境所使用的 Public 資料夾後，並將語言包放在該資料夾，才能提供可動態抽換的語言包</li></ul><pre>$ yarn build</pre><ul><li>建立 lang 資料夾在 public 之下，並加入 en.json / cn.json / fr.json / jp.json 語言包</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/0*YPY67xaO8Wjij56s.png" /></figure><ul><li>en.json</li></ul><pre>{<br>&quot;app.header&quot; : &quot;編輯src / App.js並保存以重新加載。&quot; ,<br>&quot;app.content&quot; : &quot;學習 React&quot; <br>}</pre><ul><li>cn.json</li></ul><pre>{<br>&quot;app.header&quot; : &quot;編輯src / App.js並保存以重新加載。&quot; ,<br>&quot;app.content&quot; : &quot;學習 React&quot; <br>}</pre><ul><li>fr.json</li></ul><pre>{<br>    &quot;app.header&quot; : &quot;Modifiez les fichiers et enregistrez-les pour recharger&quot; ,<br>    &quot;app.content&quot; : &quot;Apprendre React&quot; <br>}</pre><ul><li>jp.json</li></ul><pre>{<br>    &quot;app.header&quot; : &quot;src / App.jsを編集し、保存して再読み込みします。&quot; ,<br>    &quot;app.content&quot; : &quot;Reactを学ぶ&quot; <br>}</pre><ul><li>用useState在頁面上加入語言切換的下拉式選單</li></ul><pre>const [lang, setLang] = useState(&#39;en&#39;)</pre><pre>&lt;select<br>      value={lang}<br>      onChange={(evt) =&gt; {<br>        setLang(evt.target.value);<br>      }}<br>    &gt;<br>      &lt;option value=&quot;en&quot;&gt;English&lt;/option&gt;<br>      &lt;option value=&quot;cn&quot;&gt;中文&lt;/option&gt;<br>      &lt;option value=&quot;fr&quot;&gt;Français&lt;/option&gt;<br>      &lt;option value=&quot;jp&quot;&gt;日本語&lt;/option&gt;<br>    &lt;/select&gt;</pre><ul><li>透過 React hooks useEffect使用 Async/Await function 來處理語言包的切換，並在 IntlProvider 設定 messages={locale}</li></ul><p>import React, { useState, useEffect } from &#39;react&#39;</p><pre>function App() {<br>  const [lang, setLang] = useState(&#39;en&#39;)<br>  const [locale, setLocale] = useState(undefined)</pre><pre>useEffect(async() =&gt; {<br>    const resp = await fetch(`./lang/${lang}.json`)<br>    const data = await resp.json()<br>    setLocale(data)<br>  },[lang])</pre><pre>return (<br>    &lt;IntlProvider <br>      messages={locale}<br>    &gt;<br>      &lt;div className=&quot;App&quot;&gt;<br>        &lt;header className=&quot;App-header&quot;&gt;<br>          &lt;img src={logo} className=&quot;App-logo&quot; alt=&quot;logo&quot; /&gt;<br>          &lt;div&gt;<br>            &lt;select<br>              value={lang}<br>              onChange={(evt) =&gt; {<br>                setLang(evt.target.value);<br>              }}<br>            &gt;<br>              &lt;option value=&quot;en&quot;&gt;English&lt;/option&gt;<br>              &lt;option value=&quot;cn&quot;&gt;中文&lt;/option&gt;<br>              &lt;option value=&quot;fr&quot;&gt;Français&lt;/option&gt;<br>              &lt;option value=&quot;jp&quot;&gt;日本語&lt;/option&gt;<br>            &lt;/select&gt;<br>          &lt;/div&gt;<br>          &lt;p&gt;<br>            &lt;FormattedMessage<br>              id=&quot;app.header&quot;<br>              defaultMessage=&quot;Edit src/App.js and save to reload.&quot;<br>            /&gt;<br>          &lt;/p&gt;<br>          &lt;a<br>            className=&quot;App-link&quot;<br>            href=&quot;https://reactjs.org&quot;<br>            target=&quot;_blank&quot;<br>            rel=&quot;noopener noreferrer&quot;<br>          &gt;<br>            &lt;FormattedMessage id=&quot;app.content&quot; defaultMessage=&quot;Learn React&quot; /&gt;<br>          &lt;/a&gt;<br>        &lt;/header&gt;<br>      &lt;/div&gt;<br>    &lt;/IntlProvider&gt;<br>  );<br>}</pre><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodesandbox.io%2Fembed%2Flfjr4&amp;display_name=CodeSandbox&amp;url=https%3A%2F%2Fcodesandbox.io%2Fs%2Flfjr4&amp;image=https%3A%2F%2Fcodesandbox.io%2Fapi%2Fv1%2Fsandboxes%2Flfjr4%2Fscreenshot.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=codesandbox" width="1000" height="500" frameborder="0" scrolling="no"><a href="https://medium.com/media/73c104b806970a834c9083a5c5698f6e/href">https://medium.com/media/73c104b806970a834c9083a5c5698f6e/href</a></iframe><h3>多語系時間</h3><ul><li>從 react-intl import FormattedDate ,會根據瀏覽器所在地變日期顯示方式</li></ul><pre>&lt;FormattedDate<br>  value={new Date()}<br>  year=&quot;numeric&quot;<br>  month=&quot;long&quot;<br>  day=&quot;numeric&quot;<br>  weekday=&quot;long&quot;<br>/&gt;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*94ym_9mh_gFjHmzG5Pvsxg.png" /></figure><ul><li><strong>以 Chrome 為例，在 Browser 切換語言系統:</strong><br>點擊Google Chrome 瀏覽器右上角三個點的按鈕 &gt; 設定 &gt; 進階 &gt; 語言 &gt; 英文（美國）&gt; 將 Google Chrome 的介面文字設定為這種語言</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/684/1*x_MS8_FG7IMHu4TYqevwxg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*g9HpQgvVMfVxU9eBL7HHAw.png" /></figure><blockquote>!!! 注意 BROWSER SUPPORT<br>FormattedDate 並沒有支援 IE11. 如果需要支援 IE11 可以參考<a href="https://formatjs.io/docs/react-intl/components/#formatteddateparts">官方文件</a>上的做法</blockquote><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodesandbox.io%2Fembed%2Fhib02&amp;display_name=CodeSandbox&amp;url=https%3A%2F%2Fcodesandbox.io%2Fs%2Fhib02&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=codesandbox" width="1000" height="500" frameborder="0" scrolling="no"><a href="https://medium.com/media/26970b5862d4fb22dd817afaf35f1f84/href">https://medium.com/media/26970b5862d4fb22dd817afaf35f1f84/href</a></iframe><blockquote>參考資料: <a href="https://formatjs.io/docs/react-intl/">https://formatjs.io/docs/react-intl/</a></blockquote><pre>Say hello! 我是 Angel,</pre><pre>這裏的內容如果有幫到你，希望能獲得一些拍手作為鼓勵<br>工作上的合作歡迎隨時透過 Mail 聯繫我 contact@aneglho.design</pre><pre>– <br>Thanks for watching!</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=21d271df8056" width="1" height="1" alt=""><hr><p><a href="https://medium.com/itsoktomakemistakes/react-intl-create-react-app-21d271df8056">使用 React Intl 在 Create React App 建立多國語系靜態網頁</a> was originally published in <a href="https://medium.com/itsoktomakemistakes">Its Ok to Make Mistakes</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[將 Create React App Deploy 到 Github Pages]]></title>
            <link>https://medium.com/itsoktomakemistakes/create-react-app-deploy-github-pages-95a62d29ca02?source=rss-a91baa2a5e38------2</link>
            <guid isPermaLink="false">https://medium.com/p/95a62d29ca02</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[github]]></category>
            <category><![CDATA[github-pages]]></category>
            <category><![CDATA[create-react-app]]></category>
            <category><![CDATA[front-end-development]]></category>
            <dc:creator><![CDATA[Angel]]></dc:creator>
            <pubDate>Tue, 06 Apr 2021 02:02:45 GMT</pubDate>
            <atom:updated>2021-04-12T03:44:36.366Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Ch7lC8F7c9mwL34X.jpg" /></figure><p>GitHub Pages 是 GitHub 提供的一個網頁代管服務，於2008年推出，搭配 Creact React App 可快速建置靜態網頁，推薦初學者用來客製化個人履歷或作品集。</p><blockquote><a href="#8a70">建立ＧitHup 新專案</a>： 使用 Create React App</blockquote><blockquote><a href="#3b7b">安裝 Githup Pages</a></blockquote><blockquote><a href="#4fb7">打包部署</a>：修改路徑</blockquote><h3>建立 Ｇithup 新專案</h3><ul><li>建立新的 Create React App</li></ul><pre>$ npx create-react-app my-app<br>$ cd my-app<br>$ yarn start</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/765/1*CrobI8Ent0B0shdbVGdlDw.png" /><figcaption>Create React App</figcaption></figure><ul><li>如果有安裝 <a href="https://desktop.github.com/">Github Desktop</a> ，可以從已經 連結到 Github 的 Github Desktop Gui 介面快速新增 Repository</li></ul><pre>File &gt; Add Local Repository &gt; choose &gt; “my-app”</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/224/1*1IrpWx45WeUeRyKsfabnXQ.png" /><figcaption>Add Local Repository on Github Desktop</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*uU6HcXf7oSVult4xc3Fvuw.png" /><figcaption>Add Local Repository on Github Desktop</figcaption></figure><h3>安裝 Githup Pages</h3><ul><li>安裝 gh-pages</li></ul><pre>$ yarn add gh-pages</pre><ul><li>在 Package.json 加入</li></ul><pre>&quot;scripts&quot;: {<br>  &quot;deploy&quot;: &quot;gh-pages -d build&quot;<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ej_6SM1qLMNqlr9hT10riQ.png" /></figure><ul><li>加入之後 git commit / git push 上 Github</li></ul><blockquote>！！！必須取消勾選 keep this code private 才能使用 Github Pages</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/964/1*bAPxSoPxrOUMijmW22JYSw.png" /></figure><h3>打包部署</h3><ul><li>產生 bundle 檔案</li></ul><pre>$ yarn build</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1023/1*Jbolda8G6-iGPRzwip8MAQ.png" /></figure><ul><li>將Code deploy上去</li></ul><pre>$ yarn deploy</pre><ul><li>進入 Github &gt; 專案的 Repository &gt; Settings 頁面 &gt; 下滑至 GitHub Pages &gt; 出現 Publish 的連結</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/910/1*ADHH60L0kh0HCDMU7BE32g.png" /></figure><blockquote>連結打開會呈現一片空白，因為路徑指向錯誤，此時從 Github Project 切換到 Branch <strong><em>gh-pages</em></strong> 找到 index.html 更改 css 及 js 的連結路徑</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/915/1*2EJuBwpxeh0NZwgtas2iMQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*peZjMayqWWJJ-mkCoHeLVQ.png" /></figure><pre>&lt;!doctype html&gt;<br>&lt;html lang=&quot;en&quot;&gt;</pre><pre>&lt;head&gt;<br>    .<br>    .<br>    .<br>    &lt;link rel=&quot;stylesheet&quot; href=&quot;/這裡加上repository名稱/styles/style.css&quot;&gt;<br>    &lt;link rel=&quot;stylesheet&quot; href=&quot;https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.2/css/bootstrap.min.css&quot;&gt;<br>    &lt;script src=&quot;https://maps.googleapis.com/maps/api/js?key=AIzaSyAq06l5RUVfib62IYRQacLc-KAy0XIWAVs&quot;&gt;&lt;/script&gt;<br>&lt;/head&gt;</pre><pre>&lt;body&gt;<br>    .<br>    .<br>    &lt;script src=&quot;/這裡加上repository名稱/static/js/1.59eea781.chunk.js&quot;&gt;&lt;/script&gt;<br>    &lt;script src=&quot;/這裡加上repository名稱/static/js/main.e99c9045.chunk.js&quot;&gt;&lt;/script&gt;<br>&lt;/body&gt;</pre><pre>&lt;/html&gt;</pre><ul><li>存檔後，等一段時間即可顯示</li></ul><blockquote>！！！如果要使用 Custom domain，則不需要處理連結路徑。</blockquote><pre>Say hello! 我是 Angel,</pre><pre>這裏的內容如果有幫到你，希望能獲得一些拍手作為鼓勵 <br>工作上的合作歡迎隨時透過 Mail 聯繫我 contact@aneglho.design</pre><pre>– <br>Thanks for watching!</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=95a62d29ca02" width="1" height="1" alt=""><hr><p><a href="https://medium.com/itsoktomakemistakes/create-react-app-deploy-github-pages-95a62d29ca02">將 Create React App Deploy 到 Github Pages</a> was originally published in <a href="https://medium.com/itsoktomakemistakes">Its Ok to Make Mistakes</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[建立公司內部 Private npm — Verdaccio — 實作 React Styled Components Library 安裝、打包、上傳與下載]]></title>
            <link>https://medium.com/itsoktomakemistakes/private-npm-verdaccio-react-styled-components-library-14e483c42356?source=rss-a91baa2a5e38------2</link>
            <guid isPermaLink="false">https://medium.com/p/14e483c42356</guid>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[verdaccio]]></category>
            <category><![CDATA[styled-components]]></category>
            <category><![CDATA[private-npm]]></category>
            <dc:creator><![CDATA[Angel]]></dc:creator>
            <pubDate>Tue, 04 Jun 2019 02:01:00 GMT</pubDate>
            <atom:updated>2021-04-12T07:48:08.464Z</atom:updated>
            <content:encoded><![CDATA[<h3>建立公司內部 Private NPM — Verdaccio — 實作 React Styled Components Library 安裝、打包、上傳與下載</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/0*yDwPQKrf9fXmhBpQ" /></figure><p>Private NPM 提供建立一套公司內部專屬 React Components layout library 的可能。Verdaccio 是一套輕量的 Private NPM proxy registry，當其他 Developer 要 import 各種客製化元件，只要在安裝後更新到最新的版本，即可無痛翻新整個 Layout。</p><blockquote><a href="#8a70">安裝流程</a>： <a href="https://verdaccio.org/">Vardaccio</a> 安裝、設定 registry、增加使用者</blockquote><blockquote><a href="#c564">打包流程</a>：排除不需要打包的部分、設定打包工具、svgr 轉 svg、搬移圖檔</blockquote><blockquote><a href="#d026">上傳與下載流程</a>：將 Library publish、 檔案太大時的設定</blockquote><h3>安裝流程</h3><ul><li>安裝 <a href="https://verdaccio.org/">Vardaccio</a></li></ul><pre>$ npm install --global verdaccio</pre><ul><li>設訂 Registry 到 localhost:4873</li></ul><pre>$ npm set registry <a href="http://localhost:4873/">http://localhost:4873/</a></pre><ul><li>可以在根目錄中的 .npmrc 裡面看到 registry=://localhost:4873/</li><li>此時 run verdaccio 後打開 <a href="http://localhost:4873/">http://localhost:4873/</a> 就可以看到在 local 能 login 的畫面</li></ul><pre>$ verdaccio</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*1pqimq7mqsEnRmTc.png" /></figure><ul><li>增加使用者 &gt; 輸入帳號、密碼和 email</li></ul><pre>$ npm adduser --registry  <a href="http://localhost:4873/">http://localhost:4873</a></pre><ul><li>回到 <a href="http://localhost:4873/">http://localhost:4873/</a> 登錄剛輸入的帳密即可</li></ul><h3>打包流程</h3><p>打開要包裝成 Library 的 React Layout 專案後</p><ul><li>增加一個 .npmignore 檔案把不需要打包進 Library 的東西「排除」</li></ul><pre>node_modules/<br>public<br>Reference<br>src</pre><ul><li>在 .gitignore 檔案中加上 Library 才不會一起 commit 進 Git</li></ul><pre>lib<br>.tmp</pre><ul><li>增加一個 .babelrc.js 檔案設定打包工具</li></ul><pre>module.exports = {<br>  env: {<br>    es: {<br>      presets: [<br>        [&#39;@babel/preset-env&#39;, { modules: false }],<br>        &#39;@babel/preset-react&#39;<br>      ],<br>      plugins: [<br>        [&#39;@babel/plugin-proposal-decorators&#39;, { legacy: true }],<br>        &#39;@babel/plugin-proposal-class-properties&#39;,<br>        &#39;@babel/plugin-proposal-do-expressions&#39;,<br>        &#39;@babel/plugin-proposal-export-default-from&#39;,<br>        &#39;@babel/plugin-proposal-export-namespace-from&#39;,<br>        &#39;@babel/plugin-proposal-function-bind&#39;,<br>        &#39;@babel/plugin-proposal-logical-assignment-operators&#39;,<br>        &#39;@babel/plugin-proposal-nullish-coalescing-operator&#39;,<br>        &#39;@babel/plugin-proposal-optional-chaining&#39;,<br>        [&#39;@babel/plugin-proposal-pipeline-operator&#39;, { proposal: &#39;minimal&#39; }],<br>        &#39;@babel/plugin-proposal-throw-expressions&#39;,<br>        &#39;@babel/plugin-syntax-dynamic-import&#39;,<br>        &#39;@babel/plugin-transform-runtime&#39;,<br>        [<br>          &#39;transform-rename-import&#39;,<br>          {<br>            original: &#39;(.*)/([^/]+)\\.svg$&#39;,<br>            replacement: (text, $1, $2) =&gt; {<br>              return (<br>                $1 + &#39;/&#39; + $2.replace(/(^|_)./g, s =&gt; s.slice(-1).toUpperCase())<br>              )<br>            }<br>          }<br>        ]<br>      ]<br>    }<br>  }<br>}</pre><ul><li>增加 svgrTemplate.js 檔案 (package.json file 會解釋)</li></ul><pre>const types = require(&#39;@babel/types&#39;)</pre><pre>function template(babelAPI, opts, values) {<br>  const componentName = types.identifier(&#39;ReactComponent&#39;)<br>  const exports = types.exportNamedDeclaration(null, [<br>    types.exportSpecifier(componentName, componentName)<br>  ])<br>  return babelAPI.template.ast`<br>    ${values.imports}<br>    const ${componentName} = (${values.props}) =&gt; ${values.jsx}<br>    ${exports}<br>  `<br>}</pre><pre>module.exports = template</pre><ul><li>在 package.json 將此版本設訂為第一版</li></ul><pre>&quot;version&quot;: &quot;0.1.0&quot;,</pre><ul><li>加上 lib 作為打包後輸出路徑</li></ul><pre>&quot;main&quot;: &quot;lib&quot;,<br>&quot;module&quot;: &quot;lib&quot;,</pre><ul><li>移除 package.json 上的 &quot;private&quot;: true, 讓專案變成可共用的</li><li>只留下不會與使用 Library 的 Project 衝突的 dependencies (避免影響安裝 project 的 dependency 衝突，假設兩邊都基於 React，但只要以使用 Library Project 的為主即可)</li></ul><pre>&quot;dependencies&quot;: {<br>  &quot;react-swipe&quot;: &quot;5.1.1&quot;,<br>  &quot;styled-components&quot;: &quot;^4.2.0&quot;,<br>  &quot;swipe-js-iso&quot;: &quot;2.0.0&quot;<br>}</pre><ul><li>其餘打包工具和不需要一起打包進 Library 裡放在 devDependencies</li></ul><pre>&quot;devDependencies&quot;: {<br>  &quot;@babel/cli&quot;: &quot;^7.4.4&quot;,<br>  &quot;@babel/core&quot;: &quot;^7.4.4&quot;,<br>  &quot;@babel/plugin-proposal-class-properties&quot;: &quot;7.2.3&quot;,<br>  &quot;@babel/plugin-proposal-decorators&quot;: &quot;7.2.3&quot;,<br>  &quot;@babel/plugin-proposal-do-expressions&quot;: &quot;7.0.0&quot;,<br>  &quot;@babel/plugin-proposal-export-default-from&quot;: &quot;7.0.0&quot;,<br>  &quot;@babel/plugin-proposal-export-namespace-from&quot;: &quot;^7.2.0&quot;,<br>  &quot;@babel/plugin-proposal-function-bind&quot;: &quot;7.0.0&quot;,<br>  &quot;@babel/plugin-proposal-logical-assignment-operators&quot;: &quot;7.0.0&quot;,<br>  &quot;@babel/plugin-proposal-nullish-coalescing-operator&quot;: &quot;7.0.0&quot;,<br>  &quot;@babel/plugin-proposal-optional-chaining&quot;: &quot;7.0.0&quot;,<br>  &quot;@babel/plugin-proposal-pipeline-operator&quot;: &quot;7.3.2&quot;,<br>  &quot;@babel/plugin-proposal-throw-expressions&quot;: &quot;7.0.0&quot;,<br>  &quot;@babel/plugin-syntax-dynamic-import&quot;: &quot;7.0.0&quot;,<br>  &quot;@babel/plugin-transform-runtime&quot;: &quot;7.2.0&quot;,<br>  &quot;@babel/preset-env&quot;: &quot;^7.4.4&quot;,<br>  &quot;@babel/preset-react&quot;: &quot;^7.0.0&quot;,<br>  &quot;@babel/runtime&quot;: &quot;7.4.2&quot;,<br>  &quot;@babel/types&quot;: &quot;^7.4.4&quot;,<br>  &quot;@svgr/cli&quot;: &quot;^4.2.0&quot;,<br>  &quot;babel-plugin-transform-rename-import&quot;: &quot;^2.3.0&quot;,<br>  &quot;cross-env&quot;: &quot;^5.2.0&quot;,<br>  &quot;node-sass&quot;: &quot;^4.11.0&quot;,<br>  &quot;prettier&quot;: &quot;^1.17.0&quot;,<br>  &quot;prop-types&quot;: &quot;^15.7.2&quot;,<br>  &quot;query-string&quot;: &quot;^6.4.2&quot;,<br>  &quot;react&quot;: &quot;^16.8.6&quot;,<br>  &quot;react-dom&quot;: &quot;^16.8.6&quot;,<br>  &quot;react-scripts&quot;: &quot;3.0.0&quot;,<br>  &quot;rimraf&quot;: &quot;^2.6.3&quot;<br>},</pre><p>其中，@svgr/cli 用來處理 svg 打包，而 svg 打包後會從 svg 轉為 React Components ，使用套件 babel-plugin-transform-rename-import 將匯入的 SVG 自動轉符合 import 的格式，svgr 自動把檔案轉為駝峰命名。</p><p>cross-env 處理跨平台設置 NODE_ENV 指令</p><p>rimraf 處理跨平台刪除指令</p><ul><li>在 scripts 設定 build:lib 指令時所需要打包的東西</li></ul><pre>&quot;scripts&quot;: {<br>  &quot;start&quot;: &quot;react-scripts start&quot;,<br>  &quot;build&quot;: &quot;react-scripts build&quot;,<br>  &quot;format&quot;: &quot;prettier --single-quote --no-semi --write \&quot;src/**/*.{js,jsx,scss}\&quot;&quot;,<br>  &quot;test&quot;: &quot;react-scripts test&quot;,<br>  &quot;eject&quot;: &quot;react-scripts eject&quot;,<br>  &quot;pre-clean&quot;: &quot;rimraf lib&quot;,<br>  &quot;post-clean&quot;: &quot;rimraf .tmp&quot;,<br>  &quot;build-js&quot;: &quot;cross-env NODE_ENV=es babel src .tmp --out-dir lib&quot;,<br>  &quot;build-svg&quot;: &quot;svgr src --template svgrTemplate.js --out-dir .tmp&quot;,<br>  &quot;cp:resources&quot;: &quot;cp -R src/img lib&quot;,<br>  &quot;build:lib&quot;: &quot;npm run pre-clean &amp;&amp; npm run build-svg &amp;&amp; npm run build-js &amp;&amp; npm run post-clean &amp;&amp; npm run cp:resources&quot;<br>},</pre><ul><li>其中，pre-clean 先清除上次打包出來的 lib 資料夾，然後開始轉 SVG，使用 svgr 打包後所有的 .svg 檔案會變 .js 檔案。</li><li>由於我們使用 import { ReactComponent as MyComponent } form &#39;./mySvg.svg&#39; 的語法引用 SVG，因此要使用 svgrTemplate.js 去改掉所有 .svg 轉出來的 .js 檔案來符合 import 的格式。</li><li>SVG 轉成 js 會產生 .tmp 資料夾，使用 Babel 把 src 與 .tmp 一起轉譯輸出到 lib 資料夾，並且修改引用 SVG 的路徑 (包含修改為駝峰命名)，從 import { ReactComponent as MyComponent } from &#39;../my_space.svg&#39; 變成 import { ReactComponent as MyComponent } from &#39;../MySpace&#39;。</li><li>輸出完成後刪掉 .tmp ， 接著才把 img 資料夾圖片資源複製到 lib 資料夾當中，讓 image 找得到。</li></ul><p>以下為完整的 package.json</p><pre>{<br>  &quot;name&quot;: &quot;myLibrary&quot;,<br>  &quot;version&quot;: &quot;0.1.0&quot;,<br>  &quot;main&quot;: &quot;lib&quot;,<br>  &quot;module&quot;: &quot;lib&quot;,<br>  &quot;dependencies&quot;: {<br>    &quot;react-swipe&quot;: &quot;5.1.1&quot;,<br>    &quot;styled-components&quot;: &quot;^4.2.0&quot;,<br>    &quot;swipe-js-iso&quot;: &quot;2.0.0&quot;<br>  },<br>  &quot;devDependencies&quot;: {<br>    &quot;@babel/cli&quot;: &quot;^7.4.4&quot;,<br>    &quot;@babel/core&quot;: &quot;^7.4.4&quot;,<br>    &quot;@babel/plugin-proposal-class-properties&quot;: &quot;7.2.3&quot;,<br>    &quot;@babel/plugin-proposal-decorators&quot;: &quot;7.2.3&quot;,<br>    &quot;@babel/plugin-proposal-do-expressions&quot;: &quot;7.0.0&quot;,<br>    &quot;@babel/plugin-proposal-export-default-from&quot;: &quot;7.0.0&quot;,<br>    &quot;@babel/plugin-proposal-export-namespace-from&quot;: &quot;^7.2.0&quot;,<br>    &quot;@babel/plugin-proposal-function-bind&quot;: &quot;7.0.0&quot;,<br>    &quot;@babel/plugin-proposal-logical-assignment-operators&quot;: &quot;7.0.0&quot;,<br>    &quot;@babel/plugin-proposal-nullish-coalescing-operator&quot;: &quot;7.0.0&quot;,<br>    &quot;@babel/plugin-proposal-optional-chaining&quot;: &quot;7.0.0&quot;,<br>    &quot;@babel/plugin-proposal-pipeline-operator&quot;: &quot;7.3.2&quot;,<br>    &quot;@babel/plugin-proposal-throw-expressions&quot;: &quot;7.0.0&quot;,<br>    &quot;@babel/plugin-syntax-dynamic-import&quot;: &quot;7.0.0&quot;,<br>    &quot;@babel/plugin-transform-runtime&quot;: &quot;7.2.0&quot;,<br>    &quot;@babel/preset-env&quot;: &quot;^7.4.4&quot;,<br>    &quot;@babel/preset-react&quot;: &quot;^7.0.0&quot;,<br>    &quot;@babel/runtime&quot;: &quot;7.4.2&quot;,<br>    &quot;@babel/types&quot;: &quot;^7.4.4&quot;,<br>    &quot;@svgr/cli&quot;: &quot;^4.2.0&quot;,<br>    &quot;babel-plugin-transform-rename-import&quot;: &quot;^2.3.0&quot;,<br>    &quot;cross-env&quot;: &quot;^5.2.0&quot;,<br>    &quot;mathjs&quot;: &quot;^5.9.0&quot;,<br>    &quot;node-sass&quot;: &quot;^4.11.0&quot;,<br>    &quot;prettier&quot;: &quot;^1.17.0&quot;,<br>    &quot;prop-types&quot;: &quot;^15.7.2&quot;,<br>    &quot;query-string&quot;: &quot;^6.4.2&quot;,<br>    &quot;react&quot;: &quot;^16.8.6&quot;,<br>    &quot;react-dom&quot;: &quot;^16.8.6&quot;,<br>    &quot;react-scripts&quot;: &quot;3.0.0&quot;,<br>    &quot;rimraf&quot;: &quot;^2.6.3&quot;<br>  },<br>  &quot;scripts&quot;: {<br>    &quot;start&quot;: &quot;react-scripts start&quot;,<br>    &quot;build&quot;: &quot;react-scripts build&quot;,<br>    &quot;format&quot;: &quot;prettier --single-quote --no-semi --write \&quot;src/**/*.{js,jsx,scss}\&quot;&quot;,<br>    &quot;test&quot;: &quot;react-scripts test&quot;,<br>    &quot;eject&quot;: &quot;react-scripts eject&quot;,<br>    &quot;pre-clean&quot;: &quot;rimraf lib&quot;,<br>    &quot;post-clean&quot;: &quot;rimraf .tmp&quot;,<br>    &quot;build-js&quot;: &quot;cross-env NODE_ENV=es babel src .tmp --out-dir lib&quot;,<br>    &quot;build-svg&quot;: &quot;svgr src --template svgrTemplate.js --out-dir .tmp&quot;,<br>    &quot;cp:resources&quot;: &quot;cp -R src/img lib&quot;,<br>    &quot;build:lib&quot;: &quot;npm run pre-clean &amp;&amp; npm run build-svg &amp;&amp; npm run build-js &amp;&amp; npm run post-clean &amp;&amp; npm run cp:resources&quot;<br>  },<br>  &quot;eslintConfig&quot;: {<br>    &quot;extends&quot;: &quot;react-app&quot;<br>  },<br>  &quot;browserslist&quot;: [<br>    &quot;&gt;0.2%&quot;,<br>    &quot;not dead&quot;,<br>    &quot;not ie &lt;= 11&quot;,<br>    &quot;not op_mini all&quot;<br>  ]<br>}</pre><ul><li>執行 yarn 重新安裝一次 package.json</li></ul><pre>$ yarn</pre><ul><li>更改 img 路徑從 (因為打包沒辦法 import 資料夾的 index，所以要改為直接 import index 檔案)</li></ul><p>../img -&gt; ../img/index</p><p>../../img -&gt; ../../img/index</p><ul><li>開始 build lib 資料夾</li></ul><pre>$ yarn run build:lib</pre><p>完成後後準備上傳第一版的 Library</p><h3>上傳與下載流程</h3><ul><li>查看目前在哪個 registry</li></ul><pre>$ npm get registry</pre><ul><li>如果還在 <a href="http://localhost:4873/">http://localhost:4873/</a> 將其設定要上傳的 registry 位置</li></ul><pre>$ npm set registry on http://111.11.11.111</pre><ul><li>將準備好的 Library上傳到 private NPM</li></ul><pre>$ npm publish --registry http://111.11.11.111</pre><ul><li>如果上傳錯誤，要移除上傳錯誤的 Library</li></ul><pre>$ npm unpublish --force myLibrary</pre><ul><li>如果出現 npm ERR! request entity too large 檔案太大的訊息<br>可以下</li></ul><pre>$ verdaccio</pre><p>就會出現 config file — C:\Users\angel.ho.config\verdaccio\config.yaml<br>打開檔案加入 max_body_size 在檔案中</p><pre>max_body_size: 1000mb</pre><p>然後停掉 verdaccio 再重新 run 即可 publish 更大尺寸的 lib</p><ul><li>上傳完成後即可在 <a href="http://111.11.11.111/">http://111.11.11.111</a> 看到 lib 這是第幾版的 lib</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*7G750EKSpFNYP2zh.png" /></figure><ul><li>新專案準備好 React 環境之後 接著在新的空資料夾安裝此 Library</li></ul><pre>$ yarn add myLibrary</pre><ul><li>此時即可完成 Components import</li></ul><pre>import React from &#39;react&#39;;<br>import { Page } from &#39;myLibrary/lib/components/page&#39;<br>function App() {<br>  return (<br>    &lt;div className=&quot;App&quot;&gt;<br>      &lt;ResetStyle/&gt;<br>      &lt;GlobalStyle/&gt;<br>      &lt;Page/&gt;<br>    &lt;/div&gt;<br>  );<br>}<br>export default App;</pre><ul><li>久未登入記得重run npm login 才能更新 Library</li><li>如果 Project 被 registry 咬住，進入code ~/.npmrc 去確認目前所在 registry</li></ul><pre>Say hello! 我是 Angel,</pre><pre>這裏的內容如果有幫到你，希望能獲得一些拍手作為鼓勵 <br>工作上的合作歡迎隨時透過 Mail 聯繫我 contact@aneglho.design</pre><pre>– <br>Thanks for watching!</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=14e483c42356" width="1" height="1" alt=""><hr><p><a href="https://medium.com/itsoktomakemistakes/private-npm-verdaccio-react-styled-components-library-14e483c42356">建立公司內部 Private npm — Verdaccio — 實作 React Styled Components Library 安裝、打包、上傳與下載</a> was originally published in <a href="https://medium.com/itsoktomakemistakes">Its Ok to Make Mistakes</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[在 React Styled-Components 利用 Checkbox 的 checked 和 onChange 客製 Radio Button]]></title>
            <link>https://medium.com/itsoktomakemistakes/react-styled-component-checkbox-radio-button-checked-onchange-7dc11f281d4e?source=rss-a91baa2a5e38------2</link>
            <guid isPermaLink="false">https://medium.com/p/7dc11f281d4e</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[styled-components]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[css]]></category>
            <category><![CDATA[front-end-development]]></category>
            <dc:creator><![CDATA[Angel]]></dc:creator>
            <pubDate>Tue, 09 Apr 2019 02:01:02 GMT</pubDate>
            <atom:updated>2021-04-12T07:42:24.618Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/308/1*JCPewkmmDlom8AaZzz5uHg.png" /></figure><h3>Radio Button</h3><h4>第一步：先確定 React Styled-Component 開發環境設定完成</h4><blockquote>可以參考：<a href="https://medium.com/itsoktomakemistakes/create-react-app-react-styled-component-sass-ccb0e6b182bc"><strong>使用 Create-React-App 建構 React Styled-Components 及 Sass 開發環境</strong></a></blockquote><p><a href="https://medium.com/itsoktomakemistakes/create-react-app-react-styled-component-sass-ccb0e6b182bc">使用 Create-React-App 建構 React Styled-Components 及 Sass 開發環境</a></p><h4>第二步： type 及 name</h4><p>在 Template 用選項 Item 將RadioButton和 RadioButtonLabel包在一起，並在 RadioButton 標註 type 及 name。</p><pre>import React from &quot;react&quot;;<br>import ReactDOM from &quot;react-dom&quot;;<br>import styled from &quot;styled-components&quot;;</pre><pre>const App = () =&gt; {<br>  return (<br>    &lt;Wrapper&gt;<br>      &lt;Item&gt;<br>        &lt;RadioButton type=&quot;radio&quot; name=&quot;radio&quot; /&gt;<br>        &lt;RadioButtonLabel /&gt;<br>        &lt;div&gt;Auto accept better price only&lt;/div&gt;<br>      &lt;/Item&gt;<br>      &lt;Item&gt;<br>        &lt;RadioButton type=&quot;radio&quot; name=&quot;radio&quot; /&gt;<br>        &lt;RadioButtonLabel /&gt;<br>        &lt;div&gt;Auto accept any price change&lt;/div&gt;<br>      &lt;/Item&gt;<br>      &lt;Item&gt;<br>        &lt;RadioButton type=&quot;radio&quot; name=&quot;radio&quot; /&gt;<br>        &lt;RadioButtonLabel /&gt;<br>        &lt;div&gt;Never auto accept a price change&lt;/div&gt;<br>      &lt;/Item&gt;<br>    &lt;/Wrapper&gt;<br>  );<br>};</pre><pre>const rootElement = document.getElementById(&quot;root&quot;);<br>ReactDOM.render(&lt;App /&gt;, rootElement);</pre><h4>第三步：Style label 及 Button</h4><p>RadioButtonLabel 使用 label 畫出沒有點擊時空心的按鈕狀態使用 label，RadioButton 使用 input 來製作點擊切換，設定透明度為0，大小與 RadioButtonLabel 一致，並將 RadioButton 與 RadioButtonLabel 重疊。!!!注意：RadioButton 的位置必須在 RadioButtonLabel 之前，才能夠點擊該按鈕。因此要在 RadioButton 加上 z-index: 1;。</p><pre>const Wrapper = styled.div`<br>  height: auto;<br>  width: 100%;<br>  padding: 0px 16px 24px 16px;<br>  box-sizing: border-box;<br>`;</pre><pre>const Item = styled.div`<br>  display: flex;<br>  align-items: center;<br>  height: 48px;<br>  position: relative;<br>`;</pre><pre>const RadioButtonLabel = styled.label`<br>  position: absolute;<br>  top: 25%;<br>  left: 4px;<br>  width: 24px;<br>  height: 24px;<br>  border-radius: 50%;<br>  background: white;<br>  border: 1px solid #bebebe;<br>`;<br>const RadioButton = styled.input`<br>  opacity: 0;<br>  z-index: 1;<br>  border-radius: 50%;<br>  width: 24px;<br>  height: 24px;<br>  margin-right: 10px;<br>`;</pre><h4>第四步：「:checked」</h4><p>設定點擊 CheckBox 的時候必須從 RadioButton 以:checked 搭配+控制${RadioButtonLabel}去切換背景顏色。</p><pre>const RadioButton = styled.input`<br>  opacity: 0;<br>  z-index: 1;<br>  border-radius: 50%;<br>  width: 24px;<br>  height: 24px;<br>  margin-right: 10px;<br>  &amp;:checked + ${RadioButtonLabel} {<br>    background: #db7290;<br>    border: 1px solid #db7290;<br>  }<br>`;</pre><h4>第五步：CSS 偽元素</h4><p>使用 CSS 偽元素製作出可以切換的圓形按鈕於 RadioButton。</p><pre>const RadioButton = styled.input`<br>  opacity: 0;<br>  z-index: 1;<br>  border-radius: 50%;<br>  width: 24px;<br>  height: 24px;<br>  margin-right: 10px;<br>  &amp;:checked + ${RadioButtonLabel} {<br>    background: #db7290;<br>    border: 1px solid #db7290;<br>    &amp;::after {<br>      content: &quot;&quot;;<br>      display: block;<br>      border-radius: 50%;<br>      width: 12px;<br>      height: 12px;<br>      margin: 6px;<br>      box-shadow: 1px 3px 3px 1px rgba(0, 0, 0, 0.1);<br>      background: white;<br>    }<br>  }<br>`;</pre><h4>第六步：Mouse Over 效果</h4><p>設定滑鼠的 hover 效果不能直接在 RadioButtonLabel 控制，因為 RadioButton 在 RadioButtonLabel 的上一層。必須在 RadioButton 使用+控制CheckBoxLabel去切換背景顏色。</p><pre>const RadioButton = styled.input`<br>  opacity: 0;<br>  z-index: 1;<br>  border-radius: 50%;<br>  width: 24px;<br>  height: 24px;<br>  }<br>  &amp;:hover ~ ${RadioButtonLabel}{<br>    background: #bebebe;<br>    &amp;::after {<br>      content: &quot;&quot;;<br>      display: block;<br>      border-radius: 50%;<br>      width: 12px;<br>      height: 12px;<br>      margin: 6px;<br>      background: #eeeeee;<br>    }<br>  }<br>  &amp;:checked + ${RadioButtonLabel} {<br>    background: #db7290;<br>    border: 1px solid #db7290;<br>    Z-index: 3;<br>    &amp;::after {<br>      content: &quot;&quot;;<br>      display: block;<br>      border-radius: 50%;<br>      width: 12px;<br>      height: 12px;<br>      margin: 6px;<br>      box-shadow: 1px 3px 3px 1px rgba(0, 0, 0, 0.1);<br>      background: white;<br>    }<br>  }<br>`</pre><h4>第七步：設定預設狀態</h4><p>在 Template 用 React Hooks 的 useState 給予初始狀態，並設定不同 RadioButton 的 Value 及 checked 的時候 select 到哪一個 Button。</p><pre>const { useState } = React;</pre><pre>const App = () =&gt; {<br>  const [select, setSelect] = useState(&quot;betterPriceOnly&quot;);<br>  return (<br>    &lt;Wrapper&gt;<br>      &lt;Item&gt;<br>        &lt;RadioButton<br>          type=&quot;radio&quot;<br>          name=&quot;radio&quot;<br>          value=&quot;betterPriceOnly&quot;<br>          checked={select === &quot;betterPriceOnly&quot;}<br>        /&gt;<br>        &lt;RadioButtonLabel /&gt;<br>        &lt;div&gt;Auto accept better price only&lt;/div&gt;<br>      &lt;/Item&gt;<br>      &lt;Item&gt;<br>        &lt;RadioButton<br>          type=&quot;radio&quot;<br>          name=&quot;radio&quot;<br>          value=&quot;anyPriceChange&quot;<br>          checked={select === &quot;anyPriceChange&quot;}<br>        /&gt;<br>        &lt;RadioButtonLabel /&gt;<br>        &lt;div&gt;Auto accept any price change&lt;/div&gt;<br>      &lt;/Item&gt;<br>      &lt;Item&gt;<br>        &lt;RadioButton<br>          type=&quot;radio&quot;<br>          name=&quot;radio&quot;<br>          value=&quot;neverAutoAccept&quot;<br>          checked={select === &quot;neverAutoAccept&quot;}<br>        /&gt;<br>        &lt;RadioButtonLabel /&gt;<br>        &lt;div&gt;Never auto accept a price change&lt;/div&gt;<br>      &lt;/Item&gt;<br>    &lt;/Wrapper&gt;<br>  );<br>};</pre><h4>第八步：實作 onChange 事件</h4><p>實作 onChange 事件，讓 event.target.value 在每一次 checked 發生時改變</p><pre>const App = () =&gt; {<br>  const [select, setSelect] = useState(&quot;betterPriceOnly&quot;);<br>  const handleSelectChange = event =&gt; {<br>    const value = event.target.value;<br>    setSelect(value);<br>  };<br>  return (<br>    &lt;Wrapper&gt;<br>      &lt;Item&gt;<br>        &lt;RadioButton<br>          type=&quot;radio&quot;<br>          name=&quot;radio&quot;<br>          value=&quot;betterPriceOnly&quot;<br>          checked={select === &quot;betterPriceOnly&quot;}<br>          onChange={event =&gt; handleSelectChange(event)}<br>        /&gt;<br>        &lt;RadioButtonLabel /&gt;<br>        &lt;div&gt;Auto accept better price only&lt;/div&gt;<br>      &lt;/Item&gt;<br>      &lt;Item&gt;<br>        &lt;RadioButton<br>          type=&quot;radio&quot;<br>          name=&quot;radio&quot;<br>          value=&quot;anyPriceChange&quot;<br>          checked={select === &quot;anyPriceChange&quot;}<br>          onChange={event =&gt; handleSelectChange(event)}<br>        /&gt;<br>        &lt;RadioButtonLabel /&gt;<br>        &lt;div&gt;Auto accept any price change&lt;/div&gt;<br>      &lt;/Item&gt;<br>      &lt;Item&gt;<br>        &lt;RadioButton<br>          type=&quot;radio&quot;<br>          name=&quot;radio&quot;<br>          value=&quot;neverAutoAccept&quot;<br>          checked={select === &quot;neverAutoAccept&quot;}<br>          onChange={event =&gt; handleSelectChange(event)}<br>        /&gt;<br>        &lt;RadioButtonLabel /&gt;<br>        &lt;div&gt;Never auto accept a price change&lt;/div&gt;<br>      &lt;/Item&gt;<br>    &lt;/Wrapper&gt;<br>  );<br>};</pre><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodesandbox.io%2Fembed%2Fymwo5419yv%3Ffontsize%3D14&amp;url=https%3A%2F%2Fcodesandbox.io%2Fs%2Fymwo5419yv%3Ffontsize%3D14&amp;image=https%3A%2F%2Fcodesandbox.io%2Fapi%2Fv1%2Fsandboxes%2Fymwo5419yv%2Fscreenshot.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=codesandbox" width="1000" height="500" frameborder="0" scrolling="no"><a href="https://medium.com/media/c2ef915902a67d08f49d1f1134d2e5bb/href">https://medium.com/media/c2ef915902a67d08f49d1f1134d2e5bb/href</a></iframe><pre>Say hello! 我是 Angel,</pre><pre>這裏的內容如果有幫到你，希望能獲得一些拍手作為鼓勵 <br>工作上的合作歡迎隨時透過 Mail 聯繫我 contact@aneglho.design</pre><pre>– <br>Thanks for watching!</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7dc11f281d4e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/itsoktomakemistakes/react-styled-component-checkbox-radio-button-checked-onchange-7dc11f281d4e">在 React Styled-Components 利用 Checkbox 的 checked 和 onChange 客製 Radio Button</a> was originally published in <a href="https://medium.com/itsoktomakemistakes">Its Ok to Make Mistakes</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[React 搭配  Styled-Components 用 Checkbox 客製 Toggle Switch Button]]></title>
            <link>https://medium.com/itsoktomakemistakes/react-styled-components-checkbox-toggle-switch-button-4dec87b6f1a4?source=rss-a91baa2a5e38------2</link>
            <guid isPermaLink="false">https://medium.com/p/4dec87b6f1a4</guid>
            <category><![CDATA[styled-components]]></category>
            <category><![CDATA[css]]></category>
            <category><![CDATA[toggle-button]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[front-end-development]]></category>
            <dc:creator><![CDATA[Angel]]></dc:creator>
            <pubDate>Wed, 03 Apr 2019 02:01:01 GMT</pubDate>
            <atom:updated>2021-04-12T07:42:09.540Z</atom:updated>
            <content:encoded><![CDATA[<h3>React 搭配 Styled-Components 用 Checkbox 客製 Toggle Switch Button</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/0*e75IyARKKlczgvmJ.jpg" /></figure><h3>Toggle Switch Button</h3><h4>第一步：先確定 React Styled-Component 開發環境設定完成</h4><blockquote>可以參考：<a href="https://medium.com/itsoktomakemistakes/create-react-app-react-styled-component-sass-ccb0e6b182bc"><strong>使用 Create-React-App 建構 React Styled-Components 及 Sass 開發環境</strong></a></blockquote><p><a href="https://medium.com/itsoktomakemistakes/create-react-app-react-styled-component-sass-ccb0e6b182bc">使用 Create-React-App 建構 React Styled-Components 及 Sass 開發環境</a></p><h4>第二步：在 Template 使用 Wrapper 將 Checkbox 和 CheckBoxLabel 包在一起，在 CheckBox type 為 checkbox，以及任意 id， 讓 CheckBoxLabel 可以指向該 id。</h4><blockquote>!!! 在 CheckBoxLabel 一般於 html 使用 for 在 React 要使用 htmlFor 取代</blockquote><pre>import React from &quot;react&quot;;<br>import ReactDOM from &quot;react-dom&quot;;<br>import styled from &quot;styled-components&quot;;</pre><pre>const App = () =&gt; {<br>  return (<br>    &lt;div&gt;<br>      &lt;CheckBoxWrapper&gt;<br>        &lt;CheckBox id=&quot;checkbox&quot; type=&quot;checkbox&quot;/&gt;<br>        &lt;CheckBoxLabel htmlFor=&quot;checkbox&quot;/&gt;<br>      &lt;/CheckBoxWrapper&gt;<br>    &lt;/div&gt;<br>  )<br>}</pre><pre><br>const rootElement = document.getElementById(&quot;root&quot;);<br>ReactDOM.render(&lt;App /&gt;, rootElement);</pre><h4>第三步：CheckBoxLabel 的部分，使用 label 畫出 Toggle Switch Button 的外形，CheckBox 使用 input 來製作點擊切換，設定透明度為 0，大小與 CheckBoxLabel 一致，並將 CheckBox 與 CheckBoxLabel 重疊。</h4><pre>const CheckBoxWrapper = styled.div`<br>   position: relative;<br>`<br>const CheckBoxLabel = styled.label`<br>    position: absolute;<br>    top: 0;<br>    left: 0;<br>    width: 42px;<br>    height: 26px;<br>    border-radius: 15px;<br>    background: #BEBEBE;<br>    cursor: pointer;<br>`;<br>const CheckBox = styled.input`<br>    opacity: 0;<br>    z-index:1;<br>    border-radius: 15px;<br>    width: 42px;<br>    height: 26px;<br>`;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/99/1*EIrEHb8TTIfhcglnUx81Bw.png" /></figure><p>設定點擊 CheckBox 的時候切換背景顏色。</p><pre>const CheckBox = styled.input`<br>    opacity: 0;<br>    z-index:1;<br>    border-radius: 15px;<br>    width: 42px;<br>    height: 26px;<br>  &amp;:checked + ${CheckBoxLabel} {<br>    background: #4FBE79;<br>  }<br>`;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/99/1*gWUwipaPKG9uqB-ZEXxl9A.png" /></figure><p>使用 CSS 偽元素製作出可以切換的圓形按鈕於 CheckBoxLabel 及 CheckBox。並設定切換轉換的 transition 秒數。</p><pre>const CheckBoxWrapper = styled.div`<br>  position: relative;<br>`;<br>const CheckBoxLabel = styled.label`<br>  position: absolute;<br>  top: 0;<br>  left: 0;<br>  width: 42px;<br>  height: 26px;<br>  border-radius: 15px;<br>  background: #bebebe;<br>  cursor: pointer;<br>  &amp;::after {<br>    content: &quot;&quot;;<br>    display: block;<br>    border-radius: 50%;<br>    width: 18px;<br>    height: 18px;<br>    margin: 3px;<br>    background: #ffffff;<br>    box-shadow: 1px 3px 3px 1px rgba(0, 0, 0, 0.2);<br>    transition: 0.2s;<br>  }<br>`;<br>const CheckBox = styled.input`<br>  opacity: 0;<br>  z-index: 1;<br>  border-radius: 15px;<br>  width: 42px;<br>  height: 26px;<br>  &amp;:checked + ${CheckBoxLabel} {<br>    background: #4fbe79;<br>    &amp;::after {<br>      content: &quot;&quot;;<br>      display: block;<br>      border-radius: 50%;<br>      width: 18px;<br>      height: 18px;<br>      margin-left: 21px;<br>      transition: 0.2s;<br>    }<br>  }<br>`;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/210/1*Qess9XhDzhRLJhZvJCrTsQ.png" /></figure><p>輸出後完成</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodesandbox.io%2Fembed%2F6v7n1vr8yn%3Ffontsize%3D14&amp;url=https%3A%2F%2Fcodesandbox.io%2Fs%2F6v7n1vr8yn%3Ffontsize%3D14&amp;image=https%3A%2F%2Fcodesandbox.io%2Fapi%2Fv1%2Fsandboxes%2F6v7n1vr8yn%2Fscreenshot.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=codesandbox" width="1000" height="500" frameborder="0" scrolling="no"><a href="https://medium.com/media/6473d971c323bdf9069481ca64cc1910/href">https://medium.com/media/6473d971c323bdf9069481ca64cc1910/href</a></iframe><pre>Say hello! 我是 Angel,</pre><pre>這裏的內容如果有幫到你，希望能獲得一些拍手作為鼓勵 <br>工作上的合作歡迎隨時透過 Mail 聯繫我 contact@aneglho.design</pre><pre>– <br>Thanks for watching!</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4dec87b6f1a4" width="1" height="1" alt=""><hr><p><a href="https://medium.com/itsoktomakemistakes/react-styled-components-checkbox-toggle-switch-button-4dec87b6f1a4">React 搭配  Styled-Components 用 Checkbox 客製 Toggle Switch Button</a> was originally published in <a href="https://medium.com/itsoktomakemistakes">Its Ok to Make Mistakes</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[在 React Styled-Components 透過 ThemeProvider 來更換網頁色彩主題樣式]]></title>
            <link>https://medium.com/itsoktomakemistakes/%E5%9C%A8-react-styled-components-%E9%80%8F%E9%81%8E-themeprovider-%E4%BE%86%E6%9B%B4%E6%8F%9B%E7%B6%B2%E9%A0%81%E8%89%B2%E5%BD%A9%E4%B8%BB%E9%A1%8C%E6%A8%A3%E5%BC%8F-62be72b9c7ea?source=rss-a91baa2a5e38------2</link>
            <guid isPermaLink="false">https://medium.com/p/62be72b9c7ea</guid>
            <category><![CDATA[themes]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[styled-components]]></category>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Angel]]></dc:creator>
            <pubDate>Wed, 27 Mar 2019 02:01:00 GMT</pubDate>
            <atom:updated>2021-04-12T07:41:50.847Z</atom:updated>
            <content:encoded><![CDATA[<h3>在 React-Styled Components 透過 ThemeProvider 來更換網頁色彩主題樣式</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*uLJ5aKcArjQhd72c" /><figcaption>Photo by <a href="https://unsplash.com/@russn_fckr?utm_source=medium&amp;utm_medium=referral">russn_fckr</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><blockquote><em>Styled-components 提供了一個 </em><em>&lt;ThemeProvider&gt;的外層 Component 來實踐換網站主題設計的系統。 Styled-components 使用了 React context API，讓我們想要的主題設定(像是顏色</em>、<em>按鈕</em>、<em>形狀)可以不須倚賴Props一層一層往下，在Render時直接傳到整個 App 每一個 Components 及 Styled-components。</em></blockquote><blockquote>藉由 <em>ThemeProvider </em>可以簡單抽換全域所需要使用的主題樣式,像是電商要在不同節慶切換網站主題色彩,跟著活動「換皮」的遊戲網頁,都非常適合使用<em>Styled-components</em>來實踐。</blockquote><h4>第一步：將 ThemeProvider 從 Styled-components 中引入</h4><pre>import React, { Component } from &#39;react&#39;;<br>import styled from &#39;styled-components&#39;<br>import { ThemeProvider } from &quot;styled-components&quot;;</pre><h4>第二步：建立包含 Button 的 Class Component，並設定初始 Theme 為 DefaultTheme</h4><pre>class App extends Component {建立 包含 的 的 的 Components 初始 為 為 為 為 DefaultTheme</pre><pre>class App extends Component {<br>  constructor() {<br>    super();<br>    this.state = {<br>      Theme: DefaultTheme<br>    };<br>  }<br>  render() {<br>    return (<br>      &lt;div className=&quot;App&quot;&gt;<br>          &lt;div&gt;<br>            &lt;Button&gt;Normal&lt;/Button&gt;<br>            &lt;Button&gt;Themed&lt;/Button&gt;<br>          &lt;/div&gt;<br>      &lt;/div&gt;<br>    );<br>  }<br>}</pre><pre>export default App;</pre><h4>第三 步：用 Styled-components 設定 Button</h4><pre>const Button = styled.div`<br>  font-size: 1em;<br>  margin: 1em;<br>  padding: 0.25em 2em;<br>  border-radius: 3px;<br>  display: inline-block;  <br>  color: black;<br>  border: 2px solid black;<br>  background-color: white;<br>`;</pre><p>並使用 props.theme 的方式來改掉顏色設定</p><pre>color: ${props =&gt; props.theme.fontColor};<br>  border: 2px solid ${props =&gt; props.theme.borderColor};<br>  background-color: ${props =&gt; props.theme.backgroundColor};</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/319/0*-2RgI3-uEwmTPEKF.png" /></figure><h4>第四 步：設定色彩主題</h4><pre>const DefaultTheme = {<br>  backgroundColor: &#39;white&#39;,<br>  fontColor: &quot;#33997a&quot;,<br>  borderColor: &quot;#33997a&quot;<br>}<br>const PinkTheme = {<br>  backgroundColor: &#39;#DB7290&#39;,<br>  fontColor: &quot;white&quot;,<br>  borderColor: &quot;#ffd7e8&quot;<br>};</pre><h4>第五步：將 Template 中的第二顆 Button 用 &lt;ThemeProvider&gt;&lt;/ThemeProvider&gt; 包起來，並且設定 theme={this.state.Theme}</h4><blockquote>!!! theme 首字要小寫, 如果大寫為 Theme 會報錯</blockquote><pre>&lt;ThemeProvider theme={this.state.Theme}&gt;<br>  &lt;Button&gt;Themed&lt;/Button&gt;<br>&lt;/ThemeProvider&gt;</pre><p>存檔後即可看到被包裝過的 Theme</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/320/0*bq1LjN-L6xv5OeuS.png" /></figure><p>將 DefaultTheme 切換為 PinkTheme 即可抽換不同色彩主題</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/313/0*o12oHToXyETkXIpI.png" /></figure><blockquote>!!!補充 : ThemeProvider 裡面不能有多個 Child , 記得用一個&lt;div&gt;&lt;/div&gt;或&lt;Fragment&gt;&lt;/Fragment&gt;將 Childs 包起來</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1022/1*JSa53xzsTjNp6sF2rC3oRw.png" /></figure><blockquote><em>參考資料: </em><a href="https://www.styled-components.com/docs/advanced"><em>Styled-components Theming</em></a></blockquote><pre>Say hello! 我是 Angel,</pre><pre>這裏的內容如果有幫到你，希望能獲得一些拍手作為鼓勵 <br>工作上的合作歡迎隨時透過 Mail 聯繫我 contact@aneglho.design</pre><pre>– <br>Thanks for watching!</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=62be72b9c7ea" width="1" height="1" alt=""><hr><p><a href="https://medium.com/itsoktomakemistakes/%E5%9C%A8-react-styled-components-%E9%80%8F%E9%81%8E-themeprovider-%E4%BE%86%E6%9B%B4%E6%8F%9B%E7%B6%B2%E9%A0%81%E8%89%B2%E5%BD%A9%E4%B8%BB%E9%A1%8C%E6%A8%A3%E5%BC%8F-62be72b9c7ea">在 React Styled-Components 透過 ThemeProvider 來更換網頁色彩主題樣式</a> was originally published in <a href="https://medium.com/itsoktomakemistakes">Its Ok to Make Mistakes</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[使用 CreateGlobalStyle 在 React Styled-Components 取代 CSS Reset 與 CSS Normalize]]></title>
            <link>https://medium.com/itsoktomakemistakes/%E4%BD%BF%E7%94%A8-createglobalstyle-%E5%9C%A8-react-styled-components-%E5%8F%96%E4%BB%A3-css-reset-%E8%88%87-css-normalize-fc8faa8059f1?source=rss-a91baa2a5e38------2</link>
            <guid isPermaLink="false">https://medium.com/p/fc8faa8059f1</guid>
            <category><![CDATA[styled-components]]></category>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[create-react-app]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[css-reset]]></category>
            <dc:creator><![CDATA[Angel]]></dc:creator>
            <pubDate>Tue, 05 Mar 2019 02:01:00 GMT</pubDate>
            <atom:updated>2021-04-12T07:41:39.153Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*EvqpjuCdboa54qcY.jpg" /></figure><blockquote>使用 Styled-Components 來撰寫 Style 最大的好處之一，就是能夠透過 React Components 避免掉 CSS 全域汙染的問題。但仍然有些 Style 是希望跨 Components 於全域做設定的，像將瀏覽器統一重置的 CSS Reset 或 CSS Normalize 。CreateGlobalStyle 是 Styled-Components 所提出的解法。</blockquote><h3>第ㄧ步：使用 Create-React-App 建構 React Styled-Components 開發環境</h3><p>參考文章: <a href="https://medium.com/yente-ho/create-react-app-react-styled-component-sass-ccb0e6b182bc">使用 Create-React-App 創建 React Styled-Components 及 SASS 開發環境</a></p><h3>第二步：建立 globalStyle.js 並從 Styled-Components 引入 createGlobalStyle</h3><p>建立 globalStyle.js 在 components 資料夾</p><pre>$ mkdir src/components<br>$ touch src/components/globalStyle.js</pre><p>進入 globalStyle.js ，從 Styled-Components 引用 createGlobalStyle</p><pre>import { createGlobalStyle } from &quot;styled-components&quot;;</pre><p>加入 Reset 和 CSS 全域的 Style 設定</p><pre>export const ResetStyle = createGlobalStyle`<br>html, body, div, span, applet, object, iframe, h1, h2, h3, h4, h5, h6, p, blockquote, pre, a, abbr, acronym, address, big, cite, code, del, dfn, em, img, ins, kbd, q, s, samp, small, strike, strong, sub, sup, tt, var, b, u, i, center, dl, dt, dd, ol, ul, li, fieldset, form, label, legend, table, caption, tbody, tfoot, thead, tr, th, td, article, aside, canvas, details, embed, figure, figcaption, footer, header, hgroup, menu, nav, output, ruby, section, summary, time, mark, audio, video {<br>  margin: 0;<br>  padding: 0;<br>  border: 0;<br>  font-size: 100%;<br>  font: inherit;<br>  vertical-align: baseline;<br>  box-sizing: border-box;<br>}</pre><pre>address, caption, cite, code, dfn, em, strong, th, var, b {<br>  font-weight: normal;<br>  font-style: normal;<br>}</pre><pre>abbr, acronym {<br>  border: 0;<br>}</pre><pre>article, aside, details, figcaption, figure, footer, header, hgroup, menu, nav, section {<br>  display: block;<br>}</pre><pre>*,<br>*::after,<br>*::before {<br>  margin: 0;<br>  padding: 0;<br>  box-sizing: inherit;<br>}</pre><pre>html {<br>  text-size-adjust: 100%;<br>  box-sizing: border-box;<br>}</pre><pre>body {<br>    line-height: 1;<br>}</pre><pre>ol, ul {<br>  list-style: none;<br>}</pre><pre>blockquote, q {<br>  quotes: none;<br>}</pre><pre>blockquote {<br>  &amp;:before,   &amp;:after {<br>    content: &#39;&#39;;<br>    content: none;<br>  }<br>}</pre><pre>q {<br>  &amp;:before,   &amp;:after {<br>    content: &#39;&#39;;<br>    content: none;<br>  }<br>}</pre><pre>table {<br>  border-collapse: collapse;<br>  border-spacing: 0;<br>}</pre><pre>caption, th {<br>  text-align: left;<br>}</pre><pre>textarea {<br>  resize: none;<br>}</pre><pre>a {<br>  text-decoration: none;<br>  cursor: pointer;<br>}</pre><pre>button {<br>  padding: 0;<br>  border: none;<br>  background: none;<br>}<br>`;</pre><p>加入 CSS 全域設定</p><pre>export const GlobalStyle = createGlobalStyle`<br>html {<br>  box-sizing: border-box;<br>  font-size: 62.5%; <br>  font-family: &#39;HelveticaNeue&#39;, Helvetica, Arial, &#39;Lucida Grande&#39;, sans-serif;<br>}<br>`;</pre><h3>第三步：到 App.js 中將 ResetStyle 和 GlobalStyle加入 Template</h3><p>回到 App.js 裡面引入 globalStyle.js 中的 ResetStyle 和 GlobalStyle</p><pre>import React, { Component } from &#39;react&#39;;<br>import {ResetStyle, GlobalStyle} from &#39;./components/globalStyle&#39;<br>class App extends Component {<br>  render() {<br>    return (<br>      &lt;div className=&quot;App&quot;&gt;<br>      &lt;/div&gt;<br>    );<br>  }<br>}</pre><p>將 ResetStyle 和 GlobalStyle 放在 Template 最上方，記得 ResetStyle 要放在 GlobalStyle 之前。加上 &lt;ul&gt;&lt;li&gt;&lt;/li&gt;&lt;/ul&gt; 來測試是否有 Reset 掉 &lt;li&gt; 的圓點，且順利加入 Global 的字體設定。</p><pre>import React, { Component } from &#39;react&#39;;<br>import {ResetStyle, GlobalStyle} from &#39;./components/globalStyle&#39;<br>class App extends Component {<br>  render() {<br>    return (<br>      &lt;div className=&quot;App&quot;&gt;<br>        &lt;ResetStyle /&gt;<br>        &lt;GlobalStyle /&gt;<br>        &lt;ol&gt; <br>          &lt;li&gt;Test&lt;/li&gt;<br>          &lt;li&gt;Test&lt;/li&gt;<br>          &lt;li&gt;Test&lt;/li&gt;<br>        &lt;/ol&gt;<br>      &lt;/div&gt;<br>    );<br>  }<br>}</pre><pre>Say hello! 我是 Angel,</pre><pre>這裏的內容如果有幫到你，希望能獲得一些拍手作為鼓勵 <br>工作上的合作歡迎隨時透過 Mail 聯繫我 contact@aneglho.design</pre><pre>– <br>Thanks for watching!</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fc8faa8059f1" width="1" height="1" alt=""><hr><p><a href="https://medium.com/itsoktomakemistakes/%E4%BD%BF%E7%94%A8-createglobalstyle-%E5%9C%A8-react-styled-components-%E5%8F%96%E4%BB%A3-css-reset-%E8%88%87-css-normalize-fc8faa8059f1">使用 CreateGlobalStyle 在 React Styled-Components 取代 CSS Reset 與 CSS Normalize</a> was originally published in <a href="https://medium.com/itsoktomakemistakes">Its Ok to Make Mistakes</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[推薦的 VS Code Extensions 整理(2019/2月更新)]]></title>
            <link>https://medium.com/itsoktomakemistakes/vs-code-extensions-a453e5d1e926?source=rss-a91baa2a5e38------2</link>
            <guid isPermaLink="false">https://medium.com/p/a453e5d1e926</guid>
            <category><![CDATA[html]]></category>
            <category><![CDATA[vscode-extension]]></category>
            <category><![CDATA[vscode]]></category>
            <category><![CDATA[css]]></category>
            <category><![CDATA[front-end-development]]></category>
            <dc:creator><![CDATA[Angel]]></dc:creator>
            <pubDate>Tue, 19 Feb 2019 02:01:00 GMT</pubDate>
            <atom:updated>2021-04-12T07:40:54.498Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/452/0*MjmkELgaH8qK8EZM.png" /></figure><blockquote>1. 安裝 <a href="https://code.visualstudio.com/download">VS Code</a></blockquote><blockquote>2. VS Code 介面主題</blockquote><blockquote>3. HTML / 路徑 / 排版 / 檔案切換 / 瀏覽器開啟 / 錯字檢查</blockquote><blockquote>4. CSS / SASS / 色彩 / 圖片</blockquote><blockquote>5. Git 版本控管</blockquote><blockquote>6. NPM / Yarn / Dependencies</blockquote><blockquote>7. 標記書籤</blockquote><h3>VS Code 介面主題</h3><ul><li>Material Icon Theme: 基於 Material Desgin 的檔案主題icon <a href="https://marketplace.visualstudio.com/items?itemName=PKief.material-icon-theme">Link →</a></li></ul><h3>HTML / 路徑 / 排版 / 檔案切換 / 瀏覽器開啟 / 錯字檢查</h3><ul><li>Auto Close Tag: 自動關閉HTML Tag產&lt;/&gt; <a href="https://marketplace.visualstudio.com/items?itemName=formulahendry.auto-close-tag">Link →</a></li><li>Auto Rename Tag: 自動更改相同的 HTML tags. <a href="https://marketplace.visualstudio.com/items?itemName=formulahendry.auto-rename-tag">Link →</a></li><li>Prettier: 自動編排 HTML / JavaScript / TypeScript / CSS 格式 <a href="https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode">Link →</a><br>⌘ + P + &gt; + Format Document<br>=&gt; 可以與ESlint複合使用 <a href="https://www.youtube.com/watch?v=YIvjKId9m2c">教學</a></li><li>Path Intellisense: 輸入路徑時自動補完路徑 <a href="https://marketplace.visualstudio.com/items?itemName=christian-kohler.path-intellisense">Link →</a></li><li>Paste and Indent: 貼上程式碼時自動縮排 <a href="https://marketplace.visualstudio.com/items?itemName=Rubymaniac.vscode-paste-and-indent">Link →</a></li><li>Project Manager: 在不同專案間快速切換 <a href="https://marketplace.visualstudio.com/items?itemName=alefragnani.project-manager">Link →</a><br>儲存要快速切換的專案 &gt; ⌘ + P + &gt; + Project Manager: save project<br>切換專案 &gt; ⌘ + P + &gt; + Project Manager: List projects to open <a href="https://www.youtube.com/watch?v=YDw-b98HP9c&amp;t=214s">教學</a></li><li>open in browser: option(Alt) + B 打開html檔案在browser <a href="https://marketplace.visualstudio.com/items?itemName=techer.open-in-browser">Link →</a></li><li>Code Spell Checker: 檢查英文拼字錯誤 <a href="https://marketplace.visualstudio.com/items?itemName=streetsidesoftware.code-spell-checker">Link →</a></li></ul><h3>CSS / SASS / Styled-components / 色彩 / 圖片</h3><ul><li>Color Highlight： 強調 CSS 顏色 <a href="https://marketplace.visualstudio.com/items?itemName=naumovs.color-highlight">Link →</a></li><li>SVG Viewer: 右鍵看SVG圖形 <a href="https://marketplace.visualstudio.com/items?itemName=cssho.vscode-svgviewer">Link →</a></li><li>IntelliSense for CSS class names: 自動在html完成css的class <a href="https://marketplace.visualstudio.com/items?itemName=Zignd.html-css-class-completion">Link →</a></li><li>Sass Formatter: Sass / Scss 排版 <a href="https://marketplace.visualstudio.com/search?term=Sass%20Formatter&amp;target=VSCode&amp;category=All%20categories&amp;sortBy=Relevance">Link →</a> shift + option(Alt) + F</li><li>Sass: Sass的縮排、高亮、自動完成和快速縮寫 <a href="https://marketplace.visualstudio.com/items?itemName=robinbentley.sass-indented">Link →</a></li><li>Live Sass Compiler: SASS編譯 <a href="https://marketplace.visualstudio.com/items?itemName=ritwickdey.live-sass">Link →</a> 建議使用 <a href="https://www.npmjs.com/package/sass-loader">sass-loader</a> 取代</li><li>Live Server: 動態頁面更新 <a href="https://marketplace.visualstudio.com/items?itemName=ritwickdey.LiveServer">Link →</a> 建議使用 <a href="https://www.npmjs.com/package/live-server">live-server</a> 取代</li><li>styled-components-snippets: Styled-component 縮寫模版 <a href="https://marketplace.visualstudio.com/items?itemName=jonkwheeler.styled-components-snippets">Link →</a></li></ul><h3>Git 版本控管</h3><ul><li>gi: 設定gitignore <a href="https://marketplace.visualstudio.com/items?itemName=rubbersheep.gi">Link →</a> <a href="https://marketplace.visualstudio.com/items?itemName=rubbersheep.gi">教學</a> Shift+Cmd+P &gt;&gt;gi&gt;node&gt;append 來設定gitignore</li><li>Git Lens：看Git中code的狀態和git blame <a href="https://marketplace.visualstudio.com/items?itemName=eamodio.gitlens">Link →</a></li><li>Git History: Git圖形化介面 <a href="https://marketplace.visualstudio.com/items?itemName=donjayamanne.githistory">Link →</a></li></ul><h3>NPM / Yarn / Dependencies / 寫 Code 風格統一</h3><ul><li>Version Lens: 在 Package.json 檔案中可以看到安裝的套件是否為最新版本 <a href="https://marketplace.visualstudio.com/items?itemName=pflannery.vscode-versionlens">Link →</a> <a href="https://www.youtube.com/watch?v=eCz3rhsDG5s&amp;list=PLmbQyp9IK3JPFBrv31e5Gq-Zv57KxtTnZ&amp;index=1">教學</a></li><li>Import Cost: 計算 imports 進來的檔案大小 <a href="https://marketplace.visualstudio.com/items?itemName=wix.vscode-importcost">Link →</a></li><li>npm: 管理 npm commands <a href="https://marketplace.visualstudio.com/items?itemName=fknop.vscode-npm">Link →</a><br>⌘ + P + &gt; + npm</li><li>npm Intellisense: 自動完成 npm modules <a href="https://marketplace.visualstudio.com/items?itemName=christian-kohler.npm-intellisense">Link →</a></li><li>ESLint: 找出語法錯誤/寫 Code 風格統一 <a href="https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint">Link →</a><br><a href="https://www.youtube.com/watch?v=cMrDePs86Uo">教學1</a><br><a href="https://www.youtube.com/watch?v=bfyI9yl3qfE">教學2</a></li></ul><h3>標記書籤</h3><ul><li>Bookmarks: 標記書籤在正在編輯的行數前面 <a href="https://marketplace.visualstudio.com/items?itemName=alefragnani.Bookmarks">Link →</a><br><a href="https://www.youtube.com/watch?v=NfjfVzOOxBk">教學</a>command(Ctrl)+option(Alt)+K就可加書籤;command(Ctrl)+option(Alt)+L下一個書籤;command(Ctrl)+option(Alt)+J上一個書籤</li></ul><pre>Say hello! 我是 Angel,</pre><pre>這裏的內容如果有幫到你，希望能獲得一些拍手作為鼓勵 <br>工作上的合作歡迎隨時透過 Mail 聯繫我 contact@aneglho.design</pre><pre>– <br>Thanks for watching!</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a453e5d1e926" width="1" height="1" alt=""><hr><p><a href="https://medium.com/itsoktomakemistakes/vs-code-extensions-a453e5d1e926">推薦的 VS Code Extensions 整理(2019/2月更新)</a> was originally published in <a href="https://medium.com/itsoktomakemistakes">Its Ok to Make Mistakes</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[在 React Create-React-App 引入 SVG 圖檔的方法，並使用 Styled-Component 來調整 SVG Icon 在不同狀態下的色彩改變]]></title>
            <link>https://medium.com/itsoktomakemistakes/react-create-react-app-svg-icons-styled-component-570b4e9f07b?source=rss-a91baa2a5e38------2</link>
            <guid isPermaLink="false">https://medium.com/p/570b4e9f07b</guid>
            <category><![CDATA[icons]]></category>
            <category><![CDATA[styled-components]]></category>
            <category><![CDATA[svg]]></category>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[create-react-app]]></category>
            <dc:creator><![CDATA[Angel]]></dc:creator>
            <pubDate>Tue, 29 Jan 2019 02:01:00 GMT</pubDate>
            <atom:updated>2021-04-12T07:40:43.650Z</atom:updated>
            <content:encoded><![CDATA[<h3>在 React Create-React-App 引入 SVG 圖檔的方法，並使用 Styled-Components 來調整 SVG Icon 在不同狀態下的色彩改變</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*X-MsHluBJPY3-lOQ.png" /></figure><blockquote>Create React App 在第二版中增添了<a href="https://github.com/smooth-code/svgr">svgr</a>，這個 Webpack Loader 可以將 React 中的 SVG 包裝為 Component 的形式。</blockquote><p>過去想要使用大量 SVG Icons 在 React 專案中，大部分的設計師選擇將 Icon 丟入 <a href="https://icomoon.io/">Icomoon</a> 當中轉為 Font 檔，可以快速地利用 CSS 將整組 Icon Font 換色、調整尺寸等。</p><p>不過在 2017 年年底時，曾發生過 icomoon 網站修改 IconFont 產出設定的慘案，導致重新匯出時既有的 Icon 全部跑位，但我手上又沒有原本的圖檔，連全部重新匯入都無法。至從那之後，開始認真尋找替代方案，SVG Sprites 是選項之一，而使用 svgr 將一顆一顆的 SVG Icon 包裝為 Component 的形式，是我自己目前選擇的作法。</p><h3>第一步：將 SVG 以 Component 的形式匯入 React</h3><p>Create React App 提供的 Logo Sample 使用 Image Source 匯入，即便是 SVG 圖檔也無法編輯 fill、stroke 來動態改變外觀。</p><pre>import React, { Component } from &#39;react&#39;;<br>import logo from &#39;./logo.svg&#39;;<br>import &#39;./App.css&#39;;</pre><pre>class App extends Component {<br>  render() {<br>    return (<br>      &lt;div className=&quot;App&quot;&gt;<br>        &lt;img src={logo} className=&quot;App-logo&quot; alt=&quot;logo&quot; /&gt;<br>      &lt;/div&gt;<br>    );<br>  }<br>}</pre><pre>export default App;</pre><p>需要將 SVG 圖檔包裝為 Component</p><pre>import { ReactComponent as Logo } from &#39;./logo.svg&#39;</pre><p>以 Component 的方式匯入至 Template，可以保留 SVG 的特性，直接使用 stroke 來改變圖形外觀</p><pre>import React, { Component } from &#39;react&#39;;<br>import logo from &#39;./logo.svg&#39;<br>import { ReactComponent as Logo } from &#39;./logo.svg&#39;<br>import &#39;./App.css&#39;</pre><pre>class App extends Component {<br>  render() {<br>    return (<br>      &lt;div className=&quot;App&quot;&gt;<br>        &lt;img src={logo} className=&quot;App-logo&quot; alt=&quot;logo&quot; /&gt;<br>        &lt;Logo className=&quot;App-logo&quot; alt=&quot;logo&quot; stroke=&quot;#DB7290&quot; strokeWidth=&quot;1rem&quot;/&gt;<br>      &lt;/div&gt;<br>    );<br>  }<br>}</pre><pre>export default App;</pre><p>在瀏覽器就會呈現出這樣的效果：</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/116/0*cLYRDMNhi1plbSux.gif" /></figure><h3>第二步：使用 CSS 來調整 SVG Component</h3><p>在 App.css 檔案中添加動畫及其他 Style 樣式, 在 Template 中 引用 ClassName 即完成。</p><pre>.App {<br>  text-align: center;<br>}</pre><pre>.App-logo {<br>  animation: App-logo-spin infinite 20s linear;<br>}<br>.App-logo g {<br>  fill: #DB7290;;<br>}</pre><pre>.App-logo path {<br>  stroke: #DB7290;;<br>  stroke-width: 10px;<br>  fill: #FFD0DD;<br>  stroke-dasharray: 35px 15px;<br>  animation: orbit 1s infinite linear;<br>}</pre><pre>@keyframes orbit { to { stroke-dashoffset: 50px; } }</pre><pre>@keyframes App-logo-spin {<br>  from {<br>    transform: rotate(0deg);<br>  }<br>  to {<br>    transform: rotate(360deg);<br>  }<br>}</pre><p>在瀏覽器呈現的效果：</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/117/0*skn9-a9Hmd0mkM2B.gif" /></figure><h3>第三步：使用 Styled-Component 來調整 SVG Icon 在不同狀態下的色彩改變</h3><p>添加數個 SVG Icon 在 img 檔案夾中</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/311/0*JUZQDBJRwFfuhRFT.png" /></figure><p>在 Components 檔案夾中加入一個 icons.js 的檔案，並在裡面引入所需要的 SVG Icon 後匯出</p><pre>import { ReactComponent as Facebook } from &#39;../img/facebook.svg&#39;;<br>import { ReactComponent as Instagram } from &#39;../img/instagram.svg&#39;;<br>import { ReactComponent as Spotify } from &#39;../img/spotify.svg&#39;;<br>import { ReactComponent as Telegram } from &#39;../img/telegram.svg&#39;;<br>import { ReactComponent as Twitter } from &#39;../img/twitter.svg&#39;;</pre><pre>export default {<br>    Facebook, Instagram, Spotify, Telegram, Twitter<br>};</pre><p>回到 App.js 檔案，使用 Styled Component 加入 Styles（補充：Styled Component 的設定 &gt;&gt; <a href="https://medium.com/yente-ho/create-react-app-react-styled-component-sass-ccb0e6b182bc">使用 Create React App 創建 React Styled Component 及 Sass 開發環境</a>）</p><pre>import React, { Component } from &#39;react&#39;;<br>import SocialMedia from &#39;./components/icons&#39;;<br>import styled from &#39;styled-components&#39;;<br></pre><pre>const SocialMediaWrapper = styled.div`<br>  &amp; path {<br>    fill: #DB7290;<br>  } <br>`<br>class App extends Component {<br>  render() {<br>    return (<br>      &lt;div className=&quot;App&quot;&gt;<br>        &lt;SocialMediaWrapper &gt;<br>          &lt;SocialMedia.Facebook /&gt;<br>          &lt;SocialMedia.Instagram /&gt;<br>          &lt;SocialMedia.Spotify /&gt;<br>          &lt;SocialMedia.Telegram /&gt;<br>          &lt;SocialMedia.Twitter /&gt;<br>        &lt;/SocialMediaWrapper&gt;<br>      &lt;/div&gt;<br>    );<br>  }<br>}</pre><pre>export default App;</pre><p>在瀏覽器呈現的效果：</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/190/0*jBD5X8kURb3d2Gd1.png" /></figure><blockquote>使用 React 搭配 Styled Component 設定 SVG 的 fill 來動態改變 Icon 顏色，可以快速設定 Icon 的 Hover / Clicked / Normal /Active / Disabled 在不同狀態下換色，並避免過往 CSS Class 造成的全域污染問題。</blockquote><pre>import React, { Component } from &#39;react&#39;<br>import SocialMedia from &#39;./components/icons&#39;<br>import styled from &#39;styled-components&#39;</pre><pre>const Wrapper = styled.div`<br>  text-align: center;<br>  margin: 20px;<br>`;<br>const SocialMediaWrapper = styled.div`<br>  display: inline-block;<br>  padding: 1rem;<br>  &amp; path {<br>    fill: ${props =&gt; (props.disabled ? &#39;#dfdfdf&#39; : (props.active ? &#39;#DB7290&#39; : &#39;#FFD0DD&#39;))};<br>    &amp;:hover{<br>      fill: ${props =&gt; (props.disabled ? &#39;none&#39; : &#39;#f3a333&#39;)};<br>    }<br>    &amp;:active{<br>      fill: ${props =&gt; (props.disabled ? &#39;none&#39; : &#39;#930077&#39;)};<br>    }<br>  } <br>`<br>class App extends Component {<br>  render() {<br>    return (<br>      &lt;div className=&quot;App&quot;&gt;<br>        &lt;Wrapper&gt;<br>          &lt;SocialMediaWrapper active&gt;<br>            &lt;SocialMedia.Facebook/&gt;<br>            &lt;div&gt;Active&lt;/div&gt;<br>          &lt;/SocialMediaWrapper&gt;<br>          &lt;SocialMediaWrapper&gt;<br>            &lt;SocialMedia.Instagram/&gt;<br>            &lt;div&gt;Normal&lt;/div&gt;<br>          &lt;/SocialMediaWrapper&gt;<br>          &lt;SocialMediaWrapper&gt;<br>            &lt;SocialMedia.Spotify/&gt;<br>            &lt;div&gt;Hover&lt;/div&gt;<br>          &lt;/SocialMediaWrapper&gt;<br>          &lt;SocialMediaWrapper&gt;<br>            &lt;SocialMedia.Telegram /&gt;<br>            &lt;div&gt;Clicked&lt;/div&gt;<br>          &lt;/SocialMediaWrapper&gt;<br>          &lt;SocialMediaWrapper disabled&gt;<br>            &lt;SocialMedia.Twitter/&gt;<br>            &lt;div&gt;Disabled&lt;/div&gt;<br>          &lt;/SocialMediaWrapper&gt;<br>        &lt;/Wrapper&gt;<br>        <br>      &lt;/div&gt;<br>    );<br>  }<br>}</pre><pre>export default App;</pre><p>在瀏覽器呈現的效果：</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/421/1*mlo5YMvBfhMhV6ie4B7rxA.png" /></figure><blockquote>參考資料：<a href="https://egghead.io/lessons/react-add-svgs-as-react-components-with-create-react-app-2-0">Add SVGs as React Components with Create React App 2.0</a></blockquote><pre>Say hello! 我是 Angel,</pre><pre>這裏的內容如果有幫到你，希望能獲得一些拍手作為鼓勵 <br>工作上的合作歡迎隨時透過 Mail 聯繫我 contact@aneglho.design</pre><pre>– <br>Thanks for watching!</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=570b4e9f07b" width="1" height="1" alt=""><hr><p><a href="https://medium.com/itsoktomakemistakes/react-create-react-app-svg-icons-styled-component-570b4e9f07b">在 React Create-React-App 引入 SVG 圖檔的方法，並使用 Styled-Component 來調整 SVG Icon 在不同狀態下的色彩改變</a> was originally published in <a href="https://medium.com/itsoktomakemistakes">Its Ok to Make Mistakes</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>