-
-
Notifications
You must be signed in to change notification settings - Fork 3
feat: support classNames/styles semantic DOM API #51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
zombieJ
merged 6 commits into
react-component:master
from
aojunhao123:feat/semantic-dom-api
Jun 30, 2026
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
375fc1f
feat: support classNames/styles semantic DOM API
aojunhao123 0b2df82
chore: ignore .claude directory in git
aojunhao123 9de88bb
fix: keep computed sticky header top from being overridden by styles.…
aojunhao123 531ceb5
docs: add semantic DOM demo
aojunhao123 7fce56b
fix: keep item scrollMarginTop from being overridden by styles.item
aojunhao123 b7e67b5
test: guard internal positioning against styles overrides
aojunhao123 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -40,4 +40,6 @@ bun.lockb | |
|
|
||
| # dumi | ||
| .dumi/tmp | ||
| .dumi/tmp-production | ||
| .dumi/tmp-production | ||
|
|
||
| .claude | ||
This file contains hidden or 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,8 @@ | ||
| --- | ||
| title: Semantic DOM | ||
| nav: | ||
| title: Demo | ||
| path: /demo | ||
| --- | ||
|
|
||
| <code src="../examples/semantic.tsx"></code> |
This file contains hidden or 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,105 @@ | ||
| import React, { useRef, useState } from 'react'; | ||
| import Listy, { | ||
| type ListyRef, | ||
| type ListyClassNames, | ||
| type ListyStyles, | ||
| } from '@rc-component/listy'; | ||
| import '../../assets/index.less'; | ||
|
|
||
| const GROUPS = [ | ||
| { id: 'frontend', label: 'Frontend' }, | ||
| { id: 'backend', label: 'Backend' }, | ||
| { id: 'infra', label: 'Infrastructure' }, | ||
| { id: 'mobile', label: 'Mobile' }, | ||
| ]; | ||
|
|
||
| interface Task { | ||
| id: string; | ||
| name: string; | ||
| groupId: string; | ||
| } | ||
|
|
||
| const items: Task[] = GROUPS.flatMap((group) => | ||
| Array.from({ length: 8 }, (_, index) => ({ | ||
| id: `${group.id}-${index}`, | ||
| name: `${group.label} task #${index + 1}`, | ||
| groupId: group.id, | ||
| })), | ||
| ); | ||
|
|
||
| // The `classNames` and `styles` props share the same semantic slots: | ||
| // `root`, `item`, and `groupHeader` (including the sticky clone). | ||
| const classNames: ListyClassNames = { | ||
| root: 'listy-semantic-root', | ||
| groupHeader: 'listy-semantic-header', | ||
| item: 'listy-semantic-item', | ||
| }; | ||
|
|
||
| // Inline `styles` stack on top of the classNames above. | ||
| const styles: ListyStyles = { | ||
| root: { borderRadius: 10 }, | ||
| groupHeader: { letterSpacing: 0.5 }, | ||
| item: { transition: 'background 0.15s ease' }, | ||
| }; | ||
|
|
||
| const CSS = ` | ||
| .listy-semantic-root { | ||
| border: 1px solid #e5e7eb; | ||
| overflow: hidden; | ||
| background: #fff; | ||
| font-family: system-ui, sans-serif; | ||
| } | ||
| .listy-semantic-header { | ||
| padding: 10px 16px; | ||
| font-weight: 600; | ||
| color: #fff; | ||
| background: linear-gradient(90deg, #6366f1, #8b5cf6); | ||
| } | ||
| .listy-semantic-item { | ||
| padding: 0 16px; | ||
| line-height: 40px; | ||
| border-bottom: 1px solid #f3f4f6; | ||
| } | ||
| .listy-semantic-item:hover { | ||
| /* hover state — only a className slot can express this, not inline styles */ | ||
| background: #f5f3ff; | ||
| } | ||
| `; | ||
|
|
||
| export default () => { | ||
| const listRef = useRef<ListyRef>(null); | ||
| const [virtual, setVirtual] = useState(true); | ||
|
|
||
| return ( | ||
| <> | ||
| <style>{CSS}</style> | ||
| <div style={{ display: 'flex', flexDirection: 'column', gap: 12 }}> | ||
| <label style={{ display: 'flex', alignItems: 'center', gap: 6 }}> | ||
| <input | ||
| type="checkbox" | ||
| checked={virtual} | ||
| onChange={(event) => setVirtual(event.target.checked)} | ||
| /> | ||
| virtual — the same classNames / styles apply in both render modes | ||
| </label> | ||
| <Listy | ||
| ref={listRef} | ||
| height={360} | ||
| itemHeight={40} | ||
| items={items} | ||
| rowKey="id" | ||
| sticky | ||
| virtual={virtual} | ||
| classNames={classNames} | ||
| styles={styles} | ||
| itemRender={(item) => item.name} | ||
| group={{ | ||
| key: (item) => item.groupId, | ||
| title: (groupKey) => | ||
| GROUPS.find((group) => group.id === groupKey)?.label ?? groupKey, | ||
| }} | ||
| /> | ||
| </div> | ||
| </> | ||
| ); | ||
| }; |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1,5 +1,11 @@ | ||
| import Listy from './List'; | ||
|
|
||
| export type { ListyRef, ListyProps } from './List'; | ||
| export type { | ||
| ListyRef, | ||
| ListyProps, | ||
| ListySemanticName, | ||
| ListyClassNames, | ||
| ListyStyles, | ||
| } from './List'; | ||
|
|
||
| export default Listy; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.