playbook_ui 14.11.1.pre.alpha.PLAY1750pbcontenttagkitbutton5341 → 14.11.1.pre.alpha.PLAY1751pbcontenttagpt25529

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. checksums.yaml +4 -4
  2. data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_sort_control.md +2 -2
  3. data/app/pb_kits/playbook/pb_date_picker/docs/_date_picker_default_date.md +1 -1
  4. data/app/pb_kits/playbook/pb_draggable/docs/_draggable_with_list_rails.html.erb +3 -9
  5. data/app/pb_kits/playbook/pb_draggable/docs/_draggable_with_list_rails.md +5 -0
  6. data/app/pb_kits/playbook/pb_draggable/docs/_draggable_with_selectable_list_rails.html.erb +38 -0
  7. data/app/pb_kits/playbook/pb_draggable/docs/_draggable_with_selectable_list_rails.md +3 -0
  8. data/app/pb_kits/playbook/pb_draggable/docs/example.yml +1 -0
  9. data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_subtle_variant.md +1 -1
  10. data/app/pb_kits/playbook/pb_file_upload/file_upload.html.erb +1 -6
  11. data/app/pb_kits/playbook/pb_filter/filter.html.erb +1 -5
  12. data/app/pb_kits/playbook/pb_form_group/form_group.html.erb +1 -6
  13. data/app/pb_kits/playbook/pb_form_pill/form_pill.html.erb +1 -1
  14. data/app/pb_kits/playbook/pb_list/item.html.erb +30 -8
  15. data/app/pb_kits/playbook/pb_list/item.rb +7 -0
  16. data/app/pb_kits/playbook/pb_list/list.html.erb +31 -11
  17. data/app/pb_kits/playbook/pb_list/list.rb +4 -0
  18. data/app/pb_kits/playbook/pb_loading_inline/_loading_inline.tsx +6 -1
  19. data/app/pb_kits/playbook/pb_phone_number_input/_phone_number_input.tsx +30 -12
  20. data/app/pb_kits/playbook/pb_phone_number_input/docs/_phone_number_input_format.html.erb +15 -0
  21. data/app/pb_kits/playbook/pb_phone_number_input/docs/_phone_number_input_format.jsx +24 -0
  22. data/app/pb_kits/playbook/pb_phone_number_input/docs/_phone_number_input_format.md +1 -0
  23. data/app/pb_kits/playbook/pb_phone_number_input/docs/example.yml +3 -1
  24. data/app/pb_kits/playbook/pb_phone_number_input/docs/index.js +1 -0
  25. data/app/pb_kits/playbook/pb_phone_number_input/phone_number_input.rb +3 -0
  26. data/app/pb_kits/playbook/pb_phone_number_input/phone_number_input.test.js +20 -1
  27. data/app/pb_kits/playbook/pb_radio/_radio.scss +12 -8
  28. data/app/pb_kits/playbook/pb_radio/docs/_radio_custom_children.jsx +8 -3
  29. data/app/pb_kits/playbook/pb_selectable_list/selectable_list.html.erb +17 -3
  30. data/app/pb_kits/playbook/pb_selectable_list/selectable_list.rb +3 -0
  31. data/app/pb_kits/playbook/pb_selectable_list/selectable_list_item.html.erb +11 -4
  32. data/app/pb_kits/playbook/pb_selectable_list/selectable_list_item.rb +3 -0
  33. data/app/pb_kits/playbook/pb_table/_table.tsx +2 -3
  34. data/app/pb_kits/playbook/pb_table/docs/_table_sticky_columns.html.erb +74 -0
  35. data/app/pb_kits/playbook/pb_table/docs/_table_sticky_columns_rails.md +3 -0
  36. data/app/pb_kits/playbook/pb_table/docs/_table_sticky_left_columns_rails.md +2 -2
  37. data/app/pb_kits/playbook/pb_table/docs/_table_sticky_right_columns.html.erb +74 -0
  38. data/app/pb_kits/playbook/pb_table/docs/_table_sticky_right_columns_rails.md +3 -0
  39. data/app/pb_kits/playbook/pb_table/docs/example.yml +2 -0
  40. data/app/pb_kits/playbook/pb_table/index.ts +93 -34
  41. data/app/pb_kits/playbook/pb_table/styles/_scroll.scss +6 -5
  42. data/app/pb_kits/playbook/pb_table/table.html.erb +1 -1
  43. data/app/pb_kits/playbook/pb_table/table.rb +17 -2
  44. data/app/pb_kits/playbook/pb_table/utilities/addDataTitle.ts +22 -0
  45. data/app/pb_kits/playbook/pb_timeline/_timeline.scss +30 -30
  46. data/dist/chunks/{_typeahead-BNULwihE.js → _typeahead-TN5aDUj9.js} +2 -2
  47. data/dist/chunks/_weekday_stacked-BcnpLG66.js +45 -0
  48. data/dist/chunks/{lib-B7sgJtGS.js → lib-OFT985dg.js} +2 -2
  49. data/dist/chunks/{pb_form_validation-C5Cc0-1v.js → pb_form_validation-CrsXd1-Y.js} +1 -1
  50. data/dist/chunks/vendor.js +1 -1
  51. data/dist/playbook-doc.js +1 -1
  52. data/dist/playbook-rails-react-bindings.js +1 -1
  53. data/dist/playbook-rails.js +1 -1
  54. data/dist/playbook.css +1 -1
  55. data/lib/playbook/version.rb +1 -1
  56. metadata +34 -9
  57. data/dist/chunks/_weekday_stacked-BKWemDAe.js +0 -45
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d4151d717eddca9843cbee0cfc1bb9749f739689a6b2e59dc4008a54f93abeba
4
- data.tar.gz: 96d539dc7f12d61d3a1ef76e6018731f7f244ef9972e21d81c404e85a292405d
3
+ metadata.gz: 5e7aeb4eded2d7207beaad9aaac806a7287567e5fa319c711e37c0b6e7fb5a06
4
+ data.tar.gz: af7059a43605656c61fea4ee409ae64a7adf807fb655aafdc760027c45b0afcf
5
5
  SHA512:
