playbook_ui 15.7.0 → 15.8.0.pre.rc.1

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 (103) hide show
  1. checksums.yaml +4 -4
  2. data/app/pb_kits/playbook/_playbook.scss +1 -1
  3. data/app/pb_kits/playbook/pb_dropdown/_dropdown.tsx +13 -1
  4. data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_quickpick_custom.jsx +56 -0
  5. data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_quickpick_custom.md +10 -0
  6. data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_quickpick_custom_rails.html.erb +64 -0
  7. data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_quickpick_custom_rails.md +10 -0
  8. data/app/pb_kits/playbook/pb_dropdown/docs/example.yml +2 -0
  9. data/app/pb_kits/playbook/pb_dropdown/docs/index.js +2 -1
  10. data/app/pb_kits/playbook/pb_dropdown/dropdown.rb +6 -1
  11. data/app/pb_kits/playbook/pb_dropdown/dropdown.test.jsx +121 -0
  12. data/app/pb_kits/playbook/pb_dropdown/quickpick/index.ts +85 -9
  13. data/app/pb_kits/playbook/pb_dropdown/quickpick_helper.rb +83 -2
  14. data/app/pb_kits/playbook/pb_fixed_confirmation_toast/fixed_confirmation_toast.rb +9 -7
  15. data/app/pb_kits/playbook/pb_fixed_confirmation_toast/index.js +3 -8
  16. data/app/pb_kits/playbook/pb_form/docs/_form_form_with.html.erb +1 -1
  17. data/app/pb_kits/playbook/pb_form/docs/_form_form_with_validate.html.erb +2 -1
  18. data/app/pb_kits/playbook/pb_form/docs/_form_with_required_indicator.html.erb +14 -0
  19. data/app/pb_kits/playbook/pb_form/docs/_form_with_required_indicator.md +3 -0
  20. data/app/pb_kits/playbook/pb_form/docs/example.yml +1 -0
  21. data/app/pb_kits/playbook/pb_popover/docs/_popover_append_to.html.erb +2 -2
  22. data/app/pb_kits/playbook/pb_popover/docs/_popover_append_to.jsx +3 -2
  23. data/app/pb_kits/playbook/pb_rich_text_editor/TipTap/Toolbar.tsx +1 -1
  24. data/app/pb_kits/playbook/pb_rich_text_editor/_rich_text_editor.tsx +8 -3
  25. data/app/pb_kits/playbook/pb_rich_text_editor/_tiptap_styles.scss +53 -0
  26. data/app/pb_kits/playbook/pb_rich_text_editor/docs/_rich_text_editor_advanced_height.jsx +71 -0
  27. data/app/pb_kits/playbook/pb_rich_text_editor/docs/_rich_text_editor_advanced_height.md +1 -0
  28. data/app/pb_kits/playbook/pb_rich_text_editor/docs/_rich_text_editor_advanced_min_height.jsx +71 -0
  29. data/app/pb_kits/playbook/pb_rich_text_editor/docs/_rich_text_editor_advanced_min_height.md +1 -0
  30. data/app/pb_kits/playbook/pb_rich_text_editor/docs/example.yml +2 -0
  31. data/app/pb_kits/playbook/pb_rich_text_editor/docs/index.js +3 -1
  32. data/app/pb_kits/playbook/pb_text_input/_text_input.tsx +56 -6
  33. data/app/pb_kits/playbook/pb_text_input/docs/_text_input_emoji_mask.html.erb +7 -0
  34. data/app/pb_kits/playbook/pb_text_input/docs/_text_input_emoji_mask.jsx +24 -0
  35. data/app/pb_kits/playbook/pb_text_input/docs/_text_input_emoji_mask.md +2 -0
  36. data/app/pb_kits/playbook/pb_text_input/docs/_text_input_required_indicator.html.erb +6 -0
  37. data/app/pb_kits/playbook/pb_text_input/docs/_text_input_required_indicator.jsx +25 -0
  38. data/app/pb_kits/playbook/pb_text_input/docs/_text_input_required_indicator.md +3 -0
  39. data/app/pb_kits/playbook/pb_text_input/docs/example.yml +5 -0
  40. data/app/pb_kits/playbook/pb_text_input/docs/index.js +2 -0
  41. data/app/pb_kits/playbook/pb_text_input/index.js +49 -8
  42. data/app/pb_kits/playbook/pb_text_input/text_input.html.erb +6 -0
  43. data/app/pb_kits/playbook/pb_text_input/text_input.rb +7 -1
  44. data/app/pb_kits/playbook/pb_text_input/text_input.test.js +69 -0
  45. data/app/pb_kits/playbook/pb_textarea/_textarea.tsx +38 -2
  46. data/app/pb_kits/playbook/pb_textarea/docs/_textarea_emoji_mask.html.erb +5 -0
  47. data/app/pb_kits/playbook/pb_textarea/docs/_textarea_emoji_mask.jsx +24 -0
  48. data/app/pb_kits/playbook/pb_textarea/docs/_textarea_emoji_mask.md +1 -0
  49. data/app/pb_kits/playbook/pb_textarea/docs/example.yml +2 -0
  50. data/app/pb_kits/playbook/pb_textarea/docs/index.js +1 -0
  51. data/app/pb_kits/playbook/pb_textarea/index.ts +62 -5
  52. data/app/pb_kits/playbook/pb_textarea/textarea.html.erb +1 -0
  53. data/app/pb_kits/playbook/pb_textarea/textarea.rb +8 -0
  54. data/app/pb_kits/playbook/pb_textarea/textarea.test.js +57 -2
  55. data/app/pb_kits/playbook/pb_time_picker/_time_picker.scss +296 -0
  56. data/app/pb_kits/playbook/pb_time_picker/_time_picker.tsx +822 -0
  57. data/app/pb_kits/playbook/pb_time_picker/docs/_time_picker_24_hour.html.erb +2 -0
  58. data/app/pb_kits/playbook/pb_time_picker/docs/_time_picker_24_hour.jsx +16 -0
  59. data/app/pb_kits/playbook/pb_time_picker/docs/_time_picker_24_hour.md +1 -0
  60. data/app/pb_kits/playbook/pb_time_picker/docs/_time_picker_default.html.erb +1 -0
  61. data/app/pb_kits/playbook/pb_time_picker/docs/_time_picker_default.jsx +13 -0
  62. data/app/pb_kits/playbook/pb_time_picker/docs/_time_picker_default.md +1 -0
  63. data/app/pb_kits/playbook/pb_time_picker/docs/_time_picker_default_time.html.erb +4 -0
  64. data/app/pb_kits/playbook/pb_time_picker/docs/_time_picker_default_time.jsx +29 -0
  65. data/app/pb_kits/playbook/pb_time_picker/docs/_time_picker_default_time.md +1 -0
  66. data/app/pb_kits/playbook/pb_time_picker/docs/_time_picker_disabled.html.erb +13 -0
  67. data/app/pb_kits/playbook/pb_time_picker/docs/_time_picker_disabled.jsx +23 -0
  68. data/app/pb_kits/playbook/pb_time_picker/docs/_time_picker_error.html.erb +5 -0
  69. data/app/pb_kits/playbook/pb_time_picker/docs/_time_picker_error.jsx +15 -0
  70. data/app/pb_kits/playbook/pb_time_picker/docs/_time_picker_input_options.html.erb +14 -0
  71. data/app/pb_kits/playbook/pb_time_picker/docs/_time_picker_label.html.erb +2 -0
  72. data/app/pb_kits/playbook/pb_time_picker/docs/_time_picker_label.jsx +15 -0
  73. data/app/pb_kits/playbook/pb_time_picker/docs/_time_picker_min_max_time.html.erb +42 -0
  74. data/app/pb_kits/playbook/pb_time_picker/docs/_time_picker_min_max_time.jsx +52 -0
  75. data/app/pb_kits/playbook/pb_time_picker/docs/_time_picker_min_max_time.md +1 -0
  76. data/app/pb_kits/playbook/pb_time_picker/docs/_time_picker_on_handler.jsx +45 -0
  77. data/app/pb_kits/playbook/pb_time_picker/docs/_time_picker_on_handler.md +1 -0
  78. data/app/pb_kits/playbook/pb_time_picker/docs/_time_picker_timezone.html.erb +3 -0
  79. data/app/pb_kits/playbook/pb_time_picker/docs/_time_picker_timezone.jsx +21 -0
  80. data/app/pb_kits/playbook/pb_time_picker/docs/_time_picker_timezone.md +1 -0
  81. data/app/pb_kits/playbook/pb_time_picker/docs/example.yml +24 -0
  82. data/app/pb_kits/playbook/pb_time_picker/docs/index.js +9 -0
  83. data/app/pb_kits/playbook/pb_time_picker/index.ts +40 -0
  84. data/app/pb_kits/playbook/pb_time_picker/time_picker.html.erb +1 -0
  85. data/app/pb_kits/playbook/pb_time_picker/time_picker.rb +80 -0
  86. data/app/pb_kits/playbook/pb_time_picker/time_picker.test.jsx +114 -0
  87. data/app/pb_kits/playbook/pb_time_picker/time_picker_helper.ts +662 -0
  88. data/app/pb_kits/playbook/utilities/emojiMask.ts +42 -0
  89. data/app/pb_kits/playbook/utilities/globalProps.ts +1 -0
  90. data/dist/chunks/_typeahead-D0GNUBXn.js +6 -0
  91. data/dist/chunks/lib-DxCgrqqG.js +29 -0
  92. data/dist/chunks/vendor.js +3 -3
  93. data/dist/menu.yml +7 -0
  94. data/dist/playbook-rails-react-bindings.js +1 -1
  95. data/dist/playbook-rails.js +1 -1
  96. data/dist/playbook.css +1 -1
  97. data/lib/playbook/forms/builder/form_field_builder.rb +15 -2
  98. data/lib/playbook/forms/builder/time_picker_field.rb +24 -0
  99. data/lib/playbook/forms/builder.rb +1 -0
  100. data/lib/playbook/version.rb +2 -2
  101. metadata +58 -4
  102. data/dist/chunks/_typeahead-X3EqK1nR.js +0 -6
  103. data/dist/chunks/lib-BHYZzndy.js +0 -29
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 71dc76821c0c875363dbf67c1969a0f24eb0c5ea2fdb791b70c0d95a6732a3d5
4
- data.tar.gz: d95d190f3644e074b60828cf363fb37d99338050a29b4ab847ebe5bf99fe55f3
3
+ metadata.gz: d0177497af81bb89af7b26046f27197942cb10b7a6640df32234376c1f7cedcb
4
+ data.tar.gz: 164f59f14bfffc0a889b4859363c311d09dafddf5c1fce518000a42c4e647623
5
5
  SHA512:
