-
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 #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
base: main
Are you sure you want to change the base?
Changes from all commits
6c433ba
1c5ac9c
19c8675
ce5e829
06ca426
b9f6eab
3a10711
2d4b31d
3d89f76
2decf9e
aab3038
bd246a2
7fed84d
096bd2f
f28d5bd
a205534
ce4c3e4
67c3ac9
7b3b3b9
8476a80
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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> | ||
``` |
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'); | ||
} | ||
``` |
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> |
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" | ||
/> |
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> | ||
``` |
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; | ||
``` |
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> | ||
``` |
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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> | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
<div class="mode-value">{{ modeValue }}</div> | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||||||
</div> | ||||||
</ion-content> | ||||||
</ion-app> | ||||||
``` |
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'); | ||
} | ||
``` |
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> | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||
<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; */ | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove any unused code.
Suggested change
|
||||||||||||
padding: 16px; | ||||||||||||
margin: auto; | ||||||||||||
display: flex; | ||||||||||||
justify-content: center; | ||||||||||||
align-items: center; | ||||||||||||
Comment on lines
+14
to
+18
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These are not needed since they are being set through
Suggested change
|
||||||||||||
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> | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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> |
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" | ||
/> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
```html | ||
<button id="showModeBtn">Show Current Mode</button> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be using an |
||
<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> | ||
``` |
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> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
``` |
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> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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> | ||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's aim for short titles.