Dot notation for React components: Dialog.Title and one composition
How to group UI parts on one object with Object.assign, why that helps dialogs and forms, and the tree-shaking tradeoff.
Dot notation is the pattern of hanging the parts of a component off one object (Dialog.Title, Dialog.Content). It keeps the structure in one place, makes the markup easier to read, and stops the same spacing from being copied across a dozen files.
Here it is on a Dialog.
How it usually looks without composition
import {
Typography,
Dialog,
Box,
CloseIcon,
Button,
} from "@ui-lib";
export function Example() {
return (
<Dialog>
<Box p={1} display="flex" justifyContent="space-between">
<Typography variant="h5">Dialog title</Typography>
<CloseIcon onClick={handleClose} />
</Box>
<Typography variant="body1">Dialog content</Typography>
<Box p={2}>
<Button>Cancel</Button>
<Button>Confirm</Button>
</Box>
</Dialog>
);
}
What goes wrong
- Repetition, and it is brittle. Once you have more than a couple of these dialogs, a design or structure change has to be carried through every call site.
- No explicit composition. It is easy to end up with different spacing, block order, and typography, because each dialog is assembled from primitives from scratch.
Dot notation: one root, predictable parts
Build the pieces (title, content, actions) as their own components and attach them to the base dialog with Object.assign:
const DialogTitle: React.FC<DialogTitleProps> = ({
title,
onClose,
titleVariant = "h6",
...props
}) => (
<MuiDialogTitle {...props}>
<Box display="flex" justifyContent="space-between" alignItems="center">
<Typography variant={titleVariant}>{title}</Typography>
{onClose && (
<IconButton onClick={onClose} size="small">
<CloseIcon />
</IconButton>
)}
</Box>
</MuiDialogTitle>
);
// Content, Actions, and Button follow the same shape.
export const Dialog = Object.assign(BaseDialog, {
Title: DialogTitle,
Content: DialogContent,
Actions: DialogActions,
Button: DialogButton,
});
Usage after the refactor:
<Dialog open={open} onClose={onClose}>
<Dialog.Title title="Title" onClose={onClose} />
<Dialog.Content>Content</Dialog.Content>
<Dialog.Actions>
<Dialog.Button onClick={onClose}>Cancel</Dialog.Button>
<Dialog.Button onClick={handleSubmit} variant="contained">
Add
</Dialog.Button>
</Dialog.Actions>
</Dialog>
Upsides
- Readability — the role of each block in the dialog is visible immediately.
- Autocomplete — the IDE offers
Title,Content, andActionsfrom one root. - It scales — a change in
Dialog.Titleshows up on every screen at once. - One import —
Dialogis the entry point, instead of a long list of primitives.
Downsides
- Tree-shaking. If the whole
Dialoglives in one module built withObject.assign, the bundler has a harder time dropping unused subcomponents than it does with separate named exports. In practice you split the package into submodules, use lazy imports, or design the package with that limit in mind — but the limit is worth remembering.
In short: dot notation is a useful layer on top of a design system when consistency and maintenance matter. For a library with a hard bundle-size budget, think separately about how the code is split into chunks. In an application, the gain in developer experience often wins.