Skip to content

Commit

Permalink
chore: remove @internationalized/message from calendar
Browse files Browse the repository at this point in the history
  • Loading branch information
jer3m01 committed Jan 7, 2024
1 parent f1ca5b9 commit 8d4c967
Show file tree
Hide file tree
Showing 27 changed files with 8,685 additions and 4,791 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@
"tsup": "7.2.0",
"turbo": "1.10.13",
"typescript": "4.9.5",
"vite": "3.2.7",
"vite-plugin-solid": "2.7.0"
"vite": "5.0.11",
"vite-plugin-solid": "2.8.0"
},
"packageManager": "[email protected]"
}
5 changes: 3 additions & 2 deletions packages/core/src/calendar/calendar-context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import { CalendarDate, DateDuration } from "@internationalized/date";
import { RangeValue, ValidationState } from "@kobalte/utils";
import { Accessor, createContext, useContext } from "solid-js";

import { Direction, LocalizedMessageFormatter } from "../i18n";
import { Direction } from "../i18n";
import { CalendarSelectionMode, DateValue } from "./types";
import { CalendarIntlTranslations } from "./calendar.intl";

export interface CalendarDataSet {}

Expand All @@ -23,7 +24,7 @@ export interface CalendarContextValue {
max: Accessor<DateValue | undefined>;
timeZone: Accessor<string>;
validationState: Accessor<ValidationState | null>;
messageFormatter: Accessor<LocalizedMessageFormatter>;
translations: Accessor<CalendarIntlTranslations>;
isDisabled: Accessor<boolean>;
isReadOnly: Accessor<boolean>;
isDragging: Accessor<boolean>;
Expand Down
16 changes: 5 additions & 11 deletions packages/core/src/calendar/calendar-grid-body-cell-trigger.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ export function CalendarGridBodyCellTrigger(props: CalendarGridBodyCellTriggerPr
if (start && end && (isSameDay(context.date(), start) || isSameDay(context.date(), end))) {
label =
getSelectedDateDescription(
rootContext.messageFormatter(),
rootContext.translations(),
context.date(),
rootContext.timeZone(),
) + ", ";
Expand All @@ -142,25 +142,19 @@ export function CalendarGridBodyCellTrigger(props: CalendarGridBodyCellTriggerPr
label += labelDateFormatter().format(nativeDate());
if (context.isDateToday()) {
// If date is today, set appropriate string depending on selected state:
label = rootContext
.messageFormatter()
.format(context.isSelected() ? "todayDateSelected" : "todayDate", {
date: label,
});
label = rootContext.translations().todayDate(label, context.isSelected());
} else if (context.isSelected()) {
// If date is selected but not today:
label = rootContext.messageFormatter().format("dateSelected", {
date: label,
});
label = rootContext.translations().dateSelected(label);
}

const min = rootContext.min();
const max = rootContext.max();

if (min && isSameDay(context.date(), min)) {
label += ", " + rootContext.messageFormatter().format("minimumDate");
label += ", " + rootContext.translations().minimumDate;
} else if (max && isSameDay(context.date(), max)) {
label += ", " + rootContext.messageFormatter().format("maximumDate");
label += ", " + rootContext.translations().maximumDate;
}

return label;
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/calendar/calendar-grid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export function CalendarGrid(props: CalendarGridProps) {

const visibleRangeDescription = createMemo(() => {
return getVisibleRangeDescription(
rootContext.messageFormatter(),
rootContext.translations(),
startDate(),
endDate(),
rootContext.timeZone(),
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/calendar/calendar-heading.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export function CalendarHeading(props: CalendarHeadingProps) {

const title = createMemo(() => {
return getVisibleRangeDescription(
rootContext.messageFormatter(),
rootContext.translations(),
rootContext.startDate(),
rootContext.endDate(),
rootContext.timeZone(),
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/calendar/calendar-next-trigger.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export function CalendarNextTrigger(props: CalendarNextTriggerProps) {
return (
<Button.Root
disabled={nextTriggerDisabled()}
aria-label={context.messageFormatter().format("next")}
aria-label={context.translations().next}
onClick={onClick}
onFocus={onFocus}
onBlur={onBlur}
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/calendar/calendar-prev-trigger.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export function CalendarPrevTrigger(props: CalendarPrevTriggerProps) {
return (
<Button.Root
disabled={prevTriggerDisabled()}
aria-label={context.messageFormatter().format("previous")}
aria-label={context.translations().previous}
onClick={onClick}
onFocus={onFocus}
onBlur={onBlur}
Expand Down
27 changes: 18 additions & 9 deletions packages/core/src/calendar/calendar-root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ import {
splitProps,
} from "solid-js";

import { createMessageFormatter, getReadingDirection, useLocale } from "../i18n";
import { getReadingDirection, useLocale } from "../i18n";
import { announce } from "../live-announcer";
import { AsChildProp, Polymorphic } from "../polymorphic";
import { createControllableSignal, createInteractOutside } from "../primitives";
import { CALENDAR_INTL_MESSAGES } from "./calendar.intl";
import { CalendarIntlTranslations, CALENDAR_INTL_MESSAGES } from "./calendar.intl";
import { CalendarContext, CalendarContextValue, CalendarDataSet } from "./calendar-context";
import { DateAlignment, DateValue } from "./types";
import {
Expand Down Expand Up @@ -135,6 +135,9 @@ export type CalendarRootOptions = (
| CalendarRangeSelectionOptions
) &
AsChildProp & {
/** The localized strings of the component. */
translations?: CalendarIntlTranslations;

/**
* A function that creates a [Calendar](https://react-spectrum.adobe.com/internationalized/date/Calendar.html)
* object for a given calendar identifier. Such a function may be imported from the
Expand Down Expand Up @@ -207,11 +210,13 @@ export function CalendarRoot(props: CalendarRootProps) {
{
visibleDuration: { months: 1 },
selectionMode: "single",
translations: CALENDAR_INTL_MESSAGES,
},
props,
);

const [local, others] = splitProps(props, [
"translations",
"ref",
"locale",
"createCalendar",
Expand All @@ -235,8 +240,6 @@ export function CalendarRoot(props: CalendarRootProps) {
"aria-label",
]);

const messageFormatter = createMessageFormatter(() => CALENDAR_INTL_MESSAGES);

const locale = createMemo(() => {
return local.locale ?? useLocale().locale();
});
Expand Down Expand Up @@ -366,7 +369,13 @@ export function CalendarRoot(props: CalendarRootProps) {
const [isDragging, setIsDragging] = createSignal(false);

const visibleRangeDescription = createMemo(() => {
return getVisibleRangeDescription(messageFormatter(), startDate(), endDate(), timeZone(), true);
return getVisibleRangeDescription(
local.translations!,
startDate(),
endDate(),
timeZone(),
true,
);
});

const ariaLabel = () => {
Expand Down Expand Up @@ -776,16 +785,16 @@ export function CalendarRoot(props: CalendarRootProps) {

if (local.selectionMode === "single") {
const date = asSingleValue(value());
description = date && getSelectedDateDescription(messageFormatter(), date, timeZone());
description = date && getSelectedDateDescription(local.translations!, date, timeZone());
} else if (local.selectionMode === "multiple") {
const dates = asArrayValue(value());
description = dates
?.map(date => getSelectedDateDescription(messageFormatter(), date, timeZone()))
?.map(date => getSelectedDateDescription(local.translations!, date, timeZone()))
.join(", ");
} else if (local.selectionMode === "range") {
const dateRange = asRangeValue(value()) ?? {};
description = getSelectedDateRangeDescription(
messageFormatter(),
local.translations!,
dateRange,
anchorDate(),
timeZone(),
Expand Down Expand Up @@ -895,7 +904,7 @@ export function CalendarRoot(props: CalendarRootProps) {
min,
max,
timeZone,
messageFormatter,
translations: () => local.translations!,
setStartDate,
setAnchorDate,
setIsFocused,
Expand Down
Loading

0 comments on commit 8d4c967

Please sign in to comment.