الفتحات

في DatePicker عدد 15 من الفتحات. مرّر بديلًا لأي منها في components، وكل فتحة لا تمرّرها تبقى على بديلها الافتراضي. فتحات العناصر تستقبل خصائص DOM فيناسبها عنصر المكتبة كما هو، وفتحات الأدوات تستقبل خصائص مسمّاة وتحتاج عادة إلى بضعة أسطر من المحوّل.

الاسمالنوعالخصائص التي تستقبلهاالبديل الافتراضيسمات data-*
Root<element>

خصائص DOM: Omit<HTMLAttributes<HTMLDivElement>, "color">

  • ref?: Ref<HTMLDivElement>
مصدر البديل
Root: ({ className, ...props }) => <div className={cx("sdp", className)} {...props} />
  • data-disabled
  • data-empty
  • data-invalid
  • data-mode
  • data-open
Trigger<element>

خصائص DOM: Omit<HTMLAttributes<HTMLDivElement>, "color">

  • ref?: Ref<HTMLDivElement>
مصدر البديل
Trigger: ({ className, ...props }) => <div className={cx("sdp__trigger", className)} {...props} />
  • data-disabled
  • data-empty
  • data-invalid
  • data-open
  • data-trigger
Input<element>

خصائص DOM: Omit<InputHTMLAttributes<HTMLInputElement>, "color" | "size">

  • ref?: Ref<HTMLInputElement>
مصدر البديل
Input: ({ className, ...props }) => <input className={cx("sdp__input", className)} {...props} />
  • data-empty
  • data-invalid
  • data-open
Toggle<element>

خصائص DOM: Omit<ButtonHTMLAttributes<HTMLButtonElement>, "color" | "type">

  • ref?: Ref<HTMLButtonElement>
  • type?: "button"
مصدر البديل
Toggle: ({ className, type = "button", ...props }) => (
  <button type={type} className={cx("sdp__toggle", className)} {...props} />
)
  • data-open
Value{widget}
  • text?: string

    The formatted selection, when there is one.

  • placeholder: string

    Shown when nothing is picked.

  • empty: boolean

    Whether anything is picked.

مصدر البديل
Value: ({ text, placeholder, empty }) => (
  <span className={cx("sdp__value", empty && "sdp__value--empty")}>{empty ? placeholder : text}</span>
)
—
Icon{widget}
  • open: boolean

    Whether the calendar is open.

مصدر البديل
Icon: () => <CalendarIcon />
—
Clear{widget}
  • onClick: () => void

    Clears it.

  • aria-label: string

    Accessible name.

مصدر البديل
Clear: ({ onClick, ...aria }) => (
  <button
    type="button"
    className="sdp__clear"
    onClick={(event) => {
      event.stopPropagation();
      onClick();
    }}
    {...aria}
  >
    <CrossIcon />
  </button>
)
—
Popup<element>

خصائص DOM: Omit<HTMLAttributes<HTMLDivElement>, "color">

  • ref?: Ref<HTMLDivElement>
مصدر البديل
Popup: ({ className, ...props }) => <div className={cx("sdp__popup", className)} {...props} />
  • data-placement
Calendar<element>

خصائص DOM: Omit<HTMLAttributes<HTMLDivElement>, "color">

  • ref?: Ref<HTMLDivElement>
مصدر البديل
Calendar: ({ className, ...props }) => <div className={cx("sdp__calendar", className)} {...props} />
—
Caption{widget}
  • month: ISODate

    The month being shown, as the 1st of that month.

  • monthLabel: string

    The month's name in the current locale.

  • monthIndex: number

    The month being shown, 0 for January.

  • year: number

    The year being shown.

  • months: string[]

    Every month name, January first, for a dropdown.

  • years: number[]

    The years that can be picked.

  • onMonthChange: (month: number) => void

    Shows a different month of the same year. Takes a month index.

  • onYearChange: (year: number) => void

    Shows the same month of a different year.

  • labels: { month: string; year: string }

    Accessible names for the two controls.

