reboottime / WebDevelopment

Some notes, thoughts and articles aggregated here about UI/UX and web development.
6 stars 0 forks source link

[React UI Framework] Customize Styling for Mantine/Material UI #69

Open reboottime opened 1 year ago

reboottime commented 1 year ago

Common Needs

reboottime commented 1 year ago

Mantine UI

  1. For most cases, you can customize your component styling 1). via a list of properties provided by style-props 2). or the styles api on the component level

  2. Or update the mantine built-in components at the global level via “MantineProvider”, for example

import { MantineProvider, Text } from '@mantine/core';

function App() {

  return (
    <MantineProvider
      theme={{
        components: {
          Text: {
            styles: {
              root: { fontSize: '2rem' },
            },
          },
        },
      }}
      withGlobalStyles
      withNormalizeCSS
    >
      <Text>2rem text</Text>
    </MantineProvider>
  );
}
  1. styled component solution
    • to access the theme from props
    • to access the prop types from
    • naming convention on using css in js styled solution
      • Prefixed with Styled
      • For Polymorphic components case, prefixed with _Styled, for example
        1. The naming convention on Mantine components
      • maintine-ComponentName-root: represents the root element of that component
      • others: under that component
        1. Maintine also supports customize global colors
reboottime commented 1 year ago
  1. customize your color with Mantine
image image

Example code

import { MantineProvider } from '@mantine/core';

function Demo() {
  return (
    <MantineProvider
      withGlobalStyles
      withNormalizeCSS
      theme={{
        colorScheme: 'dark',
        colors: {
          // override dark colors to change them for all components
          dark: [
            '#d5d7e0',
            '#acaebf',
            '#8c8fa3',
            '#666980',
            '#4d4f66',
            '#34354a',
            '#2b2c3d',
            '#1d1e30',
            '#0c0d21',
            '#01010a',
          ],
        },
      }}
    >
      <App />
    </MantineProvider>
  );
}
reboottime commented 1 year ago

Common Problems you may meet with using Mantine

  1. How to extract css files from main bundle js file when using with CRA.
  2. Tree shaking for production
reboottime commented 1 year ago

Research List

  1. How @mantine handles the type extension of Polymorphic components, for example, if I pass. Link to the component property of NavLink, how can the NavLink know I also should set the to property
  2. Kendo UI document: https://www.telerik.com/kendo-react-ui/components/styling/icons/
reboottime commented 1 year ago

Reference

  1. Open Color: https://yeun.github.io/open-color/