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

Add more options for customizations and translations #52

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

simonlerpard
Copy link

Adding multiple options to improve customizations and language adoptions,
as well as the currency position.

It's no breaking change, simply just more options 😃

@simonlerpard
Copy link
Author

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;
Copy link
Owner

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;
Copy link
Owner

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)}`;
Copy link
Owner

@omahili omahili Oct 12, 2023

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;
Copy link
Owner

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)}`
Copy link
Owner

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}`;
Copy link
Owner

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;
Copy link
Owner

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;
Copy link
Owner

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';

Copy link
Owner

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.

@omahili
Copy link
Owner

omahili commented Oct 12, 2023

Hi @simonlerpard, thank you very much for contributing! I left a few comments here and there to improve namings and options structure.

@simonlerpard
Copy link
Author

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.

@omahili
Copy link
Owner

omahili commented Oct 12, 2023

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:

locales: {
  en: {
    front: 'Front',
    currency: '£',
  },
  it: {
    front: 'Fronte',
    currency: '€',
  }
}

And possibly a function to set locale like:

sc.setLocale('it')

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants