<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Victor Gonzalez</title>
    <description>The latest articles on DEV Community by Victor Gonzalez (@gonzavic).</description>
    <link>https://dev.to/gonzavic</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F783300%2Fd3a769e3-aa29-45c6-84a5-9c0f809a4718.jpg</url>
      <title>DEV Community: Victor Gonzalez</title>
      <link>https://dev.to/gonzavic</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/gonzavic"/>
    <language>en</language>
    <item>
      <title>Component System with Material UI: Button</title>
      <dc:creator>Victor Gonzalez</dc:creator>
      <pubDate>Mon, 17 Jan 2022 15:30:24 +0000</pubDate>
      <link>https://dev.to/gonzavic/component-system-with-material-ui-button-4ljc</link>
      <guid>https://dev.to/gonzavic/component-system-with-material-ui-button-4ljc</guid>
      <description>&lt;p&gt;This is another post from a series, where I'll be using Material UI (now mui) for creating a Component System that maps an already created Design System: &lt;a href="https://www.figma.com/file/a94lX91ZmYGIDBxvb8shwLn8/00.-Styleguide---Library?node-id=6495%3A12616" rel="noopener noreferrer"&gt;VTEX Design Sistem&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In this post I'll be setting the styles for the &lt;strong&gt;Button&lt;/strong&gt; component using the &lt;code&gt;createTheme&lt;/code&gt; mui API. For that I'll be overriding the defaults style values and also creating new variants.&lt;/p&gt;

&lt;p&gt;You can see the Button style guide within Figma &lt;a href="https://www.figma.com/file/a94lX91ZmYGIDBxvb8shwLn8/00.-Styleguide---Library?node-id=6495%3A12616" rel="noopener noreferrer"&gt;here&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1cfbjlepc41xy7f4tccp.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1cfbjlepc41xy7f4tccp.png" alt="Button Style guide figma "&gt;&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;Buttons are a core component for any web application, users interacts and trigger action from these, so it's important to  transmit the user what are the buttons hierarchy.&lt;/p&gt;

&lt;p&gt;Mui defines 3 different button variants and 3 different sizes for each of them, this is how mui defines and separates the hierarchy between Buttons.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt; &lt;strong&gt;contained&lt;/strong&gt;: this is the button with higher emphasis, it is meant to be used for primary actions. This is what you want your users to click on.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;outlined&lt;/strong&gt;: are buttons with medium emphasis, this variant is mostly used on "secondary" actions, those which are important, but it's not the main action in an specific context.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;text&lt;/strong&gt;: a variant with low emphasis, this variant is used for those actions that doesn't affect the main goal of your application. Also are mostly used on cards, dialogs/modals, and snackbars.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7qe9nwz55z1a9b7g0ure.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7qe9nwz55z1a9b7g0ure.png" alt="mui buttons variants"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here is how the &lt;a href="https://www.figma.com/file/a94lX91ZmYGIDBxvb8shwLn8/00.-Styleguide---Library?node-id=6495%3A12616" rel="noopener noreferrer"&gt;VTEX Design Sistem&lt;/a&gt; buttons guide looks implemented using the theme api from mui.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;&lt;iframe src="https://codesandbox.io/embed/9eim9?initialpath=/buttons-vtex&amp;amp;module=/src/ButtonsVTEX.js"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;As you can see on the gist above, I'm overriding the &lt;code&gt;sizeSmall&lt;/code&gt;, &lt;code&gt;sizeMedium&lt;/code&gt; and &lt;code&gt;sizeLarge&lt;/code&gt; styles from the createTheme mui function to set the correct paddings and font-size for those states.&lt;/p&gt;

&lt;p&gt;I'm also creating a new color &lt;code&gt;danger&lt;/code&gt; and defining the &lt;code&gt;main&lt;/code&gt; and &lt;code&gt;contrastText&lt;/code&gt; so that, I can create the danger buttons displayed on the codesandbox as example.&lt;/p&gt;




&lt;p&gt;I said at the beginning of the post in order to create the VTEX Button styles I will be overriding the default values for the mui buttons, and also creating new ones. But there was no need for create new variants, since mui handles very well the abstraction of the color palette and the &lt;code&gt;color&lt;/code&gt; prop on its components.&lt;/p&gt;

&lt;p&gt;I'll be creating some variants just to demonstrate how it can be done with mui.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;&lt;iframe src="https://codesandbox.io/embed/9eim9?initialpath=/buttons-custom&amp;amp;module=/src/ButtonsCustom.js"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;As you can see on the example above, I've created 2 variants called: &lt;code&gt;leftRounded&lt;/code&gt; and &lt;code&gt;dashed&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;For this I had to add a new property called &lt;code&gt;variants&lt;/code&gt; (Array) to the  &lt;code&gt;MuiButton&lt;/code&gt; object. Each object in this array represents a single variant.&lt;/p&gt;

