diff --git a/packages/vuetify/src/labs/VColorInput/VColorInput.tsx b/packages/vuetify/src/labs/VColorInput/VColorInput.tsx index 3eeead7a68a..d9dcf1b5969 100644 --- a/packages/vuetify/src/labs/VColorInput/VColorInput.tsx +++ b/packages/vuetify/src/labs/VColorInput/VColorInput.tsx @@ -1,3 +1,6 @@ +// Styles +import './VColorInput.sass' + // Components import { makeVColorPickerProps, VColorPicker } from '@/components/VColorPicker/VColorPicker' import { makeVConfirmEditProps, VConfirmEdit } from '@/components/VConfirmEdit/VConfirmEdit' @@ -14,23 +17,30 @@ import { computed, shallowRef } from 'vue' import { genericComponent, omit, propsFactory, useRender } from '@/util' // Types -import type { VFieldSlots } from '@/components/VField/VField' -import type { VInputSlots } from '@/components/VInput/VInput' +import type { DefaultInputSlot, VFieldSlots } from '@/components/VField/VField' +import type { VInputSlot, VInputSlots } from '@/components/VInput/VInput' export type VColorInputSlots = Omit & { default: never - prependInner: never - prependInnerIcon: never + prepend: VInputSlot + prependInner: DefaultInputSlot + append: VInputSlot + appendInner: DefaultInputSlot } export const makeVColorInputProps = propsFactory({ - colorPip: String, + colorPip: { + type: Boolean, + default: true, + }, hideActions: Boolean, + readonlyInput: Boolean, ...makeFocusProps(), ...makeVConfirmEditProps(), ...makeVTextFieldProps({ placeholder: '', + prependInnerIcon: '$pip', }), ...omit(makeVColorPickerProps({ }), ['width']), // TODO: Might need more added here, tbd @@ -51,8 +61,8 @@ export const VColorInput = genericComponent()({ const pickerModel = useProxiedModel(props, 'modelValue') const menu = shallowRef(false) - // TODO: Need to set true as the default value - const colorPip = computed(() => props.colorPip == null) + const colorPip = computed(() => !!props.colorPip) + const isInteractive = computed(() => !props.disabled && !props.readonly) const display = computed(() => { const value = model.value @@ -62,8 +72,6 @@ export const VColorInput = genericComponent()({ return value }) - const isInteractive = computed(() => !props.disabled && !props.readonly) - function onKeydown (e: KeyboardEvent) { if (e.key !== 'Enter') return @@ -93,14 +101,36 @@ export const VColorInput = genericComponent()({ const confirmEditProps = VConfirmEdit.filterProps(props) const colorPickerProps = VColorPicker.filterProps(omit(props, ['active', 'color'])) const textFieldProps = VTextField.filterProps(omit(props, ['prependInnerIcon'])) - const hasPrependInner = !!slots['prepend-inner'] - - const prependInnerIcon = props.prependInnerIcon || '$pip' + const hasPrepend = !!(slots.prepend) + const hasPrependInner = !!(slots.prependInner) + const hasAppendInner = !!(slots.appendInner) + const hasAppend = !!(slots.append) + + const isReadOnlyInput = computed(() => props.readonlyInput || props.readonly) + + const pipColor = computed(() => { + return colorPip.value ? model.value as string ?? 'on-surface' : undefined + }) + + const getPipIcon = (key: string) => { + const icon = key.replace(/-([a-z])/g, (_, letter) => letter.toUpperCase()) as string + + return ( + + ) + } return ( ()({ onFocus={ focus } onBlur={ blur } onClick:control={ isInteractive.value ? onClick : undefined } - onClick:prepend={ isInteractive.value ? onClick : undefined } + onClick:prependInner={ isInteractive.value ? onClick : undefined } + onClick:appendInner={ isInteractive.value ? onClick : undefined } onUpdate:modelValue={ val => { pickerModel.value = val model.value = val }} + readonly={ isReadOnlyInput.value } + prependIcon={ undefined } + prependInnerIcon={ undefined } + appendInnerIcon={ undefined } + appendIcon={ undefined } > {{ ...slots, + prepend: ({ ...slotProps }) => { + return !hasPrepend && props.prependIcon ? getPipIcon('prepend-icon') + : slots.prepend?.(slotProps) + }, [`prepend-inner`]: slotProps => { - return !hasPrependInner ? ( -
- -
- ) - : slots['prepend-inner']?.(slotProps) + return !hasPrependInner && props.prependInnerIcon ? getPipIcon('prepend-inner-icon') + : slots.prependInner?.(slotProps) }, default: () => { return ( @@ -166,6 +197,14 @@ export const VColorInput = genericComponent()({ ) }, + [`append-inner`]: slotProps => { + return !hasAppendInner && props.appendInnerIcon ? getPipIcon('append-inner-icon') + : slots.appendInner?.(slotProps) + }, + append: slotProps => { + return !hasAppend && props.appendIcon ? getPipIcon('append-icon') + : slots.append?.(slotProps) + }, }}
)