playbook_ui 14.9.0.pre.alpha.PLAY1731inputmasking4927 → 14.9.0.pre.alpha.PLAY16264818

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.
Files changed (75) hide show
  1. checksums.yaml +4 -4
  2. data/app/pb_kits/playbook/pb_advanced_table/table_header.html.erb +3 -5
  3. data/app/pb_kits/playbook/pb_avatar/_avatar.scss +2 -0
  4. data/app/pb_kits/playbook/pb_bar_graph/docs/_bar_graph_custom.jsx +49 -53
  5. data/app/pb_kits/playbook/pb_bar_graph/docs/_bar_graph_custom_rails.html.erb +36 -29
  6. data/app/pb_kits/playbook/pb_body/_body.scss +13 -14
  7. data/app/pb_kits/playbook/pb_body/_body_mixins.scss +16 -22
  8. data/app/pb_kits/playbook/pb_bread_crumbs/docs/_bread_crumbs_default.jsx +0 -6
  9. data/app/pb_kits/playbook/pb_caption/_caption_mixin.scss +1 -2
  10. data/app/pb_kits/playbook/pb_card/_card_mixin.scss +1 -1
  11. data/app/pb_kits/playbook/pb_collapsible/_collapsible.tsx +4 -9
  12. data/app/pb_kits/playbook/pb_collapsible/child_kits/CollapsibleContent.tsx +2 -2
  13. data/app/pb_kits/playbook/pb_collapsible/child_kits/CollapsibleMain.tsx +2 -2
  14. data/app/pb_kits/playbook/pb_file_upload/_file_upload.scss +0 -5
  15. data/app/pb_kits/playbook/pb_file_upload/_file_upload.tsx +2 -7
  16. data/app/pb_kits/playbook/pb_file_upload/file_upload.html.erb +2 -8
  17. data/app/pb_kits/playbook/pb_link/_link.scss +3 -3
  18. data/app/pb_kits/playbook/pb_nav/_bold_mixin.scss +1 -11
  19. data/app/pb_kits/playbook/pb_nav/_collapsible_nav.scss +2 -16
  20. data/app/pb_kits/playbook/pb_nav/_vertical_nav.scss +1 -1
  21. data/app/pb_kits/playbook/pb_select/_select.tsx +19 -14
  22. data/app/pb_kits/playbook/pb_select/docs/_select_form.jsx +108 -0
  23. data/app/pb_kits/playbook/pb_select/docs/example.yml +1 -0
  24. data/app/pb_kits/playbook/pb_select/docs/index.js +1 -0
  25. data/app/pb_kits/playbook/pb_selectable_card/_selectable_card.scss +4 -4
  26. data/app/pb_kits/playbook/pb_selectable_card/selectable_card.html.erb +1 -1
  27. data/app/pb_kits/playbook/pb_stat_change/_stat_change.tsx +36 -44
  28. data/app/pb_kits/playbook/pb_stat_change/stat_change.html.erb +4 -4
  29. data/app/pb_kits/playbook/pb_table/docs/example.yml +0 -5
  30. data/app/pb_kits/playbook/pb_table/docs/index.js +0 -5
  31. data/app/pb_kits/playbook/pb_table/index.ts +26 -100
  32. data/app/pb_kits/playbook/pb_table/styles/_all.scss +1 -2
  33. data/app/pb_kits/playbook/pb_table/subcomponents/_table_row.tsx +1 -106
  34. data/app/pb_kits/playbook/pb_table/table.html.erb +1 -1
  35. data/app/pb_kits/playbook/pb_table/table.rb +2 -17
  36. data/app/pb_kits/playbook/pb_text_input/_text_input.tsx +3 -35
  37. data/app/pb_kits/playbook/pb_text_input/docs/example.yml +0 -1
  38. data/app/pb_kits/playbook/pb_text_input/docs/index.js +0 -1
  39. data/app/pb_kits/playbook/pb_text_input/text_input.test.js +2 -139
  40. data/app/pb_kits/playbook/pb_title/_title.scss +5 -6
  41. data/app/pb_kits/playbook/pb_title/_title_mixin.scss +0 -13
  42. data/app/pb_kits/playbook/tokens/_titles.scss +8 -0
  43. data/app/pb_kits/playbook/utilities/_hover.scss +2 -11
  44. data/app/pb_kits/playbook/utilities/globalProps.ts +0 -2
  45. data/app/pb_kits/playbook/utilities/hookFormProps.ts +16 -0
  46. data/app/pb_kits/playbook/utilities/test/globalProps/hover.test.js +0 -15
  47. data/dist/chunks/_typeahead-B8fkIeXA.js +22 -0
  48. data/dist/chunks/_weekday_stacked-DxlPBh55.js +45 -0
  49. data/dist/chunks/{lib-CuCy3_xO.js → lib-SyD3buPZ.js} +3 -3
  50. data/dist/chunks/{pb_form_validation-D37k10a0.js → pb_form_validation-Dt8UJgrJ.js} +1 -1
  51. data/dist/chunks/vendor.js +1 -1
  52. data/dist/menu.yml +1 -1
  53. data/dist/playbook-doc.js +1 -1
  54. data/dist/playbook-rails-react-bindings.js +1 -1
  55. data/dist/playbook-rails.js +1 -1
  56. data/dist/playbook.css +1 -1
  57. data/lib/playbook/hover.rb +1 -7
  58. data/lib/playbook/version.rb +1 -1
  59. metadata +8 -20
  60. data/app/pb_kits/playbook/pb_table/docs/_table_sticky_left_columns.html.erb +0 -95
  61. data/app/pb_kits/playbook/pb_table/docs/_table_with_collapsible.jsx +0 -75
  62. data/app/pb_kits/playbook/pb_table/docs/_table_with_collapsible.md +0 -1
  63. data/app/pb_kits/playbook/pb_table/docs/_table_with_collapsible_with_custom_click.jsx +0 -108
  64. data/app/pb_kits/playbook/pb_table/docs/_table_with_collapsible_with_custom_click.md +0 -2
  65. data/app/pb_kits/playbook/pb_table/docs/_table_with_collapsible_with_custom_content.jsx +0 -94
  66. data/app/pb_kits/playbook/pb_table/docs/_table_with_collapsible_with_custom_content.md +0 -0
  67. data/app/pb_kits/playbook/pb_table/docs/_table_with_collapsible_with_nested_rows.jsx +0 -83
  68. data/app/pb_kits/playbook/pb_table/docs/_table_with_collapsible_with_nested_rows.md +0 -3
  69. data/app/pb_kits/playbook/pb_table/docs/_table_with_collapsible_with_nested_table.jsx +0 -120
  70. data/app/pb_kits/playbook/pb_table/docs/_table_with_collapsible_with_nested_table.md +0 -1
  71. data/app/pb_kits/playbook/pb_table/styles/_collapsible.scss +0 -35
  72. data/app/pb_kits/playbook/pb_text_input/docs/_text_input_mask.jsx +0 -88
  73. data/app/pb_kits/playbook/pb_text_input/inputMask.ts +0 -64
  74. data/dist/chunks/_typeahead-l1kq1p9m.js +0 -22
  75. data/dist/chunks/_weekday_stacked-B28kYXl9.js +0 -45
