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

Checkbox + Radio item-level styling (3rd try) #211

Merged
merged 2 commits into from
Dec 20, 2019

Conversation

jtreminio
Copy link
Contributor

Related to #203 and #200

  • Adds item-level styling (markers, item extra and display extra)
  • Item styles are passed down from parent menu, or use default values

@codecov-io
Copy link

codecov-io commented Dec 20, 2019

Codecov Report

Merging #211 into master will decrease coverage by 0.96%.
The diff coverage is 84.94%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master     #211      +/-   ##
============================================
- Coverage        94%   93.04%   -0.97%     
- Complexity      521      558      +37     
============================================
  Files            29       30       +1     
  Lines          1569     1667      +98     
============================================
+ Hits           1475     1551      +76     
- Misses           94      116      +22
Impacted Files Coverage Δ Complexity Δ
src/Builder/SplitItemBuilder.php 77.5% <ø> (ø) 12 <0> (ø) ⬇️
src/MenuStyle.php 96.99% <ø> (-0.29%) 70 <0> (-8)
src/MenuItem/RadioItem.php 100% <100%> (ø) 21 <11> (+11) ⬆️
src/CliMenu.php 95.25% <100%> (+0.2%) 113 <4> (+4) ⬆️
src/MenuItem/SplitItem.php 100% <100%> (ø) 45 <0> (-2) ⬇️
src/Builder/CliMenuBuilder.php 79.56% <38.46%> (-3.31%) 83 <6> (+8)
src/MenuItem/CheckboxItem.php 92.72% <87.87%> (-7.28%) 20 <11> (+11)
src/Style/CheckboxStyle.php 88.23% <88.23%> (ø) 12 <12> (?)
src/Style/RadioStyle.php 88.23% <88.23%> (ø) 12 <12> (?)
... and 1 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update da5a0b7...313d3e6. Read the comment docs.

@@ -560,6 +572,18 @@ private function propagateStyles(CliMenu $menu, array $items = [])
$currentItems = !empty($items) ? $items : $menu->getItems();

foreach ($currentItems as $item) {
if ($item instanceof CheckboxItem
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The late style binding here really helps reduce complexity. As more item types are refactored to support item-level styling, they should be added here to make them work properly.

Comment on lines +575 to +585
if ($item instanceof CheckboxItem
&& !$item->getStyle()->hasChangedFromDefaults()
) {
$item->setStyle(clone $menu->getCheckboxStyle());
}

if ($item instanceof RadioItem
&& !$item->getStyle()->hasChangedFromDefaults()
) {
$item->setStyle(clone $menu->getRadioStyle());
}
Copy link
Member

Choose a reason for hiding this comment

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

I don't like this and suspect it will get uglier. But also I'm happy for us to fix this later.

Copy link
Member

Choose a reason for hiding this comment

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

I mean refactor, just because of all the instanceof checks.


class CheckboxStyle
{
protected const DEFAULT_STYLES = [
Copy link
Member

Choose a reason for hiding this comment

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

I'd like to make all these private. I will do it after merge.


namespace PhpSchool\CliMenu\Style;

class CheckboxStyle
Copy link
Member

Choose a reason for hiding this comment

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

Also I will add some simple tests for these Style objects.

->setUncheckedMarker('[○] ')
->setCheckedMarker('[●] ')
->modifyCheckboxStyle(function (CheckboxStyle $style) {
$style->setMarkerOff('[○] ')
Copy link
Member

@AydinHassan AydinHassan Dec 20, 2019

Choose a reason for hiding this comment

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

I think I prefer setCheckedMarker and setUncheckedMarker. We can address that later.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was hoping to keep the naming scheme identical across Selectable, Checkbox and Radio items.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

However, since removed all the interfaces it doesn't matter much anymore.

Copy link
Member

Choose a reason for hiding this comment

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

I think I'd prefer to keep it more semantic. And I think in the end, we might push this rendering back in to the item.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've got PR for SelectableItem styling ready. Should I hold off on it, or should I submit? The code will follow this PR.

@AydinHassan AydinHassan merged commit 0902895 into php-school:master Dec 20, 2019
@@ -568,6 +592,14 @@ private function propagateStyles(CliMenu $menu, array $items = [])
$subMenu->setStyle(clone $menu->getStyle());
}

if (!$subMenu->getCheckboxStyle()->hasChangedFromDefaults()) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Each submenu object gets a copy of radio and checkbox style object to keep. This is what is handed out to children items.

@jtreminio jtreminio deleted the feature/checkbox-radio-style branch December 20, 2019 07:31
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.

3 participants