Skip to content
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

refactor: wp-791 dropdown menu #1028

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

wesleyboar
Copy link
Member

@wesleyboar wesleyboar commented Dec 3, 2024

Overview

Refactor the styles for Data Files dropdown menus to:

  • share more CSS
  • use clearer CSS

Related

Changes

.dropdown-menu:

  • remove redundant code
  • use <Dropdown> not <ButtonDropdown>1
  • clean up styles
  • use CSS var's for arrow and border
  • style .dropdown-divider like .complex-dropdown-item

DataFilesSidebar:

  • fix layout of menu and button
  • use <DropdownItem divider> like DataFilesBreadcrumbs

DataFilesBreadcrumbs:

  • use class not ID
  • position via top not margin-top
  • explain menu position value
  • explain why positioning is necessary2

Testing

  1. Open Data Files.
  2. Click "Add +" button.
    • Verify button is centered.
    • Verify menu is centered.
    • Verify menu is not cut off.
    • Verify menu is wider than button.
    • Verify elements are otherwise unchanged.
  3. Click "Go to ..." button.
    • Verify elements are unchanged.

UI

…Dropdown A …Dropdown B …Sidebar
DataFilesDropdown A DataFilesDropdown B DataFilesSidebar

Notes

Footnotes

  1. I don't see ButtonDropdown in latest ReactStrap (v9).

  2. Not desired, but necessary if we use our custom <Button> as is.

- remove most of the redundant code
- use Dropdown not ButtonDropdown
- fix layout of menu and button in DataFilesSidebar
- clean up our .dropdown-menu styles
- use variables for arrow and border
`….scss`:
- use class not ID
- position via `top` not `margin-top`
- explain menu position's "magic" value
- explain why positioning is necessary[^1]

`….jsx`:
- use class not ID
use Dropdown not ButtonDropdown[^2]

[^1]: Not desired, but necessary if we use our custom <Button> as is.
[^2]: I don't see ButtonDropdown in latest ReactStrap (v9).
This class is assigned to buttons that:
- **either** have Bootstrap btn-primary
    (in which case the `.workbench-content .btn-primary` styles it)
- **or** are our custom `<Button>`
    (in which case the `composes: c-button` styles it)
@wesleyboar wesleyboar marked this pull request as draft December 3, 2024 23:46
Copy link

codecov bot commented Dec 3, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 72.88%. Comparing base (e5c17d8) to head (958069b).

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #1028   +/-   ##
=======================================
  Coverage   72.88%   72.88%           
=======================================
  Files         534      534           
  Lines       33455    33455           
  Branches     2981     2981           
=======================================
  Hits        24385    24385           
  Misses       8875     8875           
  Partials      195      195           
Flag Coverage Δ
javascript 75.76% <100.00%> (ø)
unittests 60.44% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
.../DataFiles/DataFilesDropdown/DataFilesDropdown.jsx 94.44% <100.00%> (-0.05%) ⬇️
...ts/DataFiles/DataFilesSidebar/DataFilesSidebar.jsx 82.78% <100.00%> (+0.14%) ⬆️

@wesleyboar wesleyboar marked this pull request as ready for review December 4, 2024 00:18
@wesleyboar wesleyboar changed the title Refactor/wp 791 dropdown menu refactor: wp-791 dropdown menu Dec 4, 2024
Comment on lines -88 to 74
#go-to-button-dropdown .complex-dropdown-item-root,
.complex-dropdown-item-root,
.complex-dropdown-item-project {
display: flex !important;
display: flex;
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why?

  • Classes are custom and unique, so no need to scope them.1
  • The style works without !important.

Footnotes

  1. Ideally, the classes are modular from DataFilesBreadcrumbs.module.css but I'm trying to keep this diff light.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What did I do?

  • Use class not ID.
  • Remove unnecessary styles.
  • Remove styles that dropdown-menu.css manages.
  • Position via top not margin-top.
    Margin is for space between items. Positioning uses specific properties.

padding-left: 20px;
padding-inline: var(--global-space--section-left);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why?

  • To center the (full-width) button, instead of just push it to the left.1

Footnotes

  1. I would also use only margin not padding, but both work here and I try to keep diff light.

Comment on lines -13 to 15
#add-button-wrapper {
padding-left: var(--horizontal-buffer);
}
#data-files-add {
width: 174px;
width: 100%;
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What did I do? Match design:

  • Stretch the button.
  • Center the button.

}
}

.complex-dropdown-item {
border-top: 1px solid #707070;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why?

  • Replaced by <DropdownItem divider>.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why delete so much?
Most of the dropdown menu styles are in dropdown-menu.css thus are redundant here.

client/src/styles/components/dropdown-menu.css Outdated Show resolved Hide resolved
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why?

  • Latest Reactstrap does not document ButtonDropdown; it might be deprecated.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why?

  • Don't use wrappers (cruft) unless necessary.
  • Latest Reactstrap does not document ButtonDropdown; it might be deprecated.
  • Use <DropdownItem divider /> like DataFilesDropdown does.
    If we're gonna use Reactstrap, let's use it as designed (until we replace it).1

Footnotes

  1. A more recent guideline I follow, cuz it's easier to reference an API than search for "what we normally do".

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What did I do?

  • Add variables so arrow math is documented via code.
  • Style <DropdownItem divider>.
  • Clarify code with whitespace or comments.

@rstijerina rstijerina removed the request for review from tjgrafft December 4, 2024 03:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant