button.js
5 years ago
collapse.js
5 years ago
component-wrapper.js
5 years ago
list-table-heading.js
5 years ago
list-table-item.js
5 years ago
list-table.js
5 years ago
notice-component.js
5 years ago
notice.js
5 years ago
pagination.js
5 years ago
popup.js
5 years ago
repeater-item.js
5 years ago
repeater.js
5 years ago
tabs-panel.js
5 years ago
tabs.js
5 years ago
title.js
5 years ago
button.js
121 lines
| 1 | import { oneOf } from '../../utils/assist'; |
| 2 | import { checkConditions } from '../../mixins/check-conditions'; |
| 3 | |
| 4 | const Button = { |
| 5 | name: 'cx-vui-button', |
| 6 | template: '#cx-vui-button', |
| 7 | mixins: [ checkConditions ], |
| 8 | props: { |
| 9 | type: { |
| 10 | validator ( value ) { |
| 11 | return oneOf( value, [ 'button', 'submit', 'reset' ] ); |
| 12 | }, |
| 13 | default: 'button' |
| 14 | }, |
| 15 | buttonStyle: { |
| 16 | validator ( value ) { |
| 17 | return oneOf( value, [ 'default', 'accent', 'link-accent', 'link-error', 'accent-border', 'default-border' ] ); |
| 18 | }, |
| 19 | default: 'default' |
| 20 | }, |
| 21 | size: { |
| 22 | validator ( value ) { |
| 23 | return oneOf( value, [ 'default', 'mini', 'link' ] ); |
| 24 | }, |
| 25 | default: 'default' |
| 26 | }, |
| 27 | disabled: { |
| 28 | type: Boolean, |
| 29 | default: false |
| 30 | }, |
| 31 | loading: { |
| 32 | type: Boolean, |
| 33 | default: false |
| 34 | }, |
| 35 | customCss: { |
| 36 | type: String, |
| 37 | }, |
| 38 | url: { |
| 39 | type: String, |
| 40 | }, |
| 41 | target: { |
| 42 | type: String, |
| 43 | }, |
| 44 | tagName: { |
| 45 | validator( value ) { |
| 46 | return oneOf( value, [ 'a', 'button' ] ); |
| 47 | }, |
| 48 | default: 'button' |
| 49 | }, |
| 50 | elementId: { |
| 51 | type: String |
| 52 | }, |
| 53 | conditions: { |
| 54 | type: Array, |
| 55 | default() { |
| 56 | return []; |
| 57 | } |
| 58 | }, |
| 59 | }, |
| 60 | data() { |
| 61 | return { |
| 62 | baseClass: 'cx-vui-button', |
| 63 | }; |
| 64 | }, |
| 65 | computed: { |
| 66 | classesList() { |
| 67 | |
| 68 | let classesList = [ |
| 69 | this.baseClass, |
| 70 | this.baseClass + '--style-' + this.buttonStyle, |
| 71 | this.baseClass + '--size-' + this.size, |
| 72 | ]; |
| 73 | |
| 74 | if ( this.loading ) { |
| 75 | classesList.push( this.baseClass + '--loading' ); |
| 76 | } |
| 77 | |
| 78 | if ( this.disabled ) { |
| 79 | classesList.push( this.baseClass + '--disabled' ); |
| 80 | } |
| 81 | |
| 82 | if ( this.customCss ) { |
| 83 | classesList.push( this.customCss ); |
| 84 | } |
| 85 | |
| 86 | return classesList; |
| 87 | }, |
| 88 | tagAtts() { |
| 89 | |
| 90 | let atts = {}; |
| 91 | |
| 92 | if ( 'a' === this.tagName ) { |
| 93 | |
| 94 | if ( this.url ) { |
| 95 | atts.href = this.url; |
| 96 | } |
| 97 | |
| 98 | if ( this.target ) { |
| 99 | atts.target = this.target; |
| 100 | } |
| 101 | |
| 102 | } else { |
| 103 | atts.type = this.type; |
| 104 | } |
| 105 | |
| 106 | return atts; |
| 107 | } |
| 108 | }, |
| 109 | methods: { |
| 110 | handleClick() { |
| 111 | |
| 112 | if ( this.loading || this.disabled ) { |
| 113 | return; |
| 114 | } |
| 115 | |
| 116 | this.$emit( 'click', event ); |
| 117 | } |
| 118 | }, |
| 119 | }; |
| 120 | |
| 121 | export default Button; |