-
Notifications
You must be signed in to change notification settings - Fork 3.2k
docs(config): add code snippets of how to access the mode per framework #4172
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
Merged
Merged
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
4342d92
docs(config): added the new files to usage-v8
joesphchang f3e8fb9
docs(config): v8 is up to date and working
joesphchang 7f22554
docs(config): added the ionic mode to config docs v7
joesphchang 3e93681
docs(config): fixed no newline at endfile
joesphchang 675dfbd
config(docs): made suggested changes to code-base and simplify the ex…
joesphchang d110c24
docs(config): ran npm run lint
joesphchang 10e159a
docs(config): update demo and js examples
brandyscarney File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
static/usage/v7/config/mode/angular/example_component_html.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
```html | ||
<ion-app> | ||
<ion-content> | ||
<div class="container"> | ||
<ion-button | ||
[color]="modeValue === 'ios' ? 'secondary' : 'tertiary'" | ||
[fill]="modeValue === 'ios' ? 'outline' : 'solid'" | ||
(click)="showMode()" | ||
> | ||
{{ modeValue }} | ||
</ion-button> | ||
<div class="mode-value" *ngIf="modeValue">Current mode: {{ modeValue }}</div> | ||
</div> | ||
</ion-content> | ||
</ion-app> | ||
<style> | ||
.container { | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
justify-content: center; | ||
} | ||
.mode-value { | ||
margin-top: 16px; | ||
font-weight: bold; | ||
} | ||
</style> | ||
``` |
22 changes: 22 additions & 0 deletions
22
static/usage/v7/config/mode/angular/example_component_ts.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
```ts | ||
import { Component } from '@angular/core'; | ||
import { Config, IonicModule } from '@ionic/angular'; | ||
import { NgIf } from '@angular/common'; | ||
|
||
@Component({ | ||
selector: 'app-example', | ||
templateUrl: './example.component.html', | ||
imports: [IonicModule, NgIf], | ||
standalone: true, | ||
}) | ||
export class ExampleComponent { | ||
modeValue = ''; | ||
|
||
constructor(public config: Config) { | ||
this.modeValue = this.config.get('mode'); | ||
} | ||
showMode() { | ||
this.modeValue = this.config.get('mode'); | ||
} | ||
} | ||
joesphchang marked this conversation as resolved.
Show resolved
Hide resolved
|
||
``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<!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</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" /> | ||
joesphchang marked this conversation as resolved.
Show resolved
Hide resolved
|
||
<style> | ||
.mode-value { | ||
margin-top: 16px; | ||
font-weight: bold; | ||
} | ||
.container { | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
gap: 0; | ||
} | ||
</style> | ||
</head> | ||
|
||
<body> | ||
<ion-app> | ||
<ion-content> | ||
<div class="container"> | ||
<ion-button id="showModeBtn" color="primary" fill="solid">Show Current Mode</ion-button> | ||
<div class="mode-value" id="modeValue"></div> | ||
</div> | ||
</ion-content> | ||
</ion-app> | ||
<script type="module"> | ||
function getMode() { | ||
if (window.Ionic && window.Ionic.config && window.Ionic.config.get) { | ||
return window.Ionic.config.get('mode'); | ||
} else { | ||
return document.documentElement.getAttribute('mode') || 'md'; | ||
} | ||
} | ||
|
||
function updateButton(mode) { | ||
const btn = document.getElementById('showModeBtn'); | ||
btn.innerText = mode; | ||
btn.color = mode === 'ios' ? 'secondary' : 'tertiary'; | ||
btn.fill = mode === 'ios' ? 'outline' : 'solid'; | ||
} | ||
|
||
document.getElementById('showModeBtn').addEventListener('click', () => { | ||
const mode = getMode(); | ||
document.getElementById('modeValue').textContent = `Current mode: ${mode}`; | ||
updateButton(mode); | ||
}); | ||
|
||
// Optionally, set initial state on load | ||
document.addEventListener('DOMContentLoaded', () => { | ||
const mode = getMode(); | ||
updateButton(mode); | ||
}); | ||
</script> | ||
</body> | ||
joesphchang marked this conversation as resolved.
Show resolved
Hide resolved
|
||
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
joesphchang marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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" | ||
joesphchang marked this conversation as resolved.
Show resolved
Hide resolved
|
||
/> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
```html | ||
<div class="container"> | ||
<ion-button id="showModeBtn" color="primary" fill="solid">Show Current Mode</ion-button> | ||
<div class="mode-value" id="modeValue"></div> | ||
</div> | ||
<script> | ||
function getMode() { | ||
if (window.Ionic && window.Ionic.config && window.Ionic.config.get) { | ||
return window.Ionic.config.get('mode'); | ||
} else { | ||
return document.documentElement.getAttribute('mode') || 'md'; | ||
} | ||
} | ||
|
||
function updateButton(mode) { | ||
const btn = document.getElementById('showModeBtn'); | ||
btn.innerText = mode; | ||
btn.color = mode === 'ios' ? 'secondary' : 'tertiary'; | ||
btn.fill = mode === 'ios' ? 'outline' : 'solid'; | ||
} | ||
|
||
document.getElementById('showModeBtn').addEventListener('click', () => { | ||
const mode = getMode(); | ||
document.getElementById('modeValue').textContent = `Current mode: ${mode}`; | ||
updateButton(mode); | ||
}); | ||
|
||
// Optionally, set initial state on load | ||
document.addEventListener('DOMContentLoaded', () => { | ||
const mode = getMode(); | ||
updateButton(mode); | ||
}); | ||
</script> | ||
<style> | ||
.container { | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
} | ||
.mode-value { | ||
margin-top: 16px; | ||
font-weight: bold; | ||
} | ||
</style> | ||
joesphchang marked this conversation as resolved.
Show resolved
Hide resolved
|
||
``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
```tsx | ||
import React, { useState, useEffect } from 'react'; | ||
import { IonButton } from '@ionic/react'; | ||
import { getMode } from '@ionic/core'; | ||
|
||
function Example() { | ||
const [modeValue, setModeValue] = useState(''); | ||
|
||
useEffect(() => { | ||
setModeValue(getMode()); | ||
}, []); | ||
|
||
const showMode = () => { | ||
setModeValue(getMode()); | ||
}; | ||
|
||
const color = modeValue === 'ios' ? 'secondary' : 'tertiary'; | ||
const fill = modeValue === 'ios' ? 'outline' : 'solid'; | ||
|
||
return ( | ||
<div className="container" style={{ display: 'flex', flexDirection: 'column', alignItems: 'center' }}> | ||
<IonButton color={color} fill={fill} onClick={showMode}> | ||
{modeValue} | ||
</IonButton> | ||
<div className="mode-value" style={{ marginTop: 16, fontWeight: 'bold' }}> | ||
{modeValue && `Current mode: ${modeValue}`} | ||
</div> | ||
</div> | ||
); | ||
} | ||
export default Example; | ||
joesphchang marked this conversation as resolved.
Show resolved
Hide resolved
|
||
``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
```html | ||
<template> | ||
<div class="container"> | ||
<ion-button :color="color" :fill="fill" @click="showMode"> {{ modeValue }} </ion-button> | ||
<div class="mode-value" v-if="modeValue">Current mode: {{ modeValue }}</div> | ||
</div> | ||
</template> | ||
|
||
<script setup> | ||
import { ref, computed, onMounted } from 'vue'; | ||
import { getMode } from '@ionic/core'; | ||
|
||
const modeValue = ref(''); | ||
|
||
function showMode() { | ||
modeValue.value = getMode(); | ||
} | ||
|
||
const color = computed(() => (modeValue.value === 'ios' ? 'secondary' : 'tertiary')); | ||
const fill = computed(() => (modeValue.value === 'ios' ? 'outline' : 'solid')); | ||
|
||
onMounted(() => { | ||
modeValue.value = getMode(); | ||
}); | ||
</script> | ||
|
||
<style scoped> | ||
.container { | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
} | ||
.mode-value { | ||
margin-top: 16px; | ||
font-weight: bold; | ||
} | ||
</style> | ||
joesphchang marked this conversation as resolved.
Show resolved
Hide resolved
|
||
``` |
28 changes: 28 additions & 0 deletions
28
static/usage/v8/config/mode/angular/example_component_html.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
```html | ||
<ion-app> | ||
<ion-content> | ||
<div class="container"> | ||
<ion-button | ||
[color]="modeValue === 'ios' ? 'secondary' : 'tertiary'" | ||
[fill]="modeValue === 'ios' ? 'outline' : 'solid'" | ||
(click)="showMode()" | ||
> | ||
{{ modeValue }} | ||
</ion-button> | ||
<div class="mode-value" *ngIf="modeValue">Current mode: {{ modeValue }}</div> | ||
</div> | ||
</ion-content> | ||
</ion-app> | ||
<style> | ||
.container { | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
justify-content: center; | ||
} | ||
.mode-value { | ||
margin-top: 16px; | ||
font-weight: bold; | ||
} | ||
</style> | ||
joesphchang marked this conversation as resolved.
Show resolved
Hide resolved
|
||
``` |
22 changes: 22 additions & 0 deletions
22
static/usage/v8/config/mode/angular/example_component_ts.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
```ts | ||
import { Component } from '@angular/core'; | ||
import { Config, IonicModule } from '@ionic/angular'; | ||
import { NgIf } from '@angular/common'; | ||
|
||
@Component({ | ||
selector: 'app-example', | ||
templateUrl: './example.component.html', | ||
imports: [IonicModule, NgIf], | ||
standalone: true, | ||
}) | ||
export class ExampleComponent { | ||
modeValue = ''; | ||
|
||
constructor(public config: Config) { | ||
this.modeValue = this.config.get('mode'); | ||
} | ||
showMode() { | ||
this.modeValue = this.config.get('mode'); | ||
} | ||
} | ||
joesphchang marked this conversation as resolved.
Show resolved
Hide resolved
|
||
``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<!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</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> | ||
.mode-value { | ||
margin-top: 16px; | ||
font-weight: bold; | ||
} | ||
.container { | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
gap: 0; | ||
} | ||
</style> | ||
</head> | ||
|
||
<body> | ||
<ion-app> | ||
<ion-content> | ||
<div class="container"> | ||
<ion-button id="showModeBtn" color="primary" fill="solid">Show Current Mode</ion-button> | ||
<div class="mode-value" id="modeValue"></div> | ||
</div> | ||
</ion-content> | ||
</ion-app> | ||
<script type="module"> | ||
function getMode() { | ||
if (window.Ionic && window.Ionic.config && window.Ionic.config.get) { | ||
return window.Ionic.config.get('mode'); | ||
} else { | ||
return document.documentElement.getAttribute('mode') || 'md'; | ||
} | ||
} | ||
|
||
function updateButton(mode) { | ||
const btn = document.getElementById('showModeBtn'); | ||
btn.innerText = mode; | ||
btn.color = mode === 'ios' ? 'secondary' : 'tertiary'; | ||
btn.fill = mode === 'ios' ? 'outline' : 'solid'; | ||
} | ||
|
||
document.getElementById('showModeBtn').addEventListener('click', () => { | ||
const mode = getMode(); | ||
document.getElementById('modeValue').textContent = `Current mode: ${mode}`; | ||
updateButton(mode); | ||
}); | ||
|
||
// Optionally, set initial state on load | ||
document.addEventListener('DOMContentLoaded', () => { | ||
const mode = getMode(); | ||
updateButton(mode); | ||
}); | ||
</script> | ||
</body> | ||
joesphchang marked this conversation as resolved.
Show resolved
Hide resolved
|
||
</html> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.