Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(date-picker, input-date-picker): add numberingSystem property #5488

Merged
merged 20 commits into from
Oct 22, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/components/date-picker-day/date-picker-day.e2e.ts
Original file line number Diff line number Diff line change
@@ -8,7 +8,6 @@ describe("calcite-date-picker-day", () => {
const dateEl = document.createElement("calcite-date-picker-day") as HTMLCalciteDatePickerDayElement;
dateEl.active = true;
dateEl.day = 3;
dateEl.localeData = { numerals: "0123456789" } as HTMLCalciteDatePickerDayElement["localeData"];
document.body.append(dateEl);
});
await page.waitForChanges();
13 changes: 3 additions & 10 deletions src/components/date-picker-day/date-picker-day.tsx
Original file line number Diff line number Diff line change
@@ -11,11 +11,11 @@ import {
} from "@stencil/core";

import { getElementDir } from "../../utils/dom";
import { DateLocaleData } from "../date-picker/utils";
import { Scale } from "../interfaces";
import { CSS_UTILITY } from "../../utils/resources";
import { InteractiveComponent, updateHostInteraction } from "../../utils/interactive";
import { isActivationKey } from "../../utils/key";
import { numberStringFormatter } from "../../utils/locale";

@Component({
tag: "calcite-date-picker-day",
@@ -38,7 +38,7 @@ export class DatePickerDay implements InteractiveComponent {
//--------------------------------------------------------------------------

/** Day of the month to be shown. */
@Prop() day: number;
@Prop() day!: number;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉


/** Date is outside of range and can't be selected */
@Prop({ reflect: true }) disabled = false;
@@ -67,10 +67,6 @@ export class DatePickerDay implements InteractiveComponent {
/** Date is actively in focus for keyboard navigation */
@Prop({ reflect: true }) active = false;

/** CLDR data for current locale */
/* @internal */
@Prop() localeData: DateLocaleData;

/** specify the scale of the date picker */
@Prop({ reflect: true }) scale: Scale;

@@ -123,10 +119,7 @@ export class DatePickerDay implements InteractiveComponent {
//
//--------------------------------------------------------------------------
render(): VNode {
const formattedDay = String(this.day)
.split("")
.map((i) => this.localeData.numerals[i])
.join("");
const formattedDay = numberStringFormatter.localize(String(this.day));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

const dir = getElementDir(this.el);
return (
<Host onClick={this.onClick} onKeyDown={this.keyDownHandler} role="gridcell">
Original file line number Diff line number Diff line change
@@ -10,20 +10,14 @@ import {
Watch,
Fragment
} from "@stencil/core";
import {
dateFromRange,
nextMonth,
prevMonth,
localizeNumber,
parseNumber,
getOrder
} from "../../utils/date";
import { dateFromRange, nextMonth, prevMonth, getOrder } from "../../utils/date";

import { DateLocaleData } from "../date-picker/utils";
import { Scale } from "../interfaces";
import { HeadingLevel, Heading } from "../functional/Heading";
import { BUDDHIST_CALENDAR_YEAR_OFFSET } from "./resources";
import { isActivationKey } from "../../utils/key";
import { numberStringFormatter } from "../../utils/locale";

@Component({
tag: "calcite-date-picker-month-header",
@@ -118,7 +112,7 @@ export class DatePickerMonthHeader {
return (
<Fragment>
<a
aria-disabled={(this.prevMonthDate.getMonth() === activeMonth).toString()}
aria-disabled={`${this.prevMonthDate.getMonth() === activeMonth}`}
aria-label={this.intlPrevMonth}
class="chevron"
href="#"
@@ -155,7 +149,7 @@ export class DatePickerMonthHeader {
</span>
</div>
<a
aria-disabled={(this.nextMonthDate.getMonth() === activeMonth).toString()}
aria-disabled={`${this.nextMonthDate.getMonth() === activeMonth}`}
aria-label={this.intlNextMonth}
class="chevron"
href="#"
@@ -224,15 +218,17 @@ export class DatePickerMonthHeader {
const { localeData } = this;
const buddhistCalendar = localeData["default-calendar"] === "buddhist";
const yearOffset = buddhistCalendar ? BUDDHIST_CALENDAR_YEAR_OFFSET : 0;
return localizeNumber(year + yearOffset, localeData);

return numberStringFormatter.localize(`${year + yearOffset}`);
}

private parseCalendarYear(year: string): string {
const { localeData } = this;
const buddhistCalendar = localeData["default-calendar"] === "buddhist";
const yearOffset = buddhistCalendar ? BUDDHIST_CALENDAR_YEAR_OFFSET : 0;

return localizeNumber(parseNumber(year, localeData) - yearOffset, localeData);
const parsedYear = Number(numberStringFormatter.delocalize(year)) - yearOffset;
return numberStringFormatter.localize(`${parsedYear}`);
}

private onYearChange = (event: Event): void => {
@@ -283,8 +279,8 @@ export class DatePickerMonthHeader {
localizedYear: string;
offset?: number;
}): Date {
const { min, max, activeDate, localeData } = this;
const parsedYear = parseNumber(localizedYear, localeData);
const { min, max, activeDate } = this;
const parsedYear = Number(numberStringFormatter.delocalize(localizedYear));
const length = parsedYear.toString().length;
const year = isNaN(parsedYear) ? false : parsedYear + offset;
const inRange =
1 change: 0 additions & 1 deletion src/components/date-picker-month/date-picker-month.tsx
Original file line number Diff line number Diff line change
@@ -415,7 +415,6 @@ export class DatePickerMonth {
endOfRange={this.isEndOfRange(date)}
highlighted={this.betweenSelectedRange(date)}
key={date.toDateString()}
localeData={this.localeData}
onCalciteDaySelect={this.daySelect}
onCalciteInternalDayHover={this.dayHover}
range={!!this.startDate && !!this.endDate && !sameDate(this.startDate, this.endDate)}
Loading