playbook_ui 15.2.0 → 15.3.0.pre.rc.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fa8bd00dc42ffcbd36d00d699d533eaf7eaca092a040a7c7507f85552ee8c88f
4
- data.tar.gz: e811656bf4650d50d419e035a0e52f13cc778ab0de9f004e7010295c1b085430
3
+ metadata.gz: 923e49d3ee86d5e4c40329476d18f0ddf6624341de26ff6bfb459b47511b6e7b
4
+ data.tar.gz: '087cf99671b19f164e1051dc1ec762e67e85307eda369df19c49b0d270b19ea0'
5
5
  SHA512:
6
- metadata.gz: 7cdd213594cc5b431c3dba49c43e3fe004b673bb0d8aa749cc3a575e4c7fa3db9866fdb55300d461081796727228315b99c7f579fade2f608f52a3b12cc804a0
7
- data.tar.gz: 25f4a940305ac1cea88e5b64fa37294f408dcfe2f61337e378d31ded35649c1049ef7d47256b69e2b0214ef60bde05292e2b231e41c83117508d0be3ea6a4803
6
+ metadata.gz: bf78055ba2a71ad2e53506ededf079046677b6d50df2cd94d7bc7ac9150a5b643c9fc8415f755009eb99d8dd2375f82ecbd1847a039111854ad0fa7b4fc819f3
7
+ data.tar.gz: 76c1afb64e8a7afc52298a617106c118507c0b88639a0333b78963a66b6abc0f9f1d6434d46fdae13b3c1ae3be76462bbd78addd104fd0ec38ac3a5898b1894c
@@ -81,6 +81,12 @@ $pb_button_sizes: (
81
81
  // Loading state
82
82
  &.pb_button_loading {
83
83
  @include pb_button_loading(true);
84
+ &.pb_button_size_sm {
85
+ min-height: 30px;
86
+ }
87
+ &.pb_button_size_lg {
88
+ min-height: 45px;
89
+ }
84
90
  }
85
91
 
86
92
  // Disabled state
@@ -1,3 +1,7 @@
1
- <%= pb_rails("button", props: { aria: { label: "Loading" }, text: "Button Primary", loading: true, margin_right: "lg" }) %>
2
- <%= pb_rails("button", props: { aria: { label: "Loading" }, text: "Button Primary", variant: "secondary", loading: true, margin_right: "lg" }) %>
3
- <%= pb_rails("button", props: { aria: { label: "Loading" }, text: "Button Primary", variant: "link", loading: true, margin_right: "lg" }) %>
1
+ <%= pb_rails("caption", props: { margin_y: "md", text: "Button variants with loading" }) %>
2
+ <%= pb_rails("button", props: { aria: { label: "Loading" }, loading: true, margin_right: "lg" }) %>
3
+ <%= pb_rails("button", props: { aria: { label: "Loading" }, variant: "secondary", loading: true, margin_right: "lg" }) %>
4
+ <%= pb_rails("button", props: { aria: { label: "Loading" }, variant: "link", loading: true, margin_right: "lg" }) %>
5
+ <%= pb_rails("caption", props: { margin_y: "md", text: "Button sizes with loading" }) %>
6
+ <%= pb_rails("button", props: { aria: { label: "Loading" }, loading: true, size: "sm", margin_right: "lg" }) %>
7
+ <%= pb_rails("button", props: { aria: { label: "Loading" }, loading: true, size: "lg", margin_right: "lg" }) %>
@@ -1,8 +1,13 @@
1
1
  import React from 'react'
2
2
  import Button from "../../pb_button/_button"
3
+ import Caption from "../../pb_caption/_caption"
3
4
 
4
5
  const ButtonLoading = (props) => (
5
6
  <div>
7
+ <Caption
8
+ marginY="md"
9
+ text="Button variants with loading"
10
+ />
6
11
  <Button
7
12
  aria={{ label: 'Loading' }}
8
13
  loading
@@ -31,6 +36,30 @@ const ButtonLoading = (props) => (
31
36
  variant="link"
32
37
  {...props}
33
38
  />
39
+ <br/>
40
+ <Caption
41
+ marginY="md"
42
+ text="Button sizes with loading"
43
+ />
44
+ <Button
45
+ aria={{ label: 'Loading' }}
46
+ loading
47
+ marginRight='lg'
48
+ size="sm"
49
+ tabIndex={0}
50
+ text="Small Button"
51
+ {...props}
52
+ />
53
+ {' '}
54
+ <Button
55
+ aria={{ label: 'Loading' }}
56
+ loading
57
+ marginRight='lg'
58
+ size="lg"
59
+ tabIndex={0}
60
+ text="Small Button"
61
+ {...props}
62
+ />
34
63
  </div>
35
64
  )
36
65
 
@@ -141,4 +141,12 @@
141
141
  }
142
142
  }
