@coras-io/embed 0.7.1 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # @coras-io/embed
2
2
 
3
+ ## 0.8.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 0fd91b9: Group event section options by price, with a section dropdown per price, when more than eight sections are available
8
+
9
+ ### Patch Changes
10
+
11
+ - 85df217: Remove the drop shadow from the date field on the details page so it reads as a field, not a button
12
+
3
13
  ## 0.7.1
4
14
 
5
15
  ### Patch Changes
@@ -1,10 +1,30 @@
1
- import { type CSSResultGroup, LitElement } from "lit";
1
+ import { type CSSResultGroup, LitElement, type PropertyValues } from "lit";
2
2
  import "../../button/button.js";
3
+ import "../../dropdown/dropdown.js";
3
4
  import "../../icon/icon.js";
5
+ import "../../select-list/select-list.js";
6
+ import "../../select-list/select-option/select-option.js";
7
+ export interface SportOptionSection {
8
+ id: string;
9
+ name: string;
10
+ }
4
11
  export declare class CorasSportOption extends LitElement {
5
12
  static styles: CSSResultGroup;
6
13
  assetsURL: string;
7
14
  section: string;
8
15
  price: string;
16
+ /**
17
+ * Sections sharing this price. With more than one, the section becomes a
18
+ * dropdown and `value` holds the chosen section id.
19
+ */
20
+ sections: SportOptionSection[];
21
+ value: string;
22
+ protected willUpdate(changed: PropertyValues<this>): void;
23
+ private dropdownOpen;
24
+ private toggleDropdown;
25
+ private closeDropdown;
26
+ private selectSection;
27
+ private stopPropagation;
28
+ private renderSection;
9
29
  render(): import("lit").TemplateResult<1>;
10
30
  }
@@ -4,11 +4,15 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
4
4
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
5
  return c > 3 && r && Object.defineProperty(target, key, r), r;
6
6
  };
7
- import { LitElement, html } from "lit";
8
- import { property } from "lit/decorators.js";
7
+ import { LitElement, html, } from "lit";
8
+ import { property, state } from "lit/decorators.js";
9
+ import { map } from "lit/directives/map.js";
9
10
  import { localized, msg } from "@lit/localize";
10
11
  import "../../button/button.js";
12
+ import "../../dropdown/dropdown.js";
11
13
  import "../../icon/icon.js";
14
+ import "../../select-list/select-list.js";
15
+ import "../../select-list/select-option/select-option.js";
12
16
  import styles from "./sport-option.styles.js";
13
17
  let CorasSportOption = class CorasSportOption extends LitElement {
14
18
  constructor() {
@@ -16,16 +20,85 @@ let CorasSportOption = class CorasSportOption extends LitElement {
16
20
  this.assetsURL = "";
17
21
  this.section = "";
18
22
  this.price = "";
23
+ /**
24
+ * Sections sharing this price. With more than one, the section becomes a
25
+ * dropdown and `value` holds the chosen section id.
26
+ */
27
+ this.sections = [];
28
+ this.value = "";
29
+ this.dropdownOpen = false;
30
+ this.toggleDropdown = () => {
31
+ this.dropdownOpen = !this.dropdownOpen;
32
+ };
33
+ this.closeDropdown = (event) => {
34
+ event.stopPropagation();
35
+ this.dropdownOpen = false;
36
+ };
37
+ this.stopPropagation = (event) => {
38
+ event.stopPropagation();
39
+ };
19
40
  }
20
41
  static { this.styles = styles; }
42
+ willUpdate(changed) {
43
+ if (changed.has("sections") &&
44
+ !this.sections.some((section) => section.id === this.value)) {
45
+ this.value = this.sections[0]?.id ?? "";
46
+ }
47
+ }
48
+ selectSection(id) {
49
+ this.value = id;
50
+ this.dropdownOpen = false;
51
+ }
52
+ renderSection() {
53
+ if (this.sections.length > 1) {
54
+ const selected = this.sections.find(({ id }) => id === this.value);
55
+ return html `<div class="text" @click=${this.stopPropagation}>
56
+ <div class="label" id="section-label">${msg("Section")}</div>
57
+ <coras-dropdown
58
+ ?open=${this.dropdownOpen}
59
+ @dropdown-close-request=${this.closeDropdown}
60
+ auto-focus
61
+ >
62
+ <coras-button
63
+ slot="trigger"
64
+ variant="outlined"
65
+ radius="field"
66
+ height="md"
67
+ border-color="light"
68
+ expanded
69
+ .shadow=${false}
70
+ ?rotate-suffix=${this.dropdownOpen}
71
+ @click=${this.toggleDropdown}
72
+ >
73
+ <coras-icon
74
+ assets-url="${this.assetsURL}"
75
+ slot="suffix"
76
+ icon="keyboard-arrow-down"
77
+ ></coras-icon>
78
+ <span class="selected-section">${selected?.name}</span>
79
+ </coras-button>
80
+
81
+ <coras-select-list spacious aria-labelledby="section-label">
82
+ ${map(this.sections, ({ id, name }) => html `
83
+ <coras-select-option
84
+ key=${id}
85
+ ?selected=${id === this.value}
86
+ @click=${() => this.selectSection(id)}
87
+ >${name}</coras-select-option
88
+ >
89
+ `)}
90
+ </coras-select-list>
91
+ </coras-dropdown>
92
+ </div>`;
93
+ }
94
+ return html `<div class="text">
95
+ <div class="label">${msg("Section")}</div>
96
+ <div class="value">${this.sections[0]?.name ?? this.section}</div>
97
+ </div>`;
98
+ }
21
99
  render() {
22
100
  return html `<div class="sport-option">
23
- <div class="section">
24
- <div class="text">
25
- <div class="label">${msg("Section")}</div>
26
- <div class="value">${this.section}</div>
27
- </div>
28
- </div>
101
+ <div class="section">${this.renderSection()}</div>
29
102
  <div class="price">
30
103
  <div class="text">
31
104
  <div class="label">${msg("Price")}</div>
@@ -51,6 +124,15 @@ __decorate([
51
124
  __decorate([
52
125
  property({ type: String })
53
126
  ], CorasSportOption.prototype, "price", void 0);
127
+ __decorate([
128
+ property({ attribute: false })
129
+ ], CorasSportOption.prototype, "sections", void 0);
130
+ __decorate([
131
+ property({ type: String })
132
+ ], CorasSportOption.prototype, "value", void 0);
133
+ __decorate([
134
+ state()
135
+ ], CorasSportOption.prototype, "dropdownOpen", void 0);
54
136
  CorasSportOption = __decorate([
55
137
  localized()
56
138
  ], CorasSportOption);
@@ -103,6 +103,27 @@ export default css `
103
103
  }
104
104
  }
105
105
  }
