@westpac/ui 0.35.0 → 0.36.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,2 +1,2 @@
1
1
  import { type DatePickerProps } from './date-picker.types.js';
2
- export declare function DatePicker({ disableWeekends, disableDaysOfWeek, disableDates, placeholder, onChange, onFocus, onBlur, onOpen, onClose, min, max, value, id, size, name, block, invalid, ...props }: DatePickerProps): import("react/jsx-runtime").JSX.Element;
2
+ export declare function DatePicker({ dateFormat, disableWeekends, disableDaysOfWeek, disableDates, placeholder, onChange, onFocus, onBlur, onOpen, onClose, min, max, value, id, size, name, block, invalid, ...props }: DatePickerProps): import("react/jsx-runtime").JSX.Element;
@@ -16,7 +16,7 @@ function _extends() {
16
16
  import React, { useEffect, useLayoutEffect, useMemo, useRef, useState } from 'react';
17
17
  import { styles } from './date-picker.styles.js';
18
18
  import { formatDate, isDateDisabled, useListener } from './date-picker.utils.js';
19
- export function DatePicker({ disableWeekends , disableDaysOfWeek , disableDates , placeholder , onChange , onFocus , onBlur , onOpen , onClose , min , max , value , id , size ='md' , name , block =false , invalid =false , ...props }) {
19
+ export function DatePicker({ dateFormat ='dd-MM-yyyy' , disableWeekends , disableDaysOfWeek , disableDates , placeholder , onChange , onFocus , onBlur , onOpen , onClose , min , max , value , id , size ='md' , name , block =false , invalid =false , ...props }) {
20
20
  const [initialized, setInitialized] = useState(false);
21
21
  useEffect(()=>{
22
22
  const initDatePicker = async ()=>{
@@ -34,15 +34,17 @@ export function DatePicker({ disableWeekends , disableDaysOfWeek , disableDates
34
34
  useListener(ref, 'duetClose', onClose);
35
35
  const dateAdapter = useMemo(()=>({
36
36
  parse (value = '', createDate) {
37
- const matches = value.match(/^(\d{1,2})-(\d{1,2})-(\d{4})$/);
37
+ const matches = value.match(/^(\d{1,2})[-/](\d{1,2})[-/](\d{4})$/);
38
38
  if (matches) {
39
39
  return createDate(matches[3], matches[2], matches[1]);
40
40
  }
41
41
  },
42
42
  format (date) {
43
- return formatDate(date, 'dd-mm-yyyy');
43
+ return formatDate(date, dateFormat);
44
44
  }
45
- }), []);
45
+ }), [
46
+ dateFormat
47
+ ]);
46
48
  const localization = useMemo(()=>{
47
49
  return {
48
50
  buttonLabel: 'Choose date',
@@ -17,6 +17,11 @@ export type DatePickerProps = {
17
17
  * Make Datepicker block
18
18
  */
19
19
  block?: Variants['block'];
20
+ /**
21
+ * Date format
22
+ * @default dd-MM-yyyy
23
+ */
24
+ dateFormat?: 'dd-MM-yyyy' | 'dd/MM/yyyy';
20
25
  disableDates?: string[];
21
26
  disableDaysOfWeek?: number[];
22
27
  disableWeekends?: boolean;
@@ -4,7 +4,7 @@ import { DuetDatePickerElement } from './date-picker.types.js';
4
4
  * @param date the date to format as a Date
5
5
  * @param format the format string eg. "dd.mm.yyyy", "YYYY-MM-DD"
6
6
  */
7
- export declare function formatDate(date: Date, format: string): string;
7
+ export declare function formatDate(date: Date, format: 'dd-MM-yyyy' | 'dd/MM/yyyy'): string;
8
8
  /**
9
9
  * @param ref Element ref
10
10
  * @param eventName Event name for the event listener
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@westpac/ui",
3
- "version": "0.35.0",
3
+ "version": "0.36.0",
4
4
  "license": "MIT",
5
5
  "sideEffects": false,
6
6
  "type": "module",
@@ -7,6 +7,7 @@ import { type DatePickerProps, DuetDatePickerElement } from './date-picker.types
7
7
  import { formatDate, isDateDisabled, useListener } from './date-picker.utils.js';
8
8
 
9
9
  export function DatePicker({
10
+ dateFormat = 'dd-MM-yyyy',
10
11
  disableWeekends,
11
12
  disableDaysOfWeek,
12
13
  disableDates,
@@ -48,16 +49,16 @@ export function DatePicker({
48
49
  const dateAdapter = useMemo(
49
50
  () => ({
50
51
  parse(value = '', createDate: (year: string, month: string, day: string) => Date) {
51
- const matches = value.match(/^(\d{1,2})-(\d{1,2})-(\d{4})$/);
52
+ const matches = value.match(/^(\d{1,2})[-/](\d{1,2})[-/](\d{4})$/);
52
53
  if (matches) {
53
54
  return createDate(matches[3], matches[2], matches[1]);
54
55
  }
55
56
  },
56
57
  format(date: Date) {
57
- return formatDate(date, 'dd-mm-yyyy');
58
+ return formatDate(date, dateFormat as 'dd-MM-yyyy' | 'dd/MM/yyyy');
58
59
  },
59
60
  }),
60
- [],
61
+ [dateFormat],
61
62
  );
62
63
 
63
64
  const localization = useMemo(() => {
@@ -21,6 +21,11 @@ export type DatePickerProps = {
21
21
  * Make Datepicker block
22
22
  */
23
23
  block?: Variants['block'];
24
+ /**
25
+ * Date format
26
+ * @default dd-MM-yyyy
27
+ */
28
+ dateFormat?: 'dd-MM-yyyy' | 'dd/MM/yyyy';
24
29
  /*
25
30
  * Disable specific dates. Must be in IS0-8601 format: YYYY-MM-DD
26
31
  */
@@ -8,7 +8,7 @@ const ISO_DATE_FORMAT = /^(\d{4})-(\d{2})-(\d{2})$/;
8
8
  * @param date the date to format as a Date
9
9
  * @param format the format string eg. "dd.mm.yyyy", "YYYY-MM-DD"
10
10
  */
11
- export function formatDate(date: Date, format: string) {
11
+ export function formatDate(date: Date, format: 'dd-MM-yyyy' | 'dd/MM/yyyy') {
12
12
  if (!date) {
13
13
  return '';
14
14
  }