Skip to content

Add conditional CSS class arrays to all *Class() methods#143

Open
WarLikeLaux wants to merge 1 commit intoyiisoft:masterfrom
WarLikeLaux:add-conditional-css-classes
Open

Add conditional CSS class arrays to all *Class() methods#143
WarLikeLaux wants to merge 1 commit intoyiisoft:masterfrom
WarLikeLaux:add-conditional-css-classes

Conversation

@WarLikeLaux
Copy link
Contributor

Q A
Is bugfix?
New feature?
Docs added?
Tests added? ✔️
Breaks BC?

What does this PR do?

Extends all 29 *Class() methods in Alert, Dropdown, and Menu to accept string|array. The array format supports conditional CSS classes (Laravel Blade pattern).

Menu::widget()
    ->class(['nav' => true, 'active' => $isActive, 'dark' => $isDark])
    ->activeClass(['selected' => true, 'highlight' => $isHighlighted])
    ->items($items)
    ->render();

Keys with true values are included, false are excluded. Numeric keys are always included. This replaces ternary expressions like ->class($active ? 'nav active' : 'nav').

Resolution logic is in Normalizer::cssClasses(). No BC break, existing string calls work unchanged.

@codecov
Copy link

codecov bot commented Mar 24, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (e57424b) to head (40353da).

Additional details and impacted files
@@             Coverage Diff             @@
##              master      #143   +/-   ##
===========================================
  Coverage     100.00%   100.00%           
- Complexity       283       288    +5     
===========================================
  Files              8         8           
  Lines            892       902   +10     
===========================================
+ Hits             892       902   +10     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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