playbook_ui 14.9.0.pre.alpha.PLAY1731inputmasking4868 → 14.9.0.pre.alpha.PLAY1731inputmasking4890

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b40a6d80e2e00552963c2986d6ae0e1bad26cd43320b0959b534e37f0e7d71fa
4
- data.tar.gz: 52bb830750b5edc87fe3a4c670c944e1fcdf78764649ebcc708db45257694c0d
3
+ metadata.gz: ace04229d2b84d22c632f080832024432c4454ab7fcd274fdc941babe4b4c3e5
4
+ data.tar.gz: c950b28b5c9a9345f27eb1f7b3e4b732ff2db706cc7f55f868a67be87042dc42
5
5
  SHA512:
6
- metadata.gz: c4f3b88e16a1efe2875d297f45e030854943cc62a8a8ddaf8629c6e6f674e54583e72bfe24d1185ef67de57b3e497597f0c328c427f362f6868b5b136e720541
7
- data.tar.gz: 8d309708dbc3912906a4f2b73829fcff692c195b641bd352dee6e313409f74c6ba2c8ea782bbb4c8784a7ca5e5ee3ed5084e4cc147130e37bc9f5203e4cbdee2
6
+ metadata.gz: 8a29e24c59e3f6d6b819d65ecd3702134a15f7accedb68fc78c18c7e949249bd1eb203d562ab6bff6ec4cbae4b462a0086a128acee68c3d805831533d1695c14
7
+ data.tar.gz: d438301928055198fae77f828152f61dffa9e6f08cfdc47e7c612b14a1afee13d26575d6ed2ba65b49fe0b9f60f6ae5c52fb121da526a1e9dd5cb5ecb49aa16a
@@ -0,0 +1,95 @@
1
+ <%= pb_rails("table", props: { size: "md", responsive: "scroll", sticky_left_column: ["1", "2", "3"] }) do %>
2
+ <thead>
3
+ <tr>
4
+ <th id="1">Column 1</th>
5
+ <th id="2">Column 2</th>
6
+ <th id="3">Column 3</th>
7
+ <th>Column 4</th>
8
+ <th>Column 5</th>
9
+ <th>Column 6</th>
10
+ <th>Column 7</th>
11
+ <th>Column 8</th>
12
+ <th>Column 9</th>
13
+ <th>Column 10</th>
14
+ <th>Column 11</th>
15
+ <th>Column 12</th>
16
+ <th>Column 13</th>
17
+ <th>Column 14</th>
18
+ <th>Column 15</th>
19
+ </tr>
20
+ </thead>
21
+ <tbody>
22
+ <tr>
23
+ <td id="1">Value 1</td>
24
+ <td id="2">Value 2</td>
25
+ <td id="3">Value 3</td>
26
+ <td>Value 4</td>
27
+ <td>Value 5</td>
28
+ <td>Column 6</td>
29
+ <td>Column 7</td>
30
+ <td>Column 8</td>
31
+ <td>Column 9</td>
32
+ <td>Column 10</td>
33
+ <td>Column 11</td>
34
+ <td>Column 12</td>
35
+ <td>Column 13</td>
36
+ <td>Column 14</td>
37
+ <td>Column 15</td>
38
+
39
+ </tr>
40
+ <tr>
41
+ <td id="1">Value 1</td>
42
+ <td id="2">Value 2</td>
43
+ <td id="3">Value 3</td>
44
+ <td>Value 4</td>
45
+ <td>Value 5</td>
46
+ <td>Column 6</td>
47
+ <td>Column 7</td>
48
+ <td>Column 8</td>
49
+ <td>Column 9</td>
50
+ <td>Column 10</td>
51
+ <td>Column 11</td>
52
+ <td>Column 12</td>
53
+ <td>Column 13</td>
54
+ <td>Column 14</td>
55
+ <td>Column 15</td>
56
+
57
+ </tr>
58
+ <tr>
59
+ <td id="1">Value 1</td>
60
+ <td id="2">Value 2</td>
61
+ <td id="3">Value 3</td>
62
+ <td>Value 4</td>
63
+ <td>Value 5</td>
64
+ <td>Column 6</td>
65
+ <td>Column 7</td>
66
+ <td>Column 8</td>
67
+ <td>Column 9</td>
68
+ <td>Column 10</td>
69
+ <td>Column 11</td>
70
+ <td>Column 12</td>
71
+ <td>Column 13</td>
72
+ <td>Column 14</td>
73
+ <td>Column 15</td>
74
+
75
+ </tr>
76
+ <tr>
77
+ <td id="1">Value 1</td>
78
+ <td id="2">Value 2</td>
79
+ <td id="3">Value 3</td>
80
+ <td>Value 4</td>
81
+ <td>Value 5</td>
82
+ <td>Column 6</td>
83
+ <td>Column 7</td>
84
+ <td>Column 8</td>
85
+ <td>Column 9</td>
86
+ <td>Column 10</td>
87
+ <td>Column 11</td>
88
+ <td>Column 12</td>
89
+ <td>Column 13</td>
90
+ <td>Column 14</td>
91
+ <td>Column 15</td>
92
+
93
+ </tr>
94
+ </tbody>
95
+ <% end %>
@@ -1,32 +1,106 @@
1
1
  import PbEnhancedElement from '../pb_enhanced_element'
