diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-03-18 23:02:30 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-03-18 23:02:30 +0300 |
commit | 41fe97390ceddf945f3d967b8fdb3de4c66b7dea (patch) | |
tree | 9c8d89a8624828992f06d892cd2f43818ff5dcc8 /app/components | |
parent | 0804d2dc31052fb45a1efecedc8e06ce9bc32862 (diff) |
Add latest changes from gitlab-org/gitlab@14-9-stable-eev14.9.0-rc42
Diffstat (limited to 'app/components')
-rw-r--r-- | app/components/pajamas/component.rb | 23 | ||||
-rw-r--r-- | app/components/pajamas/toggle_component.html.haml | 16 | ||||
-rw-r--r-- | app/components/pajamas/toggle_component.rb | 34 |
3 files changed, 73 insertions, 0 deletions
diff --git a/app/components/pajamas/component.rb b/app/components/pajamas/component.rb new file mode 100644 index 00000000000..b05d93b680e --- /dev/null +++ b/app/components/pajamas/component.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +module Pajamas + class Component < ViewComponent::Base + private + + # :nocov: + + # Filter a given a value against a list of allowed values + # If no value is given or value is not allowed return default one + # + # @param [Object] value + # @param [Enumerable] allowed_values + # @param [Object] default + def filter_attribute(value, allowed_values, default: nil) + return default unless value + return value if allowed_values.include?(value) + + default + end + # :nocov: + end +end diff --git a/app/components/pajamas/toggle_component.html.haml b/app/components/pajamas/toggle_component.html.haml new file mode 100644 index 00000000000..1716e8b69c3 --- /dev/null +++ b/app/components/pajamas/toggle_component.html.haml @@ -0,0 +1,16 @@ +%span{ class: @classes, + data: { name: @name, + id: @id, + is_checked: @is_checked.to_s, + disabled: @is_disabled.to_s, + is_loading: @is_loading.to_s, + label: @label, + help: @help, + label_position: @label_position, + **@data } } + +-# Leverage this block to render a rich help text. To render a plain text help text, +-# prefer the `help` parameter. +- if content.present? + .gl-text-secondary.gl-mt-1 + = content diff --git a/app/components/pajamas/toggle_component.rb b/app/components/pajamas/toggle_component.rb new file mode 100644 index 00000000000..2d99f3d3b69 --- /dev/null +++ b/app/components/pajamas/toggle_component.rb @@ -0,0 +1,34 @@ +# frozen_string_literal: true + +# Renders a GlToggle root element +# To actually initialize the component, make sure to call the initToggle helper from ~/toggles. +class Pajamas::ToggleComponent < Pajamas::Component + LABEL_POSITION_OPTIONS = [:top, :left, :hidden].freeze + + # @param [String] classes + # @param [String] label + # @param [Symbol] label_position :top, :left or :hidden + # @param [String] id + # @param [String] name + # @param [String] help + # @param [Hash] data + # @param [Boolean] is_disabled + # @param [Boolean] is_checked + # @param [Boolean] is_loading + def initialize( + classes:, label: nil, label_position: nil, + id: nil, name: nil, help: nil, data: {}, + is_disabled: false, is_checked: false, is_loading: false) + + @id = id + @name = name + @classes = classes + @label = label + @label_position = filter_attribute(label_position, LABEL_POSITION_OPTIONS) + @help = help + @data = data + @is_disabled = is_disabled + @is_checked = is_checked + @is_loading = is_loading + end +end |