Skip to content

Commit

Permalink
fix: listbox options and inputs layout and styling
Browse files Browse the repository at this point in the history
  • Loading branch information
danielstorey committed Sep 12, 2024
1 parent db33df1 commit 30bf8f5
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 45 deletions.
2 changes: 1 addition & 1 deletion src/components/InputAffix/InputAffix.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<div class="concrete__input-affix h-full relative inline-flex items-center text-inherit px-3 border border-inherit whitespace-nowrap bg-black bg-opacity-[0.03]"
<div class="concrete__input-affix relative inline-flex items-center text-inherit px-3 border border-inherit whitespace-nowrap bg-black bg-opacity-[0.03]"
:class="[sizeClass, typeClass, userClass]">
<slot />
</div>
Expand Down
62 changes: 22 additions & 40 deletions src/components/Listbox/Listbox.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<div :class="['relative', disabledClass]">
<div class="inline-flex w-full">
<div
class="relative z-0 inline-flex w-full items-center"
class="relative z-0 inline-flex w-full"
:class="inputColorClass"
>
<CInputAffix v-if="prefix" type="prefix" v-html="prefix" />
Expand All @@ -41,7 +41,7 @@
cursorClass,
open && 'border-indigo-light',
]"
class="!flex items-center"
class="!flex items-center pr-8"
>
<slot name="buttonPrefix" />
<span
Expand All @@ -51,21 +51,8 @@
{{ selectedLabel || placeholder }}
</span>

<span
class="
absolute
inset-y-0
right-0
flex
items-center
pr-2
pointer-events-none
"
>
<ChevronUpDownIcon
:class="[iconColorClass, iconSizeClass]"
aria-hidden="true"
/>
<span class=" absolute inset-y-0 right-0 flex items-center pr-2 pointer-events-none">
<ChevronUpDownIcon :class="[iconColorClass, iconSizeClass]" aria-hidden="true" />
</span>
</ListboxButton>
<input type="hidden" :value="selectedLabel" data-selected />
Expand Down Expand Up @@ -121,7 +108,7 @@
name="optionPrefix"
:option="option"
/>
{{ option.label }}
{{ formatter(option.label || option.value) }}
</div>
</li>
</ListboxOption>
Expand Down Expand Up @@ -202,6 +189,10 @@ const isDirty = ref(false);
const localValue = ref(null);
const buttonRef = ref(null);
const formatter = (value) => {
return props.formatter ? props.formatter(value) : value;
}
const selectedValue = computed({
get() {
return getInputValue(props);
Expand All @@ -214,6 +205,14 @@ const selectedValue = computed({
},
});
const getOptionFromValue = (value) => {
const item = localOptions.value.find((option) => {
return isEqual(option.value, value);
});
return formatter(item?.label);
}
const isDisabled = computed(() => {
return props.disabled || !localOptions.value.length;
});
Expand All @@ -228,41 +227,24 @@ const localOptions = computed(() => {
const options = getInputIdToOptions(props);
return options.map((option) => {
const opt = isPlainObject(option)
return isPlainObject(option)
? option
: { label: option, value: option };
return props.formatter
? { ...opt, label: props.formatter(opt.label || opt.value) }
: opt;
});
});
const selectedLabel = computed(() => {
let sv = selectedValue.value;
const { formatter } = props;
if (!props.multiple) {
if (formatter) {
return formatter(sv);
} else {
return isPlainObject(sv) ? sv.label : sv;
}
return getOptionFromValue(sv);
}
const arrVal = Array.isArray(sv) ? sv : [sv];
const labels = arrVal
return arrVal
.filter((selectedItem) => selectedItem != null)
.map((selectedItem) => {
const item = localOptions.value.find((option) => {
return isEqual(option.value, selectedItem);
});
if (!item) return;
return formatter ? formatter(item) : item.label;
});
return labels.join(', ');
.map(getOptionFromValue)
.join(', ');
});
const optionsSizeClass = {
Expand Down
2 changes: 1 addition & 1 deletion src/components/NumericInput/NumericInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
}"
:class="inputColorClass"
>
<div class="flex w-full h-full relative concrete__numeric-input" :class="[inputColorClass, disabledClass]">
<div class="flex w-full relative concrete__numeric-input" :class="[inputColorClass, disabledClass]">
<CInputAffix v-if="prefix" type="prefix" v-html="prefix" />
<slot name="prefix" class="z-10" />
<input
Expand Down
2 changes: 1 addition & 1 deletion src/components/TextArea/TextArea.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
}"
:class="inputColorClass"
>
<div class="flex w-full h-full" :class="[colorClass, disabledClass]">
<div class="flex w-full" :class="[colorClass, disabledClass]">
<CInputAffix v-if="prefix" type="prefix" v-html="prefix" />
<slot name="prefix" class="z-10"/>
<textarea
Expand Down
2 changes: 1 addition & 1 deletion src/components/TextInput/TextInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
}"
:class="inputColorClass"
>
<div class="flex w-full h-full concrete__text-input" :class="[inputColorClass, disabledClass]">
<div class="flex w-full concrete__text-input" :class="[inputColorClass, disabledClass]">
<CInputAffix v-if="prefix" type="prefix" v-html="prefix" />
<slot name="prefix" class="z-10"/>

Expand Down
2 changes: 1 addition & 1 deletion src/composables/styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export const useInputColorClassValue = (props) => {
const status = useConcreteForms().getInputStatus(props);

return computed(() => {
return colorClassMap[status.value?.color]
return colorClassMap[status.value?.color] || colorClassMap.default;
});
}

Expand Down

0 comments on commit 30bf8f5

Please sign in to comment.