x
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
<div class="flex flex-col gap-6 p-8 max-w-2xl"> <article data-controller="midwest-card midwest-code-block" class="midwest-card padding-none midwest-code-block theme-rouge has-line-numbers"> <div class="wrap"> <header class="flex px-4"> <div class="code-block-meta"> <span class="midwest-badge size-sm theme-primary"> <span class="value">ruby</span> </span> </div> <span class="midwest-tooltip" data-controller="midwest-tooltip"> <span id="tooltip-trigger-11c98" class="midwest-tooltip-trigger" style="anchor-name: --tooltip-11c98" data-action="mouseenter->midwest-tooltip#show mouseleave->midwest-tooltip#hide focus->midwest-tooltip#show blur->midwest-tooltip#hide" aria-describedby="tooltip-11c98"> <button aria-label="Copy code" data-action="midwest-code-block#copy" class="midwest-button variant-ghost size-small theme-primary code-block-copy" name="button"> <span class="midwest-button-content"> <span class="copy-icon"> <div class="midwest-icon " aria-hidden="true"> <div class="midwest-icon-inner"> <svg xmlns="http://www.w3.org/2000/svg" class="Midwest-Icon__Svg" viewbox="0 0 512 512" focusable="false" aria-hidden="true"><path d="M368 48h-11.41a8 8 0 01-7.44-5.08A42.18 42.18 0 00309.87 16H202.13a42.18 42.18 0 00-39.28 26.92 8 8 0 01-7.44 5.08H144a64 64 0 00-64 64v320a64 64 0 0064 64h224a64 64 0 0064-64V112a64 64 0 00-64-64zm-48.13 64H192.13a16 16 0 010-32h127.74a16 16 0 010 32z"></path></svg> </div> </div> </span> <span class="check-icon"> <div class="midwest-icon " aria-hidden="true"> <div class="midwest-icon-inner"> <svg xmlns="http://www.w3.org/2000/svg" class="Midwest-Icon__Svg" viewbox="0 0 512 512" focusable="false" aria-hidden="true"><path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="32" d="M416 128L192 384l-96-96"></path></svg> </div> </div> </span> </span> <div class="midwest-loading-icon" role="img" aria-label="Loading" aria-hidden="true" style="display: none"> <div class="midwest-loading-icon-inner"> <!-- By Sam Herbert (@sherb), for everyone. More @ http://goo.gl/7AJzbL --> <svg viewbox="0 0 120 30" xmlns="http://www.w3.org/2000/svg" fill="currentColor" class="Midwest-LoadingIcon__Svg" focusable="false" aria-hidden="true"> <circle cx="15" cy="15" r="15"> <animate attributename="r" from="15" to="15" begin="0s" dur="0.8s" values="15;9;15" calcmode="linear" repeatcount="indefinite"></animate> <animate attributename="fill-opacity" from="1" to="1" begin="0s" dur="0.8s" values="1;.5;1" calcmode="linear" repeatcount="indefinite"></animate> </circle> <circle cx="60" cy="15" r="9" fill-opacity="0.3"> <animate attributename="r" from="9" to="9" begin="0s" dur="0.8s" values="9;15;9" calcmode="linear" repeatcount="indefinite"></animate> <animate attributename="fill-opacity" from="0.5" to="0.5" begin="0s" dur="0.8s" values=".5;1;.5" calcmode="linear" repeatcount="indefinite"></animate> </circle> <circle cx="105" cy="15" r="15"> <animate attributename="r" from="15" to="15" begin="0s" dur="0.8s" values="15;9;15" calcmode="linear" repeatcount="indefinite"></animate> <animate attributename="fill-opacity" from="1" to="1" begin="0s" dur="0.8s" values="1;.5;1" calcmode="linear" repeatcount="indefinite"></animate> </circle> </svg> </div> </div> </button> </span> <span id="tooltip-11c98" popover="manual" role="tooltip" class="midwest-tooltip-popover placement-top" style="position-anchor: --tooltip-11c98" data-midwest-tooltip-target="popover"> Copy code </span></span></header> <section> <div class="code-block-body" data-midwest-code-block-target="source"> <table role="presentation" class="rouge-line-table highlight"> <tbody> <tr id="line-1" class="lineno"> <td class="rouge-gutter gl" style="-moz-user-select: none;-ms-user-select: none;-webkit-user-select: none;user-select: none;"> <pre>1</pre> </td> <td class="rouge-code"> <pre><span class="k">module</span> <span class="nn">Midwest</span></pre> </td> </tr> <tr id="line-2" class="lineno"> <td class="rouge-gutter gl" style="-moz-user-select: none;-ms-user-select: none;-webkit-user-select: none;user-select: none;"> <pre>2</pre> </td> <td class="rouge-code"> <pre> <span class="k">class</span> <span class="nc">GroupComponent</span> <span class="o"><</span> <span class="no">BaseComponent</span></pre> </td> </tr> <tr id="line-3" class="lineno"> <td class="rouge-gutter gl" style="-moz-user-select: none;-ms-user-select: none;-webkit-user-select: none;user-select: none;"> <pre>3</pre> </td> <td class="rouge-code"> <pre> <span class="n">option</span> <span class="ss">:max</span><span class="p">,</span> <span class="ss">default: </span><span class="kp">nil</span></pre> </td> </tr> <tr id="line-4" class="lineno"> <td class="rouge-gutter gl" style="-moz-user-select: none;-ms-user-select: none;-webkit-user-select: none;user-select: none;"> <pre>4</pre> </td> <td class="rouge-code"> <pre> <span class="n">option</span> <span class="ss">:size</span><span class="p">,</span> <span class="ss">default: </span><span class="o">-></span> <span class="p">{</span> <span class="ss">:default</span> <span class="p">}</span></pre> </td> </tr> <tr id="line-5" class="lineno"> <td class="rouge-gutter gl" style="-moz-user-select: none;-ms-user-select: none;-webkit-user-select: none;user-select: none;"> <pre>5</pre> </td> <td class="rouge-code"> <pre> <span class="n">option</span> <span class="ss">:gap</span><span class="p">,</span> <span class="ss">default: </span><span class="o">-></span> <span class="p">{</span> <span class="ss">:default</span> <span class="p">}</span></pre> </td> </tr> <tr id="line-6" class="lineno"> <td class="rouge-gutter gl" style="-moz-user-select: none;-ms-user-select: none;-webkit-user-select: none;user-select: none;"> <pre>6</pre> </td> <td class="rouge-code"> <pre></pre> </td> </tr> <tr id="line-7" class="lineno"> <td class="rouge-gutter gl" style="-moz-user-select: none;-ms-user-select: none;-webkit-user-select: none;user-select: none;"> <pre>7</pre> </td> <td class="rouge-code"> <pre> <span class="n">renders_many</span> <span class="ss">:items</span></pre> </td> </tr> <tr id="line-8" class="lineno"> <td class="rouge-gutter gl" style="-moz-user-select: none;-ms-user-select: none;-webkit-user-select: none;user-select: none;"> <pre>8</pre> </td> <td class="rouge-code"> <pre></pre> </td> </tr> <tr id="line-9" class="lineno"> <td class="rouge-gutter gl" style="-moz-user-select: none;-ms-user-select: none;-webkit-user-select: none;user-select: none;"> <pre>9</pre> </td> <td class="rouge-code"> <pre> <span class="k">def</span> <span class="nf">visible_items</span></pre> </td> </tr> <tr id="line-10" class="lineno"> <td class="rouge-gutter gl" style="-moz-user-select: none;-ms-user-select: none;-webkit-user-select: none;user-select: none;"> <pre>10</pre> </td> <td class="rouge-code"> <pre> <span class="n">max</span> <span class="p">?</span> <span class="n">items</span><span class="p">.</span><span class="nf">first</span><span class="p">(</span><span class="n">max</span><span class="p">)</span> <span class="p">:</span> <span class="n">items</span></pre> </td> </tr> <tr id="line-11" class="lineno"> <td class="rouge-gutter gl" style="-moz-user-select: none;-ms-user-select: none;-webkit-user-select: none;user-select: none;"> <pre>11</pre> </td> <td class="rouge-code"> <pre> <span class="k">end</span></pre> </td> </tr> <tr id="line-12" class="lineno"> <td class="rouge-gutter gl" style="-moz-user-select: none;-ms-user-select: none;-webkit-user-select: none;user-select: none;"> <pre>12</pre> </td> <td class="rouge-code"> <pre></pre> </td> </tr> <tr id="line-13" class="lineno"> <td class="rouge-gutter gl" style="-moz-user-select: none;-ms-user-select: none;-webkit-user-select: none;user-select: none;"> <pre>13</pre> </td> <td class="rouge-code"> <pre> <span class="k">def</span> <span class="nf">overflow_count</span></pre> </td> </tr> <tr id="line-14" class="lineno"> <td class="rouge-gutter gl" style="-moz-user-select: none;-ms-user-select: none;-webkit-user-select: none;user-select: none;"> <pre>14</pre> </td> <td class="rouge-code"> <pre> <span class="k">return</span> <span class="mi">0</span> <span class="k">unless</span> <span class="n">max</span> <span class="o">&&</span> <span class="n">items</span><span class="p">.</span><span class="nf">length</span> <span class="o">></span> <span class="n">max</span></pre> </td> </tr> <tr id="line-15" class="lineno"> <td class="rouge-gutter gl" style="-moz-user-select: none;-ms-user-select: none;-webkit-user-select: none;user-select: none;"> <pre>15</pre> </td> <td class="rouge-code"> <pre> <span class="n">items</span><span class="p">.</span><span class="nf">length</span> <span class="o">-</span> <span class="n">max</span></pre> </td> </tr> <tr id="line-16" class="lineno"> <td class="rouge-gutter gl" style="-moz-user-select: none;-ms-user-select: none;-webkit-user-select: none;user-select: none;"> <pre>16</pre> </td> <td class="rouge-code"> <pre> <span class="k">end</span></pre> </td> </tr> <tr id="line-17" class="lineno"> <td class="rouge-gutter gl" style="-moz-user-select: none;-ms-user-select: none;-webkit-user-select: none;user-select: none;"> <pre>17</pre> </td> <td class="rouge-code"> <pre> <span class="k">end</span></pre> </td> </tr> <tr id="line-18" class="lineno"> <td class="rouge-gutter gl" style="-moz-user-select: none;-ms-user-select: none;-webkit-user-select: none;user-select: none;"> <pre>18</pre> </td> <td class="rouge-code"> <pre><span class="k">end</span></pre> </td> </tr> </tbody> </table> </div> </section> </div> </article></div>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
<%ruby_code = <<~RUBY module Midwest class GroupComponent < BaseComponent option :max, default: nil option :size, default: -> { :default } option :gap, default: -> { :default } renders_many :items def visible_items max ? items.first(max) : items end def overflow_count return 0 unless max && items.length > max items.length - max end end endRUBY%><div class="flex flex-col gap-6 p-8 max-w-2xl"> <%= render Midwest::CodeBlockComponent.new(ruby_code, language: :ruby, line_numbers: true) %></div>Line Numbers
Enable line_numbers: true for numbered lines via Rouge's table formatter.
Line numbers are excluded from clipboard copy automatically.
No params configured.
No assets to display.
Add a .js or .css file alongside the component to see it here.
Figma embed for Code Block/line_numbers
Annotate a preview to embed its Figma design here:
@figma "https://figma.com/..."