playbook_ui 15.3.0.pre.alpha.PLAY2407daterangeinlineshowcurrentyear12138 → 15.3.0.pre.alpha.PLAY2532flexboxdefaultresponsive12209
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.
- checksums.yaml +4 -4
- data/app/pb_kits/playbook/pb_advanced_table/Utilities/RowUtils.ts +1 -1
- data/app/pb_kits/playbook/pb_advanced_table/_advanced_table.scss +4 -4
- data/app/pb_kits/playbook/pb_advanced_table/advanced_table.test.jsx +5 -5
- data/app/pb_kits/playbook/pb_advanced_table/flat_advanced_table.js +2 -2
- data/app/pb_kits/playbook/pb_advanced_table/index.js +7 -7
- data/app/pb_kits/playbook/pb_advanced_table/scss_partials/advanced_table_sticky_mixin.scss +2 -2
- data/app/pb_kits/playbook/pb_advanced_table/table_row.rb +1 -1
- data/app/pb_kits/playbook/pb_date_range_inline/_date_range_inline.tsx +13 -20
- data/app/pb_kits/playbook/pb_date_range_inline/date_range_inline.rb +4 -6
- data/app/pb_kits/playbook/pb_date_range_inline/date_range_inline.test.js +0 -17
- data/app/pb_kits/playbook/pb_date_range_inline/docs/_description.md +1 -1
- data/app/pb_kits/playbook/pb_date_range_inline/docs/example.yml +2 -3
- data/app/pb_kits/playbook/pb_date_range_inline/docs/index.js +0 -1
- data/app/pb_kits/playbook/pb_form/pb_form_validation.js +44 -11
- data/app/pb_kits/playbook/pb_phone_number_input/_phone_number_input.tsx +110 -17
- data/app/pb_kits/playbook/utilities/globalProps.ts +26 -8
- data/app/pb_kits/playbook/utilities/test/globalProps/alignContent.test.js +18 -0
- data/app/pb_kits/playbook/utilities/test/globalProps/alignItems.test.js +18 -0
- data/app/pb_kits/playbook/utilities/test/globalProps/alignSelf.test.js +18 -0
- data/app/pb_kits/playbook/utilities/test/globalProps/display.test.js +18 -0
- data/app/pb_kits/playbook/utilities/test/globalProps/flex.test.js +18 -0
- data/app/pb_kits/playbook/utilities/test/globalProps/flexDirection.test.js +18 -0
- data/app/pb_kits/playbook/utilities/test/globalProps/flexGrow.test.js +18 -0
- data/app/pb_kits/playbook/utilities/test/globalProps/flexShrink.test.js +18 -0
- data/app/pb_kits/playbook/utilities/test/globalProps/flexWrap.test.js +18 -0
- data/app/pb_kits/playbook/utilities/test/globalProps/justifyContent.test.js +18 -0
- data/app/pb_kits/playbook/utilities/test/globalProps/justifySelf.test.js +18 -0
- data/app/pb_kits/playbook/utilities/test/globalProps/order.test.js +18 -0
- data/dist/chunks/{_line_graph-BRirnhGy.js → _line_graph-9bI76O2f.js} +1 -1
- data/dist/chunks/_typeahead-By0NwDwL.js +6 -0
- data/dist/chunks/{_weekday_stacked-DEkzyJsS.js → _weekday_stacked-ClJbIaDx.js} +2 -2
- data/dist/chunks/pb_form_validation-BNfSnIUF.js +1 -0
- data/dist/chunks/vendor.js +1 -1
- data/dist/playbook-doc.js +1 -1
- data/dist/playbook-rails-react-bindings.js +1 -1
- data/dist/playbook-rails.js +1 -1
- data/dist/playbook.css +1 -1
- data/lib/playbook/version.rb +1 -1
- metadata +6 -9
- data/app/pb_kits/playbook/pb_date_range_inline/docs/_date_range_inline_show_current_year.html.erb +0 -4
- data/app/pb_kits/playbook/pb_date_range_inline/docs/_date_range_inline_show_current_year.jsx +0 -43
- data/app/pb_kits/playbook/pb_date_range_inline/docs/_date_range_inline_show_current_year.md +0 -1
- data/dist/chunks/_typeahead-CFOqvZNu.js +0 -6
- data/dist/chunks/pb_form_validation-BZppqQZM.js +0 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: ecaeedfc3646abb5883eb891aecf36eb72cf8ad4a68ec156157f528a911e86f5
|
|
4
|
+
data.tar.gz: b881dd8c740a311285a3e14319641433522541e540bd6aca45c785bb606bf1dd
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e5727fa5998bd2b4252189412c52361e75404db9b332b7607a5b399562a967f4c4728a06160cf8beb7a59625bd5e5fcdb88e5cfe6dde1aefc1a026c3d9821dc7
|
|
7
|
+
data.tar.gz: 1366e8eccd9c380487d851fcedff3c58dda1c60a780b473a358994b24c55ba60c98ffe6db893c7bc26b2b2ffb623438fd8f15072fdd6fcfe987a41ce0784c9e9
|
|
@@ -17,7 +17,7 @@ export const getRowColorClass = (
|
|
|
17
17
|
(inlineRowLoading && (rowHasNoChildren || row.getCanExpand()))
|
|
18
18
|
);
|
|
19
19
|
|
|
20
|
-
return row.getIsSelected() ? "bg-row-selection" : shouldShowExpandedBackground ? "bg-silver" : "bg-white";
|
|
20
|
+
return row.getIsSelected() ? "bg-row-selection" : shouldShowExpandedBackground ? "bg-silver" : "pb-bg-row-white";
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
/**
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
background-color: lighten($silver, $opacity_7);
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
-
.bg-white {
|
|
54
|
+
.pb-bg-row-white {
|
|
55
55
|
background-color: $white;
|
|
56
56
|
}
|
|
57
57
|
|
|
@@ -278,7 +278,7 @@
|
|
|
278
278
|
}
|
|
279
279
|
}
|
|
280
280
|
|
|
281
|
-
&.bg-white {
|
|
281
|
+
&.pb-bg-row-white {
|
|
282
282
|
td:first-child {
|
|
283
283
|
background-color: $white;
|
|
284
284
|
}
|
|
@@ -756,7 +756,7 @@
|
|
|
756
756
|
border-bottom-color: $border_dark !important;
|
|
757
757
|
}
|
|
758
758
|
|
|
759
|
-
.bg-white {
|
|
759
|
+
.pb-bg-row-white {
|
|
760
760
|
background: $bg_dark_card;
|
|
761
761
|
}
|
|
762
762
|
|
|
@@ -766,7 +766,7 @@
|
|
|
766
766
|
|
|
767
767
|
// Dark mode virtualized rows
|
|
768
768
|
.virtualized-table-row {
|
|
769
|
-
&.bg-white {
|
|
769
|
+
&.pb-bg-row-white {
|
|
770
770
|
background: $bg_dark_card !important;
|
|
771
771
|
|
|
772
772
|
td:first-child {
|
|
@@ -308,10 +308,10 @@ test("Row toggle button exists and toggles subrows open and closed", () => {
|
|
|
308
308
|
const kit = screen.getByTestId(testId)
|
|
309
309
|
const rowButton = kit.querySelector(".gray-icon.expand-toggle-icon")
|
|
310
310
|
expect(rowButton).toBeInTheDocument()
|
|
311
|
-
const subRow1 = kit.querySelector(".bg-white.depth-sub-row-1")
|
|
311
|
+
const subRow1 = kit.querySelector(".pb-bg-row-white.depth-sub-row-1")
|
|
312
312
|
expect(subRow1).not.toBeInTheDocument()
|
|
313
313
|
rowButton.click()
|
|
314
|
-
const subRow = kit.querySelector(".bg-white.depth-sub-row-1")
|
|
314
|
+
const subRow = kit.querySelector(".pb-bg-row-white.depth-sub-row-1")
|
|
315
315
|
expect(subRow).toBeInTheDocument()
|
|
316
316
|
})
|
|
317
317
|
|
|
@@ -328,13 +328,13 @@ test("toggleExpansionAll button exists and toggles subrows open and closed", asy
|
|
|
328
328
|
const toggleButton = kit.querySelector(".gray-icon.toggle-all-icon");
|
|
329
329
|
expect(toggleButton).toBeInTheDocument();
|
|
330
330
|
|
|
331
|
-
const subRow1 = kit.querySelector(".bg-white.depth-sub-row-1");
|
|
331
|
+
const subRow1 = kit.querySelector(".pb-bg-row-white.depth-sub-row-1");
|
|
332
332
|
expect(subRow1).not.toBeInTheDocument();
|
|
333
333
|
|
|
334
334
|
toggleButton.click();
|
|
335
335
|
|
|
336
336
|
await waitFor(() => {
|
|
337
|
-
const subRow = kit.querySelector(".bg-white.depth-sub-row-1");
|
|
337
|
+
const subRow = kit.querySelector(".pb-bg-row-white.depth-sub-row-1");
|
|
338
338
|
expect(subRow).toBeInTheDocument();
|
|
339
339
|
})
|
|
340
340
|
})
|
|
@@ -385,7 +385,7 @@ test("expandControl prop works as expected", () => {
|
|
|
385
385
|
render (<AdvancedTableExpandControl/>)
|
|
386
386
|
|
|
387
387
|
const kit = screen.getByTestId(testId)
|
|
388
|
-
const subRow = kit.querySelector(".bg-white.depth-sub-row-1")
|
|
388
|
+
const subRow = kit.querySelector(".pb-bg-row-white.depth-sub-row-1")
|
|
389
389
|
expect(subRow).toBeInTheDocument()
|
|
390
390
|
})
|
|
391
391
|
|
|
@@ -51,7 +51,7 @@ export default class PbFlatAdvancedTable extends PbEnhancedElement {
|
|
|
51
51
|
|
|
52
52
|
const tr = rowCb.closest("tr");
|
|
53
53
|
tr?.classList.toggle("bg-row-selection", rowCb.checked);
|
|
54
|
-
tr?.classList.toggle("bg-white", !rowCb.checked);
|
|
54
|
+
tr?.classList.toggle("pb-bg-row-white", !rowCb.checked);
|
|
55
55
|
}
|
|
56
56
|
|
|
57
57
|
if (allCb) {
|
|
@@ -62,7 +62,7 @@ export default class PbFlatAdvancedTable extends PbEnhancedElement {
|
|
|
62
62
|
cb.checked = checked;
|
|
63
63
|
const tr = cb.closest("tr");
|
|
64
64
|
tr?.classList.toggle("bg-row-selection", checked);
|
|
65
|
-
tr?.classList.toggle("bg-white", !checked);
|
|
65
|
+
tr?.classList.toggle("pb-bg-row-white", !checked);
|
|
66
66
|
const id = cb.id;
|
|
67
67
|
if (checked) this.selectedRows.add(id);
|
|
68
68
|
else this.selectedRows.delete(id);
|
|
@@ -76,7 +76,7 @@ export default class PbAdvancedTable extends PbEnhancedElement {
|
|
|
76
76
|
// Only apply styling if the checkbox is inside a table row
|
|
77
77
|
if (rowEl) {
|
|
78
78
|
rowEl.classList.add("bg-row-selection");
|
|
79
|
-
rowEl.classList.remove("bg-white", "bg-silver");
|
|
79
|
+
rowEl.classList.remove("pb-bg-row-white", "bg-silver");
|
|
80
80
|
}
|
|
81
81
|
} else {
|
|
82
82
|
// Only apply styling if the checkbox is inside a table row
|
|
@@ -85,9 +85,9 @@ export default class PbAdvancedTable extends PbEnhancedElement {
|
|
|
85
85
|
|
|
86
86
|
if (this.isRowExpanded(rowEl)) {
|
|
87
87
|
rowEl.classList.remove("bg-silver");
|
|
88
|
-
rowEl.classList.add("bg-white");
|
|
88
|
+
rowEl.classList.add("pb-bg-row-white");
|
|
89
89
|
} else {
|
|
90
|
-
rowEl.classList.remove("bg-white");
|
|
90
|
+
rowEl.classList.remove("pb-bg-row-white");
|
|
91
91
|
rowEl.classList.add("bg-silver");
|
|
92
92
|
}
|
|
93
93
|
}
|
|
@@ -120,7 +120,7 @@ export default class PbAdvancedTable extends PbEnhancedElement {
|
|
|
120
120
|
if (isChecked) {
|
|
121
121
|
PbAdvancedTable.selectedRows.add(rowId);
|
|
122
122
|
rowEl.classList.add("bg-row-selection");
|
|
123
|
-
rowEl.classList.remove("bg-white", "bg-silver");
|
|
123
|
+
rowEl.classList.remove("pb-bg-row-white", "bg-silver");
|
|
124
124
|
} else {
|
|
125
125
|
PbAdvancedTable.selectedRows.delete(rowId);
|
|
126
126
|
}
|
|
@@ -130,9 +130,9 @@ export default class PbAdvancedTable extends PbEnhancedElement {
|
|
|
130
130
|
|
|
131
131
|
if (this.isRowExpanded(rowEl)) {
|
|
132
132
|
rowEl.classList.remove("bg-silver");
|
|
133
|
-
rowEl.classList.add("bg-white");
|
|
133
|
+
rowEl.classList.add("pb-bg-row-white");
|
|
134
134
|
} else {
|
|
135
|
-
rowEl.classList.remove("bg-white");
|
|
135
|
+
rowEl.classList.remove("pb-bg-row-white");
|
|
136
136
|
rowEl.classList.add("bg-silver");
|
|
137
137
|
}
|
|
138
138
|
}
|
|
@@ -407,7 +407,7 @@ export default class PbAdvancedTable extends PbEnhancedElement {
|
|
|
407
407
|
const row = this.element.closest("tr");
|
|
408
408
|
if (row) {
|
|
409
409
|
row.classList.toggle("bg-silver", !isVisible);
|
|
410
|
-
row.classList.toggle("bg-white", isVisible);
|
|
410
|
+
row.classList.toggle("pb-bg-row-white", isVisible);
|
|
411
411
|
}
|
|
412
412
|
|
|
413
413
|
this.addBorderRadiusOnLastVisibleRow();
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
-
.bg-white {
|
|
55
|
+
.pb-bg-row-white {
|
|
56
56
|
td:first-child,
|
|
57
57
|
.sticky-left {
|
|
58
58
|
background-color: $bg-main;
|
|
@@ -63,7 +63,7 @@
|
|
|
63
63
|
&.bg-silver td:first-child {
|
|
64
64
|
background-color: $bg-secondary;
|
|
65
65
|
}
|
|
66
|
-
&.bg-white td:first-child {
|
|
66
|
+
&.pb-bg-row-white td:first-child {
|
|
67
67
|
background-color: $bg-main;
|
|
68
68
|
}
|
|
69
69
|
&.bg-row-selection td:first-child {
|
|
@@ -39,7 +39,7 @@ module Playbook
|
|
|
39
39
|
end
|
|
40
40
|
|
|
41
41
|
def classname
|
|
42
|
-
generate_classname("pb_table_tr", "bg-white", subrow_depth_classname, separator: " ")
|
|
42
|
+
generate_classname("pb_table_tr", "pb-bg-row-white", subrow_depth_classname, separator: " ")
|
|
43
43
|
end
|
|
44
44
|
|
|
45
45
|
def td_classname(column, index)
|
|
@@ -19,7 +19,6 @@ type DateRangeInlineProps = {
|
|
|
19
19
|
icon?: boolean;
|
|
20
20
|
id?: string;
|
|
21
21
|
size?: "sm" | "xs";
|
|
22
|
-
showCurrentYear?: boolean;
|
|
23
22
|
startDate?: Date;
|
|
24
23
|
};
|
|
25
24
|
|
|
@@ -46,7 +45,6 @@ const DateRangeInline = (props: DateRangeInlineProps): React.ReactElement => {
|
|
|
46
45
|
icon = false,
|
|
47
46
|
size = "sm",
|
|
48
47
|
startDate,
|
|
49
|
-
showCurrentYear = false,
|
|
50
48
|
} = props;
|
|
51
49
|
|
|
52
50
|
const dateInCurrentYear = () => {
|
|
@@ -62,10 +60,13 @@ const DateRangeInline = (props: DateRangeInlineProps): React.ReactElement => {
|
|
|
62
60
|
const htmlProps = buildHtmlProps(htmlOptions);
|
|
63
61
|
|
|
64
62
|
const renderTime = (date: Date) => {
|
|
65
|
-
const includeYear = showCurrentYear || !dateInCurrentYear();
|
|
66
63
|
return (
|
|
67
64
|
<time dateTime={dateTimeIso(date)}>
|
|
68
|
-
{
|
|
65
|
+
{dateInCurrentYear() ? (
|
|
66
|
+
` ${dateTimestamp(date, false)} `
|
|
67
|
+
) : (
|
|
68
|
+
` ${dateTimestamp(date, true)} `
|
|
69
|
+
)}
|
|
69
70
|
</time>
|
|
70
71
|
);
|
|
71
72
|
};
|
|
@@ -82,8 +83,7 @@ const DateRangeInline = (props: DateRangeInlineProps): React.ReactElement => {
|
|
|
82
83
|
{icon && (
|
|
83
84
|
<Caption
|
|
84
85
|
dark={dark}
|
|
85
|
-
tag="span"
|
|
86
|
-
>
|
|
86
|
+
tag="span">
|
|
87
87
|
<Icon
|
|
88
88
|
className="pb_date_range_inline_icon"
|
|
89
89
|
dark={dark}
|
|
@@ -96,14 +96,12 @@ const DateRangeInline = (props: DateRangeInlineProps): React.ReactElement => {
|
|
|
96
96
|
)}
|
|
97
97
|
<Caption
|
|
98
98
|
dark={dark}
|
|
99
|
-
tag="span"
|
|
100
|
-
>
|
|
99
|
+
tag="span">
|
|
101
100
|
{renderTime(startDate)}
|
|
102
101
|
</Caption>
|
|
103
102
|
<Caption
|
|
104
103
|
dark={dark}
|
|
105
|
-
tag="span"
|
|
106
|
-
>
|
|
104
|
+
tag="span">
|
|
107
105
|
<Icon
|
|
108
106
|
className="pb_date_range_inline_arrow"
|
|
109
107
|
dark={dark}
|
|
@@ -114,8 +112,7 @@ const DateRangeInline = (props: DateRangeInlineProps): React.ReactElement => {
|
|
|
114
112
|
</Caption>
|
|
115
113
|
<Caption
|
|
116
114
|
dark={dark}
|
|
117
|
-
tag="span"
|
|
118
|
-
>
|
|
115
|
+
tag="span">
|
|
119
116
|
{renderTime(endDate)}
|
|
120
117
|
</Caption>
|
|
121
118
|
</>
|
|
@@ -127,8 +124,7 @@ const DateRangeInline = (props: DateRangeInlineProps): React.ReactElement => {
|
|
|
127
124
|
<Body
|
|
128
125
|
color={"light"}
|
|
129
126
|
dark={dark}
|
|
130
|
-
tag="span"
|
|
131
|
-
>
|
|
127
|
+
tag="span">
|
|
132
128
|
<Icon
|
|
133
129
|
className="pb_date_range_inline_icon"
|
|
134
130
|
dark={dark}
|
|
@@ -141,15 +137,13 @@ const DateRangeInline = (props: DateRangeInlineProps): React.ReactElement => {
|
|
|
141
137
|
)}
|
|
142
138
|
<Body
|
|
143
139
|
dark={dark}
|
|
144
|
-
tag="span"
|
|
145
|
-
>
|
|
140
|
+
tag="span">
|
|
146
141
|
{renderTime(startDate)}
|
|
147
142
|
</Body>
|
|
148
143
|
<Body
|
|
149
144
|
color={"light"}
|
|
150
145
|
dark={dark}
|
|
151
|
-
tag="span"
|
|
152
|
-
>
|
|
146
|
+
tag="span">
|
|
153
147
|
<Icon
|
|
154
148
|
className="pb_date_range_inline_arrow"
|
|
155
149
|
dark={dark}
|
|
@@ -160,8 +154,7 @@ const DateRangeInline = (props: DateRangeInlineProps): React.ReactElement => {
|
|
|
160
154
|
</Body>
|
|
161
155
|
<Body
|
|
162
156
|
dark={dark}
|
|
163
|
-
tag="span"
|
|
164
|
-
>
|
|
157
|
+
tag="span">
|
|
165
158
|
{renderTime(endDate)}
|
|
166
159
|
</Body>
|
|
167
160
|
</>
|
|
@@ -14,8 +14,7 @@ module Playbook
|
|
|
14
14
|
prop :align, type: Playbook::Props::Enum,
|
|
15
15
|
values: %w[left center right],
|
|
16
16
|
default: "left"
|
|
17
|
-
|
|
18
|
-
default: false
|
|
17
|
+
|
|
19
18
|
def classname
|
|
20
19
|
generate_classname("pb_date_range_inline_kit", dark_class, align)
|
|
21
20
|
end
|
|
@@ -39,12 +38,11 @@ module Playbook
|
|
|
39
38
|
end
|
|
40
39
|
|
|
41
40
|
def time_display(time)
|
|
42
|
-
include_year = show_current_year || !dates_in_current_year?
|
|
43
41
|
content_tag(:time, datetime: time.to_iso) do
|
|
44
|
-
if
|
|
45
|
-
"#{time.to_month_downcase} #{time.to_day}, #{time.to_year}"
|
|
46
|
-
else
|
|
42
|
+
if dates_in_current_year?
|
|
47
43
|
"#{time.to_month_downcase} #{time.to_day}"
|
|
44
|
+
else
|
|
45
|
+
"#{time.to_month_downcase} #{time.to_day}, #{time.to_year}"
|
|
48
46
|
end
|
|
49
47
|
end
|
|
50
48
|
end
|
|
@@ -111,23 +111,6 @@ describe("DateRangeInline Kit", () => {
|
|
|
111
111
|
const text = kit.querySelector('.pb_caption_kit_md:first-child')
|
|
112
112
|
expect(text.textContent).toEqual(" Jan 15 ")
|
|
113
113
|
})
|
|
114
|
-
|
|
115
|
-
test("renders DateRangeInline with year when showCurrentYear is true", () => {
|
|
116
|
-
const currentYear = new Date().getFullYear()
|
|
117
|
-
render(
|
|
118
|
-
<DateRangeInline
|
|
119
|
-
data={{ testid: testId }}
|
|
120
|
-
endDate={new Date((`15 Aug ${currentYear}`))}
|
|
121
|
-
showCurrentYear
|
|
122
|
-
size="xs"
|
|
123
|
-
startDate={new Date(`15 Jan ${currentYear}`)}
|
|
124
|
-
/>
|
|
125
|
-
)
|
|
126
|
-
|
|
127
|
-
const kit = screen.getByTestId(testId)
|
|
128
|
-
const text = kit.querySelector('.pb_caption_kit_md:first-child')
|
|
129
|
-
expect(text.textContent).toEqual(` Jan 15, ${currentYear} `)
|
|
130
|
-
})
|
|
131
114
|
|
|
132
115
|
|
|
133
116
|
})
|
|
@@ -1 +1 @@
|
|
|
1
|
-
Use to display a date range.
|
|
1
|
+
Use to display a date range. Year will not show if it is the current year.
|
|
@@ -2,12 +2,11 @@ examples:
|
|
|
2
2
|
|
|
3
3
|
rails:
|
|
4
4
|
- date_range_inline_default: Default
|
|
5
|
-
|
|
5
|
+
|
|
6
6
|
|
|
7
7
|
react:
|
|
8
8
|
- date_range_inline_default: Default
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
|
|
11
10
|
swift:
|
|
12
11
|
- date_range_inline_default_swift: Default
|
|
13
12
|
- date_range_inline_props_swift: ""
|
|
@@ -8,13 +8,13 @@ const ERROR_MESSAGE_SELECTOR = '.pb_body_kit_negative'
|
|
|
8
8
|
// Validation selectors
|
|
9
9
|
const FORM_SELECTOR = 'form[data-pb-form-validation="true"]'
|
|
10
10
|
const REQUIRED_FIELDS_SELECTOR = 'input[required],textarea[required],select[required]'
|
|
11
|
+
const PHONE_NUMBER_VALIDATION_ERROR_SELECTOR = '[data-pb-phone-validation-error="true"]'
|
|
11
12
|
|
|
12
13
|
const FIELD_EVENTS = [
|
|
13
14
|
'change',
|
|
14
15
|
'valid',
|
|
15
16
|
'invalid',
|
|
16
17
|
]
|
|
17
|
-
|
|
18
18
|
class PbFormValidation extends PbEnhancedElement {
|
|
19
19
|
static get selector() {
|
|
20
20
|
return FORM_SELECTOR
|
|
@@ -22,12 +22,27 @@ class PbFormValidation extends PbEnhancedElement {
|
|
|
22
22
|
|
|
23
23
|
connect() {
|
|
24
24
|
this.formValidationFields.forEach((field) => {
|
|
25
|
+
// Skip phone number inputs - they handle their own validation
|
|
26
|
+
const isPhoneNumberInput = field.closest('.pb_phone_number_input')
|
|
27
|
+
if (isPhoneNumberInput) return
|
|
28
|
+
|
|
25
29
|
FIELD_EVENTS.forEach((e) => {
|
|
26
30
|
field.addEventListener(e, debounce((event) => {
|
|
27
31
|
this.validateFormField(event)
|
|
28
32
|
}, 250), false)
|
|
29
33
|
})
|
|
30
34
|
})
|
|
35
|
+
|
|
36
|
+
// Add event listener to check for phone number validation errors
|
|
37
|
+
this.element.addEventListener('submit', (event) => {
|
|
38
|
+
// Use setTimeout to ensure React state updates have completed
|
|
39
|
+
setTimeout(() => {
|
|
40
|
+
if (this.hasPhoneNumberValidationErrors()) {
|
|
41
|
+
event.preventDefault()
|
|
42
|
+
return false
|
|
43
|
+
}
|
|
44
|
+
}, 0)
|
|
45
|
+
})
|
|
31
46
|
}
|
|
32
47
|
|
|
33
48
|
validateFormField(event) {
|
|
@@ -45,40 +60,58 @@ class PbFormValidation extends PbEnhancedElement {
|
|
|
45
60
|
|
|
46
61
|
showValidationMessage(target) {
|
|
47
62
|
const { parentElement } = target
|
|
63
|
+
const kitElement = parentElement.closest(KIT_SELECTOR)
|
|
64
|
+
|
|
65
|
+
// FIX: Add null check for kitElement
|
|
66
|
+
if (!kitElement) return
|
|
67
|
+
|
|
68
|
+
// Check if this is a phone number input
|
|
69
|
+
const isPhoneNumberInput = kitElement.classList.contains('pb_phone_number_input')
|
|
48
70
|
|
|
49
71
|
// ensure clean error message state
|
|
50
72
|
this.clearError(target)
|
|
51
|
-
|
|
73
|
+
kitElement.classList.add('error')
|
|
52
74
|
|
|
53
|
-
//
|
|
54
|
-
|
|
75
|
+
// Only add error message if it's NOT a phone number input
|
|
76
|
+
if (!isPhoneNumberInput) {
|
|
77
|
+
// set the error message element
|
|
78
|
+
const errorMessageContainer = this.errorMessageContainer
|
|
55
79
|
|
|
56
|
-
|
|
80
|
+
if (target.dataset.message) target.setCustomValidity(target.dataset.message)
|
|
57
81
|
|
|
58
|
-
|
|
82
|
+
errorMessageContainer.innerHTML = target.validationMessage
|
|
59
83
|
|
|
60
|
-
|
|
61
|
-
|
|
84
|
+
// add the error message element to the dom tree
|
|
85
|
+
parentElement.appendChild(errorMessageContainer)
|
|
86
|
+
}
|
|
62
87
|
}
|
|
63
88
|
|
|
64
89
|
clearError(target) {
|
|
65
90
|
const { parentElement } = target
|
|
66
|
-
parentElement.closest(KIT_SELECTOR)
|
|
91
|
+
const kitElement = parentElement.closest(KIT_SELECTOR)
|
|
92
|
+
// Remove error class from kit element
|
|
93
|
+
if (kitElement) kitElement.classList.remove('error')
|
|
94
|
+
// Remove error message from parent element
|
|
67
95
|
const errorMessageContainer = parentElement.querySelector(ERROR_MESSAGE_SELECTOR)
|
|
68
96
|
if (errorMessageContainer) errorMessageContainer.remove()
|
|
69
97
|
}
|
|
70
98
|
|
|
99
|
+
// Check if there are phone number input errors
|
|
100
|
+
hasPhoneNumberValidationErrors() {
|
|
101
|
+
const phoneNumberErrors = this.element.querySelectorAll(PHONE_NUMBER_VALIDATION_ERROR_SELECTOR)
|
|
102
|
+
return phoneNumberErrors.length > 0
|
|
103
|
+
}
|
|
104
|
+
|
|
71
105
|
get errorMessageContainer() {
|
|
72
106
|
const errorContainer = document.createElement('div')
|
|
73
107
|
const kitClassName = ERROR_MESSAGE_SELECTOR.replace(/\./, '')
|
|
74
108
|
errorContainer.classList.add(kitClassName)
|
|
75
109
|
return errorContainer
|
|
76
110
|
}
|
|
77
|
-
|
|
78
111
|
get formValidationFields() {
|
|
79
112
|
return this._formValidationFields =
|
|
80
113
|
this._formValidationFields || this.element.querySelectorAll(REQUIRED_FIELDS_SELECTOR)
|
|
81
114
|
}
|
|
82
115
|
}
|
|
83
116
|
|
|
84
|
-
window.PbFormValidation = PbFormValidation
|
|
117
|
+
window.PbFormValidation = PbFormValidation
|