### Bind keyboard shortcuts with use-hotkeys in React Source: https://mantine.dev/get-started/index The use-hotkeys hook from Mantine enables binding keyboard shortcuts to specific actions within a React application. It accepts an array of key combinations and their corresponding callback functions. This example demonstrates opening a spotlight search with 'mod + K' and toggling the color scheme with 'mod + J'. It requires Mantine's spotlight and useMantineColorScheme hooks. ```jsx import { useHotkeys } from '@mantine/hooks'; import { spotlight } from '@mantine/spotlight'; import { useMantineColorScheme } from '@mantine/core'; import { Shortcut } from './Shortcut'; function Demo() { const { toggleColorScheme } = useMantineColorScheme(); useHotkeys([ ['mod + K', () => spotlight.open()], ['mod + J', () => toggleColorScheme()], ['mod + shift + alt + X', () => secret()], ]); return ( <> ); } ``` -------------------------------- ### Use EyeDropper Hook for Color Picking in React Source: https://mantine.dev/get-started/index Demonstrates how to use the useEyeDropper hook from @mantine/hooks to allow users to pick colors from anywhere on the screen. It handles browser support, color selection, and error handling. ```typescript import { useState } from 'react'; import { ActionIcon, Group, ColorSwatch, Text } from '@mantine/core'; import { IconColorPicker } from '@tabler/icons-react'; import { useEyeDropper } from '@mantine/hooks'; function Demo() { const [color, setColor] = useState(''); const [error, setError] = useState(null); const { supported, open } = useEyeDropper(); const pickColor = async () => { try { const { sRGBHex } = (await open())!; setColor(sRGBHex); } catch (e) { setError(e as Error); } }; if (!supported) { return EyeDropper API is not supported in your browser; } return ( {color ? ( Picked color: {color} ) : ( Click the button to pick color {error && Error: {error?.message}} ); } ``` -------------------------------- ### Enable Dark Color Scheme in Mantine Application Source: https://mantine.dev/get-started/index Illustrates how to enable the dark color scheme for a Mantine application by wrapping the root component with MantineProvider and setting the defaultColorScheme prop to 'dark'. ```typescript import { MantineProvider } from '@mantine/core'; function Demo() { return ( ); } ``` -------------------------------- ### Override Mantine Component Styles with CSS Modules Source: https://mantine.dev/get-started/index Shows how to override default Mantine component styles using CSS Modules. It demonstrates targeting specific states like ':disabled' and using Mantine's PostCSS mixins for theme-aware styling. ```css .root { border-top-left-radius: var(--mantine-radius-xl); border-bottom-left-radius: var(--mantine-radius-xl); padding-left: 4px; /* The following styles will be applied only when button is disabled */ &[data-disabled] { /* You can use Mantine PostCSS mixins inside data attributes */ @mixin light { border: 1px solid var(--mantine-color-gray-2); } @mixin dark { border: 1px solid var(--mantine-color-dark-4); } /* You can target child elements that are inside .root[data-disabled] */ & .section[data-position='left'] { opacity: 0.6; } } } .section { /* Apply styles only to left section */ &[data-position='left'] { --section-size: calc(var(--button-height) - 8px); background-color: var(--mantine-color-body); color: var(--mantine-color-text); height: var(--section-size); width: var(--section-size); display: flex; align-items: center; justify-content: center; border-radius: var(--mantine-radius-xl); } &[data-position='right'] { @mixin rtl { transform: rotate(180deg); } } } ``` -------------------------------- ### Mantine Form with Uncontrolled Mode and Validation Source: https://mantine.dev/get-started/index Demonstrates the usage of the useForm hook from @mantine/form in uncontrolled mode. It includes initial values for email and terms of service, along with email validation. The form integrates seamlessly with Mantine's TextInput and Checkbox components. ```tsx import { Button, Checkbox, Group, TextInput } from '@mantine/core'; import { useForm } from '@mantine/form'; function Demo() { const form = useForm({ mode: 'uncontrolled', initialValues: { email: '', termsOfService: false, }, validate: { email: (value) => (/^\S+@\S+$/.test(value) ? null : 'Invalid email'), }, }); return (
console.log(values))}> ); } ``` -------------------------------- ### Track element size changes with use-resize-observer in React Source: https://mantine.dev/get-started/index The use-resize-observer hook from Mantine allows tracking an element's size and position changes. It returns a ref to attach to the target element and a rect object containing its dimensions. This hook is useful for responsive UIs and dynamic layout adjustments. It requires Mantine's Group and Table components for displaying the element and its dimensions. ```jsx import { Group, Table } from '@mantine/core'; import { useResizeObserver } from '@mantine/hooks'; function Demo() { const [ref, rect] = useResizeObserver(); return (
Resize me!
); } ``` -------------------------------- ### Implement slider with use-move hook in React Source: https://mantine.dev/get-started/index The use-move hook from Mantine allows for handling move behavior over a given element, useful for creating custom sliders. It takes an event handler that receives movement data and a state setter to update the slider's value. The hook requires React's useState and clamp utility, along with the IconGripVertical component for the slider thumb. ```jsx import { useState } from 'react'; import { IconGripVertical } from '@tabler/icons-react'; import { clamp, useMove } from '@mantine/hooks'; import classes from './Demo.module.css'; function Demo() { const [value, setValue] = useState(0.3); const { ref } = useMove(({ x }) => setValue(clamp(x, 0.1, 0.9))); const labelFloating = value < 0.2 || value > 0.8; return (
{(value * 100).toFixed(0)}
{((1 - value) * 100).toFixed(0)}
); } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.