playbook_ui 15.2.0.pre.alpha.advancedtableicons11557 → 15.2.0.pre.alpha.buttonfix11269

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (112) hide show
  1. checksums.yaml +4 -4
  2. data/app/pb_kits/playbook/_playbook.scss +6 -4
  3. data/app/pb_kits/playbook/pb_advanced_table/Components/CustomCell.tsx +1 -3
  4. data/app/pb_kits/playbook/pb_advanced_table/advanced_table.html.erb +2 -2
  5. data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_beta.md +1 -3
  6. data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_beta_sort.html.erb +3 -3
  7. data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_beta_subrow_headers.html.erb +3 -3
  8. data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_collapsible_trail_rails.html.erb +2 -2
  9. data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_column_styling.md +1 -1
  10. data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_column_styling_column_headers_rails.html.erb +2 -2
  11. data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_column_styling_rails.html.erb +2 -2
  12. data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_column_styling_rails.md +1 -1
  13. data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_row_styling_rails.md +1 -1
  14. data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_row_styling_react.md +1 -1
  15. data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_selectable_rows_rails.html.erb +2 -2
  16. data/app/pb_kits/playbook/pb_advanced_table/docs/example.yml +0 -3
  17. data/app/pb_kits/playbook/pb_advanced_table/index.js +1 -5
  18. data/app/pb_kits/playbook/pb_advanced_table/table_body.rb +6 -6
  19. data/app/pb_kits/playbook/pb_advanced_table/table_header.rb +6 -6
  20. data/app/pb_kits/playbook/pb_advanced_table/table_row.html.erb +2 -3
  21. data/app/pb_kits/playbook/pb_advanced_table/table_row.rb +5 -49
  22. data/app/pb_kits/playbook/pb_collapsible/__snapshots__/collapsible.test.js.snap +2 -2
  23. data/app/pb_kits/playbook/pb_date_picker/docs/_date_picker_range_pattern.jsx +1 -1
  24. data/app/pb_kits/playbook/pb_draggable/_draggable.scss +0 -8
  25. data/app/pb_kits/playbook/pb_dropdown/index.js +1 -1
  26. data/app/pb_kits/playbook/pb_fixed_confirmation_toast/_fixed_confirmation_toast.scss +1 -0
  27. data/app/pb_kits/playbook/pb_fixed_confirmation_toast/_fixed_confirmation_toast.tsx +3 -5
  28. data/app/pb_kits/playbook/pb_fixed_confirmation_toast/docs/_description.md +0 -2
  29. data/app/pb_kits/playbook/pb_fixed_confirmation_toast/fixed_confirmation_toast.rb +1 -4
  30. data/app/pb_kits/playbook/pb_fixed_confirmation_toast/fixed_confirmation_toast.test.js +0 -10
  31. data/app/pb_kits/playbook/pb_form/docs/_form_form_with_validate.html.erb +1 -1
  32. data/app/pb_kits/playbook/pb_icon/_icon.tsx +2 -1
  33. data/app/pb_kits/playbook/pb_icon/icon.rb +2 -1
  34. data/app/pb_kits/playbook/pb_list/item.html.erb +1 -1
  35. data/app/pb_kits/playbook/pb_pb_bar_graph/_pb_bar_graph.tsx +6 -8
  36. data/app/pb_kits/playbook/pb_pb_bar_graph/pb_bar_graph.rb +10 -7
  37. data/app/pb_kits/playbook/pb_pb_bar_graph/pbbargraph.test.jsx +1 -73
  38. data/app/pb_kits/playbook/pb_pb_circle_chart/_pb_circle_chart.tsx +1 -1
  39. data/app/pb_kits/playbook/pb_pb_circle_chart/pb_circle_chart.rb +10 -7
  40. data/app/pb_kits/playbook/pb_pb_circle_chart/pb_circle_chart.test.jsx +0 -47
  41. data/app/pb_kits/playbook/pb_phone_number_input/_phone_number_input.tsx +22 -105
  42. data/app/pb_kits/playbook/pb_popover/docs/_popover_list.html.erb +2 -2
  43. data/app/pb_kits/playbook/pb_rich_text_editor/TipTap/Toolbar.tsx +2 -41
  44. data/app/pb_kits/playbook/pb_rich_text_editor/TipTap/ToolbarDropdown.tsx +0 -1
  45. data/app/pb_kits/playbook/pb_rich_text_editor/_rich_text_editor.tsx +20 -60
  46. data/app/pb_kits/playbook/pb_rich_text_editor/_tiptap_styles.scss +0 -36
  47. data/app/pb_kits/playbook/pb_rich_text_editor/docs/example.yml +2 -8
  48. data/app/pb_kits/playbook/pb_rich_text_editor/docs/index.js +0 -6
  49. data/app/pb_kits/playbook/pb_rich_text_editor/rich_text_editor.test.js +1 -127
  50. data/app/pb_kits/playbook/pb_selectable_list/selectable_list_item.html.erb +1 -1
  51. data/app/pb_kits/playbook/pb_timeline/_timeline.scss +233 -250
  52. data/app/pb_kits/playbook/pb_timeline/_timeline.tsx +1 -1
  53. data/app/pb_kits/playbook/pb_timeline/timeline.test.js +2 -2
  54. data/app/pb_kits/playbook/tokens/_positioning.scss +0 -1
  55. data/app/pb_kits/playbook/utilities/_positioning.scss +1 -6
  56. data/app/pb_kits/playbook/utilities/globalProps.ts +1 -3
  57. data/dist/chunks/{_line_graph-DtToukzQ.js → _line_graph-BxcVBQsJ.js} +1 -1
  58. data/dist/chunks/_typeahead-eZENQ_Y_.js +6 -0
  59. data/dist/chunks/{_weekday_stacked-DWHza5yt.js → _weekday_stacked-BhPyFGlS.js} +3 -3
  60. data/dist/chunks/vendor.js +1 -1
  61. data/dist/menu.yml +0 -6
  62. data/dist/playbook-doc.js +2 -2
  63. data/dist/playbook-rails-react-bindings.js +1 -1
  64. data/dist/playbook-rails.js +1 -1
  65. data/dist/playbook.css +1 -1
  66. data/lib/playbook/pagination_renderer.rb +2 -2
  67. data/lib/playbook/pb_forms_helper.rb +6 -7
  68. data/lib/playbook/version.rb +1 -1
  69. data/lib/playbook/z_index.rb +1 -1
  70. metadata +5 -46
  71. data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_background_control_rails.html.erb +0 -39
  72. data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_background_control_rails.md +0 -1
  73. data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_padding_control_per_row_rails.html.erb +0 -51
  74. data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_padding_control_per_row_rails.md +0 -1
  75. data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_padding_control_rails.html.erb +0 -40
  76. data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_padding_control_rails.md +0 -1
  77. data/app/pb_kits/playbook/pb_pb_line_graph/_pb_line_graph.scss +0 -3
  78. data/app/pb_kits/playbook/pb_pb_line_graph/_pb_line_graph.tsx +0 -61
  79. data/app/pb_kits/playbook/pb_pb_line_graph/docs/_description.md +0 -3
  80. data/app/pb_kits/playbook/pb_pb_line_graph/docs/_pb_line_graph_colors.html.erb +0 -34
  81. data/app/pb_kits/playbook/pb_pb_line_graph/docs/_pb_line_graph_colors.jsx +0 -52
  82. data/app/pb_kits/playbook/pb_pb_line_graph/docs/_pb_line_graph_colors.md +0 -5
  83. data/app/pb_kits/playbook/pb_pb_line_graph/docs/_pb_line_graph_default.html.erb +0 -34
  84. data/app/pb_kits/playbook/pb_pb_line_graph/docs/_pb_line_graph_default.jsx +0 -45
  85. data/app/pb_kits/playbook/pb_pb_line_graph/docs/_pb_line_graph_height.html.erb +0 -47
  86. data/app/pb_kits/playbook/pb_pb_line_graph/docs/_pb_line_graph_height.jsx +0 -64
  87. data/app/pb_kits/playbook/pb_pb_line_graph/docs/_pb_line_graph_height.md +0 -3
  88. data/app/pb_kits/playbook/pb_pb_line_graph/docs/_pb_line_graph_legend.html.erb +0 -24
  89. data/app/pb_kits/playbook/pb_pb_line_graph/docs/_pb_line_graph_legend.jsx +0 -37
  90. data/app/pb_kits/playbook/pb_pb_line_graph/docs/_pb_line_graph_legend_nonclickable.html.erb +0 -39
  91. data/app/pb_kits/playbook/pb_pb_line_graph/docs/_pb_line_graph_legend_nonclickable.jsx +0 -45
  92. data/app/pb_kits/playbook/pb_pb_line_graph/docs/_pb_line_graph_legend_position.html.erb +0 -86
  93. data/app/pb_kits/playbook/pb_pb_line_graph/docs/_pb_line_graph_legend_position.jsx +0 -116
  94. data/app/pb_kits/playbook/pb_pb_line_graph/docs/_pb_line_graph_legend_position.md +0 -11
  95. data/app/pb_kits/playbook/pb_pb_line_graph/docs/example.yml +0 -20
  96. data/app/pb_kits/playbook/pb_pb_line_graph/docs/index.js +0 -6
  97. data/app/pb_kits/playbook/pb_pb_line_graph/pbLineGraphTheme.ts +0 -125
  98. data/app/pb_kits/playbook/pb_pb_line_graph/pb_line_graph.html.erb +0 -1
  99. data/app/pb_kits/playbook/pb_pb_line_graph/pb_line_graph.rb +0 -25
  100. data/app/pb_kits/playbook/pb_pb_line_graph/pb_line_graph.test.jsx +0 -110
  101. data/app/pb_kits/playbook/pb_rich_text_editor/docs/_rich_text_editor_advanced_attributes.jsx +0 -38
  102. data/app/pb_kits/playbook/pb_rich_text_editor/docs/_rich_text_editor_advanced_attributes.md +0 -1
  103. data/app/pb_kits/playbook/pb_rich_text_editor/docs/_rich_text_editor_advanced_focus.jsx +0 -34
  104. data/app/pb_kits/playbook/pb_rich_text_editor/docs/_rich_text_editor_advanced_focus.md +0 -1
  105. data/app/pb_kits/playbook/pb_rich_text_editor/docs/_rich_text_editor_advanced_inline.jsx +0 -37
  106. data/app/pb_kits/playbook/pb_rich_text_editor/docs/_rich_text_editor_advanced_inline.md +0 -1
  107. data/app/pb_kits/playbook/pb_rich_text_editor/docs/_rich_text_editor_advanced_simple.jsx +0 -37
  108. data/app/pb_kits/playbook/pb_rich_text_editor/docs/_rich_text_editor_advanced_sticky.jsx +0 -38
  109. data/app/pb_kits/playbook/pb_rich_text_editor/docs/_rich_text_editor_advanced_sticky.md +0 -1
  110. data/app/pb_kits/playbook/pb_rich_text_editor/docs/_rich_text_editor_advanced_templates.jsx +0 -69
  111. data/app/pb_kits/playbook/pb_rich_text_editor/docs/_rich_text_editor_advanced_templates.md +0 -1
  112. data/dist/chunks/_typeahead-nqpbB2ym.js +0 -6