2
2
 
3
3
  export default class PbTable extends PbEnhancedElement {
4
- static get selector(): string {
5
- return '.table-responsive-collapse'
6
- }
7
-
8
- connect(): void {
9
- const tables = document.querySelectorAll('.table-responsive-collapse');
10
-
11
- // Each Table
12
- [].forEach.call(tables, (table: HTMLTableElement) => {
13
- // Header Titles
14
- const headers: string[] = [];
15
- [].forEach.call(table.querySelectorAll('th'), (header: HTMLTableCellElement) => {
16
- const colSpan = header.colSpan
17
- for (let i = 0; i < colSpan; i++) {
18
- headers.push(header.textContent.replace(/\r?\n|\r/, ''));
4
+ private stickyLeftColumns: string[] = [];
5
+ private handleStickyColumnsRef: () => void;
6
+
7
+ static get selector(): string {
8
+ return '.table-responsive-collapse'
9
+ }
10
+
11
+ connect(): void {
12
+ const tables = document.querySelectorAll('.table-responsive-collapse');
13
+ // Each Table
14
+ [].forEach.call(tables, (table: HTMLTableElement) => {
15
+ // Header Titles
16
+ const headers: string[] = [];
17
+ [].forEach.call(table.querySelectorAll('th'), (header: HTMLTableCellElement) => {
18
+ const colSpan = header.colSpan
19
+ for (let i = 0; i < colSpan; i++) {
20
+ headers.push(header.textContent.replace(/\r?\n|\r/, ''));
21
+ }
22
+ });
23
+ // for each row in tbody
24
+ [].forEach.call(table.querySelectorAll('tbody tr'), (row: HTMLTableRowElement) => {
25
+ // for each cell
26
+ [].forEach.call(row.cells, (cell: HTMLTableCellElement, headerIndex: number) => {
27
+ // apply the attribute
28
+ cell.setAttribute('data-title', headers[headerIndex])
29
+ })
30
+ })
31
+ });
32
+
33
+ // New sticky columns logic
34
+ this.initStickyColumns();
35
+ }
36
+
37
+ private initStickyColumns(): void {
38
+ // Find tables with sticky-left-column class
39
+ const tables = document.querySelectorAll('.sticky-left-column');
40
+
41
+ tables.forEach((table) => {
42
+ // Extract sticky left column IDs by looking at the component's class
43
+ const classList = Array.from(table.classList);
44
+
45
+ // Look for classes in the format sticky-left-column-{ids}
46
+ const stickyColumnClass = classList.find(cls => cls.startsWith('sticky-columns-'));
47
+ if (stickyColumnClass) {
48
+ // Extract the IDs from the class name
49
+ this.stickyLeftColumns = stickyColumnClass
50
+ .replace('sticky-columns-', '')
51
+ .split('-');
52
+
53
+ if (this.stickyLeftColumns.length > 0) {
54
+ this.handleStickyColumnsRef = this.handleStickyColumns.bind(this);
55
+ this.handleStickyColumns();
56
+ window.addEventListener('resize', this.handleStickyColumnsRef);
57
+ }
19
58
  }
20
59
  });
60
+ }
21
61
 
22
- // for each row in tbody
23
- [].forEach.call(table.querySelectorAll('tbody tr'), (row: HTMLTableRowElement) => {
24
- // for each cell
25
- [].forEach.call(row.cells, (cell: HTMLTableCellElement, headerIndex: number) => {
26
- // apply the attribute
27
- cell.setAttribute('data-title', headers[headerIndex])
28
- })
29
- })
30
- })
31
- }
32
- }
62
+ private handleStickyColumns(): void {
63
+ let accumulatedWidth = 0;
64
+
65
+ this.stickyLeftColumns.forEach((colId, index) => {
66
+ const isLastColumn = index === this.stickyLeftColumns.length - 1;
67
+ const header = document.querySelector(`th[id="${colId}"]`);
68
+ const cells = document.querySelectorAll(`td[id="${colId}"]`);
69
+
70
+ if (header) {
71
+ header.classList.add('sticky');
72
+ (header as HTMLElement).style.left = `${accumulatedWidth}px`;
73
+
74
+ if (!isLastColumn) {
75
+ header.classList.add('with-border');
76
+ header.classList.remove('sticky-shadow');
77
+ } else {
78
+ header.classList.remove('with-border');
79
+ header.classList.add('sticky-shadow');
80
+ }
81
+
82
+ accumulatedWidth += (header as HTMLElement).offsetWidth;
83
+ }
84
+
85
+ cells.forEach((cell) => {
86
+ cell.classList.add('sticky');
87
+ (cell as HTMLElement).style.left = `${accumulatedWidth - (header as HTMLElement).offsetWidth}px`;
88
+
89
+ if (!isLastColumn) {
90
+ cell.classList.add('with-border');
91
+ cell.classList.remove('sticky-shadow');
92
+ } else {
93
+ cell.classList.remove('with-border');
94
+ cell.classList.add('sticky-shadow');
95
+ }
96
+ });
97
+ });
98
+ }
99
+
100
+ // Cleanup method to remove event listener
101
+ disconnect(): void {
102
+ if (this.handleStickyColumnsRef) {
103
+ window.removeEventListener('resize', this.handleStickyColumnsRef);
104
+ }
105
+ }
106
+ }
@@ -18,4 +18,4 @@
18
18
  <%= content.presence %>
19
19
  <% end %>
20
20
  <% end %>
21
- <% end %>
21
+ <% end %>
@@ -23,6 +23,8 @@ module Playbook
23
23
  prop :text
24
24
  prop :sticky, type: Playbook::Props::Boolean,
25
25
  default: false
26
+ prop :sticky_left_column, type: Playbook::Props::Array,
27
+ default: []
26
28
  prop :vertical_border, type: Playbook::Props::Boolean,
27
29
  default: false
28
30
  prop :striped, type: Playbook::Props::Boolean,
@@ -37,8 +39,8 @@ module Playbook
37
39
  def classname
38
40
  generate_classname(
39
41
  "pb_table", "table-#{size}", single_line_class, dark_class,
40
- disable_hover_class, container_class, data_table_class, sticky_class, collapse_class,
41
- vertical_border_class, striped_class, outer_padding_class,
42
+ disable_hover_class, container_class, data_table_class, sticky_class, sticky_left_column_class,
43
+ collapse_class, vertical_border_class, striped_class, outer_padding_class,
42
44
  "table-responsive-#{responsive}", separator: " "
43
45
  )
44
46
  end
@@ -73,6 +75,19 @@ module Playbook
73
75
  sticky ? "sticky-header" : nil
74
76
  end
75
77
 
78
+ def sticky_left_column_class
79
+ if sticky_left_column.empty?
80
+ nil
81
+ else
82
+ sticky_col_classname = "sticky-left-column sticky-columns"
83
+ sticky_left_column.each do |id|
84
+ sticky_col_classname += "-#{id}"
85
+ end
86
+
87
+ sticky_col_classname
88
+ end
89
+ end
90
+
76
91
  def striped_class
77
92
  striped ? "striped" : nil
78
93
  end
@@ -1,5 +1,5 @@
1
1
  type InputMask = {
2
- format: (value: string) => string
2
+ format: (value: string | number) => string
3
3
  pattern: string
4
4
  placeholder: string
5
5
  }
@@ -8,8 +8,10 @@ type InputMaskDictionary = {
8
8
  [key in 'currency' | 'zipCode' | 'postalCode' | 'ssn']: InputMask
9
9
  }
10
10
 
11
- const formatCurrency = (value: string): string => {
12
- const numericValue = value.replace(/[^0-9]/g, '').slice(0, 15)
11
+ const formatCurrency = (value: string | number): string => {
12
+ const valueString = typeof value === 'number' ? value.toString() : value;
13
+
14
+ const numericValue = valueString.replace(/[^0-9]/g, '').slice(0, 15)
13
15
 
14
16
  if (!numericValue) return ''
15
17
 
@@ -23,17 +25,23 @@ const formatCurrency = (value: string): string => {
23
25
  }).format(dollars)
24
26
  }
25
27
 
26
- const formatBasicPostal = (value: string): string => {
27
- return value.replace(/\D/g, '').slice(0, 5)
28
+ const formatBasicPostal = (value: string | number): string => {
29
+ const valueString = typeof value === 'number' ? value.toString() : value;
30
+
31
+ return valueString.replace(/\D/g, '').slice(0, 5)
28
32
  }
29
33
 
30
- const formatExtendedPostal = (value: string): string => {
31
- const cleaned = value.replace(/\D/g, '').slice(0, 9)
34
+ const formatExtendedPostal = (value: string | number): string => {
35
+ const valueString = typeof value === 'number' ? value.toString() : value;
36
+
37
+ const cleaned = valueString.replace(/\D/g, '').slice(0, 9)
32
38
  return cleaned.replace(/(\d{5})(?=\d)/, '$1-')
33
39
  }
34
40
 
35
- const formatSSN = (value: string): string => {
36
- const cleaned = value.replace(/\D/g, '').slice(0, 9)
41
+ const formatSSN = (value: string | number): string => {
42
+ const valueString = typeof value === 'number' ? value.toString() : value;
43
+
44
+ const cleaned = valueString.replace(/\D/g, '').slice(0, 9)
37
45
  return cleaned
38
46
  .replace(/(\d{5})(?=\d)/, '$1-')
39
47
  .replace(/(\d{3})(?=\d)/, '$1-')