diff --git a/CHANGELOG.md b/CHANGELOG.md index 9a22f2d2d5..684a8bf312 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,8 @@ ### Changes * The `pickerOptions` sub property of a color field's configuration has been merged with it's parent `options` object. +* Reworks `inline` and `micro` UI of some fields (color, range, select). Improve global inline style. +* Makes the range input being a number all the time instead of a string that we convert manually. ## 4.11.2 (2024-12-29) diff --git a/modules/@apostrophecms/asset/lib/globalIcons.js b/modules/@apostrophecms/asset/lib/globalIcons.js index 709f2ce368..9b6c5334ae 100644 --- a/modules/@apostrophecms/asset/lib/globalIcons.js +++ b/modules/@apostrophecms/asset/lib/globalIcons.js @@ -61,8 +61,8 @@ module.exports = { 'format-list-numbered-icon': 'FormatListNumbered', 'format-quote-close-icon': 'FormatQuoteClose', 'format-strikethrough-variant-icon': 'FormatStrikethroughVariant', - 'format-superscript-icon': 'FormatSuperscript', 'format-subscript-icon': 'FormatSubscript', + 'format-superscript-icon': 'FormatSuperscript', 'format-text-icon': 'FormatText', 'format-underline-icon': 'FormatUnderline', 'help-circle-icon': 'HelpCircle', @@ -122,5 +122,6 @@ module.exports = { 'unfold-more-horizontal-icon': 'UnfoldMoreHorizontal', 'video-icon': 'Video', 'view-column-icon': 'ViewColumn', + 'water-off-icon': 'WaterOff', 'web-icon': 'Web' }; diff --git a/modules/@apostrophecms/color-field/ui/apos/components/AposInputColor.vue b/modules/@apostrophecms/color-field/ui/apos/components/AposInputColor.vue index 8ec6be5dbd..f1da01d3fd 100644 --- a/modules/@apostrophecms/color-field/ui/apos/components/AposInputColor.vue +++ b/modules/@apostrophecms/color-field/ui/apos/components/AposInputColor.vue @@ -8,6 +8,13 @@ > @@ -42,8 +45,13 @@ @@ -54,16 +62,13 @@ export default { align-items: center; } - .apos-input-color__clear { - margin-left: 10px; - } - .apos-input-color__info { - @include type-base; + margin-left: 15px; - & { - margin-left: 15px; - color: var(--a-text-primary); + &--inline { + margin-right: 5px; + margin-left: 0; } } + diff --git a/modules/@apostrophecms/color-field/ui/apos/lib/AposColorInfo.vue b/modules/@apostrophecms/color-field/ui/apos/lib/AposColorInfo.vue new file mode 100644 index 0000000000..41f4eb82ac --- /dev/null +++ b/modules/@apostrophecms/color-field/ui/apos/lib/AposColorInfo.vue @@ -0,0 +1,62 @@ + + + + + diff --git a/modules/@apostrophecms/color-field/ui/apos/logic/AposInputColor.js b/modules/@apostrophecms/color-field/ui/apos/logic/AposInputColor.js index d294107d50..c511c8b639 100644 --- a/modules/@apostrophecms/color-field/ui/apos/logic/AposInputColor.js +++ b/modules/@apostrophecms/color-field/ui/apos/logic/AposInputColor.js @@ -16,6 +16,12 @@ export default { }; }, computed: { + isMicro() { + return this.modifiers.includes('micro'); + }, + isInline() { + return this.modifiers.includes('inline'); + }, pickerValue() { return this.next || this.defaultValue; }, @@ -33,13 +39,6 @@ export default { options() { return this.field?.options || {}; }, - valueLabel() { - if (this.next) { - return this.next; - } else { - return 'None Selected'; - } - }, classList() { return [ 'apos-input-wrapper', diff --git a/modules/@apostrophecms/schema/ui/apos/components/AposInputRange.vue b/modules/@apostrophecms/schema/ui/apos/components/AposInputRange.vue index 1dffca0090..353f351cad 100644 --- a/modules/@apostrophecms/schema/ui/apos/components/AposInputRange.vue +++ b/modules/@apostrophecms/schema/ui/apos/components/AposInputRange.vue @@ -6,12 +6,30 @@ :uid="uid" :display-options="displayOptions" > + @@ -190,6 +192,10 @@ export default { } } +.apos-field__label-meta:empty { + display: none; +} + .apos-field__help { @include type-base; @@ -235,18 +241,22 @@ export default { .apos-field--inline { display: flex; align-items: center; + justify-content: space-between; .apos-field__label { margin-bottom: 0; } - .apos-field__info, - .apos-input-wrapper { - width: 48%; + .apos-field__info { + margin-right: 30px; } .apos-field__info { - margin-right: 4%; + flex-shrink: 1; + } + + .apos-input-wrapper { + flex-grow: 1; } &.apos-field--range { diff --git a/modules/@apostrophecms/schema/ui/apos/logic/AposInputRange.js b/modules/@apostrophecms/schema/ui/apos/logic/AposInputRange.js index 5ca16fd01a..f2fbd4b4df 100644 --- a/modules/@apostrophecms/schema/ui/apos/logic/AposInputRange.js +++ b/modules/@apostrophecms/schema/ui/apos/logic/AposInputRange.js @@ -5,10 +5,14 @@ export default { mixins: [ AposInputMixin ], data() { return { + next: this.initNext(), unit: this.field.unit || '' }; }, computed: { + isMicro() { + return this.modifiers.includes('micro'); + }, minLabel() { return this.field.min + this.unit; }, @@ -21,27 +25,26 @@ export default { isSet() { // Detect whether or not a range is currently unset // Use this flag to hide/show UI elements - if (this.next >= this.field.min) { + if (typeof this.next === 'number' && this.next >= this.field.min) { return true; } else { return false; } } }, - mounted() { - // The range spec defaults to a value of midway between the min and max - // Example: a range with an unset value and a min of 0 and max of 100 will become 50 - // This does not allow ranges to go unset :( - if (!this.next && this.next !== 0) { - this.unset(); - } - }, methods: { - // Default to a value outside the range when no def is defined, - // to be used as a flag. - // The value will be set to null later in validation + initNext() { + if (this.modelValue && typeof this.modelValue.data === 'number') { + return this.modelValue.data; + } + + return this.getDefault(); + }, unset() { - this.next = typeof this.field.def === 'number' + this.next = this.getDefault(); + }, + getDefault() { + return typeof this.field.def === 'number' ? this.field.def : this.field.min - 1; }, @@ -52,9 +55,6 @@ export default { } } return false; - }, - convert(value) { - return parseFloat(value); } } }; diff --git a/modules/@apostrophecms/schema/ui/apos/logic/AposInputWrapper.js b/modules/@apostrophecms/schema/ui/apos/logic/AposInputWrapper.js index 7b286fdc16..d642a72781 100644 --- a/modules/@apostrophecms/schema/ui/apos/logic/AposInputWrapper.js +++ b/modules/@apostrophecms/schema/ui/apos/logic/AposInputWrapper.js @@ -143,6 +143,9 @@ export default { data: meta[namespace] || {} }; }); + }, + hasExtraInfo() { + return this.$slots.info; } }, mounted: function () { diff --git a/modules/@apostrophecms/schema/ui/apos/logic/AposSchema.js b/modules/@apostrophecms/schema/ui/apos/logic/AposSchema.js index 076e69e4c0..9341dd8097 100644 --- a/modules/@apostrophecms/schema/ui/apos/logic/AposSchema.js +++ b/modules/@apostrophecms/schema/ui/apos/logic/AposSchema.js @@ -53,12 +53,18 @@ export default { return getConditionTypesObject(); } }, + // Modifiers applied to all fields modifiers: { type: Array, default() { return []; } }, + // Modifiers applied to specified field types + fieldModifiers: { + type: Object, + default: () => ({}) + }, triggerValidation: Boolean, utilityRail: { type: Boolean, @@ -128,10 +134,7 @@ export default { data: this.modelValue.data[item.name] }, serverError: this.serverErrors && this.serverErrors[item.name], - modifiers: [ - ...(this.modifiers || []), - ...(item.modifiers || []) - ] + modifiers: this.computeModifiers(item) } }; }, {}); @@ -339,6 +342,10 @@ export default { generateItemUniqueKey(field) { return `${field.name}:${field._id ?? ''}:${this.modelValue?.data?._id ?? ''}`; + }, + computeModifiers(field) { + const fieldModifiers = this.fieldModifiers[field.type] || this.modifiers; + return [ ...new Set(fieldModifiers.concat(field.modifiers || [])) ]; } } }; diff --git a/modules/@apostrophecms/ui/ui/apos/scss/global/_inputs.scss b/modules/@apostrophecms/ui/ui/apos/scss/global/_inputs.scss index 3521271473..5014fd6f04 100644 --- a/modules/@apostrophecms/ui/ui/apos/scss/global/_inputs.scss +++ b/modules/@apostrophecms/ui/ui/apos/scss/global/_inputs.scss @@ -21,7 +21,7 @@ // Some browser styles set `textarea` to monospace. resize: none; } - + &::placeholder { color: var(--a-base-4); font-style: italic; @@ -106,7 +106,7 @@ .apos-field.apos-field--micro { .apos-input { - padding: 10px; + padding: 7px; font-size: var(--a-type-small); } @@ -115,6 +115,7 @@ } .apos-field__label { + margin-bottom: 7px; font-size: var(--a-type-small); font-weight: 500; }