playbook_ui 16.0.0.pre.alpha.play263413732 → 16.0.0.pre.alpha.play267313765

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.
Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/app/pb_kits/playbook/pb_form/docs/_form_with_required_indicator.html.erb +2 -1
  3. data/app/pb_kits/playbook/pb_passphrase/_passphrase.tsx +5 -20
  4. data/app/pb_kits/playbook/pb_passphrase/docs/_passphrase_meter_settings.jsx +0 -1
  5. data/app/pb_kits/playbook/pb_passphrase/docs/example.yml +0 -2
  6. data/app/pb_kits/playbook/pb_passphrase/docs/index.js +0 -1
  7. data/app/pb_kits/playbook/pb_passphrase/passphrase.rb +0 -2
  8. data/app/pb_kits/playbook/pb_passphrase/passphrase.test.jsx +1 -30
  9. data/app/pb_kits/playbook/pb_phone_number_input/_phone_number_input.tsx +0 -3
  10. data/app/pb_kits/playbook/pb_phone_number_input/docs/example.yml +0 -2
  11. data/app/pb_kits/playbook/pb_phone_number_input/docs/index.js +0 -1
  12. data/app/pb_kits/playbook/pb_phone_number_input/phone_number_input.rb +0 -3
  13. data/app/pb_kits/playbook/pb_phone_number_input/phone_number_input.test.js +3 -34
  14. data/app/pb_kits/playbook/pb_rich_text_editor/_rich_text_editor.tsx +33 -6
  15. data/app/pb_kits/playbook/pb_rich_text_editor/docs/_rich_text_editor_advanced_required_indicator.jsx +35 -0
  16. data/app/pb_kits/playbook/{pb_passphrase/docs/_passphrase_required_indicator.md → pb_rich_text_editor/docs/_rich_text_editor_advanced_required_indicator.md} +1 -1
  17. data/app/pb_kits/playbook/pb_rich_text_editor/docs/_rich_text_editor_required_indicator.html.erb +10 -0
  18. data/app/pb_kits/playbook/pb_rich_text_editor/docs/_rich_text_editor_required_indicator.jsx +21 -0
  19. data/app/pb_kits/playbook/{pb_phone_number_input/docs/_phone_number_input_required_indicator.md → pb_rich_text_editor/docs/_rich_text_editor_required_indicator.md} +1 -1
  20. data/app/pb_kits/playbook/pb_rich_text_editor/docs/example.yml +3 -0
  21. data/app/pb_kits/playbook/pb_rich_text_editor/docs/index.js +2 -0
  22. data/app/pb_kits/playbook/pb_rich_text_editor/rich_text_editor.rb +5 -0
  23. data/app/pb_kits/playbook/pb_rich_text_editor/rich_text_editor.test.js +33 -18
  24. data/app/pb_kits/playbook/pb_textarea/_textarea.tsx +29 -11
  25. data/app/pb_kits/playbook/pb_textarea/docs/_textarea_required_indicator.html.erb +5 -0
  26. data/app/pb_kits/playbook/pb_textarea/docs/_textarea_required_indicator.jsx +25 -0
  27. data/app/pb_kits/playbook/pb_textarea/docs/_textarea_required_indicator.md +3 -0
  28. data/app/pb_kits/playbook/pb_textarea/docs/example.yml +3 -1
  29. data/app/pb_kits/playbook/pb_textarea/docs/index.js +1 -0
  30. data/app/pb_kits/playbook/pb_textarea/index.ts +12 -5
  31. data/app/pb_kits/playbook/pb_textarea/textarea.html.erb +6 -0
  32. data/app/pb_kits/playbook/pb_textarea/textarea.rb +2 -0
  33. data/app/pb_kits/playbook/pb_textarea/textarea.test.js +18 -1
  34. data/app/pb_kits/playbook/pb_typeahead/_typeahead.test.jsx +24 -1
  35. data/app/pb_kits/playbook/pb_typeahead/_typeahead.tsx +2 -1
  36. data/app/pb_kits/playbook/pb_typeahead/components/MultiValue.tsx +4 -1
  37. data/dist/chunks/{_pb_line_graph-hxi01lk7.js → _pb_line_graph-BgKF_zz1.js} +1 -1
  38. data/dist/chunks/_typeahead-DlvhrqqP.js +1 -0
  39. data/dist/chunks/{globalProps-DgYwLYNx.js → globalProps-BhVYCqRf.js} +1 -1
  40. data/dist/chunks/{lib-NLxTo8OB.js → lib-DD34ZrWL.js} +1 -1
  41. data/dist/chunks/vendor.js +2 -2
  42. data/dist/playbook-rails-react-bindings.js +1 -1
  43. data/dist/playbook-rails.js +1 -1
  44. data/lib/playbook/forms/builder/phone_number_field.rb +0 -9
  45. data/lib/playbook/version.rb +1 -1
  46. metadata +14 -12
  47. data/app/pb_kits/playbook/pb_passphrase/docs/_passphrase_required_indicator.html.erb +0 -7
  48. data/app/pb_kits/playbook/pb_passphrase/docs/_passphrase_required_indicator.jsx +0 -24
  49. data/app/pb_kits/playbook/pb_phone_number_input/docs/_phone_number_input_required_indicator.html.erb +0 -5
  50. data/app/pb_kits/playbook/pb_phone_number_input/docs/_phone_number_input_required_indicator.jsx +0 -14
  51. data/dist/chunks/_typeahead-CoJpI3RG.js +0 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 28617f4ae9161e1509366284f53708aacf06482d3c3acf6ad556281eacc6eb0f
