--- name: "naive-ui-design-layout" description: "Layout system for Naive UI including Grid, Flex, Space, and Layout components. Invoke when user needs to create responsive layouts, grid systems, or understand layout components." metadata: author: jiaiyan version: "1.0.0" --- # Layout System Naive UI provides a comprehensive layout system including CSS Grid-based layout, Flexbox, Space, and Layout components for building responsive page structures. ## When to Use - Creating responsive grid layouts - Building page structures with header, sidebar, content, and footer - Implementing flexible layouts with Flexbox - Adding consistent spacing between elements --- ## Grid System (n-grid) Naive UI uses a CSS Grid-based layout system with 24 columns by default. ### Basic Concepts - **24-column system**: Default is 24 columns, configurable - **CSS Grid**: Uses native CSS Grid for layout - **Responsive**: Supports responsive breakpoints - **Flexible**: Items can span multiple columns ### Basic Grid ```vue ``` ### Grid with Gaps ```vue ``` ### Responsive Grid ```vue ``` ### Grid Item Offset ```vue ``` ### Grid Props | Name | Description | Type | Default | |------|-------------|------|---------| | cols | Number of columns | `number \| string` | `24` | | x-gap | Horizontal gap | `number \| string` | `0` | | y-gap | Vertical gap | `number \| string` | `0` | | responsive | Responsive mode | `'self' \| 'screen'` | `'self'` | | collapsed | Collapsed state | `boolean` | `false` | | collapsedRows | Rows when collapsed | `number` | `1` | ### Grid Item Props | Name | Description | Type | Default | |------|-------------|------|---------| | span | Number of columns to span | `number \| string` | `1` | | offset | Number of columns to offset | `number` | `0` | | suffix | Whether it's a suffix item | `boolean` | `false` | --- ## Flex Component (n-flex) A flexible flexbox layout component. ### Basic Flex ```vue ``` ### Flex with Justify ```vue ``` ### Flex Vertical ```vue ``` ### Flex Props | Name | Description | Type | Default | |------|-------------|------|---------| | justify | Horizontal alignment | `'start' \| 'end' \| 'center' \| 'space-around' \| 'space-between' \| 'space-evenly'` | `'start'` | | align | Vertical alignment | `'start' \| 'end' \| 'center' \| 'stretch' \| 'baseline'` | — | | vertical | Vertical direction | `boolean` | `false` | | reverse | Reverse direction | `boolean` | `false` | | wrap | Enable wrapping | `boolean` | `true` | | inline | Inline flex | `boolean` | `false` | | size | Gap size | `'small' \| 'medium' \| 'large' \| number \| [number, number]` | `'medium'` | --- ## Space Component (n-space) Add consistent spacing between elements. ### Basic Space ```vue ``` ### Space Sizes ```vue ``` ### Vertical Space ```vue ``` ### Space Props | Name | Description | Type | Default | |------|-------------|------|---------| | size | Gap size | `'small' \| 'medium' \| 'large' \| number \| [number, number]` | `'small'` | | vertical | Vertical direction | `boolean` | `false` | | wrap | Enable wrapping | `boolean` | `true` | | inline | Inline mode | `boolean` | `false` | --- ## Layout Components (n-layout) Build complete page layouts with header, sidebar, content, and footer. ### Basic Layout ```vue ``` ### Layout with Sidebar ```vue ``` ### Collapsible Sidebar ```vue ``` ### Layout Props | Name | Description | Type | Default | |------|-------------|------|---------| | embedded | Embedded mode (no background) | `boolean` | `false` | | position | Position mode | `'static' \| 'absolute'` | `'static'` | | native-scrollbar | Use native scrollbar | `boolean` | `true` | | has-sider | Has sidebar | `boolean` | `false` | | sider-placement | Sidebar placement | `'left' \| 'right'` | `'left'` | ### Layout Sider Props | Name | Description | Type | Default | |------|-------------|------|---------| | bordered | Show border | `boolean` | `false` | | collapsed | Collapsed state | `boolean` | `false` | | collapse-mode | Collapse mode | `'width' \| 'transform'` | `'transform'` | | collapsed-width | Width when collapsed | `number` | `48` | | width | Sidebar width | `number` | `272` | | show-trigger | Show collapse trigger | `boolean` | `false` | --- ## Responsive Breakpoints Naive UI uses default breakpoints for responsive design: | Breakpoint | Screen Width | |------------|--------------| | `xs` | `< 640px` | | `s` | `≥ 640px` | | `m` | `≥ 1024px` | | `l` | `≥ 1280px` | | `xl` | `≥ 1536px` | | `xxl` | `≥ 1920px` | ### Using Breakpoints ```vue ``` --- ## Best Practices 1. **Use Grid for 2D layouts**: Use `n-grid` when you need both rows and columns 2. **Use Flex for 1D layouts**: Use `n-flex` for single-row or single-column layouts 3. **Use Space for simple gaps**: Use `n-space` for consistent spacing between elements 4. **Layout composition**: Combine Layout components for full-page structures 5. **Responsive design**: Use responsive props for mobile-first design 6. **Collapsed sidebar**: Use `collapse-mode="width"` for better animation performance --- ## Related Resources | Resource | Description | |----------|-------------| | [Grid Component](https://www.naiveui.com/en-US/os-theme/components/grid) | Grid documentation | | [Flex Component](https://www.naiveui.com/en-US/os-theme/components/flex) | Flex documentation | | [Space Component](https://www.naiveui.com/en-US/os-theme/components/space) | Space documentation | | [Layout Component](https://www.naiveui.com/en-US/os-theme/components/layout) | Layout documentation |