docs(date-picker): improve docs

This commit is contained in:
Eric Liu 2025-04-22 20:51:46 -07:00
commit e08f6fa179

View file

@ -7,11 +7,7 @@ components: ["DatePicker", "DatePickerInput", "DatePickerSkeleton"]
import Preview from "../../components/Preview.svelte"; import Preview from "../../components/Preview.svelte";
</script> </script>
Carbon uses the zero dependency [flatpickr](https://github.com/flatpickr/flatpickr) library for its underlying calendar implementation. `DatePicker` lets users select a date or date range using a calendar interface. It uses the [flatpickr](https://github.com/flatpickr/flatpickr) library for its calendar implementation.
Set `datePickerType` to `"single"` or `"range"` for the calendar functionality.
Specify [flatpickr options](https://flatpickr.js.org/options/) through the `flatpickrProps` prop.
<InlineNotification svx-ignore lowContrast title="Note:" kind="info" hideCloseButton> <InlineNotification svx-ignore lowContrast title="Note:" kind="info" hideCloseButton>
<div class="body-short-01"> <div class="body-short-01">
@ -21,25 +17,27 @@ Specify [flatpickr options](https://flatpickr.js.org/options/) through the `flat
## Single ## Single
By default, the `flatpickr` option `static` is set to `true` so that the calendar is positioned inside the wrapper and next to the input element. This is required for the calendar position to work inside a [Modal](/components/Modal). Set `datePickerType` to `"single"` for single date selection.
Set `flatpickrProps.static` to `false` to opt out of this behavior.
<FileSource src="/framed/DatePicker/DatePickerSingle" /> <FileSource src="/framed/DatePicker/DatePickerSingle" />
## Range ## Range
Set `datePickerType` to `"range"` for the range variant. Set `datePickerType` to `"range"` to enable date range selection.
<FileSource src="/framed/DatePicker/DatePickerRange" /> <FileSource src="/framed/DatePicker/DatePickerRange" />
## DatePicker in a modal ## DatePicker in a modal
The calendar is positioned inside the wrapper by default (`flatpickrProps.static: true`). This ensures proper positioning within a [Modal](/components/Modal).
Set `flatpickrProps.static` to `false` to position the calendar outside the wrapper.
<FileSource src="/framed/DatePicker/DatePickerModal" /> <FileSource src="/framed/DatePicker/DatePickerModal" />
## Simple ## Simple
By default, the "simple" date picker does not have a dropdown calendar. Create a simple date picker without a dropdown calendar.
<DatePicker> <DatePicker>
<DatePickerInput labelText="Date of birth" placeholder="mm/dd/yyyy" /> <DatePickerInput labelText="Date of birth" placeholder="mm/dd/yyyy" />
@ -47,52 +45,70 @@ By default, the "simple" date picker does not have a dropdown calendar.
## With helper text ## With helper text
Add helper text to provide additional context or formatting instructions.
<DatePicker> <DatePicker>
<DatePickerInput labelText="Date of birth" helperText="Example: 01/12/1990" placeholder="mm/dd/yyyy" /> <DatePickerInput labelText="Date of birth" helperText="Example: 01/12/1990" placeholder="mm/dd/yyyy" />
</DatePicker> </DatePicker>
## Hidden label ## Hidden label
Hide the label while maintaining accessibility.
<DatePicker> <DatePicker>
<DatePickerInput hideLabel labelText="Date of birth" placeholder="mm/dd/yyyy" /> <DatePickerInput hideLabel labelText="Date of birth" placeholder="mm/dd/yyyy" />
</DatePicker> </DatePicker>
## Light variant ## Light variant
Use the light variant for light backgrounds.
<DatePicker light> <DatePicker light>
<DatePickerInput labelText="Date of birth" placeholder="mm/dd/yyyy" /> <DatePickerInput labelText="Date of birth" placeholder="mm/dd/yyyy" />
</DatePicker> </DatePicker>
## Extra-large size ## Extra-large size
Use the extra-large size for more prominent date pickers.
<DatePicker> <DatePicker>
<DatePickerInput size="xl" labelText="Date of birth" placeholder="mm/dd/yyyy" /> <DatePickerInput size="xl" labelText="Date of birth" placeholder="mm/dd/yyyy" />
</DatePicker> </DatePicker>
## Small size ## Small size
Use the small size for compact date pickers.
<DatePicker> <DatePicker>
<DatePickerInput size="sm" labelText="Date of birth" placeholder="mm/dd/yyyy" /> <DatePickerInput size="sm" labelText="Date of birth" placeholder="mm/dd/yyyy" />
</DatePicker> </DatePicker>
## Invalid state ## Invalid state
Show an invalid state when the input value is not valid.
<DatePicker> <DatePicker>
<DatePickerInput invalid invalidText="Invalid date" labelText="Date of birth" placeholder="mm/dd/yyyy" /> <DatePickerInput invalid invalidText="Invalid date" labelText="Date of birth" placeholder="mm/dd/yyyy" />
</DatePicker> </DatePicker>
## Warning state ## Warning state
Show a warning state to indicate potential issues with the input.
<DatePicker> <DatePicker>
<DatePickerInput warn warnText="This info will not be stored" labelText="Date of birth" placeholder="mm/dd/yyyy" /> <DatePickerInput warn warnText="This info will not be stored" labelText="Date of birth" placeholder="mm/dd/yyyy" />
</DatePicker> </DatePicker>
## Disabled state ## Disabled state
Disable the date picker to prevent user interaction.
<DatePicker> <DatePicker>
<DatePickerInput disabled labelText="Date of birth" placeholder="mm/dd/yyyy" /> <DatePickerInput disabled labelText="Date of birth" placeholder="mm/dd/yyyy" />
</DatePicker> </DatePicker>
## Skeleton ## Skeleton
Show a loading state with the skeleton component.
<DatePickerSkeleton /> <DatePickerSkeleton />