Skip to content

Commit c6aefbe

Browse files
authored
Merge pull request #270 from moderntribe/feature/MOOSE-156/consolidade-navigation-block-styles
[MOOSE-156] Consolidade navigation block styles
2 parents e828da2 + 19afbd1 commit c6aefbe

File tree

6 files changed

+350
-297
lines changed

6 files changed

+350
-297
lines changed

docs/navigation-blocks.md

Lines changed: 116 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,30 @@ The site navigation system is built using a collection of custom WordPress block
88

99
### Block Hierarchy
1010

11-
The navigation system consists of four main blocks that work together:
11+
The navigation system consists of four main blocks that work together with a centralized styling approach:
1212

13-
1. **Navigation Wrapper** (`tribe/navigation-wrapper`) - Structural container
13+
1. **Navigation Wrapper** (`tribe/navigation-wrapper`) - Central styling coordinator and structural container
1414
2. **Mega Menu Item** (`tribe/mega-menu-item`) - Complex dropdown menus
1515
3. **Standard Menu Item** (`tribe/standard-menu-item`) - Simple menu items with optional dropdowns
1616
4. **Navigation Link** (`tribe/navigation-link`) - Individual link items
1717

18+
### CSS Architecture
19+
20+
The styling architecture follows a centralized coordinator pattern:
21+
22+
**Navigation Wrapper** acts as the central styling coordinator that handles:
23+
- Consolidated toggle button styles (shared between mega and standard menu items)
24+
- First-level navigation styling with animated underlines
25+
- Context-specific behavior for Primary vs Utility menus
26+
- Responsive adaptations and mobile behavior
27+
28+
**Individual Blocks** handle only their specific content:
29+
- **Navigation Link**: Base link styling only
30+
- **Mega Menu Item**: Dropdown container and content styling
31+
- **Standard Menu Item**: Basic positioning and submenu wrapper styling
32+
33+
This architecture eliminates code duplication and creates a single source of truth for navigation styling.
34+
1835

1936
## HTML Structure & Implementation
2037

@@ -102,16 +119,24 @@ The navigation system consists of four main blocks that work together:
102119

103120
### 1. Navigation Wrapper (`tribe/navigation-wrapper`)
104121

105-
**Purpose**: A structural block that wraps menu items in a semantic `<nav>` tag with no added styles.
122+
**Purpose**: Central styling coordinator that provides semantic structure and handles all first-level navigation styling.
106123

107124
**Location**: `wp-content/themes/core/blocks/tribe/navigation-wrapper/`
108125

109126
**Features**:
110127
- Provides semantic HTML structure with `<nav>` element
111128
- Supports `aria-label` attribute for accessibility
112-
- No visual styling (purely structural)
113-
- Supports inner blocks and alignment
114-
- Acts as a container for menu items
129+
- **Consolidated toggle button styling** for both mega and standard menu items
130+
- **Unified first-level navigation styling** with animated underlines
131+
- **Context-aware styling** for Primary vs Utility menu placement
132+
- Responsive behavior and mobile adaptations
133+
- Acts as the styling foundation for all navigation components
134+
135+
**Styling Responsibilities**:
136+
- Toggle button styles (chevrons, padding, hover states)
137+
- First-level navigation item styling (fonts, colors, underlines)
138+
- Context-specific overrides for different menu types
139+
- Mobile responsive adaptations
115140

116141
**Attributes**:
117142
- `ariaLabel` (string) - Accessible label for the navigation
@@ -125,17 +150,22 @@ The navigation system consists of four main blocks that work together:
125150

126151
### 2. Mega Menu Item (`tribe/mega-menu-item`)
127152

128-
**Purpose**: Enhanced dropdown menus with rich content capabilities for complex navigation structures.
153+
**Purpose**: Handles mega menu dropdown content and container functionality.
129154

130155
**Location**: `wp-content/themes/core/blocks/tribe/mega-menu-item/`
131156

132157
**Features**:
133158
- Configurable menu toggle label
134159
- Uses pattern template (`patterns/mega-dropdown`) for consistent content structure
135160
- Supports complex layouts and rich content within dropdowns
161+
- **Container queries** for responsive dropdown layouts
136162
- JavaScript interactions for opening/closing mega menus
137163
- Event-driven architecture with custom events
138-
- Full width layouts and grid alignment support
164+
165+
**Styling Scope**:
166+
- **Dropdown content styling only** (first-level button styling handled by Navigation Wrapper)
167+
- Container queries for responsive layouts
168+
- Mega menu wrapper positioning and background
139169

140170
**Attributes**:
141171
- `menuToggleLabel` (string) - Text label for the top-level navigation button
@@ -152,17 +182,22 @@ The navigation system consists of four main blocks that work together:
152182

153183
### 3. Standard Menu Item (`tribe/standard-menu-item`)
154184

