# Mantine Mantine is a fully featured React components library with a focus on usability, accessibility, and developer experience. ## Overview and Key Links - **Documentation**: [https://mantine.dev/](https://mantine.dev/) - **GitHub Repository**: [https://github.com/mantinedev/mantine](https://github.com/mantinedev/mantine) - **Mantine UI**: [https://ui.mantine.dev/](https://ui.mantine.dev/) - **Mantine Help Center**: [https://mantine.dev/help-center/](https://mantine.dev/help-center/) - **Colors Generator**: [https://mantine.dev/colors-generator/](https://mantine.dev/colors-generator/) - **NPM**: [https://www.npmjs.com/org/mantine](https://www.npmjs.com/org/mantine) ## Installation & Getting Started ```bash # Create a new project with Mantine template # For Vite (SPA) npm create vite@latest my-app -- --template react-ts cd my-app npm install @mantine/core @mantine/hooks @emotion/react # For Next.js (SSR) npx create-next-app --typescript my-app cd my-app npm install @mantine/core @mantine/hooks @emotion/react ``` Import styles at the root of your application: ```jsx import '@mantine/core/styles.css'; ``` Wrap your application with MantineProvider: ```jsx import { MantineProvider } from '@mantine/core'; function App() { return ( ); } ``` ## Core Concepts ### Theme System Mantine uses a theme object to control the appearance of all components. The theme is provided through the MantineProvider component and can be customized. ```jsx import { MantineProvider, createTheme } from '@mantine/core'; const theme = createTheme({ fontFamily: 'Verdana, sans-serif', primaryColor: 'blue', colors: { // Add custom colors 'ocean-blue': ['#7AD1DD', '#5FCCDB', '#44CADC', '#2AC9DE', '#1AC2D9', '#11B7CD', '#09ADC3', '#0E99AC', '#128797', '#147885'], }, }); function App() { return ( ); } ``` ### Color System Mantine provides a rich color system with predefined colors and the ability to add custom colors: - Colors are defined as arrays of 10 shades (0-9), where 0 is lightest and 9 is darkest - Default colors: white, black, dark, gray, red, pink, grape, violet, indigo, blue, cyan, teal, green, lime, yellow, orange - Primary color is customizable via `theme.primaryColor` - Color is accessed via CSS variables: `--mantine-color-{colorName}-{shade}` - Primary color shortcuts: `--mantine-primary-color-{shade}` ### CSS Variables Mantine uses CSS variables for styling: - `--mantine-color-{name}-{shade}`: Color variables - `--mantine-primary-color-{shade}`: Primary color variables - `--mantine-spacing-{size}`: Spacing variables (xs, sm, md, lg, xl) - `--mantine-font-family`: Font family variable - `--mantine-font-size-{size}`: Font size variables ### CSS Modules Mantine components use CSS modules for styling. You can create your own `.module.css` files to customize components: ```css /* Button.module.css */ .button { padding: 10px 15px; background-color: var(--mantine-primary-color-6); } ``` ```jsx import classes from './Button.module.css'; function Demo() { return ; } ``` ### Color Schemes Mantine supports light and dark color schemes out of the box: ```jsx import { MantineProvider } from '@mantine/core'; function App() { return ( ); } ``` ## Core Components ### Layout Components #### AppShell A responsive shell for your application with configurable header, navbar and footer. ```jsx import { AppShell, Burger } from '@mantine/core'; import { useState } from 'react'; function Demo() { const [opened, setOpened] = useState(false); return ( setOpened(!opened)} /> Navbar content Main content ); } ``` [Documentation](https://mantine.dev/core/app-shell) | [Source](https://github.com/mantinedev/mantine/tree/master/packages/@mantine/core/src/components/AppShell) #### Container Center content horizontally with predefined max-width. ```jsx import { Container } from '@mantine/core'; function Demo() { return ( Centered content with sm size ); } ``` [Documentation](https://mantine.dev/core/container) | [Source](https://github.com/mantinedev/mantine/tree/master/packages/@mantine/core/src/components/Container) **Available Sizes**: - `xs`: 576px - `sm`: 768px - `md`: 992px - `lg`: 1200px - `xl`: 1400px **Best Practices**: - Use consistent container sizes throughout your application - Combine with responsive props for better mobile experiences - Use the `fluid` prop for full-width containers with padding #### Flex Responsive flexbox container. ```jsx import { Flex } from '@mantine/core'; function Demo() { return (
1
2
3
); } ``` [Documentation](https://mantine.dev/core/flex) | [Source](https://github.com/mantinedev/mantine/tree/master/packages/@mantine/core/src/components/Flex) #### Grid Responsive grid system with support for flexbox alignments. ```jsx import { Grid } from '@mantine/core'; function Demo() { return ( 1 2 ); } ``` [Documentation](https://mantine.dev/core/grid) | [Source](https://github.com/mantinedev/mantine/tree/master/packages/@mantine/core/src/components/Grid) #### Group Arrange items with equal spacing in a row. ```jsx import { Group } from '@mantine/core'; function Demo() { return (
1
2
3
); } ``` [Documentation](https://mantine.dev/core/group) | [Source](https://github.com/mantinedev/mantine/tree/master/packages/@mantine/core/src/components/Group) #### SimpleGrid Responsive grid where each item takes equal amount of space. ```jsx import { SimpleGrid } from '@mantine/core'; function Demo() { return (
1
2
3
4
); } ``` [Documentation](https://mantine.dev/core/simple-grid) | [Source](https://github.com/mantinedev/mantine/tree/master/packages/@mantine/core/src/components/SimpleGrid) #### Stack Vertical flex container. ```jsx import { Stack } from '@mantine/core'; function Demo() { return (
1
2
3
); } ``` [Documentation](https://mantine.dev/core/stack) | [Source](https://github.com/mantinedev/mantine/tree/master/packages/@mantine/core/src/components/Stack) ### Input Components #### TextInput Capture text from user. ```jsx import { TextInput } from '@mantine/core'; function Demo() { return ( ); } ``` [Documentation](https://mantine.dev/core/text-input) | [Source](https://github.com/mantinedev/mantine/tree/master/packages/@mantine/core/src/components/TextInput) #### PasswordInput Capture password from user with show/hide toggle button. ```jsx import { PasswordInput } from '@mantine/core'; function Demo() { return ( ); } ``` [Documentation](https://mantine.dev/core/password-input) | [Source](https://github.com/mantinedev/mantine/tree/master/packages/@mantine/core/src/components/PasswordInput) #### Checkbox Capture boolean input from user. ```jsx import { Checkbox } from '@mantine/core'; import { useState } from 'react'; function Demo() { const [checked, setChecked] = useState(false); return ( setChecked(event.currentTarget.checked)} /> ); } ``` [Documentation](https://mantine.dev/core/checkbox) | [Source](https://github.com/mantinedev/mantine/tree/master/packages/@mantine/core/src/components/Checkbox) #### Switch Alternative to Checkbox when you need to toggle between enabled and disabled states. ```jsx import { Switch } from '@mantine/core'; import { useState } from 'react'; function Demo() { const [checked, setChecked] = useState(false); return ( setChecked(event.currentTarget.checked)} /> ); } ``` [Documentation](https://mantine.dev/core/switch) | [Source](https://github.com/mantinedev/mantine/tree/master/packages/@mantine/core/src/components/Switch) #### Radio Radio buttons allow users to select a single option from a group. ```jsx import { Radio } from '@mantine/core'; import { useState } from 'react'; function Demo() { const [value, setValue] = useState(''); return ( ); } ``` [Documentation](https://mantine.dev/core/radio) | [Source](https://github.com/mantinedev/mantine/tree/master/packages/@mantine/core/src/components/Radio) #### Slider Capture numeric input within a range. ```jsx import { Slider } from '@mantine/core'; import { useState } from 'react'; function Demo() { const [value, setValue] = useState(50); return ( ); } ``` [Documentation](https://mantine.dev/core/slider) | [Source](https://github.com/mantinedev/mantine/tree/master/packages/@mantine/core/src/components/Slider) #### Select Select a single value from the given options. ```jsx import { Select } from '@mantine/core'; function Demo() { return (