@@ -1,6 +1,6 @@
1
1
  import React, { useMemo } from "react"
2
2
  import { globalProps } from "../utilities/globalProps";
3
- import { buildAriaProps, buildDataProps, buildCss, buildHtmlProps } from "../utilities/props";
3
+ import { buildAriaProps, buildDataProps, buildHtmlProps } from "../utilities/props";
4
4
  import Highcharts from "highcharts"
5
5
  import HighchartsReact from "highcharts-react-official"
6
6
 
@@ -18,25 +18,23 @@ type PbBarGraphProps = {
18
18
  htmlOptions?: {[key: string]: string | number | boolean | (() => void)};
19
19
  }
20
20
 
21
- const PbBarGraph = ( props: PbBarGraphProps): React.ReactElement => {
22
- const {
21
+ const PbBarGraph = ({
23
22
  aria = {},
24
23
  data = {},
25
24
  id,
26
25
  htmlOptions = {},
27
26
  options,
28
- className,
29
- } = props
27
+ className = "pb_pb_bar_graph",
28
+ }: PbBarGraphProps): React.ReactElement => {
30
29
 
31
30
  const ariaProps = buildAriaProps(aria);
32
31
  const dataProps = buildDataProps(data)
33
32
  const htmlProps = buildHtmlProps(htmlOptions);
34
- const classes = classnames(buildCss('pb_pb_bar_graph'), globalProps(props), className)
35
33
 
36
34
  const mergedOptions = useMemo(() => {
37
35
  if (!options || typeof options !== "object") {
38
36
  // eslint-disable-next-line no-console
39
- console.error("❌ Invalid options passed to <PbBarGraph />", options)
37
+ console.error("❌ Invalid options passed to <BarGraph />", options)
40
38
  return {}
41
39
  }
42
40
 
@@ -48,7 +46,7 @@ const {
48
46
  <div>
49
47
  <HighchartsReact
50
48
  containerProps={{
51
- className: classnames(classes),
49
+ className: classnames(globalProps, className),
52
50
  id: id,
53
51
  ...ariaProps,
54
52
  ...dataProps,
@@ -4,21 +4,24 @@ module Playbook
4
4
  module PbPbBarGraph
5
5
  class PbBarGraph < ::Playbook::KitBase
6
6
  prop :options, default: {}
7
+ prop :container_props, default: {}
7
8
 
8
9
  def react_props
9
10
  {
10
- className: classname,
11
- data: data,
12
11
  options: options,
13
- id: id,
12
+ containerProps: container_props_hash,
14
13
  }
15
14
  end
16
15
 
16
+ def container_props_hash
17
+ container_props.merge({
18
+ id: id,
19
+ className: classname,
20
+ }).compact
21
+ end
22
+
17
23
  def classname
18
- # Highcharts react needs classname attached to the container div,
19
- # we pass an empty string here to avoid conflicts, classname is built in the TSX
20
- # We still need generate_classnames to retain ability to pass in custom classnames or global props
21
- generate_classname("")
24
+ generate_classname("pb_pb_bar_graph")
22
25
  end
23
26
  end
24
27
  end
@@ -15,41 +15,6 @@ afterEach(() => {
15
15
  console.warn.mockRestore();
16
16
  });
17
17
 
18
- const chartData = [{
19
- name: 'Installation',
20
- data: [1475, 200, 3000, 654, 656],
21
- }, {
22
- name: 'Manufacturing',
23
- data: [4434, 524, 2320, 440, 500],
24
- }, {
25
- name: 'Sales & Distribution',
26
- data: [3387, 743, 1344, 434, 440],
27
- }, {
28
- name: 'Project Development',
29
- data: [3227, 878, 999, 780, 1000],
30
- }, {
31
- name: 'Other',
32
- data: [1111, 677, 3245, 500, 200],
33
- }]
34
-
35
- const chartOptions = {
36
- series: chartData,
37
- title: {
38
- text: 'Solar Employment Growth by Sector, 2010-2016',
39
- },
40
- subtitle: {
41
- text: 'Source: thesolarfoundation.com',
42
- },
43
- xAxis: {
44
- categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May'],
45
- },
46
- yAxis: {
47
- title: {
48
- text: 'Number of Employees',
49
- },
50
- },
51
- }
52
-
53
18
  const testId = 'bargraph1';
54
19
 
55
20
  test('bargraph uses exact classname', () => {
@@ -58,46 +23,9 @@ test('bargraph uses exact classname', () => {
58
23
  className='super_important_class'
59
24
  data={{ testid: testId }}
60
25
  id='bar-default'
61
- options={chartOptions}
62
26
  />
63
27
  );
64
28
 
65
29
  const kit = screen.getByTestId(testId);
66
30
  expect(kit).toHaveClass('super_important_class');
67
- });
68
-
69
- test('Kit to apply base classname', () => {
70
- render(
71
- <PbBarGraph
72
- data={{testid: testId}}
73
- options={chartOptions}
74
- />
75
- )
76
-
77
- expect(screen.getByTestId(testId)).toHaveClass('pb_pb_bar_graph')
78
- })
79
-
80
-
81
- test('Kit to apply global props', () => {
82
- render(
83
- <PbBarGraph
84
- data={{testid: testId}}
85
- margin="lg"
86
- options={chartOptions}
87
- />
88
- )
89
-
90
- expect(screen.getByTestId(testId)).toHaveClass('m_lg')
91
- })
92
-
93
- test('kit to apply id', () => {
94
- render(
95
- <PbBarGraph
96
- data={{testid: testId}}
97
- id='bar-graph-id'
98
- options={chartOptions}
99
- />
100
- )
101
-
102
- expect(screen.getByTestId(testId)).toHaveAttribute('id', 'bar-graph-id')
103
- })
31
+ });
@@ -46,7 +46,7 @@ const PbCircleChart = (props: PbCircleChartProps) => {
46
46
  <div>
47
47
  <HighchartsReact
48
48
  containerProps={{
49
- className: classnames(classes),
49
+ className: classnames(globalProps, className),
50
50
  id: id,
51
51
  ...ariaProps,
52
52
  ...dataProps,
@@ -4,21 +4,24 @@ module Playbook
4
4
  module PbPbCircleChart
5
5
  class PbCircleChart < ::Playbook::KitBase
6
6
  prop :options, default: {}
7
+ prop :container_props, default: {}
7
8
 
8
9
  def react_props
9
10
  {
10
- className: classname,
11
- data: data,
12
11
  options: options,
13
- id: id,
12
+ containerProps: container_props_hash,
14
13
  }
15
14
  end
16
15
 
16
+ def container_props_hash
17
+ container_props.merge({
18
+ id: id,
19
+ className: classname,
20
+ }).compact
21
+ end
22
+
17
23
  def classname
18
- # Highcharts react needs classname attached to the container div,
19
- # we pass an empty string here to avoid conflicts, classname is built in the TSX
20
- # We still need generate_classnames to retain ability to pass in custom classnames or global props
21
- generate_classname("")
24
+ generate_classname("pb_pb_circle_chart")
22
25
  end
23
26
  end
24
27
  end
@@ -49,50 +49,3 @@ test('Kit to exist', () => {
49
49
  expect(screen.getByTestId(testId)).toBeInTheDocument()
50
50
  })
51
51
 
52
- test('Kit to apply base classname', () => {
53
- render(
54
- <PbCircleChart
55
- data={{testid: testId}}
56
- options={chartOptions}
57
- />
58
- )
59
-
60
- expect(screen.getByTestId(testId)).toHaveClass('pb_pb_circle_chart')
61
- })
62
-
63
- test('Kit to have custom class', () => {
64
- render(
65
- <PbCircleChart
66
- className='custom-class'
67
- data={{testid: testId}}
68
- options={chartOptions}
69
- />
70
- )
71
-
72
- expect(screen.getByTestId(testId)).toHaveClass('custom-class')
73
- })
74
-
75
- test('Kit to apply global props', () => {
76
- render(
77
- <PbCircleChart
78
- data={{testid: testId}}
79
- margin="lg"
80
- options={chartOptions}
81
- />
82
- )
83
-
84
- expect(screen.getByTestId(testId)).toHaveClass('m_lg')
85
- })
86
-
87
- test('kit to apply id', () => {
88
- render(
89
- <PbCircleChart
90
- data={{testid: testId}}
91
- id='circle-chart-id'
92
- options={chartOptions}
93
- />
94
- )
95
-
96
- expect(screen.getByTestId(testId)).toHaveAttribute('id', 'circle-chart-id')
97
- })
98
-
@@ -111,7 +111,7 @@ const PhoneNumberInput = (props: PhoneNumberInputProps, ref?: React.Ref<unknown>
111
111
  const inputRef = useRef<HTMLInputElement | null>(null)
112
112
  const itiRef = useRef<any>(null);
113
113
  const [inputValue, setInputValue] = useState(value)
114
- const [error, setError] = useState(props.error || "")
114
+ const [error, setError] = useState(props.error)
115
115
  const [dropDownIsOpen, setDropDownIsOpen] = useState(false)
116
116
  const [selectedData, setSelectedData] = useState()
117
117
  const [hasTyped, setHasTyped] = useState(false)
@@ -124,6 +124,24 @@ const PhoneNumberInput = (props: PhoneNumberInputProps, ref?: React.Ref<unknown>
124
124
  }
125
125
  }, [error, onValidate])
126
126
 
127
+ /*
128
+ useImperativeHandle exposes the kit's input element to a parent component via a ref.
129
+ See the Playbook docs for use cases.
130
+ Read: https://react.dev/reference/react/useImperativeHandle
131
+ */
132
+ useImperativeHandle(ref, () => {
133
+ return {
134
+ clearField() {
135
+ setInputValue("")
136
+ setError("")
137
+ setHasTyped(false)
138
+ },
139
+ inputNode() {
140
+ return inputRef.current
141
+ }
142
+ }
143
+ })
144
+
127
145
  const unformatNumber = (formattedNumber: any) => {
128
146
  return formattedNumber.replace(/\D/g, "")
129
147
  }
@@ -146,13 +164,6 @@ const PhoneNumberInput = (props: PhoneNumberInputProps, ref?: React.Ref<unknown>
146
164
 
147
165
  const validateTooShortNumber = (itiInit: any) => {
148
166
  if (!itiInit) return
149
-
150
- // If field is empty, don't show "too short" error
151
- if (!inputValue || inputValue.trim() === '') {
152
- setError('')
153
- return false
154
- }
155
-
156
167
  if (itiInit.getValidationError() === ValidationError.TooShort) {
157
168
  return showFormattedError('too short')
158
169
  } else {
@@ -172,7 +183,7 @@ const PhoneNumberInput = (props: PhoneNumberInputProps, ref?: React.Ref<unknown>
172
183
  }
173
184
 
174
185
  const validateUnhandledError = (itiInit: any) => {
175
- if (!itiInit) return
186
+ if (!required || !itiInit) return
176
187
  if (itiInit.getValidationError() === ValidationError.SomethingWentWrong) {
177
188
  if (inputValue.length === 1) {
178
189
  return showFormattedError('too short')
@@ -195,27 +206,14 @@ const PhoneNumberInput = (props: PhoneNumberInputProps, ref?: React.Ref<unknown>
195
206
 
196
207
  const validateRepeatCountryCode = (itiInit: any) => {
197
208
  if (!itiInit) return
198
- const countryDialCode = itiRef.current.getSelectedCountryData().dialCode;
209
+ const countryDialCode = itiInit.getSelectedCountryData().dialCode;
199
210
  if (unformatNumber(inputValue).startsWith(countryDialCode)) {
200
211
  return showFormattedError('repeat country code')
201
212
  }
202
213
  }
203
214
 
204
- const validateRequiredField = () => {
205
- if (!inputValue || inputValue.trim() === '') {
206
- setError('Missing phone number')
207
- return true
208
- }
209
- return false
210
- }
211
215
 
212
216
  const validateErrors = () => {
213
- // If field is empty, show error message
214
- if (!inputValue || inputValue.trim() === '') {
215
- if (validateRequiredField()) return
216
- return
217
- }
218
-
219
217
  if (!hasTyped && !error) return
220
218
 
221
219
  if (itiRef.current) isValid(itiRef.current.isValidNumber())
@@ -227,87 +225,6 @@ const PhoneNumberInput = (props: PhoneNumberInputProps, ref?: React.Ref<unknown>
227
225
  if (validateRepeatCountryCode(itiRef.current)) return
228
226
  }
229
227
 
230
- /*
231
- useImperativeHandle exposes the kit's input element to a parent component via a ref.
232
- See the Playbook docs for use cases.
233
- Read: https://react.dev/reference/react/useImperativeHandle
234
- */
235
- useImperativeHandle(ref, () => {
236
- return {
237
- clearField() {
238
- setInputValue("")
239
- setError("")
240
- setHasTyped(false)
241
- },
242
- inputNode() {
243
- return inputRef.current
244
- },
245
- // Expose validation method for React Hook Form
246
- validate() {
247
- // Run validation and return error message or true
248
- const isEmpty = !inputValue || inputValue.trim() === ''
249
-
250
- if (isEmpty) {
251
- // Show missing phone number error
252
- const errorMessage = 'Missing phone number'
253
- setError(errorMessage)
254
- setHasTyped(true)
255
- // Only return error for React Hook Form if field is required
256
- return required ? errorMessage : true
257
- }
258
-
259
- if (!itiRef.current) {
260
- return true
261
- }
262
-
263
- // Check for repeat country code first
264
- const countryDialCode = itiRef.current.getSelectedCountryData().dialCode;
265
- if (unformatNumber(inputValue).startsWith(countryDialCode)) {
266
- const countryName = itiRef.current.getSelectedCountryData().name
267
- const errorMessage = `Invalid ${countryName} phone number (repeat country code)`
268
- setError(errorMessage)
269
- setHasTyped(true)
270
- return errorMessage
271
- }
272
-
273
- // Check if it only contains valid characters
274
- if (!containOnlyNumbers(inputValue)) {
275
- const countryName = itiRef.current.getSelectedCountryData().name
276
- const errorMessage = `Invalid ${countryName} phone number (enter numbers only)`
277
- setError(errorMessage)
278
- setHasTyped(true)
279
- return errorMessage
280
- }
281
-
282
- // Check if valid number
283
- if (!itiRef.current.isValidNumber()) {
284
- const countryName = itiRef.current.getSelectedCountryData().name
285
- const validationError = itiRef.current.getValidationError()
286
- let errorMessage = ''
287
-
288
- if (validationError === ValidationError.TooShort) {
289
- errorMessage = `Invalid ${countryName} phone number (too short)`
290
- } else if (validationError === ValidationError.TooLong) {
291
- errorMessage = `Invalid ${countryName} phone number (too long)`
292
- } else if (validationError === ValidationError.MissingAreaCode) {
293
- errorMessage = `Invalid ${countryName} phone number (missing area code)`
294
- } else {
295
- errorMessage = `Invalid ${countryName} phone number`
296
- }
297
-
298
- setError(errorMessage)
299
- setHasTyped(true)
300
-
301
- return errorMessage
302
- }
303
-
304
- // Clear error if valid
305
- setError('')
306
- return true
307
- }
308
- }
309
- })
310
-
311
228
  const getCurrentSelectedData = (itiInit: any, inputValue: string) => {
312
229
  return { ...itiInit.getSelectedCountryData(), number: inputValue }
313
230
  }
@@ -383,7 +300,7 @@ const PhoneNumberInput = (props: PhoneNumberInputProps, ref?: React.Ref<unknown>
383
300
  dark,
384
301
  "data-phone-number": JSON.stringify(selectedData),
385
302
  disabled,
386
- error: hasTyped ? error : props.error,
303
+ error,
387
304
  type: 'tel',
388
305
  id,
389
306
  label,
@@ -28,9 +28,9 @@
28
28
  popoverButton.onclick = () => {
29
29
  buttonClicked = !buttonClicked
30
30
  if (buttonClicked) {
31
- arrowDiv.innerHTML = '<svg xmlns="http://www.w3.org/2000/svg" width="1.5em" viewBox="0 0 31 25" fill="none" class="pb_custom_icon svg-inline--fa pb_icon_kit svg_fw" id="" data="{}" aria="{}" tabindex=""><path d="M14.2031 5.70312C14.625 5.28125 15.3281 5.28125 15.75 5.70312L24.7969 14.7031C25.2188 15.1719 25.2188 15.875 24.7969 16.2969C24.3281 16.7656 23.625 16.7656 23.2031 16.2969L15 8.09375L6.79688 16.2969C6.32812 16.7656 5.625 16.7656 5.20312 16.2969C4.73438 15.875 4.73438 15.1719 5.20312 14.75L14.2031 5.70312Z" fill="currentColor"/></svg>'
31
+ arrowDiv.innerHTML = '<svg xmlns="http://www.w3.org/2000/svg" width="auto" height="auto" viewBox="0 0 31 25" fill="none" class="pb_custom_icon svg-inline--fa pb_icon_kit svg_fw" id="" data="{}" aria="{}" tabindex=""><path d="M14.2031 5.70312C14.625 5.28125 15.3281 5.28125 15.75 5.70312L24.7969 14.7031C25.2188 15.1719 25.2188 15.875 24.7969 16.2969C24.3281 16.7656 23.625 16.7656 23.2031 16.2969L15 8.09375L6.79688 16.2969C6.32812 16.7656 5.625 16.7656 5.20312 16.2969C4.73438 15.875 4.73438 15.1719 5.20312 14.75L14.2031 5.70312Z" fill="currentColor"/></svg>'
32
32
  } else {
33
- arrowDiv.innerHTML = '<svg xmlns="http://www.w3.org/2000/svg" width="1.5em" viewBox="0 0 31 25" fill="none" class="pb_custom_icon svg-inline--fa pb_icon_kit svg_fw" id="" data="{}" aria="{}" tabindex=""><path d="M14.2031 19.2969L5.20312 10.2969C4.73438 9.875 4.73438 9.17188 5.20312 8.70312C5.625 8.28125 6.32812 8.28125 6.79688 8.70312L15 16.9531L23.2031 8.75C23.625 8.28125 24.3281 8.28125 24.7969 8.75C25.2188 9.17188 25.2188 9.875 24.7969 10.2969L15.75 19.2969C15.3281 19.7656 14.625 19.7656 14.2031 19.2969Z" fill="currentColor"/></svg>'
33
+ arrowDiv.innerHTML = '<svg xmlns="http://www.w3.org/2000/svg" width="auto" height="auto" viewBox="0 0 31 25" fill="none" class="pb_custom_icon svg-inline--fa pb_icon_kit svg_fw" id="" data="{}" aria="{}" tabindex=""><path d="M14.2031 19.2969L5.20312 10.2969C4.73438 9.875 4.73438 9.17188 5.20312 8.70312C5.625 8.28125 6.32812 8.28125 6.79688 8.70312L15 16.9531L23.2031 8.75C23.625 8.28125 24.3281 8.28125 24.7969 8.75C25.2188 9.17188 25.2188 9.875 24.7969 10.2969L15.75 19.2969C15.3281 19.7656 14.625 19.7656 14.2031 19.2969Z" fill="currentColor"/></svg>'
34
34
  }
35
35
  }
36
36
  </script>
@@ -11,7 +11,7 @@ import { ToolbarTypes } from "./EditorTypes";
11
11
  import ToolbarHistoryItems from "./ToolbarHistory";
12
12
  import MoreExtensionsDropdown from "./MoreExtensionsDropdown";
13
13
 
14
- const EditorToolbar = ({ editor, extensions, simple, sticky }: any): React.ReactElement => {
14
+ const EditorToolbar = ({ editor, extensions }: any): React.ReactElement => {
15
15
  const toolbaritems = [
16
16
  {
17
17
  icon: "bold",
@@ -33,50 +33,15 @@ const EditorToolbar = ({ editor, extensions, simple, sticky }: any): React.React
33
33
  },
34
34
  ]
35
35
 
36
- const simpleToolbaritems = [
37
- {
38
- icon: "bold",
39
- text: "Bold",
40
- classname:`toolbar_button ${editor.isActive('bold') ? 'is-active' : ''}`,
41
- onclick:()=>editor.chain().focus().toggleBold().run(),
42
- },
43
- {
44
- icon: "italic",
45
- text: "Italic",
46
- classname:`toolbar_button ${editor.isActive('italic') ? 'is-active' : ''}`,
47
- onclick:() => editor.chain().focus().toggleItalic().run(),
48
- },
49
- ]
50
-
51
36
  return (
52
37
  <Background backgroundColor="white"
53
- className={`toolbar ${sticky ? 'pb_rich_text_editor_tiptap_toolbar_sticky' : ''}`}
54
-
38
+ className="toolbar"
55
39
  >
56
40
  <Flex flex="0"
57
41
  justify="between"
58
42
  paddingX="sm"
59
43
  paddingY="xxs"
60
44
  >
61
- {
62
- simple ? (
63
- <>
64
- <Flex className="toolbar_block">
65
- {simpleToolbaritems && simpleToolbaritems.map(
66
- ({ icon, text, classname, onclick}: ToolbarTypes, index: number) => (
67
- <EditorButton
68
- classname={classname}
69
- icon={icon}
70
- key={index}
71
- onclick={onclick}
72
- text={text}
73
- />
74
- )
75
- )}
76
- </Flex>
77
- </>
78
- ) : (
79
- <>
80
45
  <FlexItem className="toolbar_block"
81
46
  displayFlex
82
47
  >
@@ -104,10 +69,6 @@ const EditorToolbar = ({ editor, extensions, simple, sticky }: any): React.React
104
69
  }
105
70
  </FlexItem>
106
71
  <ToolbarHistoryItems editor={editor} />
107
- </>
108
- )
109
- }
110
-
111
72
  </Flex>
112
73
  </Background>
113
74
  );
@@ -146,7 +146,6 @@ const popoverReference = (
146
146
 
147
147
  return (
148
148
  <PbReactPopover
149
- className='pb_tiptap_toolbar_dropdown_popover'
150
149
  closeOnClick='outside'
151
150
  padding='none'
152
151
  placement="bottom"
@@ -1,4 +1,4 @@
1
- import React, { useEffect, useState, useRef } from 'react'
1
+ import React, { useEffect, useState } from 'react'
2
2
  import classnames from 'classnames'
3
3
  import { TrixEditor } from 'react-trix'
4
4
 
@@ -77,9 +77,7 @@ const RichTextEditor = (props: RichTextEditorProps): React.ReactElement => {
77
77
 
78
78
  const ariaProps = buildAriaProps(aria),
79
79
  dataProps = buildDataProps(data),
80
- [editor, setEditor] = useState<Editor>(),
81
- [showToolbarOnFocus, setShowToolbarOnFocus] = useState(false),
82
- containerRef = useRef<HTMLDivElement>(null)
80
+ [editor, setEditor] = useState<Editor>()
83
81
 
84
82
  const htmlProps = buildHtmlProps(htmlOptions)
85
83
 
@@ -130,42 +128,6 @@ const RichTextEditor = (props: RichTextEditorProps): React.ReactElement => {
130
128
  document.addEventListener('trix-blur', inlineFocus)
131
129
  }
132
130
 
133
- //===========focus prop with advanced editor=================
134
- const isClickInPopover = (event: Event): boolean => {
135
- return !!(event.target as Element).closest('.pb_tiptap_toolbar_dropdown_popover')
136
- }
137
-
138
- const isClickInContainer = (event: Event): boolean => {
139
- return !!(containerRef.current && containerRef.current.contains(event.target as Node))
140
- }
141
-
142
- useEffect(() => {
143
- if (!advancedEditor || !focus) return
144
-
145
- const handleFocus = () => setShowToolbarOnFocus(true)
146
-
147
- const handleClickOutside = (event: Event) => {
148
- if (isClickInContainer(event) || isClickInPopover(event)) return
149
- setShowToolbarOnFocus(false)
150
- }
151
-
152
- const editorElement = advancedEditor?.view?.dom
153
- if (editorElement) {
154
- editorElement.addEventListener('focus', handleFocus)
155
- }
156
-
157
- document.addEventListener('mousedown', handleClickOutside)
158
-
159
- return () => {
160
- if (editorElement) {
161
- editorElement.removeEventListener('focus', handleFocus)
162
- }
163
- document.removeEventListener('mousedown', handleClickOutside)
164
- }
165
- }, [advancedEditor, focus])
166
-
167
- //============= end focus prop with advanced editor=================
168
-
169
131
  useEffect(() => {
170
132
  if (!editor || !template) return
171
133
  editor.loadHTML('')
@@ -186,43 +148,41 @@ const RichTextEditor = (props: RichTextEditorProps): React.ReactElement => {
186
148
  })
187
149
  }, [editor])
188
150
 
189
- // Generate CSS classes
190
- const css = classnames(
191
- 'pb_rich_text_editor_kit',
192
- {
193
- simple: simple,
194
- 'focus-editor-targets': focus,
195
- sticky: sticky,
196
- inline: inline,
197
- 'toolbar-bottom': toolbarBottom,
198
- },
199
- globalProps(props, { maxWidth }),
200
- className
151
+ const richTextEditorClass = 'pb_rich_text_editor_kit',
152
+ simpleClass = simple ? 'simple' : '',
153
+ focusClass = focus ? 'focus-editor-targets' : '',
154
+ stickyClass = sticky ? 'sticky' : '',
155
+ inlineClass = inline ? 'inline' : '',
156
+ toolbarBottomClass = toolbarBottom ? 'toolbar-bottom' : ''
157
+
158
+ let css = classnames(globalProps(props, { maxWidth }), className)
159
+ css = classnames(
160
+ richTextEditorClass,
161
+ simpleClass,
162
+ focusClass,
163
+ stickyClass,
164
+ inlineClass,
165
+ toolbarBottomClass,
166
+ css
201
167
  )
202
168
 
203
- // Determine if toolbar should be shown
204
- const shouldShowToolbar = focus && advancedEditor ? showToolbarOnFocus : advancedEditorToolbar
205
-
206
169
  return (
207
170
  <div
208
171
  {...ariaProps}
209
172
  {...dataProps}
210
173
  {...htmlProps}
211
174
  className={css}
212
- ref={focus ? containerRef : undefined}
213
175
  >
214
176
  {
215
177
  advancedEditor ? (
216
178
  <div
217
179
  className={classnames("pb_rich_text_editor_advanced_container", {
218
- ["toolbar-active"]: shouldShowToolbar,
180
+ ["toolbar-active"]: advancedEditorToolbar,
219
181
  })}
220
182
  >
221
- {shouldShowToolbar && (
183
+ {advancedEditorToolbar && (
222
184
  <EditorToolbar editor={advancedEditor}
223
185
  extensions={extensions}
224
- simple={simple}
225
- sticky={sticky}
226
186
  />
227
187
  )}
228
188
  { children }