-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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(radio): playground for compareWith #3237
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 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
This file contains 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
9 changes: 9 additions & 0 deletions
9
static/usage/v7/radio/using-comparewith/angular/example_component_html.md
This file contains 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,9 @@ | ||
```html | ||
<ion-list> | ||
<ion-radio-group [compareWith]="compareWith" (ionChange)="handleChange($event)"> | ||
<ion-item *ngFor="let food of foods; trackBy: trackItems"> | ||
<ion-radio [value]="food">{{ food.name }}</ion-radio> | ||
</ion-item> | ||
</ion-radio-group> | ||
</ion-list> | ||
``` |
39 changes: 39 additions & 0 deletions
39
static/usage/v7/radio/using-comparewith/angular/example_component_ts.md
This file contains 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,39 @@ | ||
```ts | ||
import { Component } from '@angular/core'; | ||
|
||
@Component({ | ||
selector: 'app-example', | ||
templateUrl: 'example.component.html', | ||
}) | ||
export class ExampleComponent { | ||
foods = [ | ||
{ | ||
id: 1, | ||
name: 'Apples', | ||
type: 'fruit', | ||
}, | ||
{ | ||
id: 2, | ||
name: 'Carrots', | ||
type: 'vegetable', | ||
}, | ||
{ | ||
id: 3, | ||
name: 'Cupcakes', | ||
type: 'dessert', | ||
}, | ||
]; | ||
|
||
compareWith(o1, o2) { | ||
return o1.id === o2.id; | ||
} | ||
|
||
handleChange(ev) { | ||
console.log('Current value:', JSON.stringify(ev.target.value)); | ||
} | ||
|
||
trackItems(index: number, item: any) { | ||
return item.id; | ||
} | ||
} | ||
``` |
This file contains 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,67 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>Radio</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" /> | ||
</head> | ||
|
||
<body> | ||
<ion-app> | ||
<ion-content> | ||
<div class="container"> | ||
<ion-list> | ||
<ion-radio-group></ion-radio-group> | ||
</ion-list> | ||
</div> | ||
</ion-content> | ||
</ion-app> | ||
|
||
<script> | ||
const foods = [ | ||
{ | ||
id: 1, | ||
name: 'Apples', | ||
type: 'fruit', | ||
}, | ||
{ | ||
id: 2, | ||
name: 'Carrots', | ||
type: 'vegetable', | ||
}, | ||
{ | ||
id: 3, | ||
name: 'Cupcakes', | ||
type: 'dessert', | ||
}, | ||
]; | ||
|
||
const compareWithFn = (o1, o2) => { | ||
return o1.id === o2.id; | ||
}; | ||
|
||
const radioGroupEl = document.querySelector('ion-radio-group'); | ||
radioGroupEl.compareWith = (a, b) => a.value === b.value; | ||
|
||
foods.forEach((option, i) => { | ||
const radio = document.createElement('ion-radio'); | ||
|
||
radio.value = option; | ||
radio.textContent = option.name; | ||
|
||
const item = document.createElement('ion-item'); | ||
item.appendChild(radio); | ||
|
||
radioGroupEl.appendChild(item); | ||
}); | ||
|
||
radioGroupEl.addEventListener('ionChange', () => { | ||
console.log('Current value:', JSON.stringify(radioGroupEl.value)); | ||
}); | ||
</script> | ||
</body> | ||
</html> |
This file contains 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 @@ | ||
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/radio/using-comparewith/demo.html" | ||
showConsole={true} | ||
/> |
This file contains 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,48 @@ | ||
```html | ||
<ion-list> | ||
<ion-radio-group></ion-radio-group> | ||
</ion-list> | ||
|
||
<script> | ||
const foods = [ | ||
{ | ||
id: 1, | ||
name: 'Apples', | ||
type: 'fruit', | ||
}, | ||
{ | ||
id: 2, | ||
name: 'Carrots', | ||
type: 'vegetable', | ||
}, | ||
{ | ||
id: 3, | ||
name: 'Cupcakes', | ||
type: 'dessert', | ||
}, | ||
]; | ||
|
||
const compareWithFn = (o1, o2) => { | ||
return o1.id === o2.id; | ||
}; | ||
|
||
const radioGroupEl = document.querySelector('ion-radio-group'); | ||
radioGroupEl.compareWith = compareWithFn; | ||
|
||
foods.forEach((option, i) => { | ||
const radio = document.createElement('ion-radio'); | ||
|
||
radio.value = option; | ||
radio.textContent = option.name; | ||
|
||
const item = document.createElement('ion-item'); | ||
item.appendChild(radio); | ||
|
||
radioGroupEl.appendChild(item); | ||
}); | ||
|
||
radioGroupEl.addEventListener('ionChange', () => { | ||
console.log('Current value:', JSON.stringify(radioGroupEl.value)); | ||
}); | ||
</script> | ||
``` |
This file contains 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,52 @@ | ||
```tsx | ||
import React from 'react'; | ||
import { IonItem, IonList, IonRadio, IonRadioGroup } from '@ionic/react'; | ||
|
||
interface Food { | ||
id: number; | ||
name: string; | ||
type: string; | ||
} | ||
|
||
const foods: Food[] = [ | ||
{ | ||
id: 1, | ||
name: 'Apples', | ||
type: 'fruit', | ||
}, | ||
{ | ||
id: 2, | ||
name: 'Carrots', | ||
type: 'vegetable', | ||
}, | ||
{ | ||
id: 3, | ||
name: 'Cupcakes', | ||
type: 'dessert', | ||
}, | ||
]; | ||
|
||
const compareWith = (o1: Food, o2: Food) => { | ||
return o1.id === o2.id; | ||
}; | ||
|
||
function Example() { | ||
return ( | ||
<IonList> | ||
<IonRadioGroup | ||
compareWith={compareWith} | ||
onIonChange={(ev) => console.log('Current value:', JSON.stringify(ev.detail.value))} | ||
> | ||
{foods.map((food) => ( | ||
<IonItem> | ||
<IonRadio key={food.id} value={food}> | ||
{food.name} | ||
</IonRadio> | ||
</IonItem> | ||
))} | ||
</IonRadioGroup> | ||
</IonList> | ||
); | ||
} | ||
export default Example; | ||
``` |
This file contains 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,54 @@ | ||
```html | ||
<template> | ||
<ion-list> | ||
<ion-radio-group :compareWith="compareWith" @ionChange="handleChange($event)"> | ||
<ion-item v-for="food in foods"> | ||
<ion-radio :value="food">{{ food.name }}</ion-radio> | ||
</ion-item> | ||
</ion-radio-group> | ||
</ion-list> | ||
</template> | ||
|
||
<script lang="ts"> | ||
import { IonItem, IonList, IonRadio, IonRadioGroup } from '@ionic/vue'; | ||
import { defineComponent } from 'vue'; | ||
|
||
export default defineComponent({ | ||
components: { | ||
IonItem, | ||
IonList, | ||
IonRadio, | ||
IonRadioGroup, | ||
}, | ||
data() { | ||
return { | ||
foods: [ | ||
{ | ||
id: 1, | ||
name: 'Apples', | ||
type: 'fruit', | ||
}, | ||
{ | ||
id: 2, | ||
name: 'Carrots', | ||
type: 'vegetable', | ||
}, | ||
{ | ||
id: 3, | ||
name: 'Cupcakes', | ||
type: 'dessert', | ||
}, | ||
], | ||
}; | ||
}, | ||
methods: { | ||
compareWith(o1, o2) { | ||
return o1.id === o2.id; | ||
}, | ||
handleChange(ev) { | ||
console.log('Current value:', JSON.stringify(ev.detail.value)); | ||
}, | ||
}, | ||
}); | ||
</script> | ||
``` |
This file contains 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
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.
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.
See discussion here and updated design doc