Skip to content

Commit f61213d

Browse files
authored
feat(segment): add playground & docs for segment view (#3875)
* feat(segment): add playground & docs for segment view * fix(segment-view): api import version * fix(segment-content): usage & common API sections * Force CI run
1 parent f24a2bd commit f61213d

File tree

12 files changed

+371
-1
lines changed

12 files changed

+371
-1
lines changed

docs/api/segment-content.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
---
2+
title: "ion-segment-content"
3+
---
4+
5+
import Props from '@ionic-internal/component-api/v8/segment-content/props.md';
6+
import Events from '@ionic-internal/component-api/v8/segment-content/events.md';
7+
import Methods from '@ionic-internal/component-api/v8/segment-content/methods.md';
8+
import Parts from '@ionic-internal/component-api/v8/segment-content/parts.md';
9+
import CustomProps from '@ionic-internal/component-api/v8/segment-content/custom-props.mdx';
10+
import Slots from '@ionic-internal/component-api/v8/segment-content/slots.md';
11+
12+
<head>
13+
<title>ion-segment-content: Display control element for swipeable segments</title>
14+
<meta name="description" content="ion-segment-contents are wrapper elements used to control the display of child elements when using swipeable segments." />
15+
</head>
16+
17+
import EncapsulationPill from '@components/page/api/EncapsulationPill';
18+
19+
<EncapsulationPill type="shadow" />
20+
21+
Segment content is a wrapper element used to control the display of child elements when using swipeable segments. Segment content elements are children of a single
22+
[segment view](./segment-view.md) instance that is linked to a [segment](./segment.md). See our [swipeable segments](./segment.md#swipeable-segments) documentation
23+
for more information on how to use segment contents.
24+
25+
## Usage
26+
27+
Each `ion-segment-content` needs a unique `id` attribute. This will be used to link the segment content to a segment button via the button's
28+
[contentId property](./segment-button.md#properties).
29+
30+
<!-- Reuse swipeable segments playground -->
31+
32+
import Swipeable from '@site/static/usage/v8/segment/swipeable/index.md';
33+
34+
<Swipeable />
35+
36+
## Properties
37+
<Props />
38+
39+
## Events
40+
<Events />
41+
42+
## Methods
43+
<Methods />
44+
45+
## CSS Shadow Parts
46+
<Parts />
47+
48+
## CSS Custom Properties
49+
<CustomProps />
50+
51+
## Slots
52+
<Slots />

docs/api/segment-view.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
---
2+
title: "ion-segment-view"
3+
---
4+
5+
import Props from '@ionic-internal/component-api/v8/segment-view/props.md';
6+
import Events from '@ionic-internal/component-api/v8/segment-view/events.md';
7+
import Methods from '@ionic-internal/component-api/v8/segment-view/methods.md';
8+
import Parts from '@ionic-internal/component-api/v8/segment-view/parts.md';
9+
import CustomProps from '@ionic-internal/component-api/v8/segment-view/custom-props.mdx';
10+
import Slots from '@ionic-internal/component-api/v8/segment-view/slots.md';
11+
12+
<head>
13+
<title>ion-segment-view: Controller element for swipeable segments</title>
14+
<meta name="description" content="ion-segment-views are wrapper elements that link a group of segment contents to a segment" />
15+
</head>
16+
17+
import EncapsulationPill from '@components/page/api/EncapsulationPill';
18+
19+
<EncapsulationPill type="shadow" />
20+
21+
Segment view is a wrapper element that links a group of [segment contents](./segment-content.md) to a [segment](./segment.md) when using swipeable segments.
22+
See our [swipeable segments](./segment.md#swipeable-segments) documentation for more information on how to use segment views.
23+
24+
## Properties
25+
<Props />
26+
27+
## Events
28+
<Events />
29+
30+
## Methods
31+
<Methods />
32+
33+
## CSS Shadow Parts
34+
<Parts />
35+
36+
## CSS Custom Properties
37+
<CustomProps />
38+
39+
## Slots
40+
<Slots />

docs/api/segment.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,22 @@ import Toolbar from '@site/static/usage/v8/toolbar/segments/index.md';
4949
<Toolbar />
5050

5151

52+
## Swipeable Segments
53+
54+
Each [segment button](./segment-button.md) can be associated with a [segment content](./segment-content.md) element that will be displayed
55+
when the segment is active. With this approach, each segment's content can be swiped or scrolled between and the segment will be updated
56+
to reflect the currently visible content.
57+
58+
:::warning
59+
If no initial `value` is assigned to the `ion-segment` when using swipeable segments, the segment will default to the value of the first segment button.
60+
61+
Segment buttons cannot be disabled when used with swipeable segments.
62+
:::
63+
64+
import Swipeable from '@site/static/usage/v8/segment/swipeable/index.md';
65+
66+
<Swipeable />
67+
5268
## Theming
5369

5470
### Colors

sidebars.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,7 @@ module.exports = {
450450
type: 'category',
451451
label: 'Segment',
452452
collapsed: false,
453-
items: ['api/segment', 'api/segment-button'],
453+
items: ['api/segment', 'api/segment-button', 'api/segment-content', 'api/segment-view'],
454454
},
455455
{
456456
type: 'category',
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
```css
2+
ion-segment-view {
3+
height: 150px;
4+
}
5+
6+
ion-segment-content {
7+
display: flex;
8+
align-items: center;
9+
justify-content: center;
10+
}
11+
ion-segment-content:nth-of-type(1) {
12+
background: lightpink;
13+
}
14+
ion-segment-content:nth-of-type(2) {
15+
background: lightblue;
16+
}
17+
ion-segment-content:nth-of-type(3) {
18+
background: lightgreen;
19+
}
20+
```
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
```html
2+
<ion-segment>
3+
<ion-segment-button value="first" content-id="first">
4+
<ion-label>First</ion-label>
5+
</ion-segment-button>
6+
<ion-segment-button value="second" content-id="second">
7+
<ion-label>Second</ion-label>
8+
</ion-segment-button>
9+
<ion-segment-button value="third" content-id="third">
10+
<ion-label>Third</ion-label>
11+
</ion-segment-button>
12+
</ion-segment>
13+
<ion-segment-view>
14+
<ion-segment-content id="first">First</ion-segment-content>
15+
<ion-segment-content id="second">Second</ion-segment-content>
16+
<ion-segment-content id="third">Third</ion-segment-content>
17+
</ion-segment-view>
18+
```
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
6+
<title>Segment - Swipeable</title>
7+
<link rel="stylesheet" href="../../common.css" />
8+
<script src="../../common.js"></script>
9+
<script type="module" src="https://cdn.jsdelivr.net/npm/@ionic/core@8/dist/ionic/ionic.esm.js"></script>
10+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@ionic/core@8/css/ionic.bundle.css" />
11+
12+
<style>
13+
ion-segment-view {
14+
height: 168px;
15+
}
16+
17+
ion-segment-content {
18+
display: flex;
19+
align-items: center;
20+
justify-content: center;
21+
}
22+
ion-segment-content:nth-of-type(1) {
23+
background: lightpink;
24+
}
25+
ion-segment-content:nth-of-type(2) {
26+
background: lightblue;
27+
}
28+
ion-segment-content:nth-of-type(3) {
29+
background: lightgreen;
30+
}
31+
</style>
32+
</head>
33+
34+
<body>
35+
<ion-app>
36+
<ion-content>
37+
<ion-segment>
38+
<ion-segment-button value="first" content-id="first">
39+
<ion-label>First</ion-label>
40+
</ion-segment-button>
41+
<ion-segment-button value="second" content-id="second">
42+
<ion-label>Second</ion-label>
43+
</ion-segment-button>
44+
<ion-segment-button value="third" content-id="third">
45+
<ion-label>Third</ion-label>
46+
</ion-segment-button>
47+
</ion-segment>
48+
<ion-segment-view>
49+
<ion-segment-content id="first">First</ion-segment-content>
50+
<ion-segment-content id="second">Second</ion-segment-content>
51+
<ion-segment-content id="third">Third</ion-segment-content>
52+
</ion-segment-view>
53+
</ion-content>
54+
</ion-app>
55+
</body>
56+
</html>
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import Playground from '@site/src/components/global/Playground';
2+
3+
import javascript from './javascript.md';
4+
import react_main_tsx from './react/react_tsx.md';
5+
import react_main_css from './react/react_css.md';
6+
import vue from './vue.md';
7+
import angular_html from './angular/angular_html.md';
8+
import angular_css from './angular/angular_css.md';
9+
10+
<Playground
11+
version="8"
12+
code={{
13+
javascript,
14+
react: {
15+
files: {
16+
'src/main.tsx': react_main_tsx,
17+
'src/main.css': react_main_css,
18+
},
19+
},
20+
vue,
21+
angular: {
22+
files: {
23+
'src/app/example.component.html': angular_html,
24+
'src/app/example.component.css': angular_css,
25+
},
26+
},
27+
}}
28+
src="usage/v8/segment/swipeable/demo.html"
29+
/>
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
```html
2+
<ion-segment>
3+
<ion-segment-button value="first" content-id="first">
4+
<ion-label>First</ion-label>
5+
</ion-segment-button>
6+
<ion-segment-button value="second" content-id="second">
7+
<ion-label>Second</ion-label>
8+
</ion-segment-button>
9+
<ion-segment-button value="third" content-id="third">
10+
<ion-label>Third</ion-label>
11+
</ion-segment-button>
12+
</ion-segment>
13+
<ion-segment-view>
14+
<ion-segment-content id="first">First</ion-segment-content>
15+
<ion-segment-content id="second">Second</ion-segment-content>
16+
<ion-segment-content id="third">Third</ion-segment-content>
17+
</ion-segment-view>
18+
19+
<style>
20+
ion-segment-view {
21+
height: 150px;
22+
}
23+
24+
ion-segment-content {
25+
display: flex;
26+
align-items: center;
27+
justify-content: center;
28+
}
29+
ion-segment-content:nth-of-type(1) {
30+
background: lightpink;
31+
}
32+
ion-segment-content:nth-of-type(2) {
33+
background: lightblue;
34+
}
35+
ion-segment-content:nth-of-type(3) {
36+
background: lightgreen;
37+
}
38+
</style>
39+
```
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
```css
2+
ion-segment-view {
3+
height: 150px;
4+
}
5+
6+
ion-segment-content {
7+
display: flex;
8+
align-items: center;
9+
justify-content: center;
10+
}
11+
ion-segment-content:nth-of-type(1) {
12+
background: lightpink;
13+
}
14+
ion-segment-content:nth-of-type(2) {
15+
background: lightblue;
16+
}
17+
ion-segment-content:nth-of-type(3) {
18+
background: lightgreen;
19+
}
20+
```
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
```tsx
2+
import React from 'react';
3+
import { IonLabel, IonSegment, IonSegmentButton, IonSegmentContent, IonSegmentView } from '@ionic/react';
4+
5+
import './main.css';
6+
7+
function Example() {
8+
return (
9+
<>
10+
<IonSegment value="first">
11+
<IonSegmentButton value="first" contentId="first">
12+
<IonLabel>First</IonLabel>
13+
</IonSegmentButton>
14+
<IonSegmentButton value="second" contentId="second">
15+
<IonLabel>Second</IonLabel>
16+
</IonSegmentButton>
17+
<IonSegmentButton value="third" contentId="third">
18+
<IonLabel>Third</IonLabel>
19+
</IonSegmentButton>
20+
</IonSegment>
21+
<IonSegmentView>
22+
<IonSegmentContent id="first">First</IonSegmentContent>
23+
<IonSegmentContent id="second">Second</IonSegmentContent>
24+
<IonSegmentContent id="third">Third</IonSegmentContent>
25+
</IonSegmentView>
26+
</>
27+
);
28+
}
29+
export default Example;
30+
```
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
```html
2+
<template>
3+
<ion-segment>
4+
<ion-segment-button value="first" content-id="first">
5+
<ion-label>First</ion-label>
6+
</ion-segment-button>
7+
<ion-segment-button value="second" content-id="second">
8+
<ion-label>Second</ion-label>
9+
</ion-segment-button>
10+
<ion-segment-button value="third" content-id="third">
11+
<ion-label>Third</ion-label>
12+
</ion-segment-button>
13+
</ion-segment>
14+
<ion-segment-view>
15+
<ion-segment-content id="first">First</ion-segment-content>
16+
<ion-segment-content id="second">Second</ion-segment-content>
17+
<ion-segment-content id="third">Third</ion-segment-content>
18+
</ion-segment-view>
19+
</template>
20+
21+
<style>
22+
ion-segment-view {
23+
height: 150px;
24+
}
25+
26+
ion-segment-content {
27+
display: flex;
28+
align-items: center;
29+
justify-content: center;
30+
}
31+
ion-segment-content:nth-of-type(1) {
32+
background: lightpink;
33+
}
34+
ion-segment-content:nth-of-type(2) {
35+
background: lightblue;
36+
}
37+
ion-segment-content:nth-of-type(3) {
38+
background: lightgreen;
39+
}
40+
</style>
41+
42+
<script lang="ts">
43+
import { IonLabel, IonSegment, IonSegmentButton, IonSegmentContent, IonSegmentView } from '@ionic/vue';
44+
import { defineComponent } from 'vue';
45+
46+
export default defineComponent({
47+
components: { IonLabel, IonSegment, IonSegmentButton, IonSegmentContent, IonSegmentView },
48+
});
49+
</script>
50+
```

0 commit comments

Comments
 (0)