playbook_ui 7.0.0.pre.alpha12 → 7.0.0.pre.alpha13

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 94ac0232046d608bf8ae158596a7734d1b67f23fb91b1c64b30baede6f4ad758
4
- data.tar.gz: eed40c32073db9ff048cb4c7b965dbef077058dacaff858e9a753da281fcf881
3
+ metadata.gz: e329711246ae555c5e6e13504fe7489062e64e67be40c0bbc17c473dbd3e7994
4
+ data.tar.gz: 67a8d82f86700372bc6cfb19af7f2f592f12278af0d0731388ff29b2d374dab8
5
5
  SHA512:
6
- metadata.gz: ea8f2b075e31b0bdc0cf3d9dea2b386912492c3d046095e86775e6b54e8368f3af077446962cb0cdf8ba06046ee5d7153cc354cf331f6dd8bc3308888dff529c
7
- data.tar.gz: 771928c8397ce43f9f038b9d64c8e358e1380e7f41fa51770df2742ccef8aee5de38dbd9cf0ec139accf029be26d8d7db8baacda51b7efcb5fc1efaf7845537b
6
+ metadata.gz: 7f0826a7a92bcd1f848ab4e7aea2af39d16d3a030ea28e5e5f83bf8133587f811df372587a1e5fa3c35d1cfd4068414641cc944403d59eb857ed2e62b04580a1
7
+ data.tar.gz: 1ed00c2dff812d1dfbcdc0d4bcf0dba1de40356155632be76255b5fa9ffe985800aa0b62c0a5f6889ef4e2abc4e4fc4c3a31f5c5b347fdc12f46992972ca3958
@@ -3,25 +3,20 @@
3
3
  class: object.classname + object.error_class,
4
4
  data: object.data,
5
5
  id: object.id) do %>
6
- <% if object.children %>
7
- <div class="input_wrapper">
8
- <%= capture(&object.children) %>
9
- <% else %>
10
- <div class="input_wrapper">
11
- <%= pb_rails("text_input", props: {
12
- aria: object.input_aria,
13
- autocomplete: false,
14
- dark: object.dark,
15
- data: object.input_data,
16
- disabled: object.disable_input,
17
- error: object.error,
18
- id: object.picker_id,
19
- label: object.hide_label ? nil : object.label,
20
- name: object.name,
21
- placeholder: object.placeholder,
22
- required: object.required,
23
- }) %>
24
- <% end %>
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
+ }) %>
25
20
  <% if !object.hide_icon %>
26
21
  <div
27
22
  class="<%= object.icon_wrapper_class %>"
@@ -65,6 +65,7 @@ module Playbook
65
65
  minDate: min_date,
66
66
  mode: mode,
67
67
  pickerId: picker_id,
68
+ required: required,
68
69
  yearRange: year_range,
69
70
  }.to_json.html_safe
70
71
  end
@@ -13,29 +13,14 @@ const datePickerHelper = (config) => {
13
13
  mode,
14
14
  onChange = () => {},
15
15
  pickerId,
16
+ required,
16
17
  yearRange,
17
18
  } = config
18
-
19
19
  // ===========================================================
20
20
  // | Hook Definitions |
21
21
  // ===========================================================
22
22
 
23
23
  const defaultDateGetter = () => {
24
- // if (defaultDate !== '') {
25
- // if (defaultDate === 'blank') {
26
- // return ''
27
- // } else {
28
- // return defaultDate
29
- // }
30
- // }
31
- // if (mode === 'single' && defaultDate === '') {
32
- // return new Date()
33
- // } else if (mode === 'range' && defaultDate === '') {
34
- // const today = new Date()
35
- // const tomorrow = new Date(today)
36
- // tomorrow.setDate(tomorrow.getDate() + 1)
37
- // return [today, tomorrow]
38
- // }
39
24
  if (defaultDate === '') {
40
25
  return null
41
26
  } else {
@@ -63,7 +48,6 @@ const datePickerHelper = (config) => {
63
48
  parentInput.style.justifyContent = ''
64
49
  }
65
50
  }
66
-
67
51
  // ===========================================================
68
52
  // | Flatpickr initializer w/ config |
69
53
  // ===========================================================
@@ -107,16 +91,13 @@ const datePickerHelper = (config) => {
107
91
  }],
108
92
  onChange: [(selectedDates, dateStr) => {
109
93
  onChange(dateStr, selectedDates)
110
- },
111
- (selectedDates, dateStr) => {
112
- updateValueOnChange(dateStr)
113
- },
114
- ],
115
- onYearChange: [],
94
+ }],
95
+ onYearChange: [() => {
96
+ yearChangeHook()
97
+ }],
116
98
  prevArrow: '<i class="far fa-angle-left"></i>',
