Skip to content

Commit

Permalink
feat(datepicker): add parse fn
Browse files Browse the repository at this point in the history
  • Loading branch information
segunadebayo committed Oct 18, 2023
1 parent edc8a49 commit 7fa9cbb
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 9 deletions.
6 changes: 6 additions & 0 deletions .changeset/tender-mayflies-suffer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@zag-js/date-picker": minor
---

- Add parse function to avoid installing additional `@internationalized/date` package
- Export more date picker types
6 changes: 3 additions & 3 deletions packages/machines/date-picker/src/date-picker.machine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -691,9 +691,9 @@ export function machine(userContext: UserDefinedContext) {
},
},
compareFns: {
startValue: (a, b) => a.toString() === b.toString(),
focusedValue: (a, b) => a.toString() === b.toString(),
value: (a, b) => a?.toString() === b?.toString(),
startValue: isDateEqual,
focusedValue: isDateEqual,
value: isDateEqualFn,
},
},
)
Expand Down
10 changes: 10 additions & 0 deletions packages/machines/date-picker/src/date-picker.parse.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { parseDate, type DateValue } from "@internationalized/date"

export function parse(value: string): DateValue
export function parse(value: string[]): DateValue[]
export function parse(value: string | string[]) {
if (Array.isArray(value)) {
return value.map((v) => parseDate(v)) as DateValue[]
}
return parseDate(value) as DateValue
}
15 changes: 10 additions & 5 deletions packages/machines/date-picker/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,30 @@
export { anatomy } from "./date-picker.anatomy"
export { connect } from "./date-picker.connect"
export { machine } from "./date-picker.machine"
export { parse } from "./date-picker.parse"
export type {
MachineApi as Api,
Calendar,
CalendarDate,
CalendarDateTime,
TableCellProps,
TableCellState,
UserDefinedContext as Context,
DateDuration,
DateFormatter,
DateValue,
DateValueOffset,
DateView,
DayTableCellProps,
DayTableCellState,
TableProps,
DateValueOffset,
MonthGridProps,
SelectionMode,
Send,
State,
TableCellProps,
TableCellState,
TableProps,
ViewProps,
VisibleRangeText,
WeekDay,
YearGridProps,
ZonedDateTime,
MachineApi as Api,
} from "./date-picker.types"
2 changes: 1 addition & 1 deletion packages/machines/slider/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export { anatomy } from "./slider.anatomy"
export { connect } from "./slider.connect"
export { machine } from "./slider.machine"
export type { UserDefinedContext as Context, MachineApi as Api } from "./slider.types"
export type { UserDefinedContext as Context, MachineApi as Api, ThumbProps, MarkerProps } from "./slider.types"

3 comments on commit 7fa9cbb

@vercel
Copy link

@vercel vercel bot commented on 7fa9cbb Oct 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

zag-nextjs – ./examples/next-ts

zag-nextjs-chakra-ui.vercel.app
zag-nextjs-git-main-chakra-ui.vercel.app
zag-two.vercel.app

@vercel
Copy link

@vercel vercel bot commented on 7fa9cbb Oct 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on 7fa9cbb Oct 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

zag-vue – ./examples/vue-ts

zag-vue.vercel.app
zag-vue-chakra-ui.vercel.app
zag-vue-git-main-chakra-ui.vercel.app

Please sign in to comment.