playbook_ui 14.10.0.pre.rc.9 → 14.10.0.pre.rc.11

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: 6dede8e498da8201d5783aa113ad9cfa06db70460791a7e6cc67328ced91e88a
4
- data.tar.gz: 76a40d46cd6968ef24a810333b5143b13e7ceb78b9a6bfb5a3ff5b10c5465571
3
+ metadata.gz: 02cb75778708807c68edd60c9ae394cdd6ed19db379a63bb1e8fe2f196e9e54d
4
+ data.tar.gz: 11890f70f00f0d8081be4e8ee2b1c75169f27c69b12cded4353f5242c3051731
5
5
  SHA512:
6
- metadata.gz: 6184a602390dd81aab270b57e46f23efee38f08d5d435fe18bdece7b6a2a58b3053122a130972cf4f4c400702977b9403eef85c5f875e87ed8a621cf72821006
7
- data.tar.gz: 9d89ce0480e357053bd154ce7c6996b3cf04bc7906438715b8449cece944c96f8591db62689a713dfd9c7d9c8d345becf3de978e138517b0463ed66a54604fd0
6
+ metadata.gz: a2f84f6105b56fa029596898f3f98ce0bb766507d5e6136f06ef6485d8715253716d815143340371892a8b846e95b02b172533005b18429ee45ca0f32e427f3f
7
+ data.tar.gz: 6bad2b92c4c9e4a97ea43649ce7e4f2bf4d1a44e70cede7f30aa55deab480f61a2dc9229d5c177457a4b7ee2d27fc4ef23f42370e0c06c8aad374b74db8f5f93
@@ -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
@@ -20,6 +20,13 @@
20
20
  }
21
21
  }
22
22
 
23
+ @mixin hover-underline {
24
+ .hover_underline:hover {
25
+ text-decoration: underline;
26
+ transition: text-decoration $transition-speed ease;
27
+ }
28
+ }
29
+
23
30
  @mixin hover-color-classes($colors-list) {
24
31
  @each $name, $color in $colors-list {
25
32
  .hover_background-#{"" + $name}:hover {
@@ -32,7 +39,9 @@
32
39
  }
33
40
  }
34
41
  }
35
-
42
+
43
+
44
+ @include hover-underline;
36
45
  @include hover-scale-classes($scales);
37
46
  @include hover-shadow-classes($box_shadows);
38
47
  @include hover-color-classes($product_colors);
@@ -64,4 +73,4 @@
64
73
  .group_hover.hover_visibility {
65
74
  opacity: 1;
66
75
  }
67
- }
76
+ }
@@ -64,6 +64,7 @@ type Hover = Shadow & {
64
64
  background?: string,
65
65
  color?: string,
66
66
  scale?: "sm" | "md" | "lg",
67
+ underline?: boolean,
67
68
  visibility?: boolean,
68
69
  }
69
70
 
@@ -236,6 +237,7 @@ const PROP_CATEGORIES: {[key:string]: (props: {[key: string]: any}) => string} =
236
237
  if (!hover) return css;
237
238
  css += hover.shadow ? `hover_shadow_${hover.shadow} ` : '';
238
239
  css += hover.background ? `hover_background-${hover.background } ` : '';
240
+ css += hover.underline ? `hover_underline ` : '';
239
241
  css += hover.scale ? `hover_scale_${hover.scale} ` : '';
240
242
  css += hover.color ? `hover_color-${hover.color } ` : '';
241
243
  css += hover.visibility ? `hover_visibility` : '';
@@ -57,6 +57,19 @@ test('Hover Props: returns proper class name', () => {
57
57
  expectedClassName = `hover_scale_xl`;
58
58
  expect(kit).toHaveClass(expectedClassName);
59
59
 
60
+ const testIdUnderline = `${testSubject}-hover-underline`;
61
+ render(
62
+ <Body
63
+ data={{ testid: testIdUnderline }}
64
+ hover={{ underline: true }}
65
+ text="Hi"
66
+ />
67
+ );
68
+
69
+ kit = screen.getByTestId(testIdUnderline);
70
+ expectedClassName = `hover_underline`;
71
+ expect(kit).toHaveClass(expectedClassName);
72
+
60
73
  const testIdMultiple = `${testSubject}-hover-multiple`;
61
74
  render(
62
75
  <Body
@@ -66,6 +79,7 @@ test('Hover Props: returns proper class name', () => {
66
79
  background: 'error',
67
80
  shadow: 'deeper',
68
81
  scale: 'xl',
82
+ underline: true,
69
83
  }}
70
84
  text="Hi"
71
85
  />
@@ -76,4 +90,5 @@ test('Hover Props: returns proper class name', () => {
76
90
  expect(kit).toHaveClass('hover_background-error');
77
91
  expect(kit).toHaveClass('hover_shadow_deeper');
78
92
  expect(kit).toHaveClass('hover_scale_xl');
93
+ expect(kit).toHaveClass('hover_underline');
79
94
  });