|
1 | 1 | <% |
2 | 2 | theme = %Theme{text_color: "blue"} |
| 3 | + [h2, h3] = Theme.headings(theme) |
3 | 4 | %> |
4 | 5 | <header class="text-white" style="background: <%= header_background %>;"> |
5 | 6 | <section class="container px-6 pt-6 pb-6"> |
|
12 | 13 | </section> |
13 | 14 | </header> |
14 | 15 |
|
15 | | -<div class="flex items-stretch bg-white"> |
16 | | - <nav class="w-64 p-4 pl-6 text-xl bg-gray-100 border-r border-gray-200"> |
17 | | - <ul class="fixed list-none leading-loose"> |
| 16 | +<div class="text-base lg:text-xl flex items-stretch bg-gray-900"> |
| 17 | + <nav class="w-48 lg:w-64 bg-gray-100 border-r border-gray-200"> |
| 18 | + <ul class="sticky top-0 p-4 pl-6 list-none leading-loose"> |
18 | 19 | <li><%= link "Link", to: "#link" %> |
19 | 20 | <li><%= link "Button", to: "#button" %> |
20 | 21 | <li><%= link "Checkbox", to: "#checkbox" %> |
| 22 | + <li><%= link "Textbox", to: "#textbox" %> |
21 | 23 | <li><%= link "Radio", to: "#radio" %> |
22 | | - <li><%= link "Tab", to: "#tab" %> |
| 24 | + <li><%= link "Tabs", to: "#tabs" %> |
23 | 25 | <li><%= link("List of roles 🔗", to: "https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/ARIA_Techniques") %> |
| 26 | + <li><%= link("Queries 🔗", to: "https://testing-library.com/docs/dom-testing-library/api-queries") %> |
| 27 | + <li><%= link("Matchers 🔗", to: "https://github.com/testing-library/jest-dom") %> |
24 | 28 | </ul> |
25 | 29 | </nav> |
26 | | - <div class="ml-64"> |
27 | | - <section aria-label="Roles Cheatsheet" class="px-4 pt-8 pb-16 text-xl"> |
| 30 | + <div class="mx-auto flex-shrink"> |
| 31 | + <section aria-label="Roles Cheatsheet" class="max-w-xl lg:max-w-3xl px-4 pt-8 pb-16 text-white"> |
28 | 32 | <article> |
29 | | - <%= theme |> Theme.h2("Link", id: "link") %> |
| 33 | + <%= h2.("Link", id: "link") %> |
30 | 34 |
|
31 | 35 | <%= |
32 | 36 | """ |
|
41 | 45 | </article> |
42 | 46 |
|
43 | 47 | <article> |
44 | | - <h2 id="button" class="mb-2 text-4xl leading-normal text-teal-800">Button</h2> |
| 48 | + <%= h2.("Button", id: "button") %> |
45 | 49 | <%= |
46 | | - """ |
47 | | - getByRole('button', { name: 'Click me' }); |
48 | | - """ |> code_block(:js) |
| 50 | + [ |
| 51 | + """ |
| 52 | + const saveButton = getByRole('button', { name: 'Save' }); |
| 53 | + """ |> code_block(:js), |
| 54 | + "<button>Save</button>" |> code_block(:html) |
| 55 | + ] |
49 | 56 | %> |
| 57 | + |
| 58 | + <%= h3.("It is focused", []) %> |
50 | 59 | <%= |
51 | | - """ |
52 | | - <button>Click me</button> |
53 | | - """ |> code_block(:html) |
| 60 | + [ |
| 61 | + """ |
| 62 | + expect(saveButton).toHaveFocus(); |
| 63 | + """ |> code_block(:js) |
| 64 | + ] |
54 | 65 | %> |
55 | | - </article> |
56 | 66 |
|
57 | | - <article> |
58 | | - <h2 id="checkbox" class="mb-2 text-4xl leading-normal text-teal-800">Checkbox</h2> |
| 67 | + <%= h3.("It changes text to ‘Saving’", []) %> |
59 | 68 | <%= |
60 | | - """ |
61 | | - getByRole('checkbox', { name: 'Remember me' }); |
62 | | -
|
63 | | - const rememberMe = getByRole('checkbox', { name: 'Remember me' }); |
64 | | - expect(rememberMe).toBeChecked(); |
65 | | - """ |> code_block(:js) |
| 69 | + [ |
| 70 | + "expect(saveButton).toHaveTextContent('Saving');" |> code_block(:js), |
| 71 | + "<button>Saving</button>" |> code_block(:html) |
| 72 | + ] |
66 | 73 | %> |
67 | 74 |
|
68 | | - <h3>HTML example</h3> |
| 75 | + <%= h3.("When save is clicked", []) %> |
69 | 76 | <%= |
70 | | - """ |
71 | | - <label><input type="checkbox">Remember me</label> |
72 | | - """ |> code_block(:html) |
| 77 | + [ |
| 78 | + """ |
| 79 | + beforeEach(() => { |
| 80 | + userEvent.click(saveButton); |
| 81 | + }); |
| 82 | + """ |> code_block(:js) |
| 83 | + ] |
73 | 84 | %> |
74 | 85 | </article> |
75 | 86 |
|
76 | 87 | <article> |
77 | | - <%= theme |> Theme.h2("Textbox", id: "textbox") %> |
| 88 | + <%= h2.("Checkbox", id: "checkbox") %> |
78 | 89 |
|
79 | | - <h3>It has Bio text field</h3> |
80 | 90 | <%= |
81 | | - """ |
82 | | - getByLabelText('Bio'); |
83 | | - """ |> code_block(:js) |
| 91 | + [ |
| 92 | + """ |
| 93 | + const rememberMe = getByRole('checkbox', { name: 'Remember me' }); |
| 94 | + """ |> code_block(:js), |
| 95 | + """ |
| 96 | + <label> |
| 97 | + <input type="checkbox"> |
| 98 | + Remember me |
| 99 | + </label> |
| 100 | + """ |> code_block(:html) |
| 101 | + ] |
84 | 102 | %> |
| 103 | + |
| 104 | + <%= h3.("It is checked", []) %> |
85 | 105 | <%= |
86 | | - """ |
87 | | - <label>Bio<input></label> |
88 | | - """ |> code_block(:html) |
| 106 | + [ |
| 107 | + """ |
| 108 | + expect(rememberMe).toBeChecked(); |
| 109 | + """ |> code_block(:js), |
| 110 | + """ |
| 111 | + <label><input type="checkbox">Remember me</label> |
| 112 | + """ |> code_block(:html) |
| 113 | + ] |
89 | 114 | %> |
| 115 | + </article> |
90 | 116 |
|
91 | | - <h3>It has Bio text field</h3> |
| 117 | + <article> |
| 118 | + <%= h2.("Textbox", id: "textbox") %> |
| 119 | + |
| 120 | + <%= h3.("It has Bio text field", []) %> |
92 | 121 | <%= |
93 | 122 | """ |
94 | 123 | getByLabelText('Bio'); |
95 | 124 | """ |> code_block(:js) |
96 | 125 | %> |
97 | 126 | <%= |
98 | 127 | """ |
99 | | - <label>Bio<textarea></textarea></label> |
| 128 | + <label> |
| 129 | + Bio |
| 130 | + <input> |
| 131 | + </label> |
100 | 132 | """ |> code_block(:html) |
101 | 133 | %> |
102 | 134 |
|
103 | | - <h3>It is valid</h3> |
| 135 | + <%= h3.("It has Bio text field", []) %> |
| 136 | + <%= |
| 137 | + [ |
| 138 | + """ |
| 139 | + getByLabelText('Bio'); |
| 140 | + """ |> code_block(:js), |
| 141 | + """ |
| 142 | + <label> |
| 143 | + Bio |
| 144 | + <textarea></textarea> |
| 145 | + </label> |
| 146 | + """ |> code_block(:html) |
| 147 | + ] |
| 148 | + %> |
| 149 | + |
| 150 | + <%= h3.("It is valid", []) %> |
104 | 151 | <%= |
105 | 152 | """ |
106 | 153 | expect(getByLabelText('Bio')).toBeValid(); |
107 | 154 | """ |> code_block(:js) |
108 | 155 | %> |
109 | 156 | <%= |
110 | 157 | """ |
111 | | - <label>Bio<textarea aria-invalid=false></textarea></label> |
| 158 | + <label> |
| 159 | + Bio |
| 160 | + <input aria-invalid="false"> |
| 161 | + </label> |
112 | 162 | """ |> code_block(:html) |
113 | 163 | %> |
114 | 164 |
|
115 | | - <h3>It is invalid</h3> |
| 165 | + <%= h3.("It is invalid", []) %> |
116 | 166 | <%= |
117 | 167 | """ |
118 | 168 | expect(getByLabelText('Bio')).toBeInvalid(); |
119 | 169 | """ |> code_block(:js) |
120 | 170 | %> |
121 | 171 | <%= |
122 | 172 | """ |
123 | | - <label>Bio<textarea aria-invalid=true></textarea></label> |
| 173 | + <label> |
| 174 | + Bio |
| 175 | + <input aria-invalid="true"> |
| 176 | + </label> |
124 | 177 | """ |> code_block(:html) |
125 | 178 | %> |
| 179 | + |
| 180 | + <%= h3.("When ‘Painter’ is typed", []) %> |
| 181 | + <%= |
| 182 | + [ |
| 183 | + """ |
| 184 | + beforeEach(() => { |
| 185 | + userEvent.type(getByLabelText('Bio'), 'Painter'); |
| 186 | + }); |
| 187 | + """ |> code_block(:js) |
| 188 | + ] |
| 189 | + %> |
126 | 190 | </article> |
127 | 191 |
|
128 | 192 | <article> |
129 | | - <h2 id="radio" class="mb-2 text-4xl leading-normal text-teal-800">Radio</h2> |
130 | | - <%= |
131 | | - """ |
132 | | - getByRole('radio', { name: 'Blue' }); |
133 | | - """ |> code_block(:js) |
| 193 | + <%= h2.("Radio", id: "radio") %> |
| 194 | + |
| 195 | + <%= h3.("It is checked", []) %> |
| 196 | + <%= |
| 197 | + [ |
| 198 | + """ |
| 199 | + expect(getByRole('radio', { name: 'Blue' })).toBeChecked(); |
| 200 | + """ |> code_block(:js), |
| 201 | + """ |
| 202 | + <label><input type="radio">Purple</label> |
| 203 | + <label><input type="radio" checked>Blue</label> |
| 204 | + <label><input type="radio">Orange</label> |
| 205 | + """ |> code_block(:html) |
| 206 | + ] |
134 | 207 | %> |
135 | | - <%= |
136 | | - """ |
137 | | - <label><input type="radio">Purple</label> |
138 | | - <label><input type="radio">Blue</label> |
139 | | - <label><input type="radio">Orange</label> |
140 | | - """ |> code_block(:html) |
| 208 | + </article> |
| 209 | + |
| 210 | + <article> |
| 211 | + <%= h2.("Tabs", id: "tabs") %> |
| 212 | + |
| 213 | + <%= h3.("It is checked", []) %> |
| 214 | + <%= |
| 215 | + [ |
| 216 | + """ |
| 217 | + expect(getByRole('radio', { name: 'Blue' })).toBeChecked(); |
| 218 | + """ |> code_block(:js), |
| 219 | + """ |
| 220 | + <label><input type="radio">Purple</label> |
| 221 | + <label><input type="radio" checked>Blue</label> |
| 222 | + <label><input type="radio">Orange</label> |
| 223 | + """ |> code_block(:html) |
| 224 | + ] |
141 | 225 | %> |
142 | 226 | </article> |
143 | 227 |
|
|
0 commit comments