Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(content): add playground for safe area usage #3102

Merged
merged 9 commits into from
Sep 1, 2023
23 changes: 23 additions & 0 deletions docs/api/content.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,29 @@ import CSSProps from '@site/static/usage/v7/content/theming/css-properties/index

<CSSProps />

### Safe Area Padding

The content component will not automatically apply padding to any of its sides to account for the [safe area](/docs/theming/advanced#safe-area-padding). This is because the content component is often used in conjunction with other components that apply their own padding, such as [headers](./header) and [footers](./footer). However, if the content component is being used on its own, it may be desired to apply padding to the safe area. This can be done through CSS by using the `--ion-safe-area-(dir)` variables described in [Application Variables](../theming/advanced.md#application-variables).

The most common use case for this is to apply padding to the top of the content to account for the status bar. This can be done by setting the `padding-top` property to the value of the `--ion-safe-area-top` variable.

```css
ion-content::part(scroll) {
padding-top: var(--ion-safe-area-top, 0);
}
```

Another common use case is to apply padding to the left side of the content to account for the notch when the device is in landscape mode and the notch is on the left side. This can be done by setting the `padding-left` property to the value of the `--ion-safe-area-left` variable.

```css
ion-content::part(scroll) {
padding-left: var(--ion-safe-area-left, 0);
}
```
Comment on lines +102 to +116
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we move this above the Playground? Anything under might be ignored since people stop at the demo and play with it.


import SafeArea from '@site/static/usage/v7/content/theming/safe-area/index.md';

<SafeArea />

## Interfaces

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
```css
ion-content::part(scroll) {
padding-top: var(--ion-safe-area-top, 0);
padding-bottom: var(--ion-safe-area-bottom, 0);
padding-left: var(--ion-safe-area-left, 0);
padding-right: var(--ion-safe-area-right, 0);
}
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
```html
<ion-content>
<span>Here's a small text description for the content. Nothing more, nothing less.</span>
</ion-content>
```
12 changes: 12 additions & 0 deletions static/usage/v7/content/theming/safe-area/angular/global_css.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
```css
:root {
/**
* Setting the variables for DEMO purposes only.
* Values will be set automatically when building an iOS or Android app.
*/
--ion-safe-area-top: 20px;
--ion-safe-area-bottom: 20px;
--ion-safe-area-left: 20px;
--ion-safe-area-right: 20px;
}
```
36 changes: 36 additions & 0 deletions static/usage/v7/content/theming/safe-area/demo.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Content</title>
<link rel="stylesheet" href="../../../../common.css" />
<script src="../../../../common.js"></script>
<script type="module" src="https://cdn.jsdelivr.net/npm/@ionic/core@7/dist/ionic/ionic.esm.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@ionic/core@7/css/ionic.bundle.css" />

<style>
ion-content {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
ion-content {
:root {

for consistency

--ion-safe-area-top: 40px;
--ion-safe-area-bottom: 40px;
--ion-safe-area-left: 20px;
--ion-safe-area-right: 20px;
}

ion-content::part(scroll) {
padding-top: var(--ion-safe-area-top, 0);
padding-bottom: var(--ion-safe-area-bottom, 0);
padding-left: var(--ion-safe-area-left, 0);
padding-right: var(--ion-safe-area-right, 0);
}
</style>
</head>

<body>
<ion-app>
<ion-content>
<span>Here's a small text description for the content. Nothing more, nothing less.</span>
</ion-content>
</ion-app>
</body>
</html>
36 changes: 36 additions & 0 deletions static/usage/v7/content/theming/safe-area/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import Playground from '@site/src/components/global/Playground';

import javascript from './javascript.md';

import react_main_tsx from './react/main_tsx.md';
import react_main_css from './react/main_css.md';

import vue from './vue.md';

import angular_example_component_html from './angular/example_component_html.md';
import angular_example_component_css from './angular/example_component_css.md';
import angular_global_css from './angular/global_css.md';

<Playground
version="7"
code={{
javascript,
react: {
files: {
'src/main.tsx': react_main_tsx,
'src/main.css': react_main_css,
},
},
vue,
angular: {
files: {
'src/app/example.component.html': angular_example_component_html,
'src/app/example.component.css': angular_example_component_css,
'src/global.css': angular_global_css,
},
},
}}
src="usage/v7/content/theming/safe-area/demo.html"
devicePreview
Comment on lines +33 to +34
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this needs includeIonContent={false} so you don't end up with two ion-contents

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where should I be looking for the two ion-contents? I'm not seeing them.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nvm, I found it! I've learned something new about the Playground. Thank you!

includeIonContent={false}
/>
25 changes: 25 additions & 0 deletions static/usage/v7/content/theming/safe-area/javascript.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
```html
<ion-content>
<span>Here's a small text description for the content. Nothing more, nothing less.</span>
</ion-content>

<style>
:root {
/**
* Setting the variables for DEMO purposes only.
* Values will be set automatically when building an iOS or Android app.
*/
--ion-safe-area-top: 20px;
--ion-safe-area-bottom: 20px;
--ion-safe-area-left: 20px;
--ion-safe-area-right: 20px;
}

ion-content::part(scroll) {
padding-top: var(--ion-safe-area-top, 0);
padding-bottom: var(--ion-safe-area-bottom, 0);
padding-left: var(--ion-safe-area-left, 0);
padding-right: var(--ion-safe-area-right, 0);
}
</style>
```
19 changes: 19 additions & 0 deletions static/usage/v7/content/theming/safe-area/react/main_css.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
```css
:root {
/**
* Setting the variables for DEMO purposes only.
* Values will be set automatically when building an iOS or Android app.
*/
--ion-safe-area-top: 20px;
--ion-safe-area-bottom: 20px;
--ion-safe-area-left: 20px;
--ion-safe-area-right: 20px;
}

ion-content::part(scroll) {
padding-top: var(--ion-safe-area-top, 0);
padding-bottom: var(--ion-safe-area-bottom, 0);
padding-left: var(--ion-safe-area-left, 0);
padding-right: var(--ion-safe-area-right, 0);
}
```
15 changes: 15 additions & 0 deletions static/usage/v7/content/theming/safe-area/react/main_tsx.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
```tsx
import React from 'react';
import { IonContent } from '@ionic/react';

import './main.css';

function Example() {
return (
<IonContent>
<span>Here's a small text description for the content. Nothing more, nothing less.</span>
</IonContent>
);
}
export default Example;
```
47 changes: 47 additions & 0 deletions static/usage/v7/content/theming/safe-area/vue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
```html
<template>
<ion-content>
<span>Here's a small text description for the content. Nothing more, nothing less.</span>
</ion-content>
</template>

<script lang="ts">
import { IonContent } from '@ionic/vue';
import { defineComponent } from 'vue';

export default defineComponent({
components: {
IonContent,
},
});
</script>

<style>
:root {
/**
* Setting the variables for DEMO purposes only.
* Values will be set automatically when building an iOS or Android app.
*/
--ion-safe-area-top: 20px;
--ion-safe-area-bottom: 20px;
--ion-safe-area-left: 20px;
--ion-safe-area-right: 20px;
}

ion-content::part(scroll) {
padding-top: var(--ion-safe-area-top, 0);
padding-bottom: var(--ion-safe-area-bottom, 0);
padding-left: var(--ion-safe-area-left, 0);
padding-right: var(--ion-safe-area-right, 0);
}
</style>

<style scoped>
ion-content::part(scroll) {
padding-top: var(--ion-safe-area-top, 0);
padding-bottom: var(--ion-safe-area-bottom, 0);
padding-left: var(--ion-safe-area-left, 0);
padding-right: var(--ion-safe-area-right, 0);
}
</style>
mapsandapps marked this conversation as resolved.
Show resolved Hide resolved
```
Loading