&lt;p&gt;For naming a variant you can use the &lt;code&gt;props: { variant: "name_of_your_variant" }&lt;/code&gt; and then, use the styles property on the same object to set the css styles.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;When it comes to &lt;strong&gt;Buttons&lt;/strong&gt;, most of the time there is no reason for creating new variants, unless the design system you're using contains more than the default 3 variants mui provides, or buttons with weird shapes and animations.&lt;/p&gt;

&lt;p&gt;With a correct definition of colors you can use the &lt;code&gt;color&lt;/code&gt; prop to define which set of "background color" and "color text" to use on each button.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.pauapp.com/collections/?collectionId=61e080cc1c2b700018c5af22" rel="noopener noreferrer"&gt;Some references here&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Component System with Material UI: Typography</title>
      <dc:creator>Victor Gonzalez</dc:creator>
      <pubDate>Tue, 11 Jan 2022 16:01:48 +0000</pubDate>
      <link>https://dev.to/gonzavic/component-system-with-material-ui-typography-6m9</link>
      <guid>https://dev.to/gonzavic/component-system-with-material-ui-typography-6m9</guid>
      <description>&lt;p&gt;This is the second post from a series which will attempt to create a Component System that maps an already created Design System: &lt;a href="https://www.figma.com/file/a94lX91ZmYGIDBxvb8shwLn8/00.-Styleguide---Library?node-id=3390%3A38" rel="noopener noreferrer"&gt;VTEX Design Sistem&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In this post I'll be creating the code needed to map the Typography style from the design system into the project. For that I'll be overriding the defaults style values and also creating new variants.&lt;/p&gt;

&lt;p&gt;You can check the Typography configuration within Figma &lt;a href="https://www.figma.com/file/a94lX91ZmYGIDBxvb8shwLn8/00.-Styleguide---Library?node-id=3390%3A38" rel="noopener noreferrer"&gt;here&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fi3t96yoozy9nv7dkmxwz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fi3t96yoozy9nv7dkmxwz.png" alt="Typography Design"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;A Typography is a component to render text into a React App, Mui has an already pre-defined set of variant values for this component, &lt;a href="https://mui.com/api/typography/#props" rel="noopener noreferrer"&gt;here is the documentation for it&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Setting variants styles
&lt;/h2&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;In the code example above I'm using the &lt;code&gt;typography: {...}&lt;/code&gt; property to set the correct styling for the already pre-defined typography variants, and also create new ones, like: bodyBold, small, smallBold.&lt;/p&gt;

&lt;p&gt;Also, at the same level than &lt;code&gt;typography:{...}&lt;/code&gt; there is another property called &lt;code&gt;components:{...}&lt;/code&gt;, in here I'm using &lt;code&gt;MuiTypography&lt;/code&gt; to specify which html node should be rendered when any of the new variants are being called (variantMapping).&lt;/p&gt;

&lt;p&gt;If I don't set this &lt;code&gt;variantMapping&lt;/code&gt;, when I use a Typography with variant "small", for example, a &lt;code&gt;span&lt;/code&gt; will be rendered.&lt;/p&gt;

&lt;p&gt;Here is how the code above looks on a React application:&lt;/p&gt;

&lt;p&gt;&lt;iframe src="https://codesandbox.io/embed/9eim9?initialpath=/typographies&amp;amp;module=/src/Typographies.js"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  Customizing Typographies on the flight
&lt;/h2&gt;

&lt;p&gt;The idea of creating and setting variants on Mui is to write more maintainable and clean code, most of the time you only need the default version of Typography but when you need specific changes like the color of the text, you can pass it as a property.&lt;/p&gt;

&lt;p&gt;For that you can pass a &lt;code&gt;color&lt;/code&gt; prop to a Typography component to use any defined color on the theme.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;You can see more examples of this on the codesandbox above.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Set all your typographies styles needed on your application, create some custom variants if need it and use the &lt;code&gt;Typography&lt;/code&gt; component so you don't need to set the correct styles on each text you need to display.&lt;/p&gt;

&lt;p&gt;Also take advantage of the &lt;code&gt;color&lt;/code&gt; prop to customize the color in case you need it.&lt;/p&gt;

</description>
      <category>react</category>
      <category>mui</category>
      <category>system</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Component System with Material UI: Theme API</title>
      <dc:creator>Victor Gonzalez</dc:creator>
      <pubDate>Mon, 03 Jan 2022 16:44:58 +0000</pubDate>
      <link>https://dev.to/gonzavic/component-system-with-material-ui-theme-api-3e0h</link>
      <guid>https://dev.to/gonzavic/component-system-with-material-ui-theme-api-3e0h</guid>
      <description>&lt;p&gt;Material UI (now Mui) provides an arrange of React components ready to be used on any project, but the true power of Mui comes when creating a Component System that maps any Design System using the theme api.&lt;/p&gt;