143
143
  }
144
+
145
+ .pb_draggable_item:has(.pb_item_kit) {
146
+ border-bottom: 1px solid $border_light;
147
+ }
148
+
149
+ .pb_draggable_item:has(.pb_item_kit):last-child {
150
+ border-bottom: none;
151
+ }
144
152
  }
@@ -101,7 +101,7 @@
101
101
  <%= form.typeahead :example_typeahead_validation_react, props: { options: example_typeahead_options, pills: true, label: "Example Typeahead (React Rendered)", placeholder: "Search for a user", required: true, validation: { message: "Please select a color." } } %>
102
102
  <%= form.typeahead :example_typeahead_validation_react_2, props: { options: example_typeahead_options, pills: true, label: "Example Typeahead 2 (React Rendered)", placeholder: "Search for a user", required: true } %>
103
103
  <%= form.text_field :example_text_field_validation, props: { label: true, required: true } %>
104
- <%= form.phone_number_field :example_phone_number_field_validation, props: { label: "Example phone field", hidden_inputs: true } %>
104
+ <%= form.phone_number_field :example_phone_number_field_validation, props: { label: "Example phone field", hidden_inputs: true, required: true } %>
105
105
  <%= form.email_field :example_email_field_validation, props: { label: true, required: true } %>
106
106
  <%= form.number_field :example_number_field_validation, props: { label: true, required: true } %>
107
107
  <%= form.search_field :example_project_number_validation, props: { label: true, required: true, validation: { pattern: "[0-9]{2}-[0-9]{5}", message: "Please enter a valid project number (example: 33-12345)." } } %>
@@ -111,7 +111,7 @@ const PhoneNumberInput = (props: PhoneNumberInputProps, ref?: React.Ref<unknown>
111
111
  const inputRef = useRef<HTMLInputElement | null>(null)
112
112
  const itiRef = useRef<any>(null);
113
113
  const [inputValue, setInputValue] = useState(value)
114
- const [error, setError] = useState(props.error)
114
+ const [error, setError] = useState(props.error || "")
115
115
  const [dropDownIsOpen, setDropDownIsOpen] = useState(false)
116
116
  const [selectedData, setSelectedData] = useState()
117
117
  const [hasTyped, setHasTyped] = useState(false)
@@ -124,24 +124,6 @@ const PhoneNumberInput = (props: PhoneNumberInputProps, ref?: React.Ref<unknown>
124
124
  }
125
125
  }, [error, onValidate])
126
126
 
127
- /*
128
- useImperativeHandle exposes the kit's input element to a parent component via a ref.
129
- See the Playbook docs for use cases.
130
- Read: https://react.dev/reference/react/useImperativeHandle
131
- */
132
- useImperativeHandle(ref, () => {
133
- return {
134
- clearField() {
135
- setInputValue("")
136
- setError("")
137
- setHasTyped(false)
138
- },
139
- inputNode() {
140
- return inputRef.current
141
- }
142
- }
143
- })
144
-
145
127
  const unformatNumber = (formattedNumber: any) => {
146
128
  return formattedNumber.replace(/\D/g, "")
147
129
  }
