Skip to content
This repository was archived by the owner on Mar 5, 2023. It is now read-only.

Commit 9f9c98c

Browse files
authored
Merge pull request #54 from 8fold/feed-rss
accordion available
2 parents 378fe3a + 2a70555 commit 9f9c98c

File tree

4 files changed

+95
-2
lines changed

4 files changed

+95
-2
lines changed

src/UIKit.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,16 @@ static public function webHead()
108108
return new $class();
109109
}
110110

111+
static public function accordion(
112+
string $summaryId,
113+
$summary,
114+
...$content
115+
)
116+
{
117+
$class = self::class("accordion", self::CLASSES)->unfold();
118+
return new $class($summaryId, $summary, ...$content);
119+
}
120+
111121
static public function __callStatic(string $element, array $elements)
112122
{
113123
$class = Html::class($element, self::CLASSES);
@@ -198,7 +208,8 @@ static public function __callStatic(string $element, array $elements)
198208
'markdown' => \Eightfold\Markup\UIKit\Elements\Compound\Markdown::class,
199209
'pagination' => \Eightfold\Markup\UIKit\Elements\Compound\Pagination::class,
200210
'socialMeta' => \Eightfold\Markup\UIKit\Elements\Compound\SocialMeta::class,
201-
'webHead' => \Eightfold\Markup\UIKit\Elements\Compound\WebHead::class
211+
'webHead' => \Eightfold\Markup\UIKit\Elements\Compound\WebHead::class,
212+
'accordion' => \Eightfold\Markup\UIKit\Elements\Compound\Accordion::class
202213
// , 'primary_nav' => UIKit\Elements\Compound\NavigationPrimary::class
203214
// , 'secondary_nav' => UIKit\Elements\Compound\NavigationSecondary::class
204215
// , 'side_nav' => UIKit\Elements\Compound\NavigationSide::class
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
3+
namespace Eightfold\Markup\UIKit\Elements\Compound;
4+
5+
use Eightfold\Markup\Html\Elements\HtmlElement;
6+
7+
use Eightfold\Shoop\Helpers\Type;
8+
use Eightfold\Shoop\Shoop;
9+
use Eightfold\Shoop\ESArray;
10+
use Eightfold\Shoop\ESInt;
11+
use Eightfold\Shoop\ESString;
12+
use Eightfold\Shoop\ESBool;
13+
14+
use Eightfold\Markup\UIKit;
15+
16+
class Accordion extends HtmlElement
17+
{
18+
private $summaryId = "";
19+
private $summary = "";
20+
21+
public function __construct(
22+
string $summaryId,
23+
$summary,
24+
...$content
25+
)
26+
{
27+
$this->summary = (Type::is($summary, ESString::class, "string")) ? $summary : Type::sanitizeType($summary, ESArray::class);
28+
$this->summaryId = $summaryId;
29+
30+
$this->content = $content;
31+
$this->panelId = $this->summaryId ."-panel";
32+
33+
}
34+
35+
public function unfold(): string
36+
{
37+
$header = UIKit::h2(
38+
UIKit::button(
39+
$this->summary
40+
)->attr(
41+
"aria-expanded true",
42+
"id {$this->summaryId}",
43+
"aria-controls {$this->panelId}"
44+
)
45+
)->attr("is accordion")->unfold();
46+
$panel = UIKit::div(
47+
...$this->content
48+
)->attr(
49+
"is accordion-panel",
50+
"tabindex -1",
51+
"role region",
52+
"aria-hidden false",
53+
"id {$this->panelId}",
54+
"aria-labelledby {$this->summaryId}"
55+
)->unfold();
56+
return Shoop::string($header)->plus($panel);
57+
}
58+
}

tests/UIKit/CompoundTest.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,8 @@ public function testPaginationUnfold()
124124
$actual = UIKit::pagination(2, 20);
125125
$this->assertEquals($expected, $actual->unfold());
126126

127-
$expected = '<nav class="pagination next"><ul><li><a href="/feed/page/2" aria-label="Goto page 2">2</a></li><li><a class="current" href="/feed/page/1" aria-label="Current page, page 1">1</a></li><li><a href="/feed/page/2" aria-label="Goto page 2">2</a></li><li><a href="/feed/page/3" aria-label="Goto page 3">3</a></li></ul></nav>';
127+
// TODO: Really need to work on this - don't have a business need yet
128+
$expected = '<nav class="pagination next"><ul><li><a class="current" href="/feed/page/1" aria-label="Current page, page 1">1</a></li><li><a href="/feed/page/2" aria-label="Goto page 2">2</a></li><li><a href="/feed/page/3" aria-label="Goto page 3">3</a></li></ul></nav>';
128129
$actual = UIKit::pagination(1, 30);
129130
$this->assertEquals($expected, $actual->unfold());
130131

@@ -193,4 +194,20 @@ public function testWebHead()
193194
)->socialTwitter("8foldPros");
194195
$this->assertEquals($expected, $actual->unfold());
195196
}
197+
198+
public function testAccordion()
199+
{
200+
$summaryId = "accordion";
201+
$summary = "Summary";
202+
$content = UIKit::p("The content.");
203+
$expected = '<h2 is="accordion"><button id="'. $summaryId .'" aria-controls="'. $summaryId .'-panel" aria-expanded="true">'. $summary .'</button></h2><div is="accordion-panel" role="region" id="'. $summaryId .'-panel" tabindex="-1" aria-hidden="false" aria-labelledby="'. $summaryId .'">'. $content->unfold() .'</div>';
204+
205+
'<h2 is="accordion"><button id="" aria-controls="" aria-expanded="true"></button></h2><div is="accordion-panel" id="" aria-labelledby="'. $summaryId .'" tabindex="-1" role="region" aria-hidden="false">'. $content->unfold() .'</div>';
206+
$actual = UIKit::accordion(
207+
$summaryId,
208+
$summary,
209+
$content
210+
);
211+
$this->assertEquals($expected, $actual->unfold());
212+
}
196213
}

tests/html/HtmlTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,4 +100,11 @@ public function testCanHaveAriaExpanded()
100100
$actual = Html::button()->attr("aria-expanded false");
101101
$this->assertEquals($expected, $actual->unfold());
102102
}
103+
104+
public function testCanHaveAriaLabelledBy()
105+
{
106+
$expected = '<div aria-labelledby="hello"></div>';
107+
$actual = Html::div()->attr("aria-labelledby hello");
108+
$this->assertEquals($expected, $actual->unfold());
109+
}
103110
}

0 commit comments

Comments
 (0)