6
- metadata.gz: c4ca0515955bc7b8f7b2e1b235e3361e6e9cfe8ef38e7e2969aa99196439399ba473b0e7d75cab6ad617813bff735c00d9782762d57090cbf45d2b13efa2dd18
7
- data.tar.gz: 26428d2ec5528dcdf8b5d7efb8935e4efe7726c848502bc54847f1bc251ac06d30df8de8a1b32567b7f851a73789c57a51f4141dbc7f2179f00a2b6f67084c9c
6
+ metadata.gz: 855ee14b770f338f48795930c8aa870974b3a524b6a2d87cafd20b8d397cc08343acc0005ff6a7e49cfa0b287dc6153154e7ef361ea01e26f050a7ee47eadf5b
7
+ data.tar.gz: 7cf27552a3d85aa92fb440ee752fe8cf5b2b7cd153ee4ca558209ecb6821075e461f41e852ab1714ddbbf87d27c610c3da9d0b9765c666e03d4d0b1830764b96
@@ -1,3 +1,3 @@
1
- `sortControl` is an optional prop that can be used to gain greater control over the sort state of the Advanced Table. Tanstack handles sort itself, however it does provide for a way to handle the state manually if needed. Usecases for this include needing to store the sort state so it persists on page reload, set an initial sort state, etc.
1
+ `sortControl` is an optional prop that can be used to gain greater control over the sort state of the Advanced Table. Tanstack handles sort itself, however it does provide for a way to handle the state manually if needed. Usecases for this include needing to store the sort state so it persists on page reload, set an initial sort state, etc.
2
2
 
3
- The sort state must be an object with a single key/value pair, with the key being "desc" and the value being a boolean. The default for sort directino is `desc: true`.
3
+ The sort state must be an object with a single key/value pair, with the key being "desc" and the value being a boolean. The default for sort direction is `desc: true`.
@@ -2,4 +2,4 @@ The `defaultDate`/`default_date` prop has a null or empty string value by defaul
2
2
 
3
3
  If you use a Date object without UTC time standardization the Date Picker kit may misinterpret that date as yesterdays date (consequence of timezone differentials and the Javascript Date Object constructor). See [this GitHub issue for more information](https://github.com/powerhome/playbook/issues/1167) and the anti-pattern examples below.
4
4
 
5
-
5
+ You can leverage the `defaultDate`/`default_date` prop with custom logic in your filter or controller files where the determination of the default value changes based on user interaction. The page can load with an initial default date picker value or placeholder text, then after filter submission save the submitted values as the "new default" (via state or params).
@@ -6,14 +6,8 @@
6
6
 
7
7
  ] %>
8
8
 
