Skip to content

Commit ae14f99

Browse files
committed
fix: improve docs and examples for accordion & switch
1 parent 5e7e43d commit ae14f99

File tree

13 files changed

+528
-335
lines changed

13 files changed

+528
-335
lines changed

.changeset/weak-cats-pull.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@lion/accordion': patch
3+
'@lion/switch': patch
4+
---
5+
6+
Improve documentation and examples

.markdownlint.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@
77
"first-line-h1": false,
88
"no-trailing-punctuation": {
99
"punctuation": ".,;。,;:!"
10-
}
10+
},
11+
"ol-prefix": false
1112
}

docs/components/content/accordion/features.md

-214
This file was deleted.
+110-35
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,127 @@
11
# Content >> Accordion >> Overview ||10
22

3-
A web component that can be used to toggle the display of sections of content.
4-
Its purpose is to reduce the need to scroll when presenting multiple sections of content on a single page. Accordions often allow users to get the big picture before focusing on details.
3+
<p class="lion-paragraph--emphasis">An accordion is a vertically stacked set of interactive headings that each contain a title representing a section of content. It allows users to toggle the display of sections of content.</p>
54

65
```js script
7-
import { html } from '@mdjs/mdjs-preview';
8-
import '@lion/accordion/define';
6+
import { html as previewHtml } from '@mdjs/mdjs-preview';
97
```
108

119
```js preview-story
12-
export const main = () => html`
13-
<lion-accordion>
14-
<h3 slot="invoker">
15-
<button>Lorem</button>
16-
</h3>
17-
<p slot="content">Lorem ipsum dolor sit, amet consectetur adipisicing elit.</p>
18-
<h3 slot="invoker">
19-
<button>Laboriosam</button>
20-
</h3>
21-
<p slot="content">
22-
Laboriosam sequi odit cumque, enim aut assumenda itaque quis voluptas est quos fugiat unde
23-
labore reiciendis saepe, iure, optio officiis obcaecati quibusdam.
24-
</p>
25-
</lion-accordion>
26-
`;
10+
import { html, LitElement, ScopedElementsMixin } from '@lion/core';
11+
import { LionAccordion } from '@lion/accordion';
12+
13+
class MyComponent extends ScopedElementsMixin(LitElement) {
14+
static get scopedElements() {
15+
return { 'lion-accordion': LionAccordion };
16+
}
17+
render() {
18+
return html`
19+
<lion-accordion>
20+
<h3 slot="invoker">
21+
<button>Sensory Factors</button>
22+
</h3>
23+
<div slot="content">
24+
<p>
25+
The taste of oranges is determined mainly by the relative ratios of sugars and acids,
26+
whereas orange aroma derives from volatile organic compounds, including alcohols,
27+
aldehydes, ketones, terpenes, and esters. Bitter limonoid compounds, such as limonin,
28+
decrease gradually during development, whereas volatile aroma compounds tend to peak in
29+
mid– to late–season development. Taste quality tends to improve later in harvests when
30+
there is a higher sugar/acid ratio with less bitterness. As a citrus fruit, the orange
31+
is acidic, with pH levels ranging from 2.9 to 4.0.
32+
</p>
33+
<p>
34+
Sensory qualities vary according to genetic background, environmental conditions during
35+
development, ripeness at harvest, postharvest conditions, and storage duration.
36+
</p>
37+
</div>
38+
<h3 slot="invoker">
39+
<button>Nutritional value</button>
40+
</h3>
41+
<div slot="content">
42+
Orange flesh is 87% water, 12% carbohydrates, 1% protein, and contains negligible fat
43+
(table). In a 100 gram reference amount, orange flesh provides 47 calories, and is a rich
44+
source of vitamin C, providing 64% of the Daily Value. No other micronutrients are present
45+
in significant amounts (table).
46+
</div>
47+
</lion-accordion>
48+
`;
49+
}
50+
}
51+
52+
customElements.define('my-component', MyComponent);
53+
54+
export const overview = () => previewHtml`<my-component></my-component>`;
2755
```
2856

57+
## When to use
58+
59+
- Accordions are commonly used to reduce the need to scroll when presenting multiple sections of content on a single page
60+
- Longer pages can benefit users. Accordions shorten pages and reduce scrolling, but they increase the interaction cost by requiring people to decide on topic headings.
61+
- Accordions conserve space on mobile but they can also cause disorientation and too much scrolling.
62+
- Accordions should be avoided when your audience needs most or all of the content on the page to answer their question. Better to show all page content at once when the use case supports it.
63+
- Accordions are more suitable when people need only a few key pieces of content on a single page. By hiding most of the content, users can spend their time more efficiently focused on the few topics that matter.
64+
2965
## Features
3066

31-
- content gets provided by users (slotted in)
32-
- handles accessibility
33-
- support navigation via keyboard
67+
- Content gets provided by users (slotted in)
68+
- Handles accessibility
69+
- Support navigation via keyboard
3470

35-
## Installation
71+
## How to use
3672

37-
```bash
38-
npm i --save @lion/accordion
39-
```
73+
### Code
4074

41-
```js
42-
import { LionAccordion } from '@lion/accordion';
43-
// or
44-
import '@lion/accordion/define';
45-
```
75+
1. Install
76+
77+
```bash
78+
npm i --save @lion/accordion
79+
```
80+
81+
2. Use scoped registry
82+
83+
```js
84+
import { html, LitElement, ScopedElementsMixin } from '@lion/core';
85+
import { LionAccordion } from '@lion/accordion';
86+
87+
class MyComponent extends ScopedElementsMixin(LitElement) {
88+
static get scopedElements() {
89+
return { 'lion-accordion': LionAccordion };
90+
}
91+
render() {
92+
return html`
93+
<lion-accordion>
94+
<h3 slot="invoker">
95+
<button>Nutritional value</button>
96+
</h3>
97+
<p slot="content">
98+
Orange flesh is 87% water, 12% carbohydrates, 1% protein, and contains negligible fat
99+
(table). In a 100 gram reference amount, orange flesh provides 47 calories, and is a
100+
rich source of vitamin C, providing 64% of the Daily Value. No other micronutrients are
101+
present in significant amounts (table).
102+
</p>
103+
</lion-accordion>
104+
`;
105+
}
106+
}
107+
```
46108

47-
## Rationale
109+
3. Use html
48110

49-
### Contents are not focusable
111+
```html
112+
<script type="module">
113+
import '@lion/accordion/define';
114+
</script>
50115

51-
Focusable elements should be interactive. Contents themselves do not offer any interactivity.
52-
If there is a button or a form inside the tab panel then these elements get focused directly.
116+
<lion-accordion>
117+
<h3 slot="invoker">
118+
<button>Nutritional value</button>
119+
</h3>
120+
<p slot="content">
121+
Orange flesh is 87% water, 12% carbohydrates, 1% protein, and contains negligible fat
122+
(table). In a 100 gram reference amount, orange flesh provides 47 calories, and is a rich
123+
source of vitamin C, providing 64% of the Daily Value. No other micronutrients are present in
124+
significant amounts (table).
125+
</p>
126+
</lion-accordion>
127+
```

0 commit comments

Comments
 (0)