-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathindex.html
4955 lines (4806 loc) · 196 KB
/
index.html
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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="en">
<head>
<title>Mdash</title>
<meta charset="UTF-8">
<meta name="description" content="Mdash is a tiny standards-based design system for all web projects.">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="theme-color" content="#ffffff">
<link rel="icon" type="image/png" href="favicon.png">
<link rel="apple-touch-icon" sizes="192x192" href="/favicon-192.png">
<link rel="apple-touch-icon" sizes="512x512" href="/favicon-512.png">
<link rel="manifest" href="./manifest.json" />
<link href="m-.woff2" rel="preload" as="font">
<link rel="stylesheet" href="m-.css">
<link rel="stylesheet" href="https://unpkg.com/@highlightjs/[email protected]/styles/github.min.css">
<script>hljs.highlightAll();</script>
<style>
:root {
--docs-logo-bg-color: #2B2B2B;
--docs-logo-border-color: #8DBF28;
--docs-logo-text-color: #E9C063;
}
#m-logo {
width: 60px;
height: 60px;
background-color: var(--docs-logo-bg-color);
border: 2px solid var(--docs-logo-border-color);
color: var(--docs-logo-text-color);
font-family: Menlo, Monaco, monospace;
font-size: 36px;
cursor: default;
}
#menu-toggle {
z-index: 11;
}
@media only screen and (max-width: 576px) {
#menu-toggle { display: block }
#menu { display: none }
#menu[open] {
background-color: white;
z-index: 10;
display: block;
position: absolute;
top: 0;
right: 0;
left: 0;
}
}
/* Override the syntax highlighter */
pre {
display: grid;
& > code {
padding: 1em !important;
}
}
/* The category sections get custom heading and paragraph margin */
main > section {
padding: 120px 0;
scroll-margin-top: -100px;
& h1 {
font-size: 2em;
}
& > :is(h1, h2, h3) {
margin: var(--m-space-8) 0 var(--m-space-2) 0;
}
& > :is(h4, h5) {
margin: var(--m-space-6) 0 var(--m-space-2) 0;
}
& > p {
margin: 0 0 var(--m-space-4) 0;
max-width: 75ch;
}
& table {
code {
white-space: nowrap;
}
}
}
/* Responsive font size for category headings */
@container catheading (min-width: 700px) {
.category-heading > div {
font-size: 3em;
color: red;
}
}
.category-heading {
> div {
font-size: clamp(var(--m-font-size-min), 11vw, 20vw);
}
}
</style>
</head>
<body class="flex height-full">
<m-icon id="menu-toggle" name="menu" class="hidden pos-absolute pad-4 pointer txt-md"></m-icon>
<aside class="pos-sticky pos-t-0 overflow-auto brd-r" style="flex: 0 0 180px; height: 100svh">
<a href="#" class="all-unset pointer block width-full box-sizing-border pos-sticky pos-t-0 pad-4 bg-white">
<div id="m-logo" aria-label="Mdash logo" class="mar-auto fnt-bold pos-relative brd-radius-full mar-b-2">
<span class="pos-absolute" style="top: 5px; left: 9px">m-</span>
</div>
<div class="txt-center fnt-med txt-gray-6">Mdash</div>
</a>
<nav class="pad-4">
<a href="#intro" class="block mar-b-2">Intro</a>
<!-- <a href="/examples" class="block mar-b-2">Examples</a>-->
<!-- <a href="/comparison" class="block mar-b-2">Comparison</a>-->
<a href="https://github.com/jfbrennan/m-" class="flex align-items-center mar-b-2">GitHub</a>
<a href="https://x.com/realEmDash" class="flex align-items-center mar-b-2">X</a>
<hr class="mar-t-4 mar-b-4">
<h4 class="mar-b-2">Components</h4>
<div class="flex flx-col flx-basis-content gap-1">
<a href="#accordion">Accordion</a>
<a href="#alert">Alert</a>
<a href="#autocomplete">Autocomplete</a>
<a href="#badge">Badge</a>
<a href="#box">Box</a>
<a href="#breadcrumbs">Breadcrumbs</a>
<a href="#button">Button</a>
<a href="#button-group">Button Group</a>
<a href="#checkbox">Checkbox</a>
<a href="#container">Container</a>
<a href="#details">Details</a>
<a href="#dialog">Dialog</a>
<a href="#dot">Dot</a>
<a href="#form">Form</a>
<a href="#grid">Grid</a>
<a href="#icons">Icons</a>
<a href="#input">Input</a>
<a href="#keyboard">Keyboard</a>
<a href="#link">Link</a>
<a href="#loader">Loader</a>
<a href="#menu">Menu</a>
<a href="#popover">Popover</a>
<a href="#radio">Radio</a>
<a href="#range">Range</a>
<a href="#select">Select</a>
<a href="#separator">Separator</a>
<a href="#switch">Switch</a>
<a href="#table">Table</a>
<a href="#tabs">Tabs</a>
<a href="#tag">Tag</a>
<a href="#textarea">Textarea</a>
</div>
<h4 class="mar-t-4 mar-b-2">Typography</h4>
<a href="#code" class="block mar-b-2">Code</a>
<a href="#headings" class="block mar-b-2">Headings</a>
<a href="#lists" class="block mar-b-2">Lists</a>
<a href="#rules" class="block mar-b-2">Rule</a>
<a href="#text" class="block mar-b-2">Text</a>
<h4 class="mar-t-4 mar-b-2">Styles</h4>
<a href="#custom-properties" class="block mar-b-2">Custom Properties</a>
<a href="#utility-classes" class="block mar-b-2">Utility Classes</a>
<!-- <h4 class="mar-b-3">Patterns</h4>-->
<!-- <a href="/head-tags" class="block mar-b-2">Head Tags</a>-->
<!-- <a href="/navbar" class="block mar-b-2">Navbar</a>-->
<!-- <a href="/searchbar" class="block mar-b-2">Search</a>-->
<!-- <a href="/patterns/toolbar" class="block mar-b-2">Toolbar</a>-->
<hr class="mar-t-4 mar-b-4">
<small class="block txt-center">Copyright © 2023<br>Jordan Brennan</small>
</nav>
</aside>
<main class="pad-8 flx-grow-1 bg-gray-1">
<section>
<div id="home-intro">
<div class="category-heading">
<div class="fnt-bold txt-center">Mdash</div>
</div>
<div id="home-messages" class="flex align-items-center justify-content-center txt-center mar-b-4">
<h1 hidden>93 tokens<br>31 components<br>300+ utility classes<br>7 kilobytes</h1>
<h1>A design system that fully embraces web standards 🤗</h1>
<h1 hidden>Thank of it as HTML6.</h1>
<h1 hidden>It's so modern it feels old!</h1>
<h1 hidden>#UseThePlatform</h1>
<h1 hidden>Because UI should be fun 🥳</h1>
<h1 hidden>It's freedom, baby. Yeah!</h1>
<h1 hidden>Code depressed? Call 1-800-MDASH</h1>
<h1 hidden>"Nothing is faster than nothing."<br><span style="white-space: nowrap">-Me</span></h1>
<h1 hidden>The AWS bill was $90 last month!!</h1>
<h1 hidden>You can stop reading this.</h1>
<h1 hidden>How many of these are there?</h1>
<h1 hidden>15, including this one.</h1>
<h1 hidden>Does it loop?</h1>
<h1 hidden>No.</h1>
</div>
<div class="mar-auto mar-b-2 txt-center txt-lg">
<!-- <div>Mdash intends to leverage HTML, not replace it or try to outsmart it.</div>-->
<!-- <div>This makes Mdash ideal for all web projects and skill levels.</div>-->
</div>
<div id="benefits" class="flex justify-content-center gap-2 flx-wrap txt-center txt-xs fnt-med mar-lg">
<div class="align-self-center">zero dependencies</div>
<hr aria-orientation="vertical">
<div class="align-self-center">tiny <a href="#performance">7kb</a></div>
<hr aria-orientation="vertical">
<div class="flex align-items-center">responsive</div>
<hr aria-orientation="vertical">
<div class="align-self-center">WCAG</div>
<hr aria-orientation="vertical">
<div class="align-self-center">CDN hosted</div>
<hr aria-orientation="vertical">
<a href="#compatibility" class="align-self-center">works everywhere</a>
</div>
</div>
<div class="mar-auto txt-center mar-t-10" style="max-width: 730px">
<div id="quick-start" class="txt-lg fnt-med mar-t-0 mar-b-0">Quick start</div>
<p class="mar-t-0 mar-b-2">This is the web. Just link it and go!</p>
<pre class="txt-left"><code class="language-html"><link href="https://unpkg.com/[email protected]/dist/m-.woff2" rel="preload" as="font" crossorigin>
<link href="https://unpkg.com/[email protected]/dist/m-.css" rel="stylesheet"></code></pre>
<div class="txt-xs">or <a href="#installation">npm</a></div>
</div>
<hr class="mar-t-10 mar-b-10">
<h2 id="intro" class="mar-t-0">Introduction</h2>
<h3>What is Mdash?</h3>
<p>Mdash is standards-based design system built for maximum performance in every way.</p>
<p>Mdash components are comprised of <span class="fnt-med">standard HTML</span>, <span class="fnt-med">custom HTML</span>, and <span class="fnt-med">Custom Elements</span>. As such, Mdash works with any framework (or no framework) and works with all types of web projects, like SSR, SPA, PWA, static site, and even popular email clients.</p>
<h3>What makes Mdash different?</h3>
<p>Quite literally, nothing. <span class="fnt-italic">Nothing</span> is exactly what makes Mdash different:</p>
<ul class="mar-b-3">
<li>No new concepts or abstractions</li>
<li>No setup or configuration</li>
<li>No dependencies</li>
<li>No build step</li>
</ul>
<p>However, Mdash is unlike anything you've used before. It's just CSS and HTML, but appears to be so much more.</p>
<p>Take a look around and compare Mdash's <a href="#performance">size</a> and <a href="/comparison">markup</a> to see how nothing really is better.</p>
<h3>Where did Mdash come from?</h3>
<p class="mar-b-0">Mdash is the result of building design systems in large engineering organizations where - for better or worse - tech stacks and architectures vary wildly, but the products still need to share common UI elements. It was during this time the
<a href="https://jordanbrennan.hashnode.dev/tac-a-new-css-methodology" target="_blank" class="txt-nowrap">TAC CSS methodology</a> was created with Mdash being the first open-source implementation.</p>
<hr class="mar-t-10 mar-b-10">
<h2 id="compatibility">Compatible With Everything</h2>
<p>Mdash can be used anywhere HTML is used because it is HTML.</p>
<p>All your apps will work with Mdash regardless of tech stack. Here's examples of <span class="fnt-bold">14 different technologies</span> all using the same Mdash component:</p>
<pre><code><!-- Vue -->
<m-alert v-bind:type="alert.type">{{ alert.message }}</m-alert>
<!-- Angular -->
<m-alert [type]="alert.type">{{ alert.message }}</m-alert>
<!-- React*, Preact, Solid -->
<m-alert type={props.alert.type}>{props.alert.message}</m-alert>
<!-- Riot -->
<m-alert type="{alert.type}">{alert.message}</m-alert>
<!-- Svelte -->
<m-alert bind:type="{alert.type}">{alert.message}</m-alert>
<!-- Handlebars -->
<m-alert type="{{alert.type}}">{{alert.message}}</m-alert>
<!-- Lit, Hyper -->
html`<m-alert type="${alert.type}">${alert.message}</m-alert>`
<!-- Blade -->
<m-alert type="{{ $alert→message }}">{{ $alert→message }}</m-alert>
<!-- EJS, ERB, Underscore, Lodash -->
<m-alert type="<%= alert.type %>"><%= alert.message %></m-alert></code></pre>
<small>*Framework compatibility with Custom Elements is tracked on <a href="https://custom-elements-everywhere.com" target="_blank" rel="noopener">custom-elements-everywhere.com</a> and after eight long years
<a href="https://custom-elements-everywhere.com/#react">React v19</a> is finally compatible. Good job.</small>
<h2 id="performance">Performance</h2>
<p>Mdash is fast! It is by all practical measures instant. Its <span class="fnt-med">execution speed</span> comes from leveraging native technology and avoiding abstractions as much as possible in order to minimize code and retain browser optimizations. When it comes to code, nothing is faster than nothing.</p>
<p>In addition to execution speed, <span class="fnt-med">pages load faster</span> because Mdash is so much smaller than other UI libraries:</p>
<table>
<tr>
<td style="width: 140px">
<div class="fnt-bold txt-nowrap flex align-items-center gap-1">
<div>Mdash</div>
<div class="txt-lg">🔥</div>
</div>
</td>
<td>
<meter min="0" max="353" low="20" optimum="12" high="80" value="7"></meter>
<small>7 kb</small>
</td>
</tr>
<tr>
<td style="width: 140px">
<span class="fnt-bold txt-nowrap">Bootstrap</span>
</td>
<td>
<meter min="0" max="353" low="20" optimum="12" high="80" value="71"></meter>
<small>71 kb</small>
</td>
</tr>
<tr>
<td style="width: 140px">
<span class="fnt-bold txt-nowrap">Material Web 2</span>
</td>
<td>
<meter min="0" max="353" low="20" optimum="12" high="80" value="79"></meter>
<small>79 kb</small>
</td>
</tr>
<tr>
<td style="width: 140px">
<span class="fnt-bold txt-nowrap">Zurb Foundation</span>
</td>
<td>
<meter min="0" max="353" low="20" optimum="12" high="80" value="88"></meter>
<small>88 kb</small>
</td>
</tr>
<tr>
<td style="width: 140px">
<span class="fnt-bold txt-nowrap">React Bootstrap</span>
</td>
<td>
<meter min="0" max="353" low="20" optimum="12" high="80" value="103"></meter>
<small>103 kb</small>
</td>
</tr>
<tr>
<td style="width: 140px">
<span class="fnt-bold txt-nowrap">MUI</span>
</td>
<td>
<meter min="0" max="353" low="20" optimum="12" high="80" value="146"></meter>
<small>146 kb</small>
</td>
</tr>
<tr>
<td style="width: 140px">
<span class="fnt-bold txt-nowrap">Semantic UI</span>
</td>
<td>
<meter min="0" max="353" low="20" optimum="12" high="80" value="174"></meter>
<small>174 kb</small>
</td>
</tr>
<tr>
<td style="width: 140px">
<span class="fnt-bold txt-nowrap">Microsoft Fabric</span>
</td>
<td>
<meter min="0" max="353" low="20" optimum="12" high="80" value="244"></meter>
<small>244 kb</small>
</td>
</tr>
<tr>
<td style="width: 140px">
<span class="fnt-bold txt-nowrap">Shoelace</span>
</td>
<td>
<meter min="0" max="353" low="20" optimum="12" high="80" value="294"></meter>
<small>294 kb</small>
</td>
</tr>
<tr>
<td style="width: 140px">
<span class="fnt-bold txt-nowrap">Material Web 3</span>
</td>
<td>
<meter min="0" max="353" low="20" optimum="12" high="80" value="353"></meter>
<small>353 kb</small>
</td>
</tr>
</table>
<small class="block mar-t-1">
<span class="fnt-bold">Note:</span> Sizes are min+gzip for all runtime dependencies except icons and web fonts. In other words, this is the overhead before you write your first line of code.
</small>
<p class="mar-t-8">Compare these three tech stacks to see how bundle size can impact your site performace:</p>
<div>Lit + Vaadin Router + Mdash = 21kb</div>
<div class="flex">
<div style="width: calc(6px * 2); height: 20px; background-color: lightblue"></div>
<div style="width: calc(8px * 2); height: 20px; background-color: darkcyan"></div>
<div style="width: calc(7px * 2); height: 20px; background-color: darkseagreen"></div>
</div>
<div>Solid + Solid Router + Mdash = 23kb</div>
<div class="flex">
<div style="width: calc(7px * 2); height: 20px; background-color: lightblue"></div>
<div style="width: calc(9px * 2); height: 20px; background-color: darkcyan"></div>
<div style="width: calc(7px * 2); height: 20px; background-color: darkseagreen"></div>
</div>
<div>React + React Router + MUI = 250kb</div>
<div class="flex">
<div style="width: calc(55px * 2); height: 20px; background-color: lightsteelblue"></div>
<div style="width: calc(49px * 2); height: 20px; background-color: palevioletred"></div>
<div style="width: calc(146px * 2); height: 20px; background-color: orange"></div>
</div>
<p>It's worth noting Mdash is so small it can be used as a non-blocking internal stylesheet. A page using Mdash will be painted before React and MUI have even finished downloading!</p>
<h2 id="installation">Installation</h2>
<h3 id="installation-cdn">CDN</h3>
<p>Mdash is designed for production use with a CDN. Copy and paste these two resources into the <code><head></code> section of your document and you're golden.</p>
<div>
<h4>Icon Preload</h4>
<pre><code class="language-html"><link href="https://unpkg.com/[email protected]/dist/m-.woff2" rel="preload" as="font" crossorigin></code></pre>
<p>The <a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/rel/preload" target="_blank">preload</a> option tells the browser to start downloading the icon font now instead of waiting for the stylesheet to be parsed. This must come before the stylesheet, but if you don't use icons you don't need this.</p>
</div>
<div>
<h4>Stylesheet</h4>
<pre><code class="language-html"><link href="https://unpkg.com/[email protected]/dist/m-.css" rel="stylesheet"></code></pre>
<p>The stylesheet includes all of Mdash's custom properties, components, and utility classes.</p>
</div>
<!-- <div>-->
<!-- <h4>Custom Elements</h4>-->
<!-- <pre><code class="language-html"><script src="https://unpkg.com/[email protected]/dist/m-.js" defer></script></code></pre>-->
<!-- <p>The <a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script#defer" target="_blank">defer</a> option tells the browser to download the script but delay its evaluation to avoid blocking document parsing.</p>-->
<!-- </div>-->
<h3 id="installation-npm">NPM</h3>
<p>If the CDN is not an option, you can install the Mdash package.</p>
<pre><code>npm install m-</code></pre>
<p>Built assets (those two files above) are located in <code>node_modules/m-/dist</code>. The hyper optimization of <a href="https://web.dev/extract-critical-css/" target="_blank">critical CSS</a> is also possible with Mdash because its so small, so go for it you speed demon!</p>
<h2 id="browsers">Browser support</h2>
<p>Mdash works with the latest versions of all major browsers. Please <a href="https://github.com/jfbrennan/m-/issues" target="_blank" rel="noopener">file a bug</a> if you see something not working as expected.</p>
<script>
// Cycle through the messages at the top of the page
// const intervalId = setInterval(goToNextMessage, 4100);
function goToNextMessage() {
const currentMessage = document.getElementById('home-messages').querySelector('h1:not([hidden])');
const nextMessage = currentMessage.nextElementSibling;
// Hide current and show next.
if (nextMessage) {
currentMessage.hidden = true;
nextMessage.hidden = false;
}
else {
clearInterval(intervalId);
}
}
</script>
</section>
<div class="category-heading">
<div class="fnt-bold">Components</div>
</div>
<section id="accordion">
<h1>Accordion</h1>
<h2 class="txt-gray-5">List of expandable details elements</h2>
<h2>Demo</h2>
<m-accordion>
<details>
<summary>Summary 1</summary>
<p>Details 1</p>
</details>
<details>
<summary>Summary 2</summary>
<p>Details 2</p>
</details>
<details>
<summary>Summary 3</summary>
<p>Details 3</p>
</details>
</m-accordion>
<pre><code class="language-html"><m-accordion>
<details>
<summary>Summary 1</summary>
<p>Details 1</p>
</details>
<details>
<summary>Summary 2</summary>
<p>Details 2</p>
</details>
<details>
<summary>Summary 3</summary>
<p>Details 3</p>
</details>
</m-accordion></code></pre>
<h2 id="accordion-api">API</h2>
<h3>Tag</h3>
<table layout="fixed">
<thead>
<tr>
<th colspan="2">Name</th>
<th colspan="2">Type</th>
<th colspan="6">Content</th>
</tr>
</thead>
<tbody>
<tr>
<td colspan="2"><code>m-accordion</code></td>
<td colspan="2">Custom tag</td>
<td colspan="6"><a href="#details">Details</a> children only</td>
</tr>
</tbody>
</table>
<h2 id="accordion-guidelines">Guidelines</h2>
<h3 id="accordion-named">Opening All Or One</h3>
<p>Accordion only styles its details children. Details' default behavior is each can be opened and closed independently, but details also supports defining a group of
<a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/details#name" target="_blank">named details</a> which allows only one open at a time:</p>
<m-accordion>
<details name="groupdemo">
<summary>Summary 1</summary>
<p>Details 1</p>
</details>
<details name="groupdemo">
<summary>Summary 2</summary>
<p>Details 2</p>
</details>
<details name="groupdemo">
<summary>Summary 3</summary>
<p>Details 3</p>
</details>
</m-accordion>
<pre><code><m-accordion>
<details name="groupdemo">
<summary>Summary 1</summary>
<p>Details 1</p>
</details>
<details name="groupdemo">
<summary>Summary 2</summary>
<p>Details 2</p>
</details>
<details name="groupdemo">
<summary>Summary 3</summary>
<p>Details 3</p>
</details>
</m-accordion></code></pre>
<p>Note that a details group may result in a poor UX when users need to reference information in multiple open details, so consider if limiting open details is actually beneficial to the user.</p>
<h3 id="accordion-counter">CSS Counter</h3>
<p>Accordion's details can be labeled with a <a
href="https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_counter_styles/Using_CSS_counters" target="_blank">custom CSS
counter</a>:</p>
<style>
#counterdemo {
counter-reset: counterdemo;
summary::before {
counter-increment: counterdemo;
content: counter(counterdemo) ". ";
}
}
</style>
<m-accordion id="counterdemo">
<details>
<summary>Do this first</summary>
<p>Details 1</p>
</details>
<details>
<summary>Next do this</summary>
<p>Details 2</p>
</details>
<details>
<summary>Finally do this</summary>
<p>Details 3</p>
</details>
</m-accordion>
<pre><code class="language-html"><style>
#counterdemo {
counter-reset: counterdemo;
summary::before {
counter-increment: counterdemo;
content: counter(counterdemo) ". ";
}
}
</style>
<m-accordion id="counterdemo">
<details>
<summary>Do this first</summary>
<p>Details 1</p>
</details>
<details>
<summary>Next do this</summary>
<p>Details 2</p>
</details>
<details>
<summary>Finally do this</summary>
<p>Details 3</p>
</details>
</m-accordion></code></pre>
<h3 id="accordion-a11y">Accessibility</h3>
<p>All accessibility recommendations apply to the <a href="#details">details</a> children.</p>
</section>
<hr>
<section id="alert">
<h1>Alert</h1>
<h2 class="txt-gray-5">Container for important messaging</h2>
<h2 id="alert-demo">Demo</h2>
<m-alert>Neutral message</m-alert>
<m-alert icon="info">With icon and close options <button slot="close" title="Dismiss" aria-label="Dismiss"></button></m-alert>
<m-alert type="info">Informational message</m-alert>
<m-alert type="success">Positive message</m-alert>
<m-alert type="warn">Warning message</m-alert>
<m-alert type="error">Error message</m-alert>
<pre><code class="language-html"><m-alert>Neutral message</m-alert>
<m-alert icon="info">With icon and close options <button slot="close" title="Dismiss" aria-label="Dismiss"></button></m-alert>
<m-alert type="info">Informational message</m-alert>
<m-alert type="success">Positive message</m-alert>
<m-alert type="warn">Warning message</m-alert>
<m-alert type="error">Error message</m-alert></code></pre>
<h2 id="alert-api">API</h2>
<h3>Tag</h3>
<table layout="fixed">
<thead>
<tr>
<th colspan="2">Name</th>
<th colspan="2">Type</th>
<th colspan="6">Content</th>
</tr>
</thead>
<tbody>
<tr>
<td colspan="2"><code>m-alert</code></td>
<td colspan="2">Custom Element</td>
<td colspan="6">Any</td>
</tr>
</tbody>
</table>
<h3>Slot</h3>
<table layout="fixed">
<thead>
<tr>
<th colspan="2">Name</th>
<th colspan="2">Element</th>
<th colspan="6">Content</th>
</tr>
</thead>
<tbody>
<tr>
<td colspan="2"><code>close</code></td>
<td colspan="2">button</td>
<td colspan="6">None. See <a href="#alert-close-button">close slot</a> for details.</td>
</tr>
</tbody>
</table>
<h3 id="alert-attributes">Attributes</h3>
<table layout="fixed">
<thead>
<tr>
<th colspan="2">Name</th>
<th colspan="2">Value</th>
<th colspan="6">Description</th>
</tr>
</thead>
<tbody>
<tr id="type">
<td colspan="2"><code>type</code></td>
<td colspan="2">
<ul type="none">
<li>info</li>
<li>success</li>
<li>warn</li>
<li>error</li>
</ul>
</td>
<td colspan="6">Sets the type of the message. Error messages should use "error", cautionary messages should use "warn", positive messages should use "success", and important informational messages should use "info".</td>
</tr>
<tr>
<td colspan="2"><code>icon</code></td>
<td colspan="2"><a href="#icons-all-icons">Any icon name</a></td>
<td colspan="6">Adds the specified icon. Suggested icons for each type are <code>info</code> for info, <code>check_circle</code> for success, <code>warning</code> for warn, and <code>error</code> for error, but use whatever is best for your alert.</td>
</tr>
</tbody>
</table>
<h2 id="alert-guidelines">Guidelines</h2>
<h3 id="alert-dismiss">Dismiss an Alert</h3>
<p>Slot the <code>close</code> button and use whatever method is right for your app to bind a click handler that removes the alert:</p>
<script>
function dismissAlert(e) {
e.target.parentElement.remove();
}
</script>
<m-alert>Dismiss me <button onclick="dismissAlert(event)" slot="close" title="Dismiss" aria-label="Dismiss"></button></m-alert>
<pre><code><script>
function dismissAlert(e) {
e.target.parentElement.remove();
}
</script>
<m-alert>Dismiss me <button onclick="dismissAlert(event)" slot="close" title="Dismiss" aria-label="Dismiss"></button></m-alert></code></pre>
<p>It is recommended that error alerts do not use the close slot. The user should instead be guided toward correcting the error if possible.</p>
<h3 id="alert-content">Content</h3>
<p>The content of the alert can be a simple message or something much more. Here are two example:</p>
<m-alert type="info" icon="event_repeat">
<div>
<h4>Sign up for autopay</h4>
<p>Never miss a payment with autopay. Add an account to get started!</p>
<button ord="tertiary" scale="sm" class="mar-t-1">Add Account</button>
</div>
</m-alert>
<h3 id="alert-vs-dialog">Alert vs. Dialog</h3>
<p>Some information is so important it justifies interrupting the user experience. In those cases consider displaying it in a <a href="#dialog">dialog</a> instead of an alert.</p>
<h3 id="alert-toast">Toast aka Snackbar</h3>
<p>Mdash does not have a toast component. There are several design options that serve the same purpose in a less distracting and more thoughtful way:</p>
<ul>
<li>Put the message and action in close proximity to the relevant process</li>
<li>If it's important, show a prominent alert with the message and action</li>
<li>Use a dialog (see Alert vs. Dialog above)</li>
<li>Display a notification using the <a href="https://developer.mozilla.org/en-US/docs/Web/API/Notifications_API" target="_blank">Notifications
API</a>, e.g. <code>new Notification('Hello')</code></li>
</ul>
<h3 id="alert-a11y">Accessibility</h3>
<p>Warning and error alerts should also have <code>role="alert"</code> (see <a href="https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/ARIA_Techniques/Using_the_alert_role" target="_blank" rel="noopener">ARIA alert role</a>). Add a <code>title</code> and <code>aria-label</code> to the close slot.</p>
</section>
<hr>
<section id="autocomplete">
<h1>Autocomplete</h1>
<h2 class="txt-gray-5">Text input for searching values or getting suggestions</h2>
<h2 id="autocomplete-demo">Demo</h2>
<fieldset>
<label>Search</label>
<m-autocomplete source="fruit" placeholder="Slowly type 'apl' to see the behavior"></m-autocomplete>
<datalist id="fruit">
<option value="apple"></option>
<option value="banana"></option>
<option value="cherry"></option>
<option value="peach"></option>
</datalist>
</fieldset>
<pre><code><fieldset>
<label>Search</label>
<m-autocomplete source="fruit" placeholder="Slowly type 'apl' to see the behavior"></m-autocomplete>
<datalist id="fruit">
<option value="apple"></option>
<option value="banana"></option>
<option value="cherry"></option>
<option value="peach"></option>
</datalist>
</fieldset></code></pre>
<h2 id="api">API</h2>
<h3>Tags</h3>
<table>
<thead>
<tr>
<th colspan="2">Name</th>
<th colspan="2">Type</th>
<th colspan="6">Content</th>
</tr>
</thead>
<tbody>
<tr>
<td colspan="2"><code>m-autocomplete</code></td>
<td colspan="2">Custom Element</td>
<td colspan="6">None</td>
</tr>
<tr>
<td colspan="2"><code>datalist</code></td>
<td colspan="2">Native element</td>
<td colspan="6"><code><option></code> elements</td>
</tr>
</tbody>
</table>
<h3 id="attributes">Attributes</h3>
<table layout="fixed">
<thead>
<tr>
<th colspan="2">Name</th>
<th colspan="2">Value</th>
<th colspan="6">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td colspan="2"><code>source</code> <small class="fnt-bold fnt-italic">required</small></td>
<td colspan="2">String</td>
<td colspan="6">The source of data to query for matches. This must be the id of a <code><datalist></code> element or the name of a custom source function. Learn how to create them <a href="#creating-sources">below</a>.</td>
</tr>
<tr>
<td colspan="2"><code>max</code></td>
<td colspan="2">Number</td>
<td colspan="6">Truncates the number of results to <code>max</code>. Autocomplete will overflow at about 10 visible results regardless of the max set.</td>
</tr>
</tbody>
</table>
<h3 id="events">Events</h3>
<table layout="fixed">
<thead>
<tr>
<th colspan="2">Name</th>
<th colspan="2">Details</th>
<th colspan="6">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td colspan="2"><code>select</code></td>
<td colspan="2">
<pre><code>// Name of the source for easy reference
source: '',
// Value from matches
value: '',
// Id of match, if provided
id: ''</code></pre>
</td>
<td colspan="6">
<div class="mar-b-4">Fires after a match is selected. Try it:</div>
<fieldset>
<label>Superheroes</label>
<m-autocomplete onselect="alert(JSON.stringify(event.detail, null, 2))" source="superheroes" placeholder="Search 'bat' or 'kent' and select a result"></m-autocomplete>
<datalist id="superheroes">
<option value="batman">Bruce Wayne</option>
<option value="superman">Clark Kent</option>
<option value="spiderman">Peter Parker</option>
</datalist>
</fieldset>
</td>
</tr>
</tbody>
</table>
<h2 id="guidelines">Guidelines</h2>
<h3 id="creating-sources">Creating data sources for autocomplete</h3>
<p>Sources can come from a standard <code>datalist</code> element or a custom function added to the global <code>MdashAutocomplete</code>.</p>
<h4>1. Datalist element</h4>
<p>Include a standard <a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/datalist" target="_blank" rel="noopener">datalist</a> element in the DOM. Its <code>id</code> must match the Autocomplete's <code>source</code>. The options' value attributes and optional text are searched for matches. Here's an example:</p>
<pre><code><fieldset>
<label>Search</label>
<m-autocomplete source="fruit"></m-autocomplete>
<datalist id="fruit">
<option value="apple"></option>
<option value="banana"></option>
<option value="cherry"></option>
<option value="peach"></option>
</datalist>
</fieldset></code></pre>
<h4>2. Custom source function</h4>
<p>These are asynchronous functions added to the static <code>MdashAutocomplete.sources</code> object. Here's another <code>fruit</code> example similar to the datalist above:</p>
<pre><code><script>
const mdashAutocomplete = customElements.get('m-autocomplete');
mdashAutocomplete.sources.fruit = async (query, max) => {
// 1. Use `query` to fetch, filter, map, find, or whatever your logic is for determining matching results.
// Note: `max` is the most results that will be shown, which can be helpful to know beforehand when dealing with large data sets.
const matches = ['apple', 'banana', 'cherry', 'peach'].filter(fruit => fruit.includes(query));
// 2. Result must be an object with the original `query` param and a `matches` Array.
// Note: `matches` elements can be strings or objects with `id` and `value` properties. See Events API above for more details.
const result = {query, matches};
// 3. Return a resolved Promise with the result (async functions do this automatically).
return result;
}
</script></code></pre>
<p><span class="fnt-bold"><m-icon name="lightbulb"></m-icon>Tip:</span> If the source's data is over the network, cache results client-side for faster lookup next time the same query is given. A simple object is often good enough, e.g. <code>const matches = cache[query] || await fetchAndCacheResults(query)</code>, but the
<a href="https://developer.mozilla.org/en-US/docs/Web/API/Cache" target="_blank">Cache API</a> is another excellent option. You can also use <code>max</code> if it's beneficial while searching to know the maximum number of matches that will be shown.</p>
{{> more-autocomplete}}
<h3 id="a11y">Accessibility</h3>
<p>There are no extra recommendations for Autocomplete.</p>
</section>
<hr>
<section id="badge">
<h1>Badge</h1>
<h2 class="txt-gray-5">Display notification counts</h2>
<h2>Demo</h2>
<m-badge count="1"></m-badge>
<pre><code><m-badge count="1"></m-badge></code></pre>
<h2>API</h2>
<h3>Tag</h3>
<table layout="fixed">
<thead>
<tr>
<th colspan="2">Name</th>
<th colspan="2">Type</th>
<th colspan="6">Content</th>
</tr>
</thead>
<tbody>
<tr>
<td colspan="2"><code>m-badge</code></td>
<td colspan="2">Custom tag</td>
<td colspan="6">Text or the count attribute</td>
</tr>
</tbody>
</table>
<h3>Attributes</h3>
<table layout="fixed">
<thead>
<tr>
<th colspan="2">Name</th>
<th colspan="2">Value</th>
<th colspan="6">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td colspan="2"><code>count</code></td>
<td colspan="2">Number</td>
<td colspan="6">A number to display. When zero or empty the badge will hide itself.</td>
</tr>
</tbody>
</table>
<h2>Guidelines</h2>
<h3>Badge hides itself</h3>
<p>Badge can be used to display a count or text. If either is omitted, the badge will be set to <code>display: none</code>.</p>
<h3>Localization</h3>
<p>Localize the count value before setting it.</p>
<h3>Accessibility</h3>
<p>Use <code>aria-labelledby</code> or <code>aria-label</code> to provide context for the count.</p>
</section>
<hr>
<section id="box">
<h1>Box</h1>
<h2 class="txt-gray-5">Static container for elevating content</h2>
<h2 id="demo">Demo</h2>
<m-box>Primary content</m-box>
<m-box ord="secondary">Secondary content</m-box>
<p>Content outside a box is considered neutral</p>
<pre><code><m-box>Primary content</m-box>
<m-box ord="secondary">Secondary content</m-box>
<p>Content outside a box is considered neutral</p></code></pre>
<p>See more <a href="/examples#Boxes">examples</a></p>
<h2 id="api">API</h2>
<h3>Tag</h3>
<table layout="fixed">
<thead>
<tr>
<th colspan="2">Name</th>
<th colspan="2">Type</th>
<th colspan="6">Content</th>
</tr>
</thead>
<tbody>
<tr>
<td colspan="2"><code>m-box</code></td>
<td colspan="2">Custom tag</td>
<td colspan="6">Any</td>
</tr>
</tbody>
</table>
<h3 id="attributes">Attributes</h3>
<table layout="fixed">
<thead>
<tr>
<th colspan="2">Name</th>
<th colspan="2">Value</th>
<th colspan="6">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td colspan="2"><code>ord</code></td>
<td colspan="2">
<ul type="none">
<li>secondary</li>
</ul>
</td>
<td colspan="6"><a href="https://en.wikipedia.org/wiki/Ordinal_numeral" target="_blank" rel="noopener">Ordinal number word</a> for describing the content's importance.</td>
</tr>
</tbody>
</table>
<h2 id="guidelines">Guidelines</h2>
<h3 id="nesting">Nesting</h3>
<p>Boxes of the same <code>ord</code> should not be nested inside each other. Nesting a secondary box inside a primary box is ok:</p>
<m-box>
<h3 class="mar-t-0">Terms of service</h3>
<p>You must use the web platform.</p>
<m-box ord="secondary">
<label><input type="checkbox"> I agree</label>
</m-box>
</m-box>
<pre><code><m-box>
<h3 class="mar-t-0">Terms of service</h3>
<p>You must use the web platform.</p>
<m-box ord="secondary">
<label><input type="checkbox">I agree</label>
</m-box>
</m-box></code></pre>
<h3 id="box-header-footer">Box Header & Footer</h3>
<p>Because a box header is more tricky than it seems (compensating for default padding), it doesn't get any special styles. However, it just takes a few classes to get a nice Box header:</p>
<m-box class="pad-0">
<header class="pad-4 bg-gray-1 brd-b">Header</header>
<p class="pad-4">Content</p>
<header class="pad-4 bg-gray-1 brd-t">Footer</header>
</m-box>
<pre><code><m-box class="pad-0">
<header class="pad-4 bg-gray-1 brd-b">Header</header>
<div class="pad-4">Content</div>
</m-box></code></pre>
<h3 id="box-a11y">Accessibility</h3>
<p>There are no accessibility recommendations for Box.</p>
</section>
<hr>