117
99
  static: true,
118
100
  })
119
-
120
101
  // ===========================================================
121
102
  // Additional JS Functionality |
122
103
  // ===========================================================
@@ -146,37 +127,55 @@ const datePickerHelper = (config) => {
146
127
  picker.changeYear(Number(e.target.value))
147
128
  })
148
129
 
130
+ // Allow the date picker form resetting
131
+ if (picker.input.form) {
132
+ picker.input.form.addEventListener('reset', (e) => {
133
+ e.preventDefault()
134
+ if (defaultDate){
135
+ picker.setDate(defaultDate)
136
+ yearChangeHook()
137
+ } else {
138
+ picker.clear()
139
+ }
140
+
141
+ const fields = e.target.querySelectorAll('select, input, textarea')
142
+
143
+ // Prevent year and month dropdowns from being reset
144
+ fields.forEach((field) => {
145
+ if (field == picker.monthsDropdownContainer || field == dropdown || field == picker.input){
146
+ // console.log(field)
147
+ return
148
+ } else {
149
+ field.value = field.defaultValue
150
+ }
151
+ })
152
+ // setTimeout(() => {
153
+ // dropdown.value = picker.currentYear
154
+ // picker.monthsDropdownContainer.value = picker.currentMonth
155
+ // console.log(picker)
156
+ // }, 10)
157
+ })
158
+ }
159
+
149
160
  // two way binding
150
161
  const yearChangeHook = () => {
151
162
  dropdown.value = picker.currentYear
152
163
  }
153
- picker.config.onYearChange.push(yearChangeHook)
154
164
 
155
165
  // Adding dropdown icons to year and month selects
156
166
  picker.monthElements[0].insertAdjacentHTML('afterend', '<i class="far fa-angle-down month-dropdown-icon"></i>')
157
167
  dropdown.insertAdjacentHTML('afterend', '<i class="far fa-angle-down year-dropdown-icon" id="test-id"></i>')
158
168
 
159
- // Set input value attribute on page load
160
- picker.input.setAttribute('value', picker.input.value)
161
- // logic for updating value when typing
162
- document.querySelector(`#${pickerId}`).addEventListener('input', (e) => {
163
- picker.input.setAttribute('value', e.target.value)
164
- const variant = picker.config.mode
165
- if (variant === 'single' && e.target.value.split('').length === 10) {
166
- picker.setDate(e.target.value)
167
- dropdown.value = picker.currentYear
168
- } else if (variant === 'range' && e.target.value.split('').length === 24) {
169
- picker.setDate(e.target.value)
170
- dropdown.value = picker.currentYear
171
- }
172
- })
173
- // Update input value attribute on Change
174
- const updateValueOnChange = (pickerValue) => {
175
- picker.input.setAttribute('value', pickerValue)
176
- }
169
+ // Remove readonly attribute for validation and or text input
177
170
  if (allowInput){
178
171
  picker.input.removeAttribute('readonly')
179
172
  }
173
+ if (required){
174
+ picker.input.removeAttribute('readonly')
175
+ picker.input.addEventListener('keydown', (e) => e.preventDefault())
176
+ picker.input.style.caretColor = 'transparent'
177
+ picker.input.style.cursor = 'pointer'
178
+ }
180
179
  }
181
180
 
182
181
  export default datePickerHelper
@@ -15,7 +15,7 @@
15
15
  <%= pb_rails("date_picker", props: {
16
16
  label: "Blank Placeholder",
17
17
  picker_id: "date-picker-input3",
18
- placeholder: "",
18
+ placeholder: ""
19
19
  }) %>
20
20
 