6
- metadata.gz: 4ea3c249a93b41caa33133053b9fccb280d01b539c4bc61516e7a231174ef7cb879d35d756bb4fea03f4e5d35d7f52d39b593a49a7b0374f509a724a27fc86d3
7
- data.tar.gz: aed75a53ce523d6736b2e8ab00986472f1068f7c2f8e1f5c50194d10003ccccc1e31320a2d45fa59da4e31b6539c84a9d768112f6cf541274cac96dda9468347
6
+ metadata.gz: 6c3ead358396ac6c1adf2c5a2a5af3409513bfc0a944fa7298d74135b66ea59f865e30a51167b6f81247967b5ac2be7326aa5717d5b3d0c2993a2a2a96831d48
7
+ data.tar.gz: 4a5d41bdcc5e01b9dc0a3ffbaba5292702873902e5325dfeba5759e54049e03c95ce6ba760a0c0e8b1c9bd35c0ca6958bbec137fe7a33da7d978148cc6bc5b2f
@@ -1,4 +1,3 @@
1
-
2
1
  @import 'pb_advanced_table/advanced_table';
3
2
  @import 'pb_avatar/avatar';
4
3
  @import 'pb_background/background';
@@ -98,6 +97,7 @@
98
97
  @import 'pb_text_input/text_input';