155-
**Purpose**: Simple menu items with optional dropdown functionality for basic navigation needs.
185+
**Purpose**: Handles basic menu item positioning and submenu wrapper functionality.
156186

157187
**Location**: `wp-content/themes/core/blocks/tribe/standard-menu-item/`
158188

159189
**Features**:
160190
- Toggle for enabling simple dropdown submenus
161191
- Only allows `tribe/navigation-link` as child blocks
162192
- Configurable menu toggle label when used as dropdown
163-
- Lightweight alternative to mega menu items
193+
- **Lightweight positioning and layout** (first-level styling handled by Navigation Wrapper)
164194
- Perfect for simple link lists
165195

196+
**Styling Scope**:
197+
- **Basic positioning and layout only** (first-level button styling handled by Navigation Wrapper)
198+
- Toggle label styling (underline on hover)
199+
- Submenu wrapper positioning and behavior
200+
166201
**Attributes**:
167202
- `hasSubMenu` (boolean) - Enables dropdown functionality
168203
- `menuToggleLabel` (string) - Text label when used as dropdown toggle
@@ -176,16 +211,20 @@ The navigation system consists of four main blocks that work together:
176211

177212
### 4. Navigation Link (`tribe/navigation-link`)
178213

179-
**Purpose**: Individual link items within menu structures.
214+
**Purpose**: Provides base link styling with consistent behavior across all navigation contexts.
180215

181216
**Location**: `wp-content/themes/core/blocks/tribe/navigation-link/`
182217

183218
**Features**:
184219
- Rich text editing for link text
185220
- URL configuration with WordPress LinkControl component
186221
- Target/new window option
187-
- Can only be used as child of `tribe/standard-menu-item`
188-
- Proper link management with unlink functionality
222+
- **Base link styling only** (context-specific enhancements handled by Navigation Wrapper)
223+
- Consistent foundation across all menu types
224+
225+
**Styling Scope**:
226+
- **Base link styles only**: underline, transitions, focus states
227+
- Context-specific styling (Primary vs Utility menu) handled by Navigation Wrapper
189228

190229
**Attributes**:
191230
- `text` (string) - Link text content
@@ -200,6 +239,46 @@ The navigation system consists of four main blocks that work together:
200239
- Link control popover for URL management
201240
- Toolbar controls for link/unlink actions
202241

242+
## Styling Architecture
243+
244+
### Centralized Coordinator Pattern
245+
246+
The navigation system uses a **centralized coordinator pattern** where the Navigation Wrapper acts as the central styling authority:
247+
248+
```
249+
Navigation Wrapper (Coordinator)
250+
├── Toggle Button Styles (shared by mega & standard menu items)
251+
├── First-Level Navigation Styling (animated underlines, hover states)
252+
├── Context-Specific Overrides (Primary vs Utility menu)
253+
└── Responsive Adaptations (mobile behavior)
254+
255+
Individual Blocks (Content-Specific)
256+
├── Navigation Link: Base link styles only
257+
├── Mega Menu Item: Dropdown container & content
258+
└── Standard Menu Item: Basic positioning & submenu wrapper
259+
```
260+
261+
### Key Benefits
262+
263+
**Eliminates Code Duplication**: Shared styles are defined once in Navigation Wrapper
264+
**Single Source of Truth**: Navigation behavior modifications happen in one place
265+
**Clear Separation**: Each block has a specific, well-defined styling responsibility
266+
**Easy Maintenance**: Changes to navigation styling require updates to only one file
267+
**Consistent Experience**: Unified first-level navigation behavior across all menu types
268+
269+
### CSS File Organization
270+
271+
**Navigation Wrapper** (`navigation-wrapper/style.pcss`):
272+
- Toggle button styles (consolidated)
273+
- Primary navigation first-level styles
274+
- Utility menu style overrides
275+
- Responsive behavior
276+
277+
**Individual Block Files**:
278+
- **Navigation Link**: Base link foundation only
279+
- **Mega Menu Item**: Dropdown content and container queries
280+
- **Standard Menu Item**: Simple positioning and submenu wrapper
281+
203282
## JavaScript Architecture
204283

205284
### Event System
@@ -259,6 +338,30 @@ The navigation system integrates with:
259338
- Focus management for dropdown interactions
260339
- Screen reader friendly markup
261340

