-
Notifications
You must be signed in to change notification settings - Fork 78
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
Changes from 11 commits
b292585
8408f06
72618d9
e228ec7
561456e
f49008f
8cae4ff
158862a
01be7d3
2bef53d
7ec6565
cad5a3f
11fd935
44c8588
519c826
ddb8230
748f79d
b96a9d3
c605d33
168b73f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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", | ||
|
@@ -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).toString()); | ||
} | ||
|
||
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.toString()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nitpick: using template literals can be more concise. Up to you. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah you're right template literals are cleaner here. I use |
||
} | ||
|
||
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 = | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this needed for the
disabled
test?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah
numberFormatOptions
needs to be set at some point with the way the class is currently configured because all of the initialization happens in its setter.numberFormatOptions
is always set in components (or their parents in the case ofdate-picker-day
) with the values of thelang
/numberingSystem
props.I could add a constructor to the class to initialize values with the default
numberingSystem
/lang
, but that's just an extra iteration we don't need in the actual components. What do you think?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or I could just return the
localize
/delocalize
methods' params ifnumberFormatOptions
isn't set, which would effectively assumelang === "en && numberingSystem === "latn"
. e.g.It would be the equivolent outcome as adding a constructor and actually populating the internal properties based on defaults, but without the extra formatter creations.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I went with my second comment ☝️
Now
numberStringFormatter.numberFormatOptions
only needs to be set when thelang
andnumberingSystem
props are not their default values ("en" and "latn" respectively). This means that for a good portion of our users, we won't be initializing a formatter at all.That's down from 10+ formatters created/destroyed for each character typed in
calcite-input
alone 🚀