odt-ui-rails 2.2.7 → 2.2.9
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 +4 -4
- data/README.md +11 -1
- data/app/assets/stylesheets/odt_ui/styles.css +2872 -1949
- data/app/assets/stylesheets/odt_ui/tokens.css +26 -27
- data/app/assets/stylesheets/odt_ui.css +2709 -1787
- data/lib/generators/odt/templates/odt_ui.rbs +14 -0
- data/lib/odt_ui/helper.rb +55 -0
- data/lib/odt_ui/version.rb +1 -1
- data/sig/odt_ui.rbs +14 -0
- metadata +1 -1
|
@@ -41,6 +41,9 @@ module OdtUi
|
|
|
41
41
|
type radio_size = :sm | :md | :lg
|
|
42
42
|
type radio_orientation = :horizontal | :vertical
|
|
43
43
|
|
|
44
|
+
type switch_color = :primary | :secondary | :success | :warning | :danger | :info | :dark
|
|
45
|
+
type switch_size = :sm | :md | :lg
|
|
46
|
+
|
|
44
47
|
def odt_button: (
|
|
45
48
|
?String? text,
|
|
46
49
|
?variant: button_variant,
|
|
@@ -199,6 +202,17 @@ module OdtUi
|
|
|
199
202
|
**untyped
|
|
200
203
|
) -> untyped
|
|
201
204
|
|
|
205
|
+
def odt_switch: (
|
|
206
|
+
?label: String?,
|
|
207
|
+
?description: String?,
|
|
208
|
+
?checked: bool,
|
|
209
|
+
?color: switch_color,
|
|
210
|
+
?size: switch_size,
|
|
211
|
+
?disabled: bool,
|
|
212
|
+
?error: String?,
|
|
213
|
+
**untyped
|
|
214
|
+
) ?{ () -> untyped } -> untyped
|
|
215
|
+
|
|
202
216
|
def odt_form_group: (
|
|
203
217
|
?label: String?,
|
|
204
218
|
?error: String?,
|
data/lib/odt_ui/helper.rb
CHANGED
|
@@ -457,6 +457,61 @@ module OdtUi
|
|
|
457
457
|
end
|
|
458
458
|
end
|
|
459
459
|
|
|
460
|
+
def odt_switch(label: nil, description: nil, checked: false, color: :primary, size: :md, disabled: false, error: nil, **html_options, &block)
|
|
461
|
+
color_key = color.to_sym == :dark ? "neutral" : color.to_s.tr("_", "-")
|
|
462
|
+
size_key = size.to_s.tr("_", "-")
|
|
463
|
+
has_error = error.present?
|
|
464
|
+
|
|
465
|
+
classes = [
|
|
466
|
+
"odt-switch",
|
|
467
|
+
"odt-switch--#{color_key}",
|
|
468
|
+
"odt-switch--#{size_key}"
|
|
469
|
+
]
|
|
470
|
+
classes << "odt-switch--error" if has_error
|
|
471
|
+
classes << html_options.delete(:class)
|
|
472
|
+
|
|
473
|
+
opts = html_options.merge(
|
|
474
|
+
type: "checkbox",
|
|
475
|
+
role: "switch",
|
|
476
|
+
class: classes.compact.reject(&:blank?).join(" "),
|
|
477
|
+
disabled: disabled
|
|
478
|
+
)
|
|
479
|
+
opts[:checked] = "checked" if checked
|
|
480
|
+
opts["aria-checked"] = checked ? "true" : "false"
|
|
481
|
+
|
|
482
|
+
switch_input = tag.input(**opts)
|
|
483
|
+
|
|
484
|
+
resolved_label = block_given? ? capture(&block) : label
|
|
485
|
+
|
|
486
|
+
if resolved_label.blank? && description.blank? && !has_error
|
|
487
|
+
return switch_input
|
|
488
|
+
end
|
|
489
|
+
|
|
490
|
+
container_classes = ["odt-switch-container"]
|
|
491
|
+
container_classes << "odt-switch-container--disabled" if disabled
|
|
492
|
+
|
|
493
|
+
tag.div(class: "odt-switch-wrapper") do
|
|
494
|
+
parts = []
|
|
495
|
+
parts << tag.label(class: container_classes.join(" ")) do
|
|
496
|
+
label_parts = [switch_input]
|
|
497
|
+
|
|
498
|
+
if resolved_label.present? || description.present?
|
|
499
|
+
label_parts << tag.div(class: "odt-switch__label-content") do
|
|
500
|
+
d_parts = []
|
|
501
|
+
d_parts << tag.span(resolved_label, class: "odt-switch__label") if resolved_label.present?
|
|
502
|
+
d_parts << tag.span(description, class: "odt-switch__description") if description.present?
|
|
503
|
+
safe_join(d_parts)
|
|
504
|
+
end
|
|
505
|
+
end
|
|
506
|
+
|
|
507
|
+
safe_join(label_parts)
|
|
508
|
+
end
|
|
509
|
+
|
|
510
|
+
parts << tag.p(error, class: "odt-error-text", role: "alert") if has_error
|
|
511
|
+
safe_join(parts)
|
|
512
|
+
end
|
|
513
|
+
end
|
|
514
|
+
|
|
460
515
|
def odt_form_group(label: nil, error: nil, helper: nil, helper_text: nil, success: nil, required: false, **html_options, &block)
|
|
461
516
|
resolved_helper = helper.presence || helper_text.presence
|
|
462
517
|
has_error = error.present?
|
data/lib/odt_ui/version.rb
CHANGED
data/sig/odt_ui.rbs
CHANGED
|
@@ -41,6 +41,9 @@ module OdtUi
|
|
|
41
41
|
type radio_size = :sm | :md | :lg
|
|
42
42
|
type radio_orientation = :horizontal | :vertical
|
|
43
43
|
|
|
44
|
+
type switch_color = :primary | :secondary | :success | :warning | :danger | :info | :dark
|
|
45
|
+
type switch_size = :sm | :md | :lg
|
|
46
|
+
|
|
44
47
|
def odt_button: (
|
|
45
48
|
?String? text,
|
|
46
49
|
?variant: button_variant,
|
|
@@ -199,6 +202,17 @@ module OdtUi
|
|
|
199
202
|
**untyped
|
|
200
203
|
) -> untyped
|
|
201
204
|
|
|
205
|
+
def odt_switch: (
|
|
206
|
+
?label: String?,
|
|
207
|
+
?description: String?,
|
|
208
|
+
?checked: bool,
|
|
209
|
+
?color: switch_color,
|
|
210
|
+
?size: switch_size,
|
|
211
|
+
?disabled: bool,
|
|
212
|
+
?error: String?,
|
|
213
|
+
**untyped
|
|
214
|
+
) ?{ () -> untyped } -> untyped
|
|
215
|
+
|
|
202
216
|
def odt_form_group: (
|
|
203
217
|
?label: String?,
|
|
204
218
|
?error: String?,
|