playbook_ui 15.3.0.pre.alpha.PLAY2577reactpopoverappendToPOC11730 → 15.3.0.pre.alpha.play259311731

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 688c9a3aae91a38d69ebd8bb04ac8f3e487dd9717307116273916f0b04b0e408
4
- data.tar.gz: 8dfc9836c8f67dce77139ea4b57455b2745f2c56f685dd4557af5c4d8951675f
3
+ metadata.gz: ffcc9cd701358929b90b6a4de99034138c4f04b90909aaff546fa9a4c8c1c73c
4
+ data.tar.gz: 6728bf7227bdd1440d3b415dd561a518793fdc02ef54cda3b212f8526a237811
5
5
  SHA512:
6
- metadata.gz: 80e9119c3ed2a8421a63862c8d84989658d4750f6b2ab3f3bd1b1c5b2a46e260feed7329ee83f745f57d703f0a0e3d6ed65f456fa7a81a84ba400ab4041928e7
7
- data.tar.gz: 25c31816061867ffed3e23beb88691b8578a2ad87264e5bf33ddb2dc2d86a3a35ea753a4b2dadebbfd162a3ed0d585260e7fb78cb47556c6abad965db43d3e09
6
+ metadata.gz: 0e8fa30daf530ffa258a9a131c7eacdf6d401f5b64b47b7396752adb348a15e6612505d5c4caf65fa189fcd67eae631d6e23f21ea2111861bd696314ce1db181
7
+ data.tar.gz: 85a6aebcf6d61d4b75c0c556f580b1a68e17e46d9b57519636d3ca636e485aec1b0e15c7652886db25cd6aaa747dd35be6f44e25bade49e059b864a255540e54
@@ -24,7 +24,6 @@ import { uniqueId } from '../utilities/object';
24
24
  type ModifiedGlobalProps = Omit<GlobalProps, 'minWidth' | 'maxHeight' | 'minHeight'>
25
25
 
