-
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 all 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
5 changes: 5 additions & 0 deletions
5
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,5 @@ | ||
```html | ||
<ion-button [color]="mode === 'ios' ? 'secondary' : 'tertiary'" [fill]="mode === 'ios' ? 'outline' : 'solid'"> | ||
Current mode: {{ mode }} | ||
</ion-button> | ||
``` |
16 changes: 16 additions & 0 deletions
16
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,16 @@ | ||
```ts | ||
import { Component } from '@angular/core'; | ||
import { Config, IonButton } from '@ionic/angular/standalone'; | ||
|
||
@Component({ | ||
selector: 'app-example', | ||
templateUrl: './example.component.html', | ||
imports: [IonButton], | ||
}) | ||
export class ExampleComponent { | ||
mode: string; | ||
constructor(public config: Config) { | ||
this.mode = this.config.get('mode'); | ||
} | ||
} | ||
``` |
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,41 @@ | ||
<!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="modeButton"></ion-button> | ||
</div> | ||
</ion-content> | ||
</ion-app> | ||
<script type="module"> | ||
const modeButton = document.querySelector('#modeButton'); | ||
const mode = window.Ionic.config.get('mode') || document.documentElement.getAttribute('mode') || 'md'; | ||
|
||
modeButton.innerHTML = `Current mode: ${mode}`; | ||
modeButton.setAttribute('color', mode === 'ios' ? 'secondary' : 'tertiary'); | ||
modeButton.setAttribute('fill', mode === 'ios' ? 'outline' : 'solid'); | ||
</script> | ||
</body> | ||
</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="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" | ||
/> |
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,12 @@ | ||
```html | ||
<ion-button id="modeButton"></ion-button> | ||
|
||
<script> | ||
const modeButton = document.querySelector('#modeButton'); | ||
const mode = window.Ionic.config.get('mode') || document.documentElement.getAttribute('mode') || 'md'; | ||
|
||
modeButton.innerHTML = `Current mode: ${mode}`; | ||
modeButton.setAttribute('color', mode === 'ios' ? 'secondary' : 'tertiary'); | ||
modeButton.setAttribute('fill', mode === 'ios' ? 'outline' : 'solid'); | ||
</script> | ||
``` |
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,25 @@ | ||
```tsx | ||
import React, { useState, useEffect } from 'react'; | ||
import { IonButton } from '@ionic/react'; | ||
import { getMode } from '@ionic/core'; | ||
|
||
function Example() { | ||
const [mode, setMode] = useState(''); | ||
|
||
useEffect(() => { | ||
const mode = getMode() || 'md'; | ||
setMode(mode); | ||
}, []); | ||
|
||
const color = mode === 'ios' ? 'secondary' : 'tertiary'; | ||
const fill = mode === 'ios' ? 'outline' : 'solid'; | ||
|
||
return ( | ||
<IonButton color={color} fill={fill}> | ||
Current mode: {mode} | ||
</IonButton> | ||
); | ||
} | ||
|
||
export default Example; | ||
``` |
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,20 @@ | ||
```html | ||
<template> | ||
<ion-button :color="color" :fill="fill"> Current mode: {{ mode }} </ion-button> | ||
</template> | ||
|
||
<script setup> | ||
import { ref, computed, onMounted } from 'vue'; | ||
import { IonButton } from '@ionic/vue'; | ||
import { getMode } from '@ionic/core'; | ||
|
||
const mode = ref(''); | ||
|
||
const color = computed(() => (mode.value === 'ios' ? 'secondary' : 'tertiary')); | ||
const fill = computed(() => (mode.value === 'ios' ? 'outline' : 'solid')); | ||
|
||
onMounted(() => { | ||
mode.value = getMode() || 'md'; | ||
}); | ||
</script> | ||
``` |
5 changes: 5 additions & 0 deletions
5
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,5 @@ | ||
```html | ||
<ion-button [color]="mode === 'ios' ? 'secondary' : 'tertiary'" [fill]="mode === 'ios' ? 'outline' : 'solid'"> | ||
Current mode: {{ mode }} | ||
</ion-button> | ||
``` |
16 changes: 16 additions & 0 deletions
16
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,16 @@ | ||
```ts | ||
import { Component } from '@angular/core'; | ||
import { Config, IonButton } from '@ionic/angular/standalone'; | ||
|
||
@Component({ | ||
selector: 'app-example', | ||
templateUrl: './example.component.html', | ||
imports: [IonButton], | ||
}) | ||
export class ExampleComponent { | ||
mode: string; | ||
constructor(public config: Config) { | ||
this.mode = this.config.get('mode'); | ||
} | ||
} | ||
``` |
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,41 @@ | ||
<!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="modeButton"></ion-button> | ||
</div> | ||
</ion-content> | ||
</ion-app> | ||
<script type="module"> | ||
const modeButton = document.querySelector('#modeButton'); | ||
const mode = window.Ionic.config.get('mode') || document.documentElement.getAttribute('mode') || 'md'; | ||
|
||
modeButton.innerHTML = `Current mode: ${mode}`; | ||
modeButton.setAttribute('color', mode === 'ios' ? 'secondary' : 'tertiary'); | ||
modeButton.setAttribute('fill', mode === 'ios' ? 'outline' : 'solid'); | ||
</script> | ||
</body> | ||
</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" | ||
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" | ||
/> |
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,12 @@ | ||
```html | ||
<ion-button id="modeButton"></ion-button> | ||
|
||
<script> | ||
const modeButton = document.querySelector('#modeButton'); | ||
const mode = window.Ionic.config.get('mode') || document.documentElement.getAttribute('mode') || 'md'; | ||
|
||
modeButton.innerHTML = `Current mode: ${mode}`; | ||
modeButton.setAttribute('color', mode === 'ios' ? 'secondary' : 'tertiary'); | ||
modeButton.setAttribute('fill', mode === 'ios' ? 'outline' : 'solid'); | ||
</script> | ||
``` |
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 @@ | ||
```tsx | ||
import React, { useState, useEffect } from 'react'; | ||
import { IonButton } from '@ionic/react'; | ||
import { getMode } from '@ionic/core'; | ||
|
||
function Example() { | ||
const [mode, setMode] = useState(''); | ||
|
||
useEffect(() => { | ||
const mode = getMode() || 'md'; | ||
setMode(mode); | ||
}, []); | ||
|
||
const color = mode === 'ios' ? 'secondary' : 'tertiary'; | ||
const fill = mode === 'ios' ? 'outline' : 'solid'; | ||
|
||
return ( | ||
<IonButton color={color} fill={fill}> | ||
Current mode: {mode} | ||
</IonButton> | ||
); | ||
} | ||
export default Example; | ||
``` |
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,20 @@ | ||
```html | ||
<template> | ||
<ion-button :color="color" :fill="fill"> Current mode: {{ mode }} </ion-button> | ||
</template> | ||
|
||
<script setup> | ||
import { ref, computed, onMounted } from 'vue'; | ||
import { IonButton } from '@ionic/vue'; | ||
import { getMode } from '@ionic/core'; | ||
|
||
const mode = ref(''); | ||
|
||
const color = computed(() => (mode.value === 'ios' ? 'secondary' : 'tertiary')); | ||
const fill = computed(() => (mode.value === 'ios' ? 'outline' : 'solid')); | ||
|
||
onMounted(() => { | ||
mode.value = getMode() || 'md'; | ||
}); | ||
</script> | ||
``` |
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
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.