playbook_ui 7.0.0.pre.alpha9 → 7.0.0.pre.alpha10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -4
- data/app/pb_kits/playbook/_playbook.scss +1 -0
- data/app/pb_kits/playbook/data/menu.yml +1 -0
- data/app/pb_kits/playbook/index.js +3 -0
- data/app/pb_kits/playbook/pb_button/_button.jsx +1 -0
- data/app/pb_kits/playbook/pb_button/_button_mixins.scss +1 -1
- data/app/pb_kits/playbook/pb_button/docs/_button_default.jsx +3 -7
- data/app/pb_kits/playbook/pb_button/docs/_button_default_dark.jsx +3 -0
- data/app/pb_kits/playbook/pb_button/docs/_button_link.jsx +2 -0
- data/app/pb_kits/playbook/pb_button/docs/_button_loading.jsx +2 -0
- data/app/pb_kits/playbook/pb_circle_icon_button/docs/_circle_icon_button_link.html.erb +2 -1
- data/app/pb_kits/playbook/pb_date/_date.html.erb +8 -32
- data/app/pb_kits/playbook/pb_date/_date.jsx +67 -76
- data/app/pb_kits/playbook/pb_date/_date.scss +0 -25
- data/app/pb_kits/playbook/pb_date/date.rb +10 -18
- data/app/pb_kits/playbook/pb_date/docs/_date_default.html.erb +17 -2
- data/app/pb_kits/playbook/pb_date/docs/_date_default.jsx +28 -0
- data/app/pb_kits/playbook/pb_date/docs/example.yml +2 -5
- data/app/pb_kits/playbook/pb_date/docs/index.js +1 -3
- data/app/pb_kits/playbook/pb_date_picker/_date_picker.html.erb +39 -0
- data/app/pb_kits/playbook/pb_date_picker/_date_picker.jsx +149 -0
- data/app/pb_kits/playbook/pb_date_picker/_date_picker.scss +33 -0
- data/app/pb_kits/playbook/pb_date_picker/date_picker.rb +85 -0
- data/app/pb_kits/playbook/pb_date_picker/date_picker_helper.js +165 -0
- data/app/pb_kits/playbook/pb_date_picker/docs/_date_picker_allow_input.html.erb +4 -0
- data/app/pb_kits/playbook/pb_date_picker/docs/_date_picker_allow_input.jsx +13 -0
- data/app/pb_kits/playbook/pb_date_picker/docs/_date_picker_allow_input.md +1 -0
- data/app/pb_kits/playbook/pb_date_picker/docs/_date_picker_dark.html.erb +4 -0
- data/app/pb_kits/playbook/pb_date_picker/docs/_date_picker_dark.jsx +13 -0
- data/app/pb_kits/playbook/pb_date_picker/docs/_date_picker_default.html.erb +1 -0
- data/app/pb_kits/playbook/pb_date_picker/docs/_date_picker_default.jsx +12 -0
- data/app/pb_kits/playbook/pb_date_picker/docs/_date_picker_default_date.html.erb +24 -0
- data/app/pb_kits/playbook/pb_date_picker/docs/_date_picker_default_date.jsx +30 -0
- data/app/pb_kits/playbook/pb_date_picker/docs/_date_picker_disabled.html.erb +43 -0
- data/app/pb_kits/playbook/pb_date_picker/docs/_date_picker_disabled.jsx +48 -0
- data/app/pb_kits/playbook/pb_date_picker/docs/_date_picker_error.html.erb +4 -0
- data/app/pb_kits/playbook/pb_date_picker/docs/_date_picker_error.jsx +13 -0
- data/app/pb_kits/playbook/pb_date_picker/docs/_date_picker_format.html.erb +19 -0
- data/app/pb_kits/playbook/pb_date_picker/docs/_date_picker_format.jsx +25 -0
- data/app/pb_kits/playbook/pb_date_picker/docs/_date_picker_format.md +1 -0
- data/app/pb_kits/playbook/pb_date_picker/docs/_date_picker_hide_icon.html.erb +4 -0
- data/app/pb_kits/playbook/pb_date_picker/docs/_date_picker_hide_icon.jsx +13 -0
- data/app/pb_kits/playbook/pb_date_picker/docs/_date_picker_hooks.html.erb +37 -0
- data/app/pb_kits/playbook/pb_date_picker/docs/_date_picker_hooks.jsx +37 -0
- data/app/pb_kits/playbook/pb_date_picker/docs/_date_picker_hooks.md +1 -0
- data/app/pb_kits/playbook/pb_date_picker/docs/_date_picker_input.html.erb +26 -0
- data/app/pb_kits/playbook/pb_date_picker/docs/_date_picker_input.jsx +32 -0
- data/app/pb_kits/playbook/pb_date_picker/docs/_date_picker_input.md +3 -0
- data/app/pb_kits/playbook/pb_date_picker/docs/_date_picker_label.html.erb +9 -0
- data/app/pb_kits/playbook/pb_date_picker/docs/_date_picker_label.jsx +17 -0
- data/app/pb_kits/playbook/pb_date_picker/docs/_date_picker_label.md +1 -0
- data/app/pb_kits/playbook/pb_date_picker/docs/_date_picker_min_max.html.erb +14 -0
- data/app/pb_kits/playbook/pb_date_picker/docs/_date_picker_min_max.jsx +22 -0
- data/app/pb_kits/playbook/pb_date_picker/docs/_date_picker_range.html.erb +4 -0
- data/app/pb_kits/playbook/pb_date_picker/docs/_date_picker_range.jsx +13 -0
- data/app/pb_kits/playbook/pb_date_picker/docs/_date_picker_year_range.html.erb +7 -0
- data/app/pb_kits/playbook/pb_date_picker/docs/_date_picker_year_range.jsx +16 -0
- data/app/pb_kits/playbook/pb_date_picker/docs/_date_picker_year_range.md +1 -0
- data/app/pb_kits/playbook/pb_date_picker/docs/_description.md +7 -0
- data/app/pb_kits/playbook/pb_date_picker/docs/example.yml +35 -0
- data/app/pb_kits/playbook/pb_date_picker/docs/index.js +14 -0
- data/app/pb_kits/playbook/pb_date_picker/sass_partials/_calendar_input_icon.scss +33 -0
- data/app/pb_kits/playbook/pb_date_picker/sass_partials/_day_styles.scss +53 -0
- data/app/pb_kits/playbook/pb_date_picker/sass_partials/_flatpickr_styles.scss +785 -0
- data/app/pb_kits/playbook/pb_date_picker/sass_partials/_header_styles.scss +108 -0
- data/app/pb_kits/playbook/pb_date_picker/sass_partials/_overrides.scss +44 -0
- data/app/pb_kits/playbook/pb_filter/_filter.scss +1 -1
- data/app/pb_kits/playbook/pb_form/docs/_form_form_with.html.erb +1 -0
- data/app/pb_kits/playbook/pb_form/docs/_form_form_with_validate.html.erb +1 -0
- data/app/pb_kits/playbook/pb_form/docs/_form_simple_form.html.erb +2 -0
- data/app/pb_kits/playbook/pb_form/docs/_form_simple_form_validate.html.erb +2 -0
- data/app/pb_kits/playbook/pb_form/form_builder.rb +1 -0
- data/app/pb_kits/playbook/pb_form/form_builder/date_picker_field.rb +20 -0
- data/app/pb_kits/playbook/pb_progress_step/progress_step.rb +2 -2
- data/app/pb_kits/playbook/pb_progress_step/progress_step_item.rb +0 -1
- data/app/pb_kits/playbook/pb_table/table.rb +3 -3
- data/app/pb_kits/playbook/pb_text_input/_text_input.html.erb +1 -0
- data/app/pb_kits/playbook/pb_text_input/_text_input.jsx +21 -17
- data/app/pb_kits/playbook/pb_text_input/_text_input.scss +17 -8
- data/app/pb_kits/playbook/pb_text_input/text_input.rb +2 -0
- data/app/pb_kits/playbook/pb_time/_time.html.erb +23 -17
- data/app/pb_kits/playbook/pb_time/_time.jsx +20 -11
- data/app/pb_kits/playbook/pb_time/_time.scss +16 -8
- data/app/pb_kits/playbook/pb_time/docs/_time_align.html.erb +18 -0
- data/app/pb_kits/playbook/pb_time/docs/_time_align.jsx +3 -3
- data/app/pb_kits/playbook/pb_time/docs/_time_dark.html.erb +70 -0
- data/app/pb_kits/playbook/pb_time/docs/_time_dark.jsx +1 -6
- data/app/pb_kits/playbook/pb_time/docs/_time_default.html.erb +47 -3
- data/app/pb_kits/playbook/pb_time/docs/_time_default.jsx +33 -4
- data/app/pb_kits/playbook/pb_time/docs/_time_sizes.html.erb +11 -0
- data/app/pb_kits/playbook/pb_time/docs/_time_sizes.jsx +19 -0
- data/app/pb_kits/playbook/pb_time/docs/_time_timestamp.html.erb +2 -1
- data/app/pb_kits/playbook/pb_time/docs/_time_timestamp.jsx +0 -7
- data/app/pb_kits/playbook/pb_time/docs/_time_timezone.html.erb +42 -0
- data/app/pb_kits/playbook/pb_time/docs/_time_timezone.jsx +12 -14
- data/app/pb_kits/playbook/pb_time/docs/example.yml +7 -2
- data/app/pb_kits/playbook/pb_time/docs/index.js +1 -0
- data/app/pb_kits/playbook/pb_time/time.rb +14 -2
- data/app/pb_kits/playbook/pb_typeahead/_typeahead.jsx +60 -0
- data/app/pb_kits/playbook/pb_typeahead/_typeahead.scss +20 -3
- data/app/pb_kits/playbook/pb_typeahead/components/Control.jsx +30 -0
- data/app/pb_kits/playbook/pb_typeahead/components/IndicatorsContainer.jsx +13 -0
- data/app/pb_kits/playbook/pb_typeahead/components/MenuList.jsx +12 -0
- data/app/pb_kits/playbook/pb_typeahead/components/MultiValue.jsx +51 -0
- data/app/pb_kits/playbook/pb_typeahead/components/Option.jsx +34 -0
- data/app/pb_kits/playbook/pb_typeahead/components/Placeholder.jsx +13 -0
- data/app/pb_kits/playbook/pb_typeahead/components/ValueContainer.jsx +13 -0
- data/app/pb_kits/playbook/pb_typeahead/docs/_typeahead_default.jsx +22 -0
- data/app/pb_kits/playbook/pb_typeahead/docs/_typeahead_with_pills.jsx +29 -0
- data/app/pb_kits/playbook/pb_typeahead/docs/_typeahead_with_pills_async.jsx +84 -0
- data/app/pb_kits/playbook/pb_typeahead/docs/_typeahead_with_pills_async_summary.jsx +45 -0
- data/app/pb_kits/playbook/pb_typeahead/docs/_typeahead_with_pills_async_users.jsx +101 -0
- data/app/pb_kits/playbook/pb_typeahead/docs/_typeahead_with_pills_summary.jsx +27 -0
- data/app/pb_kits/playbook/pb_typeahead/docs/example.yml +8 -2
- data/app/pb_kits/playbook/pb_typeahead/docs/index.js +4 -0
- data/app/pb_kits/playbook/tokens/_typography.scss +4 -4
- data/app/pb_kits/playbook/vendor.js +6 -0
- data/lib/playbook/version.rb +1 -1
- metadata +71 -8
- data/app/pb_kits/playbook/pb_date/docs/_date_alignment.html.erb +0 -24
- data/app/pb_kits/playbook/pb_date/docs/_date_alignment.jsx +0 -32
- data/app/pb_kits/playbook/pb_date/docs/_date_default_react.jsx +0 -20
- data/app/pb_kits/playbook/pb_date/docs/_date_default_react.md +0 -3
- data/app/pb_kits/playbook/pb_date/docs/_date_variants.html.erb +0 -27
- data/app/pb_kits/playbook/pb_date/docs/_date_variants.jsx +0 -39
@@ -1,9 +1,24 @@
|
|
1
1
|
<%= pb_rails("date", props: {
|
2
2
|
date: Date.today,
|
3
|
+
size: "lg"
|
3
4
|
}) %>
|
4
5
|
|
5
|
-
<br
|
6
|
+
<br>
|
6
7
|
|
7
8
|
<%= pb_rails("date", props: {
|
8
|
-
date:
|
9
|
+
date: DateTime.now
|
10
|
+
}) %>
|
11
|
+
|
12
|
+
<br>
|
13
|
+
|
14
|
+
<%= pb_rails("date", props: {
|
15
|
+
date: DateTime.now,
|
16
|
+
timezone: "Asia/Tokyo"
|
17
|
+
}) %>
|
18
|
+
|
19
|
+
<br>
|
20
|
+
|
21
|
+
<%= pb_rails("date", props: {
|
22
|
+
date: Date.new(2010, 11, 12),
|
23
|
+
size: "xs"
|
9
24
|
}) %>
|
@@ -0,0 +1,28 @@
|
|
1
|
+
import React from 'react'
|
2
|
+
import { Date } from '../../'
|
3
|
+
|
4
|
+
const DateDefault = () => {
|
5
|
+
return (
|
6
|
+
<div>
|
7
|
+
<Date
|
8
|
+
size="lg"
|
9
|
+
value="1995-12-25"
|
10
|
+
/>
|
11
|
+
|
12
|
+
<br />
|
13
|
+
|
14
|
+
<Date
|
15
|
+
value="17 Mar 69"
|
16
|
+
/>
|
17
|
+
|
18
|
+
<br />
|
19
|
+
|
20
|
+
<Date
|
21
|
+
size="xs"
|
22
|
+
value="2020-04-20T04:20:00.000Z"
|
23
|
+
/>
|
24
|
+
</div>
|
25
|
+
)
|
26
|
+
}
|
27
|
+
|
28
|
+
export default DateDefault
|
@@ -3,11 +3,8 @@ examples:
|
|
3
3
|
rails:
|
4
4
|
- date_default: Default
|
5
5
|
- date_timezone: Timezones
|
6
|
-
|
7
|
-
- date_alignment: Alignment
|
6
|
+
|
8
7
|
|
9
8
|
react:
|
10
|
-
-
|
11
|
-
- date_variants: Variants
|
12
|
-
- date_alignment: Alignment
|
9
|
+
- date_default: Default
|
13
10
|
|
@@ -0,0 +1,39 @@
|
|
1
|
+
<%= content_tag(:div,
|
2
|
+
aria: object.aria,
|
3
|
+
class: object.classname + object.error_class,
|
4
|
+
data: object.data,
|
5
|
+
id: object.id) do %>
|
6
|
+
<div class="input_wrapper">
|
7
|
+
<%= pb_rails("text_input", props: {
|
8
|
+
aria: object.input_aria,
|
9
|
+
autocomplete: false,
|
10
|
+
dark: object.dark,
|
11
|
+
data: object.input_data,
|
12
|
+
disabled: object.disable_input,
|
13
|
+
error: object.error,
|
14
|
+
id: object.picker_id,
|
15
|
+
label: object.hide_label ? nil : object.label,
|
16
|
+
name: object.name,
|
17
|
+
placeholder: object.placeholder,
|
18
|
+
required: object.required,
|
19
|
+
type: object.type
|
20
|
+
}) %>
|
21
|
+
<% if !object.hide_icon %>
|
22
|
+
<div
|
23
|
+
class="<%= object.icon_wrapper_class %>"
|
24
|
+
id="cal-icon-<%= object.picker_id %>"
|
25
|
+
>
|
26
|
+
<%= pb_rails("icon", props: {
|
27
|
+
classname: "cal_icon",
|
28
|
+
icon: "calendar-alt"
|
29
|
+
}) %>
|
30
|
+
</div>
|
31
|
+
<% end %>
|
32
|
+
</div>
|
33
|
+
|
34
|
+
<%= javascript_tag do %>
|
35
|
+
window.addEventListener("DOMContentLoaded", () => {
|
36
|
+
datePickerHelper(<%= object.date_picker_config %>)
|
37
|
+
})
|
38
|
+
<% end %>
|
39
|
+
<% end %>
|
@@ -0,0 +1,149 @@
|
|
1
|
+
/* @flow */
|
2
|
+
|
3
|
+
import React, { useEffect } from 'react'
|
4
|
+
import classnames from 'classnames'
|
5
|
+
import { buildAriaProps, buildCss, buildDataProps } from '../utilities/props'
|
6
|
+
import { globalProps } from '../utilities/globalProps.js'
|
7
|
+
import { Icon, TextInput } from '../'
|
8
|
+
import datePickerHelper from './date_picker_helper.js'
|
9
|
+
|
10
|
+
type DatePickerProps = {
|
11
|
+
allowInput?: Boolean,
|
12
|
+
aria?: object,
|
13
|
+
className?: String,
|
14
|
+
dark?: Boolean,
|
15
|
+
data?: object,
|
16
|
+
defaultDate?: String,
|
17
|
+
disableDate?: Array,
|
18
|
+
disableInput?: Boolean,
|
19
|
+
disableRange?: Array,
|
20
|
+
disableWeekdays?: Array,
|
21
|
+
error?: String,
|
22
|
+
format?: String,
|
23
|
+
hideIcon?: Boolean,
|
24
|
+
hideLabel?: Boolean,
|
25
|
+
id?: String,
|
26
|
+
inputAria?: object,
|
27
|
+
inputData?: object,
|
28
|
+
label?: String,
|
29
|
+
maxDate: String,
|
30
|
+
minDate: String,
|
31
|
+
mode?: String,
|
32
|
+
name: String,
|
33
|
+
onChange: (String) => void,
|
34
|
+
pickerId?: String,
|
35
|
+
placeholder?: String,
|
36
|
+
type?: String,
|
37
|
+
yearRange?: Array,
|
38
|
+
}
|
39
|
+
const DatePicker = (props: DatePickerProps) => {
|
40
|
+
const {
|
41
|
+
allowInput = false,
|
42
|
+
aria = {},
|
43
|
+
className,
|
44
|
+
dark = false,
|
45
|
+
data = {},
|
46
|
+
defaultDate = '',
|
47
|
+
disableDate = null,
|
48
|
+
disableInput,
|
49
|
+
disableRange = null,
|
50
|
+
disableWeekdays = null,
|
51
|
+
error,
|
52
|
+
format = 'm/d/Y',
|
53
|
+
hideIcon = false,
|
54
|
+
hideLabel = false,
|
55
|
+
id,
|
56
|
+
inputAria,
|
57
|
+
inputData,
|
58
|
+
label = 'Date Picker',
|
59
|
+
maxDate,
|
60
|
+
minDate,
|
61
|
+
mode = 'single',
|
62
|
+
name,
|
63
|
+
onChange = () => {},
|
64
|
+
pickerId,
|
65
|
+
placeholder,
|
66
|
+
type,
|
67
|
+
yearRange = [ 1900, 2100 ],
|
68
|
+
} = props
|
69
|
+
|
70
|
+
const ariaProps = buildAriaProps(aria)
|
71
|
+
const dataProps = buildDataProps(data)
|
72
|
+
const classes = classnames(
|
73
|
+
buildCss('pb_date_picker_kit'),
|
74
|
+
className,
|
75
|
+
globalProps(props),
|
76
|
+
error ? 'error' : null,
|
77
|
+
)
|
78
|
+
|
79
|
+
useEffect(() => {
|
80
|
+
datePickerHelper({
|
81
|
+
allowInput: allowInput,
|
82
|
+
defaultDate: defaultDate,
|
83
|
+
disableDate: disableDate,
|
84
|
+
disableRange: disableRange,
|
85
|
+
disableWeekdays: disableWeekdays,
|
86
|
+
format: format,
|
87
|
+
hideIcon: hideIcon,
|
88
|
+
maxDate: maxDate,
|
89
|
+
minDate: minDate,
|
90
|
+
mode: mode,
|
91
|
+
pickerId: pickerId,
|
92
|
+
yearRange: yearRange,
|
93
|
+
})
|
94
|
+
}, [])
|
95
|
+
|
96
|
+
const iconWrapperClass = () => {
|
97
|
+
let base = 'cal_icon_wrapper'
|
98
|
+
if (dark){
|
99
|
+
base += ' dark'
|
100
|
+
}
|
101
|
+
if (hideLabel){
|
102
|
+
base += ' no_label_shift'
|
103
|
+
}
|
104
|
+
if (error){
|
105
|
+
base += ' error'
|
106
|
+
}
|
107
|
+
return base
|
108
|
+
}
|
109
|
+
|
110
|
+
return (
|
111
|
+
<div
|
112
|
+
{...ariaProps}
|
113
|
+
{...dataProps}
|
114
|
+
className={classes}
|
115
|
+
id={id}
|
116
|
+
>
|
117
|
+
{className}
|
118
|
+
<div className="input_wrapper">
|
119
|
+
<TextInput
|
120
|
+
aria={inputAria}
|
121
|
+
autoComplete="off"
|
122
|
+
dark={dark}
|
123
|
+
data={inputData}
|
124
|
+
disabled={disableInput}
|
125
|
+
error={error}
|
126
|
+
id={pickerId}
|
127
|
+
label={hideLabel ? null : label}
|
128
|
+
name={name}
|
129
|
+
onChange={onChange}
|
130
|
+
placeholder={placeholder}
|
131
|
+
type={type}
|
132
|
+
/>
|
133
|
+
<If condition={!hideIcon}>
|
134
|
+
<div
|
135
|
+
className={iconWrapperClass()}
|
136
|
+
id={`cal-icon-${pickerId}`}
|
137
|
+
>
|
138
|
+
<Icon
|
139
|
+
className="cal_icon"
|
140
|
+
icon="calendar-alt"
|
141
|
+
/>
|
142
|
+
</div>
|
143
|
+
</If>
|
144
|
+
</div>
|
145
|
+
</div>
|
146
|
+
)
|
147
|
+
}
|
148
|
+
|
149
|
+
export default DatePicker
|
@@ -0,0 +1,33 @@
|
|
1
|
+
@import "../pb_caption/caption_mixin";
|
2
|
+
@import "../pb_textarea/textarea_mixin";
|
3
|
+
@import "../tokens/colors";
|
4
|
+
@import "./sass_partials/flatpickr_styles";
|
5
|
+
|
6
|
+
[class^=pb_date_picker_kit] {
|
7
|
+
.input_wrapper {
|
8
|
+
margin-bottom: $space_sm;
|
9
|
+
position: relative;
|
10
|
+
@import "./sass_partials/calendar_input_icon";
|
11
|
+
@import "./sass_partials/day_styles";
|
12
|
+
@import "./sass_partials/header_styles";
|
13
|
+
@import "./sass_partials/overrides";
|
14
|
+
|
15
|
+
.flatpickr-wrapper {
|
16
|
+
display: block;
|
17
|
+
.text_input.flatpickr-input {
|
18
|
+
text-overflow: ellipsis;
|
19
|
+
padding-right: $space_xl + 10 !important;
|
20
|
+
}
|
21
|
+
// Calendar Shadow and Border
|
22
|
+
.flatpickr-calendar {
|
23
|
+
box-shadow: $shadow_deeper;
|
24
|
+
border: 1px solid $border_light;
|
25
|
+
}
|
26
|
+
// Hide Caret
|
27
|
+
.flatpickr-calendar:before,
|
28
|
+
.flatpickr-calendar:after {
|
29
|
+
content: none;
|
30
|
+
}
|
31
|
+
}
|
32
|
+
}
|
33
|
+
}
|
@@ -0,0 +1,85 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Playbook
|
4
|
+
module PbDatePicker
|
5
|
+
class DatePicker
|
6
|
+
include Playbook::Props
|
7
|
+
|
8
|
+
partial "pb_date_picker/date_picker"
|
9
|
+
|
10
|
+
prop :allow_input, type: Playbook::Props::Boolean,
|
11
|
+
default: false
|
12
|
+
prop :dark, type: Playbook::Props::Boolean,
|
13
|
+
default: false
|
14
|
+
prop :default_date, type: Playbook::Props::String,
|
15
|
+
default: ""
|
16
|
+
prop :disable_date, type: Playbook::Props::Array,
|
17
|
+
default: []
|
18
|
+
prop :disable_input, type: Playbook::Props::Boolean,
|
19
|
+
default: false
|
20
|
+
prop :disable_range, type: Playbook::Props::Array,
|
21
|
+
default: []
|
22
|
+
prop :disable_weekdays, type: Playbook::Props::Array,
|
23
|
+
default: []
|
24
|
+
prop :error, type: Playbook::Props::String
|
25
|
+
prop :format, type: Playbook::Props::String,
|
26
|
+
default: "m/d/Y"
|
27
|
+
prop :hide_icon, type: Playbook::Props::Boolean,
|
28
|
+
default: false
|
29
|
+
prop :hide_label, type: Playbook::Props::Boolean,
|
30
|
+
default: false
|
31
|
+
prop :label, type: Playbook::Props::String,
|
32
|
+
default: "Date Picker"
|
33
|
+
prop :input_aria, type: Playbook::Props::Hash,
|
34
|
+
default: {}
|
35
|
+
prop :input_data, type: Playbook::Props::Hash,
|
36
|
+
default: {}
|
37
|
+
prop :max_date, type: Playbook::Props::String
|
38
|
+
prop :min_date, type: Playbook::Props::String
|
39
|
+
prop :name, type: Playbook::Props::String
|
40
|
+
prop :mode, type: Playbook::Props::String,
|
41
|
+
default: "single"
|
42
|
+
prop :picker_id, type: Playbook::Props::String,
|
43
|
+
required: true
|
44
|
+
prop :placeholder, type: Playbook::Props::String
|
45
|
+
prop :required, type: Playbook::Props::Boolean,
|
46
|
+
default: false
|
47
|
+
prop :type, type: Playbook::Props::String
|
48
|
+
prop :year_range, type: Playbook::Props::Array,
|
49
|
+
default: [1900, 2100]
|
50
|
+
|
51
|
+
def classname
|
52
|
+
generate_classname("pb_date_picker_kit")
|
53
|
+
end
|
54
|
+
|
55
|
+
def date_picker_config
|
56
|
+
{
|
57
|
+
allowInput: allow_input,
|
58
|
+
defaultDate: default_date,
|
59
|
+
disableDate: disable_date,
|
60
|
+
disableRange: disable_range,
|
61
|
+
disableWeekdays: disable_weekdays,
|
62
|
+
format: format,
|
63
|
+
hideIcon: hide_icon,
|
64
|
+
maxDate: max_date,
|
65
|
+
minDate: min_date,
|
66
|
+
mode: mode,
|
67
|
+
pickerId: picker_id,
|
68
|
+
yearRange: year_range,
|
69
|
+
}.to_json.html_safe
|
70
|
+
end
|
71
|
+
|
72
|
+
def error_class
|
73
|
+
error ? " error" : ""
|
74
|
+
end
|
75
|
+
|
76
|
+
def icon_wrapper_class
|
77
|
+
class_string = "cal_icon_wrapper"
|
78
|
+
class_string += " dark" if dark
|
79
|
+
class_string += " no_label_shift" if hide_label
|
80
|
+
class_string += error_class
|
81
|
+
class_string
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
@@ -0,0 +1,165 @@
|
|
1
|
+
import flatpickr from 'flatpickr'
|
2
|
+
|
3
|
+
const datePickerHelper = (config) => {
|
4
|
+
const {
|
5
|
+
allowInput,
|
6
|
+
defaultDate,
|
7
|
+
disableDate,
|
8
|
+
disableRange,
|
9
|
+
disableWeekdays,
|
10
|
+
format,
|
11
|
+
maxDate,
|
12
|
+
minDate,
|
13
|
+
mode,
|
14
|
+
pickerId,
|
15
|
+
yearRange,
|
16
|
+
} = config
|
17
|
+
|
18
|
+
// ===========================================================
|
19
|
+
// | Hook Definitions |
|
20
|
+
// ===========================================================
|
21
|
+
|
22
|
+
const defaultDateGetter = () => {
|
23
|
+
if (defaultDate !== '') {
|
24
|
+
if (defaultDate === 'blank') {
|
25
|
+
return ''
|
26
|
+
} else {
|
27
|
+
return defaultDate
|
28
|
+
}
|
29
|
+
}
|
30
|
+
if (mode === 'single' && defaultDate === '') {
|
31
|
+
return new Date()
|
32
|
+
} else if (mode === 'range' && defaultDate === '') {
|
33
|
+
const today = new Date()
|
34
|
+
const tomorrow = new Date(today)
|
35
|
+
tomorrow.setDate(tomorrow.getDate() + 1)
|
36
|
+
return [today, tomorrow]
|
37
|
+
}
|
38
|
+
}
|
39
|
+
const disabledParser = () => {
|
40
|
+
if (disableDate && disableDate.length > 0) {
|
41
|
+
return disableDate
|
42
|
+
} else if (disableRange && disableRange.length > 0) {
|
43
|
+
return disableRange
|
44
|
+
} else {
|
45
|
+
return []
|
46
|
+
}
|
47
|
+
}
|
48
|
+
const calendarResizer = () => {
|
49
|
+
const cal = document.querySelector(`#cal-${pickerId}.open`)
|
50
|
+
const parentInput = cal.parentElement
|
51
|
+
if (cal.getBoundingClientRect().right > window.innerWidth) {
|
52
|
+
parentInput.style.display = 'flex'
|
53
|
+
parentInput.style.justifyContent = 'center'
|
54
|
+
}
|
55
|
+
if (cal.offsetWidth <= parentInput.offsetWidth) {
|
56
|
+
parentInput.style.display = ''
|
57
|
+
parentInput.style.justifyContent = ''
|
58
|
+
}
|
59
|
+
}
|
60
|
+
|
61
|
+
// ===========================================================
|
62
|
+
// | Flatpickr initializer w/ config |
|
63
|
+
// ===========================================================
|
64
|
+
|
65
|
+
flatpickr(`#${pickerId}`, {
|
66
|
+
disableMobile: true,
|
67
|
+
dateFormat: format,
|
68
|
+
defaultDate: defaultDateGetter(),
|
69
|
+
disable: disableWeekdays && disableWeekdays.length > 0 ? [
|
70
|
+
(date) => {
|
71
|
+
const weekdayObj = {
|
72
|
+
Sunday: 0,
|
73
|
+
Monday: 1,
|
74
|
+
Tuesday: 2,
|
75
|
+
Wednesday: 3,
|
76
|
+
Thursday: 4,
|
77
|
+
Friday: 5,
|
78
|
+
Saturday: 6,
|
79
|
+
}
|
80
|
+
return (
|
81
|
+
date.getDay() === weekdayObj[disableWeekdays[0]] ||
|
82
|
+
date.getDay() === weekdayObj[disableWeekdays[1]] ||
|
83
|
+
date.getDay() === weekdayObj[disableWeekdays[2]] ||
|
84
|
+
date.getDay() === weekdayObj[disableWeekdays[3]] ||
|
85
|
+
date.getDay() === weekdayObj[disableWeekdays[4]] ||
|
86
|
+
date.getDay() === weekdayObj[disableWeekdays[5]] ||
|
87
|
+
date.getDay() === weekdayObj[disableWeekdays[6]]
|
88
|
+
)
|
89
|
+
},
|
90
|
+
] : disabledParser(),
|
91
|
+
maxDate: maxDate,
|
92
|
+
minDate: minDate,
|
93
|
+
mode: mode,
|
94
|
+
nextArrow: '<i class="far fa-angle-right"></i>',
|
95
|
+
onOpen: [() => {
|
96
|
+
calendarResizer()
|
97
|
+
window.addEventListener('resize', calendarResizer)
|
98
|
+
}],
|
99
|
+
onClose: [() => {
|
100
|
+
window.removeEventListener('resize', calendarResizer)
|
101
|
+
}],
|
102
|
+
onYearChange: [],
|
103
|
+
prevArrow: '<i class="far fa-angle-left"></i>',
|
104
|
+
static: true,
|
105
|
+
})
|
106
|
+
|
107
|
+
// ===========================================================
|
108
|
+
// Additional JS Functionality |
|
109
|
+
// ===========================================================
|
110
|
+
|
111
|
+
// Assign dynamically sourced flatpickr instance to variable
|
112
|
+
const picker = document.querySelector(`#${pickerId}`)._flatpickr
|
113
|
+
picker.innerContainer.parentElement.id = `cal-${pickerId}`
|
114
|
+
|
115
|
+
// replace year selector with dropdown
|
116
|
+
picker.yearElements[0].parentElement.innerHTML = `<select class="numInput cur-year" type="number" tabIndex="-1" aria-label="Year" id="year-${pickerId}"></select>`
|
117
|
+
|
118
|
+
// create html option tags for desired years
|
119
|
+
let years = ''
|
120
|
+
for (let year = yearRange[1]; year >= yearRange[0]; year--) {
|
121
|
+
years += `<option value="${year}">${year}</option>`
|
122
|
+
}
|
123
|
+
|
124
|
+
// variablize each dropdown selecttor
|
125
|
+
const dropdown = document.querySelector(`#year-${pickerId}`)
|
126
|
+
|
127
|
+
// inject year options into dropdown and assign it the flatpickr's current year value
|
128
|
+
dropdown.innerHTML = years
|
129
|
+
dropdown.value = picker.currentYear
|
130
|
+
|
131
|
+
// whenever a new year is selected from dropdown update flatpickr's current year value
|
132
|
+
dropdown.addEventListener('input', (e) => {
|
133
|
+
picker.changeYear(Number(e.target.value))
|
134
|
+
})
|
135
|
+
|
136
|
+
// two way binding
|
137
|
+
const yearChangeHook = () => {
|
138
|
+
dropdown.value = picker.currentYear
|
139
|
+
}
|
140
|
+
picker.config.onYearChange.push(yearChangeHook)
|
141
|
+
|
142
|
+
// Adding dropdown icons to year and month selects
|
143
|
+
picker.monthElements[0].insertAdjacentHTML('afterend', '<i class="far fa-angle-down month-dropdown-icon"></i>')
|
144
|
+
dropdown.insertAdjacentHTML('afterend', '<i class="far fa-angle-down year-dropdown-icon" id="test-id"></i>')
|
145
|
+
|
146
|
+
// Set input value attribute on page load
|
147
|
+
picker.input.setAttribute('value', picker.input.value)
|
148
|
+
// logic for updating value when typing
|
149
|
+
document.querySelector(`#${pickerId}`).addEventListener('input', (e) => {
|
150
|
+
picker.input.setAttribute('value', e.target.value)
|
151
|
+
const variant = picker.config.mode
|
152
|
+
if (variant === 'single' && e.target.value.split('').length === 10) {
|
153
|
+
picker.setDate(e.target.value)
|
154
|
+
dropdown.value = picker.currentYear
|
155
|
+
} else if (variant === 'range' && e.target.value.split('').length === 24) {
|
156
|
+
picker.setDate(e.target.value)
|
157
|
+
dropdown.value = picker.currentYear
|
158
|
+
}
|
159
|
+
})
|
160
|
+
if (allowInput){
|
161
|
+
picker.input.removeAttribute('readonly')
|
162
|
+
}
|
163
|
+
}
|
164
|
+
|
165
|
+
export default datePickerHelper
|