playbook_ui 12.25.0.pre.alpha.railsmultilevelimprovements785 → 12.26.0.pre.alpha.PLAY603datepickerquickpickinputpresetdropdown794

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 (26) hide show
  1. checksums.yaml +4 -4
  2. data/app/pb_kits/playbook/pb_date_picker/_date_picker.scss +26 -0
  3. data/app/pb_kits/playbook/pb_date_picker/_date_picker.tsx +102 -95
  4. data/app/pb_kits/playbook/pb_date_picker/date_picker.html.erb +30 -2
  5. data/app/pb_kits/playbook/pb_date_picker/date_picker.rb +11 -4
  6. data/app/pb_kits/playbook/pb_date_picker/date_picker.test.js +44 -1
  7. data/app/pb_kits/playbook/pb_date_picker/date_picker_helper.ts +38 -4
  8. data/app/pb_kits/playbook/pb_date_picker/docs/_date_picker_quick_pick.html.erb +8 -0
  9. data/app/pb_kits/playbook/pb_date_picker/docs/_date_picker_quick_pick.jsx +18 -0
  10. data/app/pb_kits/playbook/pb_date_picker/docs/example.yml +2 -0
  11. data/app/pb_kits/playbook/pb_date_picker/docs/index.js +2 -1
  12. data/app/pb_kits/playbook/pb_date_picker/plugins/quickPick.tsx +168 -0
  13. data/app/pb_kits/playbook/pb_date_picker/sass_partials/_calendar_input_icon.scss +3 -2
  14. data/app/pb_kits/playbook/pb_date_picker/sass_partials/_quick_pick_styles.scss +75 -0
  15. data/app/pb_kits/playbook/pb_multi_level_select/_multi_level_select.tsx +0 -16
  16. data/app/pb_kits/playbook/pb_multi_level_select/docs/_multi_level_select_return_all_selected.html.erb +1 -0
  17. data/app/pb_kits/playbook/pb_multi_level_select/docs/example.yml +0 -1
  18. data/app/pb_kits/playbook/pb_multi_level_select/multi_level_select.rb +0 -3
  19. data/app/pb_kits/playbook/pb_nav/_item.tsx +1 -1
  20. data/app/pb_kits/playbook/pb_nav/_subtle_mixin.scss +1 -1
  21. data/dist/playbook-rails.js +279 -7
  22. data/lib/playbook/forms/builder.rb +0 -1
  23. data/lib/playbook/version.rb +2 -2
  24. metadata +6 -4
  25. data/app/pb_kits/playbook/pb_multi_level_select/docs/_multi_level_select_with_form.html.erb +0 -72
  26. data/lib/playbook/forms/builder/multi_level_select_field.rb +0 -12
