playbook_ui 15.3.0.pre.alpha.PLAY2569advancedtablecolumnstylingfontcolor11977 → 15.3.0.pre.alpha.PLAY258611978
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/app/pb_kits/playbook/pb_advanced_table/Components/RegularTableView.tsx +1 -2
- data/app/pb_kits/playbook/pb_advanced_table/advanced_table.test.jsx +0 -63
- data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_background_control_rails.html.erb +0 -4
- data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_background_control_rails.md +1 -1
- data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_column_styling.jsx +1 -3
- data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_column_styling.md +0 -2
- data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_column_styling_column_headers.jsx +2 -16
- data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_column_styling_column_headers_rails.html.erb +1 -6
- data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_column_styling_rails.html.erb +0 -1
- data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_column_styling_rails.md +0 -2
- data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_padding_control.jsx +1 -9
- data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_padding_control.md +1 -1
- data/app/pb_kits/playbook/pb_advanced_table/table_row.rb +2 -31
- data/app/pb_kits/playbook/pb_background/background.html.erb +2 -10
- data/app/pb_kits/playbook/pb_date_picker/date_picker_helper.ts +16 -4
- data/app/pb_kits/playbook/pb_date_picker/docs/_date_picker_and_dropdown_range..md +14 -0
- data/app/pb_kits/playbook/pb_date_picker/docs/_date_picker_and_dropdown_range.jsx +38 -0
- data/app/pb_kits/playbook/pb_date_picker/docs/example.yml +2 -1
- data/app/pb_kits/playbook/pb_date_picker/docs/index.js +2 -1
- data/app/pb_kits/playbook/pb_dropdown/_dropdown.scss +1 -0
- data/app/pb_kits/playbook/pb_dropdown/_dropdown.tsx +111 -6
- data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_quickpick.jsx +18 -0
- data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_quickpick.md +4 -0
- data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_quickpick_default_dates.jsx +18 -0
- data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_quickpick_default_dates.md +1 -0
- data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_quickpick_range_end.jsx +19 -0
- data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_quickpick_range_end.md +1 -0
- data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_quickpick_with_date_pickers.jsx +38 -0
- data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_quickpick_with_date_pickers.md +14 -0
- data/app/pb_kits/playbook/pb_dropdown/docs/example.yml +5 -0
- data/app/pb_kits/playbook/pb_dropdown/docs/index.js +5 -1
- data/app/pb_kits/playbook/pb_dropdown/dropdown.test.jsx +148 -2
- data/app/pb_kits/playbook/pb_dropdown/quickpick/index.ts +60 -0
- data/dist/chunks/{_line_graph-CqE0-dq5.js → _line_graph-BokgW0SI.js} +1 -1
- data/dist/chunks/{_typeahead-3ZAbZUqU.js → _typeahead-BR-uKbcO.js} +1 -1
- data/dist/chunks/_weekday_stacked-n_2SPgc2.js +37 -0
- data/dist/chunks/{lib-CGxXTQ75.js → lib-BXBHAZMY.js} +1 -1
- data/dist/chunks/{pb_form_validation-DebqlUKZ.js → pb_form_validation-BZppqQZM.js} +1 -1
- data/dist/chunks/vendor.js +1 -1
- data/dist/playbook-doc.js +1 -1
- data/dist/playbook-rails-react-bindings.js +1 -1
- data/dist/playbook-rails.js +1 -1
- data/dist/playbook.css +1 -1
- data/lib/playbook/version.rb +1 -1
- metadata +17 -6
- data/dist/chunks/_weekday_stacked-D32ib52e.js +0 -37
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: a1a62cafaa16e4da926d69ebca037e59cce874784adfe55e1650cd94f7152f08
|
|
4
|
+
data.tar.gz: c3689d869441ef31917edf4c5e124e0a0a1b42f66d9753fea748897b15a20d2e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f1274d98903345d89ebb1ab7cf7aa5d07f138aa90fd36e6f5d6fdee3ce3ca242999a02b4f97bfc338408d1f33628c01c0d0277a266ce1abe50b8518c7d298eb7
|
|
7
|
+
data.tar.gz: be5e89b4822ed1af5030fa5abcc219e36c6cb97fd95b6b414ac91c2e4814686ad834e7b8dca0da3cdaaf0e7ba27abb27911b5247ce54381bf5385f199fb34c81
|
|
@@ -66,7 +66,6 @@ const TableCellRenderer = ({
|
|
|
66
66
|
// Find the “owning” colDefinition by accessor. Needed for multi column logic
|
|
67
67
|
const colDef = findColumnDefByAccessor(columnDefinitions ?? [], column.id)
|
|
68
68
|
const cellAlignment = colDef?.columnStyling?.cellAlignment ?? "right"
|
|
69
|
-
const cellFontColor = colDef?.columnStyling?.fontColor
|
|
70
69
|
const paddingValue = colDef?.columnStyling?.cellPadding ?? customRowStyle?.cellPadding
|
|
71
70
|
const paddingClass = paddingValue ? `p_${paddingValue}` : undefined
|
|
72
71
|
|
|
@@ -89,7 +88,7 @@ const TableCellRenderer = ({
|
|
|
89
88
|
: `${column.getStart("left")}px`
|
|
90
89
|
: undefined,
|
|
91
90
|
backgroundColor: i === 0 && customRowStyle?.backgroundColor,
|
|
92
|
-
color:
|
|
91
|
+
color: customRowStyle?.fontColor,
|
|
93
92
|
}}
|
|
94
93
|
>
|
|
95
94
|
{collapsibleTrail && i === 0 && row.depth > 0 && renderCollapsibleTrail(row.depth)}
|
|
@@ -740,69 +740,6 @@ test("columnStyling.cellPadding sets cell padding", () => {
|
|
|
740
740
|
expect(firstEnrollmentCell).toHaveClass('p_none')
|
|
741
741
|
});
|
|
742
742
|
|
|
743
|
-
test("columnStyling.fontColor sets cell font color", () => {
|
|
744
|
-
const styledColumnDefs = [
|
|
745
|
-
{
|
|
746
|
-
accessor: "year",
|
|
747
|
-
label: "Year",
|
|
748
|
-
cellAccessors: ["quarter", "month", "day"],
|
|
749
|
-
},
|
|
750
|
-
{
|
|
751
|
-
accessor: "newEnrollments",
|
|
752
|
-
label: "New Enrollments",
|
|
753
|
-
columnStyling: { fontColor: colors.category_1 },
|
|
754
|
-
},
|
|
755
|
-
{
|
|
756
|
-
accessor: "scheduledMeetings",
|
|
757
|
-
label: "Scheduled Meetings",
|
|
758
|
-
},
|
|
759
|
-
];
|
|
760
|
-
|
|
761
|
-
render(
|
|
762
|
-
<AdvancedTable
|
|
763
|
-
columnDefinitions={styledColumnDefs}
|
|
764
|
-
data={{ testid: testId }}
|
|
765
|
-
tableData={MOCK_DATA}
|
|
766
|
-
/>
|
|
767
|
-
);
|
|
768
|
-
|
|
769
|
-
const firstEnrollmentCell = screen.getAllByText("20")[0].closest("td");
|
|
770
|
-
expect(firstEnrollmentCell).toHaveStyle({ color: colors.category_1 });
|
|
771
|
-
});
|
|
772
|
-
|
|
773
|
-
test("columnStyling.fontColor works with background color", () => {
|
|
774
|
-
const styledColumnDefs = [
|
|
775
|
-
{
|
|
776
|
-
accessor: "year",
|
|
777
|
-
label: "Year",
|
|
778
|
-
cellAccessors: ["quarter", "month", "day"],
|
|
779
|
-
},
|
|
780
|
-
{
|
|
781
|
-
accessor: "newEnrollments",
|
|
782
|
-
label: "New Enrollments",
|
|
783
|
-
columnStyling: {
|
|
784
|
-
cellBackgroundColor: (row) => row.newEnrollments > 20 ? "success_secondary" : "warning_secondary",
|
|
785
|
-
fontColor: colors.white
|
|
786
|
-
},
|
|
787
|
-
},
|
|
788
|
-
{
|
|
789
|
-
accessor: "scheduledMeetings",
|
|
790
|
-
label: "Scheduled Meetings",
|
|
791
|
-
},
|
|
792
|
-
];
|
|
793
|
-
|
|
794
|
-
render(
|
|
795
|
-
<AdvancedTable
|
|
796
|
-
columnDefinitions={styledColumnDefs}
|
|
797
|
-
data={{ testid: testId }}
|
|
798
|
-
tableData={MOCK_DATA}
|
|
799
|
-
/>
|
|
800
|
-
);
|
|
801
|
-
|
|
802
|
-
const firstEnrollmentCell = screen.getAllByText("20")[0].closest("td");
|
|
803
|
-
expect(firstEnrollmentCell).toHaveStyle({ color: colors.white });
|
|
804
|
-
});
|
|
805
|
-
|
|
806
743
|
test("renders virtualized table rows and header", () => {
|
|
807
744
|
render(
|
|
808
745
|
<AdvancedTable
|
data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_background_control_rails.md
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
`column_styling` can also be used to control the background color on all cells in a given column via the use of the `cell_background_color` key/value pair. Use `cell_background_color` to achieve custom background colors for individual cells as seen here.
|
|
1
|
+
`column_styling` can also be used to control the background color on all cells in a given column via the use of the `cell_background_color` key/value pair. Use `cell_background_color` to achieve custom background colors for individual cells as seen here.
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import React from "react"
|
|
2
|
-
import
|
|
2
|
+
import AdvancedTable from '../../pb_advanced_table/_advanced_table'
|
|
3
3
|
import MOCK_DATA from "./advanced_table_mock_data.json"
|
|
4
4
|
|
|
5
|
-
|
|
6
5
|
const AdvancedTableColumnStyling = (props) => {
|
|
7
6
|
const columnDefinitions = [
|
|
8
7
|
{
|
|
@@ -35,7 +34,6 @@ const AdvancedTableColumnStyling = (props) => {
|
|
|
35
34
|
{
|
|
36
35
|
accessor: "graduatedStudents",
|
|
37
36
|
label: "Graduated Students",
|
|
38
|
-
columnStyling:{fontColor: colors.data_8},
|
|
39
37
|
},
|
|
40
38
|
]
|
|
41
39
|
|
|
@@ -4,6 +4,4 @@ The `columnStyling` prop is an optional item that can be used within `columnDefi
|
|
|
4
4
|
|
|
5
5
|
2) `cellAlignment`: This will allow you to control alignment of content within all cells in the given column. This is set to right aligned by default. you can set this to `left`, `right` or `center`.
|
|
6
6
|
|
|
7
|
-
3) `fontColor`: This will allow you to control the font color for a given column.
|
|
8
|
-
|
|
9
7
|
`columnStyling` can be used within the columnDefinition of all the columns or some of them, as shown. Each column has its own individual control in this way.
|
data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_column_styling_column_headers.jsx
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
import
|
|
2
|
+
import AdvancedTable from '../../pb_advanced_table/_advanced_table';
|
|
3
3
|
import MOCK_DATA from "./advanced_table_mock_data.json";
|
|
4
4
|
|
|
5
5
|
const AdvancedTableColumnStylingColumnHeaders = (props) => {
|
|
@@ -38,24 +38,11 @@ const AdvancedTableColumnStylingColumnHeaders = (props) => {
|
|
|
38
38
|
{
|
|
39
39
|
accessor: "completedClasses",
|
|
40
40
|
label: "Completed Classes",
|
|
41
|
-
columnStyling:{
|
|
42
|
-
headerAlignment: "center",
|
|
43
|
-
cellAlignment: "center",
|
|
44
|
-
fontColor: colors.success,
|
|
45
|
-
},
|
|
41
|
+
columnStyling:{headerAlignment: "center", cellAlignment: "center"},
|
|
46
42
|
},
|
|
47
43
|
{
|
|
48
44
|
accessor: "classCompletionRate",
|
|
49
45
|
label: "Class Completion Rate",
|
|
50
|
-
columnStyling: { cellPadding: "none", fontColor: colors.error },
|
|
51
|
-
customRenderer: (row, value) => (
|
|
52
|
-
<Background
|
|
53
|
-
backgroundColor={"warning_secondary"}
|
|
54
|
-
padding="xs"
|
|
55
|
-
>
|
|
56
|
-
{value}
|
|
57
|
-
</Background>
|
|
58
|
-
),
|
|
59
46
|
},
|
|
60
47
|
],
|
|
61
48
|
},
|
|
@@ -65,7 +52,6 @@ const AdvancedTableColumnStylingColumnHeaders = (props) => {
|
|
|
65
52
|
{
|
|
66
53
|
accessor: "attendanceRate",
|
|
67
54
|
label: "Attendance Rate",
|
|
68
|
-
columnStyling: { fontColor: colors.category_1 },
|
|
69
55
|
},
|
|
70
56
|
{
|
|
71
57
|
accessor: "scheduledMeetings",
|
|
@@ -32,15 +32,11 @@
|
|
|
32
32
|
{
|
|
33
33
|
accessor: "completedClasses",
|
|
34
34
|
label: "Completed Classes",
|
|
35
|
-
column_styling:{header_alignment:"center", cell_alignment:"center"
|
|
35
|
+
column_styling:{header_alignment:"center", cell_alignment:"center"}
|
|
36
36
|
},
|
|
37
37
|
{
|
|
38
38
|
accessor: "classCompletionRate",
|
|
39
39
|
label: "Class Completion Rate",
|
|
40
|
-
column_styling: {
|
|
41
|
-
cell_background_color: "warning_secondary",
|
|
42
|
-
font_color: "red"
|
|
43
|
-
}
|
|
44
40
|
},
|
|
45
41
|
],
|
|
46
42
|
},
|
|
@@ -50,7 +46,6 @@
|
|
|
50
46
|
{
|
|
51
47
|
accessor: "attendanceRate",
|
|
52
48
|
label: "Attendance Rate",
|
|
53
|
-
column_styling: { font_color: "#0056CF" }
|
|
54
49
|
},
|
|
55
50
|
{
|
|
56
51
|
accessor: "scheduledMeetings",
|
|
@@ -4,6 +4,4 @@ The `column_styling` prop is an optional item that can be used within `column_de
|
|
|
4
4
|
|
|
5
5
|
2) `cell_alignment`: This will allow you to control alignment of content within all cells in the given column. This is set to right aligned by default. you can set this to `left`, `right` or `center`.
|
|
6
6
|
|
|
7
|
-
3) `font_color`: This will allow you to control the font color for a given column.
|
|
8
|
-
|
|
9
7
|
`column_styling` can be used within the column_definition of all the columns or some of them, as shown. Each column has its own individual control in this way.
|
|
@@ -22,6 +22,7 @@ const AdvancedTablePaddingControl = (props) => {
|
|
|
22
22
|
{value}
|
|
23
23
|
</Background>
|
|
24
24
|
),
|
|
25
|
+
|
|
25
26
|
},
|
|
26
27
|
{
|
|
27
28
|
accessor: "scheduledMeetings",
|
|
@@ -38,15 +39,6 @@ const AdvancedTablePaddingControl = (props) => {
|
|
|
38
39
|
{
|
|
39
40
|
accessor: "classCompletionRate",
|
|
40
41
|
label: "Class Completion Rate",
|
|
41
|
-
columnStyling:{cellPadding: "none", fontColor: "white"},
|
|
42
|
-
customRenderer: (row, value) => (
|
|
43
|
-
<Background
|
|
44
|
-
backgroundColor={"category_1"}
|
|
45
|
-
padding="xs"
|
|
46
|
-
>
|
|
47
|
-
{value}
|
|
48
|
-
</Background>
|
|
49
|
-
),
|
|
50
42
|
},
|
|
51
43
|
{
|
|
52
44
|
accessor: "graduatedStudents",
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
`columnStyling` can also be used to control padding on all cells in a given column via the use of the `cellPadding` key/value pair. `cellPadding` lets you use 'xxs', 'xs', 'sm', 'md', 'lg', 'xl' and 'none'.
|
|
2
2
|
|
|
3
|
-
This control can be used in conjunction with the `customRenderer` item within each columnDefinition to achieve custom background colors for individual cells as seen here.
|
|
3
|
+
This control can be used in conjunction with the `customRenderer` item within each columnDefinition to achieve custom background colors for individual cells as seen here.
|
|
@@ -79,44 +79,15 @@ module Playbook
|
|
|
79
79
|
cell_background_color(column).present?
|
|
80
80
|
end
|
|
81
81
|
|
|
82
|
-
def cell_font_color(column)
|
|
83
|
-
return nil unless column[:accessor].present?
|
|
84
|
-
|
|
85
|
-
orig_def = find_column_def_by_accessor(column_definitions, column[:accessor])
|
|
86
|
-
if orig_def && orig_def[:column_styling].is_a?(Hash) && orig_def[:column_styling][:font_color].present?
|
|
87
|
-
font_color = orig_def[:column_styling][:font_color]
|
|
88
|
-
if font_color.respond_to?(:call)
|
|
89
|
-
font_color.call(row)
|
|
90
|
-
else
|
|
91
|
-
font_color
|
|
92
|
-
end
|
|
93
|
-
end
|
|
94
|
-
end
|
|
95
|
-
|
|
96
82
|
# Uses a regular table/table_cell component if there is no custom background color; if there is a cell_background_color uses a background component with tag "td"
|
|
97
83
|
def cell_component_info(column, index, bg_color, font_color)
|
|
98
|
-
column_font_color = cell_font_color(column)
|
|
99
|
-
effective_font_color = column_font_color || font_color
|
|
100
|
-
|
|
101
84
|
if has_custom_background_color?(column)
|
|
102
85
|
custom_bg_color = cell_background_color(column)
|
|
103
86
|
component_name = "background"
|
|
104
|
-
component_props = {
|
|
105
|
-
background_color: custom_bg_color,
|
|
106
|
-
tag: "td",
|
|
107
|
-
classname: td_classname(column, index),
|
|
108
|
-
}
|
|
109
|
-
component_props[:html_options] = { style: { color: effective_font_color } } if effective_font_color.present?
|
|
87
|
+
component_props = { background_color: custom_bg_color, tag: "td", classname: td_classname(column, index) }
|
|
110
88
|
else
|
|
111
89
|
component_name = "table/table_cell"
|
|
112
|
-
|
|
113
|
-
style_hash[:color] = effective_font_color if effective_font_color.present?
|
|
114
|
-
component_props = {
|
|
115
|
-
html_options: {
|
|
116
|
-
style: style_hash,
|
|
117
|
-
},
|
|
118
|
-
classname: td_classname(column, index),
|
|
119
|
-
}
|
|
90
|
+
component_props = { html_options: { style: { "background-color": bg_color, color: font_color } }, classname: td_classname(column, index) }
|
|
120
91
|
end
|
|
121
92
|
|
|
122
93
|
{ name: component_name, props: component_props }
|
|
@@ -1,11 +1,3 @@
|
|
|
1
|
-
<%
|
|
2
|
-
html_options_style = ""
|
|
3
|
-
if object.html_options[:style].is_a?(Hash)
|
|
4
|
-
html_options_style = object.html_options[:style].map { |k, v| "#{k.to_s.tr('_', '-')}: #{v}" }.join("; ")
|
|
5
|
-
elsif object.html_options[:style].is_a?(String)
|
|
6
|
-
html_options_style = object.html_options[:style]
|
|
7
|
-
end
|
|
8
|
-
%>
|
|
9
1
|
<% if object.image_url.present? %>
|
|
10
2
|
<%= pb_content_tag(object.tag,
|
|
11
3
|
style: "background-image: url('#{object.image_url}');
|
|
@@ -17,8 +9,8 @@
|
|
|
17
9
|
<% end %>
|
|
18
10
|
<% else %>
|
|
19
11
|
<%= pb_content_tag(object.tag,
|
|
20
|
-
style:
|
|
12
|
+
style: object.custom_background_color
|
|
21
13
|
) do %>
|
|
22
14
|
<%= content.presence %>
|
|
23
15
|
<% end %>
|
|
24
|
-
<% end %>
|
|
16
|
+
<% end %>
|
|
@@ -350,8 +350,14 @@ const datePickerHelper = (config: DatePickerConfig, scrollContainer: string | HT
|
|
|
350
350
|
if (syncStartWith) {
|
|
351
351
|
picker.config.onClose.push((selectedDates: string) => {
|
|
352
352
|
if (selectedDates?.length) {
|
|
353
|
-
const
|
|
354
|
-
|
|
353
|
+
const element = document.querySelector(`#${syncStartWith}`) as any;
|
|
354
|
+
// Check if it's a Dropdown QuickPick (has _dropdownRef) or DatePicker QuickPick (has _flatpickr)
|
|
355
|
+
if (element?._dropdownRef?.current) {
|
|
356
|
+
element._dropdownRef.current.clearSelected();
|
|
357
|
+
} else {
|
|
358
|
+
const quickpick = element?._flatpickr;
|
|
359
|
+
quickpick?.clear();
|
|
360
|
+
}
|
|
355
361
|
}
|
|
356
362
|
});
|
|
357
363
|
}
|
|
@@ -360,8 +366,14 @@ const datePickerHelper = (config: DatePickerConfig, scrollContainer: string | HT
|
|
|
360
366
|
if (syncEndWith) {
|
|
361
367
|
picker.config.onClose.push((selectedDates: string) => {
|
|
362
368
|
if (selectedDates?.length) {
|
|
363
|
-
const
|
|
364
|
-
|
|
369
|
+
const element = document.querySelector(`#${syncEndWith}`) as any;
|
|
370
|
+
// Check if it's a Dropdown QuickPick (has _dropdownRef) or DatePicker QuickPick (has _flatpickr)
|
|
371
|
+
if (element?._dropdownRef?.current) {
|
|
372
|
+
element._dropdownRef.current.clearSelected();
|
|
373
|
+
} else {
|
|
374
|
+
const quickpick = element?._flatpickr;
|
|
375
|
+
quickpick?.clear();
|
|
376
|
+
}
|
|
365
377
|
}
|
|
366
378
|
});
|
|
367
379
|
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
You can link a Dropdown (`quickpick` variant) to standard DatePickers using the following props:
|
|
2
|
+
|
|
3
|
+
**For the Dropdown**:
|
|
4
|
+
`controlsStartId`: ID of the DatePicker that should receive the start date.
|
|
5
|
+
|
|
6
|
+
`controlsEndId`: ID of the DatePicker that should receive the end date.
|
|
7
|
+
|
|
8
|
+
When a quickpick option like “This Year” is selected, it automatically populates the linked start and end inputs.
|
|
9
|
+
|
|
10
|
+
**For the Start/End DatePickers**:
|
|
11
|
+
`syncStartWith`: ID of the quickpick this start date is synced to.
|
|
12
|
+
`syncEndWith`: ID of the quickpick this end date is synced to.
|
|
13
|
+
|
|
14
|
+
When a user manually edits the start or end date, it clears the selected quickpick to prevent conflicting values.
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import Dropdown from "../../pb_dropdown/_dropdown";
|
|
3
|
+
import DatePicker from "../../pb_date_picker/_date_picker";
|
|
4
|
+
|
|
5
|
+
const DatePickerAndDropdownRange = (props) => {
|
|
6
|
+
return (
|
|
7
|
+
<>
|
|
8
|
+
<Dropdown
|
|
9
|
+
controlsEndId="end-date-picker1"
|
|
10
|
+
controlsStartId="start-date-picker1"
|
|
11
|
+
id="dropdown-as-quickpick"
|
|
12
|
+
label="Date Range"
|
|
13
|
+
marginBottom="sm"
|
|
14
|
+
placeholder="Select a Date Range"
|
|
15
|
+
variant="quickpick"
|
|
16
|
+
{...props}
|
|
17
|
+
/>
|
|
18
|
+
|
|
19
|
+
<DatePicker
|
|
20
|
+
label="Start Date"
|
|
21
|
+
pickerId="start-date-picker1"
|
|
22
|
+
placeholder="Select a Start Date"
|
|
23
|
+
syncStartWith="dropdown-as-quickpick"
|
|
24
|
+
{...props}
|
|
25
|
+
/>
|
|
26
|
+
|
|
27
|
+
<DatePicker
|
|
28
|
+
label="End Date"
|
|
29
|
+
pickerId="end-date-picker1"
|
|
30
|
+
placeholder="Select an End Date"
|
|
31
|
+
syncEndWith="dropdown-as-quickpick"
|
|
32
|
+
{...props}
|
|
33
|
+
/>
|
|
34
|
+
</>
|
|
35
|
+
);
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
export default DatePickerAndDropdownRange;
|
|
@@ -48,7 +48,8 @@ examples:
|
|
|
48
48
|
- date_picker_quick_pick_custom: Custom Quick Pick Dates
|
|
49
49
|
- date_picker_quick_pick_custom_override: Custom Quick Pick Dates (append to defaults)
|
|
50
50
|
- date_picker_quick_pick_default_date: Range (Quick Pick w/ Default Date)
|
|
51
|
-
- date_picker_range_pattern: Range with 2 Date Pickers and a Quick Pick
|
|
51
|
+
# - date_picker_range_pattern: Range with 2 Date Pickers and a Quick Pick
|
|
52
|
+
- date_picker_and_dropdown_range: Range with Dropdown and 2 Date Pickers
|
|
52
53
|
- date_picker_format: Format
|
|
53
54
|
- date_picker_disabled: Disabled Dates
|
|
54
55
|
- date_picker_min_max: Min Max
|
|
@@ -26,4 +26,5 @@ export { default as DatePickerOnClose } from './_date_picker_on_close.jsx'
|
|
|
26
26
|
export { default as DatePickerQuickPickCustom } from './_date_picker_quick_pick_custom'
|
|
27
27
|
export { default as DatePickerQuickPickCustomOverride } from './_date_picker_quick_pick_custom_override'
|
|
28
28
|
export { default as DatePickerQuickPickDefaultDate } from './_date_picker_quick_pick_default_date'
|
|
29
|
-
export { default as DatePickerRangePattern } from './_date_picker_range_pattern'
|
|
29
|
+
export { default as DatePickerRangePattern } from './_date_picker_range_pattern'
|
|
30
|
+
export { default as DatePickerAndDropdownRange } from './_date_picker_and_dropdown_range.jsx'
|
|
@@ -12,6 +12,7 @@ import DropdownContext from "./context";
|
|
|
12
12
|
import DropdownOption from "./subcomponents/DropdownOption";
|
|
13
13
|
import DropdownTrigger from "./subcomponents/DropdownTrigger";
|
|
14
14
|
import useDropdown from "./hooks/useDropdown";
|
|
15
|
+
import getQuickPickOptions from "./quickpick";
|
|
15
16
|
|
|
16
17
|
import {
|
|
17
18
|
separateChildComponents,
|
|
@@ -36,9 +37,12 @@ type DropdownProps = {
|
|
|
36
37
|
label?: string;
|
|
37
38
|
multiSelect?: boolean;
|
|
38
39
|
onSelect?: (arg: GenericObject) => null;
|
|
39
|
-
options
|
|
40
|
+
options?: GenericObject;
|
|
40
41
|
separators?: boolean;
|
|
41
|
-
variant?: "default" | "subtle";
|
|
42
|
+
variant?: "default" | "subtle" | "quickpick";
|
|
43
|
+
rangeEndsToday?: boolean;
|
|
44
|
+
controlsStartId?: string;
|
|
45
|
+
controlsEndId?: string;
|
|
42
46
|
activeStyle?: {
|
|
43
47
|
backgroundColor?: string;
|
|
44
48
|
fontColor?: string;
|
|
@@ -71,6 +75,9 @@ let Dropdown = (props: DropdownProps, ref: any): React.ReactElement | null => {
|
|
|
71
75
|
formPillProps,
|
|
72
76
|
onSelect,
|
|
73
77
|
options,
|
|
78
|
+
rangeEndsToday = false,
|
|
79
|
+
controlsStartId,
|
|
80
|
+
controlsEndId,
|
|
74
81
|
separators = true,
|
|
75
82
|
variant = "default",
|
|
76
83
|
activeStyle,
|
|
@@ -85,11 +92,25 @@ let Dropdown = (props: DropdownProps, ref: any): React.ReactElement | null => {
|
|
|
85
92
|
globalProps(props),
|
|
86
93
|
className
|
|
87
94
|
);
|
|
95
|
+
// ------------- Quick Pick ---------------------------------
|
|
96
|
+
// Use QuickPick options when variant is "quickpick"
|
|
97
|
+
const dropdownOptions = variant === "quickpick"
|
|
98
|
+
? getQuickPickOptions(rangeEndsToday)
|
|
99
|
+
: (options || []);
|
|
100
|
+
// ----------------------------------------------------------
|
|
88
101
|
|
|
89
102
|
const [isDropDownClosed, setIsDropDownClosed, toggleDropdown] = useDropdown(isClosed);
|
|
90
103
|
|
|
91
104
|
const [filterItem, setFilterItem] = useState("");
|
|
92
105
|
const initialSelected = useMemo(() => {
|
|
106
|
+
// Handle quickpick variant with string defaultValue (e.g., "This Month")
|
|
107
|
+
if (variant === "quickpick" && typeof defaultValue === "string" && defaultValue) {
|
|
108
|
+
const matchedOption = dropdownOptions.find(
|
|
109
|
+
(opt: GenericObject) => opt.label?.toLowerCase() === (defaultValue as string).toLowerCase()
|
|
110
|
+
);
|
|
111
|
+
return matchedOption || {};
|
|
112
|
+
}
|
|
113
|
+
|
|
93
114
|
if (multiSelect) {
|
|
94
115
|
if (Array.isArray(defaultValue)) return defaultValue;
|
|
95
116
|
return defaultValue && Object.keys(defaultValue).length
|
|
@@ -97,7 +118,7 @@ let Dropdown = (props: DropdownProps, ref: any): React.ReactElement | null => {
|
|
|
97
118
|
: [];
|
|
98
119
|
}
|
|
99
120
|
return defaultValue || {};
|
|
100
|
-
}, [multiSelect, defaultValue]);
|
|
121
|
+
}, [multiSelect, defaultValue, variant, dropdownOptions]);
|
|
101
122
|
|
|
102
123
|
const [selected, setSelected] = useState<GenericObject | GenericObject[]>(
|
|
103
124
|
initialSelected
|
|
@@ -151,7 +172,7 @@ let Dropdown = (props: DropdownProps, ref: any): React.ReactElement | null => {
|
|
|
151
172
|
}, [isClosed])
|
|
152
173
|
|
|
153
174
|
const blankSelectionOption: GenericObject = blankSelection ? [{ label: blankSelection, value: "" }] : [];
|
|
154
|
-
const optionsWithBlankSelection = blankSelectionOption.concat(
|
|
175
|
+
const optionsWithBlankSelection = blankSelectionOption.concat(dropdownOptions);
|
|
155
176
|
|
|
156
177
|
const availableOptions = useMemo(()=> {
|
|
157
178
|
if (!multiSelect) return optionsWithBlankSelection;
|
|
@@ -203,6 +224,21 @@ let Dropdown = (props: DropdownProps, ref: any): React.ReactElement | null => {
|
|
|
203
224
|
setFilterItem("");
|
|
204
225
|
setIsDropDownClosed(true);
|
|
205
226
|
onSelect && onSelect(clickedItem);
|
|
227
|
+
|
|
228
|
+
// Sync with DatePickers if this is a quickpick variant
|
|
229
|
+
if (variant === "quickpick" && Array.isArray(clickedItem.value)) {
|
|
230
|
+
const [start, end] = clickedItem.value;
|
|
231
|
+
|
|
232
|
+
if (controlsStartId) {
|
|
233
|
+
const startPicker = (document.querySelector(`#${controlsStartId}`) as HTMLElement & { _flatpickr?: any })?._flatpickr;
|
|
234
|
+
startPicker?.setDate(start, true);
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
if (controlsEndId) {
|
|
238
|
+
const endPicker = (document.querySelector(`#${controlsEndId}`) as HTMLElement & { _flatpickr?: any })?._flatpickr;
|
|
239
|
+
endPicker?.setDate(end, true);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
206
242
|
}
|
|
207
243
|
};
|
|
208
244
|
|
|
@@ -219,6 +255,19 @@ let Dropdown = (props: DropdownProps, ref: any): React.ReactElement | null => {
|
|
|
219
255
|
setSelected({});
|
|
220
256
|
onSelect && onSelect(null);
|
|
221
257
|
setFocusedOptionIndex(-1);
|
|
258
|
+
|
|
259
|
+
// Clear linked DatePickers as well if this is a quickpick variant with controls
|
|
260
|
+
if (variant === "quickpick") {
|
|
261
|
+
if (controlsStartId) {
|
|
262
|
+
const startPicker = (document.querySelector(`#${controlsStartId}`) as HTMLElement & { _flatpickr?: any })?._flatpickr;
|
|
263
|
+
startPicker?.clear();
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
if (controlsEndId) {
|
|
267
|
+
const endPicker = (document.querySelector(`#${controlsEndId}`) as HTMLElement & { _flatpickr?: any })?._flatpickr;
|
|
268
|
+
endPicker?.clear();
|
|
269
|
+
}
|
|
270
|
+
}
|
|
222
271
|
}
|
|
223
272
|
};
|
|
224
273
|
|
|
@@ -232,7 +281,8 @@ let Dropdown = (props: DropdownProps, ref: any): React.ReactElement | null => {
|
|
|
232
281
|
dark
|
|
233
282
|
});
|
|
234
283
|
|
|
235
|
-
|
|
284
|
+
// Create an internal ref object that holds the imperative handle methods
|
|
285
|
+
const imperativeRef = useRef({
|
|
236
286
|
clearSelected: () => {
|
|
237
287
|
if (multiSelect) {
|
|
238
288
|
setSelected([]);
|
|
@@ -244,7 +294,61 @@ let Dropdown = (props: DropdownProps, ref: any): React.ReactElement | null => {
|
|
|
244
294
|
setFilterItem("");
|
|
245
295
|
setIsDropDownClosed(true);
|
|
246
296
|
},
|
|
247
|
-
})
|
|
297
|
+
});
|
|
298
|
+
|
|
299
|
+
// Update imperativeRef whenever dependencies change
|
|
300
|
+
// (needed for external clearing of normal Dropdown + DatePicker-synced QuickPick Dropdown)
|
|
301
|
+
useEffect(() => {
|
|
302
|
+
imperativeRef.current = {
|
|
303
|
+
clearSelected: () => {
|
|
304
|
+
if (multiSelect) {
|
|
305
|
+
setSelected([]);
|
|
306
|
+
onSelect && onSelect([]);
|
|
307
|
+
} else {
|
|
308
|
+
setSelected({});
|
|
309
|
+
onSelect && onSelect(null);
|
|
310
|
+
}
|
|
311
|
+
setFilterItem("");
|
|
312
|
+
setIsDropDownClosed(true);
|
|
313
|
+
},
|
|
314
|
+
};
|
|
315
|
+
}, [multiSelect, onSelect, setSelected, setFilterItem, setIsDropDownClosed]);
|
|
316
|
+
|
|
317
|
+
useImperativeHandle(ref, () => imperativeRef.current);
|
|
318
|
+
|
|
319
|
+
// Create a ref to the outer div to attach the dropdown ref for DatePicker sync
|
|
320
|
+
const outerDivRef = useRef<HTMLDivElement>(null);
|
|
321
|
+
|
|
322
|
+
useEffect(() => {
|
|
323
|
+
// Attach the ref to the DOM element so DatePicker can access it
|
|
324
|
+
if (outerDivRef.current && variant === "quickpick" && id) {
|
|
325
|
+
(outerDivRef.current as any)._dropdownRef = imperativeRef;
|
|
326
|
+
}
|
|
327
|
+
}, [variant, id]);
|
|
328
|
+
|
|
329
|
+
// Sync defaultValue with DatePickers on mount when 3 input pattern is used
|
|
330
|
+
useEffect(() => {
|
|
331
|
+
if (variant === "quickpick" && initialSelected && typeof initialSelected === "object" && !Array.isArray(initialSelected)) {
|
|
332
|
+
const value = initialSelected.value;
|
|
333
|
+
|
|
334
|
+
if (Array.isArray(value) && value.length === 2) {
|
|
335
|
+
const [start, end] = value;
|
|
336
|
+
|
|
337
|
+
// Wait for DatePickers to be initialized
|
|
338
|
+
setTimeout(() => {
|
|
339
|
+
if (controlsStartId) {
|
|
340
|
+
const startPicker = (document.querySelector(`#${controlsStartId}`) as HTMLElement & { _flatpickr?: any })?._flatpickr;
|
|
341
|
+
startPicker?.setDate(start, true);
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
if (controlsEndId) {
|
|
345
|
+
const endPicker = (document.querySelector(`#${controlsEndId}`) as HTMLElement & { _flatpickr?: any })?._flatpickr;
|
|
346
|
+
endPicker?.setDate(end, true);
|
|
347
|
+
}
|
|
348
|
+
}, 0);
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
}, [variant, initialSelected, controlsStartId, controlsEndId]);
|
|
248
352
|
|
|
249
353
|
return (
|
|
250
354
|
<div {...ariaProps}
|
|
@@ -252,6 +356,7 @@ let Dropdown = (props: DropdownProps, ref: any): React.ReactElement | null => {
|
|
|
252
356
|
{...htmlProps}
|
|
253
357
|
className={classes}
|
|
254
358
|
id={id}
|
|
359
|
+
ref={outerDivRef}
|
|
255
360
|
style={{position: "relative"}}
|
|
256
361
|
>
|
|
257
362
|
<DropdownContext.Provider
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import Dropdown from '../../pb_dropdown/_dropdown'
|
|
3
|
+
|
|
4
|
+
const DropdownQuickpick = (props) => {
|
|
5
|
+
|
|
6
|
+
return (
|
|
7
|
+
<div>
|
|
8
|
+
<Dropdown
|
|
9
|
+
label="Date Range"
|
|
10
|
+
onSelect={(selectedItem) => console.log(selectedItem)}
|
|
11
|
+
variant="quickpick"
|
|
12
|
+
{...props}
|
|
13
|
+
/>
|
|
14
|
+
</div>
|
|
15
|
+
)
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export default DropdownQuickpick
|