You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- show errors in Formfield based examples
- remove dependency on getDayWeekName from adapters
- document toJSDate in adapters
- re-enforce the need for LocalizationProvider through examples
- show how to set the date
Copy file name to clipboardExpand all lines: site/docs/components/calendar/examples.mdx
+7Lines changed: 7 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,6 +8,13 @@ data:
8
8
$ref: ./#/data
9
9
---
10
10
11
+
<Callouttitle="Note">
12
+
13
+
All date components require a [LocalizationProvider](/salt/components/localization-provider/examples) to be set up in your application.
14
+
For the purpose of the examples, we use type `DateFrameworkType` so the examples can be used across all date adapters. For your own code you can replace this type with the type of your date object (e.g luxon would use `DateTime` type instead).
15
+
16
+
</Callout>
17
+
11
18
## Single date selection
12
19
13
20
When the `selectionVariant` prop is set to "single", the `Calendar` component allows users to select only a single date, providing a straightforward and focused date selection experience.
Copy file name to clipboardExpand all lines: site/docs/components/date-input/examples.mdx
+17Lines changed: 17 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,6 +8,13 @@ data:
8
8
$ref: ./#/data
9
9
---
10
10
11
+
<Callouttitle="Note">
12
+
13
+
All date components require a [LocalizationProvider](/salt/components/localization-provider/examples) to be set up in your application.
14
+
For the purpose of the examples, we use type `DateFrameworkType` so the examples can be used across all date adapters. For your own code you can replace this type with the type of your date object (e.g luxon would use `DateTime` type instead).
15
+
16
+
</Callout>
17
+
11
18
## DateInputSingle
12
19
13
20
### Uncontrolled single date input
@@ -36,6 +43,16 @@ A `DateInputSingle` component with a border provides a visually distinct input f
36
43
exampleName="SingleBordered"
37
44
/>
38
45
46
+
### Custom Parsing
47
+
48
+
A custom parser can be provided through the `parse` prop.
49
+
50
+
<LivePreview
51
+
componentName="date-input"
52
+
displayName="Custom Parser"
53
+
exampleName="CustomParser"
54
+
/>
55
+
39
56
### Locale
40
57
41
58
A `DateInputSingle` component will use the locale defined by the nearest [LocalizationProvider](../LocalizationProvider) to determine locale specifics, such as date format.
Copy file name to clipboardExpand all lines: site/docs/components/date-input/usage.mdx
+63-50Lines changed: 63 additions & 50 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -21,56 +21,87 @@ To avoid misleading users, set the width of the input to correlate with the leng
21
21
22
22
Avoid using the `DateInputSingle` component if your application requires users to select a range of dates, in which case the `DateInputRange` component would be more appropriate.
23
23
24
-
### Parsing
24
+
## Import
25
+
26
+
### DateInputSingle
27
+
28
+
To import `DateInputSingle` from the Salt lab package, use:
29
+
30
+
```js
31
+
import { DateInputSingle } from"@salt-ds/lab";
32
+
```
33
+
34
+
### DateInputRange
25
35
26
-
By default, both `DateInputSingle` and `DateInputRange` accept a date string that can be passed to `new Date()`.
27
-
28
-
If the date string is valid, it is converted to an ISO string and then parsed to a local date using `parseAbsoluteToLocal(date.toISOString())`. The resulting date is then returned as a `CalendarDate` object with the year, month, and day. This default behavior ensures consistent and reliable date parsing, but it can be overridden by providing a custom parse function through the `parse` prop.
29
-
30
-
**Examples of valid date formats:**
31
-
32
-
1.**ISO 8601 string:**
33
-
- YYYY-MM-DD
34
-
- YYYY-MM-DDTHH:MM:SSZ
35
-
- YYYY-MM-DDTHH:MM:SS+HH:MM
36
-
- Example: "2023-01-15", "2023-01-15T15:45:00Z"
37
-
2.**RFC 2822 string:**
38
-
- DD MMM YYYY HH:MM:SS GMT
39
-
- Example: "15 Jan 2023 15:45:00 GMT"
40
-
3.**Date and Time String:**
41
-
- Month DD, YYYY HH:MM:SS
42
-
- Example: "January 15, 2023 15:45:00"
43
-
4.**Date only string:**
44
-
- Month DD, YYYY
45
-
- Example: "January 15, 2023"
46
-
5.**Milliseconds since epoch:**
47
-
- Number of milliseconds since January 1, 1970, 00:00:00 UTC.
48
-
- Example: 1673793900000
36
+
To import `DateInputRange` from the Salt lab package, use:
37
+
38
+
```js
39
+
import { DateInputRange } from"@salt-ds/lab";
40
+
```
41
+
42
+
### Setting the date
43
+
44
+
Date controls, require your application to contain a [LocalizationProvider](../LocalizationProvider).
45
+
46
+
Date input accept dates in two formats:
47
+
48
+
Pass a date string (compatible with `new Date()`) via the `defaultValue` or `value` props.
- If the input date string is valid, it is converted to an ISO string using `date.toISOString()`.
53
-
- The ISO string is then parsed to a local date using `parseAbsoluteToLocal(date.toISOString())`.
54
-
- The resulting date is returned as a `CalendarDate` object with the year, month, and day.
55
-
- If the date string is invalid, the function returns `undefined`.
86
+
- For a single a `null` value represents an empty date to ensure controlled components work as expected.
87
+
- For date ranges, the `startDate` and `endDate` can be `null` to represent empty dates.
88
+
- Invalid dates are represents by the `Invalid Date` object from the configured date framework.
56
89
57
90
This default behavior ensures consistent and reliable date parsing, but it can be customized by providing a custom parse function through the `parse` prop.
58
91
59
-
Additionally, you can provide your own `parse` function to convert shorthand dates to valid date objects.
60
-
61
92
### Formatting
62
93
63
94
By default, both `DateInputSingle` and `DateInputRange` format dates to `DD MMM YYYY`.
64
95
65
96
Formatting of entered dates occurs once the value is applied, either by the input losing it's focus or if the 'ENTER' is pressed.
66
97
67
-
Additionally, you can provide your own `formatDate` function to format`DateValue` to a `string`.
98
+
Additionally, you can provide your own formatter through the `format` prop.
68
99
69
100
### Locale
70
101
71
102
The default locale for Salt's date adapters is "enUS".
72
103
73
-
`DateInputSingle` and `DateInputRange` use the locale of the configured date adapter provided by the nearest [LocalizationProvider](../LocalizationProvider).
104
+
`DateInputSingle` and `DateInputRange` use the locale of the configured date adapter provided by the nearest [LocalizationProvider](../LocalizationProvider).
74
105
Configuration of locales is date framework specific and may require you to import specific locales from the date library you are using.
75
106
76
107
For example, if you are using `date-fns`, you may need to import the specific locale you want to use, such as `es` or `frFR`.
@@ -92,24 +123,6 @@ Valid values for `timezone` are date framework specific and can be one of the fo
92
123
- "UTC" uses the UTC timezone.
93
124
- string uses a specific IANA timezone string, such as "America/New_York" or "Europe/London".
94
125
95
-
## Import
96
-
97
-
### DateInputSingle
98
-
99
-
To import `DateInputSingle` from the Salt lab package, use:
100
-
101
-
```js
102
-
import { DateInputSingle } from"@salt-ds/lab";
103
-
```
104
-
105
-
### DateInputRange
106
-
107
-
To import `DateInputRange` from the Salt lab package, use:
Copy file name to clipboardExpand all lines: site/docs/components/date-picker/examples.mdx
+2-1Lines changed: 2 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,7 +10,8 @@ data:
10
10
11
11
<Callouttitle="Note">
12
12
13
-
All date components requires [LocalizationProvider](/salt/components/localization-provider/examples) to be set up in your application.
13
+
All date components require a [LocalizationProvider](/salt/components/localization-provider/examples) to be set up in your application.
14
+
For the purpose of the examples, we use type `DateFrameworkType` so the examples can be used across all date adapters. For your own code you can replace this type with the type of your date object (e.g luxon would use `DateTime` type instead).
Copy file name to clipboardExpand all lines: site/docs/components/date-picker/range-date-picker/examples.mdx
+2-1Lines changed: 2 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,7 +10,8 @@ data:
10
10
11
11
<Callouttitle="Note">
12
12
13
-
All date components requires [LocalizationProvider](/salt/components/localization-provider/examples) to be set up in your application.
13
+
All date components require a [LocalizationProvider](/salt/components/localization-provider/examples) to be set up in your application.
14
+
For the purpose of the examples, we use type `DateFrameworkType` so the examples can be used across all date adapters. For your own code you can replace this type with the type of your date object (e.g luxon would use `DateTime` type instead).
Copy file name to clipboardExpand all lines: site/docs/components/localization-provider/examples.mdx
+2Lines changed: 2 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,6 +8,8 @@ data:
8
8
$ref: ./#/data
9
9
---
10
10
11
+
> For the purpose of the examples, we use type `DateFrameworkType` so the examples can be used across all date adapters. For your own code you can replace this type with the type of your date object (e.g luxon would be `DateTime`).
12
+
11
13
## Adapters
12
14
13
15
To integrate your date framework with Salt components and enable support for locales or timezones, defining a date adapter is essential. Salt provides date adapters for the most popular date frameworks, which you can extend or use as a foundation to create your own custom adapter.
0 commit comments