9
- <%= pb_rails("draggable", props: {initial_items: initial_items}) do %>
10
- <%= pb_rails("draggable/draggable_container") do %>
11
- <%= pb_rails("list", props: {ordered: false}) do %>
12
- <% initial_items.each do |item| %>
13
- <%= pb_rails("draggable/draggable_item", props:{drag_id: item[:id]}) do %>
14
- <%= pb_rails("list/item") do %><%= item[:name] %><% end %>
15
- <% end %>
16
- <% end %>
17
- <% end %>
9
+ <%= pb_rails("list", props: { enable_drag: true, items: initial_items }) do %>
10
+ <% initial_items.each do |item| %>
11
+ <%= pb_rails("list/item", props:{drag_id: item[:id]}) do %><%= item[:name] %><% end %>
18
12
  <% end %>
19
13
  <% end %>
@@ -0,0 +1,5 @@
1
+ For a simplified version of the Draggable API for the List kit, you can do the following:
2
+
3
+ The List kit is optimized to work with the draggable kit. To enable drag, use the `enable_drag` prop on List kit with an array of the included items AND `drag_id` prop on ListItems. You will also need to include the `items` prop containing your array of listed items for the Draggable API.
4
+
5
+ An additional optional boolean prop (set to true by default) of `drag_handle` is also available on ListItem kit to show the drag handle icon.
@@ -0,0 +1,38 @@
1
+ <%= pb_rails("selectable_list",
2
+ props: {
3
+ enable_drag: true,
4
+ variant: "radio",
5
+ items: [
6
+ { drag_id: "41",
7
+ text: "Task 1",
8
+ input_options: {
9
+ value: "1",
10
+ name: "radio-name",
11
+ }
12
+ },
13
+ { drag_id: "42",
14
+ text: "Task 2",
15
+ checked: true,
16
+ input_options: {
17
+ value: "2",
18
+ name: "radio-name",
19
+ }
20
+ },
21
+ { drag_id: "43",
22
+ text: "Task 3",
23
+ input_options: {
24
+ value: "3",
25
+ name: "radio-name",
26
+ }
27
+ },
28
+ { drag_id: "44",
29
+ text: "Task 4",
30
+ input_options: {
31
+ value: "4",
32
+ name: "radio-name",
33
+ }
34
+ }
35
+ ]
36
+ }
37
+ )
38
+ %>
@@ -0,0 +1,3 @@
1
+ For a simplified version of the Draggable API for the SelectableList kit, you can do the following:
2
+
3
+ The SelectableList kit is optimized to work with the draggable kit. To enable drag, use the `enable_drag` prop on SelectableList kit AND `drag_id` prop within the SelectableList kit prop. An additional optional boolean prop (set to true by default) of `drag_handle` is also available on SelectableList kit to show the drag handle icon.
@@ -11,6 +11,7 @@ examples:
11
11
  rails:
12
12
  - draggable_default_rails: Default
13
13
  - draggable_with_list_rails: Draggable with List Kit
14
+ - draggable_with_selectable_list_rails: Draggable with SelectableList Kit
14
15
  - draggable_with_cards_rails: Draggable with Cards
15
16
 
16
17
 
@@ -1 +1 @@
1
- For the `subtle` variant, it is recommended that you set the `Separators` prop to `false` to remove the separator lines between the options for a more cleaner look.
1
+ For the `subtle` variant, it is recommended that you set the `Separators` prop to `false` to remove the separator lines between the options for a cleaner look.
@@ -1,9 +1,4 @@
1
- <%= content_tag("div",
2
- aria: object.aria,
3
- class: object.classname,
4
- data: object.data,
5
- id: object.id,
6
- **combined_html_options) do %>
1
+ <%= pb_content_tag(:div) do %>
7
2
  <%= pb_rails("form_group", props: {cursor: "pointer", full_width: object.full_width}) do %>
8
3
  <label
9
4
  for="upload-<%= object.id %>"
@@ -1,8 +1,4 @@
1
- <%= content_tag(:div,
2
- id: object.id,
3
- data: object.data,
4
- class: object.classname,
5
- **combined_html_options) do %>
1
+ <%= pb_content_tag(:div) do %>
6
2
  <%= object.wrapper do %>
7
3
  <%= pb_rails("flex", props: { orientation: "row", padding_right: "lg", vertical: "center" }) do %>
8
4
  <% if (object.template != "sort_only") %>
@@ -1,8 +1,3 @@
1
- <%= content_tag(:div,
2
- aria: object.aria,
3
- class: object.classname,
4
- data: object.data,
5
- id: object.id,
6
- **combined_html_options) do %>
1
+ <%= pb_content_tag(:div) do %>
7
2
  <%= content.presence %>
8
3
  <% end %>