مصدر البديل
Caption: function Caption({ monthIndex, year, months, years, onMonthChange, onYearChange, labels }) {
  // An id rather than a name keeps the selects out of an enclosing form's submission.
  const id = useId();
  return (
    <span className="sdp__caption">
      <select
        id={`${id}-month`}
        className="sdp__select"
        aria-label={labels.month}
        value={monthIndex}
        onChange={(event) => onMonthChange(Number(event.target.value))}
      >
        {months.map((name, index) => (
          <option key={name} value={index}>
            {name}
          </option>
        ))}
      </select>
      <select
        id={`${id}-year`}
        className="sdp__select"
        aria-label={labels.year}
        value={year}
        onChange={(event) => onYearChange(Number(event.target.value))}
      >
        {years.map((value) => (
          <option key={value} value={value}>
            {value}
          </option>
        ))}
      </select>
    </span>
  );
}
—
Nav{widget}
  • direction: "previous" | "next"

    Which way its arrow should point, as if the page were left to right. In right-to-left this is reversed for you: the control that moves back in time sits on the right and points right, so it is told next. aria-label always says what it does.

  • onClick: () => void

    Moves the calendar.

  • disabled: boolean

    Whether the move would leave the allowed range.

  • aria-label: string

    Accessible name.

مصدر البديل
Nav: ({ direction, onClick, disabled, ...aria }) => (
  <button type="button" className="sdp__nav" onClick={onClick} disabled={disabled} {...aria}>
    <ChevronIcon flip={direction === "next"} />
  </button>
)
—
Weekday{widget}
  • label: string

    The name in the current locale, in the chosen weekdayFormat.

  • name: string

    The full name, e.g. "Saturday".

  • index: number

    0 to 6, in display order.

مصدر البديل
Weekday: ({ label }) => <span className="sdp__weekday">{label}</span>
—
Day<element>

خصائص DOM: Omit<ButtonHTMLAttributes<HTMLButtonElement>, "color" | "type">

  • type?: "button"
  • ref?: Ref<HTMLButtonElement>
مصدر البديل
Day: ({ className, ...props }) => <button type="button" className={cx("sdp__day", className)} {...props} />
  • data-date
  • data-disabled
  • data-focused
  • data-in-preview
  • data-in-range
  • data-outside
  • data-range-end
  • data-range-start
  • data-selected
  • data-today
  • data-weekend
DayContent{widget}
  • day: CalendarDay

    The day being rendered.

  • selected: boolean

    Whether it is picked.

  • inRange: boolean

    Whether it sits inside a picked range.

  • inPreview: boolean

    Whether it sits inside the range preview.

  • disabled: boolean

    Whether it cannot be picked.

مصدر البديل
DayContent: ({ day }) => <span>{day.day}</span>
—

الخصائص

كل خصائص DatePicker مجمّعة كما في توثيق المكتبة. الحالة المتحكَّم بها تأتي أزواجًا: مرّر القيمة مع معالج تغييرها، أو القيمة الابتدائية وحدها لتبقى الحالة داخل المكوّن.

الاسمالنوعالافتراضيالوصف
Value and mode
modesingle mode"single"—

One date. The default mode.

modeمطلوبةmultiple mode"multiple"—

Any number of dates, toggled one click at a time.

modeمطلوبةrange mode"range"—

A start and an end: the first click sets the start, the second the end.

valuesingle modeISODate | null—

The picked date, or null for nothing.

valuemultiple modeISODate[]—

The picked dates.

valuerange modeDateRange | null—

The picked range. Either end may be missing while picking.

defaultValuesingle modeISODate | null—

The picked date while uncontrolled.

defaultValuemultiple modeISODate[]—

The picked dates while uncontrolled.

defaultValuerange modeDateRange | null—

The picked range while uncontrolled.

onChangesingle mode(value: ISODate | null) => void—

The new date, or null when cleared.

onChangemultiple mode(value: ISODate[]) => void—

The new dates, sorted, always an array.

onChangerange mode(value: DateRange | null) => void—

The new range, or null when cleared.

clearablebooleantrue

Whether the clear control is offered. Defaults to true.

closeOnSelectboolean

true in single mode and false otherwise