106
+
107
+ .section {
108
+ min-width: 0;
109
+
110
+ .text {
111
+ flex: 1;
112
+ min-width: 0;
113
+ }
114
+ }
115
+
116
+ coras-dropdown {
117
+ display: block;
118
+ width: 100%;
119
+ }
120
+
121
+ .selected-section {
122
+ min-width: 0;
123
+ overflow: hidden;
124
+ text-overflow: ellipsis;
125
+ white-space: nowrap;
126
+ }
106
127
  }
107
128
 
108
129
  @container (max-width: 400px) {
@@ -123,6 +123,7 @@ export declare class CorasDetailsPage extends CorasDetailsPage_base {
123
123
  private findSeatedPerformance;
124
124
  private renderSeatedSelector;
125
125
  private renderSectionOptions;
126
+ private renderSectionsByPrice;
126
127
  private handleSeatsConfirmed;
127
128
  private renderAvailabilityOptions;
128
129
  private openNavbarBasket;
@@ -56,7 +56,7 @@ import { BaseMixin } from "../../mixins/base.mixin.js";
56
56
  import { ErrorModalMixin } from "../../mixins/error-modal.mixin.js";
57
57
  import { currentPageContext } from "../../contexts/current-page.context.js";
58
58
  import { convertToLocaleCurrency } from "../../core/currency/index.js";
59
- import { calculateTotalPrice, formatDateWithTimezone, formatTicketDetails, getAvailabilityDays, getAvailabilityRequestKey, getAvailabilitySummary, getBookingSessionExpiry, getCurrentMonth, getMinBookingSize, getTicketsAmount, getTicketSelectorLabel, getTotalTicketsCount, groupAvailabilityByTime, isBelowMinimumBookingSize, isSingleDayAvailability, resolveAttractionLocation, scrollToTop, sumPricesAndFormat, } from "./details-page.utilts.js";
59
+ import { calculateTotalPrice, formatDateWithTimezone, formatTicketDetails, getAvailabilityDays, getAvailabilityRequestKey, getAvailabilitySummary, getBookingSessionExpiry, getCurrentMonth, getMinBookingSize, getTicketsAmount, getTicketSelectorLabel, getTotalTicketsCount, groupAvailabilityByTime, groupSectionsByPrice, isBelowMinimumBookingSize, isSingleDayAvailability, resolveAttractionLocation, scrollToTop, SECTION_GROUPING_THRESHOLD, sumPricesAndFormat, } from "./details-page.utilts.js";
60
60
  import { formatDateTimeForDisplay } from "../../core/utils/datetime.js";
61
61
  import { APIError } from "../../core/api/api-error.js";
62
62
  import { getBookingSession, storeBookingSession, } from "../../core/api/middlewares/booking-session/booking-session.utils.js";
@@ -640,6 +640,7 @@ let CorasDetailsPage = class CorasDetailsPage extends ErrorModalMixin(PointsMixi
640
640
  height="md"
641
641
  border-color="light"
642
642
  expanded
643
+ .shadow=${false}
643
644
  @click=${this.toggleCalendarDropdown}
644
645
  ?error=${this.hasAvailabilityError}
645
646
  >
@@ -1489,24 +1490,46 @@ let CorasDetailsPage = class CorasDetailsPage extends ErrorModalMixin(PointsMixi
1489
1490
  <coras-sport-options
1490
1491
  label="${msg(str `We have ${filteredOptions.length} available options`)}"
1491
1492
  >
1492
- ${map(filteredOptions, ({ name, selection_id, prices }) => html `
1493
- <coras-sport-option
1494
- assets-url="${this.assetsURL}"
1495
- section="${name || ""}"
1496
- price="${sumPricesAndFormat({
1497
- prices,
1493
+ ${filteredOptions.length > SECTION_GROUPING_THRESHOLD
1494
+ ? this.renderSectionsByPrice(filteredOptions)
1495
+ : map(filteredOptions, ({ name, selection_id, prices }) => html `
1496
+ <coras-sport-option
1497
+ assets-url="${this.assetsURL}"
1498
+ section="${name || ""}"
1499
+ price="${sumPricesAndFormat({
1500
+ prices,
1501
+ locale: this.locale,
1502
+ currency: this.currency,
1503
+ })}"
1504
+ @click=${() => {
1505
+ this.isReservationPreviewModalOpened = true;
1506
+ this.selectedSectionId = selection_id;
1507
+ }}
1508
+ ></coras-sport-option>
1509
+ `)}
1510
+ </coras-sport-options>
1511
+ </div>
1512
+ `;
1513
+ }
1514
+ renderSectionsByPrice(options) {
1515
+ return map(groupSectionsByPrice({
1516
+ options,
1498
1517
  locale: this.locale,
1499
1518
  currency: this.currency,
1500
- })}"
1501
- @click=${() => {
1519
+ }), ({ price, sections }) => html `
1520
+ <coras-sport-option
1521
+ assets-url="${this.assetsURL}"
1522
+ price="${price}"
1523
+ .sections=${sections.map(({ selection_id, name }) => ({
1524
+ id: selection_id,
1525
+ name: name || "",
1526
+ }))}
1527
+ @click=${(event) => {
1502
1528
  this.isReservationPreviewModalOpened = true;
1503
- this.selectedSectionId = selection_id;
1529
+ this.selectedSectionId = event.currentTarget.value;
1504
1530
  }}
1505
- ></coras-sport-option>
1506
- `)}
1507
- </coras-sport-options>
1508
- </div>
1509
- `;
1531
+ ></coras-sport-option>
1532
+ `);
1510
1533
  }
