Skip to content

Commit f74e7b9

Browse files
committed
Improve content page
1 parent 79282a7 commit f74e7b9

File tree

2 files changed

+69
-16
lines changed
  • apps/components_guide_web

2 files changed

+69
-16
lines changed

apps/components_guide_web/assets/css/app.css

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,13 @@ pre {
141141
color: white;
142142
background-color: #011627;
143143
}
144+
code[class*="language-"], pre[class*="language-"] {
145+
overflow-wrap: break-word !important;
146+
white-space: pre-wrap !important;
147+
}
148+
pre[class*="language-"] {
149+
font-size: 87.5%;
150+
}
144151

145152
.content {
146153
--item-spacing-left: 1rem;

apps/components_guide_web/lib/components_guide_web/templates/accessibility_first/content.html.md

Lines changed: 62 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,62 @@
11
# Semantic Content
22

33
<style>
4+
article output {
5+
--link-decoration: underline;
6+
}
7+
48
article figure {
59
display: flex;
610
flex-direction: column;
711
text-align: center;
812
align-items: center;
913
}
14+
15+
article dt {
16+
font-weight: bold;
17+
}
18+
article dd {
19+
margin-left: 1em;
20+
}
21+
22+
article summary {
23+
cursor: pointer;
24+
}
1025
</style>
1126

1227
<script type=module>
1328
import * as DOMTesting from "https://cdn.skypack.dev/@testing-library/dom";
14-
window.DOMTesting = DOMTesting;
1529

1630
function* surroundingSourceElements(el) {
1731
let prev = el;
1832
while (prev = prev.previousElementSibling) {
1933
if (prev.matches('h1, h2, h3, h4')) break;
20-
if (prev.matches('pre.language-html')) yield { type: 'html', code: prev.textContent };
21-
if (prev.matches('pre.language-javascript')) yield { type: 'javascript', code: prev.textContent };
34+
if (prev.matches('pre.language-html')) yield { type: 'html', code: prev.textContent, el: prev };
35+
if (prev.matches('pre.language-javascript')) yield { type: 'javascript', code: prev.textContent, el: prev };
2236
}
2337

2438
let next = el;
2539
while (next = next.nextElementSibling) {
2640
if (next.matches('h1, h2, h3, h4')) break;
27-
if (next.matches('pre.language-html')) yield { type: 'html', code: next.textContent };
28-
if (next.matches('pre.language-javascript')) yield { type: 'javascript', code: next.textContent };
41+
if (next.matches('pre.language-html')) yield { type: 'html', code: next.textContent, el: next };
42+
if (next.matches('pre.language-javascript')) yield { type: 'javascript', code: next.textContent, el: next };
2943
}
3044
}
3145

3246
const outputEls = document.querySelectorAll('article output');
33-
console.log(outputEls);
47+
48+
function colorFor(index) {
49+
return ['orange-500', 'purple-500', 'green-500'][index];
50+
}
3451

3552
for (const outputEl of outputEls.values()) {
3653
const div = outputEl.appendChild(document.createElement('div'));
3754
div.classList.add('p-4');
3855

39-
console.log('outputEl', outputEl);
56+
let javascriptIndex = 0;
4057
const sources = surroundingSourceElements(outputEl);
4158
for (const source of sources) {
42-
const { type, code } = source;
59+
const { type, code, el } = source;
4360

4461
console.log('source', source);
4562

@@ -48,13 +65,18 @@ for (const outputEl of outputEls.values()) {
4865
}
4966

5067
if (type === 'javascript') {
68+
const color = colorFor(javascriptIndex);
69+
70+
el.classList.add('border-l-4', `border-${color}`);
71+
5172
const screen = DOMTesting.within(div);
5273
const testFunction = new Function('screen', `return ${code}`);
53-
testFunction(screen).style.border = '2px solid red';
74+
testFunction(screen).classList.add('border-2', `border-${color}`);
75+
76+
javascriptIndex++;
5477
}
5578
}
5679
}
57-
//const htmlSourceElements = document.querySelector('article pre.language-html');
5880
</script>
5981

6082
<table class="text-left table-fixed">
@@ -95,7 +117,7 @@ Semantic HTML elements allow meaning and structure to be determined.
95117

96118
The better these crawlers can understand, and the more meaning they can infer, the higher they will rank you.
97119

98-
A web page that is just made of `<div>` and `<span>` elements means that the only content they have to use is the text. Which is a lossy and messy process. Better to provide precise and rich elements instead.
120+
A web page that is just made of `<div>` and `<span>` elements means that the only content they have to use is the text. Which is a subjective and messy process. Better to provide precise, meaningful elements instead.
99121

100122
## Headings
101123

@@ -109,6 +131,22 @@ A web page that is just made of `<div>` and `<span>` elements means that the onl
109131
screen.getByRole('heading');
110132
```
111133

134+
## Links
135+
136+
```html
137+
<p><a href="https://en.wikipedia.org/wiki/One_Thousand_and_One_Nights">One Thousand and One Nights</a> is a collection of Middle Eastern folk tales compiled in Arabic during the <a href="https://en.wikipedia.org/wiki/Islamic_Golden_Age">Islamic Golden Age</a>.
138+
```
139+
140+
<output></output>
141+
142+
```javascript
143+
screen.getByRole('link', { name: 'One Thousand and One Nights' });
144+
```
145+
146+
```javascript
147+
screen.getByRole('link', { name: /islamic golden age/i });
148+
```
149+
112150
## Lists
113151

114152
```html
@@ -178,9 +216,17 @@ screen.getByRole('figure');
178216

179217
## Details & Summary
180218

181-
## Separator
219+
```html
220+
<details>
221+
<summary>Expand me…</summary>
222+
<p>To see more content</p>
223+
</details>
224+
```
182225

183-
<script type=module>
184-
import * as DOM from "https://cdn.skypack.dev/@testing-library/dom";
185-
console.log("DOM", Object.keys(DOM), DOM.screen);
186-
</script>
226+
<output></output>
227+
228+
```javascript
229+
screen.getByRole('group');
230+
```
231+
232+
## Separator

0 commit comments

Comments
 (0)