@gorse/shards-vue 1.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (173) hide show
  1. package/.editorconfig +13 -0
  2. package/CHANGELOG.md +49 -0
  3. package/CONTRIBUTING.md +92 -0
  4. package/ISSUE_TEMPLATE.md +19 -0
  5. package/LICENSE +21 -0
  6. package/README.md +157 -0
  7. package/build/optimize.js +49 -0
  8. package/build/paths.js +12 -0
  9. package/build/rollup.config.js +106 -0
  10. package/dist/shards-vue.common.js +13994 -0
  11. package/dist/shards-vue.common.js.map +1 -0
  12. package/dist/shards-vue.common.min.js +1 -0
  13. package/dist/shards-vue.common.min.map +1 -0
  14. package/dist/shards-vue.esm.js +13990 -0
  15. package/dist/shards-vue.esm.js.map +1 -0
  16. package/dist/shards-vue.esm.min.js +1 -0
  17. package/dist/shards-vue.esm.min.map +1 -0
  18. package/dist/shards-vue.umd.js +13997 -0
  19. package/dist/shards-vue.umd.js.map +1 -0
  20. package/dist/shards-vue.umd.min.js +1 -0
  21. package/dist/shards-vue.umd.min.map +1 -0
  22. package/logo.jpg +0 -0
  23. package/package.json +121 -0
  24. package/sandbox/Sandbox.vue +45 -0
  25. package/src/components/alert/Alert.vue +156 -0
  26. package/src/components/alert/README.md +86 -0
  27. package/src/components/alert/index.js +17 -0
  28. package/src/components/badge/Badge.vue +62 -0
  29. package/src/components/badge/README.md +112 -0
  30. package/src/components/badge/index.js +17 -0
  31. package/src/components/breadcrumb/Breadcrumb.vue +55 -0
  32. package/src/components/breadcrumb/BreadcrumbItem.vue +42 -0
  33. package/src/components/breadcrumb/BreadcrumbLink.vue +56 -0
  34. package/src/components/breadcrumb/README.md +53 -0
  35. package/src/components/breadcrumb/index.js +23 -0
  36. package/src/components/button/Button.vue +107 -0
  37. package/src/components/button/ButtonClose.vue +47 -0
  38. package/src/components/button/README.md +197 -0
  39. package/src/components/button/index.js +21 -0
  40. package/src/components/button-group/ButtonGroup.vue +66 -0
  41. package/src/components/button-group/README.md +72 -0
  42. package/src/components/button-group/index.js +18 -0
  43. package/src/components/button-toolbar/ButtonToolbar.vue +29 -0
  44. package/src/components/button-toolbar/README.md +24 -0
  45. package/src/components/button-toolbar/index.js +18 -0
  46. package/src/components/card/Card.vue +57 -0
  47. package/src/components/card/CardBody.vue +92 -0
  48. package/src/components/card/CardFooter.vue +61 -0
  49. package/src/components/card/CardGroup.vue +47 -0
  50. package/src/components/card/CardHeader.vue +61 -0
  51. package/src/components/card/CardImg.vue +64 -0
  52. package/src/components/card/README.md +96 -0
  53. package/src/components/card/index.js +27 -0
  54. package/src/components/collapse/Collapse.vue +209 -0
  55. package/src/components/collapse/README.md +86 -0
  56. package/src/components/collapse/index.js +17 -0
  57. package/src/components/container/Col.vue +125 -0
  58. package/src/components/container/Container.vue +31 -0
  59. package/src/components/container/README.md +91 -0
  60. package/src/components/container/Row.vue +64 -0
  61. package/src/components/container/index.js +21 -0
  62. package/src/components/datepicker/Datepicker.vue +391 -0
  63. package/src/components/datepicker/README.md +185 -0
  64. package/src/components/datepicker/index.js +17 -0
  65. package/src/components/dropdown/Dropdown.vue +442 -0
  66. package/src/components/dropdown/DropdownDivider.vue +22 -0
  67. package/src/components/dropdown/DropdownHeader.vue +29 -0
  68. package/src/components/dropdown/DropdownItem.vue +25 -0
  69. package/src/components/dropdown/README.md +177 -0
  70. package/src/components/dropdown/index.js +23 -0
  71. package/src/components/embed/Embed.vue +47 -0
  72. package/src/components/embed/README.md +23 -0
  73. package/src/components/embed/index.js +17 -0
  74. package/src/components/form/Form.vue +40 -0
  75. package/src/components/form/FormFeedback.vue +39 -0
  76. package/src/components/form/FormInvalidFeedback.vue +39 -0
  77. package/src/components/form/FormRow.vue +21 -0
  78. package/src/components/form/FormText.vue +41 -0
  79. package/src/components/form/FormValidFeedback.vue +39 -0
  80. package/src/components/form/README.md +84 -0
  81. package/src/components/form/index.js +29 -0
  82. package/src/components/form-checkbox/FormCheckbox.vue +200 -0
  83. package/src/components/form-checkbox/README.md +131 -0
  84. package/src/components/form-checkbox/index.js +18 -0
  85. package/src/components/form-input/FormInput.vue +176 -0
  86. package/src/components/form-input/README.md +110 -0
  87. package/src/components/form-input/index.js +18 -0
  88. package/src/components/form-radio/FormRadio.vue +155 -0
  89. package/src/components/form-radio/README.md +61 -0
  90. package/src/components/form-radio/index.js +18 -0
  91. package/src/components/form-select/FormSelect.vue +246 -0
  92. package/src/components/form-select/README.md +180 -0
  93. package/src/components/form-select/index.js +18 -0
  94. package/src/components/form-textarea/FormTextarea.vue +250 -0
  95. package/src/components/form-textarea/README.md +74 -0
  96. package/src/components/form-textarea/index.js +18 -0
  97. package/src/components/image/Image.vue +123 -0
  98. package/src/components/image/README.md +32 -0
  99. package/src/components/image/index.js +18 -0
  100. package/src/components/index.js +63 -0
  101. package/src/components/input-group/InputGroup.vue +125 -0
  102. package/src/components/input-group/InputGroupAddon.vue +58 -0
  103. package/src/components/input-group/InputGroupText.vue +20 -0
  104. package/src/components/input-group/README.md +188 -0
  105. package/src/components/input-group/index.js +21 -0
  106. package/src/components/link/Link.vue +157 -0
  107. package/src/components/link/README.md +27 -0
  108. package/src/components/link/create-link-props.js +54 -0
  109. package/src/components/link/index.js +17 -0
  110. package/src/components/list-group/ListGroup.vue +30 -0
  111. package/src/components/list-group/ListGroupItem.vue +90 -0
  112. package/src/components/list-group/README.md +23 -0
  113. package/src/components/list-group/index.js +19 -0
  114. package/src/components/modal/Modal.vue +121 -0
  115. package/src/components/modal/ModalBody.vue +20 -0
  116. package/src/components/modal/ModalFooter.vue +21 -0
  117. package/src/components/modal/ModalHeader.vue +39 -0
  118. package/src/components/modal/ModalTitle.vue +21 -0
  119. package/src/components/modal/README.md +74 -0
  120. package/src/components/modal/index.js +25 -0
  121. package/src/components/nav/Nav.vue +62 -0
  122. package/src/components/nav/NavItem.vue +23 -0
  123. package/src/components/nav/NavText.vue +21 -0
  124. package/src/components/nav/README.md +94 -0
  125. package/src/components/nav/index.js +19 -0
  126. package/src/components/navbar/Navbar.vue +63 -0
  127. package/src/components/navbar/NavbarBrand.vue +41 -0
  128. package/src/components/navbar/NavbarNav.vue +38 -0
  129. package/src/components/navbar/NavbarToggle.vue +55 -0
  130. package/src/components/navbar/README.md +51 -0
  131. package/src/components/navbar/index.js +23 -0
  132. package/src/components/popover/Popover.vue +126 -0
  133. package/src/components/popover/README.md +73 -0
  134. package/src/components/popover/index.js +17 -0
  135. package/src/components/progress/Progress.vue +93 -0
  136. package/src/components/progress/ProgressBar.vue +123 -0
  137. package/src/components/progress/README.md +95 -0
  138. package/src/components/progress/index.js +19 -0
  139. package/src/components/slider/README.md +120 -0
  140. package/src/components/slider/Slider.vue +103 -0
  141. package/src/components/slider/index.js +17 -0
  142. package/src/components/tabs/README.md +111 -0
  143. package/src/components/tabs/Tab.vue +132 -0
  144. package/src/components/tabs/Tabs.vue +290 -0
  145. package/src/components/tabs/_TabButton.vue +130 -0
  146. package/src/components/tabs/index.js +19 -0
  147. package/src/components/tooltip/README.md +70 -0
  148. package/src/components/tooltip/Tooltip.vue +115 -0
  149. package/src/components/tooltip/index.js +17 -0
  150. package/src/directives/index.js +7 -0
  151. package/src/directives/toggle/index.js +16 -0
  152. package/src/directives/toggle/toggle.js +45 -0
  153. package/src/directives/tooltip/README.md +42 -0
  154. package/src/directives/tooltip/index.js +16 -0
  155. package/src/directives/tooltip/meta.json +5 -0
  156. package/src/directives/tooltip/tooltip.js +145 -0
  157. package/src/index.js +27 -0
  158. package/src/markdown/getting-started/README.md +80 -0
  159. package/src/markdown/getting-started/meta.json +4 -0
  160. package/src/markdown/roadmap/README.md +3 -0
  161. package/src/markdown/roadmap/meta.json +4 -0
  162. package/src/mixins/checkbox-radio.mixin.js +73 -0
  163. package/src/mixins/root-listener.mixin.js +32 -0
  164. package/src/mixins/tooltip-popover.mixin.js +292 -0
  165. package/src/scripts/utils.js +18 -0
  166. package/src/utils/constants.js +191 -0
  167. package/src/utils/events.js +48 -0
  168. package/src/utils/index.js +251 -0
  169. package/src/utils/observer.js +56 -0
  170. package/src/utils/popover.class.js +91 -0
  171. package/src/utils/target.js +50 -0
  172. package/src/utils/tooltip.class.js +60 -0
  173. package/src/utils/tpmanager.class.js +730 -0