21
21
  <%= pb_rails("date_picker", props: {
@@ -12,9 +12,7 @@ examples:
12
12
  - date_picker_min_max: Min Max
13
13
  - date_picker_error: Error
14
14
  - date_picker_hooks: Hooks
15
- # - date_picker_allow_input: Allow Input
16
15
  - date_picker_year_range: Year Range
17
- - date_picker_dark: Dark
18
16
 
19
17
 
20
18
  react:
@@ -30,7 +28,5 @@ examples:
30
28
  - date_picker_min_max: Min Max
31
29
  - date_picker_error: Error
32
30
  - date_picker_hooks: Hooks
33
- # - date_picker_allow_input: Allow Input
34
31
  - date_picker_year_range: Year Range
35
- - date_picker_dark: Dark
36
32
 
@@ -10,6 +10,4 @@ export { default as DatePickerDisabled } from './_date_picker_disabled.jsx'
10
10
  export { default as DatePickerMinMax } from './_date_picker_min_max.jsx'
11
11
  export { default as DatePickerError } from './_date_picker_error.jsx'
12
12
  export { default as DatePickerHooks } from './_date_picker_hooks.jsx'
13
- // export { default as DatePickerAllowInput } from './_date_picker_allow_input.jsx'
14
13
  export { default as DatePickerYearRange } from './_date_picker_year_range.jsx'
15
- export { default as DatePickerDark } from './_date_picker_dark.jsx'
@@ -30,6 +30,7 @@
30
30
  <%= pb_rails("form", props: { form_system_options: { scope: :example, method: :get } }) do |form| %>
31
31
  <%= form.text_field :example_text_field, props: { label: true } %>
32
32
  <%= form.collection_select :example_collection_select, example_collection, :value, :name, props: { label: true } %>
33
+ <%= form.date_picker :test_id, props: { label: true }%>
33
34
 
34
35
  <%= form.actions do |action| %>
35
36
  <%= action.submit props: { text: "Apply", data: { disable_with: "<i class='far fa-spinner fa-spin mr-3'></i>Searching...".html_safe },}%>
@@ -33,7 +33,7 @@
33
33
  name: "checkbox-name",
34
34
  class: "checkbox-class"
35
35
  %>
36
- <%= form.date_picker :example_date_picker1, props: { default_date: "blank", label: true } %>
36
+ <%= form.date_picker :example_date_picker_1, props: { default_date: "blank", label: true } %>
37
37
 
38
38
  <%= form.actions do |action| %>
39
39
  <%= action.submit %>
@@ -28,7 +28,7 @@
28
28
  <%= form.select :example_select, [ ["Yes", 1], ["No", 2] ], props: { label: true, blank_selection: "Select One...", required: true } %>
29
29
  <%= form.collection_select :example_collection_select, example_collection, :value, :name, props: { label: true, blank_selection: "Select One...", required: true } %>
30
30
  <%= form.check_box :example_checkbox, props: { text: "Example Checkbox", label: true, required: true } %>
31
- <%= form.date_picker :example_date_picker2, props: { default_date: 'blank', required: true, label: "hello-label" } %>
31
+ <%= form.date_picker :example_date_picker_2, props: { default_date: 'blank', label: true, required: true } %>
32
32
 
33
33
  <%= form.actions do |action| %>
34
34
  <%= action.submit %>
@@ -15,23 +15,12 @@
15
15
  :example_select_field,
16
16
  :example_collection_select_field,
17
17
  :example_checkbox_field,
18
- :example_checkbox_field_2,
19
- :example_date_picker_field_1,
20
- :example_date_picker_field_3
21
-
22
- # for local testing only
23
- # will be removed before merging
24
- def initialize
25
- # @example_number_field = 123
26
- @example_date_picker_field_1 = "10/02/1993"
27
- @example_date_picker_field_3 = Date.today.httpdate
28
- end
18
+ :example_date_picker_field_1
29
19
 
30
20
 
31
21
  def self.model_name
32
22
  ActiveModel::Name.new(self, nil, "ExampleFormModel")
33
23
  end
34
-
35
24
  end
36
25
  %>
37
26
 
@@ -52,7 +41,6 @@
52
41
 
53
42
 
54
43
  <%= pb_rails("form", props: { form_system: "simple_form", form_system_options: [example_form_model.new, url: "", method: :get] }) do |form| %>
55
-
56
44
  <%= form.input :example_text_field, as: :string %>
57
45
  <%= form.input :example_phone_field, as: :tel %>
58
46
  <%= form.input :example_email_field, as: :email %>
@@ -64,9 +52,7 @@
64
52
  <%= form.select :example_select_field, [["Yes", 1], ["No", 2]], props: { label: true } %>
65
53
  <%= form.collection_select :example_collection_select_field, example_collection, :value, :name, props: { label: true } %>
66
54
  <%= form.check_box :example_checkbox_field, props: { text: "Example Checkbox", label: true } %>
67
- <%= form.check_box :example_checkbox_field_2, props: { text: "Example Checkbox", label: true } %>
68
55
  <%= form.date_picker :example_date_picker_field_1, props: { default_date: 'blank', label: true } %>
69
- <%= form.date_picker :example_date_picker_field_3, props: { default_date: 'blank', label: true } %>
70
56
 
71
57
  <%= form.actions do |action| %>
72
58
  <%= action.submit %>
@@ -52,7 +52,7 @@
52
52
  <%= form.select :example_select_field, [["Yes", 1], ["No", 2]], props: { required: true, blank_selection: "Select One...", label: true } %>
53
53
  <%= form.collection_select :example_collection_select_field, example_collection, :value, :name, props: { required: true, blank_selection: "Select One...", label: true } %>
54
54
  <%= form.check_box :example_checkbox_field, props: { text: "Example Checkbox", label: true, required: true } %>
55
- <%= form.date_picker :example_date_picker_field_2, props: { default_date: 'blank', required: true } %>
55
+ <%= form.date_picker :example_date_picker_field_2, props: { default_date: 'blank', label: true, required: true } %>
56
56
 
57
57
  <%= form.actions do |action| %>
58
58
  <%= action.submit %>
@@ -8,44 +8,14 @@ module Playbook
8
8
  prefix = @object_name
9
9
  html_attribute_name = "#{prefix}[#{name}]"
10
10
  html_id = "#{prefix}_#{name}"
11
+ props[:label] = @template.label(@object_name, name) if props[:label] && !props[:label].is_a?(String)
11
12
 
12
13
  props[:name] = html_attribute_name
13
14
  props[:picker_id] = html_id
14
- props[:label] = @template.label(@object_name, name) if props[:label] == true
15
15
 
16
- puts @object.to_json
17
-
18
- input = text_field(
19
- name,
20
- autocomplete: "off",
21
- disabled: props[:disable_input],
22
- data: props[:input_data],
23
- aria: props[:input_aria],
24
- props: {
25
- error: props[:error],
26
- label: props[:label],
27
- placeholder: props[:placeholder],
28
- required: props[:required],
29
- }
30
- )
31
- puts input
32
-
33
- @template.pb_rails("date_picker", props: props) do
34
- input
35
- end
16
+ @template.pb_rails("date_picker", props: props)
36
17
  end
37
18
  end
38
19
  end
39
20
  end
40
21
  end
41
-
42
- # Create text input with rails form helper
43
- # pass options to text input
44
-
45
- # add hidden, implicit prop identifying it as form helper
46
- # inside dp erb, create conditional if check to leave out text_input kit
47
-
48
- # pass that input as a block to @template.pb_rails("date_picker")
49
- # let rails do the magic
50
-
51
- # null value handling
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module Playbook
3
- VERSION = "7.0.0.pre.alpha12"
3
+ VERSION = "7.0.0.pre.alpha13"
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: playbook_ui
3
3
  version: !ruby/object:Gem::Version
4
- version: 7.0.0.pre.alpha12
4
+ version: 7.0.0.pre.alpha13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Power UX
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2020-10-06 00:00:00.000000000 Z
12
+ date: 2020-10-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: actionpack
@@ -680,11 +680,6 @@ files:
680
680
  - app/pb_kits/playbook/pb_date_picker/_date_picker.scss
681
681
  - app/pb_kits/playbook/pb_date_picker/date_picker.rb
682
682
  - app/pb_kits/playbook/pb_date_picker/date_picker_helper.js
683
- - app/pb_kits/playbook/pb_date_picker/docs/_date_picker_allow_input.html.erb
684
- - app/pb_kits/playbook/pb_date_picker/docs/_date_picker_allow_input.jsx
685
- - app/pb_kits/playbook/pb_date_picker/docs/_date_picker_allow_input.md
686
- - app/pb_kits/playbook/pb_date_picker/docs/_date_picker_dark.html.erb
687
- - app/pb_kits/playbook/pb_date_picker/docs/_date_picker_dark.jsx
688
683
  - app/pb_kits/playbook/pb_date_picker/docs/_date_picker_default.html.erb
689
684
  - app/pb_kits/playbook/pb_date_picker/docs/_date_picker_default.jsx
690
685
  - app/pb_kits/playbook/pb_date_picker/docs/_date_picker_default_date.html.erb
@@ -1,4 +0,0 @@
1
- <%= pb_rails("date_picker", props: {
2
- allow_input: true,
3
- picker_id: "date-picker-read-only"
4
- }) %>
@@ -1,13 +0,0 @@
1
- import React from 'react'
2
- import { DatePicker } from '../..'
3
-
4
- const DatePickerAllowInput = () => (
5
- <div>
6
- <DatePicker
7
- allowInput
8
- pickerId="date-picker-read-only"
9
- />
10
- </div>
11
- )
12
-
13
- export default DatePickerAllowInput
@@ -1 +0,0 @@
1
- By default the date picker input can only be modified by picking a date on the calendar. This prop allows your users to manually type in the date.
@@ -1,4 +0,0 @@
1
- <%= pb_rails("date_picker", props: {
2
- dark: true,
3
- picker_id: "date-picker-dark"
4
- }) %>
@@ -1,13 +0,0 @@
1
- import React from 'react'
2
- import { DatePicker } from '../../'
3
-
4
- const DatePickerDark = () => (
5
- <div>
6
- <DatePicker
7
- dark
8
- pickerId="date-picker-dark"
9
- />
10
- </div>
11
- )
12
-
13
- export default DatePickerDark