Skip to content

Commit c250fa3

Browse files
committed
Start wiring up radio list
1 parent a7505cf commit c250fa3

10 files changed

Lines changed: 97 additions & 0 deletions

File tree

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# `<pg-input-radio>`
2+
3+
The `pg-input-radio` creates a radio list of options a user can pick from.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<div class="example">
2+
<pg-input-radio part="input" value="item1"></pg-input-check>
3+
<pg-input-radio disabled></pg-input-check>
4+
<pg-input-radio value="item2" disabled></pg-input-check>
5+
<div>
6+
<code>onchange: <span part="value"></span></code>
7+
</div>
8+
</div>
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { Component, Part, Prop } from '@pictogrammers/element';
2+
import PgInputRadio from '../../inputRadio';
3+
4+
import template from './basic.html';
5+
6+
@Component({
7+
selector: 'x-pg-input-radio-basic',
8+
template,
9+
})
10+
export default class XPgInputRadioBasic extends HTMLElement {
11+
12+
@Part() $input: PgInputRadio;
13+
@Part() $value: HTMLSpanElement;
14+
15+
connectedCallback() {
16+
this.$input.items.push({
17+
label: 'Item 1',
18+
value: 'item1',
19+
}, {
20+
label: 'Item 2',
21+
value: 'item2',
22+
});
23+
this.$input.addEventListener('change', this.handleChange.bind(this));
24+
}
25+
26+
handleChange(e) {
27+
var value = e.target.value;
28+
this.$value.innerText = value;
29+
}
30+
}

src/components/pg/inputRadio/inputRadio.css

Whitespace-only changes.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<div part="items"></div>
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { Component, Prop, Part, normalizeBoolean, forEach } from '@pictogrammers/element';
2+
3+
import template from './inputRadio.html';
4+
import style from './inputRadio.css';
5+
import PgInputRadioItem from '../inputRadioItem/inputRadioItem';
6+
7+
@Component({
8+
selector: 'pg-input-radio',
9+
style,
10+
template,
11+
})
12+
export default class PgInputRadio extends HTMLElement {
13+
@Prop() name: string = '';
14+
@Prop() value: string = '';
15+
@Prop(normalizeBoolean) readOnly: boolean = false;
16+
@Prop(normalizeBoolean) disabled: boolean = false;
17+
@Prop() items: any[] = [];
18+
19+
@Part() $items: HTMLInputElement;
20+
21+
connectedCallback() {
22+
forEach({
23+
container: this.$items,
24+
items: this.items,
25+
type: () => PgInputRadioItem,
26+
});
27+
}
28+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# `PgInputRadioItem`
2+
3+
The `PgInputRadioItem` is used internally as options are added to the `pg-input-radio`.

src/components/pg/inputRadioItem/inputRadioItem.css

Whitespace-only changes.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<label><input part="input" type="radio" /> <span part="label"></span></label>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { Component, Prop, Part, normalizeBoolean } from '@pictogrammers/element';
2+
3+
import template from './inputRadioItem.html';
4+
import style from './inputRadioItem.css';
5+
6+
@Component({
7+
selector: 'pg-input-radio-item',
8+
style,
9+
template,
10+
})
11+
export default class PgInputRadioItem extends HTMLElement {
12+
@Prop() label: string = '';
13+
@Prop() value: string = '';
14+
15+
@Part() $input: HTMLInputElement;
16+
@Part() $label: HTMLSpanElement;
17+
18+
render(changes) {
19+
if (changes.label) {
20+
this.$label.textContent = this.label;
21+
}
22+
}
23+
}

0 commit comments

Comments
 (0)