-
Notifications
You must be signed in to change notification settings - Fork 544
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(Calendar): implement component #2618
base: v3
Are you sure you want to change the base?
Conversation
@benjamincanac do you think I'm asking to see if I need to get the props part from Upd. looked at how other ui's work with the calendar. It's always a separate component, without a form, it's with a model |
No need to make it work in a form, it's a separate component indeed! Also, it should handle ranges: |
@benjamincanac at the moment it looks like this. It remains to solve the typing problem and write documentation. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should not duplicate the code to handle range
prop but use namespaced imports instead: https://www.radix-vue.com/guides/namespaced-components.html
Take a look at https://github.com/nuxt/ui/blob/v3/src/runtime/components/DropdownMenuContent.vue#L92 for example.
You could have something like const Component = computed(() => props.range ? RangeCalendar : Calendar)
.
I was going to do that originally. But I thought that typing on dynamic components might break. But since you recommend it, I'll do it like this |
@benjamincanac radix uses There is an issue where this problem was discussed: vuejs/core#2981 (comment), but the workaround looks quite unappealing. I would suggest switching to standard Example: export type DateRange = {
- start: DateValue | undefined;
- end: DateValue | undefined;
+ start: Date | undefined;
+ end: Date | undefined;
}; What do you think about this? PS Even in the example they use |
@benjamincanac done. Also returned the |
@benjamincanac I switched from the standard Pros:
Cons:
|
I don't plan to add or modify the code anymore. You can review it, and if everything looks good, go ahead and merge it π |
Awesome! Will try to make a final review tomorrow and merge it :) In both datepickers examples, would you mind formatting the dates as such: |
Done, additionally added some usage examples |
ui?: Partial<typeof calendar.slots> | ||
} | ||
export interface CalendarEmits extends Omit<CalendarRootEmits & RangeCalendarRootEmits, 'update:modelValue'> {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can remove the Omit
here so the docs show the update:modelValue
event.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the documentation, update:modelValue
is already displayed, it is taken from defineModel
.
const parsedProps = useForwardProps(reactiveOmit(props, 'color', 'size', 'range', 'monthControls', 'yearControls', 'class', 'ui', 'modelValue' as any)) | ||
const emitsAsProps = objectOmit(useEmitAsProps(emits), ['update:modelValue']) | ||
const rootProps = computed(() => ({ ...parsedProps.value, ...emitsAsProps })) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not use useForwardPropsEmits
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Initially, I used useForwardPropsEmits
, but it provides update:modelValue
, which in turn duplicates the update of v-model
. I fixed it in ee422ee.
Simply removing modelValue
doesn't work because defineModel
creates the update:modelValue
event, which in turn is not removed by useForwardPropsEmits
.
π Linked issue
Resolves #1137 and half #2524
β Type of change
π Description
UDatepicker
component to use nuxt-ui is sorely lacking. This is the first step towards implementing aUDatepicker
. I'll be doing this in my spare time, so it might be a bit of a stretch.π Checklist