app/pb_kits/playbook/props.rb in playbook_ui-2.9.9 vs app/pb_kits/playbook/props.rb in playbook_ui-3.0.0

- old
+ new

@@ -21,27 +21,30 @@ module Playbook module Props extend ActiveSupport::Concern def initialize(prop_values = {}, &block) - @values = { children: block }.merge(prop_values) + self.values = { children: block }.merge(Hash(prop_values)) self.class.props.each do |key, definition| - definition.validate! @values[key] + definition.validate! values[key] end end def prop(name) - self.class.props[name].value @values[name] + self.class.props[name].value values[name] end def generate_classname(*name_parts, separator: "_") [ name_parts.compact.join(separator), prop(:classname), ].compact.join(" ") end + attr_accessor :values + private :values, :values= + included do prop :id prop :data, type: Playbook::Props::Hash, default: {} prop :classname prop :aria, type: Playbook::Props::Hash, default: {} @@ -49,9 +52,14 @@ end class_methods do def props @props + end + + def clear_props + @props.keys.each { |prop_name| remove_method(prop_name) } + @props.clear end def prop(name, type: Playbook::Props::String, **options) @props ||= {} @props[name] = type.new(**options)