Module: LucidComponent::API

Defined in:
lib/lucid_component/api.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/lucid_component/api.rb', line 3

def self.included(base)
  base.instance_exec do
    # store
    attr_accessor :app_store
    attr_accessor :class_store
    attr_accessor :store

    def default_app_store_defined
      @default_app_store_defined
    end

    def default_class_store_defined
      @default_class_store_defined
    end

    def default_instance_store_defined
      @default_instance_store_defined
    end

    def app_store
      @default_app_store_defined = true
      @default_app_store ||= ::LucidComponent::AppStoreDefaults.new(state, self.to_s)
    end

    def class_store
      @default_class_store_defined = true
      @default_class_store ||= ::LucidComponent::ComponentClassStoreDefaults.new(state, self.to_s)
    end

    def store
      @default_instance_store_defined = true
      @default_instance_store ||= ::LucidComponent::ComponentInstanceStoreDefaults.new(state, self.to_s)
    end

    def store_updates(switch)
      case switch
      when :on then `base.store_updates = true`
      when :off then `base.store_updates = false`
      end
    end

    # styles
    def styles(styles_hash = nil, &block)
      if block_given?
        %x{
          base.jss_styles = function(theme) {
            let wrapped_theme = Opal.React.Component.Styles.$new(theme);
            var result = block.$call(wrapped_theme);
            return result.$to_n();
          }
        }
        nil
      elsif styles_hash
        `base.jss_styles = #{styles_hash.to_n}` if styles_hash
        styles_hash
      elsif `typeof base.jss_styles === 'object'`
        `Opal.Hash.$new(base.jss_styles)`
      else
        nil
      end
    end
    alias_method :styles=, :styles
  end

  def styles
    props.classes
  end

  def theme
    props.theme
  end
end

Instance Method Details

#stylesObject



67
68
69
# File 'lib/lucid_component/api.rb', line 67

def styles
  props.classes
end

#themeObject



71
72
73
# File 'lib/lucid_component/api.rb', line 71

def theme
  props.theme
end