99
98
  @import 'pb_textarea/textarea';
100
99
  @import 'pb_time/time';
100
+ @import 'pb_time_picker/time_picker';
101
101
  @import 'pb_time_range_inline/time_range_inline';
102
102
  @import 'pb_time_stacked/time_stacked';
103
103
  @import 'pb_timeline/timeline';
@@ -20,12 +20,23 @@ import {
20
20
  handleClickOutside,
21
21
  } from "./utilities";
22
22
 
23
+ type CustomQuickPickDate = {
24
+ label: string;
25
+ value: string[] | { timePeriod: string; amount: number };
26
+ };
27
+
28
+ type CustomQuickPickDates = {
29
+ override?: boolean;
30
+ dates: CustomQuickPickDate[];
31
+ };
32
+
23
33
  type DropdownProps = {
24
34
  aria?: { [key: string]: string };
25
35
  autocomplete?: boolean;
26
36
  blankSelection?: string;
27
37
  children?: React.ReactChild[] | React.ReactChild | React.ReactElement[];
28
38
  className?: string;
39
+ customQuickPickDates?: CustomQuickPickDates;
29
40
  formPillProps?: GenericObject;
30
41
  dark?: boolean;
31
42
  data?: { [key: string]: string };
@@ -63,6 +74,7 @@ let Dropdown = (props: DropdownProps, ref: any): React.ReactElement | null => {
63
74
  blankSelection = '',
64
75
  children,
65
76
  className,
77
+ customQuickPickDates,
66
78
  dark = false,
67
79
  data = {},
68
80
  defaultValue = {},
@@ -95,7 +107,7 @@ let Dropdown = (props: DropdownProps, ref: any): React.ReactElement | null => {
95
107
  // ------------- Quick Pick ---------------------------------
96
108
  // Use QuickPick options when variant is "quickpick"
97
109
  const dropdownOptions = variant === "quickpick"
98
- ? getQuickPickOptions(rangeEndsToday)
110
+ ? getQuickPickOptions(rangeEndsToday, customQuickPickDates)
99
111
  : (options || []);
100
112
  // ----------------------------------------------------------
101
113
 
@@ -0,0 +1,56 @@
1
+ import React from "react"
2
+ import Dropdown from "../_dropdown"
3
+
4
+ const DropdownQuickpickCustom = (props) => (
5
+ <div>
6
+ <Dropdown
7
+ customQuickPickDates={{
8
+ dates: [
9
+ // Allow Playbook to handle the logic...
10
+ {
11
+ label: "Last 15 months",
12
+ value: {
13
+ timePeriod: "months",
14
+ amount: 15,
15
+ },
16
+ },
17
+ // Or, be explicit with an exact date range for more control...
18
+ {
19
+ label: "First Week of June 2022",
20
+ value: ["06/01/2022", "06/07/2022"],
21
+ },
22
+ ],
23
+ }}
24
+ label="Date Range"
25
+ marginBottom="sm"
26
+ onSelect={(selectedItem) => console.log(selectedItem)}
27
+ variant="quickpick"
28
+ {...props}
29
+ />
30
+ <Dropdown
31
+ customQuickPickDates={{
32
+ dates: [
33
+ {
34
+ label: "Last 15 months",
35
+ value: {
36
+ timePeriod: "months",
37
+ amount: 15,
38
+ },
39
+ },
40
+ {
41
+ label: "First Week of June 2022",
42
+ value: ["06/01/2022", "06/07/2022"],
43
+ },
44
+ ],
45
+ override: false,
46
+ }}
47
+ label="Date Range - Append to Defaults"
48
+ onSelect={(selectedItem) => console.log(selectedItem)}
49
+ variant="quickpick"
50
+ {...props}
51
+ />
52
+ </div>
53
+ )
54
+
55
+ export default DropdownQuickpickCustom
56
+
@@ -0,0 +1,10 @@
1
+ The `customQuickPickDates` prop allows for defining custom quick pick date options for the dropdown. The prop accepts an object with two properties: `dates` and `override`.
2
+
3
+ **The `dates` property** accepts an array of objects. Each object has `label` and `value` properties. The `label` is what will be displayed in the dropdown menu. The `value` property defines the date range that will be selected, and can be:
4
+ - An array of two date strings representing a specific range (e.g., `["06/01/2022", "06/07/2022"]`)
5
+ - An object with `timePeriod` and `amount` properties for dynamic date calculations:
6
+ - The `timePeriod` property accepts `"days"`, `"weeks"`, `"months"`, `"quarters"`, or `"years"`, representing past time periods calculated from today.
7
+ - The `amount` property accepts any number.
8
+
9
+ **The `override` property** is a boolean that controls whether custom dates replace or append to the default quick pick options. Default is `true` (replaces defaults). Set to `false` to append your custom dates to the default quick pick options.
10
+
@@ -0,0 +1,64 @@
1
+ <%= pb_rails("dropdown", props: {
2
+ custom_quick_pick_dates: {
3
+ dates: [
4
+ # Allow Playbook to handle the logic...
5
+ {
6
+ label: "Last 15 months",
7
+ value: {
8
+ time_period: "months",
9
+ amount: 15
10
+ }
11
+ },
12
+ # Or, be explicit with an exact date range for more control...
13
+ {
14
+ label: "First Week of June 2022",
15
+ value: ["06/01/2022", "06/07/2022"]
16
+ }
17
+ ]
18
+ },
19
+ id: "date-range-quickpick-custom",
20
+ label: "Date Range",
21
+ margin_bottom: "sm",
22
+ variant: "quickpick"
23
+ }) %>
24
+
25
+ <%= pb_rails("dropdown", props: {
26
+ custom_quick_pick_dates: {
27
+ override: false,
28
+ dates: [
29
+ {
30
+ label: "Last 15 months",
31
+ value: {
32
+ time_period: "months",
33
+ amount: 15
34
+ }
35
+ },
36
+ {
37
+ label: "First Week of June 2022",
38
+ value: ["06/01/2022", "06/07/2022"]
39
+ }
40
+ ]
41
+ },
42
+ id: "date-range-quickpick-custom-append-to-defaults",
43
+ label: "Date Range - Append to Defaults",
44
+ variant: "quickpick"
45
+ }) %>
46
+
47
+ <script>
48
+ const dropdown1 = document.getElementById("date-range-quickpick-custom");
49
+ if (dropdown1) {
50
+ dropdown1.addEventListener("pb:dropdown:selected", (e) => {
51
+ const option = e.detail;
52
+ console.log("Selected option:", option);
53
+ });
54
+ }
55
+
56
+ const dropdown2 = document.getElementById("date-range-quickpick-custom-append-to-defaults");
57
+ if (dropdown2) {
58
+ dropdown2.addEventListener("pb:dropdown:selected", (e) => {
59
+ const option = e.detail;
60
+ console.log("Selected option:", option);
61
+ });
62
+ }
63
+ </script>
64
+
@@ -0,0 +1,10 @@
1
+ The `custom_quick_pick_dates` prop allows for defining custom quick pick date options for the dropdown. The prop accepts an object with two properties: `dates` and `override`.
2
+
3
+ **The `dates` property** accepts an array of objects. Each object has `label` and `value` properties. The `label` is what will be displayed in the dropdown menu. The `value` property defines the date range that will be selected, and can be:
4
+ - An array of two date strings representing a specific range (e.g., `["06/01/2022", "06/07/2022"]`)
5
+ - An object with `time_period` and `amount` properties for dynamic date calculations:
6
+ - The `time_period` property accepts `"days"`, `"weeks"`, `"months"`, `"quarters"`, or `"years"`, representing past time periods calculated from today.
7
+ - The `amount` property accepts any number.
8
+
9
+ **The `override` property** is a boolean that controls whether custom dates replace or append to the default quick pick options. Default is `true` (replaces defaults). Set to `false` to append your custom dates to the default quick pick options.
10
+
@@ -25,6 +25,7 @@ examples:
25
25
  - dropdown_quickpick_rails: Quick Pick Variant
26
26
  - dropdown_quickpick_range_end_rails: Quick Pick Variant (Range Ends Today)
27
27
  - dropdown_quickpick_default_dates: Quick Pick Variant (Default Dates)
28
+ - dropdown_quickpick_custom_rails: Quick Pick Variant (Custom Quick Pick Dates)
28
29
  - dropdown_quickpick_with_date_pickers_rails: Quick Pick with Date Pickers
29
30
  - dropdown_quickpick_with_date_pickers_default_rails: Quick Pick with Date Pickers (Default Value)
30
31
 
@@ -57,6 +58,7 @@ examples:
57
58
  - dropdown_quickpick: Quick Pick Variant
58
59
  - dropdown_quickpick_range_end: Quick Pick Variant (Range Ends Today)
59
60
  - dropdown_quickpick_default_dates: Quick Pick Variant (Default Dates)
61
+ - dropdown_quickpick_custom: Quick Pick Variant (Custom Quick Pick Dates)
60
62
  - dropdown_quickpick_with_date_pickers: Quick Pick Variant with Date Pickers
61
63
 
62
64
 
@@ -26,4 +26,5 @@ export {default as DropdownWithCustomActiveStyleOptions} from './_dropdown_with_
26
26
  export { default as DropdownQuickpick } from './_dropdown_quickpick.jsx'
27
27
  export { default as DropdownQuickpickRangeEnd } from './_dropdown_quickpick_range_end.jsx'
28
28
  export { default as DropdownQuickpickDefaultDates } from './_dropdown_quickpick_default_dates.jsx'
29
- export { default as DropdownQuickpickWithDatePickers } from './_dropdown_quickpick_with_date_pickers.jsx'
29
+ export { default as DropdownQuickpickWithDatePickers } from './_dropdown_quickpick_with_date_pickers.jsx'
30
+ export { default as DropdownQuickpickCustom } from './_dropdown_quickpick_custom.jsx'
@@ -15,6 +15,8 @@ module Playbook
15
15
  prop :default_value
16
16
  prop :blank_selection, type: Playbook::Props::String,
17
17
  default: ""
18
+ prop :custom_quick_pick_dates, type: Playbook::Props::HashProp,
19
+ default: {}
18
20
  prop :variant, type: Playbook::Props::Enum,
19
21
  values: %w[default subtle quickpick],
20
22
  default: "default"
@@ -94,7 +96,10 @@ module Playbook
94
96
  end
95
97
 
96
98
  def quickpick_options
97
- QuickpickHelper.get_quickpick_options(range_ends_today: range_ends_today)
99
+ QuickpickHelper.get_quickpick_options(
100
+ range_ends_today: range_ends_today,
101
+ custom_quick_pick_dates: custom_quick_pick_dates
102
+ )
98
103
  end
99
104
  end
100
105
  end
@@ -539,4 +539,125 @@ test("quickpick option values are Date objects", () => {
539
539
  expect(endDate.getTime()).not.toBeNaN()
540
540
 
541
541
  expect(endDate.getTime()).toBeGreaterThanOrEqual(startDate.getTime())
542
+ })
543
+
544
+ test("customQuickPickDates overrides default options when override is true or undefined", () => {
545
+ render(
546
+ <Dropdown
547
+ customQuickPickDates={{
548
+ dates: [
549
+ {
550
+ label: "Last 15 months",
551
+ value: { timePeriod: "months", amount: 15 }
552
+ },
553
+ {
554
+ label: "Custom Range",
555
+ value: ["06/01/2022", "06/07/2022"]
556
+ }
557
+ ]
558
+ }}
559
+ data={{ testid: testId }}
560
+ variant="quickpick"
561
+ />
562
+ )
563
+
564
+ const kit = screen.getByTestId(testId)
565
+ const options = kit.querySelectorAll('.pb_dropdown_option_list')
566
+
567
+ expect(options.length).toBe(2)
568
+ expect(options[0]).toHaveTextContent("Last 15 months")
569
+ expect(options[1]).toHaveTextContent("Custom Range")
570
+ })
571
+
572
+ test("customQuickPickDates appends to defaults when override is false", () => {
573
+ render(
574
+ <Dropdown
575
+ customQuickPickDates={{
576
+ override: false,
577
+ dates: [
578
+ {
579
+ label: "Custom Option",
580
+ value: { timePeriod: "days", amount: 30 }
581
+ }
582
+ ]
583
+ }}
584
+ data={{ testid: testId }}
585
+ variant="quickpick"
586
+ />
587
+ )
588
+
589
+ const kit = screen.getByTestId(testId)
590
+ const options = kit.querySelectorAll('.pb_dropdown_option_list')
591
+
592
+ expect(options.length).toBe(11)
593
+ expect(options[0]).toHaveTextContent("Today")
594
+ expect(options[10]).toHaveTextContent("Custom Option")
595
+ })
596
+
597
+ test("customQuickPickDates with explicit date array returns correct values", () => {
598
+ const onSelectMock = jest.fn()
599
+
600
+ render(
601
+ <Dropdown
602
+ customQuickPickDates={{
603
+ dates: [
604
+ {
605
+ label: "First Week of June 2022",
606
+ value: ["06/01/2022", "06/07/2022"]
607
+ }
608
+ ]
609
+ }}
610
+ data={{ testid: testId }}
611
+ onSelect={onSelectMock}
612
+ variant="quickpick"
613
+ />
614
+ )
615
+
616
+ const kit = screen.getByTestId(testId)
617
+ const option = kit.querySelector('.pb_dropdown_option_list')
618
+
619
+ fireEvent.click(option)
620
+
621
+ const selectedItem = onSelectMock.mock.calls[0][0]
622
+
623
+ expect(selectedItem.label).toBe("First Week of June 2022")
624
+ expect(Array.isArray(selectedItem.value)).toBe(true)
625
+ expect(selectedItem.value.length).toBe(2)
626
+ })
627
+
628
+ test("customQuickPickDates with timePeriod calculates dates correctly", () => {
629
+ const onSelectMock = jest.fn()
630
+
631
+ render(
632
+ <Dropdown
633
+ customQuickPickDates={{
634
+ dates: [
635
+ {
636
+ label: "Last 7 days",
637
+ value: { timePeriod: "days", amount: 7 }
638
+ }
639
+ ]
640
+ }}
641
+ data={{ testid: testId }}
642
+ onSelect={onSelectMock}
643
+ variant="quickpick"
644
+ />
645
+ )
646
+
647
+ const kit = screen.getByTestId(testId)
648
+ const option = kit.querySelector('.pb_dropdown_option_list')
649
+
650
+ fireEvent.click(option)
651
+
652
+ const selectedItem = onSelectMock.mock.calls[0][0]
653
+
654
+ expect(selectedItem.label).toBe("Last 7 days")
655
+ expect(Array.isArray(selectedItem.value)).toBe(true)
656
+
657
+ const [startDate, endDate] = selectedItem.value
658
+ expect(startDate instanceof Date).toBe(true)
659
+ expect(endDate instanceof Date).toBe(true)
660
+
661
+ const today = new Date()
662
+ expect(endDate.toDateString()).toBe(today.toDateString())
542
663
  })
@@ -11,8 +11,78 @@ type QuickPickOption = {
11
11
  id?: string;
12
12
  };
13
13
 
14
+ type CustomQuickPickDate = {
15
+ label: string;
16
+ value: string[] | { timePeriod: string; amount: number };
17
+ };
18
+
19
+ type CustomQuickPickDates = {
20
+ override?: boolean;
21
+ dates: CustomQuickPickDate[];
22
+ };
23
+
24
+ // Helper function to calculate date range from timePeriod and amount
25
+ const calculateDateRange = (timePeriod: string, amount: number): Date[] => {
26
+ const endDate = new Date();
27
+ const startDate = new Date();
28
+
29
+ switch (timePeriod) {
30
+ case 'days':
31
+ startDate.setDate(endDate.getDate() - amount);
32
+ break;
33
+ case 'weeks':
34
+ startDate.setDate(endDate.getDate() - (amount * 7));
35
+ break;
36
+ case 'months':
37
+ startDate.setMonth(endDate.getMonth() - amount);
38
+ break;
39
+ case 'quarters':
40
+ startDate.setMonth(endDate.getMonth() - (amount * 3));
41
+ break;
42
+ case 'years':
43
+ startDate.setFullYear(endDate.getFullYear() - amount);
44
+ break;
45
+ default:
46
+ throw new Error('Invalid time period');
47
+ }
48
+ return [startDate, endDate];
49
+ };
50
+
51
+ // Helper to format date for display
52
+ const formatDate = (date: Date) => {
53
+ const day = String(date.getDate()).padStart(2, "0");
54
+ const month = String(date.getMonth() + 1).padStart(2, "0");
55
+ const year = date.getFullYear();
56
+
57
+ return `${month}/${day}/${year}`;
58
+ };
59
+
60
+ // Helper to create a QuickPickOption from a custom date
61
+ const createOptionFromCustomDate = (customDate: CustomQuickPickDate): QuickPickOption => {
62
+ let dateRange: Date[];
63
+
64
+ if (Array.isArray(customDate.value)) {
65
+ // Explicit date range as string array
66
+ dateRange = customDate.value.map((dateStr: string) => new Date(dateStr));
67
+ } else {
68
+ // Calculate from timePeriod and amount
69
+ dateRange = calculateDateRange(
70
+ customDate.value.timePeriod,
71
+ customDate.value.amount
72
+ );
73
+ }
74
+
75
+ return {
76
+ label: customDate.label,
77
+ value: dateRange,
78
+ formattedStartDate: formatDate(dateRange[0]),
79
+ formattedEndDate: formatDate(dateRange[1]),
80
+ id: `quickpick-${customDate.label.toLowerCase().replace(/\s+/g, '-')}`,
81
+ };
82
+ };
83
+
14
84
  // Helper to get QuickPick options with date ranges
15
- const getQuickPickOptions = (rangeEndsToday = false): QuickPickOption[] => {
85
+ const getQuickPickOptions = (rangeEndsToday = false, customQuickPickDates?: CustomQuickPickDates): QuickPickOption[] => {
16
86
  const today = new Date();
17
87
  const yesterday = DateTime.getYesterdayDate(new Date());
18
88
 
@@ -36,14 +106,7 @@ const getQuickPickOptions = (rangeEndsToday = false): QuickPickOption[] => {
36
106
  const lastYearStartDate = DateTime.getPreviousYearStartDate(new Date());
37
107
  const lastYearEndDate = DateTime.getPreviousYearEndDate(new Date());
38
108
 
39
- const formatDate = (date: Date) => {
40
- const day = String(date.getDate()).padStart(2, "0")
41
- const month = String(date.getMonth() + 1).padStart(2, "0")
42
- const year = date.getFullYear()
43
-
44
- return `${month}/${day}/${year}`
45
- }
46
- return [
109
+ const defaultOptions: QuickPickOption[] = [
47
110
  { label: 'Today', value: [today, today], id: 'quickpick-today' },
48
111
  { label: 'Yesterday', value: [yesterday, yesterday], formattedStartDate: `${formatDate(yesterday)}`, formattedEndDate: `${formatDate(yesterday)}`, id: 'quickpick-yesterday' },
49
112
  { label: 'This Week', value: [thisWeekStartDate, thisWeekEndDate], formattedStartDate: `${formatDate(thisWeekStartDate)}`, formattedEndDate: `${formatDate(thisWeekEndDate)}`, id: 'quickpick-this-week' },
@@ -55,6 +118,19 @@ const getQuickPickOptions = (rangeEndsToday = false): QuickPickOption[] => {
55
118
  { label: 'Last Quarter', value: [lastQuarterStartDate, lastQuarterEndDate], formattedStartDate: `${formatDate(lastQuarterStartDate)}`, formattedEndDate: `${formatDate(lastQuarterEndDate)}`, id: 'quickpick-last-quarter' },
56
119
  { label: 'Last Year', value: [lastYearStartDate, lastYearEndDate], formattedStartDate: `${formatDate(lastYearStartDate)}`, formattedEndDate: `${formatDate(lastYearEndDate)}`, id: 'quickpick-last-year' },
57
120
  ];
121
+
122
+ // Handle customQuickPickDates and override logic
123
+ if (customQuickPickDates && customQuickPickDates.dates && customQuickPickDates.dates.length > 0) {
124
+ const customOptions = customQuickPickDates.dates.map(createOptionFromCustomDate);
125
+
126
+ if (customQuickPickDates.override === false) {
127
+ return [...defaultOptions, ...customOptions];
128
+ }
129
+
130
+ return customOptions;
131
+ }
132
+
133
+ return defaultOptions;
58
134
  };
59
135
 
60
136
  export default getQuickPickOptions
@@ -4,7 +4,31 @@ module Playbook
4
4
  module PbDropdown
5
5
  module QuickpickHelper
6
6
  class << self
7
- def get_quickpick_options(range_ends_today: false)
7
+ def get_quickpick_options(range_ends_today: false, custom_quick_pick_dates: {})
8
+ default_options = build_default_options(range_ends_today)
9
+
10
+ # Handle custom_quick_pick_dates
11
+ return default_options if custom_quick_pick_dates.blank?
12
+
13
+ dates = custom_quick_pick_dates[:dates] || custom_quick_pick_dates["dates"]
14
+ return default_options if dates.blank?
15
+
16
+ custom_options = dates.map { |date_config| build_custom_option(date_config) }
17
+
18
+ # Override logic
19
+ override = custom_quick_pick_dates[:override]
20
+ override = custom_quick_pick_dates["override"] if override.nil?
21
+
22
+ if override == false
23
+ default_options + custom_options
24
+ else
25
+ custom_options
26
+ end
27
+ end
28
+
29
+ private
30
+
31
+ def build_default_options(range_ends_today)
8
32
  today = Date.today
9
33
  yesterday = today - 1.day
10
34
 
@@ -42,7 +66,64 @@ module Playbook
42
66
  ]
43
67
  end
44
68
 
45
- private
69
+ def build_custom_option(date_config)
70
+ label = date_config[:label] || date_config["label"]
71
+ value = date_config[:value] || date_config["value"]
72
+
73
+ date_range = calculate_date_range(value)
74
+ start_date = date_range[0]
75
+ end_date = date_range[1]
76
+
77
+ {
78
+ id: "quickpick-#{label.downcase.gsub(/\s+/, '-')}",
79
+ label: label,
80
+ value: [start_date.to_s, end_date.to_s],
81
+ formatted_start_date: format_date(start_date),
82
+ formatted_end_date: format_date(end_date),
83
+ }
84
+ end
85
+
86
+ def calculate_date_range(value)
87
+ # Parse date strings if value is an array
88
+ if value.is_a?(Array)
89
+ [parse_date_string(value[0]), parse_date_string(value[1])]
90
+ else
91
+ # Calculate date range from time_period and amount
92
+ time_period = value[:time_period] || value["time_period"] || value[:timePeriod] || value["timePeriod"]
93
+ amount = value[:amount] || value["amount"]
94
+
95
+ end_date = Date.today
96
+ start_date = calculate_start_date(time_period, amount, end_date)
97
+
98
+ [start_date, end_date]
99
+ end
100
+ end
101
+
102
+ def parse_date_string(date_str)
103
+ # Handle US date format (MM/DD/YYYY) because Ruby's Date.parse defaults to European format (DD/MM/YYYY)
104
+ if date_str.include?("/")
105
+ Date.strptime(date_str, "%m/%d/%Y")
106
+ else
107
+ Date.parse(date_str)
108
+ end
109
+ end
110
+
111
+ def calculate_start_date(time_period, amount, end_date)
112
+ case time_period.to_s
113
+ when "days"
114
+ end_date - amount.days
115
+ when "weeks"
116
+ end_date - amount.weeks
117
+ when "months"
118
+ end_date - amount.months
119
+ when "quarters"
120
+ end_date - (amount * 3).months
121
+ when "years"
122
+ end_date - amount.years
123
+ else
124
+ raise ArgumentError, "Invalid time period: #{time_period}"
125
+ end
126
+ end
46
127
 
47
128
  def format_date(date)
48
129
  date.strftime("%m/%d/%Y")
@@ -30,10 +30,6 @@ module Playbook
30
30
  closeable.present? ? " remove_toast" : ""
31
31
  end
32
32
 
33
- def auto_close_class
34
- auto_close.present? ? " auto_close_#{auto_close}" : ""
35
- end
36
-
37
33
  def position_class
38
34
  horizontal && vertical ? " positioned_toast #{vertical} #{horizontal}" : ""
39
35
  end
@@ -42,6 +38,14 @@ module Playbook
42
38
  multi_line.present? ? "multi_line" : nil
43
39
  end
44
40
 
41
+ def auto_close_attribute
42
+ auto_close.present? ? { "pb-auto-close": auto_close } : {}
43
+ end
44
+
45
+ def data
46
+ Hash(prop(:data)).merge(auto_close_attribute)
47
+ end
48
+
45
49
  def icon_value
46
50
  icon || case status
47
51
  when "success"
@@ -61,9 +65,7 @@ module Playbook
61
65
 
62
66
  def classname
63
67
  default_z_index = z_index.present? ? "" : " z_index_max"
64
- # IMPORTANT: the AutoClose class must be the last class in the string for JS to read it correctly
65
- # Changing the order will break the auto_close functionality
66
- generate_classname("pb_fixed_confirmation_toast_kit", status, multi_line_class) + close_class + position_class + icon_class + default_z_index + auto_close_class
68
+ generate_classname("pb_fixed_confirmation_toast_kit", status, multi_line_class) + close_class + position_class + icon_class + default_z_index
67
69
  end
68
70
  end
69
71
  end
@@ -21,17 +21,12 @@ export default class PbFixedConfirmationToast extends PbEnhancedElement {
21
21
  }
22
22
 
23
23
  autoCloseToast(element) {
24
- const classListValues = element.classList.value
25
- const hasAutoCloseClass = classListValues.includes('auto_close')
26
-
27
- if (hasAutoCloseClass) {
28
- const classList = classListValues.split(' ')
29
- const autoCloseValue = classList[classList.length - 1].split('_')[2]
30
- const autoCloseIntValue = parseInt(autoCloseValue)
24
+ const autoCloseDataAttr = element.getAttribute('data-pb-auto-close')
31
25
 
26
+ if (autoCloseDataAttr) {
32
27
  setTimeout(() => {
33
28
  this.removeToast(element)
34
- }, autoCloseIntValue)
29
+ }, parseInt(autoCloseDataAttr))
35
30
  }
36
31
  }
37
32
  }
@@ -116,7 +116,7 @@
116
116
  <%= form.star_rating_field :example_star_rating, props: { variant: "interactive", label: true } %>
117
117
  <%= form.time_zone_select_field :example_time_zone_select, ActiveSupport::TimeZone.us_zones, { default: "Eastern Time (US & Canada)" }, props: { label: true } %>
118
118
  <%= form.multi_level_select :example_multi_level_select, props: { id: "multi-level-select-form-default", tree_data: treeData, margin_bottom: "sm", label: "Example Multi Level Select field" } %>
119
-
119
+ <%= form.time_picker :example_time_picker, props: { label: true } %>
120
120
  <%= form.actions do |action| %>
121
121
  <%= action.submit %>
122
122
  <%= action.button props: { type: "reset", text: "Cancel", variant: "secondary" } %>
@@ -117,7 +117,8 @@
117
117
  <%= form.star_rating_field :example_star_rating_validation, props: { variant: "interactive", label: true, required: true } %>
118
118
  <%= form.time_zone_select_field :example_time_zone_select, ActiveSupport::TimeZone.us_zones, { default: "Eastern Time (US & Canada)" }, props: { label: true, blank_selection: "Select a Time Zone...", required: true } %>
119
119
  <%= form.multi_level_select :example_multi_level_select, props: { id: "multi-level-select-form", tree_data: treeData, margin_bottom: "sm", required: true, label: "Example Multi Level Select field" } %>
120
-
120
+ <%= form.time_picker :example_time_picker_validation, props: { label: true, required: true, validation_message: "Please select a time." } %>
121
+
121
122
  <%= form.actions do |action| %>
122
123
  <%= action.submit %>
123
124
  <%= action.button props: { type: "reset", text: "Cancel", variant: "secondary" } %>