playbook_ui 16.7.0.pre.alpha.PLAY2868datadefaultvalues16201 → 16.7.0.pre.alpha.PLAY2932datepickerinlineproponly16247
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_date_picker/_date_picker.tsx +4 -21
- data/app/pb_kits/playbook/pb_date_picker/date_picker.html.erb +7 -10
- data/app/pb_kits/playbook/pb_date_picker/date_picker.rb +2 -13
- data/app/pb_kits/playbook/pb_date_picker/date_picker.test.js +15 -10
- data/app/pb_kits/playbook/pb_date_picker/docs/_date_picker_inline.html.erb +0 -2
- data/app/pb_kits/playbook/pb_date_picker/docs/_date_picker_inline.jsx +0 -2
- data/app/pb_kits/playbook/pb_date_picker/docs/_playground.json +1 -3
- data/app/pb_kits/playbook/pb_date_picker/docs/_playground.overrides.json +1 -3
- data/app/pb_kits/playbook/pb_dropdown/_dropdown.tsx +0 -58
- data/app/pb_kits/playbook/pb_dropdown/dropdown.html.erb +0 -2
- data/app/pb_kits/playbook/pb_dropdown/dropdown.test.jsx +1 -7
- data/app/pb_kits/playbook/pb_select/select.rb +0 -9
- data/app/pb_kits/playbook/pb_text_input/text_input.rb +0 -9
- data/dist/chunks/vendor.js +2 -2
- data/lib/playbook/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 565d8cd7eb822030903f71d51b92426f330b7baeecf691207f1a82b3950ff41a
|
|
4
|
+
data.tar.gz: c6478e1ae1e8b441d59206c3abd47a63a1e231eed35eebf357bcd2849e17df0b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: bbd0f4ace6597d6849ced75952307d949e895541c6347b56cc9c1777e8972e97e6a0589bfbe66736c23e3f37047356fa221014ce3bcd7b09554bf3e46819200b
|
|
7
|
+
data.tar.gz: f0160cd0552d3c0764ee4c968cd0aa4d921ed85ad396aa33b0ae8d6fb79e66f985d3ef77d9739c325d09095d8807b62ae5dcac2b7d951cb99339367425cd6636
|
|
@@ -12,20 +12,6 @@ import Caption from '../pb_caption/_caption'
|
|
|
12
12
|
import Body from '../pb_body/_body'
|
|
13
13
|
import colors from "../tokens/exports/_colors.module.scss"
|
|
14
14
|
|
|
15
|
-
function serializeDefaultDateForFilterReset(defaultDate: unknown): string | undefined {
|
|
16
|
-
if (defaultDate === '' || defaultDate == null) return undefined
|
|
17
|
-
if (Array.isArray(defaultDate)) {
|
|
18
|
-
const parts = defaultDate.map((d) => {
|
|
19
|
-
if (d == null || d === '') return ''
|
|
20
|
-
if (d instanceof Date) return d.toISOString()
|
|
21
|
-
return String(d)
|
|
22
|
-
}).filter(Boolean)
|
|
23
|
-
return parts.length ? parts.join(',') : undefined
|
|
24
|
-
}
|
|
25
|
-
if (defaultDate instanceof Date) return defaultDate.toISOString()
|
|
26
|
-
return String(defaultDate)
|
|
27
|
-
}
|
|
28
|
-
|
|
29
15
|
type DatePickerProps = {
|
|
30
16
|
allowInput?: boolean,
|
|
31
17
|
aria?: { [key: string]: string },
|
|
@@ -127,11 +113,7 @@ const DatePicker = (props: DatePickerProps): React.ReactElement => {
|
|
|
127
113
|
} = props
|
|
128
114
|
|
|
129
115
|
const ariaProps = buildAriaProps(aria)
|
|
130
|
-
const
|
|
131
|
-
const dataProps = buildDataProps({
|
|
132
|
-
...data,
|
|
133
|
-
...(filterResetDefaultSerialized ? { 'default-value': filterResetDefaultSerialized } : {}),
|
|
134
|
-
})
|
|
116
|
+
const dataProps = buildDataProps(data)
|
|
135
117
|
const htmlProps = buildHtmlProps(htmlOptions)
|
|
136
118
|
const inputAriaProps = buildAriaProps(inputAria)
|
|
137
119
|
const inputDataProps = buildDataProps(inputData)
|
|
@@ -198,6 +180,7 @@ const DatePicker = (props: DatePickerProps): React.ReactElement => {
|
|
|
198
180
|
//@ts-ignore
|
|
199
181
|
globalProps(filteredProps),
|
|
200
182
|
error ? 'error' : null,
|
|
183
|
+
inLine && 'inline-date-picker',
|
|
201
184
|
className
|
|
202
185
|
)
|
|
203
186
|
|
|
@@ -280,7 +263,7 @@ const DatePicker = (props: DatePickerProps): React.ReactElement => {
|
|
|
280
263
|
}
|
|
281
264
|
</div>
|
|
282
265
|
|
|
283
|
-
{!hideIcon &&
|
|
266
|
+
{!hideIcon && !inLine &&
|
|
284
267
|
<div
|
|
285
268
|
className={iconWrapperClass()}
|
|
286
269
|
id={`cal-icon-${pickerId}`}
|
|
@@ -292,7 +275,7 @@ const DatePicker = (props: DatePickerProps): React.ReactElement => {
|
|
|
292
275
|
</div>
|
|
293
276
|
}
|
|
294
277
|
|
|
295
|
-
{
|
|
278
|
+
{inLine ?
|
|
296
279
|
<div>
|
|
297
280
|
<div
|
|
298
281
|
className={`${iconWrapperClass()} date-picker-inline-icon-plus`}
|
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
date_picker_root_attrs['data-default-value'] = object.serialized_default_date_for_dom if object.serialized_default_date_for_dom.present?
|
|
7
|
-
%>
|
|
8
|
-
<%= pb_content_tag(:div, date_picker_root_attrs) do %>
|
|
1
|
+
<%= pb_content_tag(:div,
|
|
2
|
+
class: object.classname + object.error_class,
|
|
3
|
+
'data-pb-date-picker' => true,
|
|
4
|
+
'data-validation-message' => object.validation_message,
|
|
5
|
+
) do %>
|
|
9
6
|
<div class="input_wrapper">
|
|
10
7
|
<% if !object.hide_label && object.label %>
|
|
11
8
|
<label for="<%= object.picker_id %>">
|
|
@@ -42,7 +39,7 @@
|
|
|
42
39
|
<input type="hidden" id="<%= "#{object.end_date_id}" %>" name="<%= "#{object.end_date_name}" %>">
|
|
43
40
|
<% end %>
|
|
44
41
|
|
|
45
|
-
<% if !object.hide_icon %>
|
|
42
|
+
<% if !object.hide_icon && !object.inline %>
|
|
46
43
|
<div
|
|
47
44
|
class="<%= object.icon_wrapper_class %>"
|
|
48
45
|
id="cal-icon-<%= object.picker_id %>"
|
|
@@ -55,7 +52,7 @@
|
|
|
55
52
|
<% end %>
|
|
56
53
|
|
|
57
54
|
<!-- Inline -->
|
|
58
|
-
<% if object.
|
|
55
|
+
<% if object.inline %>
|
|
59
56
|
<!-- Plus Icon -->
|
|
60
57
|
<div
|
|
61
58
|
class="<%= object.icon_wrapper_class %> date-picker-inline-icon-plus"
|
|
@@ -92,7 +92,8 @@ module Playbook
|
|
|
92
92
|
|
|
93
93
|
def classname
|
|
94
94
|
default_margin_bottom = margin_bottom.present? ? "" : " mb_sm"
|
|
95
|
-
|
|
95
|
+
inline_class = inline ? " inline-date-picker" : ""
|
|
96
|
+
generate_classname("pb_date_picker_kit") + default_margin_bottom + inline_class
|
|
96
97
|
end
|
|
97
98
|
|
|
98
99
|
def date_picker_config
|
|
@@ -144,18 +145,6 @@ module Playbook
|
|
|
144
145
|
def angle_down_path
|
|
145
146
|
"app/pb_kits/playbook/utilities/icons/angle-down.svg"
|
|
146
147
|
end
|
|
147
|
-
|
|
148
|
-
# Serialized business default for opt-in smart filter reset (Nitro / data-default-value).
|
|
149
|
-
def serialized_default_date_for_dom
|
|
150
|
-
case default_date
|
|
151
|
-
when nil, ""
|
|
152
|
-
nil
|
|
153
|
-
when Array
|
|
154
|
-
default_date.compact_blank.map(&:to_s).join(",")
|
|
155
|
-
else
|
|
156
|
-
default_date.to_s.presence
|
|
157
|
-
end
|
|
158
|
-
end
|
|
159
148
|
end
|
|
160
149
|
end
|
|
161
150
|
end
|
|
@@ -40,30 +40,35 @@ describe('DatePicker Kit', () => {
|
|
|
40
40
|
expect(kit).toHaveClass('pb_date_picker_kit mb_sm')
|
|
41
41
|
})
|
|
42
42
|
|
|
43
|
-
test('
|
|
44
|
-
const testId = 'datepicker-
|
|
43
|
+
test('inLine alone adds inline-date-picker class and inline control icons, not the calendar icon', () => {
|
|
44
|
+
const testId = 'datepicker-inline-only'
|
|
45
45
|
render(
|
|
46
46
|
<DatePicker
|
|
47
47
|
data={{ testid: testId }}
|
|
48
|
-
|
|
49
|
-
pickerId="date-picker-
|
|
48
|
+
inLine
|
|
49
|
+
pickerId="date-picker-inline-only"
|
|
50
50
|
/>
|
|
51
51
|
)
|
|
52
|
+
|
|
52
53
|
const kit = screen.getByTestId(testId)
|
|
53
|
-
expect(kit).
|
|
54
|
+
expect(kit).toHaveClass('inline-date-picker')
|
|
55
|
+
expect(kit.querySelector('#cal-icon-date-picker-inline-only')).not.toBeInTheDocument()
|
|
56
|
+
expect(kit.querySelector('#date-picker-inline-only-icon-plus')).toBeInTheDocument()
|
|
57
|
+
expect(kit.querySelector('#date-picker-inline-only-angle-down')).toBeInTheDocument()
|
|
54
58
|
})
|
|
55
59
|
|
|
56
|
-
test('
|
|
57
|
-
const testId = 'datepicker-
|
|
60
|
+
test('hideIcon without inLine does not render inline control icons', () => {
|
|
61
|
+
const testId = 'datepicker-hide-icon-only'
|
|
58
62
|
render(
|
|
59
63
|
<DatePicker
|
|
60
64
|
data={{ testid: testId }}
|
|
61
|
-
|
|
62
|
-
pickerId="date-picker-
|
|
65
|
+
hideIcon
|
|
66
|
+
pickerId="date-picker-hide-icon-only"
|
|
63
67
|
/>
|
|
64
68
|
)
|
|
69
|
+
|
|
65
70
|
const kit = screen.getByTestId(testId)
|
|
66
|
-
expect(kit
|
|
71
|
+
expect(kit.querySelector('#date-picker-hide-icon-only-icon-plus')).not.toBeInTheDocument()
|
|
67
72
|
})
|
|
68
73
|
|
|
69
74
|
test('shows DatePicker date format m/d/Y', async () => {
|
|
@@ -21,58 +21,6 @@ import {
|
|
|
21
21
|
handleClickOutside,
|
|
22
22
|
} from "./utilities";
|
|
23
23
|
|
|
24
|
-
function serializeDropdownFilterResetDefault(
|
|
25
|
-
variant: "default" | "subtle" | "quickpick" | undefined,
|
|
26
|
-
multiSelect: boolean,
|
|
27
|
-
defaultValue: GenericObject | GenericObject[] | string | undefined,
|
|
28
|
-
dropdownOptions: GenericObject[] | GenericObject | undefined,
|
|
29
|
-
): string | undefined {
|
|
30
|
-
const optionList: GenericObject[] = Array.isArray(dropdownOptions)
|
|
31
|
-
? dropdownOptions
|
|
32
|
-
: [];
|
|
33
|
-
const optionDefaultId = (option: GenericObject | undefined): string | undefined => {
|
|
34
|
-
if (!option) return undefined;
|
|
35
|
-
|
|
36
|
-
const id = option.id;
|
|
37
|
-
if (id != null && id !== "") return String(id);
|
|
38
|
-
|
|
39
|
-
const matched = optionList.find((listOption: GenericObject) => (
|
|
40
|
-
(option.value != null && listOption.value === option.value) ||
|
|
41
|
-
(option.label != null && listOption.label === option.label)
|
|
42
|
-
));
|
|
43
|
-
|
|
44
|
-
if (matched?.id != null && matched.id !== "") return String(matched.id);
|
|
45
|
-
return undefined;
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
if (variant === "quickpick") {
|
|
49
|
-
if (typeof defaultValue === "string" && defaultValue) {
|
|
50
|
-
const matched = optionList.find(
|
|
51
|
-
(opt: GenericObject) => opt.label?.toLowerCase() === defaultValue.toLowerCase()
|
|
52
|
-
);
|
|
53
|
-
if (matched?.id != null && matched.id !== "") return String(matched.id);
|
|
54
|
-
}
|
|
55
|
-
return undefined;
|
|
56
|
-
}
|
|
57
|
-
if (multiSelect) {
|
|
58
|
-
const arr = Array.isArray(defaultValue)
|
|
59
|
-
? defaultValue
|
|
60
|
-
: defaultValue && typeof defaultValue === "object" && Object.keys(defaultValue).length
|
|
61
|
-
? [defaultValue as GenericObject]
|
|
62
|
-
: [];
|
|
63
|
-
if (!arr.length) return undefined;
|
|
64
|
-
const ids = arr
|
|
65
|
-
.map((v) => optionDefaultId(v as GenericObject))
|
|
66
|
-
.filter((id) => id != null && id !== "");
|
|
67
|
-
return ids.length ? ids.join(",") : undefined;
|
|
68
|
-
}
|
|
69
|
-
if (defaultValue && typeof defaultValue === "object" && !Array.isArray(defaultValue)) {
|
|
70
|
-
const id = optionDefaultId(defaultValue as GenericObject);
|
|
71
|
-
if (id) return id;
|
|
72
|
-
}
|
|
73
|
-
return undefined;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
24
|
type CustomQuickPickDate = {
|
|
77
25
|
label: string;
|
|
78
26
|
value: string[] | { timePeriod: string; amount: number };
|
|
@@ -209,11 +157,6 @@ let Dropdown = (props: DropdownProps, ref: any): React.ReactElement | null => {
|
|
|
209
157
|
initialSelected
|
|
210
158
|
);
|
|
211
159
|
|
|
212
|
-
const filterResetDefaultSerialized = useMemo(
|
|
213
|
-
() => serializeDropdownFilterResetDefault(variant, multiSelect, defaultValue, dropdownOptions),
|
|
214
|
-
[variant, multiSelect, defaultValue, dropdownOptions]
|
|
215
|
-
);
|
|
216
|
-
|
|
217
160
|
const [isInputFocused, setIsInputFocused] = useState(false);
|
|
218
161
|
const [hasTriggerSubcomponent, setHasTriggerSubcomponent] = useState(true);
|
|
219
162
|
const [hasContainerSubcomponent, setHasContainerSubcomponent] =
|
|
@@ -489,7 +432,6 @@ let Dropdown = (props: DropdownProps, ref: any): React.ReactElement | null => {
|
|
|
489
432
|
<div {...ariaProps}
|
|
490
433
|
{...dataProps}
|
|
491
434
|
{...htmlProps}
|
|
492
|
-
{...(filterResetDefaultSerialized ? { "data-default-value": filterResetDefaultSerialized } : {})}
|
|
493
435
|
className={classes}
|
|
494
436
|
id={id}
|
|
495
437
|
ref={outerDivRef}
|
|
@@ -12,9 +12,7 @@
|
|
|
12
12
|
<% end %>
|
|
13
13
|
<div class="dropdown_wrapper<%= error_class %>" style="position: relative">
|
|
14
14
|
<input
|
|
15
|
-
<% if input_default_value.present? %>
|
|
16
15
|
data-default-value="<%= input_default_value %>"
|
|
17
|
-
<% end %>
|
|
18
16
|
data-dropdown-selected-option
|
|
19
17
|
name="<%= object.name %><%= '[]' if object.multi_select %>"
|
|
20
18
|
style="display: none"
|
|
@@ -51,7 +51,6 @@ test('generated default kit and classname', () => {
|
|
|
51
51
|
const kit = screen.getByTestId(testId)
|
|
52
52
|
expect(kit).toBeInTheDocument()
|
|
53
53
|
expect(kit).toHaveClass('pb_dropdown_default')
|
|
54
|
-
expect(kit).not.toHaveAttribute('data-default-value')
|
|
55
54
|
})
|
|
56
55
|
|
|
57
56
|
test('generated default Trigger and Container when none passed in', () => {
|
|
@@ -434,16 +433,12 @@ test("defaultValue works with multiSelect", () => {
|
|
|
434
433
|
render(
|
|
435
434
|
<Dropdown
|
|
436
435
|
data={{ testid: testId }}
|
|
437
|
-
defaultValue={[
|
|
438
|
-
{ label: options[0].label, value: options[0].value },
|
|
439
|
-
{ label: options[2].label, value: options[2].value },
|
|
440
|
-
]}
|
|
436
|
+
defaultValue={[options[0], options[2]]}
|
|
441
437
|
multiSelect
|
|
442
438
|
options={options}
|
|
443
439
|
/>
|
|
444
440
|
)
|
|
445
441
|
const kit = screen.getByTestId(testId)
|
|
446
|
-
expect(kit).toHaveAttribute("data-default-value", "United-states,pakistan")
|
|
447
442
|
expect(kit.querySelectorAll(".pb_form_pill_kit.pb_form_pill_primary")).toHaveLength(2)
|
|
448
443
|
const option2 = Array.from(kit.querySelectorAll(".pb_dropdown_option_list"));
|
|
449
444
|
const firstOpt = options[0].label
|
|
@@ -504,7 +499,6 @@ test("quickpick variant accepts string defaultValue", () => {
|
|
|
504
499
|
const trigger = kit.querySelector('.pb_dropdown_trigger')
|
|
505
500
|
|
|
506
501
|
expect(trigger).toHaveTextContent("This Month")
|
|
507
|
-
expect(kit).toHaveAttribute("data-default-value", "quickpick-this-month")
|
|
508
502
|
})
|
|
509
503
|
|
|
510
504
|
test("quickpick attaches _dropdownRef to DOM element when id is provided", () => {
|
|
@@ -50,18 +50,9 @@ module Playbook
|
|
|
50
50
|
def validation_data
|
|
51
51
|
fields = input_options[:data] || {}
|
|
52
52
|
fields[:message] = validation_message unless validation_message.blank?
|
|
53
|
-
dv = filter_reset_default_value
|
|
54
|
-
fields[:default_value] = dv if dv.present?
|
|
55
53
|
fields
|
|
56
54
|
end
|
|
57
55
|
|
|
58
|
-
def filter_reset_default_value
|
|
59
|
-
s = selected
|
|
60
|
-
return if s.blank?
|
|
61
|
-
|
|
62
|
-
s.join(",")
|
|
63
|
-
end
|
|
64
|
-
|
|
65
56
|
# Same resolved id as the native +<select>+ (+all_attributes[:id]+) for label +for+.
|
|
66
57
|
def select_input_id
|
|
67
58
|
all_attributes[:id].presence
|
|
@@ -121,18 +121,9 @@ module Playbook
|
|
|
121
121
|
fields[:message] = validation_message unless validation_message.blank?
|
|
122
122
|
fields[:pb_input_mask] = true if mask
|
|
123
123
|
fields[:pb_emoji_mask] = true if emoji_mask
|
|
124
|
-
dv = filter_reset_default_value
|
|
125
|
-
fields[:default_value] = dv if dv.present?
|
|
126
124
|
fields
|
|
127
125
|
end
|
|
128
126
|
|
|
129
|
-
def filter_reset_default_value
|
|
130
|
-
return if value.nil?
|
|
131
|
-
return if value.is_a?(String) && value.empty?
|
|
132
|
-
|
|
133
|
-
value.to_s
|
|
134
|
-
end
|
|
135
|
-
|
|
136
127
|
def error_class
|
|
137
128
|
error ? " error" : ""
|
|
138
129
|
end
|