&lt;p&gt;This is the first post from a series which will attempt to create a Component System that maps an already created Design System: &lt;a href="https://www.figma.com/file/a94lX91ZmYGIDBxvb8shwLn8/00.-Styleguide---Library?node-id=3671%3A30728" rel="noopener noreferrer"&gt;VTEX Design Sistem&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9p7ddgnvsq2i1qxrfzrx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9p7ddgnvsq2i1qxrfzrx.png" alt="Figma Preview"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;There is something more than just the ability to create components system on top of the already created mui components that makes Material UI an awesome library to work with: &lt;strong&gt;High standards on how components works, and accessibility&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I have taken the path to create a components system from scratch using any other styling method, and there is a point where some components are using some props and some others are using kind of the same ones, but slightly different, and this is a problem.&lt;/p&gt;

&lt;p&gt;Since Mui has a well defined way on how components should work and what props they should receive, you don't have to worry about maintaining the components abstraction.&lt;/p&gt;

&lt;p&gt;In order to create a component system first I'll explain some definitions that will help understand how it works…&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Variant&lt;/strong&gt;: A variant is an UI representation for a specific component state. For example: the already existing Mui Button variants:&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fj0urt5s5fsw9sodgv9v0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fj0urt5s5fsw9sodgv9v0.png" alt="Mui buttons variants"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;createTheme&lt;/strong&gt;: is a function Mui provides to overrides and create variants for the Mui components. &lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  How to setup a theme in Mui
&lt;/h2&gt;

&lt;p&gt;Mui provides a &lt;code&gt;createTheme&lt;/code&gt; function and a &lt;code&gt;&amp;lt;ThemeProvider /&amp;gt;&lt;/code&gt;component, which allows us to wrap our React app with the ThemeProvider component and pass it down a prop called &lt;code&gt;theme={createTheme({})}&lt;/code&gt;, so that way, any Mui component rendered within this ThemeProvider is going to use the styles set before on the theme.&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;createTheme&lt;/strong&gt; receives an object where you can override/create the styles for the already existing component variants or, create new ones.&lt;/p&gt;

&lt;p&gt;The &amp;lt;&lt;strong&gt;ThemeProdiver&lt;/strong&gt; /&amp;gt; is a React component which wraps the whole application so all Mui children components can access the theme and therefore use the theme styling.&lt;/p&gt;

&lt;p&gt;Here is an example:&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;You can see in the example above the object passed to the &lt;code&gt;createTheme&lt;/code&gt; function has a well defined structure. It has a component property where you can list all supported Mui component with a "Mui" prefix.&lt;/p&gt;

&lt;p&gt;Then, the &lt;code&gt;stylesOverrides&lt;/code&gt; and &lt;code&gt;variants&lt;/code&gt; is where (how the name suggests) you can override the styles and create new variants.&lt;/p&gt;

&lt;p&gt;I'm going to explain how to override each Mui components and create new variants on the next posts. For now, I'm just going to set the colors and spacing…&lt;/p&gt;

&lt;h2&gt;
  
  
  Setting the color palette 👨🏻‍🎨
&lt;/h2&gt;

&lt;p&gt;Understanding the color configuration is crucial for styling correctly the Mui components. But anyway, remember you can always override that configuration for each Mui component later.&lt;/p&gt;

&lt;p&gt;Mui has a default set of colors, &lt;a href="https://mui.com/customization/palette/#palette-colors" rel="noopener noreferrer"&gt;you can check more info about this in here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;I'm creating the next example to add the Design System color guide into the Mui theme api.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;In the example above I'm overriding all Mui defaults color values, and also I'm creating a new one: "newColor". You can see how it would be applied to the buttons components on the example below.&lt;/p&gt;

&lt;p&gt;&lt;iframe src="https://codesandbox.io/embed/9eim9?initialpath=/buttons&amp;amp;module=/src/Buttons.js"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Also, you can manage the color configuration for the light and dark mode in this palette object. But I'll dig more on that on another post.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Use the &lt;code&gt;&amp;lt;ThemeProvider theme={createTheme({...})} /&amp;gt;&lt;/code&gt; to set the color values Mui components are going to use when they are rendered.&lt;/p&gt;

&lt;p&gt;Override and create more color palette values to set the design system color guide into the Mui component system.&lt;/p&gt;

</description>
      <category>react</category>
      <category>mui</category>
      <category>systems</category>
      <category>design</category>
    </item>
  </channel>
</rss>
