diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-08-19 12:08:42 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-08-19 12:08:42 +0300 |
commit | b76ae638462ab0f673e5915986070518dd3f9ad3 (patch) | |
tree | bdab0533383b52873be0ec0eb4d3c66598ff8b91 /lib/gitlab/form_builders | |
parent | 434373eabe7b4be9593d18a585fb763f1e5f1a6f (diff) |
Add latest changes from gitlab-org/gitlab@14-2-stable-eev14.2.0-rc42
Diffstat (limited to 'lib/gitlab/form_builders')
-rw-r--r-- | lib/gitlab/form_builders/gitlab_ui_form_builder.rb | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/lib/gitlab/form_builders/gitlab_ui_form_builder.rb b/lib/gitlab/form_builders/gitlab_ui_form_builder.rb new file mode 100644 index 00000000000..a5290508e42 --- /dev/null +++ b/lib/gitlab/form_builders/gitlab_ui_form_builder.rb @@ -0,0 +1,55 @@ +# frozen_string_literal: true + +module Gitlab + module FormBuilders + class GitlabUiFormBuilder < ActionView::Helpers::FormBuilder + def gitlab_ui_checkbox_component( + method, + label, + help_text: nil, + checkbox_options: {}, + checked_value: '1', + unchecked_value: '0', + label_options: {} + ) + @template.content_tag( + :div, + class: 'gl-form-checkbox custom-control custom-checkbox' + ) do + @template.check_box( + @object_name, + method, + format_options(checkbox_options, ['custom-control-input']), + checked_value, + unchecked_value + ) + + @template.label( + @object_name, method, format_options(label_options, ['custom-control-label']) + ) do + if help_text + @template.content_tag( + :span, + label + ) + + @template.content_tag( + :p, + help_text, + class: 'help-text' + ) + else + label + end + end + end + end + + private + + def format_options(options, classes) + classes << options[:class] + + objectify_options(options.merge({ class: classes.flatten.compact })) + end + end + end +end |