@@ -1,4 +1,4 @@
1
- <%= content_tag(:div, id: object.id, data: object.data, class: object.classname + object.size_class, tabindex: object.tabindex, **combined_html_options) do %>
1
+ <%= pb_content_tag(:div, class: object.classname + object.size_class, tabindex: object.tabindex) do %>
2
2
  <% if object.name.present? %>
3
3
  <%= pb_rails("avatar", props: { name: object.name, image_url: object.avatar_url, size: "xxs" }) %>
4
4
  <% if object.truncate %>
@@ -1,10 +1,32 @@
1
- <%= content_tag(:li,
2
- aria: object.aria,
3
- class: object.classname,
4
- data: object.data,
5
- id: object.id,
6
- tabindex: object.tabindex,
7
- **combined_html_options
8
- ) do %>
1
+ <% if object.draggable? %>
2
+ <%= pb_rails("draggable/draggable_item", props:{drag_id: object.drag_id}) do %>
3
+ <%= content_tag(:li,
4
+ aria: object.aria,
5
+ class: object.classname,
6
+ data: object.data,
7
+ id: object.id,
8
+ tabindex: object.tabindex,
9
+ **combined_html_options
10
+ ) do %>
11
+ <% if object.drag_handle %>
12
+ <span style="vertical-align: middle;">
13
+ <%= pb_rails("body") do %>
14
+ <svg width="auto" height="auto" viewBox="0 0 31 25" fill="none" xmlns="http://www.w3.org/2000/svg" color="currentColor" class="pb_custom_icon svg-inline--fa vertical_align_middle svg_fw"><path d="M12.904 6.355a1.48 1.48 0 01-1.5-1.5c0-.796.656-1.5 1.5-1.5.797 0 1.5.704 1.5 1.5 0 .844-.703 1.5-1.5 1.5zm0 7.5a1.48 1.48 0 01-1.5-1.5c0-.796.656-1.5 1.5-1.5.797 0 1.5.704 1.5 1.5 0 .844-.703 1.5-1.5 1.5zm1.5 6c0 .844-.703 1.5-1.5 1.5a1.48 1.48 0 01-1.5-1.5c0-.796.656-1.5 1.5-1.5.797 0 1.5.704 1.5 1.5zm4.5-13.5a1.48 1.48 0 01-1.5-1.5c0-.796.657-1.5 1.5-1.5.797 0 1.5.704 1.5 1.5 0 .844-.703 1.5-1.5 1.5zm1.5 6c0 .844-.703 1.5-1.5 1.5a1.48 1.48 0 01-1.5-1.5c0-.796.657-1.5 1.5-1.5.797 0 1.5.704 1.5 1.5zm-1.5 9a1.48 1.48 0 01-1.5-1.5c0-.796.657-1.5 1.5-1.5.797 0 1.5.704 1.5 1.5 0 .844-.703 1.5-1.5 1.5z" fill="#242B42"></path></svg>
15
+ <% end %>
16
+ </span>
17
+ <% end %>
18
+ <%= content.presence %>
19
+ <% end %>
20
+ <% end %>
21
+ <% else %>
22
+ <%= content_tag(:li,
23
+ aria: object.aria,
24
+ class: object.classname,
25
+ data: object.data,
26
+ id: object.id,
27
+ tabindex: object.tabindex,
28
+ **combined_html_options
29
+ ) do %>
9
30
  <%= content.presence %>
31
+ <% end %>
10
32
  <% end %>
@@ -3,11 +3,18 @@
3
3
  module Playbook
4
4
  module PbList
5
5
  class Item < Playbook::KitBase
6
+ prop :drag_handle, type: Playbook::Props::Boolean,
7
+ default: true
8
+ prop :drag_id, type: Playbook::Props::String
6
9
  prop :tabindex
7
10
 
8
11
  def classname
9
12
  generate_classname("pb_item_kit")
10
13
  end
14
+
15
+ def draggable?
16
+ drag_id.present?
17
+ end
11
18
  end
12
19
  end
13
20
  end
