-
Notifications
You must be signed in to change notification settings - Fork 646
migrate TreeView to CSS modules #5267
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
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
1705d26
replace sx with Primer CSS utility classes where possible
ktravers bc8a555
add support for style prop to TreeView Root
ktravers 6db4c49
Convert ul to css modules
ktravers dbe480e
Reference CSS module classnames
ktravers 4a1c8ab
update skeleton components to use css modules
ktravers e079507
add test for className support
ktravers 65acaac
add changeset
ktravers 0953ff9
auto fix with 'npm run lint:css:fix'
ktravers c2a6b56
fix syntax for multiple modules classes
ktravers 21adedb
update variable to prevent regression test failures
ktravers e97cf72
workaround for directory icon color
ktravers c1cf6e3
use `where` with attribute selector
ktravers a452922
use up-to-date color variable
ktravers 1f6b6bc
Use `where` with attr selectors
ktravers ae474e3
Merge branch 'main' into ktravers/rm-sx-from-tree-view
ktravers 0718102
drop PRIVATE_ prefix from css module classnames
ktravers fbe385d
Remove unnecessary workaround for dark high contrast mode
ktravers bdd9ffd
test(vrt): update snapshots
langermank 919f426
Merge branch 'main' into ktravers/rm-sx-from-tree-view
jonrohan 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 |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@primer/react": minor | ||
| --- | ||
|
|
||
| Update `TreeView` component to use CSS Modules | ||
Binary file modified
BIN
+9 Bytes
(100%)
...onents/TreeView.test.ts-snapshots/TreeView-Default-dark-high-contrast-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+16 Bytes
(100%)
...eView.test.ts-snapshots/TreeView-Empty-Directories-dark-high-contrast-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+26 Bytes
(100%)
.../TreeView.test.ts-snapshots/TreeView-Files-Changed-dark-high-contrast-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-2 Bytes
(100%)
...mponents/TreeView.test.ts-snapshots/TreeView-Files-dark-high-contrast-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Copied styles directly from TreeView component, then migrated to CSS variables following this guide: https://primer.style/foundations/primitives/migrating#migrating-from-sx-props-primer-react |
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,260 @@ | ||
| .TreeViewRootUlStyles { | ||
| padding: 0; | ||
| margin: 0; | ||
| list-style: none; | ||
|
|
||
| /* | ||
| * WARNING: This is a performance optimization. | ||
| * | ||
| * We define styles for the tree items at the root level of the tree | ||
| * to avoid recomputing the styles for each item when the tree updates. | ||
| * We're sacrificing maintainability for performance because TreeView | ||
| * needs to be performant enough to handle large trees (thousands of items). | ||
| * | ||
| * This is intended to be a temporary solution until we can improve the | ||
| * performance of our styling patterns. | ||
| * | ||
| * Do NOT copy this pattern without understanding the tradeoffs. | ||
| */ | ||
| .TreeViewItem { | ||
| outline: none; | ||
|
|
||
| &:focus-visible > div, | ||
| &.focus-visible > div { | ||
| box-shadow: var(--boxShadow-thick) var(--fgColor-accent); | ||
|
|
||
| @media (forced-colors: active) { | ||
| outline: 2px solid HighlightText; | ||
| outline-offset: -2; | ||
| } | ||
| } | ||
|
|
||
| &[data-has-leading-action] { | ||
| --has-leading-action: 1; | ||
| } | ||
| } | ||
|
|
||
| .TreeViewItemContainer { | ||
| --level: 1; | ||
| --toggle-width: 1rem; | ||
| --min-item-height: 2rem; | ||
|
|
||
| position: relative; | ||
| display: grid; | ||
| width: 100%; | ||
| font-size: var(--text-body-size-medium); | ||
| color: var(--fgColor-default); | ||
| cursor: pointer; | ||
| border-radius: var(--borderRadius-medium); | ||
| grid-template-columns: var(--spacer-width) var(--leading-action-width) var(--toggle-width) 1fr; | ||
| grid-template-areas: 'spacer leadingAction toggle content'; | ||
|
|
||
| --leading-action-width: calc(var(--has-leading-action, 0) * 1.5rem); | ||
| --spacer-width: calc(calc(var(--level) - 1) * (var(--toggle-width) / 2)); | ||
|
|
||
| &:hover { | ||
| background-color: var(--control-transparent-bgColor-hover); | ||
|
|
||
| @media (forced-colors: active) { | ||
| outline: 2px solid transparent; | ||
| outline-offset: -2px; | ||
| } | ||
| } | ||
|
|
||
| @media (pointer: coarse) { | ||
| --toggle-width: 1.5rem; | ||
| --min-item-height: 2.75rem; | ||
| } | ||
|
|
||
| &:has(.TreeViewItemSkeleton):hover { | ||
| cursor: default; | ||
| background-color: transparent; | ||
|
|
||
| @media (forced-colors: active) { | ||
| outline: none; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| &:where([data-omit-spacer='true']) .TreeViewItemContainer { | ||
| grid-template-columns: 0 0 0 1fr; | ||
| } | ||
|
|
||
| .TreeViewItem[aria-current='true'] > .TreeViewItemContainer { | ||
| background-color: var(--control-transparent-bgColor-selected); | ||
|
|
||
| /* Current item indicator */ | ||
| /* stylelint-disable-next-line selector-max-specificity */ | ||
| &::after { | ||
| position: absolute; | ||
| top: calc(50% - var(--base-size-12)); | ||
| left: calc(-1 * var(--base-size-8)); | ||
| width: 0.25rem; | ||
| height: 1.5rem; | ||
| content: ''; | ||
|
|
||
| /* | ||
| * Use fgColor accent for consistency across all themes. Using the "correct" variable, | ||
| * --bgColor-accent-emphasis, causes vrt failures for dark high contrast mode | ||
| */ | ||
| /* stylelint-disable-next-line primer/colors */ | ||
| background-color: var(--fgColor-accent); | ||
| border-radius: var(--borderRadius-medium); | ||
|
|
||
| @media (forced-colors: active) { | ||
| background-color: HighlightText; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| .TreeViewItemToggle { | ||
| display: flex; | ||
| height: 100%; | ||
|
|
||
| /* The toggle should appear vertically centered for single-line items, but remain at the top for items that wrap | ||
| across more lines. */ | ||
| /* stylelint-disable-next-line primer/spacing */ | ||
| padding-top: calc(var(--min-item-height) / 2 - var(--base-size-12) / 2); | ||
| color: var(--fgColor-muted); | ||
| grid-area: toggle; | ||
| justify-content: center; | ||
| align-items: flex-start; | ||
| } | ||
|
|
||
| .TreeViewItemToggleHover:hover { | ||
| background-color: var(--control-transparent-bgColor-hover); | ||
| } | ||
|
|
||
| .TreeViewItemToggleEnd { | ||
| border-top-left-radius: var(--borderRadius-medium); | ||
| border-bottom-left-radius: var(--borderRadius-medium); | ||
| } | ||
|
|
||
| .TreeViewItemContent { | ||
| display: flex; | ||
| height: 100%; | ||
| padding: 0 var(--base-size-8); | ||
|
|
||
| /* The dynamic top and bottom padding to maintain the minimum item height for single line items */ | ||
| /* stylelint-disable-next-line primer/spacing */ | ||
| padding-top: calc((var(--min-item-height) - var(--custom-line-height, 1.3rem)) / 2); | ||
| /* stylelint-disable-next-line primer/spacing */ | ||
| padding-bottom: calc((var(--min-item-height) - var(--custom-line-height, 1.3rem)) / 2); | ||
| line-height: var(--custom-line-height, var(--text-body-lineHeight-medium, 1.4285)); | ||
| grid-area: content; | ||
| gap: var(--stack-gap-condensed); | ||
| } | ||
|
|
||
| .TreeViewItemContentText { | ||
| flex: 1 1 auto; | ||
| width: 0; | ||
| } | ||
|
|
||
| &:where([data-truncate-text='true']) .TreeViewItemContentText { | ||
| overflow: hidden; | ||
| text-overflow: ellipsis; | ||
| white-space: nowrap; | ||
| } | ||
|
|
||
| &:where([data-truncate-text='false']) .TreeViewItemContentText { | ||
| word-break: break-word; | ||
| } | ||
|
|
||
| .TreeViewItemVisual { | ||
| display: flex; | ||
|
|
||
| /* The visual icons should appear vertically centered for single-line items, but remain at the top for items that wrap | ||
| across more lines. */ | ||
| height: var(--custom-line-height, 1.3rem); | ||
| color: var(--fgColor-muted); | ||
| align-items: center; | ||
| } | ||
|
|
||
| .TreeViewItemLeadingAction { | ||
| display: flex; | ||
| color: var(--fgColor-muted); | ||
| grid-area: leadingAction; | ||
| } | ||
|
|
||
| .TreeViewItemLevelLine { | ||
| width: 100%; | ||
| height: 100%; | ||
|
|
||
| /* | ||
| * On devices without hover, the nesting indicator lines | ||
| * appear at all times. | ||
| */ | ||
| border-color: var(--borderColor-muted); | ||
| border-right: var(--borderWidth-thin) solid; | ||
| } | ||
|
|
||
| /* | ||
| * On devices with :hover support, the nesting indicator lines | ||
| * fade in when the user mouses over the entire component, | ||
| * or when there's focus inside the component. This makes | ||
| * sure the component remains simple when not in use. | ||
| */ | ||
| @media (hover: hover) { | ||
| .TreeViewItemLevelLine { | ||
| border-color: transparent; | ||
| } | ||
|
|
||
| &:hover .TreeViewItemLevelLine, | ||
| &:focus-within .TreeViewItemLevelLine { | ||
| border-color: var(--borderColor-muted); | ||
| } | ||
| } | ||
|
|
||
| .TreeViewDirectoryIcon { | ||
| display: grid; | ||
| color: var(--treeViewItem-leadingVisual-iconColor-rest); | ||
ktravers marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| .TreeViewVisuallyHidden { | ||
| position: absolute; | ||
| width: 1px; | ||
| height: 1px; | ||
| padding: 0; | ||
| /* stylelint-disable-next-line primer/spacing */ | ||
| margin: -1px; | ||
| overflow: hidden; | ||
| clip: rect(0, 0, 0, 0); | ||
| white-space: nowrap; | ||
| border-width: 0; | ||
| } | ||
| } | ||
|
|
||
| .TreeViewSkeletonItemContainerStyle { | ||
| display: flex; | ||
| align-items: center; | ||
| column-gap: 0.5rem; | ||
| height: 2rem; | ||
|
|
||
| @media (pointer: coarse) { | ||
| height: 2.75rem; | ||
| } | ||
|
|
||
| &:nth-of-type(5n + 1) { | ||
| --tree-item-loading-width: 67%; | ||
| } | ||
|
|
||
| &:nth-of-type(5n + 2) { | ||
| --tree-item-loading-width: 47%; | ||
| } | ||
|
|
||
| &:nth-of-type(5n + 3) { | ||
| --tree-item-loading-width: 73%; | ||
| } | ||
|
|
||
| &:nth-of-type(5n + 4) { | ||
| --tree-item-loading-width: 64%; | ||
| } | ||
|
|
||
| &:nth-of-type(5n + 5) { | ||
| --tree-item-loading-width: 50%; | ||
| } | ||
| } | ||
|
|
||
| .TreeItemSkeletonTextStyles { | ||
| width: var(--tree-item-loading-width, 67%); | ||
| } | ||
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
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.