lib/playbook/kit_base.rb in playbook_ui-14.5.0 vs lib/playbook/kit_base.rb in playbook_ui-14.6.0.pre.alpha.PBNTR5554217

- old
+ new

@@ -71,19 +71,31 @@ prop :id prop :data, type: Playbook::Props::HashProp, default: {} prop :aria, type: Playbook::Props::HashProp, default: {} prop :html_options, type: Playbook::Props::HashProp, default: {} prop :children, type: Playbook::Props::Proc + prop :style, type: Playbook::Props::HashProp, default: {} + prop :height + prop :min_height + prop :max_height def object self end def combined_html_options default_html_options.merge(html_options.deep_merge(data_attributes)) end + def global_inline_props + { + height: height, + min_height: min_height, + max_height: max_height, + }.compact + end + # rubocop:disable Layout/CommentIndentation # pb_content_tag information (potentially to be abstracted into its own dev doc in the future) # The pb_content_tag generates HTML content tags for rails kits with flexible options. # Modify a generated kit.html.erb file accordingly (the default_options listed below no longer need to be explictly outlined in that file, only modifications). # name - the first argument is for HTML tag. The default is :div. @@ -111,16 +123,19 @@ # rubocop:enable Style/OptionalBooleanParameter private def default_options - { + options = { id: id, data: data, class: classname, aria: aria, } + inline_styles = dynamic_inline_props + options[:style] = inline_styles if inline_styles.present? + options end def default_html_options {} end @@ -128,8 +143,13 @@ def data_attributes { data: data, aria: aria, }.transform_keys { |key| key.to_s.tr("_", "-").to_sym } + end + + def dynamic_inline_props + styles = global_inline_props.map { |key, value| "#{key.to_s.gsub('_', '-')}: #{value};" if value.present? }.compact + styles.join(" ").presence end end end