primer_view_components 0.0.53 → 0.0.57
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +87 -0
- data/app/components/primer/alpha/tab_nav.html.erb +11 -0
- data/app/components/primer/alpha/tab_nav.rb +130 -0
- data/app/components/primer/{tab_nav_component.html.erb → alpha/tab_panels.html.erb} +3 -8
- data/app/components/primer/alpha/tab_panels.rb +82 -0
- data/app/components/primer/alpha/underline_nav.html.erb +15 -0
- data/app/components/primer/alpha/underline_nav.rb +137 -0
- data/app/components/primer/{underline_nav_component.html.erb → alpha/underline_panels.html.erb} +3 -8
- data/app/components/primer/alpha/underline_panels.rb +86 -0
- data/app/components/primer/base_component.rb +1 -1
- data/app/components/primer/{breadcrumb_component.html.erb → beta/breadcrumbs.html.erb} +2 -1
- data/app/components/primer/beta/breadcrumbs.rb +61 -0
- data/app/components/primer/navigation/tab_component.rb +7 -5
- data/app/components/primer/octicon_component.rb +6 -1
- data/app/components/primer/tab_container_component.rb +1 -1
- data/app/lib/primer/class_name_helper.rb +14 -13
- data/app/lib/primer/octicon/cache.rb +10 -2
- data/app/lib/primer/tab_nav_helper.rb +35 -0
- data/app/lib/primer/tabbed_component_helper.rb +4 -4
- data/app/lib/primer/underline_nav_helper.rb +44 -0
- data/lib/primer/classify/cache.rb +0 -6
- data/lib/primer/classify/utilities.rb +6 -2
- data/lib/primer/classify/utilities.yml +35 -0
- data/lib/primer/classify/validation.rb +1 -1
- data/lib/primer/classify.rb +0 -5
- data/lib/primer/view_components/engine.rb +1 -1
- data/lib/primer/view_components/linters/argument_mappers/button.rb +4 -1
- data/lib/primer/view_components/linters/flash_component_migration_counter.rb +5 -0
- data/lib/primer/view_components/version.rb +1 -1
- data/lib/rubocop/cop/primer/base_cop.rb +28 -0
- data/lib/rubocop/cop/primer/deprecated_arguments.rb +105 -15
- data/lib/rubocop/cop/primer/primer_octicon.rb +18 -1
- data/lib/rubocop/cop/primer/system_argument_instead_of_class.rb +1 -15
- data/lib/tasks/docs.rake +7 -6
- data/lib/tasks/utilities.rake +2 -0
- data/static/arguments.yml +75 -64
- data/static/classes.yml +2 -0
- data/static/constants.json +31 -29
- data/static/statuses.json +7 -5
- metadata +29 -9
- data/app/components/primer/breadcrumb_component.rb +0 -57
- data/app/components/primer/tab_nav_component.rb +0 -151
- data/app/components/primer/underline_nav_component.rb +0 -187
- data/lib/primer/classify/functional_text_colors.rb +0 -64
@@ -115,7 +115,11 @@ module Primer
|
|
115
115
|
end
|
116
116
|
|
117
117
|
def classes_to_args(classes)
|
118
|
-
classes_to_hash(classes)
|
118
|
+
hash_to_args(classes_to_hash(classes))
|
119
|
+
end
|
120
|
+
|
121
|
+
def hash_to_args(hash)
|
122
|
+
hash.map do |key, value|
|
119
123
|
val = case value
|
120
124
|
when Symbol
|
121
125
|
":#{value}"
|
@@ -175,7 +179,7 @@ module Primer
|
|
175
179
|
unless supported_value?(key, val)
|
176
180
|
raise ArgumentError, "#{val} is not a valid value for :#{key}. Use one of #{mappings(key)}" unless ENV["RAILS_ENV"] == "production"
|
177
181
|
|
178
|
-
return ""
|
182
|
+
return "#{key.to_s.dasherize}-#{val.to_s.dasherize}"
|
179
183
|
end
|
180
184
|
|
181
185
|
nil
|
@@ -22,6 +22,39 @@
|
|
22
22
|
- anim-hover-grow
|
23
23
|
:rotate:
|
24
24
|
- anim-rotate
|
25
|
+
:color:
|
26
|
+
:text_primary:
|
27
|
+
- color-text-primary
|
28
|
+
:text_secondary:
|
29
|
+
- color-text-secondary
|
30
|
+
:text_tertiary:
|
31
|
+
- color-text-tertiary
|
32
|
+
:text_link:
|
33
|
+
- color-text-link
|
34
|
+
:text_success:
|
35
|
+
- color-text-success
|
36
|
+
:text_warning:
|
37
|
+
- color-text-warning
|
38
|
+
:text_danger:
|
39
|
+
- color-text-danger
|
40
|
+
:text_inverse:
|
41
|
+
- color-text-inverse
|
42
|
+
:text_white:
|
43
|
+
- color-text-white
|
44
|
+
:icon_primary:
|
45
|
+
- color-icon-primary
|
46
|
+
:icon_secondary:
|
47
|
+
- color-icon-secondary
|
48
|
+
:icon_tertiary:
|
49
|
+
- color-icon-tertiary
|
50
|
+
:icon_info:
|
51
|
+
- color-icon-info
|
52
|
+
:icon_danger:
|
53
|
+
- color-icon-danger
|
54
|
+
:icon_success:
|
55
|
+
- color-icon-success
|
56
|
+
:icon_warning:
|
57
|
+
- color-icon-warning
|
25
58
|
:position:
|
26
59
|
:static:
|
27
60
|
- position-static
|
@@ -1220,6 +1253,8 @@
|
|
1220
1253
|
- py-lg-12
|
1221
1254
|
- py-xl-12
|
1222
1255
|
:word_break:
|
1256
|
+
:break_word:
|
1257
|
+
- wb-break-word
|
1223
1258
|
:break_all:
|
1224
1259
|
- wb-break-all
|
1225
1260
|
:display:
|
@@ -6,7 +6,7 @@ module Primer
|
|
6
6
|
class Classify
|
7
7
|
# :nodoc:
|
8
8
|
class Validation
|
9
|
-
INVALID_CLASS_NAME_PREFIXES = /bg-|color-|text-|box-shadow-|
|
9
|
+
INVALID_CLASS_NAME_PREFIXES = /bg-|color-bg-|text-|box-shadow-|box_shadow-/.freeze
|
10
10
|
|
11
11
|
class << self
|
12
12
|
def invalid?(class_name)
|
data/lib/primer/classify.rb
CHANGED
@@ -4,7 +4,6 @@ require_relative "classify/cache"
|
|
4
4
|
require_relative "classify/flex"
|
5
5
|
require_relative "classify/functional_background_colors"
|
6
6
|
require_relative "classify/functional_border_colors"
|
7
|
-
require_relative "classify/functional_text_colors"
|
8
7
|
require_relative "classify/grid"
|
9
8
|
require_relative "classify/utilities"
|
10
9
|
require_relative "classify/validation"
|
@@ -15,7 +14,6 @@ module Primer
|
|
15
14
|
# Keys where we can simply translate { key: value } into ".key-value"
|
16
15
|
CONCAT_KEYS = %i[text box_shadow].freeze
|
17
16
|
|
18
|
-
COLOR_KEY = :color
|
19
17
|
BG_KEY = :bg
|
20
18
|
TEXT_KEYS = %i[font_family font_style font_weight text_align text_transform].freeze
|
21
19
|
BOX_SHADOW_KEY = :box_shadow
|
@@ -88,7 +86,6 @@ module Primer
|
|
88
86
|
BORDER_KEY,
|
89
87
|
BORDER_COLOR_KEY,
|
90
88
|
BORDER_RADIUS_KEY,
|
91
|
-
COLOR_KEY,
|
92
89
|
BG_KEY,
|
93
90
|
BOX_SHADOW_KEY,
|
94
91
|
CONTAINER_KEY
|
@@ -176,8 +173,6 @@ module Primer
|
|
176
173
|
else
|
177
174
|
memo[:classes] << Primer::Classify::FunctionalBackgroundColors.color(val)
|
178
175
|
end
|
179
|
-
elsif key == COLOR_KEY
|
180
|
-
memo[:classes] << Primer::Classify::FunctionalTextColors.color(val)
|
181
176
|
elsif key == BORDER_KEY
|
182
177
|
border_value = if val == true
|
183
178
|
"border"
|
@@ -23,12 +23,13 @@ module ERBLint
|
|
23
23
|
component: "Primer::BaseButton",
|
24
24
|
constant: "TYPE_OPTIONS"
|
25
25
|
).freeze
|
26
|
+
|
26
27
|
DEFAULT_TAG = Primer::ViewComponents::Constants.get(
|
27
28
|
component: "Primer::BaseButton",
|
28
29
|
constant: "DEFAULT_TAG"
|
29
30
|
).freeze
|
30
31
|
|
31
|
-
ATTRIBUTES = %w[disabled type].freeze
|
32
|
+
ATTRIBUTES = %w[disabled type href name value tabindex].freeze
|
32
33
|
|
33
34
|
def attribute_to_args(attribute)
|
34
35
|
attr_name = attribute.name
|
@@ -43,6 +44,8 @@ module ERBLint
|
|
43
44
|
raise ConversionError, "Button component does not support type \"#{attribute.value}\"" unless TYPE_OPTIONS.include?(attribute.value)
|
44
45
|
|
45
46
|
{ type: ":#{attribute.value}" }
|
47
|
+
else
|
48
|
+
{ attr_name.to_sym => erb_helper.convert(attribute) }
|
46
49
|
end
|
47
50
|
end
|
48
51
|
|
@@ -22,6 +22,11 @@ module ERBLint
|
|
22
22
|
# Hash children indicates that there are tags in the content.
|
23
23
|
return nil if tag_tree[:children].first.is_a?(Hash)
|
24
24
|
|
25
|
+
content = tag_tree[:children].first
|
26
|
+
|
27
|
+
# Don't accept content with ERB blocks
|
28
|
+
return nil if content.type != :text || content.children&.any? { |n| n.try(:type) == :erb }
|
29
|
+
|
25
30
|
ARGUMENT_MAPPER.new(tag).to_s
|
26
31
|
rescue ArgumentMappers::ConversionError
|
27
32
|
nil
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "rubocop"
|
4
|
+
require "primer/view_components/statuses"
|
5
|
+
require_relative "../../../../app/lib/primer/view_helper"
|
6
|
+
|
7
|
+
module RuboCop
|
8
|
+
module Cop
|
9
|
+
module Primer
|
10
|
+
# :nodoc:
|
11
|
+
class BaseCop < RuboCop::Cop::Cop
|
12
|
+
# We only verify SystemArguments if it's a `.new` call on a component or
|
13
|
+
# a ViewHeleper call.
|
14
|
+
def valid_node?(node)
|
15
|
+
return if node.nil?
|
16
|
+
|
17
|
+
view_helpers.include?(node.method_name) || (node.method_name == :new && !node.receiver.nil? && ::Primer::ViewComponents::STATUSES.key?(node.receiver.const_name))
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def view_helpers
|
23
|
+
::Primer::ViewHelper::HELPERS.keys.map { |key| "primer_#{key}".to_sym }
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -1,8 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require "rubocop"
|
4
|
-
require "primer/view_components/statuses"
|
5
|
-
require_relative "../../../../app/lib/primer/view_helper"
|
6
4
|
|
7
5
|
# :nocov:
|
8
6
|
module RuboCop
|
@@ -15,7 +13,7 @@ module RuboCop
|
|
15
13
|
#
|
16
14
|
# good
|
17
15
|
# Component.new(foo: :bar)
|
18
|
-
class DeprecatedArguments <
|
16
|
+
class DeprecatedArguments < BaseCop
|
19
17
|
INVALID_MESSAGE = <<~STR
|
20
18
|
Avoid using deprecated arguments: https://primer.style/view-components/deprecated.
|
21
19
|
STR
|
@@ -35,6 +33,110 @@ module RuboCop
|
|
35
33
|
# }
|
36
34
|
#
|
37
35
|
DEPRECATED = {
|
36
|
+
bg: {
|
37
|
+
white: "bg: :primary",
|
38
|
+
gray_light: "bg: :secondary",
|
39
|
+
gray: "bg: :tertiary",
|
40
|
+
gray_dark: "bg: :canvas_inverse",
|
41
|
+
blue_light: "bg: :info",
|
42
|
+
blue: "bg: :info_inverse",
|
43
|
+
green_light: "bg: :success",
|
44
|
+
green: "bg: :success_inverse",
|
45
|
+
yellow_light: "bg: :warning",
|
46
|
+
yellow: "bg: :warning_inverse",
|
47
|
+
red_light: "bg: :danger",
|
48
|
+
red: "bg: :danger_inverse",
|
49
|
+
gray_0: nil,
|
50
|
+
gray_1: nil,
|
51
|
+
gray_2: nil,
|
52
|
+
gray_3: nil,
|
53
|
+
gray_4: nil,
|
54
|
+
gray_5: nil,
|
55
|
+
gray_6: nil,
|
56
|
+
gray_7: nil,
|
57
|
+
gray_8: nil,
|
58
|
+
gray_9: nil,
|
59
|
+
blue_0: nil,
|
60
|
+
blue_1: nil,
|
61
|
+
blue_2: nil,
|
62
|
+
blue_3: nil,
|
63
|
+
blue_4: nil,
|
64
|
+
blue_5: nil,
|
65
|
+
blue_6: nil,
|
66
|
+
blue_7: nil,
|
67
|
+
blue_8: nil,
|
68
|
+
blue_9: nil,
|
69
|
+
green_0: nil,
|
70
|
+
green_1: nil,
|
71
|
+
green_2: nil,
|
72
|
+
green_3: nil,
|
73
|
+
green_4: nil,
|
74
|
+
green_5: nil,
|
75
|
+
green_6: nil,
|
76
|
+
green_7: nil,
|
77
|
+
green_8: nil,
|
78
|
+
green_9: nil,
|
79
|
+
yellow_0: nil,
|
80
|
+
yellow_1: nil,
|
81
|
+
yellow_2: nil,
|
82
|
+
yellow_3: nil,
|
83
|
+
yellow_4: nil,
|
84
|
+
yellow_5: nil,
|
85
|
+
yellow_6: nil,
|
86
|
+
yellow_7: nil,
|
87
|
+
yellow_8: nil,
|
88
|
+
yellow_9: nil,
|
89
|
+
red_0: nil,
|
90
|
+
red_1: nil,
|
91
|
+
red_2: nil,
|
92
|
+
red_3: nil,
|
93
|
+
red_4: nil,
|
94
|
+
red_5: nil,
|
95
|
+
red_6: nil,
|
96
|
+
red_7: nil,
|
97
|
+
red_8: nil,
|
98
|
+
red_9: nil,
|
99
|
+
purple_0: nil,
|
100
|
+
purple_1: nil,
|
101
|
+
purple_2: nil,
|
102
|
+
purple_3: nil,
|
103
|
+
purple_4: nil,
|
104
|
+
purple_5: nil,
|
105
|
+
purple_6: nil,
|
106
|
+
purple_7: nil,
|
107
|
+
purple_8: nil,
|
108
|
+
purple_9: nil,
|
109
|
+
pink_0: nil,
|
110
|
+
pink_1: nil,
|
111
|
+
pink_2: nil,
|
112
|
+
pink_3: nil,
|
113
|
+
pink_4: nil,
|
114
|
+
pink_5: nil,
|
115
|
+
pink_6: nil,
|
116
|
+
pink_7: nil,
|
117
|
+
pink_8: nil,
|
118
|
+
pink_9: nil,
|
119
|
+
orange_0: nil,
|
120
|
+
orange_1: nil,
|
121
|
+
orange_2: nil,
|
122
|
+
orange_3: nil,
|
123
|
+
orange_4: nil,
|
124
|
+
orange_5: nil,
|
125
|
+
orange_6: nil,
|
126
|
+
orange_7: nil,
|
127
|
+
orange_8: nil,
|
128
|
+
orange_9: nil
|
129
|
+
},
|
130
|
+
border_color: {
|
131
|
+
gray: "border_color: :primary",
|
132
|
+
gray_light: "border_color: :secondary",
|
133
|
+
gray_dark: "border_color: :tertiary",
|
134
|
+
blue: "border_color: :info",
|
135
|
+
green: "border_color: :success",
|
136
|
+
yellow: "border_color: :warning",
|
137
|
+
red: "border_color: :danger",
|
138
|
+
white: "border_color: :inverse"
|
139
|
+
},
|
38
140
|
color: {
|
39
141
|
blue: "color: :text_link",
|
40
142
|
gray_dark: "color: :text_primary",
|
@@ -155,18 +257,6 @@ module RuboCop
|
|
155
257
|
corrector.replace(node, replacement) if replacement.present?
|
156
258
|
end
|
157
259
|
end
|
158
|
-
|
159
|
-
private
|
160
|
-
|
161
|
-
# We only verify SystemArguments if it's a `.new` call on a component or
|
162
|
-
# a ViewHleper call.
|
163
|
-
def valid_node?(node)
|
164
|
-
view_helpers.include?(node.method_name) || (node.method_name == :new && ::Primer::ViewComponents::STATUSES.key?(node.receiver.const_name))
|
165
|
-
end
|
166
|
-
|
167
|
-
def view_helpers
|
168
|
-
::Primer::ViewHelper::HELPERS.keys.map { |key| "primer_#{key}".to_sym }
|
169
|
-
end
|
170
260
|
end
|
171
261
|
end
|
172
262
|
end
|
@@ -128,12 +128,29 @@ module RuboCop
|
|
128
128
|
string_args = string_args_to_string(node)
|
129
129
|
|
130
130
|
args = "#{args}, #{size_attributes_to_string(size_attributes)}" if size_args.present?
|
131
|
-
args = "#{args}, #{
|
131
|
+
args = "#{args}, #{utilities_args(classes)}" if classes.present?
|
132
132
|
args = "#{args}, #{string_args}" if string_args.present?
|
133
133
|
|
134
134
|
args
|
135
135
|
end
|
136
136
|
|
137
|
+
def utilities_args(classes)
|
138
|
+
args = ::Primer::Classify::Utilities.classes_to_hash(classes)
|
139
|
+
|
140
|
+
color = case args[:color]
|
141
|
+
when :text_white
|
142
|
+
:text_white
|
143
|
+
when :text_link
|
144
|
+
:icon_info
|
145
|
+
when Symbol
|
146
|
+
args[:color].to_s.gsub("text_", "icon_").to_sym
|
147
|
+
end
|
148
|
+
|
149
|
+
args[:color] = color if color
|
150
|
+
|
151
|
+
::Primer::Classify::Utilities.hash_to_args(args)
|
152
|
+
end
|
153
|
+
|
137
154
|
def size_attributes_to_string(size_attributes)
|
138
155
|
# No arguments if they map to the default size
|
139
156
|
return if size_attributes.blank? || size_attributes.values.all?(&:blank?)
|
@@ -2,8 +2,6 @@
|
|
2
2
|
|
3
3
|
require "rubocop"
|
4
4
|
require "primer/classify/utilities"
|
5
|
-
require "primer/view_components/statuses"
|
6
|
-
require_relative "../../../../app/lib/primer/view_helper"
|
7
5
|
|
8
6
|
# :nocov:
|
9
7
|
module RuboCop
|
@@ -16,7 +14,7 @@ module RuboCop
|
|
16
14
|
#
|
17
15
|
# good
|
18
16
|
# Component.new(mr: 1)
|
19
|
-
class SystemArgumentInsteadOfClass <
|
17
|
+
class SystemArgumentInsteadOfClass < BaseCop
|
20
18
|
INVALID_MESSAGE = <<~STR
|
21
19
|
Avoid using CSS classes when you can use System Arguments: https://primer.style/view-components/system-arguments.
|
22
20
|
STR
|
@@ -53,18 +51,6 @@ module RuboCop
|
|
53
51
|
corrector.replace(node.loc.expression, args)
|
54
52
|
end
|
55
53
|
end
|
56
|
-
|
57
|
-
private
|
58
|
-
|
59
|
-
# We only verify SystemArguments if it's a `.new` call on a component or
|
60
|
-
# a ViewHleper call.
|
61
|
-
def valid_node?(node)
|
62
|
-
view_helpers.include?(node.method_name) || (node.method_name == :new && ::Primer::ViewComponents::STATUSES.key?(node.receiver.const_name))
|
63
|
-
end
|
64
|
-
|
65
|
-
def view_helpers
|
66
|
-
::Primer::ViewHelper::HELPERS.keys.map { |key| "primer_#{key}".to_sym }
|
67
|
-
end
|
68
54
|
end
|
69
55
|
end
|
70
56
|
end
|
data/lib/tasks/docs.rake
CHANGED
@@ -40,7 +40,7 @@ namespace :docs do
|
|
40
40
|
Primer::BlankslateComponent,
|
41
41
|
Primer::BorderBoxComponent,
|
42
42
|
Primer::BoxComponent,
|
43
|
-
Primer::
|
43
|
+
Primer::Beta::Breadcrumbs,
|
44
44
|
Primer::ButtonComponent,
|
45
45
|
Primer::ButtonGroup,
|
46
46
|
Primer::Alpha::ButtonMarketing,
|
@@ -68,14 +68,15 @@ namespace :docs do
|
|
68
68
|
Primer::SpinnerComponent,
|
69
69
|
Primer::SubheadComponent,
|
70
70
|
Primer::TabContainerComponent,
|
71
|
-
Primer::TabNavComponent,
|
72
71
|
Primer::Beta::Text,
|
73
72
|
Primer::TimeAgoComponent,
|
74
73
|
Primer::TimelineItemComponent,
|
75
74
|
Primer::Tooltip,
|
76
75
|
Primer::Truncate,
|
77
76
|
Primer::Beta::Truncate,
|
78
|
-
Primer::
|
77
|
+
Primer::Alpha::UnderlineNav,
|
78
|
+
Primer::Alpha::TabNav,
|
79
|
+
Primer::Alpha::TabPanels
|
79
80
|
]
|
80
81
|
|
81
82
|
js_components = [
|
@@ -85,9 +86,9 @@ namespace :docs do
|
|
85
86
|
Primer::Beta::AutoComplete,
|
86
87
|
Primer::ClipboardCopy,
|
87
88
|
Primer::TabContainerComponent,
|
88
|
-
Primer::TabNavComponent,
|
89
89
|
Primer::TimeAgoComponent,
|
90
|
-
Primer::
|
90
|
+
Primer::Alpha::UnderlinePanels,
|
91
|
+
Primer::Alpha::TabPanels
|
91
92
|
]
|
92
93
|
|
93
94
|
all_components = Primer::Component.descendants - [Primer::BaseComponent]
|
@@ -205,7 +206,7 @@ namespace :docs do
|
|
205
206
|
f.puts
|
206
207
|
f.puts("### `#{slot_documentation.name.to_s.capitalize}`")
|
207
208
|
|
208
|
-
if slot_documentation.base_docstring.present?
|
209
|
+
if slot_documentation.base_docstring.to_s.present?
|
209
210
|
f.puts
|
210
211
|
f.puts(view_context.render(inline: slot_documentation.base_docstring))
|
211
212
|
end
|