-
Notifications
You must be signed in to change notification settings - Fork 38
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
Add more options for customizations and translations #52
base: master
Are you sure you want to change the base?
Conversation
Also a lot of package updates during npm install. But that was just a bonus. There are still a lot of major versions needed to be updated etc. |
@@ -13,6 +13,7 @@ class CartItem extends Base<HTMLDivElement> { | |||
private ticket: CartTicket; | |||
private seatPriceTd: HTMLTableCellElement; | |||
private currency: string; | |||
private currencyBehind: boolean; |
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.
A better alternative and naming for this property could be:
private currencyPosition: 'start' | 'end';
@@ -27,6 +28,7 @@ class CartItem extends Base<HTMLDivElement> { | |||
|
|||
const { cart } = store.getOptions(); | |||
this.currency = cart?.currency || DEFAULT_CURRENCY; | |||
this.currencyBehind = cart?.currencyBehind ?? false; |
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.
For consistency I would create a constant DEFAULT_CURRENCY_POSITION
and set it to 'start'
, so this would be:
this.currencyPosition = cart?.currencyPosition || DEFAULT_CURRENCY_POSITION;
return `${this.currency}${price.toFixed(2)}`; | ||
return this.currencyBehind | ||
? `${price.toFixed(2)}${this.currency}` | ||
: `${this.currency}${price.toFixed(2)}`; |
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.
You can format the price once before creating the string:
const formattedValue = price.toFixed(2);
return this.currencyPosition === 'start'
? `${this.currency}${formattedValue}`
: `${formattedValue}${this.currency}`;
@@ -16,6 +18,8 @@ class CartTotal extends Base<HTMLDivElement> { | |||
|
|||
const { cart } = this.store.getOptions(); | |||
this.currency = cart?.currency || DEFAULT_CURRENCY; | |||
this.currencyBehind = cart?.currencyBehind ?? false; |
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.
Same improvements for currencyBehind
as mentioned for CartItem.
this.element.textContent = `Total: ${this.currency}${total.toFixed(2)}`; | ||
const totalString = this.currencyBehind | ||
? `${total.toFixed(2)}${this.currency}` | ||
: `${this.currency}${total.toFixed(2)}` |
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.
Also here I would create formattedValue
before building the string.
const description = `${seatType.label} (${currency}${seatType.price})`; | ||
const currencyLocation = cart?.currencyBehind | ||
? `${seatType.price}${currency}` | ||
: `${currency}${seatType.price}`; |
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.
currencyLocation
naming can be improved here to formattedCurrency
.
titleLabel?: string; | ||
totalLabel?: string; | ||
currencyBehind?: boolean; | ||
showTotal?: boolean; |
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.
showTotal
was added but it's not used anywhere.
@@ -98,11 +99,17 @@ interface Options { | |||
* Label displayed on the submit button. | |||
*/ | |||
submitLabel?: string; | |||
titleLabel?: string; | |||
totalLabel?: string; | |||
currencyBehind?: boolean; |
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.
As mentioned above this would become:
currencyPosition: 'start' | 'end';
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 see you probably used a newer version of npm and this has lockfileVersion 3. However I wouldn't update it in this PR, so it would be nice if you could revert it to original.
Hi @simonlerpard, thank you very much for contributing! I left a few comments here and there to improve namings and options structure. |
Awesome @omahili, I kind of did this in a rush... (without actually thinking it through all the way 😜) I've just quickly looked at your comments and they are very reasonable. I'll look into this further soon. Hopefully during the weekend or the next. I'll update the PR again when it's done. |
No worries @simonlerpard! For the labels I'm actually thinking if it makes more sense to have a full object in the options for locales like:
And possibly a function to set locale like:
So for now I removed all comments regarding labels. I will evaluate the solution mentioned here and eventually create another PR. I will let you know anyway! |
Adding multiple options to improve customizations and language adoptions,
as well as the currency position.
It's no breaking change, simply just more options 😃