playbook_ui 15.2.0.pre.alpha.PLAY2589advancedtableinlinerowloadingtoggleicon11607 → 15.2.0.pre.alpha.PLAY2589advancedtableinlinerowloadingtoggleicon11644
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/Components/TableHeaderCell.tsx +3 -1
- data/app/pb_kits/playbook/pb_advanced_table/SubKits/TableHeader.tsx +3 -0
- data/app/pb_kits/playbook/pb_advanced_table/_advanced_table.tsx +3 -0
- data/app/pb_kits/playbook/pb_advanced_table/advanced_table.test.jsx +59 -0
- data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_inline_row_loading.jsx +16 -0
- data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_inline_row_loading.md +11 -2
- data/app/pb_kits/playbook/pb_advanced_table/docs/_mock_data_inline_loading_empty_children.js +42 -0
- data/app/pb_kits/playbook/pb_phone_number_input/_phone_number_input.tsx +25 -6
- data/app/pb_kits/playbook/pb_typeahead/_typeahead.test.jsx +35 -1
- data/app/pb_kits/playbook/pb_typeahead/_typeahead.tsx +71 -2
- data/app/pb_kits/playbook/pb_typeahead/docs/_typeahead_default_options.html.erb +36 -0
- data/app/pb_kits/playbook/pb_typeahead/docs/_typeahead_default_options.md +1 -0
- data/app/pb_kits/playbook/pb_typeahead/docs/_typeahead_default_value.jsx +41 -0
- data/app/pb_kits/playbook/pb_typeahead/docs/_typeahead_default_value.md +1 -0
- data/app/pb_kits/playbook/pb_typeahead/docs/example.yml +2 -0
- data/app/pb_kits/playbook/pb_typeahead/docs/index.js +1 -0
- data/dist/chunks/{_line_graph-BnVgr42C.js → _line_graph-D5MBnrO9.js} +1 -1
- data/dist/chunks/{_typeahead-BH_dkgOy.js → _typeahead-BjYBazGq.js} +1 -1
- data/dist/chunks/{_weekday_stacked-Duv09EWo.js → _weekday_stacked-BQrF2byq.js} +2 -2
- data/dist/chunks/vendor.js +1 -1
- data/dist/playbook-doc.js +2 -2
- data/dist/playbook-rails-react-bindings.js +1 -1
- data/dist/playbook-rails.js +1 -1
- data/lib/playbook/version.rb +1 -1
- metadata +10 -5
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 89693ba1bf07627064652227df87422a5b6126af238967ceb09282f01f6d7e49
|
|
4
|
+
data.tar.gz: 667090ab12ab761b0bf84a8365bfb6d5dd31b5cdff7274583bfd620a864e4dee
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 7dd13b4e5110a7f0129d60c3fc5661b8523bbcb28f8ca42d18864acdba620fd361a03754ae7a1eebac3e26d4043e897c5313168e282fea640da11f7bf37900cf
|
|
7
|
+
data.tar.gz: 7520b324d9a37fc5463adefa742e571d41c64089f3e989829a3de42bb27f930befbee03f1fbc3dda32eb63652acf21cf8213911a400ef1aa553b02b7bff7996b
|
|
@@ -30,6 +30,7 @@ type TableHeaderCellProps = {
|
|
|
30
30
|
headerChildren?: React.ReactNode | React.ReactNode[]
|
|
31
31
|
isPinnedLeft?: boolean
|
|
32
32
|
loading?: boolean
|
|
33
|
+
persistToggleExpansionButton?: boolean
|
|
33
34
|
sortIcon?: string | string[]
|
|
34
35
|
table?: Table<GenericObject>
|
|
35
36
|
} & GlobalProps
|
|
@@ -58,6 +59,7 @@ export const TableHeaderCell = ({
|
|
|
58
59
|
selectableRows,
|
|
59
60
|
hasAnySubRows,
|
|
60
61
|
showActionsBar,
|
|
62
|
+
persistToggleExpansionButton,
|
|
61
63
|
stickyLeftColumn,
|
|
62
64
|
inlineRowLoading,
|
|
63
65
|
isActionBarVisible,
|
|
@@ -220,7 +222,7 @@ const isToggleExpansionEnabled =
|
|
|
220
222
|
/>
|
|
221
223
|
)
|
|
222
224
|
}
|
|
223
|
-
{isToggleExpansionEnabled &&
|
|
225
|
+
{isToggleExpansionEnabled && ((hasAnySubRows) || (inlineRowLoading && persistToggleExpansionButton)) && !expandByDepth && (
|
|
224
226
|
<ToggleIconButton onClick={handleExpandOrCollapse} />
|
|
225
227
|
)}
|
|
226
228
|
{isToggleExpansionEnabled && hasAnySubRows && expandByDepth && (
|
|
@@ -39,6 +39,7 @@ export const TableHeader = ({
|
|
|
39
39
|
hasAnySubRows,
|
|
40
40
|
showActionsBar,
|
|
41
41
|
selectableRows,
|
|
42
|
+
persistToggleExpansionButton,
|
|
42
43
|
responsive,
|
|
43
44
|
headerRef,
|
|
44
45
|
virtualizedRows,
|
|
@@ -92,6 +93,7 @@ export const TableHeader = ({
|
|
|
92
93
|
isPinnedLeft={isPinnedLeft}
|
|
93
94
|
key={`${header.id}-header`}
|
|
94
95
|
loading={loading}
|
|
96
|
+
persistToggleExpansionButton={persistToggleExpansionButton}
|
|
95
97
|
sortIcon={sortIcon}
|
|
96
98
|
table={table}
|
|
97
99
|
/>
|
|
@@ -136,6 +138,7 @@ export const TableHeader = ({
|
|
|
136
138
|
isVirtualized
|
|
137
139
|
key={`${header.id}-header-virtualized`}
|
|
138
140
|
loading={loading}
|
|
141
|
+
persistToggleExpansionButton={persistToggleExpansionButton}
|
|
139
142
|
sortIcon={sortIcon}
|
|
140
143
|
table={table}
|
|
141
144
|
/>
|
|
@@ -63,6 +63,7 @@ type AdvancedTableProps = {
|
|
|
63
63
|
scrollBarNone?: boolean,
|
|
64
64
|
selectableRows?: boolean,
|
|
65
65
|
showActionsBar?: boolean,
|
|
66
|
+
persistToggleExpansionButton?: boolean,
|
|
66
67
|
sortControl?: GenericObject
|
|
67
68
|
tableData: GenericObject[]
|
|
68
69
|
tableOptions?: GenericObject
|
|
@@ -109,6 +110,7 @@ const AdvancedTable = (props: AdvancedTableProps) => {
|
|
|
109
110
|
scrollBarNone= false,
|
|
110
111
|
showActionsBar = true,
|
|
111
112
|
selectableRows,
|
|
113
|
+
persistToggleExpansionButton = false,
|
|
112
114
|
sortControl,
|
|
113
115
|
stickyLeftColumn,
|
|
114
116
|
tableData,
|
|
@@ -349,6 +351,7 @@ const AdvancedTable = (props: AdvancedTableProps) => {
|
|
|
349
351
|
loading={loading}
|
|
350
352
|
onCustomSortClick={onCustomSortClick}
|
|
351
353
|
onExpandByDepthClick={onExpandByDepthClick}
|
|
354
|
+
persistToggleExpansionButton={persistToggleExpansionButton}
|
|
352
355
|
pinnedRows={pinnedRows}
|
|
353
356
|
responsive={responsive}
|
|
354
357
|
rowStyling={rowStyling}
|
|
@@ -108,6 +108,48 @@ const MOCK_DATA_WITH_ID = [
|
|
|
108
108
|
},
|
|
109
109
|
]
|
|
110
110
|
|
|
111
|
+
const MOCK_DATA_NO_SUBROWS = [
|
|
112
|
+
{
|
|
113
|
+
year: "2021",
|
|
114
|
+
quarter: null,
|
|
115
|
+
month: null,
|
|
116
|
+
day: null,
|
|
117
|
+
newEnrollments: "20",
|
|
118
|
+
scheduledMeetings: "10",
|
|
119
|
+
attendanceRate: "51%",
|
|
120
|
+
completedClasses: "3",
|
|
121
|
+
classCompletionRate: "33%",
|
|
122
|
+
graduatedStudents: "19",
|
|
123
|
+
children: [],
|
|
124
|
+
},
|
|
125
|
+
{
|
|
126
|
+
year: "2022",
|
|
127
|
+
quarter: null,
|
|
128
|
+
month: null,
|
|
129
|
+
day: null,
|
|
130
|
+
newEnrollments: "25",
|
|
131
|
+
scheduledMeetings: "17",
|
|
132
|
+
attendanceRate: "75%",
|
|
133
|
+
completedClasses: "5",
|
|
134
|
+
classCompletionRate: "45%",
|
|
135
|
+
graduatedStudents: "32",
|
|
136
|
+
children: [],
|
|
137
|
+
},
|
|
138
|
+
{
|
|
139
|
+
year: "2023",
|
|
140
|
+
quarter: null,
|
|
141
|
+
month: null,
|
|
142
|
+
day: null,
|
|
143
|
+
newEnrollments: "30",
|
|
144
|
+
scheduledMeetings: "22",
|
|
145
|
+
attendanceRate: "80%",
|
|
146
|
+
completedClasses: "7",
|
|
147
|
+
classCompletionRate: "55%",
|
|
148
|
+
graduatedStudents: "45",
|
|
149
|
+
children: [],
|
|
150
|
+
},
|
|
151
|
+
]
|
|
152
|
+
|
|
111
153
|
const columnDefinitions = [
|
|
112
154
|
{
|
|
113
155
|
accessor: "year",
|
|
@@ -509,6 +551,23 @@ test("inlineRowLoading prop renders inline loading if true", () => {
|
|
|
509
551
|
expect(inlineLoading).toBeInTheDocument()
|
|
510
552
|
})
|
|
511
553
|
|
|
554
|
+
test("persistToggleExpansionButton prop shows header toggle when inlineRowLoading is true", () => {
|
|
555
|
+
render(
|
|
556
|
+
<AdvancedTable
|
|
557
|
+
columnDefinitions={columnDefinitions}
|
|
558
|
+
data={{ testid: testId }}
|
|
559
|
+
enableToggleExpansion="all"
|
|
560
|
+
inlineRowLoading
|
|
561
|
+
persistToggleExpansionButton
|
|
562
|
+
tableData={MOCK_DATA_NO_SUBROWS}
|
|
563
|
+
/>
|
|
564
|
+
)
|
|
565
|
+
|
|
566
|
+
const kit = screen.getByTestId(testId)
|
|
567
|
+
const headerToggleButton = kit.querySelector(".gray-icon.toggle-all-icon")
|
|
568
|
+
expect(headerToggleButton).toBeInTheDocument()
|
|
569
|
+
})
|
|
570
|
+
|
|
512
571
|
test("responsive prop functions as expected", () => {
|
|
513
572
|
render(
|
|
514
573
|
<AdvancedTable
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import React from "react"
|
|
2
2
|
import AdvancedTable from '../../pb_advanced_table/_advanced_table'
|
|
3
|
+
import Caption from '../../pb_caption/_caption'
|
|
3
4
|
import { MOCK_DATA_INLINE_LOADING } from "./_mock_data_inline_loading"
|
|
5
|
+
import { MOCK_DATA_INLINE_LOADING_EMPTY_CHILDREN } from "./_mock_data_inline_loading_empty_children"
|
|
4
6
|
|
|
5
7
|
const AdvancedTableInlineRowLoading = (props) => {
|
|
6
8
|
const columnDefinitions = [
|
|
@@ -41,16 +43,30 @@ const AdvancedTableInlineRowLoading = (props) => {
|
|
|
41
43
|
|
|
42
44
|
return (
|
|
43
45
|
<div>
|
|
46
|
+
<Caption>Inline Row Loading</Caption>
|
|
44
47
|
<AdvancedTable
|
|
45
48
|
columnDefinitions={columnDefinitions}
|
|
46
49
|
enableToggleExpansion="all"
|
|
47
50
|
inlineRowLoading
|
|
51
|
+
marginBottom="md"
|
|
48
52
|
tableData={MOCK_DATA_INLINE_LOADING}
|
|
49
53
|
{...props}
|
|
50
54
|
>
|
|
51
55
|
<AdvancedTable.Header />
|
|
52
56
|
<AdvancedTable.Body subRowHeaders={subRowHeaders}/>
|
|
53
57
|
</AdvancedTable>
|
|
58
|
+
<Caption>Inline Row Loading with Persist Toggle Expansion Button</Caption>
|
|
59
|
+
<AdvancedTable
|
|
60
|
+
columnDefinitions={columnDefinitions}
|
|
61
|
+
enableToggleExpansion="all"
|
|
62
|
+
inlineRowLoading
|
|
63
|
+
persistToggleExpansionButton
|
|
64
|
+
tableData={MOCK_DATA_INLINE_LOADING_EMPTY_CHILDREN}
|
|
65
|
+
{...props}
|
|
66
|
+
>
|
|
67
|
+
<AdvancedTable.Header />
|
|
68
|
+
<AdvancedTable.Body subRowHeaders={subRowHeaders}/>
|
|
69
|
+
</AdvancedTable>
|
|
54
70
|
</div>
|
|
55
71
|
)
|
|
56
72
|
}
|
|
@@ -1,5 +1,14 @@
|
|
|
1
|
+
### inlineRowLoading
|
|
1
2
|
As a default, the kit assumes that the initial dataset is complete, and it renders all expansion buttons/controls based on that data; if no children are present, no expansion controls are rendered. If, however, you want to change the initial dataset to omit some or all of its children (to improve load times of a complex dataset, perhaps), and you implement a querying logic that loads children only when its parent is expanded, then you must use the `inlineRowLoading` prop to ensure your expansion controls are rendered even though your child data is not yet loaded. You must also pass an empty `children` array to any node that will have children to ensure its parent maintains its ability to expand. If this prop is called AND your data contains empty `children` arrays, the kit will render expansion controls on any row with empty children, and then add an inline loading state within the expanded subrow until those child row(s) are returned to the page [by your query logic].
|
|
2
3
|
|
|
3
|
-
In this code example, 2021 has an empty children array. Toggle it open to see the inline loading state. Once the correct data loads, this state will be replaced with the correct data rows.
|
|
4
|
+
In the first Advanced Table in this code example, 2021 has an empty children array. Toggle it open to see the inline loading state. Once the correct data loads, this state will be replaced with the correct data rows.
|
|
4
5
|
|
|
5
|
-
This prop is set to `false` by default.
|
|
6
|
+
This prop is set to `false` by default.
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### persistToggleExpansion
|
|
10
|
+
The `persistToggleExpansionButton` is a boolean prop that renders the toggle-all icon in the top left header cell for complex datasets with empty `children` arrays and advanced querying logic explained in the preceeding doc example. Your logic may require an additional query helper file to update data specifically from requerying via toggle all buttons.
|
|
11
|
+
|
|
12
|
+
In the second Advanced Table in this code example, all 3 rows have empty children arrays. The toggle all button would not render (prior to an initial row expansion) without `persistToggleExpansionButton` in place.
|
|
13
|
+
|
|
14
|
+
This prop is set to false by default and should only be used in conjunction with `inlineRowLoading`.
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
export const MOCK_DATA_INLINE_LOADING_EMPTY_CHILDREN = [
|
|
2
|
+
{
|
|
3
|
+
year: "2021",
|
|
4
|
+
quarter: null,
|
|
5
|
+
month: null,
|
|
6
|
+
day: null,
|
|
7
|
+
newEnrollments: "20",
|
|
8
|
+
scheduledMeetings: "10",
|
|
9
|
+
attendanceRate: "51%",
|
|
10
|
+
completedClasses: "3",
|
|
11
|
+
classCompletionRate: "33%",
|
|
12
|
+
graduatedStudents: "19",
|
|
13
|
+
children: [],
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
year: "2022",
|
|
17
|
+
quarter: null,
|
|
18
|
+
month: null,
|
|
19
|
+
day: null,
|
|
20
|
+
newEnrollments: "25",
|
|
21
|
+
scheduledMeetings: "17",
|
|
22
|
+
attendanceRate: "75%",
|
|
23
|
+
completedClasses: "5",
|
|
24
|
+
classCompletionRate: "45%",
|
|
25
|
+
graduatedStudents: "32",
|
|
26
|
+
children: [],
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
year: "2023",
|
|
30
|
+
quarter: null,
|
|
31
|
+
month: null,
|
|
32
|
+
day: null,
|
|
33
|
+
newEnrollments: "10",
|
|
34
|
+
scheduledMeetings: "15",
|
|
35
|
+
attendanceRate: "65%",
|
|
36
|
+
completedClasses: "4",
|
|
37
|
+
classCompletionRate: "49%",
|
|
38
|
+
graduatedStudents: "29",
|
|
39
|
+
children: [],
|
|
40
|
+
},
|
|
41
|
+
]
|
|
42
|
+
|
|
@@ -314,14 +314,18 @@ const PhoneNumberInput = (props: PhoneNumberInputProps, ref?: React.Ref<unknown>
|
|
|
314
314
|
|
|
315
315
|
const handleOnChange = (evt: React.ChangeEvent<HTMLInputElement>) => {
|
|
316
316
|
if (!hasTyped) setHasTyped(true)
|
|
317
|
+
|
|
317
318
|
setInputValue(evt.target.value)
|
|
319
|
+
|
|
318
320
|
let phoneNumberData
|
|
321
|
+
|
|
319
322
|
if (formatAsYouType) {
|
|
320
323
|
const formattedPhoneNumberData = getCurrentSelectedData(itiRef.current, evt.target.value)
|
|
321
324
|
phoneNumberData = {...formattedPhoneNumberData, number: unformatNumber(formattedPhoneNumberData.number)}
|
|
322
325
|
} else {
|
|
323
326
|
phoneNumberData = getCurrentSelectedData(itiRef.current, evt.target.value)
|
|
324
327
|
}
|
|
328
|
+
|
|
325
329
|
setSelectedData(phoneNumberData)
|
|
326
330
|
onChange(phoneNumberData)
|
|
327
331
|
isValid(itiRef.current.isValidNumber())
|
|
@@ -370,11 +374,26 @@ const PhoneNumberInput = (props: PhoneNumberInputProps, ref?: React.Ref<unknown>
|
|
|
370
374
|
|
|
371
375
|
inputRef.current.addEventListener("open:countrydropdown", () => setDropDownIsOpen(true))
|
|
372
376
|
inputRef.current.addEventListener("close:countrydropdown", () => setDropDownIsOpen(false))
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
377
|
+
|
|
378
|
+
// Handle formatAsYouType with input event
|
|
379
|
+
if (formatAsYouType) {
|
|
380
|
+
inputRef.current.addEventListener("input", (evt: Event) => {
|
|
381
|
+
const target = evt.target as HTMLInputElement
|
|
382
|
+
const formattedValue = target.value
|
|
383
|
+
|
|
384
|
+
// Update internal state
|
|
385
|
+
setInputValue(formattedValue)
|
|
386
|
+
setHasTyped(true)
|
|
387
|
+
|
|
388
|
+
// Get phone number data with unformatted number
|
|
389
|
+
const formattedPhoneNumberData = getCurrentSelectedData(telInputInit, formattedValue)
|
|
390
|
+
const phoneNumberData = {...formattedPhoneNumberData, number: unformatNumber(formattedPhoneNumberData.number)}
|
|
391
|
+
|
|
392
|
+
setSelectedData(phoneNumberData)
|
|
393
|
+
onChange(phoneNumberData)
|
|
394
|
+
isValid(telInputInit.isValidNumber())
|
|
395
|
+
})
|
|
396
|
+
}
|
|
378
397
|
}
|
|
379
398
|
}, [])
|
|
380
399
|
|
|
@@ -389,7 +408,7 @@ const PhoneNumberInput = (props: PhoneNumberInputProps, ref?: React.Ref<unknown>
|
|
|
389
408
|
label,
|
|
390
409
|
name,
|
|
391
410
|
onBlur: validateErrors,
|
|
392
|
-
onChange: handleOnChange,
|
|
411
|
+
onChange: formatAsYouType ? undefined : handleOnChange,
|
|
393
412
|
value: inputValue
|
|
394
413
|
}
|
|
395
414
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from 'react'
|
|
2
|
-
import { render, screen } from '../utilities/test-utils'
|
|
2
|
+
import { render, screen, fireEvent, waitFor } from '../utilities/test-utils'
|
|
3
3
|
import Typeahead from './_typeahead'
|
|
4
4
|
|
|
5
5
|
const options = [
|
|
@@ -137,4 +137,38 @@ test('typeahead with colored pills', () => {
|
|
|
137
137
|
const kit = screen.getByTestId('pills-color-test')
|
|
138
138
|
const pill = kit.querySelector(".pb_form_pill_kit.pb_form_pill_neutral")
|
|
139
139
|
expect(pill).toBeInTheDocument()
|
|
140
|
+
})
|
|
141
|
+
|
|
142
|
+
test('typeahead with defaultValue with focus behavior', async () => {
|
|
143
|
+
render(
|
|
144
|
+
<Typeahead
|
|
145
|
+
data={{ testid: 'default-value-focus-test' }}
|
|
146
|
+
defaultValue={[options[1]]}
|
|
147
|
+
options={options}
|
|
148
|
+
/>
|
|
149
|
+
)
|
|
150
|
+
|
|
151
|
+
const kit = screen.getByTestId('default-value-focus-test')
|
|
152
|
+
const inputDiv = kit.querySelector(".typeahead-kit-select__single-value")
|
|
153
|
+
expect(inputDiv).toHaveTextContent("Red")
|
|
154
|
+
|
|
155
|
+
// Test that the control can receive focus
|
|
156
|
+
const control = kit.querySelector('.typeahead-kit-select__control')
|
|
157
|
+
expect(control).toBeInTheDocument()
|
|
158
|
+
|
|
159
|
+
// Simulate opening the menu by clicking the control
|
|
160
|
+
fireEvent.mouseDown(control)
|
|
161
|
+
|
|
162
|
+
// Wait for menu to appear
|
|
163
|
+
await waitFor(() => {
|
|
164
|
+
const menu = kit.querySelector('.typeahead-kit-select__menu')
|
|
165
|
+
expect(menu).toBeInTheDocument()
|
|
166
|
+
})
|
|
167
|
+
|
|
168
|
+
// Check that the correct option has the focused class
|
|
169
|
+
await waitFor(() => {
|
|
170
|
+
const focusedOption = kit.querySelector('.typeahead-kit-select__option--is-focused')
|
|
171
|
+
expect(focusedOption).toBeInTheDocument()
|
|
172
|
+
expect(focusedOption).toHaveTextContent('Red')
|
|
173
|
+
})
|
|
140
174
|
})
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { useState, useEffect, forwardRef} from 'react'
|
|
1
|
+
import React, { useState, useEffect, forwardRef, useRef} from 'react'
|
|
2
2
|
import Select from 'react-select'
|
|
3
3
|
import AsyncSelect from 'react-select/async'
|
|
4
4
|
import CreateableSelect from 'react-select/creatable'
|
|
@@ -106,6 +106,8 @@ const Typeahead = forwardRef<HTMLInputElement, TypeaheadProps>(({
|
|
|
106
106
|
const [inputValue, setInputValue] = useState("")
|
|
107
107
|
// State to track if form has been submitted to control validation display for react rendered rails kit
|
|
108
108
|
const [formSubmitted, setFormSubmitted] = useState(false)
|
|
109
|
+
// State to track if user has made a selection (to disable defaultValue focus behavior)
|
|
110
|
+
const [hasUserSelected, setHasUserSelected] = useState(false)
|
|
109
111
|
|
|
110
112
|
// If preserveSearchInput is true, we need to control the input value
|
|
111
113
|
const handleInputChange = preserveSearchInput
|
|
@@ -139,6 +141,69 @@ const Typeahead = forwardRef<HTMLInputElement, TypeaheadProps>(({
|
|
|
139
141
|
}
|
|
140
142
|
: props.onBlur
|
|
141
143
|
|
|
144
|
+
// Create a ref to access React Select instance
|
|
145
|
+
const selectRef = useRef<any>(null)
|
|
146
|
+
|
|
147
|
+
// Configure focus on selected option using React Select's API
|
|
148
|
+
const handleMenuOpen = () => {
|
|
149
|
+
setTimeout(() => {
|
|
150
|
+
let currentValue = props.value || props.defaultValue
|
|
151
|
+
|
|
152
|
+
// Handle react rendered rails version which passes arrays even for single selects
|
|
153
|
+
if (Array.isArray(currentValue) && currentValue.length > 0) {
|
|
154
|
+
currentValue = currentValue[0]
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// Only apply custom focus if user has NOT made a selection yet
|
|
158
|
+
if (currentValue && selectRef.current && !hasUserSelected && !props.isMulti) {
|
|
159
|
+
|
|
160
|
+
const options = props.options
|
|
161
|
+
if (options) {
|
|
162
|
+
// Find the index of the current value
|
|
163
|
+
const focusedIndex = options.findIndex((option: any) => {
|
|
164
|
+
const optionValue = props.getOptionValue ? props.getOptionValue(option) : option.value
|
|
165
|
+
const currentOptionValue = props.getOptionValue ? props.getOptionValue(currentValue) : currentValue.value
|
|
166
|
+
return optionValue === currentOptionValue
|
|
167
|
+
})
|
|
168
|
+
|
|
169
|
+
if (focusedIndex >= 0 && options[focusedIndex]) {
|
|
170
|
+
// Use React Select's internal state to set focused option
|
|
171
|
+
if (selectRef.current && selectRef.current.setState) {
|
|
172
|
+
const targetOption = options[focusedIndex]
|
|
173
|
+
selectRef.current.setState({
|
|
174
|
+
focusedOption: targetOption,
|
|
175
|
+
focusedValue: null
|
|
176
|
+
})
|
|
177
|
+
|
|
178
|
+
// Handle scrolling so selected option is visible
|
|
179
|
+
setTimeout(() => {
|
|
180
|
+
if (selectRef.current && selectRef.current.menuListRef) {
|
|
181
|
+
const menuElement = selectRef.current.menuListRef
|
|
182
|
+
if (menuElement && menuElement.children && menuElement.children[focusedIndex]) {
|
|
183
|
+
// Calculate the position of the selected option and scroll the menu container
|
|
184
|
+
const optionElement = menuElement.children[focusedIndex] as HTMLElement
|
|
185
|
+
const optionTop = optionElement.offsetTop
|
|
186
|
+
const optionHeight = optionElement.offsetHeight
|
|
187
|
+
const menuHeight = menuElement.clientHeight
|
|
188
|
+
|
|
189
|
+
// Set the menu's scrollTop to position the selected option in the middle
|
|
190
|
+
const scrollToMiddle = optionTop - (menuHeight / 2) + (optionHeight / 2)
|
|
191
|
+
menuElement.scrollTop = Math.max(0, scrollToMiddle)
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
}, 20)
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
}, 0)
|
|
200
|
+
|
|
201
|
+
// Call original onMenuOpen if provided
|
|
202
|
+
if (props.onMenuOpen) {
|
|
203
|
+
props.onMenuOpen()
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
142
207
|
const selectProps = {
|
|
143
208
|
cacheOptions: true,
|
|
144
209
|
required,
|
|
@@ -172,6 +237,7 @@ const Typeahead = forwardRef<HTMLInputElement, TypeaheadProps>(({
|
|
|
172
237
|
...(preserveSearchInput ? { inputValue } : {}),
|
|
173
238
|
onInputChange: handleInputChange,
|
|
174
239
|
onBlur: handleBlur,
|
|
240
|
+
onMenuOpen: handleMenuOpen,
|
|
175
241
|
...props,
|
|
176
242
|
}
|
|
177
243
|
|
|
@@ -261,6 +327,8 @@ const Typeahead = forwardRef<HTMLInputElement, TypeaheadProps>(({
|
|
|
261
327
|
// Reset form submitted state when a selection is made (this is all for react rendered rails kit)
|
|
262
328
|
if (action === 'select-option') {
|
|
263
329
|
setFormSubmitted(false)
|
|
330
|
+
// Mark that user has made a selection to disable default value focus behavior
|
|
331
|
+
setHasUserSelected(true)
|
|
264
332
|
}
|
|
265
333
|
|
|
266
334
|
// If a value is selected and we're preserving input on blur, clear the input
|
|
@@ -269,7 +337,7 @@ const Typeahead = forwardRef<HTMLInputElement, TypeaheadProps>(({
|
|
|
269
337
|
}
|
|
270
338
|
|
|
271
339
|
if (action === 'select-option') {
|
|
272
|
-
if (selectProps.onMultiValueClick) selectProps.onMultiValueClick(option)
|
|
340
|
+
if (selectProps.onMultiValueClick && option) selectProps.onMultiValueClick(option)
|
|
273
341
|
const multiValueClearEvent = new CustomEvent(`pb-typeahead-kit-${selectProps.id}-result-option-select`, { detail: option ? option : _data })
|
|
274
342
|
document.dispatchEvent(multiValueClearEvent)
|
|
275
343
|
}
|
|
@@ -317,6 +385,7 @@ const Typeahead = forwardRef<HTMLInputElement, TypeaheadProps>(({
|
|
|
317
385
|
error={errorDisplay}
|
|
318
386
|
isDisabled={disabled}
|
|
319
387
|
onChange={handleOnChange}
|
|
388
|
+
ref={selectRef}
|
|
320
389
|
{...selectProps}
|
|
321
390
|
/>
|
|
322
391
|
</div>
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
<%
|
|
2
|
+
options = [
|
|
3
|
+
{ label: 'Orange', value: '#FFA500' },
|
|
4
|
+
{ label: 'Red', value: '#FF0000' },
|
|
5
|
+
{ label: 'Green', value: '#1e3d1eff' },
|
|
6
|
+
{ label: 'Blue', value: '#0000FF' },
|
|
7
|
+
{ label: 'Purple', value: '#800080' },
|
|
8
|
+
{ label: 'Yellow', value: '#FFFF00' },
|
|
9
|
+
{ label: 'Pink', value: '#FFC0CB' },
|
|
10
|
+
{ label: 'Brown', value: '#A52A2A' },
|
|
11
|
+
{ label: 'Black', value: '#000000' },
|
|
12
|
+
{ label: 'White', value: '#FFFFFF' },
|
|
13
|
+
{ label: 'Gray', value: '#808080' },
|
|
14
|
+
{ label: 'Cyan', value: '#00FFFF' },
|
|
15
|
+
{ label: 'Magenta', value: '#FF00FF' },
|
|
16
|
+
{ label: 'Lime', value: '#00FF00' },
|
|
17
|
+
{ label: 'Maroon', value: '#800000' },
|
|
18
|
+
{ label: 'Olive', value: '#808000' },
|
|
19
|
+
{ label: 'Navy', value: '#000080' },
|
|
20
|
+
{ label: 'Teal', value: '#008080' },
|
|
21
|
+
{ label: 'Silver', value: '#C0C0C0' },
|
|
22
|
+
{ label: 'Gold', value: '#FFD700' },
|
|
23
|
+
{ label: 'Beige', value: '#F5F5DC' },
|
|
24
|
+
{ label: 'Coral', value: '#FF7F50' }
|
|
25
|
+
]
|
|
26
|
+
%>
|
|
27
|
+
|
|
28
|
+
<%= pb_rails("typeahead", props: {
|
|
29
|
+
default_options: [{ label: 'Gray', value: '#808080' }],
|
|
30
|
+
id: "typeahead-default-value",
|
|
31
|
+
options: options,
|
|
32
|
+
label: "Colors",
|
|
33
|
+
name: :foo,
|
|
34
|
+
is_multi: false
|
|
35
|
+
})
|
|
36
|
+
%>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
The optional `default_options` prop can be used to set a default value for the kit. When a default value is set, focus will be automatically set to the selected option and the dropdown container will scroll to bring the selected option into view.
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
|
|
3
|
+
import Typeahead from '../_typeahead'
|
|
4
|
+
|
|
5
|
+
const options = [
|
|
6
|
+
{ label: 'Orange', value: '#FFA500' },
|
|
7
|
+
{ label: 'Red', value: '#FF0000' },
|
|
8
|
+
{ label: 'Green', value: '#1e3d1eff' },
|
|
9
|
+
{ label: 'Blue', value: '#0000FF' },
|
|
10
|
+
{ label: 'Purple', value: '#800080' },
|
|
11
|
+
{ label: 'Yellow', value: '#FFFF00' },
|
|
12
|
+
{ label: 'Pink', value: '#FFC0CB' },
|
|
13
|
+
{ label: 'Brown', value: '#A52A2A' },
|
|
14
|
+
{ label: 'Black', value: '#000000' },
|
|
15
|
+
{ label: 'White', value: '#FFFFFF' },
|
|
16
|
+
{ label: 'Gray', value: '#808080' },
|
|
17
|
+
{ label: 'Cyan', value: '#00FFFF' },
|
|
18
|
+
{ label: 'Magenta', value: '#FF00FF' },
|
|
19
|
+
{ label: 'Lime', value: '#00FF00' },
|
|
20
|
+
{ label: 'Maroon', value: '#800000' },
|
|
21
|
+
{ label: 'Olive', value: '#808000' },
|
|
22
|
+
{ label: 'Navy', value: '#000080' },
|
|
23
|
+
{ label: 'Teal', value: '#008080' },
|
|
24
|
+
{ label: 'Silver', value: '#C0C0C0' },
|
|
25
|
+
{ label: 'Gold', value: '#FFD700' },
|
|
26
|
+
{ label: 'Beige', value: '#F5F5DC' },
|
|
27
|
+
{ label: 'Coral', value: '#FF7F50' }
|
|
28
|
+
]
|
|
29
|
+
|
|
30
|
+
const TypeaheadDefaultValue = (props) => {
|
|
31
|
+
return (
|
|
32
|
+
<Typeahead
|
|
33
|
+
defaultValue={options[10]}
|
|
34
|
+
label="Colors"
|
|
35
|
+
options={options}
|
|
36
|
+
{...props}
|
|
37
|
+
/>
|
|
38
|
+
)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export default TypeaheadDefaultValue
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
The optional `defaultValue` prop can be used to set a default value for the kit. When a default value is set, focus will be automatically set to the selected option and the dropdown container will scroll to bring the selected option into view.
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
examples:
|
|
2
2
|
rails:
|
|
3
3
|
- typeahead_default: Default
|
|
4
|
+
- typeahead_default_options: With Default Options
|
|
4
5
|
- typeahead_with_context: With Context
|
|
5
6
|
- typeahead_with_pills: With Pills
|
|
6
7
|
- typeahead_without_pills: Without Pills (Single Select)
|
|
@@ -19,6 +20,7 @@ examples:
|
|
|
19
20
|
|
|
20
21
|
react:
|
|
21
22
|
- typeahead_default: Default
|
|
23
|
+
- typeahead_default_value: With Default Value
|
|
22
24
|
- typeahead_react_hook: React Hook
|
|
23
25
|
- typeahead_with_highlight: With Highlight
|
|
24
26
|
- typeahead_with_pills: With Pills
|
|
@@ -16,3 +16,4 @@ export { default as TypeaheadTruncatedText } from './_typeahead_truncated_text.j
|
|
|
16
16
|
export { default as TypeaheadReactHook } from './_typeahead_react_hook.jsx'
|
|
17
17
|
export { default as TypeaheadDisabled } from './_typeahead_disabled.jsx'
|
|
18
18
|
export { default as TypeaheadPreserveInput } from './_typeahead_preserve_input.jsx'
|
|
19
|
+
export { default as TypeaheadDefaultValue } from './_typeahead_default_value.jsx'
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx,Fragment,jsxs}from"react/jsx-runtime";import{useState,useEffect}from"react";import{f as buildAriaProps,g as buildDataProps,h as buildHtmlProps,H as HighchartsReact,i as Highcharts,j as classnames,k as globalProps,l as HighchartsMore,S as SolidGauge,m as buildCss}from"./_typeahead-BH_dkgOy.js";import{c as colors,h as highchartsTheme,m as merge,a as highchartsDarkTheme,t as typography}from"./lib-QZuu1ltS.js";const mapColors=array=>{const regex=/(data)\-[1-8]/;const newArray=array.map((item=>regex.test(item)?`${colors[`data_${item[item.length-1]}`]}`:item));return newArray};const BarGraph=({aria:aria={},data:data={},align:align="center",axisTitle:axisTitle,dark:dark=false,chartData:chartData,className:className="pb_bar_graph",colors:colors2,htmlOptions:htmlOptions={},customOptions:customOptions={},axisFormat:axisFormat,id:id,pointStart:pointStart,stacking:stacking,subTitle:subTitle,type:type="column",title:title="Title",xAxisCategories:xAxisCategories,yAxisMin:yAxisMin,yAxisMax:yAxisMax,legend:legend=false,toggleLegendClick:toggleLegendClick=true,height:height,layout:layout="horizontal",verticalAlign:verticalAlign="bottom",x:x=0,y:y=0,...props})=>{const ariaProps=buildAriaProps(aria);const dataProps=buildDataProps(data);const htmlProps=buildHtmlProps(htmlOptions);const setupTheme=()=>{dark?Highcharts.setOptions(highchartsDarkTheme):Highcharts.setOptions(highchartsTheme)};setupTheme();const staticOptions={title:{text:title},chart:{height:height,type:type},subtitle:{text:subTitle},yAxis:[{labels:{format:typeof axisFormat==="string"?axisFormat:axisFormat&&axisFormat[0]?axisFormat[0].format:""},min:yAxisMin,max:yAxisMax,opposite:false,title:{text:Array.isArray(axisTitle)?axisTitle.length>0?axisTitle[0].name:null:axisTitle},plotLines:typeof yAxisMin!=="undefined"&&yAxisMin!==null?[]:[{value:0,zIndex:10,color:"#E4E8F0"}]}],xAxis:{categories:xAxisCategories},legend:{enabled:legend,align:align,verticalAlign:verticalAlign,layout:layout,x:x,y:y},colors:colors2!==void 0&&colors2.length>0?mapColors(colors2):highchartsTheme.colors,plotOptions:{series:{stacking:stacking,pointStart:pointStart,borderWidth:stacking?0:"",events:{},dataLabels:{enabled:false}}},series:chartData,credits:false};if(Array.isArray(axisTitle)&&axisTitle.length>1&&axisTitle[1].name){staticOptions.yAxis.push({labels:{format:typeof axisFormat==="string"?axisFormat:axisFormat[1].format},min:yAxisMin,max:yAxisMax,opposite:true,title:{text:axisTitle[1].name},plotLines:typeof yAxisMin!=="undefined"&&yAxisMin!==null?[]:[{value:0,zIndex:10,color:"#E4E8F0"}]})}if(!toggleLegendClick){staticOptions.plotOptions.series.events={legendItemClick:()=>false}}const filteredProps={...props};delete filteredProps.verticalAlign;const[options,setOptions]=useState({});useEffect((()=>{setOptions(merge(staticOptions,customOptions))}),[chartData]);return jsx(HighchartsReact,{containerProps:{className:classnames(globalProps(filteredProps),className),id:id,...ariaProps,...dataProps,...htmlProps},highcharts:Highcharts,options:options})};const alignBlockElement=event=>{const itemToMove=document.querySelector(`#wrapper-circle-chart-${event.target.renderTo.id} .pb-circle-chart-block`);const chartContainer=document.querySelector(`#${event.target.renderTo.id}`);if(itemToMove!==null&&chartContainer!==null){itemToMove.style.height=`${event.target.chartHeight}px`;itemToMove.style.width=`${event.target.chartWidth}px`;if(chartContainer.firstChild!==null){chartContainer.firstChild.before(itemToMove)}}};const CircleChart=({align:align="center",aria:aria={},rounded:rounded=false,borderColor:borderColor=(rounded?null:""),borderWidth:borderWidth=(rounded?20:null),chartData:chartData,children:children,className:className,colors:colors2=[],customOptions:customOptions={},dark:dark=false,data:data={},dataLabelHtml:dataLabelHtml="<div>{point.name}</div>",dataLabels:dataLabels=false,height:height,htmlOptions:htmlOptions={},id:id,innerSize:innerSize="md",legend:legend=false,maxPointSize:maxPointSize=null,minPointSize:minPointSize=null,startAngle:startAngle=null,style:style="pie",title:title,tooltipHtml:tooltipHtml,useHtml:useHtml=false,zMin:zMin=null,layout:layout="horizontal",verticalAlign:verticalAlign="bottom",x:x=0,y:y=0,...props})=>{const ariaProps=buildAriaProps(aria);const dataProps=buildDataProps(data);const htmlProps=buildHtmlProps(htmlOptions);HighchartsMore(Highcharts);const setupTheme=()=>{dark?Highcharts.setOptions(highchartsDarkTheme):Highcharts.setOptions(highchartsTheme)};setupTheme();Highcharts.setOptions({tooltip:{headerFormat:null,pointFormat:tooltipHtml?tooltipHtml:'<span style="font-weight: bold; color:{point.color};">●</span>{point.name}: <b>{point.y}</b>',useHTML:useHtml}});const innerSizes={sm:"35%",md:"50%",lg:"85%",none:"0%"};const innerSizeFormat=size=>innerSizes[size];const filteredProps={...props};delete filteredProps.verticalAlign;const[options,setOptions]=useState({});useEffect((()=>{const formattedChartData=chartData.map((obj=>{obj.y=obj.value;delete obj.value;return obj}));const staticOptions={title:{text:title},chart:{height:height,type:style,events:{render:event=>alignBlockElement(event),redraw:event=>alignBlockElement(event)}},legend:{align:align,verticalAlign:verticalAlign,layout:layout,x:x,y:y},plotOptions:{pie:{colors:colors2.length>0?mapColors(colors2):highchartsTheme.colors,dataLabels:{enabled:dataLabels,connectorShape:"straight",connectorWidth:3,format:dataLabelHtml},showInLegend:legend}},series:[{minPointSize:minPointSize,maxPointSize:maxPointSize,innerSize:borderWidth==20?"100%":innerSizeFormat(innerSize),data:formattedChartData,zMin:zMin,startAngle:startAngle,borderWidth:borderWidth,borderColor:borderColor}],credits:false};setOptions(merge(staticOptions,customOptions))}),[chartData]);return jsx(Fragment,{children:children?jsxs("div",{id:`wrapper-circle-chart-${id}`,children:[jsx(HighchartsReact,{containerProps:{className:classnames("pb_circle_chart",globalProps(filteredProps)),id:id,...ariaProps,...dataProps,...htmlProps},highcharts:Highcharts,options:options}),jsx("div",{className:"pb-circle-chart-block",children:children})]}):jsx(HighchartsReact,{containerProps:{className:classnames("pb_circle_chart",globalProps(filteredProps)),id:id,...ariaProps,...dataProps,...htmlProps},highcharts:Highcharts,options:options})})};const Gauge=({aria:aria={},chartData:chartData,customOptions:customOptions={},dark:dark=false,data:data={},disableAnimation:disableAnimation=false,fullCircle:fullCircle=false,height:height=null,htmlOptions:htmlOptions={},id:id,max:max=100,min:min=0,prefix:prefix="",showLabels:showLabels=false,style:style="solidgauge",suffix:suffix="",title:title="",tooltipHtml:tooltipHtml='<span style="font-weight: bold; color:{point.color};">●</span>{point.name}: <b>{point.y}</b>',colors:colors$1=[],minorTickInterval:minorTickInterval=null,circumference:circumference=(fullCircle?[0,360]:[-100,100]),...props})=>{const ariaProps=buildAriaProps(aria);const dataProps=buildDataProps(data);const htmlProps=buildHtmlProps(htmlOptions);HighchartsMore(Highcharts);SolidGauge(Highcharts);const setupTheme=()=>{dark?Highcharts.setOptions(highchartsDarkTheme):Highcharts.setOptions(highchartsTheme)};setupTheme();Highcharts.setOptions({tooltip:{pointFormat:tooltipHtml,followPointer:true}});const css=buildCss({pb_gauge_kit:true});const[options,setOptions]=useState({});useEffect((()=>{const formattedChartData=chartData.map((obj=>{obj.y=obj.value;delete obj.value;return obj}));const staticOptions={chart:{events:{load(){setTimeout(this.reflow.bind(this),0)}},type:style,height:height},title:{text:title},yAxis:{min:min,max:max,lineWidth:0,tickWidth:0,minorTickInterval:minorTickInterval,tickAmount:2,tickPositions:[min,max],labels:{y:26,enabled:showLabels}},credits:false,series:[{data:formattedChartData}],pane:{center:["50%","50%"],size:"90%",startAngle:circumference[0],endAngle:circumference[1],background:{borderWidth:20,innerRadius:"90%",outerRadius:"90%",shape:"arc",className:"gauge-pane"}},colors:colors$1!==void 0&&colors$1.length>0?mapColors(colors$1):highchartsTheme.colors,plotOptions:{series:{animation:!disableAnimation},solidgauge:{borderColor:colors$1!==void 0&&colors$1.length===1?mapColors(colors$1).join():highchartsTheme.colors[0],borderWidth:20,radius:90,innerRadius:"90%",dataLabels:{borderWidth:0,color:colors.text_lt_default,enabled:true,format:`<span class="prefix${dark?" dark":""}">${prefix}</span><span class="fix${dark?" dark":""}">{y:,f}</span><span class="suffix${dark?" dark":""}">${suffix}</span>`,style:{fontFamily:typography.font_family_base,fontWeight:typography.regular,fontSize:typography.heading_2},y:-26}}}};setOptions(merge(staticOptions,customOptions));if(document.querySelector(".prefix")){document.querySelectorAll(".prefix").forEach((prefix2=>{prefix2.setAttribute("y","28")}));document.querySelectorAll(".fix").forEach((fix=>fix.setAttribute("y","38")))}}),[chartData]);return jsx(HighchartsReact,{containerProps:{className:classnames(css,globalProps(props)),id:id,...ariaProps,...dataProps,...htmlProps},highcharts:Highcharts,options:options})};const LineGraph=({aria:aria={},data:data={},align:align="center",className:className="pb_bar_graph",customOptions:customOptions={},dark:dark=false,gradient:gradient=false,type:type="line",htmlOptions:htmlOptions={},id:id,legend:legend=false,toggleLegendClick:toggleLegendClick=true,layout:layout="horizontal",verticalAlign:verticalAlign="bottom",x:x=0,y:y=0,axisTitle:axisTitle,xAxisCategories:xAxisCategories,yAxisMin:yAxisMin,yAxisMax:yAxisMax,chartData:chartData,pointStart:pointStart,subTitle:subTitle,title:title,height:height,colors:colors2=[],...props})=>{const ariaProps=buildAriaProps(aria);const dataProps=buildDataProps(data);const htmlProps=buildHtmlProps(htmlOptions);const setupTheme=()=>{dark?Highcharts.setOptions(highchartsDarkTheme):Highcharts.setOptions(highchartsTheme)};setupTheme();const staticOptions={title:{text:title},chart:{height:height,type:type},subtitle:{text:subTitle},yAxis:{min:yAxisMin,max:yAxisMax,title:{text:axisTitle}},xAxis:{categories:xAxisCategories},legend:{enabled:legend,align:align,verticalAlign:verticalAlign,layout:layout,x:x,y:y},colors:colors2!==void 0&&colors2.length>0?mapColors(colors2):highchartsTheme.colors,plotOptions:{series:{pointStart:pointStart,events:{},dataLabels:{enabled:false}}},series:chartData,credits:false};if(!toggleLegendClick){staticOptions.plotOptions.series.events={legendItemClick:()=>false}}const filteredProps={...props};delete filteredProps.verticalAlign;const[options,setOptions]=useState({});useEffect((()=>{setOptions(merge(staticOptions,customOptions))}),[chartData]);return jsx(HighchartsReact,{containerProps:{className:classnames(globalProps(filteredProps),className),id:id,...ariaProps,...dataProps,...htmlProps},highcharts:Highcharts,options:options})};export{BarGraph as B,CircleChart as C,Gauge as G,LineGraph as L};
|
|
1
|
+
import{jsx,Fragment,jsxs}from"react/jsx-runtime";import{useState,useEffect}from"react";import{f as buildAriaProps,g as buildDataProps,h as buildHtmlProps,H as HighchartsReact,i as Highcharts,j as classnames,k as globalProps,l as HighchartsMore,S as SolidGauge,m as buildCss}from"./_typeahead-BjYBazGq.js";import{c as colors,h as highchartsTheme,m as merge,a as highchartsDarkTheme,t as typography}from"./lib-QZuu1ltS.js";const mapColors=array=>{const regex=/(data)\-[1-8]/;const newArray=array.map((item=>regex.test(item)?`${colors[`data_${item[item.length-1]}`]}`:item));return newArray};const BarGraph=({aria:aria={},data:data={},align:align="center",axisTitle:axisTitle,dark:dark=false,chartData:chartData,className:className="pb_bar_graph",colors:colors2,htmlOptions:htmlOptions={},customOptions:customOptions={},axisFormat:axisFormat,id:id,pointStart:pointStart,stacking:stacking,subTitle:subTitle,type:type="column",title:title="Title",xAxisCategories:xAxisCategories,yAxisMin:yAxisMin,yAxisMax:yAxisMax,legend:legend=false,toggleLegendClick:toggleLegendClick=true,height:height,layout:layout="horizontal",verticalAlign:verticalAlign="bottom",x:x=0,y:y=0,...props})=>{const ariaProps=buildAriaProps(aria);const dataProps=buildDataProps(data);const htmlProps=buildHtmlProps(htmlOptions);const setupTheme=()=>{dark?Highcharts.setOptions(highchartsDarkTheme):Highcharts.setOptions(highchartsTheme)};setupTheme();const staticOptions={title:{text:title},chart:{height:height,type:type},subtitle:{text:subTitle},yAxis:[{labels:{format:typeof axisFormat==="string"?axisFormat:axisFormat&&axisFormat[0]?axisFormat[0].format:""},min:yAxisMin,max:yAxisMax,opposite:false,title:{text:Array.isArray(axisTitle)?axisTitle.length>0?axisTitle[0].name:null:axisTitle},plotLines:typeof yAxisMin!=="undefined"&&yAxisMin!==null?[]:[{value:0,zIndex:10,color:"#E4E8F0"}]}],xAxis:{categories:xAxisCategories},legend:{enabled:legend,align:align,verticalAlign:verticalAlign,layout:layout,x:x,y:y},colors:colors2!==void 0&&colors2.length>0?mapColors(colors2):highchartsTheme.colors,plotOptions:{series:{stacking:stacking,pointStart:pointStart,borderWidth:stacking?0:"",events:{},dataLabels:{enabled:false}}},series:chartData,credits:false};if(Array.isArray(axisTitle)&&axisTitle.length>1&&axisTitle[1].name){staticOptions.yAxis.push({labels:{format:typeof axisFormat==="string"?axisFormat:axisFormat[1].format},min:yAxisMin,max:yAxisMax,opposite:true,title:{text:axisTitle[1].name},plotLines:typeof yAxisMin!=="undefined"&&yAxisMin!==null?[]:[{value:0,zIndex:10,color:"#E4E8F0"}]})}if(!toggleLegendClick){staticOptions.plotOptions.series.events={legendItemClick:()=>false}}const filteredProps={...props};delete filteredProps.verticalAlign;const[options,setOptions]=useState({});useEffect((()=>{setOptions(merge(staticOptions,customOptions))}),[chartData]);return jsx(HighchartsReact,{containerProps:{className:classnames(globalProps(filteredProps),className),id:id,...ariaProps,...dataProps,...htmlProps},highcharts:Highcharts,options:options})};const alignBlockElement=event=>{const itemToMove=document.querySelector(`#wrapper-circle-chart-${event.target.renderTo.id} .pb-circle-chart-block`);const chartContainer=document.querySelector(`#${event.target.renderTo.id}`);if(itemToMove!==null&&chartContainer!==null){itemToMove.style.height=`${event.target.chartHeight}px`;itemToMove.style.width=`${event.target.chartWidth}px`;if(chartContainer.firstChild!==null){chartContainer.firstChild.before(itemToMove)}}};const CircleChart=({align:align="center",aria:aria={},rounded:rounded=false,borderColor:borderColor=(rounded?null:""),borderWidth:borderWidth=(rounded?20:null),chartData:chartData,children:children,className:className,colors:colors2=[],customOptions:customOptions={},dark:dark=false,data:data={},dataLabelHtml:dataLabelHtml="<div>{point.name}</div>",dataLabels:dataLabels=false,height:height,htmlOptions:htmlOptions={},id:id,innerSize:innerSize="md",legend:legend=false,maxPointSize:maxPointSize=null,minPointSize:minPointSize=null,startAngle:startAngle=null,style:style="pie",title:title,tooltipHtml:tooltipHtml,useHtml:useHtml=false,zMin:zMin=null,layout:layout="horizontal",verticalAlign:verticalAlign="bottom",x:x=0,y:y=0,...props})=>{const ariaProps=buildAriaProps(aria);const dataProps=buildDataProps(data);const htmlProps=buildHtmlProps(htmlOptions);HighchartsMore(Highcharts);const setupTheme=()=>{dark?Highcharts.setOptions(highchartsDarkTheme):Highcharts.setOptions(highchartsTheme)};setupTheme();Highcharts.setOptions({tooltip:{headerFormat:null,pointFormat:tooltipHtml?tooltipHtml:'<span style="font-weight: bold; color:{point.color};">●</span>{point.name}: <b>{point.y}</b>',useHTML:useHtml}});const innerSizes={sm:"35%",md:"50%",lg:"85%",none:"0%"};const innerSizeFormat=size=>innerSizes[size];const filteredProps={...props};delete filteredProps.verticalAlign;const[options,setOptions]=useState({});useEffect((()=>{const formattedChartData=chartData.map((obj=>{obj.y=obj.value;delete obj.value;return obj}));const staticOptions={title:{text:title},chart:{height:height,type:style,events:{render:event=>alignBlockElement(event),redraw:event=>alignBlockElement(event)}},legend:{align:align,verticalAlign:verticalAlign,layout:layout,x:x,y:y},plotOptions:{pie:{colors:colors2.length>0?mapColors(colors2):highchartsTheme.colors,dataLabels:{enabled:dataLabels,connectorShape:"straight",connectorWidth:3,format:dataLabelHtml},showInLegend:legend}},series:[{minPointSize:minPointSize,maxPointSize:maxPointSize,innerSize:borderWidth==20?"100%":innerSizeFormat(innerSize),data:formattedChartData,zMin:zMin,startAngle:startAngle,borderWidth:borderWidth,borderColor:borderColor}],credits:false};setOptions(merge(staticOptions,customOptions))}),[chartData]);return jsx(Fragment,{children:children?jsxs("div",{id:`wrapper-circle-chart-${id}`,children:[jsx(HighchartsReact,{containerProps:{className:classnames("pb_circle_chart",globalProps(filteredProps)),id:id,...ariaProps,...dataProps,...htmlProps},highcharts:Highcharts,options:options}),jsx("div",{className:"pb-circle-chart-block",children:children})]}):jsx(HighchartsReact,{containerProps:{className:classnames("pb_circle_chart",globalProps(filteredProps)),id:id,...ariaProps,...dataProps,...htmlProps},highcharts:Highcharts,options:options})})};const Gauge=({aria:aria={},chartData:chartData,customOptions:customOptions={},dark:dark=false,data:data={},disableAnimation:disableAnimation=false,fullCircle:fullCircle=false,height:height=null,htmlOptions:htmlOptions={},id:id,max:max=100,min:min=0,prefix:prefix="",showLabels:showLabels=false,style:style="solidgauge",suffix:suffix="",title:title="",tooltipHtml:tooltipHtml='<span style="font-weight: bold; color:{point.color};">●</span>{point.name}: <b>{point.y}</b>',colors:colors$1=[],minorTickInterval:minorTickInterval=null,circumference:circumference=(fullCircle?[0,360]:[-100,100]),...props})=>{const ariaProps=buildAriaProps(aria);const dataProps=buildDataProps(data);const htmlProps=buildHtmlProps(htmlOptions);HighchartsMore(Highcharts);SolidGauge(Highcharts);const setupTheme=()=>{dark?Highcharts.setOptions(highchartsDarkTheme):Highcharts.setOptions(highchartsTheme)};setupTheme();Highcharts.setOptions({tooltip:{pointFormat:tooltipHtml,followPointer:true}});const css=buildCss({pb_gauge_kit:true});const[options,setOptions]=useState({});useEffect((()=>{const formattedChartData=chartData.map((obj=>{obj.y=obj.value;delete obj.value;return obj}));const staticOptions={chart:{events:{load(){setTimeout(this.reflow.bind(this),0)}},type:style,height:height},title:{text:title},yAxis:{min:min,max:max,lineWidth:0,tickWidth:0,minorTickInterval:minorTickInterval,tickAmount:2,tickPositions:[min,max],labels:{y:26,enabled:showLabels}},credits:false,series:[{data:formattedChartData}],pane:{center:["50%","50%"],size:"90%",startAngle:circumference[0],endAngle:circumference[1],background:{borderWidth:20,innerRadius:"90%",outerRadius:"90%",shape:"arc",className:"gauge-pane"}},colors:colors$1!==void 0&&colors$1.length>0?mapColors(colors$1):highchartsTheme.colors,plotOptions:{series:{animation:!disableAnimation},solidgauge:{borderColor:colors$1!==void 0&&colors$1.length===1?mapColors(colors$1).join():highchartsTheme.colors[0],borderWidth:20,radius:90,innerRadius:"90%",dataLabels:{borderWidth:0,color:colors.text_lt_default,enabled:true,format:`<span class="prefix${dark?" dark":""}">${prefix}</span><span class="fix${dark?" dark":""}">{y:,f}</span><span class="suffix${dark?" dark":""}">${suffix}</span>`,style:{fontFamily:typography.font_family_base,fontWeight:typography.regular,fontSize:typography.heading_2},y:-26}}}};setOptions(merge(staticOptions,customOptions));if(document.querySelector(".prefix")){document.querySelectorAll(".prefix").forEach((prefix2=>{prefix2.setAttribute("y","28")}));document.querySelectorAll(".fix").forEach((fix=>fix.setAttribute("y","38")))}}),[chartData]);return jsx(HighchartsReact,{containerProps:{className:classnames(css,globalProps(props)),id:id,...ariaProps,...dataProps,...htmlProps},highcharts:Highcharts,options:options})};const LineGraph=({aria:aria={},data:data={},align:align="center",className:className="pb_bar_graph",customOptions:customOptions={},dark:dark=false,gradient:gradient=false,type:type="line",htmlOptions:htmlOptions={},id:id,legend:legend=false,toggleLegendClick:toggleLegendClick=true,layout:layout="horizontal",verticalAlign:verticalAlign="bottom",x:x=0,y:y=0,axisTitle:axisTitle,xAxisCategories:xAxisCategories,yAxisMin:yAxisMin,yAxisMax:yAxisMax,chartData:chartData,pointStart:pointStart,subTitle:subTitle,title:title,height:height,colors:colors2=[],...props})=>{const ariaProps=buildAriaProps(aria);const dataProps=buildDataProps(data);const htmlProps=buildHtmlProps(htmlOptions);const setupTheme=()=>{dark?Highcharts.setOptions(highchartsDarkTheme):Highcharts.setOptions(highchartsTheme)};setupTheme();const staticOptions={title:{text:title},chart:{height:height,type:type},subtitle:{text:subTitle},yAxis:{min:yAxisMin,max:yAxisMax,title:{text:axisTitle}},xAxis:{categories:xAxisCategories},legend:{enabled:legend,align:align,verticalAlign:verticalAlign,layout:layout,x:x,y:y},colors:colors2!==void 0&&colors2.length>0?mapColors(colors2):highchartsTheme.colors,plotOptions:{series:{pointStart:pointStart,events:{},dataLabels:{enabled:false}}},series:chartData,credits:false};if(!toggleLegendClick){staticOptions.plotOptions.series.events={legendItemClick:()=>false}}const filteredProps={...props};delete filteredProps.verticalAlign;const[options,setOptions]=useState({});useEffect((()=>{setOptions(merge(staticOptions,customOptions))}),[chartData]);return jsx(HighchartsReact,{containerProps:{className:classnames(globalProps(filteredProps),className),id:id,...ariaProps,...dataProps,...htmlProps},highcharts:Highcharts,options:options})};export{BarGraph as B,CircleChart as C,Gauge as G,LineGraph as L};
|