Whether picking closes the popup. Defaults to true in single mode and false otherwise.

valueFormatDateValueFormat

"iso-datetime"; "YYYY-MM-DD" keeps the calendar day alone

How the days the picker exchanges with you are written: value, defaultValue, onChange, minDate, maxDate, the presets and the day disabledDates is asked about. A pattern such as "DD/MM/YYYY", "iso-datetime" for the instant the day starts in timeZone, or a codec of your own. Defaults to "iso-datetime"; "YYYY-MM-DD" keeps the calendar day alone.

timeZonestring

the browser's own

The time zone the calendar works in: an IANA name such as "Asia/Tokyo", "UTC", or an offset such as "+09:00". Today is today in that zone, and with valueFormat: "iso-datetime" (the default) a picked day is the instant it starts there and an instant is read as the day it falls on there. Defaults to the browser's own.

namestring—

The form field name. The root then holds a hidden input of that name per picked day, written as valueFormat says, so a plain HTML form submits the value: one day, each of several days, or a range's start then end.

Calendar
localeLocaleInput

the provider's, then en-US

The language: a locale object, or a BCP 47 tag. A tag formats dates and names with Intl as always, and takes its labels from the pack of that language given to SlotsmithProvider, if there is one. Defaults to the provider's, then en-US.

weekStartsOnWeekStart

the locale's own first day

The first column of the grid. Defaults to the locale's own first day.

weekdayFormat"narrow" | "short" | "long"narrow

How long the column headers are. narrow is a single character in every language, and is the only form that reliably fits a square day column. Defaults to narrow.

presetsDatePickerPreset[]—

Shortcuts shown under the grid. A date preset in range mode picks that one day.

Bounds
minDateISODate—

Nothing before this date can be picked, and the calendar does not page past it.

maxDateISODate—

Nothing after this date can be picked, and the calendar does not page past it.

disabledDates(date: ISODate) => boolean—

Blocks individual dates — weekends, holidays, days already booked. They stay focusable.

Open state
openboolean—

Whether the popup is open.

defaultOpenboolean—

Whether the popup starts open.

onOpenChange(open: boolean) => void—

Told when the popup opens or closes.

disabledboolean—

Disables the whole control. Separate from disabledDates.

invalidboolean—

The value failed validation. Sets aria-invalid on the combobox and data-invalid on the root and trigger, so a skin can show its error style. Pair it with aria-errormessage or aria-describedby pointing at the message. Default false.

onBlur(event: FocusEvent<HTMLElement>) => void—

Told when focus leaves the whole control, for form libraries.

Display
triggerDatePickerTriggerKind—

What opens the calendar. "input", the default, is a text field the date can be typed into, in the locale's numeric order (MM/DD/YYYY in en-US), with a calendar button beside it. "button" is one control that shows the formatted value and opens the calendar when pressed.

openOnFocusbooleanfalse

With the "input" trigger, focusing or clicking the text field opens the calendar too. Defaults to false.

placeholderstring—

Shown when nothing is picked. With the "button" trigger it defaults to labels.placeholder; the "input" trigger's text field shows the date order to type in, such as MM/DD/YYYY.

formatIntl.DateTimeFormatOptions{ day: "numeric", month: "short", year: "numeric" }

How the trigger formats a date. Defaults to { day: "numeric", month: "short", year: "numeric" }.

placementPopupPlacementbottom

Which side of the trigger the popup prefers. Defaults to bottom.

popupOffsetnumber4

Gap between trigger and popup, in pixels. Defaults to 4.

portalPortalTargetfalse

Renders the popup in a portal: true for document.body, or an element of your own. It then escapes any ancestor's overflow, transform or stacking context, and still counts as part of the control. Set the --ss-* tokens and the dark class on :root or on that element, which the popup then inherits from. Defaults to false.

Slots and labels
componentsPartial<DatePickerComponents>—

Replace any part; the rest fall back to SlotsmithProvider's components.datePicker, then to the built-in ones.

labelsPartial<DatePickerLabels>—

Override any string. Wins over locale.

slotPropsDatePickerSlotProps—

