-
Notifications
You must be signed in to change notification settings - Fork 26
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: Day.render / CalendarDays.render #47
Conversation
✅ Deploy Preview for uselessdev-datepicker ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
Hi, @astahmer first of all thank you for opening this pull request. So, about the implementation, I really want to avoid the use of render props (yes I know I'm using render props in controls but I'm planning to change this) and use <CalendarDays>
{({ day }) => {
if (new Date(day).getDate() < 8) {
return (
<Box d="flex" flexDirection="column" alignItems="center">
<div>{day /* should use date-fns format as well */}</div>
<Circle size="4px" bgColor="pink.300" />
</Box>
)
}
return day
}}
</CalendarDays> But, I still don't know if this is 'ok' maybe we can find another solution something like exposing a hook such as const { days } = useCalendarDays()
<CalendarDays>
{days.map(day => <Box>{day}</Box>)}
</CalendarDays> |
Ok I see, no problem i'll change it ! 👍 Out of curiosity, is there a problem with render props ? I think that with a hook such as IMO you could make it a hook at the Day level: `const { day, isSelected, isInRange, isDisabled, variant } = useCalendarDay()` or make it another compound component at the Day level: <CalendarDays>
<CalendarDay>
{({ day }) => (day ? `(${format(day, 'd')})` : <span />)}
</CalendarDay>
<CalendarDays> or even better we can just make both and |
feat: DayContext /CalendarDay / useCalendarDay docs: add stories
absolutely not
I was thinking of something like this |
</Day> | ||
) | ||
} | ||
export const CustomDayComponent: ComponentStory<typeof Calendar> = () => { |
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.
let's keep this simple by only adding the WithCustomDay
story.
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.
For the story I was thinking in something like this:
function CustomDay({ day, ...props }: Day) {
if (new Date(day).getDate() > 8) {
return <CalendarDay day={day} {...props} />
}
return (
<CalendarDay
day={day}
{...props}
flexDir="column"
rounded="md"
_hover={{ bgColor: 'pink.100' }}
>
{format(day, 'd')}
<Circle size="4px" bgColor="pink.300" />
</CalendarDay>
)
}
export const WithCustomDay: ComponentStory<typeof Calendar> = () => {
const [dates, setDates] = React.useState<CalendarValues>({})
const handleSelectDate = (dates: CalendarValues) => setDates(dates)
return (
<Calendar value={dates} onSelectDate={handleSelectDate}>
<CalendarControls>
<CalendarPrevButton />
<CalendarNextButton />
</CalendarControls>
<CalendarMonths>
<CalendarMonth>
<CalendarMonthName />
<CalendarWeek />
<CalendarDays>{props => <CustomDay {...props} />}</CalendarDays>
</CalendarMonth>
</CalendarMonths>
</Calendar>
)
}
this is similar to what you already did
src/day.tsx
Outdated
|
||
export function Day({ day, variant, disabled, onSelectDate,render }: Day) { | ||
export function Day({ day, variant, disabled, onSelectDate, children }: Day) { |
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.
Now this component will be 'public' we should rename it to CalendarDay
@@ -15,8 +15,56 @@ import { CalendarContext } from './context' | |||
import { Day } from './day' | |||
import { MonthContext } from './month' | |||
|
|||
export function CalendarDays({render}: Pick<Day, "render">) { | |||
export function CalendarDays({ children }: CalendarDayProps) { |
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.
this file has too much change, for this PR I want to suggest only add props for the children:
type Props = {
children?: (props: Day) => React.ReactElement<Day>
}
export function CalendarDays({ children }: Props) {
and just before the return verify if children exists and return:
if (children) {
return children({
day,
onSelectDate: onSelectDates,
disabled: isDisabled,
variant,
})
}
) as JSX.Element | ||
} | ||
|
||
export const useCalendarDay = () => { |
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.
I really like the hook, but I think we should add this in another pull request.
done in the last commit 👍
that makes sense but at the same time, then how would you name the built-in component containing the
if you don't mind, could you do it ? this might be more straightforward than me doing it since i'm not really sure how you want to split the PR |
@all-contributors please add @astahmer for code |
@uselessdev I've put up a pull request to add @astahmer! 🎉 |
Hey, I needed to customize the content of each day's cell, this should cover it
example story:

with: