primer_view_components 0.0.38 → 0.0.43
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +283 -27
- data/app/assets/javascripts/primer_view_components.js +1 -1
- data/app/assets/javascripts/primer_view_components.js.map +1 -1
- data/app/components/primer/auto_complete.rb +4 -2
- data/app/components/primer/auto_complete/item.rb +1 -1
- data/app/components/primer/avatar_component.rb +22 -3
- data/app/components/primer/avatar_stack_component.rb +8 -5
- data/app/components/primer/base_button.rb +1 -1
- data/app/components/primer/base_component.rb +24 -13
- data/app/components/primer/blankslate_component.html.erb +1 -0
- data/app/components/primer/blankslate_component.rb +68 -47
- data/app/components/primer/border_box_component.rb +1 -1
- data/app/components/primer/box_component.rb +1 -1
- data/app/components/primer/breadcrumb_component.rb +1 -1
- data/app/components/primer/button_component.html.erb +9 -0
- data/app/components/primer/button_component.rb +39 -5
- data/app/components/primer/button_group.rb +3 -3
- data/app/components/primer/button_marketing_component.rb +1 -1
- data/app/components/primer/clipboard_copy.rb +1 -1
- data/app/components/primer/clipboard_copy_component.js +17 -8
- data/app/components/primer/clipboard_copy_component.ts +19 -8
- data/app/components/primer/close_button.rb +4 -2
- data/app/components/primer/component.rb +22 -3
- data/app/components/primer/counter_component.rb +6 -1
- data/app/components/primer/details_component.rb +1 -1
- data/app/components/primer/dropdown/menu_component.rb +1 -1
- data/app/components/primer/dropdown_component.rb +1 -1
- data/app/components/primer/flash_component.rb +3 -3
- data/app/components/primer/flex_component.rb +28 -1
- data/app/components/primer/flex_item_component.rb +20 -1
- data/app/components/primer/heading_component.rb +12 -19
- data/app/components/primer/hidden_text_expander.rb +4 -4
- data/app/components/primer/icon_button.rb +65 -0
- data/app/components/primer/image.rb +46 -0
- data/app/components/primer/image_crop.d.ts +1 -0
- data/app/components/primer/image_crop.html.erb +12 -0
- data/app/components/primer/image_crop.js +1 -0
- data/app/components/primer/image_crop.rb +36 -0
- data/app/components/primer/image_crop.ts +1 -0
- data/app/components/primer/label_component.rb +7 -3
- data/app/components/primer/layout_component.rb +1 -1
- data/app/components/primer/link_component.rb +1 -1
- data/app/components/primer/local_time.d.ts +1 -0
- data/app/components/primer/local_time.js +1 -0
- data/app/components/primer/local_time.rb +59 -0
- data/app/components/primer/local_time.ts +1 -0
- data/app/components/primer/{markdown_component.rb → markdown.rb} +12 -7
- data/app/components/primer/menu_component.rb +1 -1
- data/app/components/primer/navigation/tab_component.rb +8 -1
- data/app/components/primer/octicon_component.html.erb +7 -0
- data/app/components/primer/octicon_component.rb +53 -19
- data/app/components/primer/octicon_symbols_component.html.erb +3 -0
- data/app/components/primer/octicon_symbols_component.rb +61 -0
- data/app/components/primer/popover_component.rb +1 -1
- data/app/components/primer/primer.d.ts +2 -0
- data/app/components/primer/primer.js +2 -0
- data/app/components/primer/primer.ts +2 -0
- data/app/components/primer/progress_bar_component.rb +1 -1
- data/app/components/primer/spinner_component.rb +3 -3
- data/app/components/primer/state_component.rb +1 -1
- data/app/components/primer/subhead_component.rb +34 -4
- data/app/components/primer/tab_container_component.rb +1 -1
- data/app/components/primer/tab_nav_component.html.erb +5 -1
- data/app/components/primer/tab_nav_component.rb +63 -10
- data/app/components/primer/text_component.rb +6 -3
- data/app/components/primer/time_ago_component.rb +1 -1
- data/app/components/primer/timeline_item_component.rb +1 -1
- data/app/components/primer/{tooltip_component.rb → tooltip.rb} +11 -9
- data/app/components/primer/truncate.rb +7 -3
- data/app/components/primer/underline_nav_component.html.erb +1 -1
- data/app/components/primer/underline_nav_component.rb +18 -2
- data/app/lib/primer/classify.rb +27 -39
- data/app/lib/primer/classify/cache.rb +35 -15
- data/app/lib/primer/classify/flex.rb +111 -0
- data/app/lib/primer/classify/functional_border_colors.rb +1 -2
- data/app/lib/primer/classify/grid.rb +45 -0
- data/app/lib/primer/fetch_or_fallback_helper.rb +2 -2
- data/app/lib/primer/octicon/cache.rb +42 -0
- data/app/lib/primer/tabbed_component_helper.rb +2 -2
- data/app/lib/primer/view_helper.rb +2 -1
- data/lib/primer/view_components.rb +1 -1
- data/lib/primer/view_components/engine.rb +2 -0
- data/lib/primer/view_components/linters.rb +3 -0
- data/lib/primer/view_components/linters/button_component_migration_counter.rb +16 -0
- data/lib/primer/view_components/linters/flash_component_migration_counter.rb +16 -0
- data/lib/primer/view_components/linters/helpers.rb +89 -0
- data/lib/primer/view_components/version.rb +1 -1
- data/lib/tasks/coverage.rake +14 -0
- data/lib/tasks/docs.rake +372 -0
- data/lib/tasks/statuses.rake +12 -0
- data/lib/yard/docs_helper.rb +57 -0
- data/static/statuses.json +54 -1
- metadata +62 -11
- data/app/components/primer/button_component.rb.orig +0 -138
- data/app/components/primer/foo_bar.d.ts +0 -1
- data/app/components/primer/foo_bar.js +0 -1
data/app/lib/primer/classify.rb
CHANGED
@@ -3,16 +3,11 @@
|
|
3
3
|
module Primer
|
4
4
|
# :nodoc:
|
5
5
|
class Classify
|
6
|
-
DIRECTION_KEY = :direction
|
7
|
-
JUSTIFY_CONTENT_KEY = :justify_content
|
8
|
-
ALIGN_ITEMS_KEY = :align_items
|
9
6
|
DISPLAY_KEY = :display
|
10
7
|
SPACING_KEYS = Primer::Classify::Spacing::KEYS
|
11
|
-
RESPONSIVE_KEYS = ([DISPLAY_KEY, DIRECTION_KEY, JUSTIFY_CONTENT_KEY, ALIGN_ITEMS_KEY, :col, :float] + SPACING_KEYS).freeze
|
12
|
-
BREAKPOINTS = ["", "-sm", "-md", "-lg", "-xl"].freeze
|
13
8
|
|
14
9
|
# Keys where we can simply translate { key: value } into ".key-value"
|
15
|
-
CONCAT_KEYS = SPACING_KEYS + %i[hide position v float
|
10
|
+
CONCAT_KEYS = SPACING_KEYS + %i[hide position v float text box_shadow].freeze
|
16
11
|
|
17
12
|
INVALID_CLASS_NAME_PREFIXES =
|
18
13
|
(["bg-", "color-", "text-", "d-", "v-align-", "wb-", "box-shadow-"] + CONCAT_KEYS.map { |k| "#{k}-" }).freeze
|
@@ -21,16 +16,16 @@ module Primer
|
|
21
16
|
BG_KEY = :bg
|
22
17
|
VERTICAL_ALIGN_KEY = :vertical_align
|
23
18
|
WORD_BREAK_KEY = :word_break
|
24
|
-
TEXT_KEYS = %i[text_align
|
25
|
-
FLEX_KEY = :flex
|
26
|
-
FLEX_GROW_KEY = :flex_grow
|
27
|
-
FLEX_SHRINK_KEY = :flex_shrink
|
28
|
-
ALIGN_SELF_KEY = :align_self
|
19
|
+
TEXT_KEYS = %i[font_family font_style font_weight text_align text_transform].freeze
|
29
20
|
WIDTH_KEY = :width
|
30
21
|
HEIGHT_KEY = :height
|
31
22
|
BOX_SHADOW_KEY = :box_shadow
|
32
23
|
VISIBILITY_KEY = :visibility
|
33
24
|
ANIMATION_KEY = :animation
|
25
|
+
CONTAINER_KEY = :container
|
26
|
+
|
27
|
+
BREAKPOINTS = ["", "-sm", "-md", "-lg", "-xl"].freeze
|
28
|
+
RESPONSIVE_KEYS = ([DISPLAY_KEY, :float, Primer::Classify::Grid::COL_KEY] + SPACING_KEYS + Primer::Classify::Flex::RESPONSIVE_KEYS).freeze
|
34
29
|
|
35
30
|
BOOLEAN_MAPPINGS = {
|
36
31
|
underline: {
|
@@ -89,6 +84,8 @@ module Primer
|
|
89
84
|
BORDER_MARGIN_KEYS +
|
90
85
|
TYPOGRAPHY_KEYS +
|
91
86
|
TEXT_KEYS +
|
87
|
+
Primer::Classify::Flex::KEYS +
|
88
|
+
Primer::Classify::Grid::KEYS +
|
92
89
|
[
|
93
90
|
BORDER_KEY,
|
94
91
|
BORDER_COLOR_KEY,
|
@@ -98,18 +95,12 @@ module Primer
|
|
98
95
|
DISPLAY_KEY,
|
99
96
|
VERTICAL_ALIGN_KEY,
|
100
97
|
WORD_BREAK_KEY,
|
101
|
-
DIRECTION_KEY,
|
102
|
-
JUSTIFY_CONTENT_KEY,
|
103
|
-
ALIGN_ITEMS_KEY,
|
104
|
-
FLEX_KEY,
|
105
|
-
FLEX_GROW_KEY,
|
106
|
-
FLEX_SHRINK_KEY,
|
107
|
-
ALIGN_SELF_KEY,
|
108
98
|
WIDTH_KEY,
|
109
99
|
HEIGHT_KEY,
|
110
100
|
BOX_SHADOW_KEY,
|
111
101
|
VISIBILITY_KEY,
|
112
|
-
ANIMATION_KEY
|
102
|
+
ANIMATION_KEY,
|
103
|
+
CONTAINER_KEY
|
113
104
|
]
|
114
105
|
).freeze
|
115
106
|
|
@@ -120,7 +111,7 @@ module Primer
|
|
120
111
|
extracted_results[:class] = [
|
121
112
|
validated_class_names(classes),
|
122
113
|
extracted_results.delete(:classes)
|
123
|
-
].compact.join(" ").presence
|
114
|
+
].compact.join(" ").strip.presence
|
124
115
|
|
125
116
|
extracted_results[:style] = [
|
126
117
|
extracted_results.delete(:styles),
|
@@ -135,13 +126,13 @@ module Primer
|
|
135
126
|
def validated_class_names(classes)
|
136
127
|
return if classes.blank?
|
137
128
|
|
138
|
-
if ENV["
|
129
|
+
if force_system_arguments? && !ENV["PRIMER_WARNINGS_DISABLED"]
|
139
130
|
invalid_class_names =
|
140
131
|
classes.split(" ").each_with_object([]) do |class_name, memo|
|
141
132
|
memo << class_name if INVALID_CLASS_NAME_PREFIXES.any? { |prefix| class_name.start_with?(prefix) }
|
142
133
|
end
|
143
134
|
|
144
|
-
raise ArgumentError, "Use System Arguments (https://primer.style/view-components/system-arguments) instead of Primer CSS class #{'name'.pluralize(invalid_class_names.length)} #{invalid_class_names.to_sentence}. This warning will not be raised in production." if invalid_class_names.any?
|
135
|
+
raise ArgumentError, "Use System Arguments (https://primer.style/view-components/system-arguments) instead of Primer CSS class #{'name'.pluralize(invalid_class_names.length)} #{invalid_class_names.to_sentence}. This warning will not be raised in production. Set PRIMER_WARNINGS_DISABLED=1 to disable this warning." if invalid_class_names.any?
|
145
136
|
end
|
146
137
|
|
147
138
|
classes
|
@@ -216,23 +207,12 @@ module Primer
|
|
216
207
|
memo[:classes] << "#{key.to_s.dasherize}-#{val}"
|
217
208
|
elsif key == BORDER_RADIUS_KEY
|
218
209
|
memo[:classes] << "rounded-#{val}"
|
219
|
-
elsif key
|
220
|
-
memo[:classes] <<
|
221
|
-
elsif key
|
222
|
-
|
223
|
-
memo[:classes] << "flex#{breakpoint}-justify-#{formatted_value}"
|
224
|
-
elsif key == ALIGN_ITEMS_KEY
|
225
|
-
memo[:classes] << "flex#{breakpoint}-items-#{val.to_s.gsub('flex_', '')}"
|
226
|
-
elsif key == FLEX_KEY
|
227
|
-
memo[:classes] << "flex-#{val}"
|
228
|
-
elsif key == FLEX_GROW_KEY
|
229
|
-
memo[:classes] << "flex-grow-#{val}"
|
230
|
-
elsif key == FLEX_SHRINK_KEY
|
231
|
-
memo[:classes] << "flex-shrink-#{val}"
|
232
|
-
elsif key == ALIGN_SELF_KEY
|
233
|
-
memo[:classes] << "flex-self-#{val}"
|
210
|
+
elsif Primer::Classify::Flex::KEYS.include?(key)
|
211
|
+
memo[:classes] << Primer::Classify::Flex.classes(key, val, breakpoint)
|
212
|
+
elsif Primer::Classify::Grid::KEYS.include?(key)
|
213
|
+
memo[:classes] << Primer::Classify::Grid.classes(key, val, breakpoint)
|
234
214
|
elsif key == WIDTH_KEY || key == HEIGHT_KEY
|
235
|
-
if val == :fit
|
215
|
+
if val == :fit
|
236
216
|
memo[:classes] << "#{key}-#{val}"
|
237
217
|
else
|
238
218
|
memo[key] = val
|
@@ -240,7 +220,11 @@ module Primer
|
|
240
220
|
elsif TEXT_KEYS.include?(key)
|
241
221
|
memo[:classes] << "text-#{val.to_s.dasherize}"
|
242
222
|
elsif TYPOGRAPHY_KEYS.include?(key)
|
243
|
-
memo[:classes] <<
|
223
|
+
memo[:classes] << if val == :small || val == :normal
|
224
|
+
"text-#{val.to_s.dasherize}"
|
225
|
+
else
|
226
|
+
"f#{val.to_s.dasherize}"
|
227
|
+
end
|
244
228
|
elsif key == BOX_SHADOW_KEY
|
245
229
|
memo[:classes] << if val == true
|
246
230
|
"color-shadow-small"
|
@@ -261,6 +245,10 @@ module Primer
|
|
261
245
|
memo[:classes] << "#{key.to_s.dasherize}#{breakpoint}-#{val.to_s.dasherize}"
|
262
246
|
end
|
263
247
|
end
|
248
|
+
|
249
|
+
def force_system_arguments?
|
250
|
+
Rails.application.config.primer_view_components.force_system_arguments
|
251
|
+
end
|
264
252
|
end
|
265
253
|
|
266
254
|
Cache.preload!
|
@@ -40,18 +40,33 @@ module Primer
|
|
40
40
|
)
|
41
41
|
|
42
42
|
preload(
|
43
|
-
keys: Primer::Classify::DIRECTION_KEY,
|
44
|
-
values:
|
43
|
+
keys: Primer::Classify::Flex::DIRECTION_KEY,
|
44
|
+
values: Primer::Classify::Flex::DIRECTION_VALUES
|
45
45
|
)
|
46
46
|
|
47
47
|
preload(
|
48
|
-
keys: Primer::Classify::JUSTIFY_CONTENT_KEY,
|
49
|
-
values:
|
48
|
+
keys: Primer::Classify::Flex::JUSTIFY_CONTENT_KEY,
|
49
|
+
values: Primer::Classify::Flex::JUSTIFY_CONTENT_VALUES
|
50
50
|
)
|
51
51
|
|
52
52
|
preload(
|
53
|
-
keys: Primer::Classify::ALIGN_ITEMS_KEY,
|
54
|
-
values:
|
53
|
+
keys: Primer::Classify::Flex::ALIGN_ITEMS_KEY,
|
54
|
+
values: Primer::Classify::Flex::ALIGN_ITEMS_VALUES
|
55
|
+
)
|
56
|
+
|
57
|
+
preload(
|
58
|
+
keys: Primer::Classify::Grid::CONTAINER_KEY,
|
59
|
+
values: Primer::Classify::Grid::CONTAINER_VALUES
|
60
|
+
)
|
61
|
+
|
62
|
+
preload(
|
63
|
+
keys: Primer::Classify::Grid::CLEARFIX_KEY,
|
64
|
+
values: [true]
|
65
|
+
)
|
66
|
+
|
67
|
+
preload(
|
68
|
+
keys: Primer::Classify::Grid::COL_KEY,
|
69
|
+
values: Primer::Classify::Grid::COL_VALUES
|
55
70
|
)
|
56
71
|
|
57
72
|
preload(
|
@@ -61,12 +76,12 @@ module Primer
|
|
61
76
|
|
62
77
|
preload(
|
63
78
|
keys: [Primer::Classify::COLOR_KEY],
|
64
|
-
values:
|
79
|
+
values: Primer::Classify::FunctionalTextColors::OPTIONS
|
65
80
|
)
|
66
81
|
|
67
82
|
preload(
|
68
83
|
keys: [Primer::Classify::BG_KEY],
|
69
|
-
values:
|
84
|
+
values: Primer::Classify::FunctionalBackgroundColors::OPTIONS
|
70
85
|
)
|
71
86
|
|
72
87
|
preload(
|
@@ -90,23 +105,28 @@ module Primer
|
|
90
105
|
)
|
91
106
|
|
92
107
|
preload(
|
93
|
-
keys: Primer::Classify::FLEX_KEY,
|
94
|
-
values:
|
108
|
+
keys: Primer::Classify::Flex::FLEX_KEY,
|
109
|
+
values: Primer::Classify::Flex::FLEX_VALUES
|
110
|
+
)
|
111
|
+
|
112
|
+
preload(
|
113
|
+
keys: Primer::Classify::Flex::GROW_KEY,
|
114
|
+
values: Primer::Classify::Flex::GROW_VALUES
|
95
115
|
)
|
96
116
|
|
97
117
|
preload(
|
98
|
-
keys:
|
99
|
-
values:
|
118
|
+
keys: Primer::Classify::Flex::SHRINK_KEY,
|
119
|
+
values: Primer::Classify::Flex::SHRINK_VALUES
|
100
120
|
)
|
101
121
|
|
102
122
|
preload(
|
103
|
-
keys:
|
104
|
-
values:
|
123
|
+
keys: Primer::Classify::Flex::ALIGN_SELF_KEY,
|
124
|
+
values: Primer::Classify::Flex::ALIGN_SELF_VALUES
|
105
125
|
)
|
106
126
|
|
107
127
|
preload(
|
108
128
|
keys: [Primer::Classify::WIDTH_KEY, Primer::Classify::HEIGHT_KEY],
|
109
|
-
values: [:fit
|
129
|
+
values: [:fit]
|
110
130
|
)
|
111
131
|
|
112
132
|
preload(
|
@@ -0,0 +1,111 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Primer
|
4
|
+
class Classify
|
5
|
+
# Handler for PrimerCSS flex classes.
|
6
|
+
class Flex
|
7
|
+
extend Primer::FetchOrFallbackHelper
|
8
|
+
|
9
|
+
FLEX_KEY = :flex
|
10
|
+
FLEX_VALUES = [1, :auto].freeze
|
11
|
+
|
12
|
+
WRAP_KEY = :flex_wrap
|
13
|
+
WRAP_MAPPINGS = {
|
14
|
+
wrap: "flex-wrap",
|
15
|
+
nowrap: "flex-nowrap",
|
16
|
+
reverse: "flex-wrap-reverse"
|
17
|
+
}.freeze
|
18
|
+
|
19
|
+
SHRINK_KEY = :flex_shrink
|
20
|
+
SHRINK_VALUES = [0].freeze
|
21
|
+
|
22
|
+
GROW_KEY = :flex_grow
|
23
|
+
GROW_VALUES = [0].freeze
|
24
|
+
|
25
|
+
ALIGN_SELF_KEY = :align_self
|
26
|
+
ALIGN_SELF_VALUES = [:auto, :start, :end, :center, :baseline, :stretch].freeze
|
27
|
+
|
28
|
+
DIRECTION_KEY = :direction
|
29
|
+
DIRECTION_VALUES = [:column, :column_reverse, :row, :row_reverse].freeze
|
30
|
+
|
31
|
+
JUSTIFY_CONTENT_KEY = :justify_content
|
32
|
+
JUSTIFY_CONTENT_VALUES = [:flex_start, :flex_end, :center, :space_between, :space_around].freeze
|
33
|
+
|
34
|
+
ALIGN_ITEMS_KEY = :align_items
|
35
|
+
ALIGN_ITEMS_VALUES = [:flex_start, :flex_end, :center, :baseline, :stretch].freeze
|
36
|
+
|
37
|
+
KEYS = [FLEX_KEY, WRAP_KEY, SHRINK_KEY, GROW_KEY, ALIGN_SELF_KEY, DIRECTION_KEY, JUSTIFY_CONTENT_KEY, ALIGN_ITEMS_KEY].freeze
|
38
|
+
RESPONSIVE_KEYS = [DIRECTION_KEY, JUSTIFY_CONTENT_KEY, ALIGN_ITEMS_KEY].freeze
|
39
|
+
|
40
|
+
class << self
|
41
|
+
def classes(key, value, breakpoint)
|
42
|
+
send(key, value, breakpoint)
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
def flex(value, _breakpoint)
|
48
|
+
generate(
|
49
|
+
value: value,
|
50
|
+
allowed_values: FLEX_VALUES,
|
51
|
+
prefix: "flex"
|
52
|
+
)
|
53
|
+
end
|
54
|
+
|
55
|
+
def flex_shrink(value, _breakpoint)
|
56
|
+
generate(
|
57
|
+
value: value,
|
58
|
+
allowed_values: SHRINK_VALUES,
|
59
|
+
prefix: "flex-shrink"
|
60
|
+
)
|
61
|
+
end
|
62
|
+
|
63
|
+
def flex_grow(value, _breakpoint)
|
64
|
+
generate(
|
65
|
+
value: value,
|
66
|
+
allowed_values: GROW_VALUES,
|
67
|
+
prefix: "flex-grow"
|
68
|
+
)
|
69
|
+
end
|
70
|
+
|
71
|
+
def align_self(value, _breakpoint)
|
72
|
+
generate(
|
73
|
+
value: value,
|
74
|
+
allowed_values: ALIGN_SELF_VALUES,
|
75
|
+
prefix: "flex-self"
|
76
|
+
)
|
77
|
+
end
|
78
|
+
|
79
|
+
def flex_wrap(value, _breakpoint)
|
80
|
+
WRAP_MAPPINGS[fetch_or_fallback(WRAP_MAPPINGS.keys, value)]
|
81
|
+
end
|
82
|
+
|
83
|
+
def direction(value, breakpoint)
|
84
|
+
val = fetch_or_fallback(DIRECTION_VALUES, value)
|
85
|
+
|
86
|
+
"flex#{breakpoint}-#{val.to_s.dasherize}"
|
87
|
+
end
|
88
|
+
|
89
|
+
def justify_content(value, breakpoint)
|
90
|
+
val = fetch_or_fallback(JUSTIFY_CONTENT_VALUES, value)
|
91
|
+
|
92
|
+
formatted_value = val.to_s.gsub(/(flex\_|space\_)/, "")
|
93
|
+
"flex#{breakpoint}-justify-#{formatted_value}"
|
94
|
+
end
|
95
|
+
|
96
|
+
def align_items(value, breakpoint)
|
97
|
+
val = fetch_or_fallback(ALIGN_ITEMS_VALUES, value)
|
98
|
+
|
99
|
+
formatted_value = val.to_s.gsub("flex_", "")
|
100
|
+
"flex#{breakpoint}-items-#{formatted_value}"
|
101
|
+
end
|
102
|
+
|
103
|
+
def generate(value:, allowed_values:, prefix:)
|
104
|
+
val = fetch_or_fallback(allowed_values, value)
|
105
|
+
|
106
|
+
"#{prefix}-#{val}"
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Primer
|
4
|
+
class Classify
|
5
|
+
# Handler for PrimerCSS grid classes.
|
6
|
+
class Grid
|
7
|
+
extend Primer::FetchOrFallbackHelper
|
8
|
+
|
9
|
+
CONTAINER_KEY = :container
|
10
|
+
CONTAINER_VALUES = [:xl, :lg, :md, :sm].freeze
|
11
|
+
|
12
|
+
CLEARFIX_KEY = :clearfix
|
13
|
+
CLEARFIX_VALUES = [true, false].freeze
|
14
|
+
|
15
|
+
COL_KEY = :col
|
16
|
+
COL_VALUES = (1..12).to_a.freeze
|
17
|
+
|
18
|
+
KEYS = [CONTAINER_KEY, CLEARFIX_KEY, COL_KEY].freeze
|
19
|
+
|
20
|
+
class << self
|
21
|
+
def classes(key, value, breakpoint)
|
22
|
+
send(key, value, breakpoint)
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def container(value, _breakpoint)
|
28
|
+
val = fetch_or_fallback(CONTAINER_VALUES, value)
|
29
|
+
|
30
|
+
"container-#{val}"
|
31
|
+
end
|
32
|
+
|
33
|
+
def clearfix(value, _breakpoint)
|
34
|
+
"clearfix" if fetch_or_fallback(CLEARFIX_VALUES, value)
|
35
|
+
end
|
36
|
+
|
37
|
+
def col(value, breakpoint)
|
38
|
+
val = fetch_or_fallback(COL_VALUES, value.to_i)
|
39
|
+
|
40
|
+
"col#{breakpoint}-#{val}"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -25,10 +25,10 @@ module Primer
|
|
25
25
|
|
26
26
|
InvalidValueError = Class.new(StandardError)
|
27
27
|
|
28
|
-
def fetch_or_fallback(allowed_values, given_value, fallback = nil, deprecated_values:
|
28
|
+
def fetch_or_fallback(allowed_values, given_value, fallback = nil, deprecated_values: nil)
|
29
29
|
if allowed_values.include?(given_value)
|
30
30
|
given_value
|
31
|
-
elsif deprecated_values
|
31
|
+
elsif deprecated_values&.include?(given_value)
|
32
32
|
ActiveSupport::Deprecation.warn("#{given_value} is deprecated and will be removed in a future version.") unless Rails.env.production? || silence_deprecations?
|
33
33
|
|
34
34
|
given_value
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Primer
|
4
|
+
module Octicon
|
5
|
+
# :nodoc:
|
6
|
+
class Cache
|
7
|
+
LOOKUP = {} # rubocop:disable Style/MutableConstant
|
8
|
+
# Preload the top 20 used icons.
|
9
|
+
PRELOADED_ICONS = [:alert, :check, :"chevron-down", :clippy, :clock, :"dot-fill", :info, :"kebab-horizontal", :link, :lock, :mail, :pencil, :plus, :question, :repo, :search, :"shield-lock", :star, :trash, :x].freeze
|
10
|
+
|
11
|
+
class << self
|
12
|
+
def get_key(symbol:, size:, width: nil, height: nil)
|
13
|
+
[symbol, size, width, height].join("_")
|
14
|
+
end
|
15
|
+
|
16
|
+
def read(key)
|
17
|
+
LOOKUP[key]
|
18
|
+
end
|
19
|
+
|
20
|
+
# Cache size limit.
|
21
|
+
def limit
|
22
|
+
500
|
23
|
+
end
|
24
|
+
|
25
|
+
def set(key, value)
|
26
|
+
LOOKUP[key] = value
|
27
|
+
|
28
|
+
# Remove first item when the cache is too large.
|
29
|
+
LOOKUP.shift if LOOKUP.size > limit
|
30
|
+
end
|
31
|
+
|
32
|
+
def clear!
|
33
|
+
LOOKUP.clear
|
34
|
+
end
|
35
|
+
|
36
|
+
def preload!
|
37
|
+
PRELOADED_ICONS.each { |icon| Primer::OcticonComponent.new(icon: icon) }
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|