Skip to content

Commit

Permalink
website: playground updates
Browse files Browse the repository at this point in the history
  • Loading branch information
gpbl committed Dec 30, 2024
1 parent a06052e commit 6477c20
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 12 deletions.
8 changes: 5 additions & 3 deletions website/docs/docs/customization.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,16 @@ To display the column with week numbers, use the `showWeekNumber` prop.

### Handling Week Numbers Click

To handle clicks on the week numbers, you can set a custom `WeekNumber` [component](../guides/custom-components.mdx):
To handle clicks on the week numbers, you can set the `WeekNumber` [custom component](../guides/custom-components.mdx):

```tsx
<DayPicker
showWeekNumber
components={{
weekNumber: ({ weekNumber }) => (
<button onClick={() => alert(`Week ${weekNumber}`)}>{weekNumber}</button>
WeekNumber: (props) => (
<button onClick={() => alert(`Week ${props.weekNumber}`)}>
{props.weekNumber}
</button>
)
}}
/>
Expand Down
19 changes: 11 additions & 8 deletions website/src/components/Playground/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,9 @@ export function Playground() {
let formattedProps = `<DayPicker${toJSX({
...props,
locale: undefined,
month: undefined,
dir: calendar === "Persian" && props.dir === "rtl" ? undefined : props.dir
})} \n/>`;
})} />`;

if (calendar === "Persian") {
formattedProps =
Expand Down Expand Up @@ -221,18 +222,20 @@ export function Playground() {
min={1}
max={12}
size={4}
value={props.numberOfMonths}
value={props.numberOfMonths ?? ""}
name="numberOfMonths"
onChange={(e) =>
onChange={(e) => {
const value = e.target.value;
setProps({
...props,
numberOfMonths: Number(e.target.value)
})
}
numberOfMonths:
value === "" ? undefined : Math.max(1, Number(value))
});
}}
/>
</label>

{props.numberOfMonths && props.numberOfMonths > 1 && (
{props.numberOfMonths !== undefined && props.numberOfMonths > 1 && (
<label>
<input
type="checkbox"
Expand All @@ -248,7 +251,7 @@ export function Playground() {
Reverse Months
</label>
)}
{props.numberOfMonths && props.numberOfMonths > 1 && (
{props.numberOfMonths !== undefined && props.numberOfMonths > 1 && (
<label>
<input
type="checkbox"
Expand Down
2 changes: 1 addition & 1 deletion website/src/components/Playground/toJSX.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export function toJSX(props: Partial<DayPickerProps>) {
: value
? ""
: `x={${JSON.stringify(value)}}`;
return `\n ${key}${valueAsString}`;
return ` ${key}${valueAsString}`;
})
.join("")
);
Expand Down

0 comments on commit 6477c20

Please sign in to comment.