@@ -223,7 +223,6 @@
223
223
  }
224
224
  }
225
225
  [class*="pb_collapsible_nav_item"][class*="pb_nav_list_item_link_collapsible"][class*="pb_nav_list_kit_item"] {
226
- box-shadow: unset !important;
227
226
  .pb_nav_list_item_text_collapsible {
228
227
  color: $white !important;
229
228
  }
@@ -241,17 +240,11 @@
241
240
 
242
241
  .pb_collapsible_main_kit:hover {
243
242
  background-color: mix($white, $card_dark, 20%);
244
- .pb_nav_list_item_text_collapsible {
245
- color: $white !important;
246
- }
247
- }
248
-
249
- .pb_collapsible_main_kit {
243
+ .pb_nav_list_item_text_collapsible,
250
244
  svg {
251
- color: $text_dk_default !important;
245
+ color: $white !important;
252
246
  }
253
247
  }
254
-
255
248
  .icon_wrapper:hover {
256
249
  background-color: mix($white, $card_dark, 40%);
257
250
  }
@@ -263,13 +256,6 @@
263
256
  }
264
257
  }
265
258
  }
266
-
267
- &[class*="_active"] {
268
- > .pb_collapsible_main_kit {
269
- background-color: $primary;
270
- box-shadow: 0 2px 10px 0 $shadow_dark;
271
- }
272
- }
273
259
  }
274
260
  }
275
261
  }