@@ -0,0 +1,131 @@
1
+ # Form Checkbox
2
+
3
+ The `<d-form-checkbox>` component is a wrapper over Bootstrap's [custom checkbox component](https://getbootstrap.com/docs/4.1/components/forms/#checkboxes-and-radios-1).
4
+
5
+ ## Alias
6
+
7
+ The `<d-form-checkbox>` component is also available as `<d-checkbox>`.
8
+
9
+ ## Basic Demo
10
+
11
+ :::demo
12
+ ```html
13
+ <template>
14
+ <div>
15
+ <label>Select your favorite fruits</label>
16
+ <d-checkbox v-model="selected" name="fav_fruits" value="orange">Orange</d-checkbox>
17
+ <d-checkbox v-model="selected" name="fav_fruits" value="lemon">Lemon</d-checkbox>
18
+ <d-checkbox v-model="selected" name="fav_fruits" value="kiwi">Kiwi</d-checkbox>
19
+ <p>Checked Status: {{ selected }}</p>
20
+ </div>
21
+ </template>
22
+
23
+ <script>
24
+ export default {
25
+ data() {
26
+ return {
27
+ selected: ['orange']
28
+ }
29
+ }
30
+ }
31
+ </script>
32
+
33
+ <!-- checkbox-1.vue -->
34
+ ```
35
+ :::
36
+
37
+ ## Toggles
38
+
39
+ Checkboxes can be turned into toggles by using the `toggle` prop.
40
+
41
+ :::demo
42
+ ```html
43
+
44
+
45
+ <template>
46
+ <div class="mb-3">
47
+ <d-checkbox inline v-model="enabled" toggle>Enable Rockets <span v-if="enabled">- 🚀🚀 Rockets enabled! 🚀🚀</span> </d-checkbox>
48
+ </div>
49
+ </template>
50
+
51
+ <script>
52
+ export default {
53
+ data() {
54
+ return {
55
+ enabled: false
56
+ }
57
+ }
58
+ }
59
+ </script>
60
+
61
+ <!-- checkbox-2.vue -->
62
+ ```
63
+ :::
64
+
65
+
66
+ ## Inline Display
67
+
68
+ Checkboxes can also be displayed inline using the `inline` prop.
69
+
70
+ :::demo
71
+ ```html
72
+ <div>
73
+ <label class="d-block">Select your favorite sports</label>
74
+ <d-checkbox inline checked="basketball" name="fav_sports" value="basketball">Basketball</d-checkbox>
75
+ <d-checkbox inline name="fav_sports" value="football">Football</d-checkbox>
76
+ <d-checkbox inline name="fav_sports" value="Tennis">Tennis</d-checkbox>
77
+ </div>
78
+
79
+ <!-- checkbox-3.vue -->
80
+ ```
81
+ :::
82
+
83
+ ## Values
84
+
85
+ By default, the `<d-form-checkbox>` component's value will be `true` or `false` depending on its checked state. However, this can be easily adjusted using the `value` and `unchecked-value` props.
86
+
87
+ ## Indeterminate State
88
+
89
+ :::demo
90
+ ```html
91
+ <template>
92
+ <div>
93
+ <d-form-checkbox v-model="checked" :indeterminate.sync="indeterminate">
94
+ I'm <span v-if="indeterminate">indeterminate 😕</span><span v-else-if="checked">checked 😊</span><span v-else>not checked! 😟</span>
95
+ </d-form-checkbox>
96
+
97
+ <div class="my-3">
98
+ Checked: <strong>{{ checked }}</strong><br>
99
+ Indeterminate: <strong>{{ indeterminate }}</strong>
100
+ </div>
101
+ <d-btn @click="toggleIndeterminateState">Toggle Indeterminate</d-btn>
102
+ </div>
103
+ </template>
104
+
105
+ <script>
106
+ export default {
107
+ data () {
108
+ return {
109
+ checked: true,
110
+ indeterminate: true
111
+ }
112
+ },
113
+ methods: {
114
+ toggleIndeterminateState () {
115
+ this.indeterminate = !this.indeterminate
116
+ }
117
+ }
118
+ }
119
+ </script>
120
+
121
+ <!-- checkbox-4.vue -->
122
+ ```
123
+ :::
124
+
125
+ ## Missing Features
126
+
127
+ The following checkbox features are currently not supported, but available on the [roadmap](/roadmap).
128
+
129
+ * Possibility of creating plain checkboxes.
130
+ * Checkbox groups.
131
+ * Button style checkboxes.
@@ -0,0 +1,18 @@
1
+ import { registerComponents, vueUse } from './../../utils'
2
+
3
+ import dFormCheckbox from './FormCheckbox.vue'
4
+
5
+ const components = {
6
+ dFormCheckbox,
7
+ dCheckbox: dFormCheckbox
8
+ }
9
+
10
+ const VuePlugin = {
11
+ install (Vue) {
12
+ registerComponents(Vue, components)
13
+ }
14
+ }
15
+
16
+ vueUse(VuePlugin)
17
+
18
+ export default VuePlugin
@@ -0,0 +1,176 @@
1
+ <template>
2
+ <input ref="input"
3
+ :id="computedID"
4
+ :type="type"
5
+ :name="name"
6
+ :disabled="disabled"
7
+ :required="required"
8
+ :readonly="readonly || plaintext"
9
+ :placeholder="placeholder"
10
+ :autocomplete="autocomplete"
11
+ :aria-required="required ? true : null"
12
+ :aria-invalid="computedAriaInvalid"
13
+ :value="value"
14
+ :class="[
15
+ plaintext ? 'form-control-plaintext' : 'form-control',
16
+ plaintext ? 'w-100' : '',
17
+ size ? `form-control-${size}` : null,
18
+ computedStateClass
19
+ ]"
20
+ v-bind="$attrs"
21
+ @input="onInput"
22
+ @change="onChange" />
23
+ </template>
24
+
25
+ <script>
26
+ import { guid } from './../../utils'
27
+ import { INPUT_TYPES } from './../../utils/constants'
28
+
29
+ export default {
30
+ name: 'd-form-input',
31
+ props: {
32
+ /**
33
+ * Input type.
34
+ */
35
+ type: {
36
+ type: String,
37
+ default: 'text',
38
+ validator: (v) => INPUT_TYPES.includes(v)
39
+ },
40
+ /**
41
+ * Input value.
42
+ */
43
+ value: {
44
+ type: [String, Number],
45
+ default: ''
46
+ },
47
+ /**
48
+ * Input size.
49
+ */
50
+ size: {
51
+ type: String,
52
+ default: null
53
+ },
54
+ /**
55
+ * Input state. eg: 'valid', 'invalid'
56
+ */
57
+ state: {
58
+ type: [Boolean, String],
59
+ default: null,
60
+ validator: (v) => [null, 'valid', 'invalid', true, false].includes(v)
61
+ },
62
+ /**
63
+ * Input name.
64
+ */
65
+ name: {
66
+ type: String
67
+ },
68
+ /**
69
+ * Input disabled state.
70
+ */
71
+ disabled: {
72
+ type: Boolean,
73
+ default: false
74
+ },
75
+ /**
76
+ * Input required state.
77
+ */
78
+ required: {
79
+ type: Boolean,
80
+ default: false
81
+ },
82
+ /**
83
+ * Input placeholder text.
84
+ */
85
+ placeholder: {
86
+ type: String,
87
+ default: null
88
+ },
89
+ /**
90
+ * Enable or disable field autocomplete.
91
+ */
92
+ autocomplete: {
93
+ type: String,
94
+ default: null
95
+ },
96
+ /**
97
+ * Display as plain text and remove styling.
98
+ */
99
+ plaintext: {
100
+ type: Boolean,
101
+ default: false
102
+ },
103
+ /**
104
+ * Display as read-only.
105
+ */
106
+ readonly: {
107
+ type: Boolean,
108
+ default: false
109
+ },
110
+ /**
111
+ * The input `aria-invalid` attribute.
112
+ */
113
+ ariaInvalid: {
114
+ type: [Boolean, String],
115
+ default: false
116
+ }
117
+ },
118
+ watch: {
119
+ value (newVal) {
120
+ this.setValue(newVal)
121
+ }
122
+ },
123
+ mounted() {
124
+ if (this.value) {
125
+ this.setValue(this.value)
126
+ }
127
+ },
128
+ computed: {
129
+ computedID() {
130
+ return `dr-input-${guid()}`
131
+ },
132
+ computedAriaInvalid() {
133
+ if (!this.ariaInvalid || this.ariaInvalid === 'false') {
134
+ return this.state === 'invalid' ? 'true' : null
135
+ }
136
+
137
+ if (this.ariaInvalid === true) {
138
+ return 'true'
139
+ }
140
+
141
+ return this.ariaInvalid
142
+ },
143
+ computedState() {
144
+ if (this.state === true || this.state === 'valid') {
145
+ return true
146
+ } else if (this.state === false || this.state === 'invalid') {
147
+ return false
148
+ }
149
+
150
+ return null
151
+ },
152
+ computedStateClass() {
153
+ if (this.computedState === true || this.computedState === 'valid') {
154
+ return 'is-valid'
155
+ } else if (this.computedState === false) {
156
+ return 'is-invalid'
157
+ }
158
+
159
+ return null
160
+ }
161
+ },
162
+ methods: {
163
+ setValue(value) {
164
+ this.$refs.input.value = value
165
+ this.$emit('input', value)
166
+ },
167
+ onInput(e) {
168
+ this.setValue(e.target.value)
169
+ },
170
+ onChange(e) {
171
+ this.setValue(e.target.value)
172
+ this.$emit('change', e.target.value)
173
+ }
174
+ }
175
+ }
176
+ </script>
@@ -0,0 +1,110 @@
1
+ # Form Input
2
+
3
+ The form input allows you to create various text style inputs such as `text`, `password`, `email`, `number`, `url`, `search` and more.
4
+
5
+ ## Alias
6
+
7
+ The `<d-form-input>` component is also available as `<d-input>`.
8
+
9
+ ## Basic Input
10
+
11
+ The `<d-form-input>` component is a `text` input by default. However, you can set its type prop to one of the supported types as well: `text`, `password`, `email`, `number`, `url`, `tel`, `search`, `date`, `datetime`, `datetime-local`, `month`, `week`, `time`.
12
+
13
+ :::demo
14
+ ```html
15
+
16
+ <template>
17
+ <div>
18
+ <d-input v-model="inputValue" class="mb-2" />
19
+ <div v-if="inputValue">🤔 So you're saying: {{ inputValue }}</div>
20
+ <div v-else>😃 Waiting for you to say something!</div>
21
+ </div>
22
+ </template>
23
+
24
+ <script>
25
+ export default {
26
+ data: {
27
+ inputValue: ''
28
+ }
29
+ }
30
+ </script>
31
+
32
+ <!-- form-input-1.vue -->
33
+ ```
34
+ :::
35
+
36
+ ## Supported Types
37
+
38
+ The following input types are currently supported.
39
+
40
+ :::demo
41
+ ```html
42
+
43
+ <template>
44
+ <d-container fluid>
45
+ <d-row class="my-1" v-for="type in inputTypes" :key="type">
46
+ <d-col sm="3"><label :for="`type-${type}`">Type {{ type }}:</label></d-col>
47
+ <d-col sm="9"><d-form-input :id="`type-${type}`" :type="type"></d-form-input></d-col>
48
+ </d-row>
49
+ </d-container>
50
+ </template>
51
+
52
+ <script>
53
+ export default {
54
+ data () {
55
+ return {
56
+ inputTypes: ['text', 'password', 'email', 'number', 'url','tel', 'date', 'time']
57
+ }
58
+ }
59
+ }
60
+ </script>
61
+
62
+ <!-- form-input-2.vue -->
63
+ ```
64
+ :::
65
+
66
+ > Note: The `range` and `color` input types are currently not supported.
67
+
68
+ ## Sizing
69
+
70
+ Using the `size` prop, you can change the input size as small (`sm`) or large (`lg`).
71
+
72
+ :::demo
73
+ ```html
74
+
75
+ <div>
76
+ <d-form-input size="sm" type="text" placeholder="I'm small" class="mb-2"></d-form-input>
77
+ <d-form-input type="text" placeholder="I'm normal" class="mb-2"></d-form-input>
78
+ <d-form-input size="lg" type="text" placeholder="I'm large"></d-form-input>
79
+ </div>
80
+
81
+ <!-- form-input-3.vue -->
82
+ ```
83
+ :::
84
+
85
+ ## Validation States
86
+
87
+ Using the `state` prop on the `<d-form-input>` component you can control the input's validation state.
88
+
89
+ The following input states are available:
90
+
91
+ * `invalid` when the input is invalid.
92
+ * `valid` when the use input is valid.
93
+ * `null` when the input should display no validation state (neutral).
94
+
95
+ :::demo
96
+ ```html
97
+
98
+ <div>
99
+ <d-form-input type="text" placeholder="I'm Neutral" class="mb-2"></d-form-input>
100
+ <d-form-input :state="true" type="text" placeholder="I'm Valid" class="mb-2"></d-form-input>
101
+ <d-form-input state="invalid" type="text" placeholder="I'm Invalid"></d-form-input>
102
+ </div>
103
+
104
+ <!-- form-input-4.vue -->
105
+ ```
106
+ :::
107
+
108
+ ## Readonly & Plaintext
109
+
110
+ You can also display the input as readonly or plain text using the `readonly` and `plaintext` props.
@@ -0,0 +1,18 @@
1
+ import { registerComponents, vueUse } from './../../utils'
2
+
3
+ import dFormInput from './FormInput.vue'
4
+
5
+ const components = {
6
+ dFormInput,
7
+ dInput: dFormInput
8
+ }
9
+
10
+ const VuePlugin = {
11
+ install (Vue) {
12
+ registerComponents(Vue, components)
13
+ }
14
+ }
15
+
16
+ vueUse(VuePlugin)
17
+
18
+ export default VuePlugin
@@ -0,0 +1,155 @@
1
+ <template>
2
+ <label :class="[
3
+ 'custom-control',
4
+ 'custom-radio',
5
+ inline ? 'custom-control-inline' : '',
6
+ computedStateClass
7
+ ]">
8
+ <input type="radio"
9
+ ref="check"
10
+ autocomplete="off"
11
+ :aria-required="required ? 'true' : null"
12
+ :id="computedID"
13
+ :class="[ 'custom-control-input', computedStateClass ]"
14
+ :name="name"
15
+ :value="value"
16
+ :disabled="disabled"
17
+ :required="name && required"
18
+ v-model="computedLocalChecked"
19
+ @change="handleChange" />
20
+ <label :for="computedID" class="custom-control-label" aria-hidden="true"></label>
21
+ <span :class="['custom-control-description']">
22
+ <slot />
23
+ </span>
24
+ </label>
25
+ </template>
26
+
27
+ <script>
28
+ import { guid } from '../../utils'
29
+
30
+ export default {
31
+ name: 'd-form-radio',
32
+ model: {
33
+ prop: 'checked',
34
+ event: 'input'
35
+ },
36
+ data() {
37
+ return {
38
+ localChecked: this.checked
39
+ }
40
+ },
41
+ props: {
42
+ /**
43
+ * The radio input name.
44
+ */
45
+ name: {
46
+ type: String
47
+ },
48
+ /**
49
+ * The radio input ID.
50
+ */
51
+ id: {
52
+ type: String,
53
+ default: null
54
+ },
55
+ /**
56
+ * The radio input value.
57
+ */
58
+ value: {
59
+ default: true
60
+ },
61
+ /**
62
+ * The disabled state.
63
+ */
64
+ disabled: {
65
+ type: Boolean
66
+ },
67
+ /**
68
+ * The required state.
69
+ */
70
+ required: {
71
+ type: Boolean,
72
+ default: false
73
+ },
74
+ /**
75
+ * The checked state.
76
+ */
77
+ checked: {
78
+ type: [Boolean, String, Array]
79
+ },
80
+ /**
81
+ * The validation state.
82
+ */
83
+ state: {
84
+ type: [Boolean, String],
85
+ default: null
86
+ },
87
+ /**
88
+ * Whether the radio should be displayed inline, or not.
89
+ */
90
+ inline: {
91
+ type: Boolean,
92
+ default: false
93
+ }
94
+ },
95
+ computed: {
96
+ computedLocalChecked: {
97
+ get() {
98
+ return this.localChecked
99
+ },
100
+
101
+ set(val) {
102
+ this.localChecked = val
103
+ }
104
+ },
105
+ computedID() {
106
+ return this.id || `dr-radio-${guid()}`
107
+ },
108
+ computedState() {
109
+ if (this.state === true || this.state === 'valid') {
110
+ return true
111
+ }
112
+
113
+ if (this.state === false || this.state === 'invalid') {
114
+ return false
115
+ }
116
+
117
+ return null
118
+ },
119
+ computedStateClass() {
120
+ if (this.computedState === true) {
121
+ return 'is-valid'
122
+ }
123
+
124
+ if (this.computedState === false) {
125
+ return 'is-invalid'
126
+ }
127
+
128
+ return null
129
+ }
130
+ },
131
+ watch: {
132
+ computedLocalChecked(newVal, oldVal) {
133
+ if (newVal == oldVal) {
134
+ return
135
+ }
136
+
137
+ this.$emit('input', newVal)
138
+ },
139
+
140
+ checked(newVal, oldVal) {
141
+ if (newVal == oldVal) {
142
+ return
143
+ }
144
+
145
+ this.computedLocalChecked = newVal
146
+ },
147
+ },
148
+
149
+ methods: {
150
+ handleChange(e) {
151
+ this.$emit('change', e.target.checked ? this.value : null)
152
+ }
153
+ }
154
+ }
155
+ </script>
@@ -0,0 +1,61 @@
1
+ # Form Radio
2
+
3
+ The `<d-form-radio>` component is a wrapper over Bootstrap's [custom radio component](https://getbootstrap.com/docs/4.1/components/forms/#checkboxes-and-radios-1).
4
+
5
+ ## Alias
6
+
7
+ The `<d-form-radio>` component is also available as `<d-radio>`.
8
+
9
+ ## Basic Demo
10
+
11
+ :::demo
12
+ ```html
13
+ <template>
14
+ <div>
15
+ <label>Select your favorite fruits:</label>
16
+ <d-form-radio v-model="selected" value="orange">Orange</d-form-radio>
17
+ <d-form-radio v-model="selected" value="lemon">Lemon</d-form-radio>
18
+ <d-form-radio v-model="selected" value="kiwi">Kiwi</d-form-radio>
19
+ <p>Selected Status: {{ selected }}</p>
20
+ </div>
21
+ </template>
22
+
23
+ <script>
24
+ export default {
25
+ data() {
26
+ return {
27
+ selected: 'orange'
28
+ }
29
+ }
30
+ }
31
+ </script>
32
+
33
+ <!-- radio-1.vue -->
34
+ ```
35
+ :::
36
+
37
+ ## Inline Display
38
+
39
+ Radios can also be displayed inline using the `inline` prop.
40
+
41
+ :::demo
42
+ ```html
43
+
44
+ <div>
45
+ <label class="d-block">Select your favorite sport</label>
46
+ <d-form-radio inline name="fav_sport" value="basketball">Basketball</d-form-radio>
47
+ <d-form-radio inline name="fav_sport" value="football">Football</d-form-radio>
48
+ <d-form-radio inline name="fav_sport" value="tennis">Tennis</d-form-radio>
49
+ </div>
50
+
51
+ <!-- radio-2.vue -->
52
+ ```
53
+ :::
54
+
55
+ ## Missing Features
56
+
57
+ The following radio features are currently not supported, but available on the [roadmap](/roadmap).
58
+
59
+ * Possibility of creating plain radios.
60
+ * Radio groups.
61
+ * Button style radios.
@@ -0,0 +1,18 @@
1
+ import { registerComponents, vueUse } from './../../utils'
2
+
3
+ import dFormRadio from './FormRadio.vue'
4
+
5
+ const components = {
6
+ dFormRadio,
7
+ dRadio: dFormRadio
8
+ }
9
+
10
+ const VuePlugin = {
11
+ install (Vue) {
12
+ registerComponents(Vue, components)
13
+ }
14
+ }
15
+
16
+ vueUse(VuePlugin)
17
+
18
+ export default VuePlugin