@@ -164,6 +146,13 @@ const PhoneNumberInput = (props: PhoneNumberInputProps, ref?: React.Ref<unknown>
164
146
 
165
147
  const validateTooShortNumber = (itiInit: any) => {
166
148
  if (!itiInit) return
149
+
150
+ // If field is empty, don't show "too short" error
151
+ if (!inputValue || inputValue.trim() === '') {
152
+ setError('')
153
+ return false
154
+ }
155
+
167
156
  if (itiInit.getValidationError() === ValidationError.TooShort) {
168
157
  return showFormattedError('too short')
169
158
  } else {
@@ -183,7 +172,7 @@ const PhoneNumberInput = (props: PhoneNumberInputProps, ref?: React.Ref<unknown>
183
172
  }
184
173
 
185
174
  const validateUnhandledError = (itiInit: any) => {
186
- if (!required || !itiInit) return
175
+ if (!itiInit) return
187
176
  if (itiInit.getValidationError() === ValidationError.SomethingWentWrong) {
188
177
  if (inputValue.length === 1) {
189
178
  return showFormattedError('too short')
@@ -206,14 +195,27 @@ const PhoneNumberInput = (props: PhoneNumberInputProps, ref?: React.Ref<unknown>
206
195
 
207
196
  const validateRepeatCountryCode = (itiInit: any) => {
208
197
  if (!itiInit) return
209
- const countryDialCode = itiInit.getSelectedCountryData().dialCode;
198
+ const countryDialCode = itiRef.current.getSelectedCountryData().dialCode;
210
199
  if (unformatNumber(inputValue).startsWith(countryDialCode)) {
211
200
  return showFormattedError('repeat country code')
212
201
  }
213
202
  }
214
203
 
204
+ const validateRequiredField = () => {
205
+ if (!inputValue || inputValue.trim() === '') {
206
+ setError('Missing phone number')
207
+ return true
208
+ }
209
+ return false
210
+ }
215
211
 
216
212
  const validateErrors = () => {
213
+ // If field is empty, show error message
214
+ if (!inputValue || inputValue.trim() === '') {
215
+ if (validateRequiredField()) return
216
+ return
217
+ }
218
+
217
219
  if (!hasTyped && !error) return
218
220
 
219
221
  if (itiRef.current) isValid(itiRef.current.isValidNumber())
@@ -225,6 +227,87 @@ const PhoneNumberInput = (props: PhoneNumberInputProps, ref?: React.Ref<unknown>
225
227
  if (validateRepeatCountryCode(itiRef.current)) return
226
228
  }
227
229
 
230
+ /*
231
+ useImperativeHandle exposes the kit's input element to a parent component via a ref.
232
+ See the Playbook docs for use cases.
233
+ Read: https://react.dev/reference/react/useImperativeHandle
234
+ */
235
+ useImperativeHandle(ref, () => {
236
+ return {
237
+ clearField() {
238
+ setInputValue("")
239
+ setError("")
240
+ setHasTyped(false)
241
+ },
242
+ inputNode() {
243
+ return inputRef.current
244
+ },
245
+ // Expose validation method for React Hook Form
246
+ validate() {
247
+ // Run validation and return error message or true
248
+ const isEmpty = !inputValue || inputValue.trim() === ''
249
+
250
+ if (isEmpty) {
251
+ // Show missing phone number error
252
+ const errorMessage = 'Missing phone number'
253
+ setError(errorMessage)
254
+ setHasTyped(true)
255
+ // Only return error for React Hook Form if field is required
256
+ return required ? errorMessage : true
257
+ }
258
+
259
+ if (!itiRef.current) {
260
+ return true
261
+ }
262
+
263
+ // Check for repeat country code first
264
+ const countryDialCode = itiRef.current.getSelectedCountryData().dialCode;
265
+ if (unformatNumber(inputValue).startsWith(countryDialCode)) {
266
+ const countryName = itiRef.current.getSelectedCountryData().name
267
+ const errorMessage = `Invalid ${countryName} phone number (repeat country code)`
268
+ setError(errorMessage)
269
+ setHasTyped(true)
270
+ return errorMessage
271
+ }
272
+
273
+ // Check if it only contains valid characters
274
+ if (!containOnlyNumbers(inputValue)) {
275
+ const countryName = itiRef.current.getSelectedCountryData().name
276
+ const errorMessage = `Invalid ${countryName} phone number (enter numbers only)`
277
+ setError(errorMessage)
278
+ setHasTyped(true)
279
+ return errorMessage
280
+ }
281
+
282
+ // Check if valid number
283
+ if (!itiRef.current.isValidNumber()) {
284
+ const countryName = itiRef.current.getSelectedCountryData().name
285
+ const validationError = itiRef.current.getValidationError()
286
+ let errorMessage = ''
287
+
288
+ if (validationError === ValidationError.TooShort) {
289
+ errorMessage = `Invalid ${countryName} phone number (too short)`
290
+ } else if (validationError === ValidationError.TooLong) {
291
+ errorMessage = `Invalid ${countryName} phone number (too long)`
292
+ } else if (validationError === ValidationError.MissingAreaCode) {
293
+ errorMessage = `Invalid ${countryName} phone number (missing area code)`
294
+ } else {
295
+ errorMessage = `Invalid ${countryName} phone number`
296
+ }
297
+
298
+ setError(errorMessage)
299
+ setHasTyped(true)
300
+
301
+ return errorMessage
302
+ }
303
+
304
+ // Clear error if valid
305
+ setError('')
306
+ return true
307
+ }
308
+ }
309
+ })
310
+
228
311
  const getCurrentSelectedData = (itiInit: any, inputValue: string) => {
229
312
  return { ...itiInit.getSelectedCountryData(), number: inputValue }
230
313
  }
@@ -300,7 +383,7 @@ const PhoneNumberInput = (props: PhoneNumberInputProps, ref?: React.Ref<unknown>
300
383
  dark,
301
384
  "data-phone-number": JSON.stringify(selectedData),
302
385
  disabled,
303
- error,
386
+ error: hasTyped ? error : props.error,
304
387
  type: 'tel',
305
388
  id,
306
389
  label,