Skip to content

Commit 5d2a61c

Browse files
committed
fix: sync SM Lab cascade captions with signal controls
Fixes #107
1 parent 9874475 commit 5d2a61c

5 files changed

Lines changed: 30 additions & 8 deletions

File tree

dist/js/lab-showcase.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Lab/ShowcaseRenderer.php

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,10 @@ class="sm-lab-signal-cascade__signal"
420420
<span data-sm-lab-cascade-value="signal"><?php echo esc_html( $node['signal_label'] ); ?></span>
421421
</button>
422422
<strong><?php echo esc_html( $node['label'] ); ?></strong>
423-
<small><?php echo esc_html( $node['caption'] ); ?></small>
423+
<small>
424+
<span data-sm-lab-cascade-caption-signal><?php echo esc_html( sprintf( __( 'Color Signal: %s.', '__plugin_txtd' ), $node['signal_label'] ) ); ?></span>
425+
<?php echo esc_html( $node['caption'] ); ?>
426+
</small>
424427
<div class="sm-lab-cascade-chips" aria-hidden="true">
425428
<span class="sm-lab-cascade-chip" data-sm-lab-cascade-chip="signal-label" data-sm-lab-cascade-chip-signal-label>
426429
<?php esc_html_e( 'Color Signal:', '__plugin_txtd' ); ?> <?php echo esc_html( $node['signal_label'] ); ?>
@@ -493,42 +496,42 @@ private function get_signal_cascade_nodes( QueryParams $params, int $root_variat
493496
'parent' => '',
494497
'signal' => 0,
495498
'label' => __( 'Page container', '__plugin_txtd' ),
496-
'caption' => __( 'Color Signal: None. Sets the page surface — everything below resolves against it.', '__plugin_txtd' ),
499+
'caption' => __( 'Sets the page surface — everything below resolves against it.', '__plugin_txtd' ),
497500
],
498501
[
499502
'id' => 'header',
500503
'parent' => 'page',
501504
'signal' => 3,
502505
'label' => __( 'Header block', '__plugin_txtd' ),
503-
'caption' => __( 'Color Signal: High. Resolved against the page surface, not against another block.', '__plugin_txtd' ),
506+
'caption' => __( 'Resolved against the page surface, not against another block.', '__plugin_txtd' ),
504507
],
505508
[
506509
'id' => 'content',
507510
'parent' => 'page',
508511
'signal' => 1,
509512
'label' => __( 'Content block', '__plugin_txtd' ),
510-
'caption' => __( 'Color Signal: Low. First layer below page; the parent for any nested block.', '__plugin_txtd' ),
513+
'caption' => __( 'First layer below page; the parent for any nested block.', '__plugin_txtd' ),
511514
],
512515
[
513516
'id' => 'inner',
514517
'parent' => 'content',
515518
'signal' => 2,
516519
'label' => __( 'First inner block', '__plugin_txtd' ),
517-
'caption' => __( 'Color Signal: Medium. Resolved against the content surface, not against page.', '__plugin_txtd' ),
520+
'caption' => __( 'Resolved against the content surface, not against page.', '__plugin_txtd' ),
518521
],
519522
[
520523
'id' => 'second-inner',
521524
'parent' => 'inner',
522525
'signal' => 3,
523526
'label' => __( 'Second inner block', '__plugin_txtd' ),
524-
'caption' => __( 'Color Signal: High. Resolved against inner — flips to the opposite end of the rail.', '__plugin_txtd' ),
527+
'caption' => __( 'Resolved against inner — flips to the opposite end of the rail.', '__plugin_txtd' ),
525528
],
526529
[
527530
'id' => 'footer',
528531
'parent' => 'page',
529532
'signal' => 3,
530533
'label' => __( 'Footer block', '__plugin_txtd' ),
531-
'caption' => __( 'Color Signal: High. Same input as Header, same parent — same resolved grade.', '__plugin_txtd' ),
534+
'caption' => __( 'Same input as Header, same parent — same resolved grade.', '__plugin_txtd' ),
532535
],
533536
];
534537
$resolved_by_id = [];