@@ -0,0 +1,168 @@
1
+ import moment from 'moment'
2
+
3
+ type FpTypes = {
4
+ setDate: (arg0: any, arg1: boolean) => void,
5
+ config: { [key: string]: string },
6
+ clear: (arg0: boolean, arg1: boolean) => void,
7
+ close: () => void,
8
+ calendarContainer?: {
9
+ classList: { add: (arg0: string) => void };
10
+ prepend: (arg0: HTMLDivElement) => void;
11
+ append: (arg0: HTMLDivElement) => void;
12
+ },
13
+ loadedPlugins: string[],
14
+ };
15
+
16
+ type pluginDataType = {
17
+ ranges: { [key: string]: Date[] },
18
+ rangesNav: HTMLUListElement,
19
+ rangesButtons: [] | any,
20
+ }
21
+
22
+ let activeLabel = ""
23
+
24
+ const quickPickPlugin = (thisRangesEndToday: boolean) => {
25
+ return function (fp: FpTypes & any): any {
26
+ const thisWeekEndDate = thisRangesEndToday ? new Date() : moment().endOf('isoWeek').toDate()
27
+ const thisMonthEndDate = thisRangesEndToday ? new Date() : moment().endOf('month').toDate()
28
+ const thisQuarterEndDate = thisRangesEndToday ? new Date() : moment().endOf('quarter').toDate()
29
+ const thisYearEndDate = thisRangesEndToday ? new Date() : moment().endOf('year').toDate()
30
+
31
+ // variable that holds the ranges available
32
+ const ranges = {
33
+ 'Today': [new Date(), new Date()],
34
+ 'Yesterday': [moment().subtract(1, 'days').toDate(), moment().subtract(1, 'days').toDate()],
35
+ 'This week': [moment().startOf('isoWeek').toDate(), thisWeekEndDate],
36
+ 'This month': [moment().startOf('month').toDate(), thisMonthEndDate],
37
+ 'This quarter': [moment().startOf('quarter').toDate(), thisQuarterEndDate],
38
+ 'This year': [moment().startOf('year').toDate(), thisYearEndDate],
39
+ 'Last week': [
40
+ moment().subtract(1, 'week').startOf('isoWeek').toDate(),
41
+ moment().subtract(1, 'week').endOf('isoWeek').toDate()
42
+ ],
43
+ 'Last month': [
44
+ moment().subtract(1, 'month').startOf('month').toDate(),
45
+ moment().subtract(1, 'month').endOf('month').toDate()
46
+ ],
47
+ 'Last quarter': [
48
+ moment().subtract(1, 'quarter').startOf('quarter').toDate(),
49
+ moment().subtract(1, 'quarter').endOf('quarter').toDate()
50
+ ],
51
+ 'Last year': [
52
+ moment().subtract(1, 'year').startOf('year').toDate(),
53
+ moment().subtract(1, 'year').endOf('year').toDate()
54
+ ]
55
+ }
56
+ //creating the ul element for the nav dropdown and giving it classnames
57
+ const rangesNav = document.createElement('ul');
58
+
59
+ // creating the pluginData object that will hold the properties of this plugin
60
+ const pluginData: pluginDataType = {
61
+ ranges: ranges,
62
+ rangesNav: rangesNav,
63
+ rangesButtons: [],
64
+ };
65
+
66
+ /**
67
+ * @param {string} label
68
+ * @returns HTML Element
69
+ */
70
+
71
+ //function for creating the range buttons in the nav
72
+ const addRangeButton = (label: string) => {
73
+
74
+ // creating new elements to mimick selectable card component
75
+ const div2 = document.createElement('div');
76
+ div2.className = "nav-item-link"
77
+ div2.innerHTML = label;
78
+
79
+ pluginData.rangesButtons[label] = div2;
80
+
81
+ // create li elements inside the dropdown
82
+ const item = document.createElement('li');
83
+ item.className = "nav-item";
84
+
85
+ // append those nav items to the li items
86
+ item.appendChild(pluginData.rangesButtons[label]);
87
+
88
+ // append the li item to the ul rangeNav prop
89
+ pluginData.rangesNav.appendChild(item);
90
+
91
+ // return the ranges buton prop
92
+ return pluginData.rangesButtons[label];
93
+ };
94
+
95
+ const selectActiveRangeButton = (selectedDates: Array<string>) => {
96
+ const current = pluginData.rangesNav.querySelector('.active');
97
+
98
+ if (current) {
99
+ current.classList.remove('active');
100
+ }
101
+ /** conditional statment to extract start and end dates from selectedDates,
102
+ * then loop through ranges prop in pluginData
103
+ * and check if chosen dates equal to a date in the ranges prop
104
+ * if they are equal, add the active class
105
+ */
106
+ if (selectedDates.length > 0 && activeLabel) {
107
+ // const selected = pluginData.rangesNav.querySelectorAll(".nav-item-link")
108
+ // selected.forEach(el => {
109
+ // if (el.innerHTML === activeLabel)
110
+ // el.classList.add('active')
111
+ // return
112
+ // })
113
+
114
+ pluginData.rangesButtons[activeLabel].classList.add('active');
115
+ }
116
+ }
117
+
118
+
119
+ return {
120
+ // onReady is a hook from flatpickr that runs when calender is in a ready state
121
+ onReady(selectedDates: Array<string>) {
122
+ // loop through the ranges and create an anchor tag for each range and add an event listener to set the date when user clicks on a date range
123
+ for (const [label, range] of Object.entries(pluginData.ranges)) {
124
+ addRangeButton(label).addEventListener('click', function () {
125
+
126
+ const start = moment(range[0]).toDate();
127
+ const end = moment(range[1]).toDate();
128
+
129
+ if (!start) {
130
+ fp.clear();
131
+ }
132
+ else {
133
+ activeLabel = label
134
+ fp.setDate([start, end], true);
135
+ fp.close();
136
+ }
137
+ });
138
+ }
139
+ // conditional to check if there is a dropdown to add it to the calendar container and get it the classes it needs
140
+ if (pluginData.rangesNav.children.length > 0) {
141
+
142
+ fp.calendarContainer.prepend(pluginData.rangesNav);
143
+ pluginData.rangesNav.classList.add('quick-pick-ul')
144
+ fp.calendarContainer.classList.add('quick-pick-drop-down');
145
+
146
+ /**
147
+ *
148
+ * @param {Array} selectedDates
149
+ */
150
+ // function to give the active button the active class
151
+ selectActiveRangeButton(selectedDates);
152
+ }
153
+ },
154
+ onValueUpdate(selectedDates: Array<string>) {
155
+ selectActiveRangeButton(selectedDates);
156
+ },
157
+
158
+ onClose(selectedDates: Array<string>) {
159
+ // set the input value to the selected dates when the dropdown is closed
160
+ if (selectedDates.length < 2 && selectedDates.length > 0) {
161
+ fp.input.placeholder = fp.formatDate(this.selectedDates[0], fp.config.dateFormat);
162
+ }
163
+ }
164
+ };
165
+ };
166
+ }
167
+
168
+ export default quickPickPlugin;
@@ -1,3 +1,4 @@
1
+ @import "../../tokens/colors";
1
2
  // Calendar Icon Styles
