-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add custom content errors and rename item form component
- Loading branch information
Showing
16 changed files
with
137 additions
and
121 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<%= turbo_frame_tag dom_id(container, :errors) do %> | ||
<%= form_builder.govuk_error_summary(**html_attributes) %> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# frozen_string_literal: true | ||
|
||
module Koi | ||
module Content | ||
module Editor | ||
class ErrorsComponent < ViewComponent::Base | ||
include Katalyst::HtmlAttributes | ||
include Katalyst::Tables::TurboReplaceable | ||
include Turbo::FramesHelper | ||
|
||
attr_reader :container | ||
|
||
def initialize(container:) | ||
super() | ||
|
||
@container = container | ||
end | ||
|
||
def id | ||
dom_id(container, :errors) | ||
end | ||
|
||
def form_builder | ||
Koi::FormBuilder.new(container.model_name.param_key, container, self, {}) | ||
end | ||
end | ||
end | ||
end | ||
end |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
# frozen_string_literal: true | ||
|
||
module Koi | ||
module Content | ||
module Editor | ||
class ItemFormComponent < ViewComponent::Base | ||
attr_reader :model, :url, :builder, :form | ||
|
||
def initialize(model:, url:, builder: Koi::FormBuilder) | ||
super() | ||
|
||
@model = model | ||
@url = url | ||
@builder = builder | ||
end | ||
|
||
def form_with(**options, &block) | ||
view_context.form_with(**options) do |form| | ||
@form = form | ||
form.extend(ContentFormHelper) | ||
capture(form, &block) | ||
end | ||
end | ||
|
||
def content | ||
@__vc_content_evaluated = true | ||
return @__vc_content if defined?(@__vc_content) | ||
|
||
@__vc_content = view_context.capture(@form, &@__vc_render_in_block) | ||
end | ||
|
||
def inspect | ||
"#<#{self.class.name} model: #{model.inspect} url: #{url.inspect}>" | ||
end | ||
|
||
module ContentFormHelper | ||
def content_heading_fieldset | ||
govuk_fieldset(legend: { text: "Heading", size: "m" }) do | ||
concat(content_heading_field(label: nil)) | ||
concat(content_heading_style_field) | ||
end | ||
end | ||
|
||
def content_heading_field(args = {}) | ||
govuk_text_field :heading, | ||
**{ label: { text: "Heading", size: "s" } }.deep_merge(args) | ||
end | ||
|
||
def content_heading_style_field(args = {}) | ||
govuk_collection_radio_buttons :heading_style, | ||
Katalyst::Content.config.heading_styles, | ||
:itself, | ||
:itself, | ||
**{ small: true, legend: { text: "Style", size: "s" } }.deep_merge(args) | ||
end | ||
|
||
def content_url_field(args = {}) | ||
govuk_text_field :url, | ||
**{ label: { text: "URL", size: "s" } }.deep_merge(args) | ||
end | ||
|
||
def content_http_method_field(methods, args = {}) | ||
govuk_select :http_method, methods, | ||
**{ label: { text: "HTTP method", size: "s" } }.deep_merge(args) | ||
end | ||
|
||
def content_target_field(targets, args = {}) | ||
govuk_select :target, targets, | ||
**{ label: { text: "HTTP target", size: "s" } }.deep_merge(args) | ||
end | ||
|
||
def content_background_field(args = {}) | ||
govuk_select :background, Katalyst::Content.config.backgrounds, | ||
**{ label: { size: "s" } }.deep_merge(args) | ||
end | ||
|
||
def content_visible_field(args = {}) | ||
govuk_check_box_field :visible, | ||
**{ label: { text: "Visible? ", size: "s" }, small: true }.deep_merge(args) | ||
end | ||
|
||
def content_buttons | ||
tag.div(class: "actions") do | ||
concat(admin_save("Done")) | ||
concat(admin_discard) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
<%= render Koi::Content::EditorComponent.new(model: aside, url: path) do |form| %> | ||
<%= render Koi::Content::Editor::ItemFormComponent.new(model: aside, url: path) do |form| %> | ||
<%= form.content_heading_fieldset %> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
<%= render Koi::Content::EditorComponent.new(model: column, url: path) do |form| %> | ||
<%= render Koi::Content::Editor::ItemFormComponent.new(model: column, url: path) do |form| %> | ||
<%= form.content_heading_fieldset %> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
<%= render Koi::Content::EditorComponent.new(model: group, url: path) do |form| %> | ||
<%= render Koi::Content::Editor::ItemFormComponent.new(model: group, url: path) do |form| %> | ||
<%= form.content_heading_fieldset %> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
<%= render Koi::Content::EditorComponent.new(model: item, url: path) do |form| %> | ||
<%= render Koi::Content::Editor::ItemFormComponent.new(model: item, url: path) do |form| %> | ||
<%= form.content_heading_fieldset %> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
<%= render Koi::Content::EditorComponent.new(model: section, url: path) do |form| %> | ||
<%= render Koi::Content::Editor::ItemFormComponent.new(model: section, url: path) do |form| %> | ||
<%= form.content_heading_fieldset %> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# frozen_string_literal: true | ||
|
||
Katalyst::Content.config.errors_component = "Koi::Content::Editor::ErrorsComponent" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
# Describe your gem and declare its dependencies: | ||
Gem::Specification.new do |s| | ||
s.name = "katalyst-koi" | ||
s.version = "4.3.0-beta" | ||
s.version = "4.3.0.beta.2" | ||
s.authors = ["Katalyst Interactive"] | ||
s.email = ["[email protected]"] | ||
|
||
|