341+
## Development Guidelines
342+
343+
### Working with the Centralized Architecture
344+
345+
#### **Making Navigation Styling Changes**
346+
347+
**For First-Level Navigation Changes**: Edit `navigation-wrapper/style.pcss`
348+
- Toggle button styling (padding, colors, hover states)
349+
- Animated underlines and transitions
350+
- Font sizes and spacing
351+
- Context-specific behavior (Primary vs Utility)
352+
353+
**For Individual Block Content**: Edit respective block files
354+
- `navigation-link/style.pcss`: Base link foundation only
355+
- `mega-menu-item/style.pcss`: Dropdown content and container queries
356+
- `standard-menu-item/style.pcss`: Basic positioning and submenu wrapper
357+
358+
### Customization Points
359+
360+
- **Navigation Wrapper**: Central coordinator for all first-level styling
361+
- **Patterns**: Modify `patterns/mega-dropdown` for mega menu layouts
362+
- **Individual Blocks**: Content-specific styling only
363+
- **Context Selectors**: Use `.site-header__navigation` and `.site-header__utility-menu` for targeting
364+
262365
## File Structure
263366

264367
```

wp-content/themes/core/blocks/tribe/mega-menu-item/style.pcss

Lines changed: 4 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
/* -------------------------------------------------------------------------
22
*
3-
* Block - Mega Navigation Menu - Styles - FE / Editor
3+
* Block - Tribe Mega Menu Item
4+
*
5+
* Handles styling for mega menu dropdown content and wrapper.
6+
* First-level navigation button styles are consolidated in Navigation Wrapper.
47
*
58
* ------------------------------------------------------------------------- */
6-
79
.wp-block-tribe-mega-menu-item {
810
color: var(--color-text);
911

@@ -32,92 +34,6 @@
3234
}
3335
}
3436

35-
/* mega menu item button toggle */
36-
.tribe-mega-menu-item__toggle {
37-
background-color: transparent;
38-
border: 0;
39-
padding: var(--spacer-10) var(--spacer-30) var(--spacer-20) var(--spacer-10);
40-
position: relative;
41-
color: var(--color-text);
42-
transition: var(--transition);
43-
44-
@media (--mq-navigation-max) {
45-
width: 100%;
46-
font-size: var(--font-size-40);
47-
text-align: left;
48-
padding-left: 0;
49-
}
50-
51-
&::before {
52-
content: "";
53-
width: 0;
54-
height: 4px;
55-
background-color: var(--masthead-navigation-accent-color);
56-
position: absolute;
57-
bottom: -4px;
58-
left: var(--spacer-10);
59-
transition: width 0.15s ease-in-out;
60-
z-index: 11;
61-
62-
@media (--mq-navigation-max) {
63-
display: none;
64-
}
65-
}
66-
67-
&::after {
68-
content: "";
69-
background-color: currentcolor;
70-
display: block;
71-
height: 16px;
72-
width: 10px;
73-
mask: var(--icon-chevron-right) center no-repeat;
74-
mask-size: contain;
75-
position: absolute;
76-
right: 2px;
77-
top: calc(var(--spacer-10) + 5px);
78-
transform: rotate(90deg);
79-
transition: var(--transition);
80-
}
81-
82-
&:hover,
83-
&:active,
84-
.menu-item-active & {
85-
outline: none;
86-
color: var(--masthead-navigation-accent-color);
87-
88-
&::before {
89-
width: calc(100% - var(--spacer-10));
90-
}
91-
92-
@media (--mq-navigation-max) {
93-
outline: revert;
94-
color: var(--color-text);
95-
}
96-
}
97-
98-
&:focus-visible {
99-
outline: 2px solid var(--masthead-navigation-accent-color);
100-
}
101-
102-
/* Hide border on closed menu items, even when hovered or active */
103-
:not(.menu-item-active) & {
104-
105-
@media (--mq-navigation-max) {
106-
107-
&::before {
108-
width: 0;
109-
}
110-
}
111-
}
112-
113-
.menu-item-active & {
114-
115-
&::after {
116-
transform: rotate(-90deg);
117-
}
118-
}
119-
}
120-
12137
/* enhanced menu pattern wrapper */
12238
.site-header__mega-menu-item-wrapper {
12339
width: 100%;
Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,29 @@
11
/* -------------------------------------------------------------------------
22
*
3-
* Block - Tribe Navigation Link - Styles - FE / Editor
3+
* Block - Tribe Navigation Link
4+
*
5+
* Handles individual link styling with base behavior:
6+
* - Base link styles (underline, transitions, focus states)
7+
* - Consistent styling across all navigation contexts
8+
*
9+
* Context-specific enhancements are handled in Navigation Wrapper.
410
*
511
* ------------------------------------------------------------------------- */
612

713
.wp-block-tribe-navigation-link {
14+
text-decoration: underline 1px;
815
text-decoration-color: transparent;
916
transition: var(--transition);
1017
color: var(--color-text);
1118
display: block;
1219

1320
&:hover,
21+
&:active,
1422
&:focus {
1523
text-decoration-color: currentcolor;
1624
}
1725

1826
&:focus-visible {
1927
outline: 2px solid var(--masthead-navigation-accent-color);
2028
}
21-
22-
.site-header__utility-menu & {
23-
font-size: 14px;
24-
}
2529
}

0 commit comments

Comments
 (0)