@@ -1,13 +1,33 @@
1
- <%= content_tag(:div, class: object.list_classname) do %>
2
- <%= content_tag(:"#{object.ordered_class}",
3
- aria: object.aria,
4
- class: object.classname,
5
- data: object.data,
6
- id: object.id,
7
- role: object.role,
8
- tabindex: object.tabindex,
9
- **combined_html_options
10
- ) do %>
11
- <%= content.presence %>
1
+ <% if object.enable_drag %>
2
+ <%= pb_rails("draggable", props: {initial_items: object.items}) do %>
3
+ <%= pb_rails("draggable/draggable_container") do %>
4
+ <%= content_tag(:div, class: object.list_classname) do %>
5
+ <%= content_tag(:"#{object.ordered_class}",
6
+ aria: object.aria,
7
+ class: object.classname,
8
+ data: object.data,
9
+ id: object.id,
10
+ role: object.role,
11
+ tabindex: object.tabindex,
12
+ **combined_html_options
13
+ ) do %>
14
+ <%= content.presence %>
15
+ <% end %>
16
+ <% end %>
17
+ <% end %>
18
+ <% end %>
19
+ <% else %>
20
+ <%= content_tag(:div, class: object.list_classname) do %>
21
+ <%= content_tag(:"#{object.ordered_class}",
22
+ aria: object.aria,
23
+ class: object.classname,
24
+ data: object.data,
25
+ id: object.id,
26
+ role: object.role,
27
+ tabindex: object.tabindex,
28
+ **combined_html_options
29
+ ) do %>
30
+ <%= content.presence %>
31
+ <% end %>
12
32
  <% end %>
13
33
  <% end %>
@@ -7,6 +7,10 @@ module Playbook
7
7
  default: false
8
8
  prop :dark, type: Playbook::Props::Boolean,
9
9
  default: false
10
+ prop :enable_drag, type: Playbook::Props::Boolean,
11
+ default: false
12
+ prop :items, type: Playbook::Props::Array,
13
+ default: []
10
14
  prop :layout, type: Playbook::Props::Enum,
11
15
  values: ["left", "right", ""],
12
16
  default: ""
