Skip to content

Commit

Permalink
date field api ref
Browse files Browse the repository at this point in the history
  • Loading branch information
huntabyte committed Dec 1, 2023
1 parent c8e0fa3 commit 9329736
Show file tree
Hide file tree
Showing 9 changed files with 533 additions and 22 deletions.
28 changes: 14 additions & 14 deletions src/content/api-reference/calendar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import type { APISchema } from "@/types";
import * as C from "@/content/constants.js";
import {
asChild,
daysOfWeekSlotProp,
weekdaysSlotProp,
enums,
monthsSlotProp
} from "@/content/api-reference/helpers.js";
import type * as Calendar from "$lib/bits/calendar/_types.js";
import { attrsSlotProp, builderAndAttrsSlotProps } from "./helpers";

const root: APISchema<Calendar.Props> = {
export const root: APISchema<Calendar.Props> = {
title: "Root",
description: "The root calendar component which contains all other calendar components.",
props: {
Expand Down Expand Up @@ -121,7 +121,7 @@ const root: APISchema<Calendar.Props> = {
},
slotProps: {
months: monthsSlotProp,
daysOfWeek: daysOfWeekSlotProp,
daysOfWeek: weekdaysSlotProp,
...builderAndAttrsSlotProps
},
dataAttributes: [
Expand All @@ -144,7 +144,7 @@ const root: APISchema<Calendar.Props> = {
]
};

const cell: APISchema<Calendar.CellProps> = {
export const cell: APISchema<Calendar.CellProps> = {
title: "Cell",
description: "A cell in the calendar grid.",
props: {
Expand All @@ -169,7 +169,7 @@ const cell: APISchema<Calendar.CellProps> = {
]
};

const date: APISchema<Calendar.DateProps> = {
export const date: APISchema<Calendar.DateProps> = {
title: "Date",
description: "A date in the calendar grid.",
props: {
Expand Down Expand Up @@ -238,7 +238,7 @@ const date: APISchema<Calendar.DateProps> = {
]
};

const grid: APISchema<Calendar.GridProps> = {
export const grid: APISchema<Calendar.GridProps> = {
title: "Grid",
description: "The grid of dates in the calendar, typically representing a month.",
props: {
Expand All @@ -253,7 +253,7 @@ const grid: APISchema<Calendar.GridProps> = {
]
};

const gridBody: APISchema<Calendar.GridBodyProps> = {
export const gridBody: APISchema<Calendar.GridBodyProps> = {
title: "GridBody",
description: "The body of the grid of dates in the calendar.",
props: {
Expand All @@ -268,7 +268,7 @@ const gridBody: APISchema<Calendar.GridBodyProps> = {
]
};

const gridHead: APISchema<Calendar.GridHeadProps> = {
export const gridHead: APISchema<Calendar.GridHeadProps> = {
title: "GridHead",
description: "The head of the grid of dates in the calendar.",
props: {
Expand All @@ -285,7 +285,7 @@ const gridHead: APISchema<Calendar.GridHeadProps> = {
]
};

const gridRow: APISchema<Calendar.GridRowProps> = {
export const gridRow: APISchema<Calendar.GridRowProps> = {
title: "GridRow",
description: "A row in the grid of dates in the calendar.",
props: {
Expand All @@ -302,7 +302,7 @@ const gridRow: APISchema<Calendar.GridRowProps> = {
]
};

const headCell: APISchema<Calendar.HeadCellProps> = {
export const headCell: APISchema<Calendar.HeadCellProps> = {
title: "HeadCell",
description: "A cell in the head of the grid of dates in the calendar.",
props: {
Expand All @@ -319,7 +319,7 @@ const headCell: APISchema<Calendar.HeadCellProps> = {
]
};

const header: APISchema<Calendar.HeaderProps> = {
export const header: APISchema<Calendar.HeaderProps> = {
title: "Header",
description: "The header of the calendar.",
props: {
Expand All @@ -336,7 +336,7 @@ const header: APISchema<Calendar.HeaderProps> = {
]
};

const heading: APISchema<Calendar.HeadingProps> = {
export const heading: APISchema<Calendar.HeadingProps> = {
title: "Heading",
description: "The heading of the calendar.",
props: {
Expand All @@ -357,7 +357,7 @@ const heading: APISchema<Calendar.HeadingProps> = {
]
};

const nextButton: APISchema<Calendar.NextButtonProps> = {
export const nextButton: APISchema<Calendar.NextButtonProps> = {
title: "NextButton",
description: "The next button of the calendar.",
props: {
Expand All @@ -374,7 +374,7 @@ const nextButton: APISchema<Calendar.NextButtonProps> = {
]
};

const prevButton: APISchema<Calendar.PrevButtonProps> = {
export const prevButton: APISchema<Calendar.PrevButtonProps> = {
title: "PrevButton",
description: "The previous button of the calendar.",
props: {
Expand Down
212 changes: 212 additions & 0 deletions src/content/api-reference/date-field.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,212 @@
import * as C from "@/content/constants.js";
import type * as DateField from "$lib/bits/date-field/_types.js";
import type { APISchema } from "@/types";
import { enums, idsSlotProp, union, asChild } from "@/content/api-reference/helpers.js";
import { builderAndAttrsSlotProps } from "./helpers";

export const root: APISchema<DateField.Props> = {
title: "Root",
description: "The root date field component.",
props: {
value: {
type: "DateValue",
description: "The selected date."
},
onValueChange: {
type: {
type: C.FUNCTION,
definition: "(date: DateValue | undefined) => void"
},
description: "A function that is called when the selected date changes."
},
placeholder: {
type: "DateValue",
description:
"The placeholder date, which is used to determine what date to start the segments from when no value exists."
},
onPlaceholderChange: {
type: {
type: C.FUNCTION,
definition: "(date: DateValue) => void"
},
description: "A function that is called when the placeholder date changes."
},
isDateUnavailable: {
type: {
type: C.FUNCTION,
definition: "(date: DateValue) => boolean"
},
description: "A function that returns whether or not a date is unavailable."
},
hourCycle: {
type: {
type: C.ENUM,
definition: union("12", "24")
},
description: "The hour cycle to use for formatting times. Defaults to the locale preference"
},
granularity: {
type: {
type: C.ENUM,
definition: enums("day", "hour", "minute", "second")
},
description:
"The granularity to use for formatting the field. Defaults to `'day'` if a `CalendarDate` is provided, otherwise defaults to `'minute'`. The field will render segments for each part of the date up to and including the specified granularity."
},
hideTimeZone: {
type: C.BOOLEAN,
description: "Whether or not to hide the time zone segment of the field.",
default: C.FALSE
},
validationId: {
type: C.STRING,
description:
"The id of your validation message element, if any, which will be applied to the `aria-describedby` attribute of the appropriate elements when a validation error occurs."
},
descriptionId: {
type: C.STRING,
description:
"The id of your description element, if any, which will be applied to the `aria-describedby` attribute of the appropriate elements."
},
maxValue: {
type: "DateValue",
description: "The maximum valid date that can be entered."
},
minValue: {
type: "DateValue",
description: "The minimum valid date that can be entered."
},
locale: {
type: C.STRING,
description: "The locale to use for formatting dates."
},
disabled: {
default: C.FALSE,
type: C.BOOLEAN,
description: "Whether or not the accordion is disabled."
},
readonly: {
type: C.BOOLEAN,
description: "Whether or not the field is readonly.",
default: C.FALSE
}
},
slotProps: {
ids: idsSlotProp,
isInvalid: {
type: C.BOOLEAN,
description: "Whether or not the field is invalid."
}
}
};

const input: APISchema<DateField.InputProps> = {
title: "Input",
description: "The container for the segments of the date field.",
props: {
asChild
},
slotProps: {
...builderAndAttrsSlotProps,
segments: {
type: {
type: C.ARRAY,
definition: "{ part: SegmentPart; value: string; }[]"
},
description: "An array of objects used to render the segments of the date field."
}
},
dataAttributes: [
{
name: "invalid",
description: "Present on the element when the field is invalid."
},
{
name: "disabled",
description: "Present on the element when the field is disabled."
},
{
name: "date-field-input",
description: "Present on the element."
}
]
};

const segment: APISchema<DateField.SegmentProps> = {
title: "Segment",
description: "A segment of the date field.",
props: {
asChild,
part: {
type: {
type: "SegmentPart",
definition: enums(
"month",
"day",
"year",
"hour",
"minute",
"second",
"dayPeriod",
"timeZoneName",
"literal"
)
},
description: "The part of the date to render."
}
},
slotProps: {
...builderAndAttrsSlotProps
},
dataAttributes: [
{
name: "invalid",
description: "Present on the element when the field is invalid"
},
{
name: "disabled",
description: "Present on the element when the field is disabled"
},
{
name: "segment",
value: enums(
"month",
"day",
"year",
"hour",
"minute",
"second",
"dayPeriod",
"timeZoneName",
"literal"
),
isEnum: true,
description: "The type of segment the element represents."
},
{
name: "date-field-segment",
description: "Present on the element."
}
]
};

const label: APISchema<DateField.LabelProps> = {
title: "Label",
description: "The label for the date field.",
props: { asChild },
slotProps: {
...builderAndAttrsSlotProps
},
dataAttributes: [
{
name: "invalid",
description: "Present on the element when the field is invalid"
},
{
name: "date-field-label",
description: "Present on the element."
}
]
};

export const dateField = [root, input, segment, label];
Loading

0 comments on commit 9329736

Please sign in to comment.