@happeouikit/form-elements 3.0.0-alpha.1 → 3.0.0-alpha.3

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,5 +1,6 @@
1
1
  import React from "react";
2
2
  import type { DayPickerProps } from "react-day-picker";
3
+ import type { DateFormat } from "./dateLocale";
3
4
  export interface DateRange {
4
5
  from: Date | number | string;
5
6
  to: Date | number | string;
@@ -10,14 +11,10 @@ export interface DisabledDays {
10
11
  }
11
12
  export interface DatePickerProps {
12
13
  label?: React.ReactNode;
14
+ /** BCP 47 locale for written month names only (e.g. the "MMMM YYYY" caption). */
13
15
  locale?: string;
14
- /**
15
- * Language for the calendar's written month names, e.g. "fr". Unlike
16
- * `locale`, this should be a language the surrounding app is actually
17
- * displaying its own UI copy in (never a raw OS/browser locale) — falls
18
- * back to English when omitted.
19
- */
20
- calendarLanguage?: string;
16
+ /** Numeric day/month/year order; see `dateLocale.ts`. Defaults to `DD/MM/YYYY`. */
17
+ dateFormat?: DateFormat;
21
18
  width?: string;
22
19
  date?: DateRange;
23
20
  type?: "from" | "to";
@@ -38,7 +35,6 @@ export interface DatePickerProps {
38
35
  export interface MonthPickerProps {
39
36
  date: Date;
40
37
  disabledDays: DisabledDays;
41
- calendarLanguage?: string;
42
38
  onChange: (val: {
43
39
  month: number;
44
40
  year: number;
@@ -1,4 +1,5 @@
1
1
  import React from "react";
2
+ import type { DateFormat } from "./dateLocale";
2
3
  export interface MonthDay {
3
4
  /** 1-12 */
4
5
  month: number;
@@ -7,15 +8,10 @@ export interface MonthDay {
7
8
  }
8
9
  export interface MonthDayPickerProps {
9
10
  label?: React.ReactNode;
10
- /** BCP 47 locale for the day/month order, e.g. "en-gb" or "en-us" */
11
+ /** BCP 47 locale for written month names only (e.g. "en-gb" or "en-us"). */
11
12
  locale?: string;
12
- /**
13
- * Language for the calendar's written month names, e.g. "fr". Unlike
14
- * `locale`, this should be a language the surrounding app is actually
15
- * displaying its own UI copy in (never a raw OS/browser locale) — falls
16
- * back to English when omitted.
17
- */
18
- calendarLanguage?: string;
13
+ /** Numeric day/month order; see `dateLocale.ts`. Defaults to `DD/MM/YYYY`. */
14
+ dateFormat?: DateFormat;
19
15
  width?: string;
20
16
  value?: MonthDay | null;
21
17
  inputProps?: React.InputHTMLAttributes<HTMLInputElement> & {
@@ -1,41 +1,33 @@
1
1
  /**
2
- * Numeric date format/parse, driven by Intl instead of moment's locale data.
3
- * No month-name localization here — only the day/month/year order and separators
4
- * that `date.toLocaleDateString(locale)` would use for a plain numeric date.
2
+ * Happeo's two supported numeric date formats. Always `/`-separated; written
3
+ * month/weekday names are a separate concern (driven by `locale`, unrelated
4
+ * to this).
5
5
  */
6
- /** Explicit locale if valid, else the browser/OS regional locale (same as `new Date().toLocaleDateString()`). */
7
- export declare const resolveLocale: (locale?: string) => string;
8
- /** Placeholder like "DD/MM/YYYY" matching the locale's part order, separators, and padding. */
9
- export declare const getDateFormatPattern: (locale?: string) => string;
10
- /** Same output as `date.toLocaleDateString(locale)` for a calendar date. */
11
- export declare const formatDate: (value: Date | number | string | undefined, locale?: string) => string | null;
6
+ export type DateFormat = "MM/DD/YYYY" | "DD/MM/YYYY";
7
+ export declare const DEFAULT_DATE_FORMAT: DateFormat;
8
+ /** The literal placeholder for a month-and-day-only input, e.g. "MM/DD". */
9
+ export declare const monthDayPlaceholder: (dateFormat: DateFormat) => string;
10
+ /** e.g. "12/23/1996" for `MM/DD/YYYY`, "23/12/1996" for `DD/MM/YYYY`. */
11
+ export declare const formatNumericDate: (date: Date, dateFormat: DateFormat) => string;
12
12
  /**
13
- * Parse typed input in the locale's day/month/year order.
14
- * Accepts 1-2 digit day/month and a 4-digit year. Returns null if it doesn't match.
13
+ * Parses typed input in one of Happeo's two supported numeric date formats.
14
+ * Day/month may be 1 or 2 digits, year must be 4. Only ASCII digits match
15
+ * (`\d` does not match a native-script digit, e.g. Devanagari or Persian) —
16
+ * such input simply fails to parse here, it is never converted. Returns null
17
+ * for a syntactically-matching but impossible date (e.g. 31/02).
15
18
  */
16
- export declare const parseDate: (input: string, locale?: string) => Date | null;
19
+ export declare const parseNumericDate: (input: string, dateFormat: DateFormat) => Date | null;
20
+ /** Same as `formatNumericDate`, but month/day only (e.g. for a birthday). */
21
+ export declare const formatNumericMonthDay: ({ month, day }: {
22
+ month: number;
23
+ day: number;
24
+ }, dateFormat: DateFormat) => string;
17
25
  /**
18
- * Parses a `DisabledDays` boundary (`Date | string | number`) consistently as
19
- * local time. A bare "YYYY-MM-DD" string is read as local midnight — matching
20
- * how a user reads "disable before 2024-03-01" — rather than the UTC midnight
21
- * `new Date("2024-03-01")` would parse it as.
26
+ * Same as `parseNumericDate`, but month/day only. Does not bounds-check
27
+ * `day` against the month (e.g. Feb 30) — the caller does, since that
28
+ * depends on whether a leap-year day (29 Feb) should be allowed.
22
29
  */
23
- export declare const toLocalDate: (value: Date | string | number) => Date;
24
- /**
25
- * Long/short written month names for calendar UI (e.g. "December" / "Dec").
26
- * Unlike `resolveLocale`, this never falls back to the OS/browser locale:
27
- * written text must only switch language when the caller can vouch that the
28
- * rest of the app is displaying in that language too (a Happeo UI language,
29
- * not a raw system locale) — an unrecognised or missing locale falls back to
30
- * English instead.
31
- */
32
- export declare const getMonthNames: (locale?: string) => {
33
- long: string;
34
- short: string;
35
- }[];
36
- /**
37
- * Short written weekday names for a calendar's header row (e.g. "Sun", "Mon"),
38
- * indexed like `Date#getDay()` (0 = Sunday). Same English-only-unless-vouched-for
39
- * fallback as `getMonthNames`.
40
- */
41
- export declare const getWeekdayNames: (locale?: string) => string[];
30
+ export declare const parseNumericMonthDay: (input: string, dateFormat: DateFormat) => {
31
+ month: number;
32
+ day: number;
33
+ } | null;