@fsegurai/marked-extended-accordion 18.0.0 → 19.0.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.custom.md +181 -68
- package/README.md +182 -68
- package/dist/index.cjs +13 -4
- package/dist/index.esm.js +376 -135
- package/dist/index.umd.js +13 -4
- package/dist/styles/accordion-theme.css +71 -71
- package/dist/styles/accordion-theme.scss +45 -45
- package/dist/styles/accordion.css +57 -16
- package/dist/styles/accordion.scss +52 -10
- package/dist/types/index.d.ts +6 -6
- package/dist/types/runtime.d.ts +27 -0
- package/dist/types/types.d.ts +69 -0
- package/dist/types/utils/constants.d.ts +29 -9
- package/dist/types/utils/props.d.ts +9 -36
- package/package.json +1 -1
- package/dist/types/markdown-utils.d.ts +0 -19
package/README.custom.md
CHANGED
|
@@ -203,6 +203,49 @@ Content with slower transition
|
|
|
203
203
|
|
|
204
204
|
<!-- SECTION:CUSTOM_USAGE_NOTES -->
|
|
205
205
|
|
|
206
|
+
### Sanitizer-safe markup and the browser runtime (19.0.0-beta.0)
|
|
207
|
+
|
|
208
|
+
By default the HTML survives strict sanitizers such as Angular's `SecurityContext.HTML`, which removes `id`, `name`,
|
|
209
|
+
`style`, `data-*` and `<svg>`. Those values move into class tokens (`mx-accordion-<key>-<value>`):
|
|
210
|
+
|
|
211
|
+
| 18.0 markup | 19.0.0-beta.0 default |
|
|
212
|
+
| --- | --- |
|
|
213
|
+
| `id="accordion-x1y2z3"` | `mx-accordion-id-accordion-x1y2z3` |
|
|
214
|
+
| `name="faq"` (exclusive group) | `mx-accordion-group-faq` |
|
|
215
|
+
| `style="--…-animation-duration: 0.5s; …"` | `mx-accordion-duration-0_2e5s`, `mx-accordion-easing-…` (only when they differ from the defaults) |
|
|
216
|
+
| `data-section="intro"` | `mx-accordion-dataSection-intro` |
|
|
217
|
+
| variant `<svg>` icon | `<span class="mx-accordion-icon mx-accordion-icon-note">`, drawn by `accordion.css` |
|
|
218
|
+
|
|
219
|
+
`<details>`, `<summary>` and `open` survive sanitizing, so expanding and collapsing works without JavaScript. The rest is
|
|
220
|
+
done by a scoped runtime that you attach after the HTML is in the DOM:
|
|
221
|
+
|
|
222
|
+
```javascript
|
|
223
|
+
import markedExtendedAccordion, { attachAccordion } from '@fsegurai/marked-extended-accordion';
|
|
224
|
+
|
|
225
|
+
marked.use(markedExtendedAccordion());
|
|
226
|
+
container.innerHTML = marked.parse(markdown);
|
|
227
|
+
|
|
228
|
+
// { className } if you changed the extension's className; allowedDataAttributes for custom data-* values
|
|
229
|
+
const dispose = attachAccordion(container, { allowedDataAttributes: ['data-section'] });
|
|
230
|
+
// later: dispose();
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
- Applies the per-block `duration`/`easing` CSS variables and restores the `data-*` attributes listed in
|
|
234
|
+
`allowedDataAttributes` (case-insensitive, default `[]`). Class tokens can be written by hand in Markdown HTML, so
|
|
235
|
+
other `mx-accordion-data*` tokens are never restored: content cannot forge attributes such as `data-line`.
|
|
236
|
+
- Exclusive groups: opening an accordion closes the other open accordions of its group inside `container`.
|
|
237
|
+
- `#id` links whose target lost its `id` open and scroll to the accordion carrying that id token.
|
|
238
|
+
- Dispatches a bubbling `marked-extended:accordion:toggle` event with `detail: { id, open, group }`.
|
|
239
|
+
- Listeners live on `container` only; attaching twice is a no-op; the first `dispose()` removes everything.
|
|
240
|
+
- Replacing the content of `container` keeps groups, links and events working (they are delegated). The CSS variables
|
|
241
|
+
and `data-*` attributes are per element: call `attachAccordion.refresh(container)` after a re-render, or attach with
|
|
242
|
+
`attachAccordion(container, { observe: true })` (a `MutationObserver` on `container` only, disconnected by dispose).
|
|
243
|
+
|
|
244
|
+
Pass `unsafeHtml: true` to keep the 18.0 markup (`id`, `name`, `style`, `data-*`, inline `<svg>`) when you do not
|
|
245
|
+
sanitize the HTML. Custom templates can still use `{accordionId}`, `{nameAttr}`, `{dataAttrs}` and `{styleAttr}`
|
|
246
|
+
(strict sanitizers remove what they produce), and the new `{tokenClasses}` placeholder.
|
|
247
|
+
|
|
248
|
+
|
|
206
249
|
### Importing Styles
|
|
207
250
|
|
|
208
251
|
Starting from version 17.0.0, this extension **does not automatically inject styles**. You must import the CSS or SCSS
|
|
@@ -302,7 +345,7 @@ Complete example for projects without build tools:
|
|
|
302
345
|
<title>Marked Extended Accordion Example</title>
|
|
303
346
|
|
|
304
347
|
<!-- Import Marked.js from CDN -->
|
|
305
|
-
<script src="https://cdn.jsdelivr.net/npm/marked@
|
|
348
|
+
<script src="https://cdn.jsdelivr.net/npm/marked@18/lib/marked.umd.js"></script>
|
|
306
349
|
|
|
307
350
|
<!-- Import Accordion Extension from CDN -->
|
|
308
351
|
<script src="https://cdn.jsdelivr.net/npm/@fsegurai/marked-extended-accordion@latest/dist/index.umd.js"></script>
|
|
@@ -358,20 +401,20 @@ The extension generates semantic HTML using native `<details>` and `<summary>` e
|
|
|
358
401
|
|
|
359
402
|
```html
|
|
360
403
|
|
|
361
|
-
<details id="accordion-{hash}" class="
|
|
362
|
-
style="--
|
|
363
|
-
<summary class="
|
|
364
|
-
<span class="
|
|
365
|
-
<h3 class="
|
|
404
|
+
<details id="accordion-{hash}" class="mx-accordion" open name="faq"
|
|
405
|
+
style="--mx-accordion-animation-duration: 0.3s; --mx-accordion-transition-timing: ease-in-out;">
|
|
406
|
+
<summary class="mx-accordion-header">
|
|
407
|
+
<span class="mx-accordion-icon" aria-hidden="true">➤</span>
|
|
408
|
+
<h3 class="mx-accordion-title">Your Title</h3>
|
|
366
409
|
</summary>
|
|
367
|
-
<div class="
|
|
410
|
+
<div class="mx-accordion-content">
|
|
368
411
|
<!-- rendered markdown content -->
|
|
369
412
|
</div>
|
|
370
413
|
</details>
|
|
371
414
|
```
|
|
372
415
|
|
|
373
416
|
(The `name` attribute and icon span only appear when `group`/`icon`/`variant` are set. A `variant` adds a
|
|
374
|
-
`
|
|
417
|
+
`mx-accordion-{variant}` class, `class` appends extra classes, and `data-*` keys become `data-*`
|
|
375
418
|
attributes. With `iconPosition: after` the icon span moves after the heading.)
|
|
376
419
|
|
|
377
420
|
**Benefits of using `<details>`:**
|
|
@@ -385,11 +428,11 @@ attributes. With `iconPosition: after` the icon span moves after the heading.)
|
|
|
385
428
|
|
|
386
429
|
| Class | Element | Purpose |
|
|
387
430
|
|--------------------------------------|-----------|----------------------------------|
|
|
388
|
-
| `.
|
|
389
|
-
| `.
|
|
390
|
-
| `.
|
|
391
|
-
| `.
|
|
392
|
-
| `.
|
|
431
|
+
| `.mx-accordion` | `details` | Main container element |
|
|
432
|
+
| `.mx-accordion-header` | `summary` | Clickable header/trigger element |
|
|
433
|
+
| `.mx-accordion-title` | `h1-h6` | Title text element |
|
|
434
|
+
| `.mx-accordion-icon` | `span` | Optional icon before title |
|
|
435
|
+
| `.mx-accordion-content` | `div` | Content wrapper |
|
|
393
436
|
|
|
394
437
|
**Styling Targets:**
|
|
395
438
|
|
|
@@ -418,7 +461,7 @@ Create your own styles targeting the classes:
|
|
|
418
461
|
|
|
419
462
|
```css
|
|
420
463
|
/* Base accordion styling */
|
|
421
|
-
.
|
|
464
|
+
.mx-accordion {
|
|
422
465
|
border: 1px solid #e0e0e0;
|
|
423
466
|
border-radius: 8px;
|
|
424
467
|
margin: 1rem 0;
|
|
@@ -427,7 +470,7 @@ Create your own styles targeting the classes:
|
|
|
427
470
|
}
|
|
428
471
|
|
|
429
472
|
/* Header (summary) styling */
|
|
430
|
-
.
|
|
473
|
+
.mx-accordion-header {
|
|
431
474
|
padding: 1rem;
|
|
432
475
|
background: #f5f5f5;
|
|
433
476
|
cursor: pointer;
|
|
@@ -436,16 +479,16 @@ Create your own styles targeting the classes:
|
|
|
436
479
|
}
|
|
437
480
|
|
|
438
481
|
/* Remove default disclosure triangle in WebKit browsers */
|
|
439
|
-
.
|
|
482
|
+
.mx-accordion-header::-webkit-details-marker {
|
|
440
483
|
display: none;
|
|
441
484
|
}
|
|
442
485
|
|
|
443
|
-
.
|
|
486
|
+
.mx-accordion-header:hover {
|
|
444
487
|
background: #ebebeb;
|
|
445
488
|
}
|
|
446
489
|
|
|
447
490
|
/* Title styling */
|
|
448
|
-
.
|
|
491
|
+
.mx-accordion-title {
|
|
449
492
|
margin: 0;
|
|
450
493
|
font-size: 1.1rem;
|
|
451
494
|
font-weight: 600;
|
|
@@ -454,7 +497,7 @@ Create your own styles targeting the classes:
|
|
|
454
497
|
}
|
|
455
498
|
|
|
456
499
|
/* Add custom icon using pseudo-element */
|
|
457
|
-
.
|
|
500
|
+
.mx-accordion-header::before {
|
|
458
501
|
content: '▶';
|
|
459
502
|
display: inline-block;
|
|
460
503
|
margin-right: 0.5rem;
|
|
@@ -463,12 +506,12 @@ Create your own styles targeting the classes:
|
|
|
463
506
|
}
|
|
464
507
|
|
|
465
508
|
/* Rotate icon when expanded */
|
|
466
|
-
.
|
|
509
|
+
.mx-accordion[open] .mx-accordion-header::before {
|
|
467
510
|
transform: rotate(90deg);
|
|
468
511
|
}
|
|
469
512
|
|
|
470
513
|
/* Content styling */
|
|
471
|
-
.
|
|
514
|
+
.mx-accordion-content {
|
|
472
515
|
padding: 1rem;
|
|
473
516
|
background: #fff;
|
|
474
517
|
}
|
|
@@ -485,7 +528,7 @@ Create your own styles targeting the classes:
|
|
|
485
528
|
}
|
|
486
529
|
}
|
|
487
530
|
|
|
488
|
-
.
|
|
531
|
+
.mx-accordion[open] .mx-accordion-content {
|
|
489
532
|
animation: accordion-open 0.3s ease;
|
|
490
533
|
}
|
|
491
534
|
```
|
|
@@ -505,24 +548,24 @@ Use CSS variables for easy theming:
|
|
|
505
548
|
}
|
|
506
549
|
|
|
507
550
|
/* Apply variables to classes */
|
|
508
|
-
.
|
|
551
|
+
.mx-accordion {
|
|
509
552
|
border: 1px solid var(--accordion-border);
|
|
510
553
|
background: var(--accordion-bg);
|
|
511
554
|
}
|
|
512
555
|
|
|
513
|
-
.
|
|
556
|
+
.mx-accordion-header {
|
|
514
557
|
background: var(--accordion-header-bg);
|
|
515
558
|
}
|
|
516
559
|
|
|
517
|
-
.
|
|
560
|
+
.mx-accordion-header:hover {
|
|
518
561
|
background: var(--accordion-header-hover);
|
|
519
562
|
}
|
|
520
563
|
|
|
521
|
-
.
|
|
564
|
+
.mx-accordion-title {
|
|
522
565
|
color: var(--accordion-text);
|
|
523
566
|
}
|
|
524
567
|
|
|
525
|
-
.
|
|
568
|
+
.mx-accordion-icon {
|
|
526
569
|
color: var(--accordion-icon);
|
|
527
570
|
}
|
|
528
571
|
```
|
|
@@ -533,32 +576,32 @@ Add dark theme overrides:
|
|
|
533
576
|
|
|
534
577
|
```css
|
|
535
578
|
/* Light theme (default) */
|
|
536
|
-
body.light .
|
|
579
|
+
body.light .mx-accordion {
|
|
537
580
|
border-color: #e0e0e0;
|
|
538
581
|
background: #ffffff;
|
|
539
582
|
}
|
|
540
583
|
|
|
541
|
-
body.light .
|
|
584
|
+
body.light .mx-accordion-header {
|
|
542
585
|
background: #f5f5f5;
|
|
543
586
|
color: #333;
|
|
544
587
|
}
|
|
545
588
|
|
|
546
589
|
/* Dark theme */
|
|
547
|
-
body.dark .
|
|
590
|
+
body.dark .mx-accordion {
|
|
548
591
|
border-color: #444c56;
|
|
549
592
|
background: #22272e;
|
|
550
593
|
}
|
|
551
594
|
|
|
552
|
-
body.dark .
|
|
595
|
+
body.dark .mx-accordion-header {
|
|
553
596
|
background: #2d333b;
|
|
554
597
|
color: #d1d5da;
|
|
555
598
|
}
|
|
556
599
|
|
|
557
|
-
body.dark .
|
|
600
|
+
body.dark .mx-accordion-header:hover {
|
|
558
601
|
background: #343b45;
|
|
559
602
|
}
|
|
560
603
|
|
|
561
|
-
body.dark .
|
|
604
|
+
body.dark .mx-accordion-content {
|
|
562
605
|
color: #d1d5da;
|
|
563
606
|
}
|
|
564
607
|
```
|
|
@@ -576,36 +619,36 @@ Enhance keyboard navigation styling:
|
|
|
576
619
|
|
|
577
620
|
```css
|
|
578
621
|
/* Focus styles for keyboard navigation */
|
|
579
|
-
.
|
|
622
|
+
.mx-accordion-header:focus {
|
|
580
623
|
outline: 2px solid #0066cc;
|
|
581
624
|
outline-offset: 2px;
|
|
582
625
|
}
|
|
583
626
|
|
|
584
|
-
.
|
|
627
|
+
.mx-accordion-header:focus-visible {
|
|
585
628
|
outline: 2px solid #0066cc;
|
|
586
629
|
outline-offset: 2px;
|
|
587
630
|
}
|
|
588
631
|
|
|
589
632
|
/* Remove outline for mouse users (but keep for keyboard) */
|
|
590
|
-
.
|
|
633
|
+
.mx-accordion-header:focus:not(:focus-visible) {
|
|
591
634
|
outline: none;
|
|
592
635
|
}
|
|
593
636
|
|
|
594
637
|
/* High contrast mode support */
|
|
595
638
|
@media (prefers-contrast: high) {
|
|
596
|
-
.
|
|
639
|
+
.mx-accordion {
|
|
597
640
|
border-width: 2px;
|
|
598
641
|
}
|
|
599
642
|
|
|
600
|
-
.
|
|
643
|
+
.mx-accordion-header {
|
|
601
644
|
border: 2px solid currentColor;
|
|
602
645
|
}
|
|
603
646
|
}
|
|
604
647
|
|
|
605
648
|
/* Reduced motion support */
|
|
606
649
|
@media (prefers-reduced-motion: reduce) {
|
|
607
|
-
.
|
|
608
|
-
.
|
|
650
|
+
.mx-accordion-header::before,
|
|
651
|
+
.mx-accordion-content {
|
|
609
652
|
transition: none;
|
|
610
653
|
animation: none;
|
|
611
654
|
}
|
|
@@ -615,30 +658,30 @@ Enhance keyboard navigation styling:
|
|
|
615
658
|
#### Example: Minimal Modern Style
|
|
616
659
|
|
|
617
660
|
```css
|
|
618
|
-
.
|
|
661
|
+
.mx-accordion {
|
|
619
662
|
border: none;
|
|
620
663
|
border-left: 3px solid #0066cc;
|
|
621
664
|
margin: 1.5rem 0;
|
|
622
665
|
background: transparent;
|
|
623
666
|
}
|
|
624
667
|
|
|
625
|
-
.
|
|
668
|
+
.mx-accordion-header {
|
|
626
669
|
padding: 0.75rem 1rem;
|
|
627
670
|
background: rgba(0, 102, 204, 0.05);
|
|
628
671
|
border-radius: 4px;
|
|
629
672
|
list-style: none;
|
|
630
673
|
}
|
|
631
674
|
|
|
632
|
-
.
|
|
675
|
+
.mx-accordion-header::-webkit-details-marker {
|
|
633
676
|
display: none;
|
|
634
677
|
}
|
|
635
678
|
|
|
636
|
-
.
|
|
679
|
+
.mx-accordion[open] .mx-accordion-header {
|
|
637
680
|
background: rgba(0, 102, 204, 0.1);
|
|
638
681
|
border-radius: 4px 4px 0 0;
|
|
639
682
|
}
|
|
640
683
|
|
|
641
|
-
.
|
|
684
|
+
.mx-accordion-content {
|
|
642
685
|
padding: 1rem 1rem 1rem 1.5rem;
|
|
643
686
|
}
|
|
644
687
|
```
|
|
@@ -647,6 +690,63 @@ Check the [demo](https://fsegurai.github.io/marked-extensions) to see various st
|
|
|
647
690
|
|
|
648
691
|
<!-- SECTION:CUSTOM_SECTIONS -->
|
|
649
692
|
|
|
693
|
+
### CSS classes and custom properties
|
|
694
|
+
|
|
695
|
+
Every class follows the shared 19.x convention: root `mx-accordion`, parts `mx-accordion-<part>`, modifiers
|
|
696
|
+
`mx-accordion--<modifier>`. Class tokens (`mx-accordion-<key>-<value>`) carry configuration and are read by
|
|
697
|
+
`attachAccordion`; do not style them, except the icon tokens listed below. The class names derive from the `className`
|
|
698
|
+
option (default `mx-accordion`).
|
|
699
|
+
|
|
700
|
+
| Class | Element | Purpose |
|
|
701
|
+
|---------------------------------------|-----------------------------|---------------------------------------------------------------------------|
|
|
702
|
+
| `mx-accordion` | `<details>` | Root of one accordion |
|
|
703
|
+
| `mx-accordion--<variant>` | `<details>` | Variant modifier (`note`, `tip`, `important`, `warning`, `caution`, custom) |
|
|
704
|
+
| `mx-accordion-header` | `<summary>` | Clickable header |
|
|
705
|
+
| `mx-accordion-title` | `<h1>`…`<h6>` | Title |
|
|
706
|
+
| `mx-accordion-icon` | `<span>` | Icon (explicit `icon` or variant icon) |
|
|
707
|
+
| `mx-accordion-icon-<variant>` | `<span>` | Class token of a built-in CSS (mask) icon |
|
|
708
|
+
| `mx-accordion-content` | `<div>` | Body |
|
|
709
|
+
| `mx-accordion-id-*`, `-group-*`, `-duration-*`, `-easing-*`, `-data*-*` | `<details>` | Class tokens read by the runtime |
|
|
710
|
+
|
|
711
|
+
Classes owned by others: `octicon` (inline Octicon `<svg>` icons with `unsafeHtml: true`) and `body.light` /
|
|
712
|
+
`body.dark` (the host page's theme switch, read by `accordion-theme.css`).
|
|
713
|
+
|
|
714
|
+
| Custom property | Default | Used for |
|
|
715
|
+
|--------------------------------------------------|-------------------------------|--------------------------------------------------|
|
|
716
|
+
| `--mx-accordion-animation-duration` | `0.3s` | Open animation duration (set per block by the runtime) |
|
|
717
|
+
| `--mx-accordion-transition-timing` | `ease-in-out` | Content transition timing (set per block by the runtime) |
|
|
718
|
+
| `--mx-accordion-animation-easing` | `ease` | Open animation easing |
|
|
719
|
+
| `--mx-accordion-fade-distance` | `-10px` | Vertical offset of the open animation |
|
|
720
|
+
| `--mx-accordion-icon-gap` | `0.5rem` | Space between icon and title |
|
|
721
|
+
| `--mx-accordion-icon-size` | `16px` | Size of the built-in CSS icons |
|
|
722
|
+
| `--mx-accordion-icon` | per variant | Mask image of a built-in icon |
|
|
723
|
+
| `--mx-accordion-border-color` | `#ddd` | Border (theme) |
|
|
724
|
+
| `--mx-accordion-border-width` | `1px` | Border width (theme) |
|
|
725
|
+
| `--mx-accordion-background-color` | `#ffffff` | Background (theme) |
|
|
726
|
+
| `--mx-accordion-header-background-color` | `#f5f5f5` | Header background (theme) |
|
|
727
|
+
| `--mx-accordion-header-hover-background-color` | `#e8e8e8` | Header hover background (theme) |
|
|
728
|
+
| `--mx-accordion-hover-duration` | `0.2s` | Header hover transition (theme) |
|
|
729
|
+
| `--mx-accordion-text-color` | `#333` | Header and title text (theme) |
|
|
730
|
+
| `--mx-accordion-content-color` | `#24292e` | Body text (theme) |
|
|
731
|
+
| `--mx-accordion-radius` | `4px` | Corner radius (theme) |
|
|
732
|
+
| `--mx-accordion-margin` | `1rem 0` | Outer margin (theme) |
|
|
733
|
+
| `--mx-accordion-header-padding` | `0.75rem 1rem` | Header padding (theme) |
|
|
734
|
+
| `--mx-accordion-content-padding` | `1rem` | Body padding (theme) |
|
|
735
|
+
| `--mx-accordion-accent-width` | `4px` | Left accent of a variant (theme) |
|
|
736
|
+
| `--mx-accordion-<variant>-color` | GitHub alert palette | Accent and icon colour of a variant (theme) |
|
|
737
|
+
|
|
738
|
+
#### Migration from 18.x class names
|
|
739
|
+
|
|
740
|
+
| 18.x | 19.x |
|
|
741
|
+
|---------------------------------------------|---------------------------------------|
|
|
742
|
+
| `marked-extended-accordion` | `mx-accordion` |
|
|
743
|
+
| `marked-extended-accordion-<variant>` | `mx-accordion--<variant>` |
|
|
744
|
+
| `marked-extended-accordion-header` | `mx-accordion-header` |
|
|
745
|
+
| `marked-extended-accordion-title` | `mx-accordion-title` |
|
|
746
|
+
| `marked-extended-accordion-icon` | `mx-accordion-icon` |
|
|
747
|
+
| `marked-extended-accordion-content` | `mx-accordion-content` |
|
|
748
|
+
| `--marked-extended-accordion-*` | `--mx-accordion-*` |
|
|
749
|
+
|
|
650
750
|
### Configuration Options
|
|
651
751
|
|
|
652
752
|
The accordion extension accepts several configuration options when initializing. Pass them as an object to the extension
|
|
@@ -666,7 +766,7 @@ marked.use(markedExtendedAccordion({
|
|
|
666
766
|
|
|
667
767
|
| Option | Type | Default | Description |
|
|
668
768
|
|---------------------|-------------|-------------------------------|------------------------------------------------------------------------------------------|
|
|
669
|
-
| `className` | `string` | `'
|
|
769
|
+
| `className` | `string` | `'mx-accordion'` | Base CSS class name applied to all accordion containers |
|
|
670
770
|
| `prefixId` | `string` | `'accordion-'` | Prefix for generating unique accordion IDs |
|
|
671
771
|
| `animationDuration` | `string` | `'0.3s'` | Default animation duration (can be overridden per accordion) |
|
|
672
772
|
| `animationEasing` | `string` | `'ease-in-out'` | Default animation timing function (can be overridden per accordion via `easing`) |
|
|
@@ -675,6 +775,19 @@ marked.use(markedExtendedAccordion({
|
|
|
675
775
|
| `template` | `string` | `null` | Custom HTML template for rendering (see [Custom Templates](#custom-html-template)) |
|
|
676
776
|
| `customizeToken` | `function` | `null` | Function to customize tokens before rendering |
|
|
677
777
|
|
|
778
|
+
#### Exports and constants (19.0.0-beta.1)
|
|
779
|
+
|
|
780
|
+
```javascript
|
|
781
|
+
import markedExtendedAccordion, {
|
|
782
|
+
markedExtendedAccordion as accordion, // same factory, named export
|
|
783
|
+
ACCORDION_VARIANTS, // ['note', 'tip', 'important', 'warning', 'caution'] (frozen)
|
|
784
|
+
ACCORDION_ICON_POSITIONS, // ['before', 'after'] (frozen)
|
|
785
|
+
} from '@fsegurai/marked-extended-accordion';
|
|
786
|
+
```
|
|
787
|
+
|
|
788
|
+
The factory returns a `MarkedExtension`. The accordion renders no fixed text of its own (titles, icons and content come
|
|
789
|
+
from your Markdown), so it has no `labels` option.
|
|
790
|
+
|
|
678
791
|
#### Markdown Syntax Properties
|
|
679
792
|
|
|
680
793
|
These properties are specified in the accordion's front matter:
|
|
@@ -811,7 +924,7 @@ Generated attribute: `<details id="pricing" ...>`.
|
|
|
811
924
|
#### Optional Icon
|
|
812
925
|
|
|
813
926
|
Set `icon` to render a character or emoji before the title. The icon is wrapped in
|
|
814
|
-
`<span class="
|
|
927
|
+
`<span class="mx-accordion-icon" aria-hidden="true">`.
|
|
815
928
|
|
|
816
929
|
`````markdown
|
|
817
930
|
```accordion
|
|
@@ -822,7 +935,7 @@ Follow these steps to get up and running quickly.
|
|
|
822
935
|
```
|
|
823
936
|
`````
|
|
824
937
|
|
|
825
|
-
The `.
|
|
938
|
+
The `.mx-accordion-icon` class provides structural styling for positioning the icon relative to the title.
|
|
826
939
|
|
|
827
940
|
#### Icon Position
|
|
828
941
|
|
|
@@ -864,8 +977,8 @@ marked.use(markedExtendedAccordion({
|
|
|
864
977
|
}));
|
|
865
978
|
```
|
|
866
979
|
|
|
867
|
-
The variant name is also emitted as a modifier class (`{className}
|
|
868
|
-
`
|
|
980
|
+
The variant name is also emitted as a modifier class (`{className}--{variant}`, e.g.
|
|
981
|
+
`mx-accordion--warning`), so you can target it from CSS.
|
|
869
982
|
|
|
870
983
|
#### Custom Classes and Data Attributes
|
|
871
984
|
|
|
@@ -878,7 +991,7 @@ title: Tracked panel
|
|
|
878
991
|
class: highlight featured
|
|
879
992
|
data-analytics-id: faq-pricing
|
|
880
993
|
---
|
|
881
|
-
Renders as `<details class="
|
|
994
|
+
Renders as `<details class="mx-accordion highlight featured" data-analytics-id="faq-pricing">`.
|
|
882
995
|
```
|
|
883
996
|
`````
|
|
884
997
|
|
|
@@ -1069,19 +1182,19 @@ marked.use(markedExtendedAccordion({
|
|
|
1069
1182
|
| Placeholder | Description | Example Value |
|
|
1070
1183
|
|-----------------------|------------------------------------------------------------------------|----------------------------------------------------------------------------------|
|
|
1071
1184
|
| `{accordionId}` | Unique identifier for the accordion | `accordion-abc123` |
|
|
1072
|
-
| `{className}` | Base CSS class name | `
|
|
1073
|
-
| `{variantClass}` | Variant modifier class (leading space), empty when no variant | `
|
|
1185
|
+
| `{className}` | Base CSS class name | `mx-accordion` |
|
|
1186
|
+
| `{variantClass}` | Variant modifier class (leading space), empty when no variant | ` mx-accordion--warning` or `` |
|
|
1074
1187
|
| `{extraClasses}` | Per-block classes from `class` (leading space), empty when none | ` highlight featured` or `` |
|
|
1075
1188
|
| `{expandedAttr}` | `open` attribute if expanded, empty otherwise | `open` or `` |
|
|
1076
1189
|
| `{headingTag}` | HTML heading tag based on level | `h2`, `h3`, etc. |
|
|
1077
1190
|
| `{title}` | Accordion title text (may contain inline HTML) | `My Accordion` |
|
|
1078
1191
|
| `{content}` | Rendered markdown content | `<p>Content...</p>` |
|
|
1079
1192
|
| `{animationDuration}` | Animation duration value | `0.3s` |
|
|
1080
|
-
| `{styleAttr}` | Inline CSS variables for duration and easing | `--
|
|
1193
|
+
| `{styleAttr}` | Inline CSS variables for duration and easing | `--mx-accordion-animation-duration: 0.3s; ...` |
|
|
1081
1194
|
| `{expanded}` | Boolean string value | `true` or `false` |
|
|
1082
1195
|
| `{nameAttr}` | `name="group"` attribute for exclusive accordions, empty when no group | `name="faq"` or `` |
|
|
1083
1196
|
| `{dataAttrs}` | Serialized custom `data-*` attributes, empty when none | ` data-id="42"` or `` |
|
|
1084
|
-
| `{icon}` | Icon span markup (before-title alias), empty when no icon | `<span class="
|
|
1197
|
+
| `{icon}` | Icon span markup (before-title alias), empty when no icon | `<span class="mx-accordion-icon" aria-hidden="true">➤</span>` or `` |
|
|
1085
1198
|
| `{iconBefore}` | Icon span markup when positioned before the title, empty otherwise | same as `{icon}` or `` |
|
|
1086
1199
|
| `{iconAfter}` | Icon span markup when positioned after the title, empty otherwise | same as `{icon}` or `` |
|
|
1087
1200
|
|
|
@@ -1120,13 +1233,13 @@ marked.use(markedExtendedAccordion({
|
|
|
1120
1233
|
2. **CSS Animations**: Use CSS transforms for better performance:
|
|
1121
1234
|
|
|
1122
1235
|
```css
|
|
1123
|
-
.
|
|
1236
|
+
.mx-accordion-content {
|
|
1124
1237
|
transform-origin: top;
|
|
1125
1238
|
transition: transform 0.3s ease, opacity 0.3s ease;
|
|
1126
1239
|
}
|
|
1127
1240
|
|
|
1128
1241
|
/* Use will-change sparingly, only when needed */
|
|
1129
|
-
.
|
|
1242
|
+
.mx-accordion-header:hover ~ .mx-accordion-content {
|
|
1130
1243
|
will-change: transform, opacity;
|
|
1131
1244
|
}
|
|
1132
1245
|
```
|
|
@@ -1136,7 +1249,7 @@ marked.use(markedExtendedAccordion({
|
|
|
1136
1249
|
4. **Content Loading**: For very large content blocks, consider using `content-visibility`:
|
|
1137
1250
|
|
|
1138
1251
|
```css
|
|
1139
|
-
.
|
|
1252
|
+
.mx-accordion-content {
|
|
1140
1253
|
content-visibility: auto;
|
|
1141
1254
|
contain-intrinsic-size: 0 500px; /* Estimated height */
|
|
1142
1255
|
}
|
|
@@ -1240,7 +1353,7 @@ accordion.addEventListener('toggle', (event) => {
|
|
|
1240
1353
|
2. Check for conflicting CSS that might disable pointer events:
|
|
1241
1354
|
```css
|
|
1242
1355
|
/* Remove if present */
|
|
1243
|
-
.
|
|
1356
|
+
.mx-accordion-header {
|
|
1244
1357
|
pointer-events: none; /* ❌ This breaks functionality */
|
|
1245
1358
|
}
|
|
1246
1359
|
```
|
|
@@ -1269,11 +1382,11 @@ accordion.addEventListener('toggle', (event) => {
|
|
|
1269
1382
|
**Solution**: Hide the default marker:
|
|
1270
1383
|
|
|
1271
1384
|
```css
|
|
1272
|
-
.
|
|
1385
|
+
.mx-accordion-header::-webkit-details-marker {
|
|
1273
1386
|
display: none;
|
|
1274
1387
|
}
|
|
1275
1388
|
|
|
1276
|
-
.
|
|
1389
|
+
.mx-accordion-header {
|
|
1277
1390
|
list-style: none; /* Firefox */
|
|
1278
1391
|
}
|
|
1279
1392
|
```
|
|
@@ -1285,14 +1398,14 @@ accordion.addEventListener('toggle', (event) => {
|
|
|
1285
1398
|
**Solution**:
|
|
1286
1399
|
|
|
1287
1400
|
```css
|
|
1288
|
-
.
|
|
1401
|
+
.mx-accordion-content {
|
|
1289
1402
|
overflow: hidden;
|
|
1290
1403
|
word-wrap: break-word;
|
|
1291
1404
|
overflow-wrap: break-word;
|
|
1292
1405
|
}
|
|
1293
1406
|
|
|
1294
1407
|
/* For code blocks */
|
|
1295
|
-
.
|
|
1408
|
+
.mx-accordion-content pre {
|
|
1296
1409
|
overflow-x: auto;
|
|
1297
1410
|
max-width: 100%;
|
|
1298
1411
|
}
|
|
@@ -1309,13 +1422,13 @@ accordion.addEventListener('toggle', (event) => {
|
|
|
1309
1422
|
|
|
1310
1423
|
```css
|
|
1311
1424
|
/* Smooth animation with max-height trick */
|
|
1312
|
-
.
|
|
1425
|
+
.mx-accordion-content {
|
|
1313
1426
|
max-height: 0;
|
|
1314
1427
|
overflow: hidden;
|
|
1315
1428
|
transition: max-height 0.3s ease-out;
|
|
1316
1429
|
}
|
|
1317
1430
|
|
|
1318
|
-
.
|
|
1431
|
+
.mx-accordion[open] .mx-accordion-content {
|
|
1319
1432
|
max-height: 2000px; /* Large enough value */
|
|
1320
1433
|
transition: max-height 0.3s ease-in;
|
|
1321
1434
|
}
|
|
@@ -1324,7 +1437,7 @@ accordion.addEventListener('toggle', (event) => {
|
|
|
1324
1437
|
2. Use `will-change` sparingly for better performance:
|
|
1325
1438
|
|
|
1326
1439
|
```css
|
|
1327
|
-
.
|
|
1440
|
+
.mx-accordion:hover .mx-accordion-content {
|
|
1328
1441
|
will-change: max-height;
|
|
1329
1442
|
}
|
|
1330
1443
|
```
|
|
@@ -1537,7 +1650,7 @@ Optional advanced settings
|
|
|
1537
1650
|
Ensure tap targets are large enough (minimum 44×44px):
|
|
1538
1651
|
|
|
1539
1652
|
```css
|
|
1540
|
-
.
|
|
1653
|
+
.mx-accordion-header {
|
|
1541
1654
|
min-height: 44px;
|
|
1542
1655
|
padding: 12px 16px;
|
|
1543
1656
|
}
|
|
@@ -1688,7 +1801,7 @@ interface AccordionVariant {
|
|
|
1688
1801
|
}
|
|
1689
1802
|
|
|
1690
1803
|
interface AccordionOptions {
|
|
1691
|
-
className?: string; // Base CSS class (default: '
|
|
1804
|
+
className?: string; // Base CSS class (default: 'mx-accordion')
|
|
1692
1805
|
prefixId?: string; // ID prefix (default: 'accordion-')
|
|
1693
1806
|
animationDuration?: string; // Animation duration (default: '0.3s')
|
|
1694
1807
|
animationEasing?: string; // Animation timing function (default: 'ease-in-out')
|