Extra DOM props for the element parts.

تُمرَّر أي خاصية أخرى إلى العنصر الجذر <div>.

النصوص واللغات

كل نص يعرضه DatePicker أو يعلنه، مع قيمته الافتراضية بالإنجليزية. مرّر labels لتغيير بعضها في مكوّن واحد، أو locale لتحويل كل النصوص إلى لغة أخرى. العرض أدناه يفعل الأمرين.

المفتاحالنوعالافتراضي بالإنجليزيةالوصف
placeholderstring"Pick a date"

Trigger text when nothing is picked, and the trigger's default accessible name.

clearstring"Clear date"

Accessible name for the clear control.

openCalendarstring"Open calendar"

Accessible name for the calendar button beside the text field.

previousstring"Previous month"

Accessible name for the previous-month control.

nextstring"Next month"

Accessible name for the next-month control.

todaystring"Go to today"

Label for the control that jumps to today's month without picking it — a navigation verb, not the bare word "today", so it reads apart from the presets.

monthstring"Month"

Accessible name for the month dropdown.

yearstring"Year"

Accessible name for the year dropdown.

dialogstring"Choose a date"

Accessible name for the popup.

count(count: number) => stringcount(3)

يطبع "3 dates selected"

Multiple mode: how the trigger summarises more than two dates.

rangeStart(from: string) => stringrangeStart("Mar 3")

يطبع "Mar 3 — …"

Range mode, when only the start is picked. Receives the formatted start.

range(from: string, to: string) => stringrange("Mar 3", "Mar 9")

يطبع "Mar 3 — Mar 9"

Range mode, when both ends are picked. Receives both formatted ends.

حزم اللغات الجاهزة ودعم الكتابة من اليمين إلى اليسار واللغة على مستوى التطبيق موضّحة في صفحة اللغات.

التنسيق

أسماء الأصناف التي تضعها البدائل الافتراضية في DatePicker على عناصرها، والمتغيرات التي يقرؤها ملف تنسيقه. اضبط متغيرًا على المكوّن أو على أي عنصر يحيط به لتغيير مظهره، واستهدف الصنف فقط لما لا يغطيه متغير.

الصنفالفتحة
.sdp
.sdp__header—
.sdp__cell—
.sdp__weekdays—
.sdp__columnheader—
.sdp__week—
.sdp__chevron—
.sdp__icon
.sdp__today-icon—
.sdp__clear
.sdp__caption
.sdp__select—
.sdp__nav
.sdp__weekday
.sdp__footer
.sdp__preset—
.sdp__preset--today—
.sdp__today—
.sdp__trigger
.sdp__input
.sdp__toggle
.sdp__value
.sdp__value--empty—
.sdp__popup
.sdp__calendar
.sdp__day
المتغيرالطبقة
--sdp-accentهذا المكوّن
--sdp-borderهذا المكوّن
--sdp-cellهذا المكوّن
--sdp-dangerهذا المكوّن
--sdp-font-sizeهذا المكوّن
--sdp-gapهذا المكوّن
--sdp-hoverهذا المكوّن
--sdp-mutedهذا المكوّن
--sdp-on-accentهذا المكوّن
--sdp-radiusهذا المكوّن
--sdp-surfaceهذا المكوّن
--sdp-textهذا المكوّن
--ss-accentمشترك بين كل المكوّنات
--ss-borderمشترك بين كل المكوّنات
--ss-dangerمشترك بين كل المكوّنات
--ss-font-sizeمشترك بين كل المكوّنات
--ss-hoverمشترك بين كل المكوّنات
--ss-mutedمشترك بين كل المكوّنات
--ss-on-accentمشترك بين كل المكوّنات
--ss-radiusمشترك بين كل المكوّنات
--ss-surfaceمشترك بين كل المكوّنات
--ss-textمشترك بين كل المكوّنات

تنتقل كل المتغيرات إلى قيمها الداكنة تحت .dark, [data-theme="dark"]، على الصفحة أو على أي عنصر يحيط بالمكوّن.

صفحة السمات تشرح المتغيرات والسمات الجاهزة.

آخر تحديث