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.
- checksums.yaml +4 -4
- data/app/pb_kits/playbook/pb_advanced_table/table_header.html.erb +3 -5
- data/app/pb_kits/playbook/pb_avatar/_avatar.scss +2 -0
- data/app/pb_kits/playbook/pb_bar_graph/docs/_bar_graph_custom.jsx +49 -53
- data/app/pb_kits/playbook/pb_bar_graph/docs/_bar_graph_custom_rails.html.erb +36 -29
- data/app/pb_kits/playbook/pb_body/_body.scss +13 -14
- data/app/pb_kits/playbook/pb_body/_body_mixins.scss +16 -22
- data/app/pb_kits/playbook/pb_bread_crumbs/docs/_bread_crumbs_default.jsx +0 -6
- data/app/pb_kits/playbook/pb_caption/_caption_mixin.scss +1 -2
- data/app/pb_kits/playbook/pb_card/_card_mixin.scss +1 -1
- data/app/pb_kits/playbook/pb_collapsible/_collapsible.tsx +4 -9
- data/app/pb_kits/playbook/pb_collapsible/child_kits/CollapsibleContent.tsx +2 -2
- data/app/pb_kits/playbook/pb_collapsible/child_kits/CollapsibleMain.tsx +2 -2
- data/app/pb_kits/playbook/pb_file_upload/_file_upload.scss +0 -5
- data/app/pb_kits/playbook/pb_file_upload/_file_upload.tsx +2 -7
- data/app/pb_kits/playbook/pb_file_upload/file_upload.html.erb +2 -8
- data/app/pb_kits/playbook/pb_link/_link.scss +3 -3
- data/app/pb_kits/playbook/pb_nav/_bold_mixin.scss +1 -11
- data/app/pb_kits/playbook/pb_nav/_collapsible_nav.scss +2 -16
- data/app/pb_kits/playbook/pb_nav/_vertical_nav.scss +1 -1
- data/app/pb_kits/playbook/pb_select/_select.tsx +19 -14
- data/app/pb_kits/playbook/pb_select/docs/_select_form.jsx +108 -0
- data/app/pb_kits/playbook/pb_select/docs/example.yml +1 -0
- data/app/pb_kits/playbook/pb_select/docs/index.js +1 -0
- data/app/pb_kits/playbook/pb_selectable_card/_selectable_card.scss +4 -4
- data/app/pb_kits/playbook/pb_selectable_card/selectable_card.html.erb +1 -1
- data/app/pb_kits/playbook/pb_stat_change/_stat_change.tsx +36 -44
- data/app/pb_kits/playbook/pb_stat_change/stat_change.html.erb +4 -4
- data/app/pb_kits/playbook/pb_table/docs/example.yml +0 -5
- data/app/pb_kits/playbook/pb_table/docs/index.js +0 -5
- data/app/pb_kits/playbook/pb_table/index.ts +26 -100
- data/app/pb_kits/playbook/pb_table/styles/_all.scss +1 -2
- data/app/pb_kits/playbook/pb_table/subcomponents/_table_row.tsx +1 -106
- data/app/pb_kits/playbook/pb_table/table.html.erb +1 -1
- data/app/pb_kits/playbook/pb_table/table.rb +2 -17
- data/app/pb_kits/playbook/pb_text_input/_text_input.tsx +3 -35
- data/app/pb_kits/playbook/pb_text_input/docs/example.yml +0 -1
- data/app/pb_kits/playbook/pb_text_input/docs/index.js +0 -1
- data/app/pb_kits/playbook/pb_text_input/text_input.test.js +2 -139
- data/app/pb_kits/playbook/pb_title/_title.scss +5 -6
- data/app/pb_kits/playbook/pb_title/_title_mixin.scss +0 -13
- data/app/pb_kits/playbook/tokens/_titles.scss +8 -0
- data/app/pb_kits/playbook/utilities/_hover.scss +2 -11
- data/app/pb_kits/playbook/utilities/globalProps.ts +0 -2
- data/app/pb_kits/playbook/utilities/hookFormProps.ts +16 -0
- data/app/pb_kits/playbook/utilities/test/globalProps/hover.test.js +0 -15
- data/dist/chunks/_typeahead-B8fkIeXA.js +22 -0
- data/dist/chunks/_weekday_stacked-DxlPBh55.js +45 -0
- data/dist/chunks/{lib-CuCy3_xO.js → lib-SyD3buPZ.js} +3 -3
- data/dist/chunks/{pb_form_validation-D37k10a0.js → pb_form_validation-Dt8UJgrJ.js} +1 -1
- data/dist/chunks/vendor.js +1 -1
- data/dist/menu.yml +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/hover.rb +1 -7
- data/lib/playbook/version.rb +1 -1
- metadata +8 -20
- data/app/pb_kits/playbook/pb_table/docs/_table_sticky_left_columns.html.erb +0 -95
- data/app/pb_kits/playbook/pb_table/docs/_table_with_collapsible.jsx +0 -75
- data/app/pb_kits/playbook/pb_table/docs/_table_with_collapsible.md +0 -1
- data/app/pb_kits/playbook/pb_table/docs/_table_with_collapsible_with_custom_click.jsx +0 -108
- data/app/pb_kits/playbook/pb_table/docs/_table_with_collapsible_with_custom_click.md +0 -2
- data/app/pb_kits/playbook/pb_table/docs/_table_with_collapsible_with_custom_content.jsx +0 -94
- data/app/pb_kits/playbook/pb_table/docs/_table_with_collapsible_with_custom_content.md +0 -0
- data/app/pb_kits/playbook/pb_table/docs/_table_with_collapsible_with_nested_rows.jsx +0 -83
- data/app/pb_kits/playbook/pb_table/docs/_table_with_collapsible_with_nested_rows.md +0 -3
- data/app/pb_kits/playbook/pb_table/docs/_table_with_collapsible_with_nested_table.jsx +0 -120
- data/app/pb_kits/playbook/pb_table/docs/_table_with_collapsible_with_nested_table.md +0 -1
- data/app/pb_kits/playbook/pb_table/styles/_collapsible.scss +0 -35
- data/app/pb_kits/playbook/pb_text_input/docs/_text_input_mask.jsx +0 -88
- data/app/pb_kits/playbook/pb_text_input/inputMask.ts +0 -64
- data/dist/chunks/_typeahead-l1kq1p9m.js +0 -22
- 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: $
|
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
|
}
|
@@ -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
|
35
|
+
margin?: string,
|
34
36
|
marginBottom: string,
|
37
|
+
marginTop: string,
|
35
38
|
multiple?: boolean,
|
36
39
|
name?: string,
|
37
|
-
onChange
|
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
|
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
|
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
|
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
|
+
|
@@ -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 $
|
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:
|
164
|
+
background: transparent;
|
165
165
|
|
166
166
|
.pb_selectable_card_circle {
|
167
167
|
border-color: $bg_dark;
|
168
|
-
background: $
|
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:
|
176
|
+
background: transparent;
|
177
177
|
}
|
178
178
|
}
|
179
179
|
|
@@ -1,46 +1,40 @@
|
|
1
|
-
import React from
|
2
|
-
import classnames from
|
1
|
+
import React from 'react'
|
2
|
+
import classnames from 'classnames'
|
3
3
|
|
4
|
-
import { buildCss, buildHtmlProps } from
|
5
|
-
import { globalProps } from
|
4
|
+
import { buildCss, buildHtmlProps } from '../utilities/props'
|
5
|
+
import { globalProps } from '../utilities/globalProps'
|
6
6
|
|
7
|
-
import Body from
|
8
|
-
import Icon from
|
7
|
+
import Body from '../pb_body/_body'
|
8
|
+
import Icon from '../pb_icon/_icon'
|
9
9
|
|
10
|
-
const statusMap: {
|
11
|
-
|
12
|
-
decrease:
|
13
|
-
|
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:
|
22
|
-
decrease:
|
17
|
+
increase: 'arrow-up',
|
18
|
+
decrease: 'arrow-down',
|
23
19
|
}
|
24
20
|
|
25
21
|
type StatChangeProps = {
|
26
|
-
change?:
|
27
|
-
className?: string
|
28
|
-
|
29
|
-
|
30
|
-
id?: string
|
31
|
-
|
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 =
|
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
|
-
|
60
|
-
|
61
|
-
|
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
|
67
|
-
|
68
|
-
>
|
69
|
-
{" "}
|
70
|
-
{returnedIcon && (
|
60
|
+
<Body status={status}>
|
61
|
+
{returnedIcon &&
|
71
62
|
<>
|
72
|
-
<Icon
|
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
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
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
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
//
|
14
|
-
|
15
|
-
|
16
|
-
const
|
17
|
-
|
18
|
-
|
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
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
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
|
+
}
|