4
- data.tar.gz: 1d4a3acb8922f30259bed23161b5adfe9ce1aaea99880a26181deec26b5420d1
3
+ metadata.gz: ac10d2ec1ccce77a839f88b0a14f4328c5f382e44f1f722e4e789f0cdc3a51c9
4
+ data.tar.gz: a23d74c5d2ad1c2d34953893a56b29e21f631cd9e862200b56241cee51e68c71
5
5
  SHA512:
6
- metadata.gz: 0afdd7ba0dfd9a04dcd3fe768150d05be2a4bd61066654664d4593f19e030046616cc4fa0d08305fbbbdda970a4eceff4b20a3cb7dbbef1deb1d1896ba320ca4
7
- data.tar.gz: 2b36e35618c97ba6be60522fb2166d3a737e8a24db9f8ff46583b7c22b33f32a220e28ae8ba5e8b54f00847659258fee7aa5cf5a4b6cdfec6cfdf6e6b7462b17
6
+ metadata.gz: fb2fd3f590838627a23827456229e0fb206cb673e7eddc07c4f27fb94bd5a071735aeeacab49749f3e9d30563b419357829bf41e3ce4287811bffaa0efd5588e
7
+ data.tar.gz: 2fa1d34d4e0c34afc990271677363268025f48851db9bb0967bbd19d99719ae5a9818c4ce716bf37236f14ae50f02b151dd0d43a2553785d825ee83a176fc15f
@@ -1,12 +1,13 @@
1
1
  <%= pb_form_with(scope: :example, url: "", method: :get, validate: true) do |form| %>
2
2
  <%= form.text_field :example_text_field, props: { label: true, required: true, required_indicator: true } %>
3
3
  <%= form.text_field :example_text_field_2, props: { label: "Text Field Custom Label", required: true, required_indicator: true } %>
4
+ <%= form.text_area :example_text_area, props: { label: true, required: true, required_indicator: true } %>
5
+ <%= form.text_area :example_text_area_2, props: { label: "Textarea Custom Label", required: true, required_indicator: true } %>
4
6
  <%= form.email_field :example_email_field, props: { label: true, required: true, required_indicator: true } %>
5
7
  <%= form.number_field :example_number_field, props: { label: true, required: true, required_indicator: true } %>
6
8
  <%= form.search_field :example_search_field, props: { label: true, required: true, required_indicator: true } %>
7
9
  <%= form.password_field :example_password_field, props: { label: true, required: true, required_indicator: true } %>
8
10
  <%= form.url_field :example_url_field, props: { label: true, required: true, required_indicator: true } %>
9
- <%= form.phone_number_field :example_phone_number_field, props: { label: true, required: true, required_indicator: true } %>
10
11
 
11
12
  <%= form.actions do |action| %>
12
13
  <%= action.submit %>
@@ -7,7 +7,6 @@ import { globalProps } from "../utilities/globalProps"
7
7
  import Body from '../pb_body/_body'
8
8
  import Caption from '../pb_caption/_caption'
9
9
  import CircleIconButton from '../pb_circle_icon_button/_circle_icon_button'
10
- import colors from '../tokens/exports/_colors.module.scss'
11
10
  import Flex from '../pb_flex/_flex'
12
11
  import Icon from '../pb_icon/_icon'
13
12
  import PbReactPopover from '../pb_popover/_popover'
