Skip to content

docs(config): add code snippets of how to access the mode per framework #4147

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

Open
wants to merge 20 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
6c433ba
docs(config): added given code-snippets to config file
joesphchang Jun 11, 2025
1c5ac9c
docs(config): fixed spelling error
joesphchang Jun 12, 2025
19c8675
docs(config): added new folder to v8 for ionic-mode
joesphchang Jun 17, 2025
ce5e829
docs(config): added dummy code for playground to work
joesphchang Jun 17, 2025
06ca426
docs(config): Added ionic-mode to config tab
joesphchang Jun 18, 2025
b9f6eab
docs(config): added iconic-mode to v7 config docs
joesphchang Jun 18, 2025
3a10711
docs(config): added ionic-mode docs to Reading the Config"
joesphchang Jun 6, 2025
2d4b31d
chore(deps): update ionic to v8.6.1 (#4148)
renovate[bot] Jun 12, 2025
3d89f76
docs(accordion): update demos to always set accordion to 300px wide (…
brandyscarney Jun 13, 2025
2decf9e
chore(deps): update dependency @vitejs/plugin-react to v4.5.2 (#4152)
renovate[bot] Jun 13, 2025
aab3038
chore(deps): update dependency @types/node to v22.15.31 (#4151)
renovate[bot] Jun 13, 2025
bd246a2
chore(deps): update dependency @types/react to v19.1.7 (#4150)
renovate[bot] Jun 13, 2025
7fed84d
chore(deps): update dependency web-vitals to v5.0.3 (#4155)
renovate[bot] Jun 16, 2025
096bd2f
chore(deps): update dependency @types/react to v19.1.8 (#4154)
renovate[bot] Jun 16, 2025
f28d5bd
docs(docusaurus): add support for diff language syntax highlighting
soundproofboot Jun 16, 2025
a205534
docs(docusaurus): add .token.deleted css selector back in case used e…
soundproofboot Jun 16, 2025
ce4c3e4
docs(docusaurus): remove diff style section, move diff selectors to e…
soundproofboot Jun 17, 2025
67c3ac9
docs(config): fixed spellcheck
joesphchang Jun 18, 2025
7b3b3b9
docs(config): fixed spell check
joesphchang Jun 18, 2025
8476a80
Merge branch 'main' into ionic-mode-config
joesphchang Jun 24, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions docs/developing/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@ import PerPlatformOverridesExample from '@site/docs/developing/config/per-platfo

<PerPlatformOverridesExample />

## Accessing the Current Mode Programmatically
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
## Accessing the Current Mode Programmatically
## Accessing the Mode

Let's aim for short titles.


In some cases, you may need to access the current Ionic mode programmatically within your application logic. This can be useful for applying conditional behavior, fetching specific assets, or performing other actions based on the active styling mode.

import IonicMode from '@site/static/usage/v8/config/mode/index.md';

<IonicMode />

## Reading the Config (Angular)

Ionic Angular provides a `Config` provider for accessing the Ionic Config.
Expand Down
2 changes: 1 addition & 1 deletion docusaurus.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ module.exports = {
prism: {
theme: { plain: {}, styles: [] },
// https://github.com/FormidableLabs/prism-react-renderer/blob/e6d323332b0363a633407fabab47b608088e3a4d/packages/generate-prism-languages/index.ts#L9-L25
additionalLanguages: ['shell-session', 'http'],
additionalLanguages: ['shell-session', 'http', 'diff'],
},
algolia: {
appId: 'O9QSL985BS',
Expand Down
6 changes: 4 additions & 2 deletions src/styles/components/_code.scss
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,8 @@ pre[class*='language-'] {
.token.attr-value,
.language-css .token.string,
.style .token.string,
.token.variable {
.token.variable,
.language-diff .token.inserted {
color: #42b983;
}

Expand All @@ -159,7 +160,8 @@ pre[class*='language-'] {

.token.regex,
.token.keyword,
.token.important {
.token.important,
.language-diff .token.deleted {
color: #f55073;
}

Expand Down
10 changes: 10 additions & 0 deletions static/usage/v7/config/mode/angular/example_component_html.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
```html
<ion-app>
<ion-content>
<div class="container">
<ion-button (click)="showMode()">Show Current Mode</ion-button>
<div class="mode-value">{{ modeValue }}</div>
</div>
</ion-content>
</ion-app>
```
11 changes: 11 additions & 0 deletions static/usage/v7/config/mode/angular/example_component_ts.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
```ts
import { Config } from '@ionic/angular';

modeValue = '';

constructor(public config: Config) { }

showMode() {
this.modeValue = this.config.get('mode');
}
```
49 changes: 49 additions & 0 deletions static/usage/v7/config/mode/demo.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Ionic Config Mode Example</title>
<link rel="stylesheet" href="../../common.css" />
<script src="../../common.js"></script>
<script type="module" src="https://cdn.jsdelivr.net/npm/@ionic/core@8/dist/ionic/ionic.esm.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@ionic/core@8/css/ionic.bundle.css" />
<style>
.container {
/* display: block; */
padding: 16px;
margin: auto;
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
}
.mode-value {
margin-top: 16px;
font-weight: bold;
}
</style>
</head>

<body>
<ion-app>
<ion-content>
<div class="container">
<ion-button id="showModeBtn">Show Current Mode</ion-button>
<div class="mode-value" id="modeValue"></div>
</div>
</ion-content>
</ion-app>
<script type="module">
document.getElementById('showModeBtn').addEventListener('click', () => {
let mode;
if (window.Ionic && window.Ionic.config && window.Ionic.config.get) {
mode = window.Ionic.config.get('mode');
} else {
mode = document.documentElement.getAttribute('mode') || 'md';
}
document.getElementById('modeValue').textContent = `Current mode: ${mode}`;
});
</script>
</body>
</html>
24 changes: 24 additions & 0 deletions static/usage/v7/config/mode/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import Playground from '@site/src/components/global/Playground';

import javascript from './javascript.md';
import react from './react.md';
import vue from './vue.md';

import angular_example_component_html from './angular/example_component_html.md';
import angular_example_component_ts from './angular/example_component_ts.md';

<Playground
version="7"
code={{
javascript,
react,
vue,
angular: {
files: {
'src/app/example.component.html': angular_example_component_html,
'src/app/example.component.ts': angular_example_component_ts,
},
},
}}
src="usage/v7/config/mode/demo.html"
/>
15 changes: 15 additions & 0 deletions static/usage/v7/config/mode/javascript.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
```html
<button id="showModeBtn">Show Current Mode</button>
<div id="modeValue"></div>
<script>
document.getElementById('showModeBtn').addEventListener('click', () => {
let mode;
if (window.Ionic && window.Ionic.config && window.Ionic.config.get) {
mode = window.Ionic.config.get('mode');
} else {
mode = document.documentElement.getAttribute('mode') || 'md';
}
document.getElementById('modeValue').textContent = `Current mode: ${mode}`;
});
</script>
```
21 changes: 21 additions & 0 deletions static/usage/v7/config/mode/react.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
```tsx
import React, { useState } from 'react';
import { IonButton } from '@ionic/react';
import { getMode } from '@ionic/core';

function Example() {
const [modeValue, setModeValue] = useState('');

const showMode = () => {
setModeValue(getMode());
};

return (
<>
<IonButton onClick={showMode}>Show Current Mode</IonButton>
<div className="mode-value">{modeValue && `Current mode: ${modeValue}`}</div>
</>
);
}
export default Example;
```
17 changes: 17 additions & 0 deletions static/usage/v7/config/mode/vue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
```html
<template>
<ion-button @click="showMode">Show Current Mode</ion-button>
<div class="mode-value" v-if="modeValue">Current mode: {{ modeValue }}</div>
</template>

<script setup>
import { ref } from 'vue';
import { getMode } from '@ionic/core';
const modeValue = ref('');
function showMode() {
modeValue.value = getMode();
}
</script>
```
10 changes: 10 additions & 0 deletions static/usage/v8/config/mode/angular/example_component_html.md
Copy link
Contributor

Choose a reason for hiding this comment

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

The Stackblitz environment does not work. This can be seen by selecting "Angular" under the tabs and then the StackBlitz logo. The environment needs to be fixed.

Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
```html
<ion-app>
<ion-content>
<div class="container">
<ion-button (click)="showMode()">Show Current Mode</ion-button>
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
<ion-button (click)="showMode()">Show Current Mode</ion-button>
<ion-button (click)="showMode()">Show Mode</ion-button>

<div class="mode-value">{{ modeValue }}</div>
Copy link
Contributor

Choose a reason for hiding this comment

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

Update this to be consistent with the text from the demo. This one is missing Current mode: . All the frameworks need to match the demo for consistency.

</div>
</ion-content>
</ion-app>
```
11 changes: 11 additions & 0 deletions static/usage/v8/config/mode/angular/example_component_ts.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
```ts
import { Config } from '@ionic/angular';

modeValue = '';

constructor(public config: Config) { }

showMode() {
this.modeValue = this.config.get('mode');
}
```
49 changes: 49 additions & 0 deletions static/usage/v8/config/mode/demo.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Ionic Config Mode Example</title>
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
<title>Ionic Config Mode Example</title>
<title>Ionic Config Mode</title>

<link rel="stylesheet" href="../../common.css" />
<script src="../../common.js"></script>
<script type="module" src="https://cdn.jsdelivr.net/npm/@ionic/core@8/dist/ionic/ionic.esm.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@ionic/core@8/css/ionic.bundle.css" />
<style>
.container {
/* display: block; */
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove any unused code.

Suggested change
/* display: block; */

padding: 16px;
margin: auto;
display: flex;
justify-content: center;
align-items: center;
Comment on lines +14 to +18
Copy link
Contributor

Choose a reason for hiding this comment

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

These are not needed since they are being set through common.css.

Suggested change
padding: 16px;
margin: auto;
display: flex;
justify-content: center;
align-items: center;

flex-direction: column;
}
.mode-value {
margin-top: 16px;
font-weight: bold;
}
</style>
</head>

<body>
<ion-app>
<ion-content>
<div class="container">
<ion-button id="showModeBtn">Show Current Mode</ion-button>
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's change the button to be more visual based. For example, let's set the color and fill based on the mode and the button text should be the mode.

<IonButton color={mode === 'ios' ? 'secondary' : 'tertiary'} fill={mode === 'ios' ? 'outline' : 'solid'}>
   {mode}
</IonButton>

The example is in React, just update the code to be appropriate per framework.

<div class="mode-value" id="modeValue"></div>
</div>
</ion-content>
</ion-app>
<script type="module">
document.getElementById('showModeBtn').addEventListener('click', () => {
let mode;
if (window.Ionic && window.Ionic.config && window.Ionic.config.get) {
mode = window.Ionic.config.get('mode');
} else {
mode = document.documentElement.getAttribute('mode') || 'md';
}
document.getElementById('modeValue').textContent = `Current mode: ${mode}`;
});
</script>
</body>
</html>
24 changes: 24 additions & 0 deletions static/usage/v8/config/mode/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import Playground from '@site/src/components/global/Playground';

import javascript from './javascript.md';
import react from './react.md';
import vue from './vue.md';

import angular_example_component_html from './angular/example_component_html.md';
import angular_example_component_ts from './angular/example_component_ts.md';

<Playground
version="8"
code={{
javascript,
react,
vue,
angular: {
files: {
'src/app/example.component.html': angular_example_component_html,
'src/app/example.component.ts': angular_example_component_ts,
},
},
}}
src="usage/v8/config/mode/demo.html"
/>
15 changes: 15 additions & 0 deletions static/usage/v8/config/mode/javascript.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
```html
<button id="showModeBtn">Show Current Mode</button>
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be using an ion-button since that's what the demo is using.

<div id="modeValue"></div>
<script>
document.getElementById('showModeBtn').addEventListener('click', () => {
let mode;
if (window.Ionic && window.Ionic.config && window.Ionic.config.get) {
mode = window.Ionic.config.get('mode');
} else {
mode = document.documentElement.getAttribute('mode') || 'md';
}
document.getElementById('modeValue').textContent = `Current mode: ${mode}`;
});
</script>
```
21 changes: 21 additions & 0 deletions static/usage/v8/config/mode/react.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
```tsx
import React, { useState } from 'react';
import { IonButton } from '@ionic/react';
import { getMode } from '@ionic/core';

function Example() {
const [modeValue, setModeValue] = useState('');

const showMode = () => {
setModeValue(getMode());
};

return (
<>
<IonButton onClick={showMode}>Show Current Mode</IonButton>
<div className="mode-value">{modeValue && `Current mode: ${modeValue}`}</div>
Copy link
Contributor

Choose a reason for hiding this comment

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

This should have the same styling as the demo. Same reason, for consistency.

</>
);
}
export default Example;
```
17 changes: 17 additions & 0 deletions static/usage/v8/config/mode/vue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
```html
<template>
<ion-button @click="showMode">Show Current Mode</ion-button>
<div class="mode-value" v-if="modeValue">Current mode: {{ modeValue }}</div>
Copy link
Contributor

Choose a reason for hiding this comment

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

This should have the same styling as the demo. Same reason, for consistency.

</template>

<script setup>
import { ref } from 'vue';
import { getMode } from '@ionic/core';
const modeValue = ref('');
function showMode() {
modeValue.value = getMode();
}
</script>
```
8 changes: 8 additions & 0 deletions versioned_docs/version-v7/developing/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@ import PerPlatformOverridesExample from '@site/docs/developing/config/per-platfo

<PerPlatformOverridesExample />

## Accessing the Current Mode Programmatically

In some cases, you may need to access the current Ionic mode programmatically within your application logic. This can be useful for applying conditional behavior, fetching specific assets, or performing other actions based on the active styling mode.

import IonicMode from '@site/static/usage/v8/config/mode/index.md';

<IonicMode />

## Reading the Config (Angular)

Ionic Angular provides a `Config` provider for accessing the Ionic Config.
Expand Down