<?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 lindahehexdev on Medium]]></title>
        <description><![CDATA[Stories by lindahehexdev on Medium]]></description>
        <link>https://medium.com/@tkd09152129?source=rss-b3fcc237e83f------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*jv_yH0pr0wBFctN_E7KMMA.png</url>
            <title>Stories by lindahehexdev on Medium</title>
            <link>https://medium.com/@tkd09152129?source=rss-b3fcc237e83f------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 00:10:11 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@tkd09152129/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[夠用就好系列文 — Chakra UI (2)]]></title>
            <link>https://medium.com/@tkd09152129/%E5%A4%A0%E7%94%A8%E5%B0%B1%E5%A5%BD%E7%B3%BB%E5%88%97%E6%96%87-chakra-ui-2-57db9e1a7f3a?source=rss-b3fcc237e83f------2</link>
            <guid isPermaLink="false">https://medium.com/p/57db9e1a7f3a</guid>
            <dc:creator><![CDATA[lindahehexdev]]></dc:creator>
            <pubDate>Fri, 02 Jun 2023 11:30:10 GMT</pubDate>
            <atom:updated>2023-06-02T11:59:53.210Z</atom:updated>
            <content:encoded><![CDATA[<h3>夠用就好系列文 — Chakra UI (2)</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*XNiEx-za1weWVpT9zxeyLA.png" /></figure><p>這是Chakra UI的夠用就好系列文第二篇，此篇將提到:</p><ul><li>明暗切換</li><li>設計共用組件</li><li>響應式設計(RWD)</li></ul><p>讓我們直接開始!</p><h4>明暗切換</h4><p>Chakra UI 明與暗切換簡單好用，使用useColorMode、useColorModeValue 即可。</p><p>useColorMode : 一個讓你去切換明暗的React Hook。</p><p>useColorModeValue: 根據當下明暗模式下，去顯示不同顏色。</p><p>了解後我們實作一個的明暗模式切換按鈕:</p><pre>import { Button, Flex } from &quot;@chakra-ui/react&quot;;<br>import { useColorMode, useColorModeValue } from &quot;@chakra-ui/react&quot;;<br><br>const SwitcherButton = () =&gt; {<br>//記得用useColorMode Hook<br>  const { colorMode, toggleColorMode } = useColorMode();<br>//定義不同模式下的顏色<br>  const bgColor = useColorModeValue(&quot;gray.100&quot;, &quot;gray.900&quot;);<br>  const buttonColor = useColorModeValue(&quot;gray.900&quot;, &quot;gray.100&quot;);<br>  const buttonTextColor = useColorModeValue(&quot;gray.100&quot;, &quot;gray.900&quot;);<br>  const buttoneHoverColor = useColorModeValue(&quot;teal.500&quot;, &quot;pink.300&quot;);<br><br>  return (<br>    &lt;Flex h=&quot;100vh&quot; justify=&quot;center&quot; align=&quot;center&quot; bg={bgColor}&gt;<br>      &lt;Button<br>        onClick={toggleColorMode}<br>        bg={buttonColor}<br>        color={buttonTextColor}<br>        _hover={{ bg: buttoneHoverColor }}<br>      &gt;<br>        {colorMode === &quot;light&quot; ? &quot;This is Lihgt Mode&quot; : &quot;This is Dark Mode&quot;}<br>      &lt;/Button&gt;<br>    &lt;/Flex&gt;<br>  );<br>};<br><br>export default SwitcherButton;</pre><p>簡單說明一下上段代碼:</p><ol><li>引入兩個組件，Flex用於製作背景；Button則是我們要做的按鈕。</li><li>我們引入了 useColorMode, useColorModeValue 。</li><li>在SwitcherButton下方，用了useColorMode的Hook，讓我們等等可以用來切換顏色。</li><li>使用useColorModeValue來定義明暗模式下應該呈現的顏色。</li><li>Button裡面使用style-props去設定背景、文字、hover的顏色。</li><li>Button的內容透過colorMode+三元式的方式判斷當前應該渲染的文字。</li></ol><p>來看結果吧 GOGO !</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/615/1*9Chddy91HyaJuFbisgLAzw.gif" /></figure><h4>設計組件</h4><p>現在我們來看看Chakra UI如何自己定義組件，避免每個Button都要塞很多props。</p><p>現在我們要做事如下，先長話短說(你可將下列檔案放入一個資料夾管理):</p><p>建立button.ts &gt; 建立 theme.ts &gt; 將theme傳入&lt;ChakraProvider&gt;後即可使用</p><ol><li>建立一個button.ts檔案，設定基本樣式後，在vairant這個props中去定義了想要的顏色，我列了三個: solid, outline, myCustomRed。</li></ol><pre>import type { ComponentStyleConfig } from &quot;@chakra-ui/theme&quot;;<br><br>export const Button: ComponentStyleConfig = {<br>  baseStyle: {<br>    borderRadius: &quot;60px&quot;,<br>    fontSize: &quot;10pt&quot;,<br>    fontWeight: 700,<br>    _focus: {<br>      boxShadow: &quot;none&quot;,<br>    },<br>  },<br>  variants: {<br>    solid: {<br>      color: &quot;white&quot;,<br>      bg: &quot;blue.500&quot;,<br>    },<br>    outline: {<br>      color: &quot;teal.600&quot;,<br>      border: &quot;1px solid&quot;,<br>      borderColor: &quot;blue.600&quot;,<br>    },<br>    myCustomRed:{<br>        color: &quot;white&quot;,<br>        bg: &quot;red.500&quot;,<br>    }<br>  },<br>};</pre><p>2. 建立一個theme.ts檔案, 使用extendTheme，並傳入剛剛定義好的Button到我們的components裡。</p><pre>import { extendTheme } from &quot;@chakra-ui/react&quot;;<br>import { Button } from &#39;./button&#39;<br><br>// 2. Call `extendTheme` and pass your custom values<br>export const theme = extendTheme({<br>  components: {<br>    Button,<br>  }<br>});</pre><p>3. 回到_app.tsx修改一下我們的Chakra UI Provider。</p><pre>import type { AppProps } from &#39;next/app&#39;<br>import { ChakraProvider } from &#39;@chakra-ui/react&#39;<br>//把剛剛的theme.ts引入<br>import { theme } from &#39;@/theme&#39;<br><br><br>export default function App({ Component, pageProps }: AppProps) {<br>  return (<br>//把theme.ts的設定傳進來就好了<br>    &lt;ChakraProvider theme={theme}&gt;<br>      &lt;Component {...pageProps} /&gt;<br>    &lt;/ChakraProvider&gt;<br>  )<br>}</pre><p>4. 用正常方式引入Chakra UI Button後，帶入剛剛設定好的variant(變體)。</p><pre>import { Button, Flex } from &quot;@chakra-ui/react&quot;;<br><br>const CustomButton = () =&gt; {<br><br>  return (<br>    &lt;Flex h=&quot;100vh&quot; justify=&quot;center&quot; align=&quot;center&quot; gap=&#39;10px&#39;&gt;<br>      &lt;Button variant=&#39;outline&#39;&gt;Outline&lt;/Button&gt;<br>      &lt;Button variant=&#39;solid&#39; &gt;Solid&lt;/Button&gt;<br>      &lt;Button variant=&#39;myCustomRed&#39;&gt;Others&lt;/Button&gt;<br>    &lt;/Flex&gt;<br>  );<br>};<br><br>export default CustomButton;</pre><p>來看看成果八，就這樣，搞定。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/505/1*3ztuK38yQQ0k53OMgKJrvA.png" /></figure><h4>響應式設計(RWD)</h4><p>Chakra UI 的組件需要自己設定RWD，但也相對好上手。</p><p>首先，Chakra UI 官網有自己定義好的breakpoint(斷點)，如下:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/778/1*-SAOEgKxBeHamL-v8WTobg.png" /></figure><p>至於如何使用，我們直接看官方的使用實例:</p><p><strong>陣列語法</strong></p><pre>&lt;Box bg=&#39;red.200&#39; w={[300, 400, 500]}&gt;<br>  This is a box<br>&lt;/Box&gt;</pre><p>這個例子中，Box 元件的寬度根據不同的螢幕尺寸而變化。在小型螢幕上，寬度為 100px，在中型螢幕上為 200px，在大型螢幕上為 300px。就這樣，簡單吧。</p><p><strong>物件語法</strong></p><pre>&lt;Text fontSize={{ base: &#39;24px&#39;, md: &#39;40px&#39;, lg: &#39;56px&#39; }}&gt;<br>  This is responsive text<br>&lt;/Text&gt;</pre><ul><li>base：當沒有特定斷點的值時，將使用這個字型大小。</li><li>md：在這個斷點上，字型大小被設置為 &#39;40px&#39;。</li><li>lg：在這個斷點上，字型大小被設置為 &#39;56px&#39;。</li></ul><p><strong>實際應用</strong></p><p>為了練習，我們兩種語法都使用看看吧，下面程式碼是根據上面的按鈕進行小修改的。我們設定了在不同尺寸下，按鈕會有不同的寬度和顏色。</p><pre>import { Button, Flex } from &quot;@chakra-ui/react&quot;;<br><br>const RwdButton = () =&gt; {<br>  return (<br>    &lt;Flex<br>      h=&quot;100vh&quot;<br>      justify=&quot;center&quot;<br>      align=&quot;center&quot;<br>      direction=&quot;column&quot;<br>    &gt;<br>//使用陣列語法和物件語法<br>      &lt;Button<br>        variant=&quot;solid&quot;<br>        w={[100, 200, 300, 400]}<br>        bg={{ base: &quot;blue.400&quot;, sm: &quot;pink.400&quot;, md: &quot;red.500&quot;, lg: &quot;teal.500&quot; }}<br>      &gt;<br>        Hi<br>      &lt;/Button&gt;<br>    &lt;/Flex&gt;<br>  );<br>};<br><br>export default RwdButton;</pre><p>成果如下</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KsHFeydPbQzAcPAyshDzWQ.gif" /></figure><h4>總結</h4><p>明暗切換，會用到:</p><ul><li>useColorMode</li><li>useColorModeValue</li></ul><p><strong>設計元件</strong></p><ol><li>建立資料夾(可有可無)。</li><li>建立要自製的檔案，如button.ts。</li><li>建立 theme.ts 。</li><li>將theme傳入&lt;ChakraProvider&gt;。</li></ol><p><strong>響應式設計</strong></p><ul><li>陣列語法</li><li>物件語法</li></ul><p>以上是Chakra UI 夠用就好的系列文下篇，希望讀者能夠清楚明白大致上會用到的使用方式，讚讚。</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=57db9e1a7f3a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[夠用就好系列文 — Chakra UI (1)]]></title>
            <link>https://medium.com/@tkd09152129/%E5%A4%A0%E7%94%A8%E5%B0%B1%E5%A5%BD%E7%B3%BB%E5%88%97%E6%96%87-chakra-ui-1-7f40c59a351b?source=rss-b3fcc237e83f------2</link>
            <guid isPermaLink="false">https://medium.com/p/7f40c59a351b</guid>
            <dc:creator><![CDATA[lindahehexdev]]></dc:creator>
            <pubDate>Mon, 22 May 2023 10:46:27 GMT</pubDate>
            <atom:updated>2023-05-22T10:46:27.301Z</atom:updated>
            <content:encoded><![CDATA[<h3>夠用就好系列文 — Chakra UI (1)</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1009/1*lRO0Bxx2PfErAFSBIMGc1Q.png" /></figure><h3>序</h3><p>這是筆者的第一篇medium文章，希望透過簡單明瞭的方式，讓對於前端有興趣的讀者，能夠有更多學習的資源與管道，並且以主打<strong>夠用就好</strong>為核心理念，讓各位能夠快速理解並上手前端相關技術。</p><p>本篇將介紹Chakra UI，預計分成<strong>上下兩篇</strong>，並搭配React使用。</p><h3>介紹</h3><p>Chakra UI 是一個React UI 框架 ，使用者可透過簡單理解的模組化UI元件去設計自己的網站。目前在GitHub上的星數已經來到32.7K。</p><h3>優點</h3><ul><li>每個組件都能設定顏色、大小、CSS，不用另外寫CSS去覆蓋</li><li>絕大多數組件都支援明亮/黑暗模式</li><li>客製組件簡單</li><li>文件清晰易懂</li><li>支援TypeScript</li><li>佈局方便</li></ul><h3>安裝</h3><p>在安裝Chakra UI前，你需要先安裝好你的React，你可以選擇用Vite、Create-react-app ，或是使用Next.js 。 如果用npm，於Terminal下此行:</p><pre>npm i @chakra-ui/react @emotion/react @emotion/styled framer-motion</pre><p>如果習慣用yarn，於Terminal下此行:</p><pre>yarn add @chakra-ui/react @emotion/react @emotion/styled framer-motion</pre><p>接著去index.js / App.js 把ChakraProvider 引入近來，讓所有元件都能使用Chakra UI相關資料，好了，就這樣。</p><pre>// pages/_app.js<br>import { ChakraProvider } from “@chakra-ui/react” <br>function MyApp({ Component, pageProps }) { <br>return ( <br>&lt;ChakraProvider&gt;<br>&lt;Component {…pageProps} /&gt;<br>&lt;/ChakraProvider&gt;<br> )<br>}<br>export default App</pre><h3>使用組件</h3><p>Chakra UI 提供不少組件。直接來練習怎麼使用吧。</p><h4>常用組件-以Button為例</h4><p>按鈕簡單也很常用到，來直接瞭解如何使用吧！</p><h4>使用方式</h4><p>看一下官網的文檔的使用方式如下圖，以Button為例，只要引入一個&lt;Button/&gt;的組件就可以使用嚕！</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/811/1*gvmXQwmLdb_BjfC6KQps9g.png" /></figure><h4>Import的方式</h4><p>方法一、可以直接點選官網的COPY按鈕複製貼上。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/799/1*XvjnzUM3joRqG1qp1Hvzpg.png" /></figure><p>方法二、 如果使用 VS Code的話，可以直接在行內打&lt;Button&gt;選擇import來源。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/521/1*sv7tDXMBT2fzFtAw83NKdg.gif" /></figure><p>方法三、 假設想使用別人或官網上的代碼，其中可能多個組件，在複製貼上後，可以將滑鼠移到組件文字上方點選Quick Fix或是使用快捷鍵Ctrl+. &gt; Add all missing imports即可。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/536/1*6EuUTuInNuzdqugF6iD93w.gif" /></figure><h4>修改樣式</h4><p>Chakra UI 提供非常多<strong> Style Props</strong> ， 可以直接寫在組件內，語法也相對簡單，可以當作簡化版的CSS property，本質一樣，如果沒有支援，也可以直接透過sx={{}} 的方式去寫原生的CSS，算是非常方便。需要的連結都下面。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/409/1*4-3yubxJnsuU6_tsz5efvA.png" /><figcaption>這邊使用style props 的 w、h 去代表 &#39;width&#39; 及 &#39;height’ ，省了不少時間</figcaption></figure><ul><li>Style Props列表: <a href="https://chakra-ui.com/docs/styled-system/style-props">https://chakra-ui.com/docs/styled-system/style-props</a></li><li>sx props : <a href="https://chakra-ui.com/docs/styled-system/the-sx-prop">https://chakra-ui.com/docs/styled-system/the-sx-prop</a></li><li>你也可能會用到chakra UI 提供的色票:<br><a href="https://chakra-ui.com/docs/styled-system/theme">https://chakra-ui.com/docs/styled-system/theme</a></li></ul><h4><strong>元件本身的props</strong></h4><p>除了上述的style props，組件本身也會有自己的props，在設定上能夠更方便，以Button來說，可能常用到的會有下列props:</p><p>colorTheme: 設定按鈕主題顏色。</p><p>size : 調整按鈕大小 。</p><p>variant: 設定變體，可以是ghost, outline, solid , ……等等。</p><p>其他相關props，可透過 組件的頁面 &gt; 點擊Props 前往觀看</p><h4><strong>實際演練與應用</strong></h4><p>如何，你現在會引入了，現在練習一下怎麼使用Button這組件吧</p><pre>      &lt;Button<br>        bg=&quot;blue.900&quot;<br>        size=&quot;lg&quot;<br>        p=&quot;5px&quot;<br>        color=&quot;white&quot;<br>        borderRadius=&quot;lg&quot;<br>        _hover={{<br>          bg: &quot;red.200&quot;,<br>        }}<br>        onClick={onClick}<br>      &gt;<br>        Submit<br>      &lt;/Button&gt;</pre><p>這是個按鈕的範例，使用了style props及元件提供的size props，效果如下:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/296/1*MTW5Yzf5dhd_bb3uZ5rIpg.gif" /></figure><h4>常用組件 - 佈局 Flex, Stack , Box</h4><p>了解組件的使用方式後，來看看佈局，常用到的會是 Flex, Box , Stack :</p><p>Flex : display : flex 的div，無須再設置display屬性，另外style-props也有相對簡化，原本需要下flex的都可省略，以下是常用到的:</p><ul><li>direction (flexDirection)</li><li>justify (justifyContent)</li><li>align (alignItems)</li><li>wrap (flexWrap)</li><li>grow (flexGrow)</li><li>shrink (flexShrink)</li></ul><p>Box : 就是一般的div，沒排版需求時可用。</p><p>Stack: 一個容器，可設定方向、間距。其中也有HStack和VStack，H代表水平，V代表垂直。</p><h4>範例</h4><p>這邊使用Flex和Box的應用，使用Flex包住裡面的Box組件，並設定direction 讓方向變成直的。</p><pre> &lt;&gt;<br>      &lt;Flex direction=&#39;column&#39; justify=&quot;center&quot; align=&quot;center&quot; h=&quot;100vh&quot;&gt;<br>        &lt;Box w=&quot;50%&quot; h=&quot;30px&quot; bg=&quot;pink.100&quot; /&gt;<br>        &lt;Box w=&quot;50%&quot; h=&quot;30px&quot; bg=&quot;teal.100&quot; /&gt;<br>        &lt;Box w=&quot;50%&quot; h=&quot;30px&quot; bg=&quot;orange.100&quot; /&gt;<br>        &lt;Box w=&quot;50%&quot; h=&quot;30px&quot; bg=&quot;blue.100&quot; /&gt;<br>      &lt;/Flex&gt;<br>    &lt;/&gt;</pre><p>成果如下:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/751/1*XqqE4Zubs5mWbUlDeeImVQ.png" /></figure><p><strong>前篇總結</strong></p><p>以上是Chakra UI 的前篇內容，現在你應該懂得:</p><ul><li>安裝</li><li>引入組件</li><li>使用style props</li><li>了解組件提供的props</li><li>了解佈局組件的差別及實際應用</li></ul><p>下篇會著重於更多實際層面的應用，例如<strong>明暗切換</strong>、<strong>響應式設計</strong>、<strong>設計組件</strong>。</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7f40c59a351b" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>