-
Notifications
You must be signed in to change notification settings - Fork 39
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?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. A better alternative and naming for this property could be:
|
||
|
||
public constructor(index: SeatIndex, store: Store) { | ||
const cartItem = document.createElement('tr'); | ||
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. For consistency I would create a constant
|
||
|
||
this.seatPriceTd = document.createElement('td'); | ||
this.seatPriceTd.textContent = this.formatPrice(typeOptions.price); | ||
|
@@ -50,7 +52,9 @@ class CartItem extends Base<HTMLDivElement> { | |
} | ||
|
||
private formatPrice(price: number) { | ||
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 commentThe reason will be displayed to describe this comment to others. Learn more. You can format the price once before creating the string:
|
||
} | ||
|
||
public update(seatLabel: string, seatType: SeatType) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,8 @@ import { DEFAULT_CURRENCY } from 'consts'; | |
class CartTotal extends Base<HTMLDivElement> { | ||
private store: Store; | ||
private currency: string; | ||
private currencyBehind: boolean; | ||
private label: string; | ||
|
||
public constructor(store: Store) { | ||
const total = document.createElement('p'); | ||
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. Same improvements for |
||
this.label = cart?.totalLabel ?? 'Total'; | ||
|
||
this.updateTotalText(); // init total text | ||
this.updateTotalText = this.updateTotalText.bind(this); | ||
|
@@ -27,7 +31,10 @@ class CartTotal extends Base<HTMLDivElement> { | |
|
||
private updateTotalText() { | ||
const total = this.store.getCartTotal(); | ||
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 commentThe reason will be displayed to describe this comment to others. Learn more. Also here I would create |
||
this.element.textContent = `${this.label}: ${totalString}`; | ||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ import { DEFAULT_CURRENCY } from 'consts'; | |
|
||
class Legend extends Base<HTMLUListElement> { | ||
public constructor(store: Store) { | ||
const { cart, map } = store.getOptions(); | ||
const { cart, map, reservedLegendLabel, hideLegendPrice } = store.getOptions(); | ||
const list = document.createElement('ul'); | ||
list.className = 'sc-legend'; | ||
|
||
|
@@ -17,12 +17,17 @@ class Legend extends Base<HTMLUListElement> { | |
|
||
for (const type of types) { | ||
const seatType = seatTypesOptions[type]; | ||
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 commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
const description = hideLegendPrice | ||
? `${seatType.label}` | ||
: `${seatType.label} (${currencyLocation})`; | ||
const item = new LegendItem(description, seatType.cssClass); | ||
list.appendChild(item.element); | ||
} | ||
|
||
const reservedItem = new LegendItem('Reserved', 'sc-seat-reserved'); | ||
const reservedItem = new LegendItem(reservedLegendLabel ?? 'Reserved', 'sc-seat-reserved'); | ||
list.appendChild(reservedItem.element); | ||
|
||
super(list); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -81,6 +81,7 @@ interface Options { | |
* Sets front header visibility. | ||
*/ | ||
frontVisible?: boolean; | ||
frontLabel?: string; | ||
}; | ||
/** | ||
* Cart options. | ||
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. As mentioned above this would become:
|
||
showTotal?: boolean; | ||
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.
|
||
}; | ||
/** | ||
* Legend visibility. | ||
*/ | ||
legendVisible?: boolean; | ||
reservedLegendLabel?: string; | ||
hideLegendPrice?: boolean; | ||
} | ||
|
||
export { Options }; |
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.