app.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. <template>
  2. <div id="app">
  3. <img src="./assets/logo.png">
  4. <h3>Vue Monthly Picker</h3>
  5. <div class="demo-component">
  6. <vue-monthly-picker
  7. :inputClass="{'input': isDisplayInput}"
  8. :disabled="isDisable"
  9. :monthLabels="locale"
  10. :clearOption="clearOption"
  11. :min="min"
  12. :max="max"
  13. @selected="handleSelect"
  14. v-model="selectedMonth"
  15. :alignment="alignment"
  16. :selectedBackgroundColor="selectedBackgroundColor">
  17. </vue-monthly-picker>
  18. </div>
  19. <div class="columns option-list">
  20. <div class="column is-3">
  21. <b-field label="Disabled" expanded>
  22. <b-checkbox v-model="isDisable">
  23. {{ isDisable ? 'Disabled': 'Enable'}}
  24. </b-checkbox>
  25. </b-field>
  26. </div>
  27. <div class="column is-3">
  28. <b-field label="Range" expanded>
  29. <b-checkbox v-model="isLimitRange">
  30. {{ rangeDisplay }}
  31. </b-checkbox>
  32. </b-field>
  33. </div>
  34. <div class="column is-3">
  35. <b-field label="Display" expanded position="is-centered">
  36. <b-switch v-model="isDisplayInput"
  37. true-value="Input"
  38. false-value="Label">
  39. {{ isDisplayInput? 'Input': 'Label' }}
  40. </b-switch>
  41. </b-field>
  42. </div>
  43. <div class="column is-3">
  44. <b-field label="Clear icon" expanded>
  45. <b-checkbox v-model="clearOption">
  46. {{ clearOption ? 'Enable': 'Disabled'}}
  47. </b-checkbox>
  48. </b-field>
  49. </div>
  50. </div>
  51. <div class="columns">
  52. <div class="column is-4">
  53. <b-field label="Localization" expanded>
  54. <b-select placeholder="Select a language" v-model="locale">
  55. <option
  56. v-for="option in options"
  57. :value="option.monthLabels"
  58. :key="option.id">
  59. {{ option.title }}
  60. </option>
  61. </b-select>
  62. </b-field>
  63. </div>
  64. <div class="column is-4">
  65. <b-field label="Alignment" expanded>
  66. <b-select placeholder="Select an alignment" v-model="alignment">
  67. <option
  68. v-for="alignment in alignments"
  69. :value="alignment"
  70. :key="alignment">
  71. {{ alignment }}
  72. </option>
  73. </b-select>
  74. </b-field>
  75. </div>
  76. <div class="column is-4">
  77. <b-field label="Selected background color" expanded>
  78. <b-select placeholder="Select an color" v-model="selectedBackgroundColor">
  79. <option
  80. v-for="color in colorExamples"
  81. :value="color"
  82. :key="color">
  83. {{ color }}
  84. </option>
  85. </b-select>
  86. </b-field>
  87. </div>
  88. </div>
  89. </div>
  90. </template>
  91. <script>
  92. import moment from 'moment'
  93. import VueMonthlyPicker from './lib'
  94. export default {
  95. name: 'app',
  96. data () {
  97. return {
  98. selectedMonth: moment(),
  99. isDisable: false,
  100. isDisplayInput: true,
  101. locale: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
  102. alignment: 'left',
  103. selectedBackgroundColor: 'blue',
  104. options: [
  105. {
  106. id: 1,
  107. title: 'English',
  108. monthLabels: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
  109. },
  110. {
  111. id: 2,
  112. title: 'Japanese',
  113. monthLabels: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月']
  114. },
  115. {
  116. id: 3,
  117. title: 'Korean',
  118. monthLabels: ['1월', '2월', '3월', '4월', '5월', '6월', '7월', '8월', '9월', '10월', '11월', '12월']
  119. }
  120. ],
  121. alignments: ['left', 'center', 'right'],
  122. colorExamples: ['blue', 'red', 'black'],
  123. min: null,
  124. max: null,
  125. isLimitRange: false,
  126. clearOption: true
  127. }
  128. },
  129. computed: {
  130. rangeDisplay () {
  131. if (!this.min || !this.max) {
  132. return 'Disabled'
  133. }
  134. return this.min.format('YYYY/MM') + '-' + this.max.format('YYYY/MM')
  135. }
  136. },
  137. watch: {
  138. isLimitRange (newValue) {
  139. if (newValue) {
  140. this.setSelectRange(moment().subtract(6, 'months'), moment().add(6, 'months'))
  141. } else {
  142. this.setSelectRange(null, null)
  143. }
  144. }
  145. },
  146. methods: {
  147. handleSelect (value) {
  148. console.log('Select', value)
  149. },
  150. setSelectRange (min, max) {
  151. this.min = min
  152. this.max = max
  153. }
  154. },
  155. components: {
  156. VueMonthlyPicker
  157. }
  158. }
  159. </script>
  160. <style>
  161. #app {
  162. font-family: 'Avenir', Helvetica, Arial, sans-serif;
  163. -webkit-font-smoothing: antialiased;
  164. -moz-osx-font-smoothing: grayscale;
  165. text-align: center;
  166. color: #2c3e50;
  167. margin-top: 60px;
  168. }
  169. .demo-component {
  170. width: 250px;
  171. margin: auto;
  172. }
  173. .control-group {
  174. margin-top: 100px;
  175. }
  176. .control {
  177. text-align: center;
  178. }
  179. .option-list {
  180. margin-top: 20px;
  181. }
  182. </style>