UNPKG

3.47 kBJavaScriptView Raw
1/*
2Copyright 2013-2015 ASIAL CORPORATION
3Licensed under the Apache License, Version 2.0 (the "License");
4you may not use this file except in compliance with the License.
5You may obtain a copy of the License at
6 http://www.apache.org/licenses/LICENSE-2.0
7Unless required by applicable law or agreed to in writing, software
8distributed under the License is distributed on an "AS IS" BASIS,
9WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10See the License for the specific language governing permissions and
11limitations under the License.
12*/
13
14import onsElements from '../ons/elements.js';
15import BaseCheckboxElement from './base/base-checkbox.js';
16
17const scheme = {
18 '.radio-button': 'radio-button--*',
19 '.radio-button__input': 'radio-button--*__input',
20 '.radio-button__checkmark': 'radio-button--*__checkmark'
21};
22
23/**
24 * @element ons-radio
25 * @category form
26 * @modifier material
27 * [en]Displays a Material Design radio button.[/en]
28 * [ja][/ja]
29 * @description
30 * [en]
31 * A radio button element. The component will automatically render as a Material Design radio button on Android devices.
32 *
33 * Most attributes that can be used for a normal `<input type="radio">` element can also be used on the `<ons-radio>` element.
34 * [/en]
35 * [ja][/ja]
36 * @tutorial vanilla/Reference/radio
37 * @seealso ons-select
38 * [en]The `<ons-select>` element is used to display a select box.[/en]
39 * [ja][/ja]
40 * @seealso ons-checkbox
41 * [en]The `<ons-checkbox>` element is used to display a checkbox.[/en]
42 * [ja][/ja]
43 * @seealso ons-switch
44 * [en]The `<ons-switch>` element is used to display a draggable toggle switch.[/en]
45 * [ja][/ja]
46 * @seealso ons-input
47 * [en]The `<ons-input>` element is used to display a text input.[/en]
48 * [ja][/ja]
49 * @seealso ons-search-input
50 * [en]The `<ons-search-input>` element is used to display a search input.[/en]
51 * [ja][/ja]
52 * @seealso ons-range
53 * [en]The `<ons-range>` element is used to display a range slider.[/en]
54 * [ja][/ja]
55 * @guide theming.html#modifiers [en]More details about the `modifier` attribute[/en][ja]modifier属性の使い方[/ja]
56 * @example
57 * <ons-radio checked></ons-radio>
58 */
59export default class RadioElement extends BaseCheckboxElement {
60
61 get _scheme() {
62 return scheme;
63 }
64
65 get _defaultClassName() {
66 return 'radio-button';
67 }
68
69 get type() {
70 return 'radio';
71 }
72
73 /**
74 * @attribute input-id
75 * @type {String}
76 * @description
77 * [en]Specify the "id" attribute of the inner `<input>` element. This is useful when using `<label for="...">` elements.[/en]
78 * [ja][/ja]
79 */
80
81 /**
82 * @property value
83 * @type {String}
84 * @description
85 * [en]The current value of the radio button.[/en]
86 * [ja][/ja]
87 */
88
89 /**
90 * @property checked
91 * @type {Boolean}
92 * @description
93 * [en]Whether the radio button is checked or not.[/en]
94 * [ja][/ja]
95 */
96
97 /**
98 * @property disabled
99 * @type {Boolean}
100 * @description
101 * [en]Whether the radio button is disabled or not.[/en]
102 * [ja]無効化されている場合に`true`。[/ja]
103 */
104
105 /**
106 * @method focus
107 * @signature focus()
108 * @description
109 * [en]Focuses the radio button.[/en]
110 * [ja][/ja]
111 */
112
113 /**
114 * @method blur
115 * @signature blur()
116 * @description
117 * [en]Removes focus from the radio button.[/en]
118 * [ja][/ja]
119 */
120}
121
122onsElements.Radio = RadioElement;
123customElements.define('ons-radio', RadioElement);