26
26
  type PbPopoverProps = {
27
- appendTo?: string;
28
27
  aria?: { [key: string]: string };
29
28
  className?: string;
30
29
  closeOnClick?: "outside" | "inside" | "any";
@@ -63,25 +62,6 @@ const popoverModifiers = ({
63
62
  return offset ? modifiers.concat([POPOVER_MODIFIERS.offset]) : modifiers;
64
63
  };
65
64
 
66
- const getAppendTarget = (
67
- appendTo: string | undefined,
68
- targetId: string
69
- ): HTMLElement => {
70
- if (!appendTo || appendTo === "body") return document.body;
71
-
72
- if (appendTo === "parent") {
73
- const referenceWrapper = document.querySelector(`#reference-${targetId}`);
74
- if (referenceWrapper?.parentElement) {
75
- return referenceWrapper.parentElement;
76
- }
77
- }
78
-
79
- const selectorMatch = document.querySelector(appendTo);
80
- if (selectorMatch instanceof HTMLElement) return selectorMatch;
81
-
82
- return document.body;
83
- };
84
-
85
65
  const Popover = (props: PbPopoverProps) => {
86
66
  const {
87
67
  aria = {},
@@ -133,7 +113,7 @@ const Popover = (props: PbPopoverProps) => {
133
113
 
134
114
  return (
135
115
  <Popper
136
- modifiers={popoverModifiers({ modifiers, offset: offset || false })}
116
+ modifiers={popoverModifiers({ modifiers, offset })}
137
117
  placement={placement}
138
118
  referenceElement={referenceElement}
139
119
  >
@@ -174,7 +154,6 @@ const Popover = (props: PbPopoverProps) => {
174
154
  const PbReactPopover = (props: PbPopoverProps): React.ReactElement => {
175
155
  const [targetId] = useState(uniqueId('id-'))
176
156
  const {
177
- appendTo,
178
157
  className,
179
158
  children,
180
159
  modifiers = [],
@@ -267,10 +246,10 @@ const PbReactPopover = (props: PbPopoverProps): React.ReactElement => {
267
246
  {show &&
268
247
  (usePortal ? (
269
248
  <>
270
- {ReactDOM.createPortal(
271
- popoverComponent,
272
- getAppendTarget(appendTo, targetId)
273
- )}
249
+ {ReactDOM.createPortal(
250
+ popoverComponent,
251
+ document.querySelector(portal)
252
+ )}
274
253
  </>
275
254
  ) : (
276
255
  { popoverComponent }
@@ -15,4 +15,3 @@ examples:
15
15
  - popover_z_index: Set Z-Index
16
16
  - popover_scroll_height: Scroll and Height Settings
17
17
  - popover_actionable_content: With Actionable Content
18
- - popover_append_to: Append To
@@ -4,4 +4,3 @@ export { default as PopoverClose } from './_popover_close.jsx'
4
4
  export { default as PopoverZIndex } from './_popover_z_index.jsx'
5
5
  export { default as PopoverScrollHeight } from './_popover_scroll_height.jsx'
6
6
  export { default as PopoverActionableContent } from './_popover_actionable_content.jsx'
7
- export { default as PopoverAppendTo } from './_popover_append_to.jsx'
@@ -159,62 +159,6 @@ const PopoverTestClicktoClose3 = () => {
159
159
  )
160
160
  };
161
161
 
162
- //Test Popover with appendTo="parent"
163
- const PopoverTestAppendToParent = () => {
164
- const [mockState, setMockState] = React.useState(false)
165
- const togglePopover = () => {
166
- setMockState(!mockState)
167
- }
168
-
169
- const popoverReference = (
170
- <Button onClick={togglePopover}
171
- text="Click Me"
172
- />
173
- );
174
- return (
175
- <div data-testid="parent-container"
176
- id="parent-container"
177
- >
178
- <PbReactPopover
179
- appendTo="parent"
180
- offset
181
- reference={popoverReference}
182
- show={mockState}
183
- >
184
- {"Appended to parent"}
185
- </PbReactPopover>
186
- </div>
187
- )
188
- };
189
-
190
- //Test Popover with appendTo CSS selector
191
- const PopoverTestAppendToSelector = () => {
192
- const [mockState, setMockState] = React.useState(false)
193
- const togglePopover = () => {
194
- setMockState(!mockState)
195
- }
196
-
197
- const popoverReference = (
198
- <Button onClick={togglePopover}
199
- text="Click Me"
200
- />
201
- );
202
- return (
203
- <div data-testid="custom-container"
204
- id="custom-container"
205
- >
206
- <PbReactPopover
207
- appendTo="#custom-container"
208
- offset
209
- reference={popoverReference}
210
- show={mockState}
211
- >
212
- {"Appended to custom container"}
213
- </PbReactPopover>
214
- </div>
215
- )
216
- };
217
-
218
162
 
219
163
  test("renders Popover", () => {
220
164
  render(<PopoverTest data={{ testid: testId}}/>)
@@ -273,28 +217,4 @@ const PopoverTestAppendToSelector = () => {
273
217
  fireEvent.click(btn);
274
218
 
275
219
  expect(kit).not.toBeInTheDocument;
276
- });
277
-
278
- test("renders Popover with appendTo parent", () => {
279
- render(<PopoverTestAppendToParent data={{ testid: testId}}/>)
280
- const btn = screen.getByText(/click me/i)
281
- fireEvent.click(btn);
282
- const kit = screen.getByText("Appended to parent");
283
- expect(kit).toBeInTheDocument();
284
-
285
- // Check that the popover is rendered inside the parent container
286
- const parentContainer = screen.getByTestId("parent-container");
287
- expect(parentContainer).toContainElement(kit);
288
- });
289
-
290
- test("renders Popover with appendTo CSS selector", () => {
291
- render(<PopoverTestAppendToSelector data={{ testid: testId}}/>)
292
- const btn = screen.getByText(/click me/i)
293
- fireEvent.click(btn);
294
- const kit = screen.getByText("Appended to custom container");
295
- expect(kit).toBeInTheDocument();
296
-
297
- // Check that the popover is rendered inside the custom container
298
- const customContainer = screen.getByTestId("custom-container");
299
- expect(customContainer).toContainElement(kit);
300
220
  });
@@ -171,4 +171,45 @@ test('typeahead with defaultValue with focus behavior', async () => {
171
171
  expect(focusedOption).toBeInTheDocument()
172
172
  expect(focusedOption).toHaveTextContent('Red')
173
173
  })
174
+ })
175
+
176
+ test('typeahead with grouped options and defaultValue focus behavior', async () => {
177
+ const groupedOptions = [
178
+ {
179
+ label: "Warm Colors",
180
+ options: [
181
+ { label: "Red", value: "#FF0000" },
182
+ { label: "Orange", value: "#FFA500" },
183
+ { label: "Yellow", value: "#FFFF00" }
184
+ ]
185
+ },
186
+ {
187
+ label: "Cool Colors",
188
+ options: [
189
+ { label: "Blue", value: "#0000FF" },
190
+ { label: "Teal", value: "#008080" },
191
+ { label: "Cyan", value: "#00FFFF" }
192
+ ]
193
+ },
194
+ {
195
+ label: "Fun Shades",
196
+ options: [
197
+ { label: "Pink", value: "#FFC0CB" },
198
+ { label: "Magenta", value: "#FF00FF" },
199
+ { label: "Purple", value: "#800080" }
200
+ ]
201
+ }
202
+ ]
203
+
204
+ render(
205
+ <Typeahead
206
+ data={{ testid: 'grouped-options-focus-test' }}
207
+ defaultValue={[{ label: "Pink", value: "#FFC0CB" }]}
208
+ options={groupedOptions}
209
+ />
210
+ )
211
+
212
+ const kit = screen.getByTestId('grouped-options-focus-test')
213
+ const inputDiv = kit.querySelector(".typeahead-kit-select__single-value")
214
+ expect(inputDiv).toHaveTextContent("Pink")
174
215
  })
@@ -144,6 +144,18 @@ const Typeahead = forwardRef<HTMLInputElement, TypeaheadProps>(({
144
144
  // Create a ref to access React Select instance
145
145
  const selectRef = useRef<any>(null)
146
146
 
147
+ // Helper function to flatten grouped options if custom groups are used
148
+ const flattenOptions = (options: any[]): any[] => {
149
+ if (!options) return []
150
+
151
+ return options.reduce((acc, option) => {
152
+ if (option.options && Array.isArray(option.options)) {
153
+ return [...acc, ...option.options]
154
+ }
155
+ return [...acc, option]
156
+ }, [])
157
+ }
158
+
147
159
  // Configure focus on selected option using React Select's API
148
160
  const handleMenuOpen = () => {
149
161
  setTimeout(() => {
@@ -159,17 +171,18 @@ const Typeahead = forwardRef<HTMLInputElement, TypeaheadProps>(({
159
171
 
160
172
  const options = props.options
161
173
  if (options) {
162
- // Find the index of the current value
163
- const focusedIndex = options.findIndex((option: any) => {
174
+ // Flatten grouped options to find the matching option and find matching option
175
+ const flatOptions = flattenOptions(options)
176
+
177
+ const targetOption = flatOptions.find((option: any) => {
164
178
  const optionValue = props.getOptionValue ? props.getOptionValue(option) : option.value
165
179
  const currentOptionValue = props.getOptionValue ? props.getOptionValue(currentValue) : currentValue.value
166
180
  return optionValue === currentOptionValue
167
181
  })
168
182
 
169
- if (focusedIndex >= 0 && options[focusedIndex]) {
183
+ if (targetOption) {
170
184
  // Use React Select's internal state to set focused option
171
185
  if (selectRef.current && selectRef.current.setState) {
172
- const targetOption = options[focusedIndex]
173
186
  selectRef.current.setState({
174
187
  focusedOption: targetOption,
175
188
  focusedValue: null
@@ -179,11 +192,12 @@ const Typeahead = forwardRef<HTMLInputElement, TypeaheadProps>(({
179
192
  setTimeout(() => {
180
193
  if (selectRef.current && selectRef.current.menuListRef) {
181
194
  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
195
+ // Find the focused option using React Select's class
196
+ const focusedElement = menuElement.querySelector('.typeahead-kit-select__option--is-focused')
197
+
198
+ if (focusedElement) {
199
+ const optionTop = focusedElement.offsetTop
200
+ const optionHeight = focusedElement.offsetHeight
187
201
  const menuHeight = menuElement.clientHeight
188
202
 
189
203
  // Set the menu's scrollTop to position the selected option in the middle
@@ -0,0 +1,64 @@
1
+ <%
2
+ grouped_options = [
3
+ {
4
+ label: "Warm Colors",
5
+ options: [
6
+ { label: "Red", value: "#FF0000" },
7
+ { label: "Orange", value: "#FFA500" },
8
+ { label: "Yellow", value: "#FFFF00" },
9
+ { label: "Coral", value: "#FF7F50" },
10
+ { label: "Gold", value: "#FFD700" }
11
+ ]
12
+ },
13
+ {
14
+ label: "Cool Colors",
15
+ options: [
16
+ { label: "Blue", value: "#0000FF" },
17
+ { label: "Teal", value: "#008080" },
18
+ { label: "Cyan", value: "#00FFFF" },
19
+ { label: "Navy", value: "#000080" },
20
+ { label: "Turquoise", value: "#40E0D0" }
21
+ ]
22
+ },
23
+ {
24
+ label: "Neutrals",
25
+ options: [
26
+ { label: "White", value: "#FFFFFF" },
27
+ { label: "Black", value: "#000000" },
28
+ { label: "Gray", value: "#808080" },
29
+ { label: "Beige", value: "#F5F5DC" },
30
+ { label: "Silver", value: "#C0C0C0" }
31
+ ]
32
+ },
33
+ {
34
+ label: "Earth Tones",
35
+ options: [
36
+ { label: "Brown", value: "#A52A2A" },
37
+ { label: "Olive", value: "#808000" },
38
+ { label: "Forest Green", value: "#228B22" },
39
+ { label: "Tan", value: "#D2B48C" },
40
+ { label: "Maroon", value: "#800000" }
41
+ ]
42
+ },
43
+ {
44
+ label: "Fun Shades",
45
+ options: [
46
+ { label: "Pink", value: "#FFC0CB" },
47
+ { label: "Magenta", value: "#FF00FF" },
48
+ { label: "Lime", value: "#00FF00" },
49
+ { label: "Purple", value: "#800080" },
50
+ { label: "Indigo", value: "#4B0082" }
51
+ ]
52
+ }
53
+ ]
54
+ %>
55
+
56
+ <%= pb_rails("typeahead", props: {
57
+ default_options:[{ label: "Pink", value: "#FFC0CB" }],
58
+ id: "typeahead-custom-options",
59
+ options: grouped_options,
60
+ label: "Colors",
61
+ name: :foo,
62
+ is_multi: false
63
+ })
64
+ %>
@@ -0,0 +1,70 @@
1
+ import React from 'react'
2
+
3
+ import Typeahead from '../_typeahead'
4
+
5
+ const groupedOptions = [
6
+ {
7
+ label: "Warm Colors",
8
+ options: [
9
+ { label: "Red", value: "#FF0000" },
10
+ { label: "Orange", value: "#FFA500" },
11
+ { label: "Yellow", value: "#FFFF00" },
12
+ { label: "Coral", value: "#FF7F50" },
13
+ { label: "Gold", value: "#FFD700" }
14
+ ]
15
+ },
16
+ {
17
+ label: "Cool Colors",
18
+ options: [
19
+ { label: "Blue", value: "#0000FF" },
20
+ { label: "Teal", value: "#008080" },
21
+ { label: "Cyan", value: "#00FFFF" },
22
+ { label: "Navy", value: "#000080" },
23
+ { label: "Turquoise", value: "#40E0D0" }
24
+ ]
25
+ },
26
+ {
27
+ label: "Neutrals",
28
+ options: [
29
+ { label: "White", value: "#FFFFFF" },
30
+ { label: "Black", value: "#000000" },
31
+ { label: "Gray", value: "#808080" },
32
+ { label: "Beige", value: "#F5F5DC" },
33
+ { label: "Silver", value: "#C0C0C0" }
34
+ ]
35
+ },
36
+ {
37
+ label: "Earth Tones",
38
+ options: [
39
+ { label: "Brown", value: "#A52A2A" },
40
+ { label: "Olive", value: "#808000" },
41
+ { label: "Forest Green", value: "#228B22" },
42
+ { label: "Tan", value: "#D2B48C" },
43
+ { label: "Maroon", value: "#800000" }
44
+ ]
45
+ },
46
+ {
47
+ label: "Fun Shades",
48
+ options: [
49
+ { label: "Pink", value: "#FFC0CB" },
50
+ { label: "Magenta", value: "#FF00FF" },
51
+ { label: "Lime", value: "#00FF00" },
52
+ { label: "Purple", value: "#800080" },
53
+ { label: "Indigo", value: "#4B0082" }
54
+ ]
55
+ }
56
+ ]
57
+
58
+ const TypeaheadCustomOptions = (props) => {
59
+ return (
60
+ <Typeahead
61
+ defaultValue={[{ label: "Pink", value: "#FFC0CB" }]}
62
+ label="Colors"
63
+ options={groupedOptions}
64
+ {...props}
65
+ />
66
+ )
67
+ }
68
+
69
+ export default TypeaheadCustomOptions
70
+
@@ -0,0 +1 @@
1
+ Grouped options can also be achieved with the Typeahead as seen here.
@@ -2,6 +2,7 @@ examples:
2
2
  rails:
3
3
  - typeahead_default: Default
4
4
  - typeahead_default_options: With Default Options
5
+ - typeahead_custom_options: With Grouped Options
5
6
  - typeahead_with_context: With Context
6
7
  - typeahead_with_pills: With Pills
7
8
  - typeahead_without_pills: Without Pills (Single Select)
@@ -21,6 +22,7 @@ examples:
21
22
  react:
22
23
  - typeahead_default: Default
23
24
  - typeahead_default_value: With Default Value
25
+ - typeahead_custom_options: With Grouped Options
24
26
  - typeahead_react_hook: React Hook
25
27
  - typeahead_with_highlight: With Highlight
26
28
  - typeahead_with_pills: With Pills
@@ -16,4 +16,5 @@ 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'
19
+ export { default as TypeaheadDefaultValue } from './_typeahead_default_value.jsx'
20
+ export { default as TypeaheadCustomOptions } from './_typeahead_custom_options.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-esKmpSrF.js";import{c as colors,h as highchartsTheme,m as merge,a as highchartsDarkTheme,t as typography}from"./lib-CGxXTQ75.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--U_6fwUM.js";import{c as colors,h as highchartsTheme,m as merge,a as highchartsDarkTheme,t as typography}from"./lib-CGxXTQ75.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};