@@ -115,7 +115,7 @@ $selector: ".pb_nav_list";
115
115
  }
116
116
  [class*="_item_text"],
117
117
  [class*="_item_icon"] {
118
- color: $text_dk_light !important;
118
+ color: $text_dk_lighter !important;
119
119
  }
120
120
  &[class*="_link"] {
121
121
  &:hover {
@@ -1,8 +1,10 @@
1
1
  import React, { forwardRef } from 'react'
2
2
  import classnames from 'classnames'
3
+ import { FieldValues } from 'react-hook-form'
3
4
 
4
5
  import { buildAriaProps, buildCss, buildDataProps, buildHtmlProps } from '../utilities/props'
5
6
  import { globalProps, GlobalProps, domSafeProps } from '../utilities/globalProps'
7
+ import { HookFormProps, withHookForm } from '../utilities/hookFormProps'
6
8
  import type { InputCallback } from '../types'
7
9
  import { getAllIcons } from "../utilities/icons/allicons"
8
10
 
@@ -16,7 +18,7 @@ type SelectOption = {
16
18
  disabled?: boolean,
17
19
  }
18
20
 
19
- type SelectProps = {
21
+ type SelectProps<T extends FieldValues = FieldValues> = {
20
22
  aria?: { [key: string]: string },
21
23
  blankSelection?: string,
22
24
  children?: Node,
@@ -30,16 +32,17 @@ type SelectProps = {
30
32
  includeBlank?: string,
31
33
  inline?: boolean,
32
34
  label?: string,
33
- margin: string,
35
+ margin?: string,
34
36
  marginBottom: string,
37
+ marginTop: string,
35
38
  multiple?: boolean,
36
39
  name?: string,
37
- onChange: InputCallback<HTMLSelectElement>,
40
+ onChange?: InputCallback<HTMLSelectElement>,
38
41
  options: SelectOption[],
39
42
  required?: boolean,
40
43
  showArrow?: boolean,
41
44
  value?: string,
42
- } & GlobalProps
45
+ } & GlobalProps & Partial<HookFormProps<T>>
43
46
 
44
47
  const createOptions = (options: SelectOption[]) => options.map((option, index) => (
45
48
  <option
@@ -51,7 +54,7 @@ const createOptions = (options: SelectOption[]) => options.map((option, index) =
51
54
  </option>
52
55
  ))
53
56
 
54
- const Select = ({
57
+ const Select = <T extends FieldValues = FieldValues>({
55
58
  aria = {},
56
59
  blankSelection,
57
60
  children,
@@ -65,17 +68,20 @@ const Select = ({
65
68
  inline = false,
66
69
  multiple = false,
67
70
  name,
68
- onChange = () => undefined,
71
+ onChange,
69
72
  options = [],
73
+ register,
70
74
  required = false,
75
+ rules,
71
76
  showArrow = false,
72
77
  value,
73
78
  ...props
74
- }: SelectProps, ref: React.LegacyRef<HTMLSelectElement>) => {
79
+ }: SelectProps<T>, ref: React.LegacyRef<HTMLSelectElement>) => {
75
80
  const ariaProps = buildAriaProps(aria)
76
81
  const dataProps = buildDataProps(data)
77
82
  const htmlProps = buildHtmlProps(htmlOptions)
78
83
  const optionsList = createOptions(options)
84
+ const hookFormProps = name ? withHookForm({ register, name, rules }) : {}
79
85
 
80
86
  const inlineClass = inline ? 'inline' : null
81
87
  const compactClass = compact ? 'compact' : null
@@ -91,21 +97,22 @@ const Select = ({
91
97
  compactClass
92
98
  );
93
99
 
94
- const angleDown = getAllIcons()["angleDown"].icon as unknown as { [key: string]: SVGElement }
100
+ const icons = getAllIcons()
101
+ const angleDown = icons?.angleDown?.icon as { [key: string]: SVGElement }
95
102
 
96
103
  const selectWrapperClass = classnames(buildCss('pb_select_kit_wrapper'), { error }, className)
97
104
  const selectBody =(() =>{
98
105
  if (children) return children
99
106
  return (
100
107
  <select
101
- {...htmlOptions}
102
108
  {...domSafeProps(props)}
109
+ {...hookFormProps}
103
110
  disabled={disabled}
104
111
  id={name}
105
112
  multiple={multiple}
106
113
  name={name}
107
- onChange={onChange}
108
- ref={ref}
114
+ onChange={onChange || hookFormProps.onChange}
115
+ ref={ref || hookFormProps.ref}
109
116
  required={required}
110
117
  value={value}
111
118
  >
@@ -135,14 +142,12 @@ const Select = ({
135
142
  htmlFor={name}
136
143
  >
137
144
  {selectBody}
138
- { multiple !== true ?
145
+ { multiple !== true && angleDown &&
139
146
  <Icon
140
147
  className="pb_select_kit_caret svg-inline--fa"
141
148
  customIcon={angleDown}
142
149
  fixedWidth
143
150
  />
144
- :
145
- null
146
151
  }
147
152
  {error &&
148
153
  <Body
@@ -0,0 +1,108 @@
1
+ import React from 'react'
2
+ import { useForm } from 'react-hook-form'
3
+ import { Select, Card, Body, Button } from 'playbook-ui'
4
+
5
+ const SelectForm = (props) => {
6
+ const {
7
+ register,
8
+ handleSubmit,
9
+ formState: { errors },
10
+ watch,
11
+ } = useForm({
12
+ defaultValues: {
13
+ favoriteFood: '',
14
+ mealType: '',
15
+ dietaryRestrictions: '',
16
+ }
17
+ })
18
+
19
+ const onSubmit = (data) => {
20
+ console.log('Form submitted:', data)
21
+ }
22
+
23
+ // Watch form values for real-time display
24
+ const formValues = watch()
25
+
26
+ const foodOptions = [
27
+ { value: 'pizza', text: 'Pizza' },
28
+ { value: 'burger', text: 'Burger' },
29
+ { value: 'sushi', text: 'Sushi' },
30
+ { value: 'salad', text: 'Salad' },
31
+ ]
32
+
33
+ const mealTypes = [
34
+ { value: 'breakfast', text: 'Breakfast' },
35
+ { value: 'lunch', text: 'Lunch' },
36
+ { value: 'dinner', text: 'Dinner' },
37
+ ]
38
+
39
+ const dietaryOptions = [
40
+ { value: 'none', text: 'No Restrictions' },
41
+ { value: 'vegetarian', text: 'Vegetarian' },
42
+ { value: 'vegan', text: 'Vegan' },
43
+ { value: 'glutenFree', text: 'Gluten Free' },
44
+ ]
45
+
46
+ return (
47
+ <div>
48
+ <Card>
49
+ <form onSubmit={handleSubmit(onSubmit)}>
50
+ <Select
51
+ error={errors.favoriteFood?.message}
52
+ label="What's your favorite food?"
53
+ name="favoriteFood"
54
+ options={foodOptions}
55
+ register={register}
56
+ rules={{
57
+ required: 'Please select your favorite food',
58
+ }}
59
+ {...props}
60
+ />
61
+ <Select
62
+ blankSelection="Choose a meal type..."
63
+ error={errors.mealType?.message}
64
+ label="Preferred meal time"
65
+ marginTop="md"
66
+ name="mealType"
67
+ options={mealTypes}
68
+ register={register}
69
+ rules={{
70
+ required: 'Please select a meal type',
71
+ }}
72
+ {...props}
73
+ />
74
+ <Select
75
+ label="Dietary Restrictions"
76
+ marginTop="md"
77
+ name="dietaryRestrictions"
78
+ options={dietaryOptions}
79
+ register={register}
80
+ {...props}
81
+ />
82
+
83
+ <Button
84
+ marginTop="lg"
85
+ text="Submit"
86
+ type="submit"
87
+ variant="primary"
88
+
89
+ />
90
+ </form>
91
+ <Card marginTop="lg">
92
+ <Body
93
+ text="Current Form Values:"
94
+ variant="bold"
95
+ />
96
+ <pre style={{ marginTop: '8px', color: "white" }}>
97
+ {JSON.stringify(formValues, null, 2)}
98
+ </pre>
99
+ </Card>
100
+ </Card>
101
+ </div>
102
+ )
103
+ }
104
+
105
+ export default SelectForm
106
+
107
+
108
+
@@ -30,6 +30,7 @@ examples:
30
30
  - select_inline_show_arrow: Select Inline (Always Show Arrow)
31
31
  - select_inline_compact: Select Inline Compact
32
32
  - select_multiple: Select Multiple
33
+ - select_form: Form
33
34
 
34
35
  swift:
35
36
  - select_default_swift: Default
@@ -10,3 +10,4 @@ export { default as SelectInline } from './_select_inline.jsx'
10
10
  export { default as SelectInlineShowArrow } from './_select_inline_show_arrow.jsx'
11
11
  export { default as SelectInlineCompact } from './_select_inline_compact.jsx'
12
12
  export { default as SelectMultiple } from './_select_multiple.jsx'
13
+ export { default as SelectForm } from './_select_form.jsx'
@@ -151,7 +151,7 @@ $pb_selectable_paddings: (
151
151
  input[type="radio"] {
152
152
  &:checked ~ label {
153
153
  border-width: $pb_card_border_width;
154
- outline: 1px solid $primary_action_dark;
154
+ outline: 1px solid $primary;
155
155
  }
156
156
  }
157
157
  }
@@ -161,11 +161,11 @@ $pb_selectable_paddings: (
161
161
  color: $white;
162
162
  > label {
163
163
  @include pb_card_dark;
164
- background: $bg_dark_card;
164
+ background: transparent;
165
165
 
166
166
  .pb_selectable_card_circle {
167
167
  border-color: $bg_dark;
168
- background: $primary_action_dark;
168
+ background: $primary-action;
169
169
  }
170
170
  }
171
171
 
@@ -173,7 +173,7 @@ $pb_selectable_paddings: (
173
173
  input[type="radio"] {
174
174
  &:checked ~ label {
175
175
  @include pb_card_selected_dark;
176
- background: $bg_dark_card;
176
+ background: transparent;
177
177
  }
178
178
  }
179
179
 
@@ -35,7 +35,7 @@
35
35
  <% end %>
36
36
  <% else %>
37
37
  <% if content.nil? %>
38
- <%= pb_rails("body", props: { text: object.text, dark: object.dark }) %>
38
+ <%= pb_rails("body", props: { text: object.text }) %>
39
39
  <% else %>
40
40
  <%= content %>
41
41
  <% end %>
@@ -1,46 +1,40 @@
1
- import React from "react"
2
- import classnames from "classnames"
1
+ import React from 'react'
2
+ import classnames from 'classnames'
3
3
 
4
- import { buildCss, buildHtmlProps } from "../utilities/props"
5
- import { globalProps } from "../utilities/globalProps"
4
+ import { buildCss, buildHtmlProps } from '../utilities/props'
5
+ import { globalProps } from '../utilities/globalProps'
6
6
 
7
- import Body from "../pb_body/_body"
8
- import Icon from "../pb_icon/_icon"
7
+ import Body from '../pb_body/_body'
8
+ import Icon from '../pb_icon/_icon'
9
9
 
10
- const statusMap: {
11
- neutral: "neutral"
12
- decrease: "negative"
13
- increase: "positive"
14
- } = {
15
- increase: "positive",
16
- decrease: "negative",
17
- neutral: "neutral",
10
+ const statusMap: {neutral: 'neutral', decrease: 'negative' ,increase: 'positive'} = {
11
+ increase: 'positive',
12
+ decrease: 'negative',
13
+ neutral: 'neutral',
18
14
  }
19
15
 
20
16
  const iconMap = {
21
- increase: "arrow-up",
22
- decrease: "arrow-down",
17
+ increase: 'arrow-up',
18
+ decrease: 'arrow-down',
23
19
  }
24
20
 
25
21
  type StatChangeProps = {
26
- change?: "increase" | "decrease" | "neutral"
27
- className?: string
28
- dark?: boolean
29
- icon?: string
30
- id?: string
31
- htmlOptions?: { [key: string]: string | number | boolean | (() => void) }
32
- value?: string | number
22
+ change?: 'increase' | 'decrease' | 'neutral',
23
+ className?: string,
24
+ icon?: string,
25
+ htmlOptions?: {[key: string]: string | number | boolean | (() => void)},
26
+ id?: string,
27
+ value?: string | number,
33
28
  }
34
29
 
35
30
  const StatChange = (props: StatChangeProps): React.ReactElement => {
36
- const {
37
- change = "neutral",
38
- className,
39
- dark = false,
31
+ const {
32
+ change = 'neutral',
33
+ className,
40
34
  htmlOptions = {},
41
- icon,
42
- id,
43
- value,
35
+ icon,
36
+ id,
37
+ value
44
38
  } = props
45
39
 
46
40
  const status = statusMap[change as keyof typeof statusMap]
@@ -53,32 +47,30 @@ const StatChange = (props: StatChangeProps): React.ReactElement => {
53
47
 
54
48
  return (
55
49
  <>
56
- {value && (
50
+ {value &&
57
51
  <div
58
52
  className={classnames(
59
- buildCss("pb_stat_change_kit", status),
60
- globalProps(props),
61
- className
62
- )}
53
+ buildCss('pb_stat_change_kit', status),
54
+ globalProps(props),
55
+ className
56
+ )}
63
57
  id={id}
64
58
  {...htmlProps}
65
59
  >
66
- <Body dark={dark}
67
- status={status}
68
- >
69
- {" "}
70
- {returnedIcon && (
60
+ <Body status={status}>
61
+ {returnedIcon &&
71
62
  <>
72
- <Icon dark={dark}
63
+ <Icon
73
64
  fixed_width
74
65
  icon={returnedIcon}
75
- />{" "}
66
+ />
67
+ {' '}
76
68
  </>
77
- )}
69
+ }
78
70
  {`${value}%`}
79
71
  </Body>
80
72
  </div>
81
- )}
73
+ }
82
74
  </>
83
75
  )
84
76
  }
@@ -1,6 +1,6 @@
1
1
  <%= pb_content_tag do %>
2
- <%= pb_rails("body", props: { status: object.status, dark: object.dark }) do %>
3
- <%= pb_rails("icon", props: { fixed_width: true, icon: object.returned_icon, dark: object.dark }) if object.returned_icon %>
4
- <%= "#{object.value}%" if object.value %>
5
- <% end %>
2
+ <%= pb_rails("body", props: { status: object.status }) do %>
3
+ <%= pb_rails("icon", props: { fixed_width: true, icon: object.returned_icon }) if object.returned_icon %>
4
+ <%= "#{object.value}%" if object.value %>
5
+ <% end %>
6
6
  <% end %>
@@ -55,8 +55,3 @@ examples:
55
55
  - table_with_subcomponents: Table with Sub Components (Table Elements)
56
56
  - table_with_subcomponents_as_divs: Table with Sub Components (Divs)
57
57
  - table_outer_padding: Outer Padding
58
- - table_with_collapsible: Table with Collapsible
59
- - table_with_collapsible_with_custom_click: Table with Collapsible with Custom Click
60
- - table_with_collapsible_with_custom_content: Table with Collapsible with Custom Content
61
- - table_with_collapsible_with_nested_rows: Table with Collapsible with Nested Rows
62
- - table_with_collapsible_with_nested_table: Table with Collapsible with Nested Table
@@ -26,8 +26,3 @@ export { default as TableWithSubcomponents } from './_table_with_subcomponents.j
26
26
  export { default as TableWithSubcomponentsAsDivs } from './_table_with_subcomponents_as_divs.jsx'
27
27
  export { default as TableOuterPadding } from './_table_outer_padding.jsx'
28
28
  export { default as TableStickyLeftColumns } from './_table_sticky_left_columns.jsx'
29
- export { default as TableWithCollapsible } from './_table_with_collapsible.jsx'
30
- export { default as TableWithCollapsibleWithCustomContent } from './_table_with_collapsible_with_custom_content.jsx'
31
- export { default as TableWithCollapsibleWithNestedTable } from './_table_with_collapsible_with_nested_table.jsx'
32
- export { default as TableWithCollapsibleWithNestedRows } from './_table_with_collapsible_with_nested_rows.jsx'
33
- export { default as TableWithCollapsibleWithCustomClick } from './_table_with_collapsible_with_custom_click.jsx'
@@ -1,106 +1,32 @@
1
1
  import PbEnhancedElement from '../pb_enhanced_element'
2
2
 
3
3
  export default class PbTable extends PbEnhancedElement {
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
- }
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/, ''));
58
19
  }
59
20
  });
60
- }
61
-
62
- private handleStickyColumns(): void {
63
- let accumulatedWidth = 0;
64
21
 
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
- }
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
+ }
@@ -21,5 +21,4 @@
21
21
  @import "striped";
22
22
  @import "outer_padding";
23
23
  @import "sticky_columns";
24
- @import "scroll";
25
- @import "collapsible";
24
+ @import "scroll";