2
3
  .cal_icon_wrapper {
3
4
  pointer-events: none;
@@ -13,8 +14,8 @@
13
14
  padding-left: $space_sm - 1;
14
15
  color: $text_lt_light;
15
16
  @media (hover: hover) {
16
- &:hover {
17
- cursor: pointer;
17
+ &:hover{
18
+ background-color: rgba($focus_input_light,$opacity_5);
18
19
  }
19
20
  }
20
21
  &.dark {
@@ -0,0 +1,75 @@
1
+ @import "../../tokens/animation-curves";
2
+ @import "../../tokens/colors";
3
+ @import "../../tokens/typography";
4
+ @import "../../tokens/titles";
5
+ @import "../../tokens/spacing";
6
+
7
+ $pb_card_border_width: 1px;
8
+ $pb_card_border_radius: $border_rad_heavier;
9
+
10
+ // used to display dropdown on the left of the calender
11
+ .quick-pick-drop-down {
12
+ width: auto;
13
+ display: grid;
14
+ }
15
+
16
+ .quick-pick-ul {
17
+ padding: $space_xs 0px;
18
+ margin: 0;
19
+ list-style: none;
20
+ }
21
+
22
+ .nav-item {
23
+ list-style: none;
24
+ border-radius: 6px;
25
+ border-bottom: 0;
26
+ margin: $space_xs $space_sm;
27
+ }
28
+
29
+ .nav-item-link {
30
+ text-decoration: none;
31
+ border-width: $pb_card_border_width;
32
+ border-style: solid;
33
+ border-color: $border_light;
34
+ border-radius: $pb_card_border_radius;
35
+ padding: $space_xs 14px;
36
+ transition-property: color, background-color;
37
+ transition-duration: 0.15s;
38
+ transition-timing-function: $bezier;
39
+ line-height: 1.4;
40
+ color: $charcoal;
41
+ font-size: $font_default;
42
+ font-weight: $regular;
43
+ &.active {
44
+ border-width: 2px;
45
+ border-color: $primary;
46
+ }
47
+ @media (hover:hover) {
48
+ &:hover {
49
+ cursor: pointer;
50
+ box-shadow: $shadow-deep;
51
+ border-color: $slate;
52
+ }
53
+ }
54
+ }
55
+
56
+ // Hide the calendar
57
+ .quick-pick-drop-down > .flatpickr-months, .quick-pick-drop-down > .flatpickr-innerContainer {
58
+ display: none;
59
+ }
60
+
61
+ @media only screen and (max-width: 767px) {
62
+ .quick-pick-ul {
63
+ padding: $space_xs $space_xs;
64
+ display: grid;
65
+ grid-template-columns: 1fr 1fr;
66
+ }
67
+
68
+ .nav-item {
69
+ margin: $space_xxs $space_xs;
70
+ }
71
+
72
+ .nav-item-link {
73
+ padding: $space_xs $space_xxs;
74
+ }
75
+ }
@@ -25,7 +25,6 @@ type MultiLevelSelectProps = {
25
25
  className?: string;
26
26
  data?: { [key: string]: string };
27
27
  id?: string;
28
- name?: string;
29
28
  returnAllSelected?: boolean;
30
29
  treeData?: { [key: string]: string }[];
31
30
  onSelect?: (prop: { [key: string]: any }) => void;
@@ -37,7 +36,6 @@ const MultiLevelSelect = (props: MultiLevelSelectProps) => {
37
36
  className,
38
37
  data = {},
39
38
  id,
40
- name,
41
39
  returnAllSelected = false,
42
40
  treeData,
43
41
  onSelect = () => {},
@@ -75,19 +73,6 @@ const MultiLevelSelect = (props: MultiLevelSelectProps) => {
75
73
  JSON.stringify(returnAllSelected ? returnedArray : defaultReturn)
76
74
  );
77
75
  }
78
-
79
- const updateHiddenInputValue = (value: any) => {
80
- console.log("value", value)
81
- const hiddenInput = document.querySelector(
82
- "input#" + id
83
- ) as HTMLInputElement
84
- console.log("hiddenInput", hiddenInput)
85
- if (hiddenInput) {
86
- hiddenInput.value = JSON.stringify(value)
87
- }
88
- }
89
-
90
- updateHiddenInputValue(returnAllSelected ? returnedArray : defaultReturn);
91
76
  returnAllSelected
92
77
  ? onSelect(returnedArray)
93
78
  : onSelect(
@@ -348,7 +333,6 @@ const MultiLevelSelect = (props: MultiLevelSelectProps) => {
348
333
  <div ref={dropdownRef} className="wrapper">
349
334
  <div className="input_wrapper" onClick={handleInputWrapperClick}>
350
335
  <div className="input_inner_container">
351
- <input type="hidden" id={id} name={name} value={JSON.stringify(returnAllSelected ? returnedArray : defaultReturn)} />
352
336
  {returnedArray.length !== 0 && returnAllSelected
353
337
  ? returnedArray.map((item, index) => (
354
338
  <FormPill
@@ -64,6 +64,7 @@
64
64
  ],
65
65
  }] %>
66
66
 
67
+
67
68
  <%= pb_rails("multi_level_select", props: {
68
69
  id: "parent-persistence-multi-level-select",
69
70
  tree_data:treeData,
@@ -2,7 +2,6 @@ examples:
2
2
  rails:
3
3
  - multi_level_select_default: Default
4
4
  - multi_level_select_return_all_selected: Return All Selected
5
- - multi_level_select_with_form: With Form
6
5
 
7
6
  react:
8
7
  - multi_level_select_default: Default
@@ -3,8 +3,6 @@
3
3
  module Playbook
4
4
  module PbMultiLevelSelect
5
5
  class MultiLevelSelect < Playbook::KitBase
6
- prop :id
7
- prop :name
8
6
  prop :tree_data, type: Playbook::Props::Array,
9
7
  default: []
10
8
  prop :return_all_selected, type: Playbook::Props::Boolean,
@@ -17,7 +15,6 @@ module Playbook
17
15
  def multi_level_select_options
18
16
  {
19
17
  id: id,
20
- name: name,
21
18
  treeData: tree_data,
22
19
  returnAllSelected: return_all_selected,
23
20
  }
@@ -87,7 +87,7 @@ const NavItem = (props: NavItemProps) => {
87
87
  <span className="pb_nav_list_item_text">
88
88
  {text || children}
89
89
  </span>
90
-
90
+
91
91
  {iconRight &&
92
92
  <div
93
93
  className="pb_nav_list_item_icon_section"
@@ -44,7 +44,7 @@
44
44
  &[class*=_active] [class*=_link] {
45
45
  @include pb_title_4;
46
46
  color: $primary;
47
- letter-spacing: normal;
47
+ letter-spacing: normal;
48
48
  }
49
49
  }
50
50
  }