@@ -26,7 +25,6 @@ type PassphraseProps = {
26
25
  inputProps?: GenericObject,
27
26
  label?: string,
28
27
  onChange: (inputValue: string) => void,
29
- requiredIndicator?: boolean,
30
28
  showTipsBelow?: "always" | "xs" | "sm" | "md" | "lg" | "xl",
31
29
  tips?: Array<string>,
32
30
  uncontrolled?: boolean,
@@ -45,7 +43,6 @@ const Passphrase = (props: PassphraseProps): React.ReactElement => {
45
43
  inputProps = {},
46
44
  label = confirmation ? "Confirm Passphrase" : "Passphrase",
47
45
  onChange = () => undefined,
48
- requiredIndicator = false,
49
46
  showTipsBelow = "always",
50
47
  tips = [],
51
48
  uncontrolled = false,
@@ -102,7 +99,6 @@ const Passphrase = (props: PassphraseProps): React.ReactElement => {
102
99
 
103
100
  const shieldIcon = getAllIcons()["shieldCheck"]
104
101
  const eyeIcon = getAllIcons()["eye"]
105
- const hasLabel = label && label !== ""
106
102
 
107
103
  return (
108
104
  <div
@@ -113,22 +109,11 @@ const Passphrase = (props: PassphraseProps): React.ReactElement => {
113
109
  id={id}
114
110
  >
115
111
  <label>
116
- <Flex
117
- align="baseline"
118
- {...(hasLabel ? { marginBottom: "xs" } : {})}
119
- >
120
- {hasLabel && (requiredIndicator ? (
121
- <Caption
122
- className="passphrase-label"
123
- >
124
- {label} <span style={{ color: `${colors.error}` }}>*</span>
125
- </Caption>
126
- ) : (
127
- <Caption
128
- className="passphrase-label"
129
- text={label}
130
- />
131
- ))}
112
+ <Flex align="baseline">
113
+ <Caption
114
+ className="passphrase-label"
115
+ text={label}
116
+ />
132
117
  {tips.length > 0 && !confirmation &&
133
118
  <PbReactPopover
134
119
  className="passphrase-tips"
@@ -120,7 +120,6 @@ const PassphraseMeterSettings = (props) => {
120
120
  "These examples will all share the same input value. Type in any of the inputs to see how the strength meter changes in response to different settings."
121
121
  }
122
122
  </Body>
123
- <br/>
124
123
  <Passphrase
125
124
  label={"Type your passphrase"}
126
125
  onChange={handleChange}
@@ -9,7 +9,6 @@ examples:
9
9
  - passphrase_strength_change: Strength Change
10
10
  - passphrase_common: Common Passphrases
11
11
  - passphrase_breached: Breached Passphrases
12
- - passphrase_required_indicator: Required Indicator
13
12
 
14
13
  react:
15
14
  - passphrase_default: Default
@@ -20,4 +19,3 @@ examples:
20
19
  - passphrase_strength_change: Strength Change
21
20
  - passphrase_common: Common Passphrases
22
21
  - passphrase_breached: Breached Passphrases
23
- - passphrase_required_indicator: Required Indicator
@@ -6,4 +6,3 @@ export { default as PassphraseTips } from './_passphrase_tips'
6
6
  export { default as PassphraseStrengthChange } from './_passphrase_strength_change'
7
7
  export { default as PassphraseCommon } from './_passphrase_common'
8
8
  export { default as PassphraseBreached } from './_passphrase_breached'
9
- export { default as PassphraseRequiredIndicator } from './_passphrase_required_indicator.jsx'
@@ -10,7 +10,6 @@ module Playbook
10
10
  values: %w[always xs sm md lg xl],
11
11
  default: "always"
12
12
  prop :tips, type: Playbook::Props::Array, default: []
13
- prop :required_indicator, type: Playbook::Props::Boolean, default: false
14
13
  prop :value, type: Playbook::Props::String
15
14
 
16
15
  def classname
@@ -24,7 +23,6 @@ module Playbook
24
23
  confirmation: confirmation,
25
24
  inputProps: input_props,
26
25
  label: label,
27
- requiredIndicator: required_indicator,
28
26
  showTipsBelow: show_tips_below,
29
27
  tips: tips,
30
28
  uncontrolled: true,
@@ -1,5 +1,5 @@
1
1
  import React from 'react'
2
- import { render, screen, within } from '../utilities/test-utils'
2
+ import { render, screen } from '../utilities/test-utils'
3
3
  import { Passphrase } from 'playbook-ui'
4
4
 
5
5
  const testId = 'text-input1',
@@ -86,32 +86,3 @@ test('popover target does not show when tips are not given', () => {
86
86
  const kit = screen.getByTestId(testId)
87
87
  expect(kit.querySelector('[class^=pb_popover_reference_wrapper]')).toBeNull()
88
88
  })
89
-
90
- test('renders required indicator asterisk when requiredIndicator is true', () => {
91
- render(
92
- <Passphrase
93
- data={{ testid: testId }}
94
- label="Passphrase"
95
- requiredIndicator
96
- />
97
- )
98
-
99
- const kit = screen.getByTestId(testId)
100
- const label = within(kit).getByText(/Passphrase/)
101
- expect(label).toBeInTheDocument()
102
- expect(kit).toHaveTextContent('*')
103
- })
104
-
105
- test('does not render required indicator asterisk when requiredIndicator is false', () => {
106
- render(
107
- <Passphrase
108
- data={{ testid: testId }}
109
- label="Passphrase"
110
- />
111
- )
112
-
113
- const kit = screen.getByTestId(testId)
114
- const label = within(kit).getByText(/Passphrase/)
115
- expect(label).toBeInTheDocument()
116
- expect(kit).not.toHaveTextContent('*')
117
- })
@@ -36,7 +36,6 @@ type PhoneNumberInputProps = {
36
36
  excludeCountries: string[],
37
37
  preferredCountries?: string[],
38
38
  required?: boolean,
39
- requiredIndicator?: boolean,
40
39
  value?: string,
41
40
  formatAsYouType?: boolean,
42
41
  strictMode?: boolean,
@@ -92,7 +91,6 @@ const PhoneNumberInput = (props: PhoneNumberInputProps, ref?: React.Ref<unknown>
92
91
  onlyCountries = [],
93
92
  excludeCountries = [],
94
93
  required = false,
95
- requiredIndicator = false,
96
94
  preferredCountries = [],
97
95
  value = "",
98
96
  formatAsYouType = false,
@@ -535,7 +533,6 @@ const PhoneNumberInput = (props: PhoneNumberInputProps, ref?: React.Ref<unknown>
535
533
  validateErrors()
536
534
  },
537
535
  onChange: formatAsYouType ? undefined : handleOnChange,
538
- requiredIndicator,
539
536
  value: inputValue
540
537
  }
541
538
 
@@ -12,7 +12,6 @@ examples:
12
12
  - phone_number_input_format: Format as You Type
13
13
  - phone_number_input_strict_mode: Strict Mode
14
14
  - phone_number_input_country_search: Country Search
15
- - phone_number_input_required_indicator: Required Indicator
16
15
 
17
16
  rails:
18
17
  - phone_number_input_default: Default
@@ -25,4 +24,3 @@ examples:
25
24
  - phone_number_input_strict_mode: Strict Mode
26
25
  - phone_number_input_hidden_inputs: Hidden Inputs
27
26
  - phone_number_input_country_search: Country Search
28
- - phone_number_input_required_indicator: Required Indicator
@@ -9,4 +9,3 @@ export { default as PhoneNumberInputAccessInputElement } from './_phone_number_i
9
9
  export { default as PhoneNumberInputFormat } from './_phone_number_input_format'
10
10
  export { default as PhoneNumberInputStrictMode } from './_phone_number_input_strict_mode'
11
11
  export { default as PhoneNumberInputCountrySearch } from './_phone_number_input_country_search'
12
- export { default as PhoneNumberInputRequiredIndicator } from './_phone_number_input_required_indicator.jsx'
@@ -7,8 +7,6 @@ module Playbook
7
7
  default: false
8
8
  prop :required, type: Playbook::Props::Boolean,
9
9
  default: false
10
- prop :required_indicator, type: Playbook::Props::Boolean,
11
- default: false
12
10
  prop :initial_country, type: Playbook::Props::String,
13
11
  default: ""
14
12
  prop :label, type: Playbook::Props::String,
@@ -54,7 +52,6 @@ module Playbook
54
52
  excludeCountries: exclude_countries,
55
53
  preferredCountries: preferred_countries,
56
54
  required: required,
57
- requiredIndicator: required_indicator,
58
55
  value: value,
59
56
  countrySearch: country_search,
60
57
  }
@@ -1,5 +1,5 @@
1
1
  import React from "react";
2
- import { render, screen, act, within } 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";
@@ -129,7 +129,7 @@ test("should format phone number as '555-555-5555' with formatAsYouType and 'us'
129
129
  };
130
130
 
131
131
  render(<PhoneNumberInput {...props} />);
132
-
132
+
133
133
  const input = screen.getByRole("textbox");
134
134
 
135
135
  act(() => {
@@ -154,38 +154,7 @@ test("should pass countrySearch prop to component", () => {
154
154
  };
155
155
 
156
156
  render(<PhoneNumberInput {...props} />);
157
-
157
+
158
158
  const wrapper = screen.getByTestId('phone-input-with-search');
159
159
  expect(wrapper).toBeInTheDocument();
160
160
  });
161
-
162
- test("renders required indicator asterisk when requiredIndicator is true", () => {
163
- const props = {
164
- data: { testid: testId },
165
- id: testId,
166
- label: "Required Phone Number",
167
- requiredIndicator: true,
168
- };
169
-
170
- render(<PhoneNumberInput {...props} />);
171
-
172
- const kit = screen.getByTestId(testId);
173
- const label = within(kit).getByText(/Required Phone Number/);
174
- expect(label).toBeInTheDocument();
175
- expect(kit).toHaveTextContent("*");
176
- });
177
-
178
- test("does not render required indicator asterisk when requiredIndicator is false", () => {
179
- const props = {
180
- data: { testid: testId },
181
- id: testId,
182
- label: "Phone Number",
183
- };
184
-
185
- render(<PhoneNumberInput {...props} />);
186
-
187
- const kit = screen.getByTestId(testId);
188
- const label = within(kit).getByText(/Phone Number/);
189
- expect(label).toBeInTheDocument();
190
- expect(kit).not.toHaveTextContent("*");
191
- });
@@ -4,6 +4,8 @@ import { TrixEditor } from 'react-trix'
4
4
 
5
5
  import inlineFocus from './inlineFocus'
6
6
  import useFocus from './useFocus'
7
+ import Caption from '../pb_caption/_caption'
8
+ import colors from '../tokens/exports/_colors.module.scss'
7
9
  import { globalProps, GlobalProps } from '../utilities/globalProps'
8
10
  import { buildAriaProps, buildDataProps, noop, buildHtmlProps } from '../utilities/props'
9
11
 
@@ -40,12 +42,14 @@ type RichTextEditorProps = {
40
42
  inputOptions?: { [key: string]: string | number | boolean | (() => void) },
41
43
  id?: string,
42
44
  inline?: boolean,
45
+ label?: string,
43
46
  extensions?: { [key: string]: string }[],
44
47
  name?: string,
45
48
  onChange: (html: string, text: string) => void,
46
49
  placeholder?: string,
47
50
  inputHeight?: "sm" | "md" | "lg",
48
51
  inputMinHeight?: "sm" | "md" | "lg",
52
+ requiredIndicator?: boolean,
49
53
  simple?: boolean,
50
54
  sticky?: boolean,
51
55
  template: string,
@@ -64,6 +68,7 @@ const RichTextEditor = (props: RichTextEditorProps): React.ReactElement => {
64
68
  data = {},
65
69
  focus = false,
66
70
  htmlOptions = {},
71
+ id,
67
72
  inputOptions = {},
68
73
  inline = false,
69
74
  extensions,
@@ -76,7 +81,9 @@ const RichTextEditor = (props: RichTextEditorProps): React.ReactElement => {
76
81
  sticky = false,
77
82
  template = '',
78
83
  value = '',
79
- maxWidth = "md"
84
+ maxWidth = "md",
85
+ requiredIndicator = false,
86
+ label,
80
87
  } = props
81
88
 
82
89
  const ariaProps = buildAriaProps(aria),
@@ -86,7 +93,7 @@ const RichTextEditor = (props: RichTextEditorProps): React.ReactElement => {
86
93
  containerRef = useRef<HTMLDivElement>(null)
87
94
 
88
95
  const htmlProps = buildHtmlProps(htmlOptions)
89
-
96
+
90
97
  const handleOnEditorReady = (editorInstance: Editor) => {
91
98
  setEditor(editorInstance)
92
99
  setTimeout(() => {
@@ -94,7 +101,7 @@ const RichTextEditor = (props: RichTextEditorProps): React.ReactElement => {
94
101
  if (oldId) {
95
102
  const hiddenInput = document.getElementById(oldId)
96
103
  if (hiddenInput) {
97
- const newId = (inputOptions.id as string) || oldId
104
+ const newId = (inputOptions.id as string) || oldId
98
105
  hiddenInput.id = newId
99
106
  editorInstance.element.setAttribute('input', newId)
100
107
 
@@ -119,7 +126,7 @@ const RichTextEditor = (props: RichTextEditorProps): React.ReactElement => {
119
126
  // set button attributes
120
127
  inlineCodeButton.dataset.trixAttribute = 'inlineCode'
121
128
  blockCodeButton.insertAdjacentElement('afterend', inlineCodeButton)
122
- }
129
+ }
123
130
 
124
131
  if (toolbarBottom) editor.element.after(toolbarElement)
125
132
 
@@ -147,7 +154,7 @@ const RichTextEditor = (props: RichTextEditorProps): React.ReactElement => {
147
154
  if (!advancedEditor || !focus) return
148
155
 
149
156
  const handleFocus = () => setShowToolbarOnFocus(true)
150
-
157
+
151
158
  const handleClickOutside = (event: Event) => {
152
159
  if (isClickInContainer(event) || isClickInPopover(event)) return
153
160
  setShowToolbarOnFocus(false)
@@ -215,9 +222,29 @@ const RichTextEditor = (props: RichTextEditorProps): React.ReactElement => {
215
222
  className={css}
216
223
  ref={focus ? containerRef : undefined}
217
224
  >
225
+ {label && (
226
+ <label htmlFor={id}>
227
+ {
228
+ requiredIndicator ? (
229
+ <Caption className="pb_text_input_kit_label"
230
+ marginBottom="xs"
231
+ >
232
+ {label} <span style={{ color: `${colors.error}` }}>*</span>
233
+ </Caption>
234
+ ) : (
235
+ <Caption
236
+ className="pb_text_input_kit_label"
237
+ marginBottom="xs"
238
+ text={label}
239
+ />
240
+ )
241
+ }
242
+
243
+ </label>
244
+ )}
218
245
  {
219
246
  advancedEditor ? (
220
- <div
247
+ <div
221
248
  className={classnames(
222
249
  "pb_rich_text_editor_advanced_container",
223
250
  { [`input_height_${inputHeight}`]: !!inputHeight,[`input_min_height_${inputMinHeight}`]: !!inputMinHeight ,["toolbar-active"]: shouldShowToolbar }
@@ -0,0 +1,35 @@
1
+ import React from 'react'
2
+ import RichTextEditor from '../../pb_rich_text_editor/_rich_text_editor'
3
+ import { useEditor, EditorContent } from "@tiptap/react"
4
+ import StarterKit from "@tiptap/starter-kit"
5
+ import Link from '@tiptap/extension-link'
6
+
7
+
8
+ const RichTextEditorAdvancedRequiredIndicator = (props) => {
9
+
10
+ const editor = useEditor({
11
+ extensions: [
12
+ StarterKit,
13
+ Link
14
+ ],
15
+ content:"Add your text here. You can format your text, add links, quotes, and bullets."
16
+ })
17
+ if (!editor) {
18
+ return null
19
+ }
20
+
21
+ return (
22
+ <div>
23
+ <RichTextEditor
24
+ advancedEditor={editor}
25
+ label="Label"
26
+ requiredIndicator
27
+ {...props}
28
+ >
29
+ <EditorContent editor={editor}/>
30
+ </RichTextEditor>
31
+ </div>
32
+ )
33
+ }
34
+
35
+ export default RichTextEditorAdvancedRequiredIndicator
@@ -1,3 +1,3 @@
1
- The `requiredIndicator`/`required_indicator` prop displays a red asterisk (*) next to the label, visually indicating that the field is required. This is purely visual and does not enforce validation.
1
+ The `requiredIndicator`/`required_indicator` prop displays a red asterisk (*) next to the label, visually indicating that the field is required. This is purely visual and does not enforce validation.
2
2
 
3
3
  You can use `requiredIndicator`/`required_indicator` with any validation approach: HTML5 validation via the `required` prop, client-side validation, or backend validation. For this reason, it works independently and doesn't need to be paired with the `required` prop.
@@ -0,0 +1,10 @@
1
+ <%= pb_rails("rich_text_editor", props: {
2
+ id: "required-indicator",
3
+ input_options: {
4
+ id: 'hidden_input_id',
5
+ name: "hidden_input_name"
6
+ },
7
+ label: "Label",
8
+ required_indicator: true,
9
+ value: "Add your text here. You can format your text, add links, quotes, and bullets."
10
+ }) %>
@@ -0,0 +1,21 @@
1
+ import React, { useState } from 'react'
2
+ import RichTextEditor from '../../pb_rich_text_editor/_rich_text_editor'
3
+
4
+ const RichTextEditorRequiredIndicator = (props) => {
5
+ const [value, setValue] = useState('Add your text here. You can format your text, add links, quotes, and bullets.'),
6
+ handleOnChange = (html) => setValue(html)
7
+
8
+ return (
9
+ <div>
10
+ <RichTextEditor
11
+ label="Label"
12
+ onChange={handleOnChange}
13
+ requiredIndicator
14
+ value={value}
15
+ {...props}
16
+ />
17
+ </div>
18
+ )
19
+ }
20
+
21
+ export default RichTextEditorRequiredIndicator
@@ -1,3 +1,3 @@
1
- The `requiredIndicator`/`required_indicator` prop displays a red asterisk (*) next to the label, visually indicating that the field is required. This is purely visual and does not enforce validation.
1
+ The `requiredIndicator`/`required_indicator` prop displays a red asterisk (*) next to the label, visually indicating that the field is required. This is purely visual and does not enforce validation.
2
2
 
3
3
  You can use `requiredIndicator`/`required_indicator` with any validation approach: HTML5 validation via the `required` prop, client-side validation, or backend validation. For this reason, it works independently and doesn't need to be paired with the `required` prop.
@@ -9,6 +9,7 @@ examples:
9
9
  - rich_text_editor_templates: Templates
10
10
  # - rich_text_editor_toolbar_bottom: Toolbar Bottom
11
11
  - rich_text_editor_inline: Inline
12
+ - rich_text_editor_required_indicator: Required Indicator
12
13
  - rich_text_editor_preview: Preview
13
14
 
14
15
  react:
@@ -31,5 +32,7 @@ examples:
31
32
  - rich_text_editor_advanced_inline: Advanced (Inline)
32
33
  - rich_text_editor_advanced_height: Advanced Height
33
34
  - rich_text_editor_advanced_min_height: Advanced Min Height
35
+ - rich_text_editor_required_indicator: Required Indicator
36
+ - rich_text_editor_advanced_required_indicator: Advanced Required Indicator
34
37
  - rich_text_editor_preview: Preview
35
38
  - rich_text_editor_advanced_preview: Advanced Preview
@@ -19,3 +19,5 @@ export { default as RichTextEditorAdvancedSticky } from './_rich_text_editor_adv
19
19
  export { default as RichTextEditorAdvancedInline } from './_rich_text_editor_advanced_inline.jsx'
20
20
  export { default as RichTextEditorAdvancedHeight } from './_rich_text_editor_advanced_height.jsx'
21
21
  export { default as RichTextEditorAdvancedMinHeight } from './_rich_text_editor_advanced_min_height.jsx'
22
+ export { default as RichTextEditorRequiredIndicator } from './_rich_text_editor_required_indicator.jsx'
23
+ export { default as RichTextEditorAdvancedRequiredIndicator } from './_rich_text_editor_advanced_required_indicator.jsx'
@@ -21,6 +21,9 @@ module Playbook
21
21
  prop :template
22
22
  prop :placeholder
23
23
  prop :input_options
24
+ prop :label
25
+ prop :required_indicator, type: Playbook::Props::Boolean,
26
+ default: false
24
27
 
25
28
  def classname
26
29
  generate_classname("pb_rich_text_editor_kit", simple_class, focus_class, sticky_class, separator: " ")
@@ -51,6 +54,8 @@ module Playbook
51
54
  template: template,
52
55
  placeholder: placeholder,
53
56
  inputOptions: input_options,
57
+ label: label,
58
+ requiredIndicator: required_indicator,
54
59
  }
55
60
  end
56
61
  end
@@ -1,5 +1,5 @@
1
1
  import React from 'react'
2
- import { render, screen, fireEvent, waitFor } from '../utilities/test-utils'
2
+ import { render, screen, fireEvent, waitFor, within } from '../utilities/test-utils'
3
3
  import { useEditor, EditorContent } from "@tiptap/react"
4
4
  import StarterKit from "@tiptap/starter-kit"
5
5
 
@@ -89,14 +89,14 @@ const TestAdvancedEditor = ({ toolbarOnFocus = false, ...props }) => {
89
89
  describe('Advanced TipTap Editor works as expected', () => {
90
90
  test('renders advanced editor with toolbar', () => {
91
91
  render(<TestAdvancedEditor />)
92
-
92
+
93
93
  const kit = screen.getByTestId(testId)
94
94
  expect(kit).toHaveClass(kitClass)
95
-
95
+
96
96
  // Check for advanced container
97
97
  const advancedContainer = kit.querySelector('.pb_rich_text_editor_advanced_container')
98
98
  expect(advancedContainer).toBeInTheDocument()
99
-
99
+
100
100
  // Check for toolbar
101
101
  const toolbar = kit.querySelector('.toolbar')
102
102
  expect(toolbar).toBeInTheDocument()
@@ -104,7 +104,7 @@ describe('Advanced TipTap Editor works as expected', () => {
104
104
 
105
105
  test('renders advanced editor without toolbar when advancedEditorToolbar is false', () => {
106
106
  render(<TestAdvancedEditor advancedEditorToolbar={false} />)
107
-
107
+
108
108
  const kit = screen.getByTestId(testId)
109
109
  const toolbar = kit.querySelector('.toolbar')
110
110
  expect(toolbar).not.toBeInTheDocument()
@@ -112,17 +112,17 @@ describe('Advanced TipTap Editor works as expected', () => {
112
112
 
113
113
  test('shows/hides toolbar on focus when focus is enabled', async () => {
114
114
  render(<TestAdvancedEditor focus />)
115
-
115
+
116
116
  const kit = screen.getByTestId(testId)
117
-
117
+
118
118
  // Initially toolbar should be hidden
119
119
  let toolbar = kit.querySelector('.toolbar')
120
120
  expect(toolbar).not.toBeInTheDocument()
121
-
121
+
122
122
  const editorElement = kit.querySelector('.ProseMirror')
123
123
  // Focus the editor
124
124
  fireEvent.focus(editorElement)
125
-
125
+
126
126
  // Toolbar should now be visible
127
127
  await waitFor(() => {
128
128
  toolbar = kit.querySelector('.toolbar')
@@ -133,7 +133,7 @@ describe('Advanced TipTap Editor works as expected', () => {
133
133
 
134
134
  test('supports simple prop with advanced editor', () => {
135
135
  render(<TestAdvancedEditor simple />)
136
-
136
+
137
137
  const kit = screen.getByTestId(testId)
138
138
  const toolbar = kit.querySelector('.toolbar')
139
139
  expect(toolbar).toBeInTheDocument()
@@ -144,7 +144,7 @@ describe('Advanced TipTap Editor works as expected', () => {
144
144
 
145
145
  test('supports sticky prop with advanced editor', () => {
146
146
  render(<TestAdvancedEditor sticky />)
147
-
147
+
148
148
  const kit = screen.getByTestId(testId)
149
149
  const stickyToolbar = kit.querySelector('.pb_rich_text_editor_tiptap_toolbar_sticky')
150
150
  expect(stickyToolbar).toBeInTheDocument()
@@ -154,37 +154,52 @@ describe('Advanced TipTap Editor works as expected', () => {
154
154
  test('applies aria-label when provided', () => {
155
155
  const ariaLabel = 'Rich Text Editor'
156
156
  render(<TestAdvancedEditor aria={{ label: ariaLabel }} />)
157
-
157
+
158
158
  const kit = screen.getByTestId(testId)
159
159
  expect(kit).toHaveAttribute('aria-label', ariaLabel)
160
160
  })
161
161
 
162
162
  test('supports inline prop with advanced editor', () => {
163
163
  render(<TestAdvancedEditor inline />)
164
-
164
+
165
165
  const kit = screen.getByTestId(testId)
166
166
  const toolbar = kit.querySelector('.toolbar')
167
167
  expect(toolbar).toBeInTheDocument()
168
168
  expect(kit).toHaveClass(`${kitClass} inline`)
169
169
  })
170
170
 
171
+ test('renders required indicator asterisk when requiredIndicator is true', () => {
172
+ render(
173
+ <RichTextEditor
174
+ data={{ testid: testId }}
175
+ label="Label"
176
+ requiredIndicator
177
+ />
178
+ )
179
+
180
+ const kit = screen.getByTestId(testId)
181
+ const label = within(kit).getByText(/Label/)
182
+
183
+ expect(label).toBeInTheDocument()
184
+ expect(kit).toHaveTextContent('*')
185
+ })
186
+
171
187
  describe('TipTap Editor Functionality', () => {
172
188
  test('can type and update content', async () => {
173
189
  render(<TestAdvancedEditor />)
174
-
190
+
175
191
  const kit = screen.getByTestId(testId)
176
192
  const editorContent = kit.querySelector('.ProseMirror')
177
-
193
+
178
194
  // Focus and type in the editor
179
195
  fireEvent.focus(editorContent)
180
- fireEvent.input(editorContent, {
196
+ fireEvent.input(editorContent, {
181
197
  target: { textContent: 'New content' }
182
198
  })
183
-
199
+
184
200
  await waitFor(() => {
185
201
  expect(editorContent).toHaveTextContent('New content')
186
202
  })
187
203
  })
188
204
  })
189
205
  })
190
-