@warp-ds/elements 2.10.0-next.13 → 2.10.0-next.14

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,6 +1,6 @@
1
- import { server, userEvent } from 'vitest/browser';
2
1
  import { html } from 'lit';
3
2
  import { expect, test, vi } from 'vitest';
3
+ import { server, userEvent } from 'vitest/browser';
4
4
  import { render } from 'vitest-browser-lit';
5
5
  import '../button/button.js';
6
6
  import './datepicker.js';
@@ -11,3 +11,6 @@
11
11
  * @throws {Error} if string is not a valid ISO-8601 date
12
12
  */
13
13
  export declare function fromISOToDate(isoString: string): Date | null;
14
+ export declare function getDateInputType(userAgent?: string): 'date' | 'text';
15
+ export declare function getDateInputPlaceholder(locale: string): string;
16
+ export declare function getDateInputDisplayValue(value: string, locale: string): string;
@@ -26,3 +26,36 @@ export function fromISOToDate(isoString) {
26
26
  }
27
27
  return new Date(timestamp);
28
28
  }
29
+ export function getDateInputType(userAgent = typeof navigator !== 'undefined' ? navigator.userAgent : '') {
30
+ const isIOS = /iP(hone|od|ad)/.test(userAgent);
31
+ const isSafari = /Safari/.test(userAgent) && !/(Chrome|Chromium|CriOS|FxiOS|Edg|OPR|Android)/.test(userAgent);
32
+ return isIOS || isSafari ? 'text' : 'date';
33
+ }
34
+ export function getDateInputPlaceholder(locale) {
35
+ const placeholderLocale = locale === 'en' ? 'en-GB' : locale;
36
+ const parts = new Intl.DateTimeFormat(placeholderLocale, {
37
+ day: '2-digit',
38
+ month: '2-digit',
39
+ year: 'numeric',
40
+ timeZone: 'UTC',
41
+ }).formatToParts(new Date(Date.UTC(2006, 0, 2)));
42
+ return parts
43
+ .map((part) => {
44
+ if (part.type === 'day')
45
+ return 'dd';
46
+ if (part.type === 'month')
47
+ return 'mm';
48
+ if (part.type === 'year')
49
+ return 'yyyy';
50
+ return part.value;
51
+ })
52
+ .join('');
53
+ }
54
+ export function getDateInputDisplayValue(value, locale) {
55
+ const match = dateOnlyRe.exec(value);
56
+ if (!match) {
57
+ return value;
58
+ }
59
+ const [year, month, day] = value.split('-');
60
+ return getDateInputPlaceholder(locale).replace('yyyy', year).replace('mm', month).replace('dd', day);
61
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,29 @@
1
+ import { describe, expect, test } from 'vitest';
2
+ import { getDateInputDisplayValue, getDateInputPlaceholder, getDateInputType } from './utils.js';
3
+ describe('getDateInputType', () => {
4
+ test('uses text input for Safari to avoid Safari showing a concrete empty-state date', () => {
5
+ expect(getDateInputType('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.0 Safari/605.1.15')).toBe('text');
6
+ });
7
+ test('uses text input for iOS browsers', () => {
8
+ expect(getDateInputType('Mozilla/5.0 (iPhone; CPU iPhone OS 17_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/120.0.0.0 Mobile/15E148 Safari/604.1')).toBe('text');
9
+ });
10
+ test('keeps date input for Chrome on desktop', () => {
11
+ expect(getDateInputType('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36')).toBe('date');
12
+ });
13
+ });
14
+ describe('getDateInputPlaceholder', () => {
15
+ test('returns a locale-shaped date format hint', () => {
16
+ expect(getDateInputPlaceholder('en')).toBe('dd/mm/yyyy');
17
+ expect(getDateInputPlaceholder('en-GB')).toBe('dd/mm/yyyy');
18
+ expect(getDateInputPlaceholder('nb')).toBe('dd.mm.yyyy');
19
+ });
20
+ });
21
+ describe('getDateInputDisplayValue', () => {
22
+ test('formats ISO dates using the locale-shaped date format hint', () => {
23
+ expect(getDateInputDisplayValue('2026-03-25', 'en')).toBe('25/03/2026');
24
+ expect(getDateInputDisplayValue('2026-03-25', 'nb')).toBe('25.03.2026');
25
+ });
26
+ test('keeps non-ISO values unchanged', () => {
27
+ expect(getDateInputDisplayValue('25/03/2026', 'en')).toBe('25/03/2026');
28
+ });
29
+ });
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://raw.githubusercontent.com/JetBrains/web-types/master/schema/web-types.json",
3
3
  "name": "@warp-ds/elements",
4
- "version": "2.10.0-next.12",
4
+ "version": "2.10.0-next.13",
5
5
  "description-markup": "markdown",
6
6
  "contributions": {
7
7
  "html": {