Skip to content

Commit

Permalink
feat: allow for subtitles on input fields
Browse files Browse the repository at this point in the history
  • Loading branch information
meenahoda authored and Meena Brend committed Aug 22, 2022
1 parent ede263d commit 4600ec6
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 9 deletions.
4 changes: 3 additions & 1 deletion lib/builders/Input.ChoiceSet.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ module.exports = function (definition, options) {
spacing,
separator,
title,
subtitle,
tooltip,
icon,
clearable,
Expand Down Expand Up @@ -49,7 +50,7 @@ module.exports = function (definition, options) {
const builder = new ComponentBuilder(definition)
const div = builder.addTag('div')

applyTitleLabel({ source: div, title, icon, tooltip })
applyTitleLabel({ source: div, title, icon, tooltip, subtitle })
// const labelDiv = div.addChildTag('div').addAttribute('class', 'form-label')
// if (icon) labelDiv.addChildTag('q-icon').addAttribute('name', icon).addAttribute('size', '28px').addAttribute('class', 'q-ml-sm')
// if (title) labelDiv.addChildTag('span').content(title).addAttribute('class', 'q-ml-sm')
Expand Down Expand Up @@ -85,6 +86,7 @@ module.exports = function (definition, options) {
.addAttribute(':label', 'opt.label')
.addAttribute(':color', `opt.color ? ${inspect(COLORS)}[opt.color] || 'standard' : 'standard'`)
.addAttribute('v-if', showWhen('opt.disable'))
.addAttribute('size', 'lg')
.bindToModel(definition)

_onChangeResetDataPaths(opt, onChangeResetDataPaths)
Expand Down
3 changes: 2 additions & 1 deletion lib/builders/Input.FileUpload.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ module.exports = function (definition, options) {
spacing,
separator,
title,
subtitle,
isMultiUpload,
onUploadEndpoint,
additionalFields,
Expand All @@ -29,7 +30,7 @@ module.exports = function (definition, options) {

const div = builder.addTag('div')

applyTitleLabel({ source: div, title, icon, tooltip })
applyTitleLabel({ source: div, title, icon, tooltip, subtitle })

const endpoint = onUploadEndpoint ? onUploadEndpoint.name : null

Expand Down
5 changes: 3 additions & 2 deletions lib/builders/Text-field.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ module.exports = function TextField (definition, elementOptions, additionalOptio
editor,
tooltip,
mask,
fillMask
fillMask,
subtitle
} = definition

const builder = new ComponentBuilder(definition)
Expand All @@ -26,7 +27,7 @@ module.exports = function TextField (definition, elementOptions, additionalOptio
const label = definition.title || additionalOptions.title // || placeholder // TODO: Needs to be better, placeholder as well.
// const type = definition.type || additionalOptions.type

applyTitleLabel({ source: div, title: label, icon, tooltip })
applyTitleLabel({ source: div, title: label, icon, tooltip, subtitle })

let input
if (editor) {
Expand Down
24 changes: 19 additions & 5 deletions lib/utils/apply-title-label.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
const applyTooltip = require('./apply-tooltip')

module.exports = function ({ source, title, tooltip, icon }) {
if (!icon && !title && !tooltip) {
module.exports = function ({ source, title, tooltip, icon, subtitle }) {
if (!icon && !title && !subtitle && !tooltip) {
return
}

const labelDiv = source
.addChildTag('div')
.addAttribute('class', 'form-label q-ml-sm')
.addAttribute('class', 'q-ml-sm')

const span = labelDiv
.addChildTag('span')
.addAttribute('style', 'display: block;')
.addChildTag('div')

let tooltipSource = span

Expand All @@ -26,9 +25,24 @@ module.exports = function ({ source, title, tooltip, icon }) {
if (title) {
tooltipSource = span
.addChildTag('span')
.addAttribute('class', 'form-label')
.content(title)
}

if (subtitle) {
const subtitleDivClasses = ['form-sublabel']
const subtitleDiv = labelDiv
.addChildTag('div')
.content(subtitle)

if (title) {
subtitleDivClasses.push('q-mt-sm')
}

subtitleDiv
.addAttribute('class', subtitleDivClasses.join(' '))
}

if (tooltip) {
applyTooltip({ source: tooltipSource, tooltip })
}
Expand Down

0 comments on commit 4600ec6

Please sign in to comment.