JGuang

Stack

Stack · Material UI

Preview
npm install @mui/material@9.4.0 @emotion/react@11.14.0 @emotion/styled@11.14.1

Stack

Lay out immediate children in one dimension with spacing and dividers.

This guide covers Material UI Core with the default Emotion engine; extensions and additional demos are explicitly classified.

Use case and business boundary

Use sx for additional system styling in this version; PigmentStack requires a separate engine integration.

Native composition and scope

Stack

Preserve native Material UI composition and types; do not substitute JGuang UI/Base UI/Radix APIs. Example entries are not extra components.

Excluded integrations: PigmentStack (@mui/material-pigment-css). Not claimed verified in the default Emotion environment.

Native installation and initialization

npm install @mui/material@9.4.0 @emotion/react@11.14.0 @emotion/styled@11.14.1

Use native npm and Emotion, not an invented JGuang UI Registry URL. Place examples inside native ThemeProvider; choose CssBaseline or ScopedCssBaseline for the project. Inspect React, existing providers, lockfile and SSR first. Never overwrite files or conceal peer conflicts. This batch verified React 19.2.8; React 18 and below require matching react-is. See the included bilingual setup guide.

Practical native parameters

These selected parameters are not a flattened universal API. Preserve the native declaring owner, slot structure, nullable values and generics.

Owner.propPractical roleDeclaration source
Stack.directionOwning native direction enum; layout, sorting and transition directions differ.Stack
Stack.spacingNative theme-spacing units or supported CSS lengths; not always raw pixels.Stack
Stack.dividerNative Stack separator element between immediate children.Stack
Stack.useFlexGapUse CSS flex gap instead of margin-based Stack spacing.Stack

Runnable native examples

Machine keys select example entries, not universal variant props. Native demo JSX/data stay unchanged; JGuang-authored acceptance fixtures are explicitly labelled.

  • Basics · BasicStack · upstream native demo
  • Direction · DirectionStack · upstream native demo
  • Dividers · DividerStack · upstream native demo
  • Responsive values · ResponsiveStack · upstream native demo
  • Flexbox gap · FlexboxGapStack · upstream native demo
  • white-space: nowrap · ZeroWidthStack · upstream native demo

Explicitly unsupported additional examples

These remain in the upstream inventory, not silently skipped or presented as working previews. Additional dependency/framework acceptance is required.

  • Interactive demo · InteractiveStack: @mui/internal-core-docs/HighlightedCode

Actual usage example

Unmodified pinned native demo; copy its required local helper files together.

import Box from '@mui/material/Box';
import Paper from '@mui/material/Paper';
import Stack from '@mui/material/Stack';
import { styled } from '@mui/material/styles';

const Item = styled(Paper)(({ theme }) => ({
  backgroundColor: '#fff',
  ...theme.typography.body2,
  padding: theme.spacing(1),
  textAlign: 'center',
  color: (theme.vars ?? theme).palette.text.secondary,
  ...theme.applyStyles('dark', {
    backgroundColor: '#1A2027',
  }),
}));

export default function BasicStack() {
  return (
    <Box sx={{ width: '100%' }}>
      <Stack spacing={2}>
        <Item>Item 1</Item>
        <Item>Item 2</Item>
        <Item>Item 3</Item>
      </Stack>
    </Box>
  );
}

Example dependency boundaries

@mui/material/Box, @mui/material/Paper, @mui/material/Stack, @mui/material/styles, @mui/material/Divider, @mui/material/Avatar, @mui/material/Typography

Direct Icons/System/Utils example imports require their matching 9.4.0 packages. Relative data/helpers are part of the example closure, not extra components. Remote images and simulated operations do not supply a backend.

Pinned upstream API metadata reference

These tables retain the upstream metadata, not a newly inferred generic type system. Conditional generics, inherited props and callback details are defined by the source declarations below. Theme defaults may override metadata defaults.

Stack

import Stack from '@mui/material/Stack';
import { Stack } from '@mui/material';
PropRequiredUpstream metadata type / constraintMetadata default
childrennonode—
componentnoelementType—
directionno'column-reverse' | 'column' | 'row-reverse' | 'row' | Array<'column-reverse' | 'column' | 'row-reverse' | 'row'> | object'column'
dividernonode—
spacingnoArray<number | string> | number | object | string0
sxnoArray<func | object | bool> | func | object—
useFlexGapnoboolfalse

Native source declarations

Declarations/imports are extracted from pinned source without flattening unions or external inheritance. Original English comments/types are source reference, not a claim of translated upstream prose. Shared types stay in their native packages.

vendor/src/Stack/Stack.d.ts

import * as React from 'react';

import { ResponsiveStyleValue, SxProps } from '@mui/system';

import { OverrideProps, OverridableComponent } from '../OverridableComponent';

import { Theme } from '../styles/createTheme';

export interface StackOwnProps {
  /**
   * The content of the component.
   */
  children?: React.ReactNode;
  /**
   * Defines the `flex-direction` style property.
   * It is applied for all screen sizes.
   * @default 'column'
   */
  direction?: ResponsiveStyleValue<'row' | 'row-reverse' | 'column' | 'column-reverse'> | undefined;
  /**
   * Defines the space between immediate children.
   * @default 0
   */
  spacing?: ResponsiveStyleValue<number | string> | undefined;
  /**
   * Add an element between each child.
   */
  divider?: React.ReactNode;
  /**
   * If `true`, the CSS flexbox `gap` is used instead of applying `margin` to children.
   *
   * While CSS `gap` removes the known limitations,
   * it is not fully supported in some browsers. We recommend checking https://caniuse.com/?search=flex%20gap before using this flag.
   *
   * To enable this flag globally, follow the [theme's default props](https://mui.com/material-ui/customization/theme-components/#default-props) configuration.
   * @default false
   */
  useFlexGap?: boolean | undefined;
  /**
   * The system prop, which allows defining system overrides as well as additional CSS styles.
   */
  sx?: SxProps<Theme> | undefined;
}

export interface StackTypeMap<
  AdditionalProps = {},
  RootComponent extends React.ElementType = 'div',
> {
  props: AdditionalProps & StackOwnProps;
  defaultComponent: RootComponent;
}

declare const Stack: OverridableComponent<StackTypeMap>;

export type StackProps<
  RootComponent extends React.ElementType = StackTypeMap['defaultComponent'],
  AdditionalProps = {},
> = OverrideProps<StackTypeMap<AdditionalProps, RootComponent>, RootComponent> & {
  component?: React.ElementType | undefined;
};

Post-install acceptance

Run strict types, production build and real interactions. Check keyboard labels/focus, disabled/error/read-only semantics where natively supported, both themes, narrow screens and reduced motion. Verify callbacks against the real host data; do not declare installation complete from copying a prompt. Initialization fixtures also require server HTML and warning-free hydration.

Source and license

https://github.com/mui/material-ui/tree/809a7717b4c050ba3f69b75300689f07c050a16e

MIT · @mui/material@9.4.0. Vendor originals and license are preserved. Full original upstream prose remains in vendor/docs and is not represented as fully translated.