primer_view_components 0.0.35 → 0.0.40
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +178 -22
- 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_component.rb → auto_complete.rb} +12 -12
- data/app/components/primer/{auto_complete_component.d.ts → auto_complete/auto_complete.d.ts} +0 -0
- data/app/components/primer/{auto_complete_component.html.erb → auto_complete/auto_complete.html.erb} +0 -0
- data/app/components/primer/{auto_complete_component.js → auto_complete/auto_complete.js} +0 -0
- data/app/components/primer/{auto_complete_component.ts → auto_complete/auto_complete.ts} +0 -0
- data/app/components/primer/auto_complete/auto_component.d.ts +1 -0
- data/app/components/primer/auto_complete/auto_component.js +1 -0
- data/app/components/primer/auto_complete/item.rb +42 -0
- data/app/components/primer/avatar_component.rb +22 -3
- data/app/components/primer/avatar_stack_component.rb +6 -3
- data/app/components/primer/base_button.rb +47 -0
- data/app/components/primer/base_component.rb +9 -8
- data/app/components/primer/blankslate_component.rb +5 -2
- 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 +58 -21
- data/app/components/primer/{button_group_component.html.erb → button_group.html.erb} +0 -0
- data/app/components/primer/button_group.rb +61 -0
- data/app/components/primer/button_marketing_component.rb +4 -9
- data/app/components/primer/clipboard_copy.html.erb +8 -0
- data/app/components/primer/clipboard_copy.rb +26 -0
- data/app/components/primer/clipboard_copy_component.d.ts +1 -0
- data/app/components/primer/clipboard_copy_component.js +23 -0
- data/app/components/primer/clipboard_copy_component.ts +26 -0
- data/app/components/primer/close_button.rb +39 -0
- data/app/components/primer/component.rb +21 -2
- 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 +1 -1
- 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 +25 -4
- data/app/components/primer/hidden_text_expander.rb +41 -0
- data/app/components/primer/icon_button.rb +65 -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 +1 -1
- data/app/components/primer/layout_component.rb +1 -1
- data/app/components/primer/link_component.rb +1 -1
- data/app/components/primer/{markdown_component.rb → markdown.rb} +6 -5
- data/app/components/primer/menu_component.rb +1 -1
- data/app/components/primer/octicon_component.html.erb +7 -0
- data/app/components/primer/octicon_component.rb +46 -14
- 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 +3 -1
- data/app/components/primer/primer.js +3 -1
- data/app/components/primer/primer.ts +3 -1
- 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 +2 -2
- 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.rb +1 -1
- 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 +1 -1
- data/app/components/primer/{truncate_component.rb → truncate.rb} +8 -6
- data/app/components/primer/underline_nav_component.rb +1 -1
- data/app/lib/primer/classify.rb +9 -34
- data/app/lib/primer/classify/cache.rb +20 -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/fetch_or_fallback_helper.rb +2 -2
- data/app/lib/primer/octicon/cache.rb +42 -0
- data/lib/primer/view_components.rb +1 -1
- data/lib/primer/view_components/version.rb +1 -1
- data/lib/tasks/coverage.rake +14 -0
- data/lib/tasks/docs.rake +312 -0
- data/lib/tasks/statuses.rake +12 -0
- data/lib/yard/docs_helper.rb +57 -0
- data/static/statuses.json +52 -1
- metadata +53 -15
- data/app/assets/javascripts/primer_view_components.js.map.orig +0 -5
- data/app/assets/javascripts/primer_view_components.js.orig +0 -6
- data/app/components/primer/auto_complete_item_component.rb +0 -40
- data/app/components/primer/button_group_component.rb +0 -35
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Primer
|
4
|
-
# Use TabContainer to create tabbed content with keyboard support. This component does not add any styles.
|
4
|
+
# Use `TabContainer` to create tabbed content with keyboard support. This component does not add any styles.
|
5
5
|
# It only provides the tab functionality. If you want styled Tabs you can look at <%= link_to_component(Primer::TabNavComponent) %>.
|
6
6
|
#
|
7
7
|
# This component requires javascript.
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Primer
|
4
|
-
# Use TabNav to style navigation with a tab-based selected state, typically used for navigation placed at the top of the page.
|
4
|
+
# Use `TabNav` to style navigation with a tab-based selected state, typically used for navigation placed at the top of the page.
|
5
5
|
class TabNavComponent < Primer::Component
|
6
6
|
include Primer::TabbedComponentHelper
|
7
7
|
|
@@ -1,18 +1,21 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Primer
|
4
|
-
#
|
4
|
+
# `Text` is a wrapper component that will apply typography styles to the text inside.
|
5
5
|
class TextComponent < Primer::Component
|
6
6
|
status :beta
|
7
7
|
|
8
|
+
DEFAULT_TAG = :span
|
9
|
+
|
8
10
|
# @example Default
|
9
11
|
# <%= render(Primer::TextComponent.new(tag: :p, font_weight: :bold)) { "Bold Text" } %>
|
10
12
|
# <%= render(Primer::TextComponent.new(tag: :p, color: :text_danger)) { "Danger Text" } %>
|
11
13
|
#
|
14
|
+
# @param tag [Symbol]
|
12
15
|
# @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
|
13
|
-
def initialize(**system_arguments)
|
16
|
+
def initialize(tag: DEFAULT_TAG, **system_arguments)
|
14
17
|
@system_arguments = system_arguments
|
15
|
-
@system_arguments[:tag]
|
18
|
+
@system_arguments[:tag] = tag
|
16
19
|
end
|
17
20
|
|
18
21
|
def call
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Primer
|
4
|
-
# Use
|
4
|
+
# Use `TimeAgo` to display a time relative to how long ago it was. This component requires JavaScript.
|
5
5
|
class TimeAgoComponent < Primer::Component
|
6
6
|
status :beta
|
7
7
|
|
@@ -19,7 +19,7 @@ module Primer
|
|
19
19
|
|
20
20
|
# Badge that will be connected to other TimelineItems.
|
21
21
|
#
|
22
|
-
# @param icon [String] Name of
|
22
|
+
# @param icon [String] Name of <%= link_to_octicons %> to use.
|
23
23
|
# @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
|
24
24
|
renders_one :badge, "BadgeComponent"
|
25
25
|
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Primer
|
4
|
-
#
|
4
|
+
# `Tooltip` is a wrapper component that will apply a tooltip to the provided content.
|
5
5
|
class TooltipComponent < Primer::Component
|
6
6
|
DIRECTION_DEFAULT = :n
|
7
7
|
ALIGN_DEFAULT = :default
|
@@ -1,21 +1,23 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Primer
|
4
|
-
# Use
|
5
|
-
class
|
4
|
+
# Use `Truncate` to shorten overflowing text with an ellipsis.
|
5
|
+
class Truncate < Primer::Component
|
6
|
+
status :beta
|
7
|
+
|
6
8
|
# @example Default
|
7
9
|
# <div class="col-2">
|
8
|
-
# <%= render(Primer::
|
10
|
+
# <%= render(Primer::Truncate.new(tag: :p)) { "branch-name-that-is-really-long" } %>
|
9
11
|
# </div>
|
10
12
|
#
|
11
13
|
# @example Inline
|
12
|
-
# <%= render(Primer::
|
14
|
+
# <%= render(Primer::Truncate.new(tag: :span, inline: true)) { "branch-name-that-is-really-long" } %>
|
13
15
|
#
|
14
16
|
# @example Expandable
|
15
|
-
# <%= render(Primer::
|
17
|
+
# <%= render(Primer::Truncate.new(tag: :span, inline: true, expandable: true)) { "branch-name-that-is-really-long" } %>
|
16
18
|
#
|
17
19
|
# @example Custom size
|
18
|
-
# <%= render(Primer::
|
20
|
+
# <%= render(Primer::Truncate.new(tag: :span, inline: true, expandable: true, max_width: 100)) { "branch-name-that-is-really-long" } %>
|
19
21
|
#
|
20
22
|
# @param inline [Boolean] Whether the element is inline (or inline-block).
|
21
23
|
# @param expandable [Boolean] Whether the entire string should be revealed on hover. Can only be used in conjunction with `inline`.
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Primer
|
4
|
-
# Use
|
4
|
+
# Use `UnderlineNav` to style navigation with a minimal
|
5
5
|
# underlined selected state, typically used for navigation placed at the top
|
6
6
|
# of the page.
|
7
7
|
class UnderlineNavComponent < Primer::Component
|
data/app/lib/primer/classify.rb
CHANGED
@@ -3,35 +3,29 @@
|
|
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
10
|
CONCAT_KEYS = SPACING_KEYS + %i[hide position v float col text box_shadow].freeze
|
16
11
|
|
17
12
|
INVALID_CLASS_NAME_PREFIXES =
|
18
|
-
(["bg-", "color-", "text-", "d-", "v-align-", "wb-", "
|
13
|
+
(["bg-", "color-", "text-", "d-", "v-align-", "wb-", "box-shadow-"] + CONCAT_KEYS.map { |k| "#{k}-" }).freeze
|
19
14
|
|
20
15
|
COLOR_KEY = :color
|
21
16
|
BG_KEY = :bg
|
22
17
|
VERTICAL_ALIGN_KEY = :vertical_align
|
23
18
|
WORD_BREAK_KEY = :word_break
|
24
19
|
TEXT_KEYS = %i[text_align font_weight].freeze
|
25
|
-
FLEX_KEY = :flex
|
26
|
-
FLEX_GROW_KEY = :flex_grow
|
27
|
-
FLEX_SHRINK_KEY = :flex_shrink
|
28
|
-
ALIGN_SELF_KEY = :align_self
|
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
|
34
25
|
|
26
|
+
BREAKPOINTS = ["", "-sm", "-md", "-lg", "-xl"].freeze
|
27
|
+
RESPONSIVE_KEYS = ([DISPLAY_KEY, :col, :float] + SPACING_KEYS + Primer::Classify::Flex::RESPONSIVE_KEYS).freeze
|
28
|
+
|
35
29
|
BOOLEAN_MAPPINGS = {
|
36
30
|
underline: {
|
37
31
|
mappings: [
|
@@ -89,6 +83,7 @@ module Primer
|
|
89
83
|
BORDER_MARGIN_KEYS +
|
90
84
|
TYPOGRAPHY_KEYS +
|
91
85
|
TEXT_KEYS +
|
86
|
+
Primer::Classify::Flex::KEYS +
|
92
87
|
[
|
93
88
|
BORDER_KEY,
|
94
89
|
BORDER_COLOR_KEY,
|
@@ -98,13 +93,6 @@ module Primer
|
|
98
93
|
DISPLAY_KEY,
|
99
94
|
VERTICAL_ALIGN_KEY,
|
100
95
|
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
96
|
WIDTH_KEY,
|
109
97
|
HEIGHT_KEY,
|
110
98
|
BOX_SHADOW_KEY,
|
@@ -120,7 +108,7 @@ module Primer
|
|
120
108
|
extracted_results[:class] = [
|
121
109
|
validated_class_names(classes),
|
122
110
|
extracted_results.delete(:classes)
|
123
|
-
].compact.join(" ").presence
|
111
|
+
].compact.join(" ").strip.presence
|
124
112
|
|
125
113
|
extracted_results[:style] = [
|
126
114
|
extracted_results.delete(:styles),
|
@@ -216,23 +204,10 @@ module Primer
|
|
216
204
|
memo[:classes] << "#{key.to_s.dasherize}-#{val}"
|
217
205
|
elsif key == BORDER_RADIUS_KEY
|
218
206
|
memo[:classes] << "rounded-#{val}"
|
219
|
-
elsif key
|
220
|
-
memo[:classes] <<
|
221
|
-
elsif key == JUSTIFY_CONTENT_KEY
|
222
|
-
formatted_value = val.to_s.gsub(/(flex\_|space\_)/, "")
|
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}"
|
207
|
+
elsif Primer::Classify::Flex::KEYS.include?(key)
|
208
|
+
memo[:classes] << Primer::Classify::Flex.classes(key, val, breakpoint)
|
234
209
|
elsif key == WIDTH_KEY || key == HEIGHT_KEY
|
235
|
-
if val == :fit
|
210
|
+
if val == :fit
|
236
211
|
memo[:classes] << "#{key}-#{val}"
|
237
212
|
else
|
238
213
|
memo[key] = val
|
@@ -40,18 +40,18 @@ 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
55
|
)
|
56
56
|
|
57
57
|
preload(
|
@@ -61,12 +61,12 @@ module Primer
|
|
61
61
|
|
62
62
|
preload(
|
63
63
|
keys: [Primer::Classify::COLOR_KEY],
|
64
|
-
values:
|
64
|
+
values: Primer::Classify::FunctionalTextColors::OPTIONS
|
65
65
|
)
|
66
66
|
|
67
67
|
preload(
|
68
68
|
keys: [Primer::Classify::BG_KEY],
|
69
|
-
values:
|
69
|
+
values: Primer::Classify::FunctionalBackgroundColors::OPTIONS
|
70
70
|
)
|
71
71
|
|
72
72
|
preload(
|
@@ -90,23 +90,28 @@ module Primer
|
|
90
90
|
)
|
91
91
|
|
92
92
|
preload(
|
93
|
-
keys: Primer::Classify::FLEX_KEY,
|
94
|
-
values:
|
93
|
+
keys: Primer::Classify::Flex::FLEX_KEY,
|
94
|
+
values: Primer::Classify::Flex::FLEX_VALUES
|
95
95
|
)
|
96
96
|
|
97
97
|
preload(
|
98
|
-
keys:
|
99
|
-
values:
|
98
|
+
keys: Primer::Classify::Flex::GROW_KEY,
|
99
|
+
values: Primer::Classify::Flex::GROW_VALUES
|
100
100
|
)
|
101
101
|
|
102
102
|
preload(
|
103
|
-
keys:
|
104
|
-
values:
|
103
|
+
keys: Primer::Classify::Flex::SHRINK_KEY,
|
104
|
+
values: Primer::Classify::Flex::SHRINK_VALUES
|
105
|
+
)
|
106
|
+
|
107
|
+
preload(
|
108
|
+
keys: Primer::Classify::Flex::ALIGN_SELF_KEY,
|
109
|
+
values: Primer::Classify::Flex::ALIGN_SELF_VALUES
|
105
110
|
)
|
106
111
|
|
107
112
|
preload(
|
108
113
|
keys: [Primer::Classify::WIDTH_KEY, Primer::Classify::HEIGHT_KEY],
|
109
|
-
values: [:fit
|
114
|
+
values: [:fit]
|
110
115
|
)
|
111
116
|
|
112
117
|
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
|
@@ -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
|