src/_js/lab-showcase/runtime.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -933,6 +933,10 @@ const updateCascadeSignalUi = ( node, signal ) => {
933933
chip.textContent = `Color Signal: ${ label }`;
934934
} );
935935

936+
node.querySelectorAll( '[data-sm-lab-cascade-caption-signal]' ).forEach( ( caption ) => {
937+
caption.textContent = `Color Signal: ${ label }.`;
938+
} );
939+
936940
node.querySelectorAll( '[data-sm-lab-cascade-chip-signal-input]' ).forEach( ( chip ) => {
937941
chip.setAttribute( 'data-sm-lab-cascade-chip-signal-input', String( signal ) );
938942
} );

tests/js/lab-showcase-runtime.test.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,10 @@ const createShowcaseDocument = () => {
398398
node.appendChild( createCascadeValue( documentRef, key ) );
399399
} );
400400

401+
const captionSignal = documentRef.createElement( 'small' );
402+
captionSignal.setAttribute( 'data-sm-lab-cascade-caption-signal', '1' );
403+
node.appendChild( captionSignal );
404+
401405
const signalLabelChip = documentRef.createElement( 'span' );
402406
signalLabelChip.setAttribute( 'data-sm-lab-cascade-chip', 'signal-label' );
403407
signalLabelChip.setAttribute( 'data-sm-lab-cascade-chip-signal-label', '1' );
@@ -736,6 +740,11 @@ export const runLabShowcaseRuntimeTests = async ( assert ) => {
736740
'Color Signal: Low',
737741
'signal cascade should expose the human Color Signal label separately from the saved value'
738742
);
743+
assert.equal(
744+
documentRef.querySelector( '[data-sm-lab-cascade-node="content"] [data-sm-lab-cascade-caption-signal]' )?.textContent,
745+
'Color Signal: Low.',
746+
'signal cascade captions should expose the current human Color Signal label'
747+
);
739748
assert.equal(
740749
documentRef.querySelector( '[data-sm-lab-cascade-node="content"] [data-sm-lab-cascade-chip-signal-input-code]' )?.textContent,
741750
'data-color-signal="1"',
@@ -850,6 +859,11 @@ export const runLabShowcaseRuntimeTests = async ( assert ) => {
850859
'Color Signal: Medium',
851860
'clicking a cascade signal control should update the human signal chip'
852861
);
862+
assert.equal(
863+
documentRef.querySelector( '[data-sm-lab-cascade-node="content"] [data-sm-lab-cascade-caption-signal]' )?.textContent,
864+
'Color Signal: Medium.',
865+
'clicking a cascade signal control should update the human signal caption'
866+
);
853867
assert.equal(
854868
documentRef.querySelector( '[data-sm-lab-cascade-node="content"] [data-sm-lab-cascade-chip-signal-input-code]' )?.textContent,
855869
'data-color-signal="2"',

tests/phpunit/Unit/Lab/ShowcaseRendererTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ public function test_render_outputs_unique_value_showcase_sections(): void {
6565
$this->assertStringContainsString( 'data-sm-lab-cascade-signal-control', $html );
6666
$this->assertStringContainsString( 'type="button"', $html );
6767
$this->assertStringContainsString( 'Change Page container Color Signal. Current: None', $html );
68+
$this->assertStringContainsString( 'data-sm-lab-cascade-caption-signal', $html );
6869
$this->assertStringContainsString( 'data-sm-lab-cascade-active="true"', $html );
6970
$this->assertStringContainsString( 'data-sm-lab-cascade-value="parent"', $html );
7071
$this->assertStringContainsString( '--sm-lab-cascade-surface-color', $html );

0 commit comments

Comments
 (0)