Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(VDatePicker): pass through slots for day, week, month to sub components #21121

Open
wants to merge 7 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages/api-generator/src/locale/en/VDatePicker.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@
"slots": {
"actions": "Slot for the actions.",
"header": "Slot for the header.",
"year": "Slot for the year."
"year": "Slot for the year.",
"month": "Slot for the month.",
"day": "Slot for the day."
}
}
2 changes: 1 addition & 1 deletion packages/api-generator/src/locale/en/VDatePickerMonth.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@
"day": "Fired when a day is clicked."
},
"slots": {
"year": "Slot for the year."
"day": "Slot for the day."
}
}
3 changes: 3 additions & 0 deletions packages/api-generator/src/locale/en/VDatePickerYears.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,8 @@
"max": "Sets the maximum date of the month.",
"min": "Sets the minimum date of the month.",
"year": "Sets the year."
},
"slots": {
"year": "Slot for the year."
}
}
39 changes: 29 additions & 10 deletions packages/vuetify/src/components/VDatePicker/VDatePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,22 @@ import { computed, ref, shallowRef, watch } from 'vue'
import { genericComponent, omit, propsFactory, useRender, wrapInArray } from '@/util'

// Types
import type { VDatePickerHeaderSlots } from './VDatePickerHeader'
import type { VDatePickerMonthSlots } from './VDatePickerMonth'
import type { VDatePickerMonthsSlots } from './VDatePickerMonths'
import type { VDatePickerYearsSlots } from './VDatePickerYears'
import type { VPickerSlots } from '@/labs/VPicker/VPicker'
import type { GenericProps } from '@/util'

// Types
export type VDatePickerSlots = Omit<VPickerSlots, 'header'> & {
export type VDatePickerSlots = Omit<
& VDatePickerHeaderSlots
& VDatePickerMonthSlots
& VDatePickerYearsSlots
& VDatePickerMonthsSlots
& VPickerSlots,
'header' | 'default'
> & {
header: {
header: string
transition: string
Expand Down Expand Up @@ -296,7 +307,8 @@ export const VDatePicker = genericComponent<new <
props.class,
]}
style={ props.style }
v-slots={{
>
{{
title: () => slots.title?.() ?? (
<div class="v-date-picker__title">
{ t(props.title) }
Expand All @@ -316,11 +328,12 @@ export const VDatePicker = genericComponent<new <
{ ...datePickerHeaderProps }
{ ...headerProps }
onClick={ viewMode.value !== 'month' ? onClickDate : undefined }
v-slots={{
...slots,
default: undefined,
>
{{
append: slots.append,
prepend: slots.prepend,
}}
/>
</VDatePickerHeader>
),
default: () => (
<>
Expand All @@ -344,7 +357,9 @@ export const VDatePicker = genericComponent<new <
min={ minDate.value }
max={ maxDate.value }
year={ year.value }
/>
>
{{ month: slots.month }}
</VDatePickerMonths>
) : viewMode.value === 'year' ? (
<VDatePickerYears
key="date-picker-years"
Expand All @@ -353,7 +368,9 @@ export const VDatePicker = genericComponent<new <
onUpdate:modelValue={ onUpdateYear }
min={ minDate.value }
max={ maxDate.value }
/>
>
{{ year: slots.year }}
</VDatePickerYears>
) : (
<VDatePickerMonth
key="date-picker-month"
Expand All @@ -365,14 +382,16 @@ export const VDatePicker = genericComponent<new <
onUpdate:year={ onUpdateYear }
min={ minDate.value }
max={ maxDate.value }
/>
>
{{ day: slots.day }}
</VDatePickerMonth>
)}
</VFadeTransition>
</>
),
actions: slots.actions,
}}
/>
</VPicker>
)
})

Expand Down
4 changes: 3 additions & 1 deletion packages/vuetify/src/labs/VDateInput/VDateInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { genericComponent, omit, propsFactory, useRender, wrapInArray } from '@/

// Types
import type { PropType } from 'vue'
import type { VDatePickerSlots } from '@/components/VDatePicker/VDatePicker'
import type { StrategyProps } from '@/components/VOverlay/locationStrategies'
import type { VTextFieldSlots } from '@/components/VTextField/VTextField'

Expand All @@ -27,7 +28,7 @@ export type VDateInputActionsSlot = {
isPristine: boolean
}

export type VDateInputSlots = Omit<VTextFieldSlots, 'default'> & {
export type VDateInputSlots = Omit<Omit<VDatePickerSlots, 'actions'> & VTextFieldSlots, 'default'> & {
actions: VDateInputActionsSlot
default: never
}
Expand Down Expand Up @@ -184,6 +185,7 @@ export const VDateInput = genericComponent<VDateInputSlots>()({
onMousedown={ (e: MouseEvent) => e.preventDefault() }
>
{{
...slots,
actions: !props.hideActions ? () => slots.actions?.({ save, cancel, isPristine }) ?? actions() : undefined,
}}
</VDatePicker>
Expand Down