@@ -12,6 +12,7 @@ type LoadingInlineProps = {
12
12
  aria?: { [key: string]: string },
13
13
  className?: string,
14
14
  data?: { [key: string]: string },
15
+ dark?: boolean,
15
16
  htmlOptions?: {[key: string]: string | number | boolean | (() => void)},
16
17
  id?: string,
17
18
  text?: string,
@@ -23,6 +24,7 @@ const LoadingInline = (props: LoadingInlineProps) => {
23
24
  aria = {},
24
25
  className,
25
26
  data = {},
27
+ dark = false,
26
28
  htmlOptions = {},
27
29
  id,
28
30
  text = ' Loading',
@@ -45,7 +47,10 @@ const LoadingInline = (props: LoadingInlineProps) => {
45
47
  className={classes}
46
48
  id={id}
47
49
  >
48
- <Body color="light">
50
+ <Body
51
+ color="light"
52
+ dark={dark}
53
+ >
49
54
  <Icon
50
55
  aria={{ label: 'loading icon' }}
51
56
  fixedWidth
@@ -35,6 +35,7 @@ type PhoneNumberInputProps = {
35
35
  preferredCountries?: string[],
36
36
  required?: boolean,
37
37
  value?: string,
38
+ formatAsYouType?: boolean,
38
39
  }
39
40
 
40
41
  enum ValidationError {
@@ -87,6 +88,7 @@ const PhoneNumberInput = (props: PhoneNumberInputProps, ref?: React.MutableRefOb
87
88
  required = false,
88
89
  preferredCountries = [],
89
90
  value = "",
91
+ formatAsYouType = false,
90
92
  } = props
91
93
 
92
94
  const ariaProps = buildAriaProps(aria)
@@ -99,8 +101,8 @@ const PhoneNumberInput = (props: PhoneNumberInputProps, ref?: React.MutableRefOb
99
101
  )
100
102
 
101
103
  const inputRef = useRef<HTMLInputElement>()
104
+ const itiRef = useRef<any>(null);
102
105
  const [inputValue, setInputValue] = useState(value)
103
- const [itiInit, setItiInit] = useState<any>()
104
106
  const [error, setError] = useState(props.error)
105
107
  const [dropDownIsOpen, setDropDownIsOpen] = useState(false)
106
108
  const [selectedData, setSelectedData] = useState()
@@ -130,8 +132,12 @@ const PhoneNumberInput = (props: PhoneNumberInputProps, ref?: React.MutableRefOb
130
132
  }
131
133
  })
132
134
 
135
+ const unformatNumber = (formattedNumber: any) => {
136
+ return formattedNumber.replace(/\D/g, "")
137
+ }
138
+
133
139
  const showFormattedError = (reason = '') => {
134
- const countryName = itiInit.getSelectedCountryData().name
140
+ const countryName = itiRef.current.getSelectedCountryData().name
135
141
  const reasonText = reason.length > 0 ? ` (${reason})` : ''
136
142
  setError(`Invalid ${countryName} phone number${reasonText}`)
137
143
  return true
@@ -189,12 +195,12 @@ const PhoneNumberInput = (props: PhoneNumberInputProps, ref?: React.MutableRefOb
189
195
  }
190
196
 
191
197
  const validateErrors = () => {
192
- if (itiInit) isValid(itiInit.isValidNumber())
193
- if (validateOnlyNumbers(itiInit)) return
194
- if (validateTooLongNumber(itiInit)) return
195
- if (validateTooShortNumber(itiInit)) return
196
- if (validateUnhandledError(itiInit)) return
197
- if (validateMissingAreaCode(itiInit)) return
198
+ if (itiRef.current) isValid(itiRef.current.isValidNumber())
199
+ if (validateOnlyNumbers(itiRef.current)) return
200
+ if (validateTooLongNumber(itiRef.current)) return
201
+ if (validateTooShortNumber(itiRef.current)) return
202
+ if (validateUnhandledError(itiRef.current)) return
203
+ if (validateMissingAreaCode(itiRef.current)) return
198
204
  }
199
205
 
200
206
  const getCurrentSelectedData = (itiInit: any, inputValue: string) => {
@@ -203,10 +209,16 @@ const PhoneNumberInput = (props: PhoneNumberInputProps, ref?: React.MutableRefOb
203
209
 
204
210
  const handleOnChange = (evt: React.ChangeEvent<HTMLInputElement>) => {
205
211
  setInputValue(evt.target.value)
206
- const phoneNumberData = getCurrentSelectedData(itiInit, evt.target.value)
212
+ let phoneNumberData
213
+ if (formatAsYouType) {
214
+ const formattedPhoneNumberData = getCurrentSelectedData(itiRef.current, evt.target.value)
215
+ phoneNumberData = {...formattedPhoneNumberData, number: unformatNumber(formattedPhoneNumberData.number)}
216
+ } else {
217
+ phoneNumberData = getCurrentSelectedData(itiRef.current, evt.target.value)
218
+ }
207
219
  setSelectedData(phoneNumberData)
208
220
  onChange(phoneNumberData)
209
- isValid(itiInit.isValidNumber())
221
+ isValid(itiRef.current.isValidNumber())
210
222
  }
211
223
 
212
224
  // Separating Concerns as React Docs Recommend
@@ -230,9 +242,11 @@ const PhoneNumberInput = (props: PhoneNumberInputProps, ref?: React.MutableRefOb
230
242
  onlyCountries,
231
243
  countrySearch: false,
232
244
  fixDropdownWidth: false,
233
- formatAsYouType: false,
245
+ formatAsYouType: formatAsYouType,
234
246
  })
235
247
 
248
+ itiRef.current = telInputInit;
249
+
236
250
  inputRef.current.addEventListener("countrychange", (evt: Event) => {
237
251
  const phoneNumberData = getCurrentSelectedData(telInputInit, (evt.target as HTMLInputElement).value)
238
252
  setSelectedData(phoneNumberData)
@@ -243,7 +257,11 @@ const PhoneNumberInput = (props: PhoneNumberInputProps, ref?: React.MutableRefOb
243
257
  inputRef.current.addEventListener("open:countrydropdown", () => setDropDownIsOpen(true))
244
258
  inputRef.current.addEventListener("close:countrydropdown", () => setDropDownIsOpen(false))
245
259
 
246
- setItiInit(telInputInit)
260
+ if (formatAsYouType) {
261
+ inputRef.current?.addEventListener("input", (evt) => {
262
+ handleOnChange(evt as unknown as React.ChangeEvent<HTMLInputElement>);
263
+ });
264
+ }
247
265
  }, [])
248
266
 
249
267
  let textInputProps: {[key: string]: any} = {
@@ -0,0 +1,15 @@
1
+ <%= pb_rails("phone_number_input", props: {
2
+ id: "phone_number_input",
3
+ format_as_you_type: true
4
+ }) %>
5
+
6
+ <%= pb_rails("button", props: {id: "clickable", text: "Save Phone Number"}) %>
7
+
8
+ <%= javascript_tag do %>
9
+ document.querySelector('#clickable').addEventListener('click', () => {
10
+ const formattedPhoneNumber = document.querySelector('#phone_number_input').value
11
+ const unformattedPhoneNumber = formattedPhoneNumber.replace(/\D/g, "")
12
+
13
+ alert(`Formatted: ${formattedPhoneNumber}. Unformatted: ${unformattedPhoneNumber}`)
14
+ })
15
+ <% end %>
@@ -0,0 +1,24 @@
1
+ import React, { useState } from "react";
2
+ import { PhoneNumberInput, Body } from "playbook-ui";
3
+
4
+ const PhoneNumberInputFormat = (props) => {
5
+ const [phoneNumber, setPhoneNumber] = useState("");
6
+
7
+ const handleOnChange = ({ number }) => {
8
+ setPhoneNumber(number);
9
+ };
10
+
11
+ return (
12
+ <>
13
+ <PhoneNumberInput
14
+ formatAsYouType
15
+ id="format"
16
+ onChange={handleOnChange}
17
+ {...props}
18
+ />
19
+ {phoneNumber && <Body>Unformatted number: {phoneNumber}</Body>}
20
+ </>
21
+ );
22
+ };
23
+
24
+ export default PhoneNumberInputFormat;
@@ -0,0 +1 @@
1
+ NOTE: the `number` in the React `onChange` event will not include formatting (no spaces, dashes, and parentheses). For Rails, the `value` will include formatting and its value must be sanitized manually.
@@ -8,10 +8,12 @@ examples:
8
8
  - phone_number_input_validation: Form Validation
9
9
  - phone_number_input_clear_field: Clearing the Input Field
10
10
  - phone_number_input_access_input_element: Accessing the Input Element
11
+ - phone_number_input_format: Format as You Type
11
12
 
12
13
  rails:
13
14
  - phone_number_input_default: Default
14
15
  - phone_number_input_preferred_countries: Preferred Countries
15
16
  - phone_number_input_initial_country: Initial Country
16
17
  - phone_number_input_only_countries: Limited Countries
17
- - phone_number_input_validation: Form Validation
18
+ - phone_number_input_validation: Form Validation
19
+ - phone_number_input_format: Format as You Type
@@ -5,3 +5,4 @@ export { default as PhoneNumberInputOnlyCountries } from './_phone_number_input_
5
5
  export { default as PhoneNumberInputValidation } from './_phone_number_input_validation'
6
6
  export { default as PhoneNumberInputClearField } from './_phone_number_input_clear_field'
7
7
  export { default as PhoneNumberInputAccessInputElement } from './_phone_number_input_access_input_element'
8
+ export { default as PhoneNumberInputFormat } from './_phone_number_input_format'
@@ -21,6 +21,8 @@ module Playbook
21
21
  default: ""
22
22
  prop :value, type: Playbook::Props::String,
23
23
  default: ""
24
+ prop :format_as_you_type, type: Playbook::Props::Boolean,
25
+ default: false
24
26
 
25
27
  def classname
26
28
  generate_classname("pb_phone_number_input")
@@ -32,6 +34,7 @@ module Playbook
32
34
  dark: dark,
33
35
  disabled: disabled,
34
36
  error: error,
37
+ formatAsYouType: format_as_you_type,
35
38
  initialCountry: initial_country,
36
39
  label: label,
37
40
  name: name,
@@ -1,5 +1,5 @@
1
1
  import React from "react";
2
- import { render, screen } from "../utilities/test-utils";
2
+ import { render, screen, act } from "../utilities/test-utils";
3
3
  import PhoneNumberInput from "./_phone_number_input";
4
4
 
5
5
  const testId = "phoneNumberInput";
@@ -120,3 +120,22 @@ test("should trigger callback", () => {
120
120
 
121
121
  expect(handleOnValidate).toBeCalledWith(true)
122
122
  });
123
+
124
+ test("should format phone number as '555-555-5555' with formatAsYouType and 'us' country", () => {
125
+ const props = {
126
+ initialCountry: 'us',
127
+ formatAsYouType: true,
128
+ id: testId,
129
+ };
130
+
131
+ render(<PhoneNumberInput {...props} />);
132
+
133
+ const input = screen.getByRole("textbox");
134
+
135
+ act(() => {
136
+ input.value = "5555555555";
137
+ input.dispatchEvent(new Event('input', { bubbles: true }));
138
+ });
139
+
140
+ expect(input.value).toBe("555-555-5555");
141
+ });
@@ -4,7 +4,7 @@
4
4
  @import "../pb_body/body";
5
5
  @import "../tokens/transition";
6
6
 
7
- [class^=pb_radio_kit] {
7
+ [class^="pb_radio_kit"] {
8
8
  display: inline-flex;
9
9
  cursor: pointer;
10
10
 
@@ -16,10 +16,11 @@
16
16
  border-radius: 1000px;
17
17
  border: 2px solid $border_light;
18
18
  margin-right: $space_xs;
19
- transition: background $transition_default ease, box-shadow $transition_default ease, border-color $transition_default ease;
19
+ transition: background $transition_default ease,
20
+ box-shadow $transition_default ease, border-color $transition_default ease;
20
21
  }
21
22
 
22
- @media (hover:hover) {
23
+ @media (hover: hover) {
23
24
  &:hover .pb_radio_button {
24
25
  background-color: $bg_light;
25
26
  border-color: $border_light;
@@ -52,14 +53,14 @@
52
53
  }
53
54
  }
54
55
 
55
- &:disabled:checked + .pb_radio_button{
56
+ &:disabled:checked + .pb_radio_button {
56
57
  cursor: not-allowed;
57
58
  background-color: $white;
58
59
  border: 6px solid $neutral;
59
60
  }
60
61
  }
61
62
 
62
- &[class*=vertical] {
63
+ &[class*="vertical"] {
63
64
  flex-direction: column;
64
65
  align-items: center;
65
66
  .pb_radio_button {
@@ -80,7 +81,7 @@
80
81
  }
81
82
  &:checked {
82
83
  & ~ .pb_radio_button {
83
- border: 6px solid $primary;
84
+ border: 6px solid $active_dark;
84
85
  }
85
86
  }
86
87
 
@@ -103,10 +104,10 @@
103
104
  }
104
105
  }
105
106
 
106
- @media (hover:hover) {
107
+ @media (hover: hover) {
107
108
  &:hover {
108
109
  .pb_radio_button {
109
- background-color: rgba($white,.10);
110
+ background-color: rgba($white, 0.1);
110
111
  border-color: $border_dark;
111
112
  }
112
113
  }
@@ -115,6 +116,9 @@
115
116
  > .pb_radio_button {
116
117
  border-color: $error_dark;
117
118
  }
119
+ > .pb_body_kit_negative {
120
+ color: $error_dark;
121
+ }
118
122
  }
119
123
  }
120
124
  &.error {
@@ -29,6 +29,7 @@ const RadioChildren = (props) => {
29
29
  marginBottom="none"
30
30
  minWidth="xs"
31
31
  options={options}
32
+ {...props}
32
33
  />
33
34
  </Radio>
34
35
  <Radio
@@ -40,10 +41,11 @@ const RadioChildren = (props) => {
40
41
  value="Typeahead"
41
42
  {...props}
42
43
  >
43
- <Typeahead
44
+ <Typeahead
44
45
  marginBottom="none"
45
46
  minWidth="xs"
46
47
  options={options}
48
+ {...props}
47
49
  />
48
50
  </Radio>
49
51
  <Radio
@@ -54,9 +56,12 @@ const RadioChildren = (props) => {
54
56
  value="Typography"
55
57
  {...props}
56
58
  >
57
- <Title text="Custom Typography" />
59
+ <Title
60
+ text="Custom Typography"
61
+ {...props}
62
+ />
58
63
  </Radio>
59
64
  </div>
60
65
  )
61
66
  }
62
- export default RadioChildren
67
+ export default RadioChildren
@@ -4,9 +4,23 @@
4
4
  data: object.data,
5
5
  id: object.id,
6
6
  **combined_html_options) do %>
7
- <%= pb_rails("list") do %>
8
- <% object.items.each do |item| %>
9
- <%= pb_rails("selectable_list/selectable_list_item", props: item.merge(variant: object.variant, id: object.get_id(item)) )%>
7
+ <% if enable_drag %>
8
+ <%= pb_rails("draggable", props: {initial_items: object.items}) do %>
9
+ <%= pb_rails("draggable/draggable_container") do %>
10
+ <%= pb_rails("list", props: {ordered: false}) do %>
11
+ <% object.items.each do |item| %>
12
+ <%= pb_rails("draggable/draggable_item", props: {drag_id: item[:drag_id]}) do %>
13
+ <%= pb_rails("selectable_list/selectable_list_item", props: item.merge(variant: object.variant, id: object.get_id(item), drag_id: item[:drag_id]) )%>
14
+ <% end %>
15
+ <% end %>
16
+ <% end %>
17
+ <% end %>
18
+ <% end %>
19
+ <% else %>
20
+ <%= pb_rails("list") do %>
21
+ <% object.items.each do |item| %>
22
+ <%= pb_rails("selectable_list/selectable_list_item", props: item.merge(variant: object.variant, id: object.get_id(item)) )%>
23
+ <% end %>
10
24
  <% end %>
11
25
  <% end %>
12
26
  <% end %>