Skip to content

Commit 6654b10

Browse files
docs(content): add component playgrounds (#2622)
1 parent 8dc8ad3 commit 6654b10

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+1800
-162
lines changed

docs/api/content.md

Lines changed: 60 additions & 162 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,6 @@
11
---
22
title: "ion-content"
3-
hide_table_of_contents: true
4-
demoUrl: "/docs/demos/api/content/index.html"
5-
demoSourceUrl: "https://github.com/ionic-team/ionic-docs/tree/main/static/demos/api/content/index.html"
63
---
7-
import Tabs from '@theme/Tabs';
8-
import TabItem from '@theme/TabItem';
9-
import TOCInline from '@theme/TOCInline';
10-
114
import Props from '@site/static/auto-generated/content/props.md';
125
import Events from '@site/static/auto-generated/content/events.md';
136
import Methods from '@site/static/auto-generated/content/methods.md';
@@ -24,14 +17,6 @@ import EncapsulationPill from '@components/page/api/EncapsulationPill';
2417

2518
<EncapsulationPill type="shadow" />
2619

27-
<h2 className="table-of-contents__title">Contents</h2>
28-
29-
<TOCInline
30-
toc={toc}
31-
maxHeadingLevel={2}
32-
/>
33-
34-
3520

3621
The content component provides an easy to use content area with some useful methods
3722
to control the scrollable area. There should only be one content in a single
@@ -40,204 +25,117 @@ view.
4025
Content, along with many other Ionic components, can be customized to modify its padding, margin, and more using the global styles provided in the [CSS Utilities](/docs/layout/css-utilities) or by individually styling it using CSS and the available [CSS Custom Properties](#css-custom-properties).
4126

4227

43-
## Fixed Content
28+
## Basic Usage
4429

45-
In order to place elements outside of the scrollable area, `slot="fixed"` can be added to the element. This will absolutely position the element placing it in the top left. In order to place the element in a different position, style it using [top, right, bottom, and left](https://developer.mozilla.org/en-US/docs/Web/CSS/position).
30+
import Basic from '@site/static/usage/content/basic/index.md';
4631

47-
## Interfaces
32+
<Basic />
4833

49-
### ScrollBaseDetail
5034

51-
```typescript
52-
interface ScrollBaseDetail {
53-
isScrolling: boolean;
54-
}
55-
```
35+
## Header & Footer
5636

57-
### ScrollDetail
37+
Content can be the only top-level component in a page, or it can be used alongside a [header](./header), [footer](./footer), or both. When used with a header or footer, it will adjust its size to fill the remaining height.
5838

59-
```typescript
60-
interface ScrollDetail extends GestureDetail, ScrollBaseDetail {
61-
scrollTop: number;
62-
scrollLeft: number;
63-
}
64-
```
65-
66-
### ScrollBaseCustomEvent
39+
import HeaderFooter from '@site/static/usage/content/header-footer/index.md';
6740

68-
While not required, this interface can be used in place of the `CustomEvent` interface for stronger typing on the `ionScrollStart` and `ionScrollEnd` events.
69-
70-
```typescript
71-
interface ScrollBaseCustomEvent extends CustomEvent {
72-
detail: ScrollBaseDetail;
73-
target: HTMLIonContentElement;
74-
}
75-
```
76-
77-
### ScrollCustomEvent
78-
79-
While not required, this interface can be used in place of the `CustomEvent` interface for stronger typing on the `ionScroll` event.
80-
81-
```typescript
82-
interface ScrollCustomEvent extends ScrollBaseCustomEvent {
83-
detail: ScrollDetail;
84-
}
85-
```
41+
<HeaderFooter />
8642

8743

44+
## Fullscreen Content
8845

46+
By default, content fills the space between a [header](./header) and [footer](./footer) but does not go behind them. In certain cases, it may be desired to have the content scroll behind the header and footer, such as when the `translucent` property is set on either of them, or `opacity` is set on the toolbar. This can be achieved by setting the `fullscreen` property on the content to `true`.
8947

90-
## Usage
48+
import Fullscreen from '@site/static/usage/content/fullscreen/index.md';
9149

92-
<Tabs groupId="framework" defaultValue="angular" values={[{ value: 'angular', label: 'Angular' }, { value: 'javascript', label: 'Javascript' }, { value: 'react', label: 'React' }, { value: 'stencil', label: 'Stencil' }, { value: 'vue', label: 'Vue' }]}>
50+
<Fullscreen />
9351

94-
<TabItem value="angular">
9552

96-
```html
97-
<ion-content
98-
[scrollEvents]="true"
99-
(ionScrollStart)="logScrollStart()"
100-
(ionScroll)="logScrolling($event)"
101-
(ionScrollEnd)="logScrollEnd()">
102-
<h1>Main Content</h1>
53+
## Fixed Content
10354

104-
<div slot="fixed">
105-
<h1>Fixed Content</h1>
106-
</div>
107-
</ion-content>
108-
```
55+
To place elements outside of the scrollable area, assign them to the `fixed` slot. Doing so will [absolutely position](https://developer.mozilla.org/en-US/docs/Web/CSS/position#absolute_positioning) the element to the top left of the content. In order to change the position of the element, it can be styled using the [top, right, bottom, and left](https://developer.mozilla.org/en-US/docs/Web/CSS/position) CSS properties.
10956

57+
import Fixed from '@site/static/usage/content/fixed/index.md';
11058

59+
<Fixed />
11160

112-
</TabItem>
61+
## Scroll Methods
11362

63+
Content provides [methods](#methods) that can be called to scroll the content to the bottom, top, or to a specific point. They can be passed a `duration` in order to smoothly transition instead of instantly changing the position.
11464

115-
<TabItem value="javascript">
65+
import ScrollMethods from '@site/static/usage/content/scroll-methods/index.md';
11666

117-
```html
118-
<ion-content>
119-
<h1>Main Content</h1>
67+
<ScrollMethods />
12068

121-
<div slot="fixed">
122-
<h1>Fixed Content</h1>
123-
</div>
124-
</ion-content>
125-
```
69+
## Scroll Events
12670

127-
```javascript
128-
var content = document.querySelector('ion-content');
129-
content.scrollEvents = true;
130-
content.addEventListener('ionScrollStart', () => console.log('scroll start'));
131-
content.addEventListener('ionScroll', (ev) => console.log('scroll', ev.detail));
132-
content.addEventListener('ionScrollEnd', () => console.log('scroll end'));
133-
```
71+
Scroll events are disabled by default for content due to performance. However, they can be enabled by setting `scrollEvents` to `true`. This is necessary before listening to any of the scroll [events](#events).
13472

73+
import ScrollEvents from '@site/static/usage/content/scroll-events/index.md';
13574

136-
</TabItem>
75+
<ScrollEvents />
13776

13877

139-
<TabItem value="react">
78+
## Theming
14079

141-
```tsx
142-
import React from 'react';
143-
import { IonContent } from '@ionic/react';
80+
### Colors
14481

145-
const ContentExample: React.FC = () => (
146-
<IonContent
147-
scrollEvents={true}
148-
onIonScrollStart={() => {}}
149-
onIonScroll={() => {}}
150-
onIonScrollEnd={() => {}}>
151-
<h1>Main Content</h1>
82+
import Colors from '@site/static/usage/content/theming/colors/index.md';
15283

153-
<div slot="fixed">
154-
<h1>Fixed Content</h1>
155-
</div>
156-
</IonContent>
157-
);
158-
```
84+
<Colors />
15985

86+
### CSS Shadow Parts
16087

161-
</TabItem>
88+
import CSSParts from '@site/static/usage/content/theming/css-shadow-parts/index.md';
16289

90+
<CSSParts />
16391

164-
<TabItem value="stencil">
92+
### CSS Custom Properties
16593

166-
```tsx
167-
import { Component, h } from '@stencil/core';
94+
import CSSProps from '@site/static/usage/content/theming/css-properties/index.md';
16895

169-
@Component({
170-
tag: 'content-example',
171-
styleUrl: 'content-example.css'
172-
})
173-
export class ContentExample {
174-
logScrollStart() {
175-
console.log('Scroll start');
176-
}
96+
<CSSProps />
17797

178-
logScrolling(ev) {
179-
console.log('Scrolling', ev);
180-
}
18198

182-
logScrollEnd() {
183-
console.log('Scroll end');
184-
}
99+
## Interfaces
185100

186-
render() {
187-
return [
188-
<ion-content
189-
scrollEvents={true}
190-
onIonScrollStart={() => this.logScrollStart()}
191-
onIonScroll={(ev) => this.logScrolling(ev)}
192-
onIonScrollEnd={() => this.logScrollEnd()}>
193-
<h1>Main Content</h1>
101+
### ScrollBaseDetail
194102

195-
<div slot="fixed">
196-
<h1>Fixed Content</h1>
197-
</div>
198-
</ion-content>
199-
];
200-
}
103+
```typescript
104+
interface ScrollBaseDetail {
105+
isScrolling: boolean;
201106
}
202107
```
203108

109+
### ScrollDetail
204110

205-
</TabItem>
206-
207-
208-
<TabItem value="vue">
209-
210-
```html
211-
<template>
212-
<ion-content
213-
:scroll-events="true"
214-
@ionScrollStart="logScrollStart()"
215-
@ionScroll="logScrolling($event)"
216-
@ionScrollEnd="logScrollEnd()">
217-
<h1>Main Content</h1>
218-
219-
<div slot="fixed">
220-
<h1>Fixed Content</h1>
221-
</div>
222-
</ion-content>
223-
</template>
111+
```typescript
112+
interface ScrollDetail extends GestureDetail, ScrollBaseDetail {
113+
scrollTop: number;
114+
scrollLeft: number;
115+
}
116+
```
224117

225-
<script>
226-
import { IonContent } from '@ionic/vue';
227-
import { defineComponent } from 'vue';
118+
### ScrollBaseCustomEvent
228119

229-
export default defineComponent({
230-
components: { IonContent }
231-
});
232-
</script>
120+
While not required, this interface can be used in place of the `CustomEvent` interface for stronger typing on the `ionScrollStart` and `ionScrollEnd` events.
233121

122+
```typescript
123+
interface ScrollBaseCustomEvent extends CustomEvent {
124+
detail: ScrollBaseDetail;
125+
target: HTMLIonContentElement;
126+
}
234127
```
235128

129+
### ScrollCustomEvent
236130

131+
While not required, this interface can be used in place of the `CustomEvent` interface for stronger typing on the `ionScroll` event.
237132

238-
</TabItem>
133+
```typescript
134+
interface ScrollCustomEvent extends ScrollBaseCustomEvent {
135+
detail: ScrollDetail;
136+
}
137+
```
239138

240-
</Tabs>
241139

242140
## Properties
243141
<Props />
@@ -255,4 +153,4 @@ export default defineComponent({
255153
<CustomProps />
256154

257155
## Slots
258-
<Slots />
156+
<Slots />

static/usage/content/basic/angular.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
```html
2+
<ion-content class="ion-padding">
3+
<h1>Heading 1</h1>
4+
<h2>Heading 2</h2>
5+
<h3>Heading 3</h3>
6+
<h4>Heading 4</h4>
7+
<h5>Heading 5</h5>
8+
<h6>Heading 6</h6>
9+
10+
<p>Here's a small text description for the content. Nothing more, nothing less.</p>
11+
</ion-content>
12+
```

static/usage/content/basic/demo.html

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
4+
<head>
5+
<meta charset="UTF-8" />
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
7+
<title>Content</title>
8+
<link rel="stylesheet" href="../../common.css" />
9+
<script src="../../common.js"></script>
10+
<script type="module" src="https://cdn.jsdelivr.net/npm/@ionic/core@6/dist/ionic/ionic.esm.js"></script>
11+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@ionic/core@6/css/ionic.bundle.css" />
12+
</head>
13+
14+
<body>
15+
<ion-app>
16+
<ion-content class="ion-padding">
17+
<h1>Heading 1</h1>
18+
<h2>Heading 2</h2>
19+
<h3>Heading 3</h3>
20+
<h4>Heading 4</h4>
21+
<h5>Heading 5</h5>
22+
<h6>Heading 6</h6>
23+
24+
<p>Here's a small text description for the content. Nothing more, nothing less.</p>
25+
</ion-content>
26+
</ion-app>
27+
</body>
28+
29+
</html>

static/usage/content/basic/index.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import Playground from '@site/src/components/global/Playground';
2+
3+
import javascript from './javascript.md';
4+
import react from './react.md';
5+
import vue from './vue.md';
6+
import angular from './angular.md';
7+
8+
<Playground
9+
code={{ javascript, react, vue, angular }}
10+
src="usage/content/basic/demo.html"
11+
includeIonContent={false}
12+
devicePreview={true}
13+
/>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
```html
2+
<ion-content class="ion-padding">
3+
<h1>Heading 1</h1>
4+
<h2>Heading 2</h2>
5+
<h3>Heading 3</h3>
6+
<h4>Heading 4</h4>
7+
<h5>Heading 5</h5>
8+
<h6>Heading 6</h6>
9+
10+
<p>Here's a small text description for the content. Nothing more, nothing less.</p>
11+
</ion-content>
12+
```

static/usage/content/basic/react.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
```tsx
2+
import React from 'react';
3+
import { IonContent } from '@ionic/react';
4+
5+
function Example() {
6+
return (
7+
<IonContent className="ion-padding">
8+
<h1>Heading 1</h1>
9+
<h2>Heading 2</h2>
10+
<h3>Heading 3</h3>
11+
<h4>Heading 4</h4>
12+
<h5>Heading 5</h5>
13+
<h6>Heading 6</h6>
14+
15+
<p>Here's a small text description for the content. Nothing more, nothing less.</p>
16+
</IonContent>
17+
);
18+
}
19+
export default Example;
20+
```

0 commit comments

Comments
 (0)