-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
150 changed files
with
5,178 additions
and
519 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,3 +54,4 @@ apps/mantine.dev/.cache | |
apps/mantine.dev/out | ||
apps/mantine.dev/.next | ||
apps/mantine.dev/src/.docgen/ | ||
.samples |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
108 changes: 108 additions & 0 deletions
108
apps/help.mantine.dev/src/demos/NestedPopovers.demo.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
import { Button, Popover, Select } from '@mantine/core'; | ||
import { MantineDemo } from '@mantinex/demo'; | ||
|
||
const codeWithIssue = ` | ||
import { Button, Popover, Select } from '@mantine/core'; | ||
import { InputBase } from '@mantine/core'; | ||
function Demo() { | ||
return ( | ||
<Popover width={200} position="bottom" withArrow shadow="md"> | ||
<Popover.Target> | ||
<Button>Toggle popover</Button> | ||
</Popover.Target> | ||
<Popover.Dropdown> | ||
<Select | ||
placeholder="Choose your framework" | ||
data={[ | ||
{ value: 'react', label: 'React' }, | ||
{ value: 'vue', label: 'Vue' }, | ||
{ value: 'angular', label: 'Angular' }, | ||
]} | ||
/> | ||
</Popover.Dropdown> | ||
</Popover> | ||
); | ||
} | ||
`; | ||
|
||
function DemoWithIssue() { | ||
return ( | ||
<Popover width={200} position="bottom" withArrow shadow="md"> | ||
<Popover.Target> | ||
<Button>Toggle popover</Button> | ||
</Popover.Target> | ||
<Popover.Dropdown> | ||
<Select | ||
data={[ | ||
{ value: 'react', label: 'React' }, | ||
{ value: 'vue', label: 'Vue' }, | ||
{ value: 'angular', label: 'Angular' }, | ||
]} | ||
placeholder="Choose your framework" | ||
/> | ||
</Popover.Dropdown> | ||
</Popover> | ||
); | ||
} | ||
|
||
export const NestedPopovers: MantineDemo = { | ||
type: 'code', | ||
component: DemoWithIssue, | ||
code: codeWithIssue, | ||
centered: true, | ||
}; | ||
|
||
const codeWithoutIssue = ` | ||
import { Button, Popover, Select } from '@mantine/core'; | ||
import { InputBase } from '@mantine/core'; | ||
function Demo() { | ||
return ( | ||
<Popover width={200} position="bottom" withArrow shadow="md"> | ||
<Popover.Target> | ||
<Button>Toggle popover</Button> | ||
</Popover.Target> | ||
<Popover.Dropdown> | ||
<Select | ||
comboboxProps={{ withinPortal: false }} | ||
placeholder="Choose your framework" | ||
data={[ | ||
{ value: 'react', label: 'React' }, | ||
{ value: 'vue', label: 'Vue' }, | ||
{ value: 'angular', label: 'Angular' }, | ||
]} | ||
/> | ||
</Popover.Dropdown> | ||
</Popover> | ||
); | ||
} | ||
`; | ||
|
||
function DemoWithoutIssue() { | ||
return ( | ||
<Popover width={200} position="bottom" withArrow shadow="md"> | ||
<Popover.Target> | ||
<Button>Toggle popover</Button> | ||
</Popover.Target> | ||
<Popover.Dropdown> | ||
<Select | ||
comboboxProps={{ withinPortal: false }} | ||
data={[ | ||
{ value: 'react', label: 'React' }, | ||
{ value: 'vue', label: 'Vue' }, | ||
{ value: 'angular', label: 'Angular' }, | ||
]} | ||
placeholder="Choose your framework" | ||
/> | ||
</Popover.Dropdown> | ||
</Popover> | ||
); | ||
} | ||
|
||
export const NestedPopoversWorking: MantineDemo = { | ||
type: 'code', | ||
component: DemoWithoutIssue, | ||
code: codeWithoutIssue, | ||
centered: true, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { Layout } from '@/layout'; | ||
|
||
export const meta = { | ||
title: 'How can I change body background color?', | ||
description: 'Use CSS to change body background color', | ||
slug: 'body-background', | ||
category: 'styles', | ||
tags: ['body', 'html', 'global styles'], | ||
created_at: 'September 8, 2024', | ||
last_updated_at: 'September 8, 2024', | ||
}; | ||
|
||
export default Layout(meta); | ||
|
||
## Change body background with CSS | ||
|
||
To change `body` background color you can use CSS. To do that, create `styles.css` | ||
file in your project and import it at the root of your application: | ||
|
||
```css | ||
body { | ||
background-color: #f9f9f9; | ||
} | ||
``` | ||
|
||
## Change body background with CSS variable | ||
|
||
`--mantine-color-body` CSS variable is used for body background and | ||
as background color of some components ([Modal](https://mantine.dev/core/modal/), [Paper](https://mantine.dev/core/paper/), etc.). | ||
To override this variable, create `styles.css` file in your project and import it at the root of your application: | ||
|
||
```scss | ||
:root { | ||
@mixin light { | ||
--mantine-color-body: #f9f9f9; | ||
} | ||
|
||
@mixin dark { | ||
--mantine-color-body: #333; | ||
} | ||
} | ||
``` |
30 changes: 30 additions & 0 deletions
30
apps/help.mantine.dev/src/pages/q/carousel-missing-styles.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { Layout } from '@/layout'; | ||
|
||
export const meta = { | ||
title: 'Why my Carousel slides are in vertical orientation?', | ||
description: 'You forgot to import carousel styles', | ||
slug: 'carousel-missing-styles', | ||
category: 'styles', | ||
tags: ['carousel', '@mantine/carousel', 'broken'], | ||
created_at: 'September 7, 2024', | ||
last_updated_at: 'September 7, 2024', | ||
}; | ||
|
||
export default Layout(meta); | ||
|
||
## Carousel component looks broken | ||
|
||
If your [Carousel](https://mantine.dev/x/carousel/) component renders slides in vertical orientation | ||
or has incorrect controls/indicators position, you forgot to import carousel styles. | ||
Follow [@mantine/carousel](https://mantine.dev/x/carousel/#installation) installation | ||
instructions to fix the issue. Import `@mantine/core` and `@mantine/carousel` styles at | ||
the root of your application: | ||
|
||
```tsx | ||
import '@mantine/core/styles.css'; | ||
import '@mantine/carousel/styles.css'; | ||
``` | ||
|
||
## That's it! It works now! | ||
|
||
Nice! 👍 |
99 changes: 99 additions & 0 deletions
99
apps/help.mantine.dev/src/pages/q/nested-inline-styles.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
import { Layout } from '@/layout'; | ||
|
||
export const meta = { | ||
title: 'Can I use nested inline styles with Mantine components?', | ||
description: 'Nested styles are supported only in CSS files', | ||
slug: 'nested-inline-styles', | ||
category: 'styles', | ||
tags: ['hover', 'focus', 'data-', '::selection'], | ||
created_at: 'September 7, 2024', | ||
last_updated_at: 'September 7, 2024', | ||
}; | ||
|
||
export default Layout(meta); | ||
|
||
## What are nested inline styles? | ||
|
||
Nested inline styles are commonly used in CSS-in-JS libraries like [emotion](https://emotion.sh/). | ||
Nested inline styles syntax looks something like this (example from [emotion documentation](https://emotion.sh/docs/css-prop#object-styles)): | ||
|
||
```tsx | ||
render( | ||
<div | ||
css={{ | ||
backgroundColor: 'hotpink', | ||
'&:hover': { | ||
color: 'lightgreen', | ||
}, | ||
}} | ||
> | ||
This has a hotpink background. | ||
</div> | ||
); | ||
``` | ||
|
||
## Styles in Mantine components | ||
|
||
Mantine components do not support nested inline styles out of the box. The following | ||
example will not work: | ||
|
||
```tsx | ||
import { Button } from '@mantine/core'; | ||
|
||
function Demo() { | ||
return ( | ||
<Button | ||
style={{ | ||
// ✅ This works | ||
backgroundColor: 'hotpink', | ||
|
||
// ❌ This does not work | ||
'&:hover': { color: 'lightgreen' }, | ||
}} | ||
styles={{ | ||
root: { | ||
// ✅ This works | ||
backgroundColor: 'hotpink', | ||
|
||
// ❌ This does not work | ||
'&[data-disabled]': { color: 'lightgreen' }, | ||
'&:hover': { color: 'lightgreen' }, | ||
'&:focus': { color: 'lightgreen' }, | ||
'& span': { color: 'lightgreen' }, | ||
}, | ||
}} | ||
> | ||
This has a hotpink background. | ||
</Button> | ||
); | ||
} | ||
``` | ||
|
||
## Why nested inline styles are not supported? | ||
|
||
Mantine does not use CSS-in-JS library for styling – all styles are either in CSS files | ||
or inline in the `style` attribute which does not support nested styles. Mantine does not | ||
use CSS-in-JS to keep bundle size small, provide support for server-side rendering and | ||
improve performance. You can learn more about performance [in the styles performance guide](https://mantine.dev/styles/styles-performance/). | ||
|
||
## What is the alternative? | ||
|
||
You can use nested selectors in [CSS files](https://mantine.dev/styles/css-modules/): | ||
|
||
```scss | ||
.button { | ||
background-color: hotpink; | ||
|
||
&:hover { | ||
color: lightgreen; | ||
} | ||
} | ||
``` | ||
|
||
To learn more about styles in Mantine, follow [CSS modules](https://mantine.dev/styles/css-modules/), | ||
[PostCSS preset](https://mantine.dev/styles/postcss-preset/) and [Styles API](https://mantine.dev/styles/styles-api/) guides. | ||
|
||
## I still want to use nested inline styles | ||
|
||
Mantine has support for emotion. To set it up, follow [emotion installation guide](https://mantine.dev/styles/emotion/). | ||
Note that this will increase bundle size and will affect performance. |
Oops, something went wrong.