katalyst-govuk-formbuilder 1.1.1 → 1.2.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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c6480175ffd7ac7e718126f6b3e41314693c56cf87614d8691fb180adc7048fb
|
4
|
+
data.tar.gz: 67d870ab5c506e5dcfb9e85a599f1940085457963d04f114f8db11571eba0b9f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e6b24e8b2adbd0415313a030d1362b0b8739525ef1c0996dfb0d3f8dc4f18e040cb380ac9f4de090a4e9c22b961b6f2e2cd02701e3a5370df0c280b08b151f6a
|
7
|
+
data.tar.gz: 7bfea8bff24edd542f4a786becbefc587f3ba50e529c8a08f5d8469a12c404b75206cfeaf8ca33e4a0dd7d619741d7403da4324fe34efdf0a1a6fcd8c0854291
|
@@ -0,0 +1,108 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "govuk_design_system_formbuilder"
|
4
|
+
|
5
|
+
module GOVUKDesignSystemFormBuilder
|
6
|
+
module Elements
|
7
|
+
class RichTextArea < Base
|
8
|
+
using PrefixableArray
|
9
|
+
|
10
|
+
include Traits::Error
|
11
|
+
include Traits::Hint
|
12
|
+
include Traits::Label
|
13
|
+
include Traits::Supplemental
|
14
|
+
include Traits::HTMLAttributes
|
15
|
+
include Traits::HTMLClasses
|
16
|
+
|
17
|
+
def initialize(builder, object_name, attribute_name, hint:, label:, caption:, form_group:, **kwargs, &block)
|
18
|
+
super(builder, object_name, attribute_name, &block)
|
19
|
+
|
20
|
+
@label = label
|
21
|
+
@caption = caption
|
22
|
+
@hint = hint
|
23
|
+
@form_group = form_group
|
24
|
+
@html_attributes = kwargs
|
25
|
+
end
|
26
|
+
|
27
|
+
def html
|
28
|
+
Containers::FormGroup.new(*bound, **@form_group).html do
|
29
|
+
safe_join([label_element, supplemental_content, hint_element, error_element, rich_text_area])
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def rich_text_area
|
36
|
+
@builder.rich_text_area(@attribute_name, **attributes(@html_attributes))
|
37
|
+
end
|
38
|
+
|
39
|
+
def classes
|
40
|
+
build_classes(%(richtextarea), %(richtextarea--error) => has_errors?).prefix(brand)
|
41
|
+
end
|
42
|
+
|
43
|
+
def options
|
44
|
+
{
|
45
|
+
id: field_id(link_errors: true),
|
46
|
+
class: classes,
|
47
|
+
aria: { describedby: combine_references(hint_id, error_id, supplemental_id) },
|
48
|
+
}
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
module GOVUKDesignSystemFormBuilder
|
55
|
+
module Builder
|
56
|
+
delegate :config, to: GOVUKDesignSystemFormBuilder
|
57
|
+
|
58
|
+
# Generates a pair of +trix-toolbar+ and +trix-editor+ elements with a label, optional hint. Requires action-text to
|
59
|
+
# be correctly setup in the application
|
60
|
+
#
|
61
|
+
# @param attribute_name [Symbol] The name of the attribute
|
62
|
+
# @param hint [Hash,Proc] The content of the hint. No hint will be added if 'text' is left +nil+. When a +Proc+ is
|
63
|
+
# supplied the hint will be wrapped in a +div+ instead of a +span+
|
64
|
+
# @option hint text [String] the hint text
|
65
|
+
# @option hint kwargs [Hash] additional arguments are applied as attributes to the hint
|
66
|
+
# @param label [Hash,Proc] configures or sets the associated label content
|
67
|
+
# @option label text [String] the label text
|
68
|
+
# @option label size [String] the size of the label font, can be +xl+, +l+, +m+, +s+ or nil
|
69
|
+
# @option label tag [Symbol,String] the label's wrapper tag, intended to allow labels to act as page headings
|
70
|
+
# @option label hidden [Boolean] control the visibility of the label. Hidden labels will still be read by screen
|
71
|
+
# readers
|
72
|
+
# @option label kwargs [Hash] additional arguments are applied as attributes on the +label+ element
|
73
|
+
# @param caption [Hash] configures or sets the caption content which is inserted above the label
|
74
|
+
# @option caption text [String] the caption text
|
75
|
+
# @option caption size [String] the size of the caption, can be +xl+, +l+ or +m+. Defaults to +m+
|
76
|
+
# @option caption kwargs [Hash] additional arguments are applied as attributes on the caption +span+ element
|
77
|
+
# @option kwargs [Hash] kwargs additional arguments are applied as attributes to the +trix-editor+ element. This is
|
78
|
+
# picked up and handled by the action-text gem
|
79
|
+
# @param form_group [Hash] configures the form group
|
80
|
+
# @option form_group classes [Array,String] sets the form group's classes
|
81
|
+
# @option form_group kwargs [Hash] additional attributes added to the form group
|
82
|
+
# @param block [Block] arbitrary HTML that will be rendered between the hint and the input
|
83
|
+
# @return [ActiveSupport::SafeBuffer] HTML output
|
84
|
+
#
|
85
|
+
# @example A rich text area with injected content
|
86
|
+
# = f.govuk_rich_text_area :description,
|
87
|
+
# label: { text: 'Where did the incident take place?' } do
|
88
|
+
#
|
89
|
+
# p.govuk-inset-text
|
90
|
+
# | If you don't know exactly leave this section blank
|
91
|
+
#
|
92
|
+
# @example A rich text area with the label supplied as a proc
|
93
|
+
# = f.govuk_rich_text_area :instructions,
|
94
|
+
# label: -> { tag.h3("How do you set it up?") }
|
95
|
+
#
|
96
|
+
# @example A rich text area with a custom direct upload url and a custom stimulus controller
|
97
|
+
# = f.govuk_rich_text_area :description,
|
98
|
+
# data: {
|
99
|
+
# direct_upload_url: direct_uploads_url,
|
100
|
+
# controller: "content--editor--trix",
|
101
|
+
# action: "trix-initialize->content--editor--trix#trixInitialize",
|
102
|
+
# }
|
103
|
+
#
|
104
|
+
def govuk_rich_text_area(attribute_name, hint: {}, label: {}, caption: {}, form_group: {}, **kwargs, &block)
|
105
|
+
Elements::RichTextArea.new(self, object_name, attribute_name, hint: hint, label: label, caption: caption, form_group: form_group, **kwargs, &block).html
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: katalyst-govuk-formbuilder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Katalyst Interactive
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-10-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: govuk_design_system_formbuilder
|
@@ -38,6 +38,7 @@ files:
|
|
38
38
|
- app/assets/javascripts/katalyst/govuk/formbuilder.js
|
39
39
|
- app/assets/javascripts/katalyst/govuk/formbuilder.min.js
|
40
40
|
- config/importmap.rb
|
41
|
+
- lib/govuk_design_system_formbuilder/elements/rich_text_area.rb
|
41
42
|
- lib/katalyst/govuk/formbuilder.rb
|
42
43
|
- lib/katalyst/govuk/formbuilder/engine.rb
|
43
44
|
- lib/katalyst/govuk/formbuilder/frontend.rb
|