astro-better-details 0.1.0
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/Details.astro +70 -0
- package/README.md +85 -0
- package/package.json +16 -0
package/Details.astro
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
---
|
|
2
|
+
interface Props {
|
|
3
|
+
open?: boolean;
|
|
4
|
+
class?: string;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
const { open, class: cls } = Astro.props;
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
<details class:list={['abt-details', cls]} open={open}>
|
|
11
|
+
<summary class="abt-details-summary">
|
|
12
|
+
<span class="abt-details-title"><slot name="title" /></span>
|
|
13
|
+
<svg class="abt-details-chevron" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true">
|
|
14
|
+
<path fill-rule="evenodd" d="M5.23 7.21a.75.75 0 011.06.02L10 11.168l3.71-3.938a.75.75 0 111.08 1.04l-4.25 4.5a.75.75 0 01-1.08 0l-4.25-4.5a.75.75 0 01.02-1.06z" clip-rule="evenodd" />
|
|
15
|
+
</svg>
|
|
16
|
+
</summary>
|
|
17
|
+
<div class="abt-details-body">
|
|
18
|
+
<slot />
|
|
19
|
+
</div>
|
|
20
|
+
</details>
|
|
21
|
+
|
|
22
|
+
<style is:global>
|
|
23
|
+
.abt-details {
|
|
24
|
+
border: 1px solid var(--abt-details-border, #d1d5db);
|
|
25
|
+
border-radius: 0.375rem;
|
|
26
|
+
margin: 1rem 0;
|
|
27
|
+
overflow: hidden;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
.abt-details-summary {
|
|
31
|
+
display: flex;
|
|
32
|
+
align-items: center;
|
|
33
|
+
justify-content: space-between;
|
|
34
|
+
gap: 0.75rem;
|
|
35
|
+
padding: 0.75rem 1rem;
|
|
36
|
+
cursor: pointer;
|
|
37
|
+
list-style: none;
|
|
38
|
+
background: var(--abt-details-summary-bg, #f9fafb);
|
|
39
|
+
font-weight: 500;
|
|
40
|
+
user-select: none;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
.abt-details-summary::-webkit-details-marker { display: none; }
|
|
44
|
+
.abt-details-summary::marker { display: none; }
|
|
45
|
+
|
|
46
|
+
.abt-details[open] > .abt-details-summary {
|
|
47
|
+
border-bottom: 1px solid var(--abt-details-border, #d1d5db);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
.abt-details-title {
|
|
51
|
+
flex: 1;
|
|
52
|
+
min-width: 0;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
.abt-details-chevron {
|
|
56
|
+
width: 1.25rem;
|
|
57
|
+
height: 1.25rem;
|
|
58
|
+
flex-shrink: 0;
|
|
59
|
+
color: var(--abt-details-chevron, #9ca3af);
|
|
60
|
+
transition: transform 0.2s ease;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
.abt-details[open] .abt-details-chevron {
|
|
64
|
+
transform: rotate(180deg);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
.abt-details-body {
|
|
68
|
+
padding: 1rem;
|
|
69
|
+
}
|
|
70
|
+
</style>
|
package/README.md
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
# astro-better-details
|
|
2
|
+
|
|
3
|
+
Expandable `<details>` / `<summary>` disclosure component for Astro MDX. No JavaScript required -- the browser handles expand/collapse natively. The chevron animates with CSS.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```shell
|
|
8
|
+
npm install astro-better-details
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Basic usage
|
|
12
|
+
|
|
13
|
+
```mdx
|
|
14
|
+
import Details from 'astro-better-details/Details.astro';
|
|
15
|
+
|
|
16
|
+
<Details>
|
|
17
|
+
<span slot="title">What is this?</span>
|
|
18
|
+
This is the expanded content. It can contain any Markdown or MDX.
|
|
19
|
+
</Details>
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
The `title` slot holds the always-visible summary label. The default slot holds the body content shown when expanded.
|
|
23
|
+
|
|
24
|
+
## Props
|
|
25
|
+
|
|
26
|
+
| Prop | Type | Default | Description |
|
|
27
|
+
|------|------|---------|-------------|
|
|
28
|
+
| `open` | `boolean` | `false` | Render the component already expanded |
|
|
29
|
+
| `class` | `string` | -- | Additional CSS class(es) applied to the `<details>` element |
|
|
30
|
+
|
|
31
|
+
## Slots
|
|
32
|
+
|
|
33
|
+
| Slot | Description |
|
|
34
|
+
|------|-------------|
|
|
35
|
+
| `title` (named) | Label shown in the clickable summary bar |
|
|
36
|
+
| default | Body content, shown when expanded |
|
|
37
|
+
|
|
38
|
+
The title slot accepts any inline content -- plain text, backtick code, links, or JSX components.
|
|
39
|
+
|
|
40
|
+
## Theming
|
|
41
|
+
|
|
42
|
+
The component uses CSS custom properties for all visual values. Override them on `.abt-details` or any parent selector to match your brand:
|
|
43
|
+
|
|
44
|
+
| Property | Default | Controls |
|
|
45
|
+
|----------|---------|----------|
|
|
46
|
+
| `--abt-details-border` | `#d1d5db` | Border color around the whole component and between summary/body |
|
|
47
|
+
| `--abt-details-summary-bg` | `#f9fafb` | Background of the summary bar |
|
|
48
|
+
| `--abt-details-chevron` | `#9ca3af` | Chevron icon color |
|
|
49
|
+
|
|
50
|
+
Example -- purple light mode, orange dark mode to match a common docs site palette:
|
|
51
|
+
|
|
52
|
+
```css
|
|
53
|
+
.abt-details {
|
|
54
|
+
--abt-details-border: #ddd6fe;
|
|
55
|
+
--abt-details-summary-bg: #f5f3ff;
|
|
56
|
+
--abt-details-chevron: #7c3aed;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
.dark .abt-details {
|
|
60
|
+
--abt-details-border: #1c0e00;
|
|
61
|
+
--abt-details-summary-bg: #0f0f0f;
|
|
62
|
+
--abt-details-chevron: #fb923c;
|
|
63
|
+
}
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
If your project uses a `data-theme` attribute instead of a `.dark` class, adjust the selector accordingly.
|
|
67
|
+
|
|
68
|
+
## Code blocks inside Details
|
|
69
|
+
|
|
70
|
+
The body slot renders its content as raw HTML. Code block titles (the `title="..."` meta from `astro-better-code-blocks`) render correctly because that package's CSS targets `.code-figure` globally. Do not add a `.prose` class to the body if you use Tailwind Typography -- the typography plugin styles `<figcaption>` as italic, which would override the `font-style: normal` on code titles.
|
|
71
|
+
|
|
72
|
+
If your site needs prose-style typography inside the body, apply it via a wrapper element inside the slot rather than on the component itself:
|
|
73
|
+
|
|
74
|
+
```mdx
|
|
75
|
+
<Details>
|
|
76
|
+
<span slot="title">Example</span>
|
|
77
|
+
<div class="prose">
|
|
78
|
+
Content here gets prose styling.
|
|
79
|
+
</div>
|
|
80
|
+
</Details>
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
## Accessibility
|
|
84
|
+
|
|
85
|
+
The component renders a native `<details>` / `<summary>` element pair. Screen readers expose this as a disclosure widget with the summary as the interactive label. No ARIA attributes need to be added manually.
|
package/package.json
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "astro-better-details",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "Expandable details/disclosure component for Astro",
|
|
6
|
+
"author": "Nathan Contino <ncontino@lambdalatitudinarians.org>",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"keywords": ["astro", "astro-component", "details", "disclosure"],
|
|
9
|
+
"exports": {
|
|
10
|
+
"./Details.astro": "./Details.astro"
|
|
11
|
+
},
|
|
12
|
+
"files": ["Details.astro"],
|
|
13
|
+
"peerDependencies": {
|
|
14
|
+
"astro": ">=4.0.0"
|
|
15
|
+
}
|
|
16
|
+
}
|