This repository is currently being migrated. It's locked while the migration is in progress.
-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathva-radio-option.tsx
More file actions
105 lines (92 loc) · 2.23 KB
/
va-radio-option.tsx
File metadata and controls
105 lines (92 loc) · 2.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import {
Component,
Element,
Event,
EventEmitter,
Prop,
h,
} from '@stencil/core';
import classnames from 'classnames';
@Component({
tag: 'va-radio-option',
styleUrl: 'va-radio-option.scss',
shadow: false,
})
export class VaRadioOption {
@Element() el: HTMLElement;
/**
* The name attribute for the input element.
*/
@Prop() name!: string;
/**
* The text label for the input element.
*/
@Prop() label!: string;
/**
* The value attribute for the input element.
*/
@Prop() value!: string;
/**
* Whether or not the option is selected.
*/
@Prop() checked?: boolean = false;
/**
* Whether or not the component will display as a tile.
*/
@Prop() tile?: boolean = false;
/**
* Description of the option displayed below the option label.
*/
@Prop() description?: string;
/**
* Whether or not the radio option is disabled.
*/
@Prop() disabled?: boolean = false;
/**
* Optional string for the ariaDescribedBy attribute.
*/
@Prop() ariaDescribedby?: string;
/**
* The event emitted when the selected option value changes
*/
@Event({
composed: true,
bubbles: true,
})
radioOptionSelected: EventEmitter;
private handleChange(): void {
this.radioOptionSelected.emit();
}
render() {
const { checked, name, value, label, disabled, tile, description } = this;
const id = this.el.id || name + value;
const containerClass = classnames('usa-radio', {
'va-radio-option__container--tile': tile,
'va-radio-option__container--tile--checked': tile && checked,
});
return (
<div class={containerClass} onClick={() => this.handleChange()}>
<input
class="va-radio-option__input"
type="radio"
name={name}
value={value}
checked={checked}
disabled={disabled}
id={id + 'input'}
/>
<label class="usa-radio__label" htmlFor={id + 'input'}>
{label}
{description && (
<span
class="usa-radio__label-description dd-privacy-hidden"
data-dd-action-name="description"
>
{description}
</span>
)}
</label>
</div>
);
}
}