Skip to content

Commit

Permalink
[xprototype#4/feature] Add radio component
Browse files Browse the repository at this point in the history
  • Loading branch information
wilcorrea committed Mar 29, 2019
1 parent 5f78ff8 commit e8ee6dc
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 40 deletions.
1 change: 1 addition & 0 deletions quasar.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ module.exports = function (context) {
'QCheckbox',
'QSelect',
'QRadio',
'QOptionGroup',
'QCard',
'QCardSection',
'QCardActions',
Expand Down
85 changes: 50 additions & 35 deletions src/app/Prototype/Prototype/FieldIs.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,81 +23,96 @@ export default {
},

/**
* @param {Boolean} upperCase
* @param {Object} attrs
* @returns {Prototype}
*/
fieldIsInput (upperCase = true) {
fieldIsInput (attrs = {}) {
this.setComponent('input')
return this.setAttrs({ upperCase })
},

/**
* @returns {Prototype}
*/
fieldIsNumber () {
this.setComponent('input')
this.setAttrs({ type: 'number' })
this.setAttrs({ ...attrs })
return this
},

/**
* @param {Array} options
* @param {Object} attrs
* @returns {Prototype}
*/
fieldIsSelect (options) {
this.setComponent('select')
this.setAttrs({ options })
this.setLayout({
tableFormat (value/* , row */) {
return options.find((option) => option.value === value).label
}
})
fieldIsNumber (attrs = {}) {
this.setComponent('number')
this.setAttrs({ ...attrs })
return this
},

/**
* @param {Number} rows
* @param {Object} attrs
* @returns {Prototype}
*/
fieldIsText (rows = 3) {
this.setComponent('text')
return this.setAttrs({ rows })
fieldIsPassword (attrs = {}) {
this.setComponent('password')
this.setAttrs({ ...attrs })
return this
},

/**
* @param {Object} attrs
* @returns {Prototype}
*/
fieldIsPassword () {
return this.setComponent('password')
fieldIsEmail (attrs = {}) {
this.setComponent('email')
this.setAttrs({ ...attrs })
return this
},

/**
* @param {Number} rows
* @param {Object} attrs
* @returns {Prototype}
*/
fieldIsRadio () {
return this.setComponent('radio')
fieldIsText (rows = 4, attrs = {}) {
this.setComponent('text')
this.setAttrs({ ...attrs, rows })
return this
},

/**
* @param {Object} attrs
* @returns {Prototype}
*/
fieldIsHtml () {
return this.setComponent('html')
fieldIsCheckbox (attrs = {}) {
this.setComponent('checkbox')
this.setAttrs({ ...attrs })
return this
},

/**
* @param {Array} options
* @param {Object} attrs
* @returns {Prototype}
*/
fieldIsFile () {
return this.setComponent('file')
fieldIsRadio (options = undefined, attrs = {}) {
if (!Array.isArray(options)) {
options = [
{ value: true, label: 'Yes' },
{ value: false, label: 'No' }
]
}
this.setComponent('radio')
this.setAttrs({ ...attrs, options })
return this
},

/**
* @param {Array} options
* @param {Object} attrs
* @returns {Prototype}
*/
fieldIsEmail () {
this.setComponent('input')
this.setAttrs({ type: 'password' })
fieldIsSelect (options, attrs = {}) {
this.setComponent('select')
this.setAttrs({ ...attrs, options })
this.setLayout({
tableFormat (value/* , row */) {
return options.find((option) => option.value === value).label
}
})
return this
}
}
34 changes: 29 additions & 5 deletions src/config/app/components.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,46 @@ export default {
is: 'q-input',
attrs: { ...attrs }
},
text: {
number: {
is: 'q-input',
attrs: {
type: 'textarea',
rows: 4,
type: 'number',
...attrs
}
},
password: {
is: 'q-input',
attrs: { ...attrs }
attrs: {
type: 'number',
...attrs
}
},
image: {
email: {
is: 'q-input',
attrs: {
type: 'email',
...attrs
}
},
text: {
is: 'q-input',
attrs: {
type: 'textarea',
rows: 4,
...attrs
}
},
checkbox: {
is: 'q-checkbox',
attrs: { ...attrs }
},
radio: {
is: 'q-option-group',
attrs: {
inline: true,
...attrs
}
},
select: {
is: 'q-select',
attrs: { ...attrs }
Expand Down

0 comments on commit e8ee6dc

Please sign in to comment.