feat(streamdown): add hierarchical list bullet styles with depth trac… - #489
feat(streamdown): add hierarchical list bullet styles with depth trac…#489simon5057 wants to merge 2 commits into
Conversation
…king(vercel#377) Add `listStyle` prop to configure bullet style cycling for nested unordered lists. Defaults to hierarchical mode which cycles through disc → circle → square styles based on nesting depth. Features: - Two style presets: flat (uniform disc, backward compatible) and hierarchical (disc/circle/square cycling) - `data-depth` attributes on all list elements for custom CSS targeting - Proper unordered depth tracking that skips ordered list nesting - Context-based depth propagation for accurate per-level styling
- Add listStyle to Styling Props TypeTable in configuration.mdx
|
@simon5057 is attempting to deploy a commit to the Vercel Team on Vercel. A member of the Team first needs to authorize it. |
|
Thanks for the PR, @simon5057! ul[data-streamdown="unordered-list"] {
list-style-type: disc;
}
ul ul[data-streamdown="unordered-list"] {
list-style-type: circle;
}
ul ul ul[data-streamdown="unordered-list"] {
list-style-type: square;
} |
Thanks for the suggestion, @farnabaz ! After comparing both approaches, I agree that CSS is the better fit if the intended change is only to provide hierarchical bullet styles by default. |
feat(streamdown): add hierarchical list bullet styles with depth tracking (#377)
Add
listStyleprop to configure bullet style cycling for nested unordered lists. Defaults to hierarchical mode which cycles through disc → circle → square styles based on nesting depth.Features:
data-depthattributes on all list elements for custom CSS targetingDescription
Adds depth-aware bullet styling to nested unordered lists in the
streamdownpackage. Previously all list items rendered with the same bullet style regardless of nesting level. Now the default"hierarchical"mode cycles through disc → circle → square as lists nest deeper, making it visually easy to distinguish list depth. Users who prefer uniform styling can opt into"flat"mode. All list elements receive adata-depthattribute for full custom CSS control.Type of Change
Related Issues
Fixes #
Closes #
Related to #
Changes Made
ListStylePresettype ("flat" | "hierarchical") andlistStyleprop toStreamdownPropsinindex.tsxlistStyletoStreamdownContextTypewith default value"hierarchical"ListContextinlib/components.tsxto trackdepth,ulDepth, andisUnorderedthrough the component treeLI_BULLET_STYLESpreset map applying bullet classes (list-disc,list-[circle],list-[square]) on<li>elements based onulDepthdata-depthattributes to all<ul>,<ol>, and<li>elements for custom CSS targetingremendalias tovitest.config.tsfor proper module resolution in testsTesting
Test Coverage
Created
packages/streamdown/__tests__/list-style.test.tsxwith 9 dedicated test cases:data-depth on <ul>data-depth="0", nested hasdata-depth="1"data-depth on <ol>data-depth on <li>flat mode<li>uselist-discregardless of depthhierarchical modeno bullets in <ol><li>inside<ol>receive no bullet classno bullet class on <ul><li>, not parent<ul>sibling lists resetmixed ol/ululDepthonly counts<ul>levels, skipping<ol>nestingAll 142 tests passing across 5 test files.
Checklist
pnpm changeset)Changeset
Additional Notes
Custom styling via
data-depth:Users can target specific nesting depths directly in CSS without needing a new preset:
ulDepthvsdepth:ulDepthcounts only<ul>nesting levels and is used to determine the bullet style cycle. Totaldepth(which includes<ol>) is used fordata-depthattributes. This means an<li>inside<ol> > <ul>correctly receives the depth-1 bullet style (disc), not depth-2, since the outer<ol>doesn't affect unordered bullet cycling.