1511
1534
  // The navbar is a light-DOM child the SDK slots into the page (sdk/chrome.ts)
1512
1535
  // and picks the modal or dropdown for its own layout.
@@ -113,3 +113,19 @@ export declare const getMinBookingSize: (apiResponse: components["schemas"]["Att
113
113
  * ticket and the minimum, not the visitor clearing the selector.
114
114
  */
115
115
  export declare const isBelowMinimumBookingSize: (totalTickets: number, minBookingSize: number) => boolean;
116
+ /**
117
+ * Above this many sections the options list groups them by price band.
118
+ */
119
+ export declare const SECTION_GROUPING_THRESHOLD = 8;
120
+ /**
121
+ * Groups section options by their formatted ticket price, keeping the order in
122
+ * which each price first appears.
123
+ */
124
+ export declare const groupSectionsByPrice: ({ options, locale, currency, }: {
125
+ options: components["schemas"]["AvailabilityItemModel"][];
126
+ locale: SupportedLocales;
127
+ currency: SupportedCurrencies;
128
+ }) => {
129
+ price: string;
130
+ sections: components["schemas"]["AvailabilityItemModel"][];
131
+ }[];
@@ -255,3 +255,23 @@ export const getMinBookingSize = (apiResponse) => {
255
255
  * ticket and the minimum, not the visitor clearing the selector.
256
256
  */
257
257
  export const isBelowMinimumBookingSize = (totalTickets, minBookingSize) => totalTickets > 0 && totalTickets < minBookingSize;
258
+ /**
259
+ * Above this many sections the options list groups them by price band.
260
+ */
261
+ export const SECTION_GROUPING_THRESHOLD = 8;
262
+ /**
263
+ * Groups section options by their formatted ticket price, keeping the order in
264
+ * which each price first appears.
265
+ */
266
+ export const groupSectionsByPrice = ({ options, locale, currency, }) => {
267
+ const groups = new Map();
268
+ for (const option of options) {
269
+ const price = sumPricesAndFormat({
270
+ prices: option.prices,
271
+ locale,
272
+ currency,
273
+ });
274
+ groups.set(price, [...(groups.get(price) ?? []), option]);
275
+ }
276
+ return Array.from(groups, ([price, sections]) => ({ price, sections }));
277
+ };
package/package.json CHANGED
@@ -20,7 +20,7 @@
20
20
  "engines": {
21
21
  "node": ">=22"
22
22
  },
23
- "version": "0.7.1",
23
+ "version": "0.8.0",
24
24
  "private": false,
25
25
  "homepage": "https://docs.coras.io",
26
26
  "bugs": {