backpack 0.4.5 → 0.4.6
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/README.md +8 -0
- data/lib/backpack/components/callout/callout.css +36 -0
- data/lib/backpack/components/callout/callout.js +1 -0
- data/lib/backpack/components/callout.rb +35 -0
- data/lib/backpack/components/data_table/data_table.css +59 -0
- data/lib/backpack/components/data_table/data_table.js +1 -0
- data/lib/backpack/components/data_table.rb +60 -0
- data/lib/backpack/components/icon/icon.css +1 -0
- data/lib/backpack/components/icon_sprite.rb +2 -2
- data/lib/backpack/stylesheets/tokens/_colors.css +89 -13
- data/lib/backpack/tokens.rb +1 -1
- data/lib/backpack/version.rb +1 -1
- data/spec/components/callout_spec.rb +55 -0
- data/spec/components/data_table_spec.rb +114 -0
- data/spec/components/icon_sprite_spec.rb +1 -1
- data/spec/components/previews/callout_preview/overview.html.erb +27 -0
- data/spec/components/previews/callout_preview.rb +12 -0
- data/spec/components/previews/data_table_preview/array.html.erb +13 -0
- data/spec/components/previews/data_table_preview/hash.html.erb +15 -0
- data/spec/components/previews/data_table_preview.rb +6 -0
- metadata +21 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: f763c502adc19a3fc112de13c1d14e872ff8113b3c343bdc0884a1a60b1463c0
|
|
4
|
+
data.tar.gz: d78a9c3b7407f8165d688bf997501d8cbe70301ed878fcb460bda830e93fb877
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c244f3d01a40e7e174941679ff36dfcbbac8ffc8f9a93f5562ff22089278e56c307470b0fbcd1b80a71e8b972623437a4dffd0d2a19bc601602a7377ff760d06
|
|
7
|
+
data.tar.gz: d92cd0aba578be70000e9bfb731d9dd0fb5ed4b2c53cd6612e743ad00f7a85a74b4fd5b137f6a34f0c9e36179e4ad332732dc88adb4f0ec488ff5355b8576765
|
data/README.md
CHANGED
|
@@ -37,6 +37,14 @@ You can run the command line in development:
|
|
|
37
37
|
bundle exec bin/backpack
|
|
38
38
|
```
|
|
39
39
|
|
|
40
|
+
## Lookbook
|
|
41
|
+
|
|
42
|
+
You can setup and run the Lookbook server with:
|
|
43
|
+
|
|
44
|
+
```
|
|
45
|
+
cd demo && make setup && make dev
|
|
46
|
+
```
|
|
47
|
+
|
|
40
48
|
## Contributing
|
|
41
49
|
|
|
42
50
|
Bug reports and pull requests are welcome on GitHub at https://github.com/etaminstudio/backpack.
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
.root {
|
|
2
|
+
align-items: center;
|
|
3
|
+
border-radius: var(--radius-4);
|
|
4
|
+
display: flex;
|
|
5
|
+
font-family: var(--font-body);
|
|
6
|
+
font-size: var(--font-base);
|
|
7
|
+
font-style: normal;
|
|
8
|
+
gap: 1rem;
|
|
9
|
+
justify-content: center;
|
|
10
|
+
line-height: var(--height-3);
|
|
11
|
+
padding: var(--space-6) var(--space-7);
|
|
12
|
+
width: fit-content;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
.icon {
|
|
16
|
+
--icon-size: var(--height-2);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/* soft */
|
|
20
|
+
.variant-soft {
|
|
21
|
+
background-color: var(--accent-4);
|
|
22
|
+
color: var(--accent-12);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/* surface */
|
|
26
|
+
.variant-surface {
|
|
27
|
+
background-color: var(--accent-3);
|
|
28
|
+
border: 1px solid var(--accent-8);
|
|
29
|
+
color: var(--accent-12);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/* outline */
|
|
33
|
+
.variant-outline {
|
|
34
|
+
border: 1px solid var(--accent-7);
|
|
35
|
+
color: var(--accent-12);
|
|
36
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import "./callout.css";
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
class Components::Callout < Components::Base
|
|
4
|
+
Type = _Union(:accent, :error, :warning, :success)
|
|
5
|
+
Variant = _Union(:soft, :surface, :outline)
|
|
6
|
+
|
|
7
|
+
DEFAULT_ICONS = {accent: "info", error: "circle-x", warning: "triangle-alert", success: "circle-check"}.freeze
|
|
8
|
+
|
|
9
|
+
prop :type, Type, default: :accent
|
|
10
|
+
prop :variant, Variant, default: :soft
|
|
11
|
+
prop :icon, _Union?(Symbol, String), default: -> { DEFAULT_ICONS[@type] }
|
|
12
|
+
|
|
13
|
+
def view_template(&block)
|
|
14
|
+
div(**root_attributes) { content(&block) }
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
private
|
|
18
|
+
|
|
19
|
+
def content
|
|
20
|
+
icon
|
|
21
|
+
yield
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def variant_props
|
|
25
|
+
%i[type variant]
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def extra_root_attributes
|
|
29
|
+
{ data_accent_color: @type }
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def icon
|
|
33
|
+
Icon(@icon, class: "#{root_class}-icon")
|
|
34
|
+
end
|
|
35
|
+
end
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
.root {
|
|
2
|
+
-webkit-overflow-scrolling: touch;
|
|
3
|
+
overflow-x: auto;
|
|
4
|
+
scrollbar-color: var(--example-8) transparent;
|
|
5
|
+
scrollbar-width: thin;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
.root > table {
|
|
9
|
+
border: 1px solid var(--example-5);
|
|
10
|
+
border-collapse: separate;
|
|
11
|
+
border-spacing: 0;
|
|
12
|
+
font-size: var(--size-2);
|
|
13
|
+
table-layout: auto;
|
|
14
|
+
width: 100%;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
.head {
|
|
18
|
+
background-color: var(--example-3);
|
|
19
|
+
font-weight: var(--bold);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
.head-cell,
|
|
23
|
+
.body-cell {
|
|
24
|
+
padding: var(--space-3);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
.head-cell {
|
|
28
|
+
font-weight: var(--medium);
|
|
29
|
+
text-align: start;
|
|
30
|
+
white-space: nowrap;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
.head-count {
|
|
34
|
+
font-size: var(--font-1);
|
|
35
|
+
margin-left: 0.8rem;
|
|
36
|
+
white-space: nowrap;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
.body-cell {
|
|
40
|
+
border-top: 1px solid var(--example-5);
|
|
41
|
+
text-align: start;
|
|
42
|
+
vertical-align: top;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
.body-cell strong {
|
|
46
|
+
font-family: var(--amulya);
|
|
47
|
+
font-weight: var(--bold);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
.row {
|
|
51
|
+
padding-inline: 1.2rem;
|
|
52
|
+
transition: background-color 0.2s ease-in-out;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
@media (hover: hover) {
|
|
56
|
+
.row:hover {
|
|
57
|
+
background-color: var(--example-2);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import "./data_table.css";
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
class Components::DataTable < Components::Base
|
|
4
|
+
class Column < Literal::Data
|
|
5
|
+
prop :label, String, reader: :public
|
|
6
|
+
prop :count, _Nilable(Integer), reader: :public
|
|
7
|
+
prop :content, Proc, :&, reader: :public
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
prop :columns, _Array(Column), default: proc { [] }
|
|
11
|
+
prop :rows, Enumerable, default: proc { [] }
|
|
12
|
+
|
|
13
|
+
def view_template(&)
|
|
14
|
+
div(**root_attributes) do
|
|
15
|
+
table do
|
|
16
|
+
vanish(&) # like yield but ensures it can’t output HTML
|
|
17
|
+
|
|
18
|
+
thead(class: "#{root_class}-head") do
|
|
19
|
+
tr(class: "#{root_class}-row") do
|
|
20
|
+
@columns.each do |column|
|
|
21
|
+
th(class: "#{root_class}-head-cell") do
|
|
22
|
+
plain column.label
|
|
23
|
+
if column.count
|
|
24
|
+
span(class: "#{root_class}-head-count") { column.count.to_s }
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
tbody(class: "#{root_class}-body") do
|
|
31
|
+
case @rows
|
|
32
|
+
when Array
|
|
33
|
+
# TODO: If you want to support passing relations, replace with:
|
|
34
|
+
# when Array, ActiveRecord::Relation
|
|
35
|
+
@rows.each do |row|
|
|
36
|
+
tr(class: "#{root_class}-row") do
|
|
37
|
+
@columns.each do |column|
|
|
38
|
+
td(class: "#{root_class}-body-cell") { column.content.call(row) }
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
when Hash
|
|
43
|
+
@rows.each do |key, value|
|
|
44
|
+
tr(class: "#{root_class}-row") do
|
|
45
|
+
@columns.each do |column|
|
|
46
|
+
td(class: "#{root_class}-body-cell") { column.content.call(key, value) }
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def column(**attributes, &content)
|
|
57
|
+
@columns << Column.new(**attributes, &content)
|
|
58
|
+
self
|
|
59
|
+
end
|
|
60
|
+
end
|
|
@@ -53,11 +53,11 @@ class Components::IconSprite < Components::Base
|
|
|
53
53
|
# rubocop:enable Rails/OutputSafety
|
|
54
54
|
|
|
55
55
|
def allowed_tags
|
|
56
|
-
%w[svg path circle rect line polyline polygon ellipse g defs use]
|
|
56
|
+
%w[svg path circle rect line polyline polygon ellipse g defs clipPath filter use]
|
|
57
57
|
end
|
|
58
58
|
|
|
59
59
|
def allowed_attributes
|
|
60
|
-
%w[x y cx cy r rx ry d fill stroke stroke-width viewbox]
|
|
60
|
+
%w[x y cx cy r rx ry d fill stroke stroke-width stroke-linecap stroke-linejoin viewbox]
|
|
61
61
|
end
|
|
62
62
|
end
|
|
63
63
|
end
|
|
@@ -148,19 +148,19 @@ Full list of available colors: https://www.radix-ui.com/colors
|
|
|
148
148
|
--accent-12: var(--green-12);
|
|
149
149
|
}
|
|
150
150
|
|
|
151
|
-
[data-accent-color="
|
|
152
|
-
--accent-1: var(--
|
|
153
|
-
--accent-2: var(--
|
|
154
|
-
--accent-3: var(--
|
|
155
|
-
--accent-4: var(--
|
|
156
|
-
--accent-5: var(--
|
|
157
|
-
--accent-6: var(--
|
|
158
|
-
--accent-7: var(--
|
|
159
|
-
--accent-8: var(--
|
|
160
|
-
--accent-9: var(--
|
|
161
|
-
--accent-10: var(--
|
|
162
|
-
--accent-11: var(--
|
|
163
|
-
--accent-12: var(--
|
|
151
|
+
[data-accent-color="amber"] {
|
|
152
|
+
--accent-1: var(--amber-1);
|
|
153
|
+
--accent-2: var(--amber-2);
|
|
154
|
+
--accent-3: var(--amber-3);
|
|
155
|
+
--accent-4: var(--amber-4);
|
|
156
|
+
--accent-5: var(--amber-5);
|
|
157
|
+
--accent-6: var(--amber-6);
|
|
158
|
+
--accent-7: var(--amber-7);
|
|
159
|
+
--accent-8: var(--amber-8);
|
|
160
|
+
--accent-9: var(--amber-9);
|
|
161
|
+
--accent-10: var(--amber-10);
|
|
162
|
+
--accent-11: var(--amber-11);
|
|
163
|
+
--accent-12: var(--amber-12);
|
|
164
164
|
}
|
|
165
165
|
|
|
166
166
|
[data-accent-color="red"] {
|
|
@@ -177,3 +177,79 @@ Full list of available colors: https://www.radix-ui.com/colors
|
|
|
177
177
|
--accent-11: var(--red-11);
|
|
178
178
|
--accent-12: var(--red-12);
|
|
179
179
|
}
|
|
180
|
+
|
|
181
|
+
[data-accent-color="sky"] {
|
|
182
|
+
--accent-1: var(--sky-1);
|
|
183
|
+
--accent-2: var(--sky-2);
|
|
184
|
+
--accent-3: var(--sky-3);
|
|
185
|
+
--accent-4: var(--sky-4);
|
|
186
|
+
--accent-5: var(--sky-5);
|
|
187
|
+
--accent-6: var(--sky-6);
|
|
188
|
+
--accent-7: var(--sky-7);
|
|
189
|
+
--accent-8: var(--sky-8);
|
|
190
|
+
--accent-9: var(--sky-9);
|
|
191
|
+
--accent-10: var(--sky-10);
|
|
192
|
+
--accent-11: var(--sky-11);
|
|
193
|
+
--accent-12: var(--sky-12);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/* Semantics */
|
|
197
|
+
[data-accent-color="error"] {
|
|
198
|
+
--accent-1: var(--red-1);
|
|
199
|
+
--accent-2: var(--red-2);
|
|
200
|
+
--accent-3: var(--red-3);
|
|
201
|
+
--accent-4: var(--red-4);
|
|
202
|
+
--accent-5: var(--red-5);
|
|
203
|
+
--accent-6: var(--red-6);
|
|
204
|
+
--accent-7: var(--red-7);
|
|
205
|
+
--accent-8: var(--red-8);
|
|
206
|
+
--accent-9: var(--red-9);
|
|
207
|
+
--accent-10: var(--red-10);
|
|
208
|
+
--accent-11: var(--red-11);
|
|
209
|
+
--accent-12: var(--red-12);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
[data-accent-color="success"] {
|
|
213
|
+
--accent-1: var(--green-1);
|
|
214
|
+
--accent-2: var(--green-2);
|
|
215
|
+
--accent-3: var(--green-3);
|
|
216
|
+
--accent-4: var(--green-4);
|
|
217
|
+
--accent-5: var(--green-5);
|
|
218
|
+
--accent-6: var(--green-6);
|
|
219
|
+
--accent-7: var(--green-7);
|
|
220
|
+
--accent-8: var(--green-8);
|
|
221
|
+
--accent-9: var(--green-9);
|
|
222
|
+
--accent-10: var(--green-10);
|
|
223
|
+
--accent-11: var(--green-11);
|
|
224
|
+
--accent-12: var(--green-12);
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
[data-accent-color="warning"] {
|
|
228
|
+
--accent-1: var(--amber-1);
|
|
229
|
+
--accent-2: var(--amber-2);
|
|
230
|
+
--accent-3: var(--amber-3);
|
|
231
|
+
--accent-4: var(--amber-4);
|
|
232
|
+
--accent-5: var(--amber-5);
|
|
233
|
+
--accent-6: var(--amber-6);
|
|
234
|
+
--accent-7: var(--amber-7);
|
|
235
|
+
--accent-8: var(--amber-8);
|
|
236
|
+
--accent-9: var(--amber-9);
|
|
237
|
+
--accent-10: var(--amber-10);
|
|
238
|
+
--accent-11: var(--amber-11);
|
|
239
|
+
--accent-12: var(--amber-12);
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
[data-accent-color="info"] {
|
|
243
|
+
--accent-1: var(--sky-1);
|
|
244
|
+
--accent-2: var(--sky-2);
|
|
245
|
+
--accent-3: var(--sky-3);
|
|
246
|
+
--accent-4: var(--sky-4);
|
|
247
|
+
--accent-5: var(--sky-5);
|
|
248
|
+
--accent-6: var(--sky-6);
|
|
249
|
+
--accent-7: var(--sky-7);
|
|
250
|
+
--accent-8: var(--sky-8);
|
|
251
|
+
--accent-9: var(--sky-9);
|
|
252
|
+
--accent-10: var(--sky-10);
|
|
253
|
+
--accent-11: var(--sky-11);
|
|
254
|
+
--accent-12: var(--sky-12);
|
|
255
|
+
}
|
data/lib/backpack/tokens.rb
CHANGED
|
@@ -2,7 +2,7 @@ module Backpack
|
|
|
2
2
|
module Tokens
|
|
3
3
|
extend Literal::Properties
|
|
4
4
|
|
|
5
|
-
Color = _Union(:green, :
|
|
5
|
+
Color = _Union(:green, :amber, :red, :sky)
|
|
6
6
|
OptionalColor = _Union(nil, Color)
|
|
7
7
|
Variant = _Union(:solid, :soft, :surface, :outline, :ghost)
|
|
8
8
|
Size = _Union(1, 2, 3)
|
data/lib/backpack/version.rb
CHANGED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe Components::Callout, type: :component do
|
|
4
|
+
let(:component) { described_class.new(**params) { text } }
|
|
5
|
+
let(:params) { {} }
|
|
6
|
+
let(:text) { "Label" }
|
|
7
|
+
|
|
8
|
+
subject(:output) { render_fragment(component) }
|
|
9
|
+
|
|
10
|
+
it "renders a Callout element with the default styling" do
|
|
11
|
+
expect(output).to have_css(
|
|
12
|
+
".Callout.Callout-variant-soft", text:
|
|
13
|
+
)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
context "with type options" do
|
|
17
|
+
let(:params) { { type: :warning } }
|
|
18
|
+
|
|
19
|
+
it "updates the variant modifiers in the class list" do
|
|
20
|
+
expect(output).to have_css(".Callout.Callout-variant-soft.Callout-type-warning", text:)
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
context "with variant options" do
|
|
25
|
+
let(:params) { { variant: :outline } }
|
|
26
|
+
|
|
27
|
+
it "updates the variant modifiers in the class list" do
|
|
28
|
+
expect(output).to have_css(".Callout.Callout-variant-outline", text:)
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
context "with HTML attributes" do
|
|
33
|
+
let(:params) do
|
|
34
|
+
{ class: "custom", data: { test: "value" }, aria: { label: "Perform action" } }
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
it "merges the custom attributes with the generated ones" do
|
|
38
|
+
expect(output).to have_css(
|
|
39
|
+
".Callout.Callout-variant-soft.custom[data-test='value'][aria-label='Perform action']", text:
|
|
40
|
+
)
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
context "with an icon" do
|
|
45
|
+
let(:params) { { icon: :user } }
|
|
46
|
+
|
|
47
|
+
it "renders a Callout element with the default styling" do
|
|
48
|
+
expect(output).to have_css(".Callout.Callout-variant-soft", text:)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
it "renders the icon" do
|
|
52
|
+
expect(output).to have_css(".Callout svg.Icon.Callout-icon[data-icon-key='user']")
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe Components::DataTable, type: :component do
|
|
4
|
+
before do
|
|
5
|
+
stub_const('Record', Data.define(:title, :text))
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
let(:component) { described_class.new(**params) }
|
|
9
|
+
let(:params) { { rows: } }
|
|
10
|
+
let(:rows) { [] }
|
|
11
|
+
|
|
12
|
+
subject(:output) { render_fragment(component) }
|
|
13
|
+
|
|
14
|
+
it "renders a DataTable element" do
|
|
15
|
+
expect(output).to have_css(
|
|
16
|
+
".DataTable"
|
|
17
|
+
)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
context "with columns and array rows" do
|
|
21
|
+
let(:component) do
|
|
22
|
+
described_class.new(**params) do |table|
|
|
23
|
+
table.column(label: "Title", count: 3) do |record|
|
|
24
|
+
record.title.upcase
|
|
25
|
+
end
|
|
26
|
+
table.column(label: "Description", &:text)
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
let(:rows) do
|
|
31
|
+
[
|
|
32
|
+
Record.new("Hello world", "This is a data table"),
|
|
33
|
+
Record.new("Hello moon", "This is still a data table"),
|
|
34
|
+
Record.new("Hello mars", nil)
|
|
35
|
+
]
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
it "renders a DataTable element" do
|
|
39
|
+
expect(output).to have_css(
|
|
40
|
+
".DataTable"
|
|
41
|
+
)
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
it "renders 2 head cells with the correct labels" do
|
|
45
|
+
expect(output).to have_css(".DataTable-head-cell", count: 2)
|
|
46
|
+
expect(output).to have_css(".DataTable-head-cell", text: "Title")
|
|
47
|
+
expect(output).to have_css(".DataTable-head-cell", text: "Description")
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
it "renders the count in first head cell" do
|
|
51
|
+
expect(output).to have_css(".DataTable-head-cell:first-child .DataTable-head-count", text: "3")
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
it "renders 3 rows in the body" do
|
|
55
|
+
expect(output).to have_css(".DataTable-body .DataTable-row", count: 3)
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
it "renders 6 cells in the body with the correct values" do
|
|
59
|
+
expect(output).to have_css(".DataTable-body-cell", count: 6)
|
|
60
|
+
expect(output).to have_css(".DataTable-body-cell", text: "HELLO WORLD")
|
|
61
|
+
expect(output).to have_css(".DataTable-body-cell", text: "This is a data table")
|
|
62
|
+
expect(output).to have_css(".DataTable-body-cell", text: "HELLO MOON")
|
|
63
|
+
expect(output).to have_css(".DataTable-body-cell", text: "This is still a data table")
|
|
64
|
+
expect(output).to have_css(".DataTable-body-cell", text: "HELLO MARS")
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
context "with columns and hash rows" do
|
|
68
|
+
let(:component) do
|
|
69
|
+
described_class.new(**params) do |table|
|
|
70
|
+
table.column(label: "Title", count: 3) do |id, record|
|
|
71
|
+
"#{id}. #{record.title.upcase}"
|
|
72
|
+
end
|
|
73
|
+
table.column(label: "Description") do |id, record|
|
|
74
|
+
record.text.presence || "No description"
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
let(:rows) do
|
|
80
|
+
{
|
|
81
|
+
1 => Record.new("Hello world", "This is a data table"),
|
|
82
|
+
2 => Record.new("Hello moon", "This is still a data table"),
|
|
83
|
+
3 => Record.new("Hello mars", nil)
|
|
84
|
+
}
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
it "renders 3 rows in the body" do
|
|
88
|
+
expect(output).to have_css(".DataTable-body .DataTable-row", count: 3)
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
it "renders 6 cells in the body with the correct values" do
|
|
92
|
+
expect(output).to have_css(".DataTable-body-cell", count: 6)
|
|
93
|
+
expect(output).to have_css(".DataTable-body-cell", text: "1. HELLO WORLD")
|
|
94
|
+
expect(output).to have_css(".DataTable-body-cell", text: "This is a data table")
|
|
95
|
+
expect(output).to have_css(".DataTable-body-cell", text: "2. HELLO MOON")
|
|
96
|
+
expect(output).to have_css(".DataTable-body-cell", text: "This is still a data table")
|
|
97
|
+
expect(output).to have_css(".DataTable-body-cell", text: "3. HELLO MARS")
|
|
98
|
+
expect(output).to have_css(".DataTable-body-cell", text: "No description")
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
context "with HTML attributes" do
|
|
103
|
+
let(:params) do
|
|
104
|
+
{ class: "custom", data: { test: "value" }, aria: { label: "Perform action" } }
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
it "merges the custom attributes with the generated ones" do
|
|
108
|
+
expect(output).to have_css(
|
|
109
|
+
".DataTable.custom[data-test='value'][aria-label='Perform action']"
|
|
110
|
+
)
|
|
111
|
+
end
|
|
112
|
+
end
|
|
113
|
+
end
|
|
114
|
+
end
|
|
@@ -41,7 +41,7 @@ describe Components::IconSprite, type: :component do
|
|
|
41
41
|
|
|
42
42
|
it "renders the sprite with icons ordered alphabetically" do
|
|
43
43
|
expect(output).to eq_html <<~HTML
|
|
44
|
-
<svg class="IconSprite" hidden=""><defs><symbol id="IconSprite-close" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M18 6 6 18"></path><path d="m6 6 12 12"></path></symbol><symbol id="IconSprite-user" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M19 21v-2a4 4 0 0 0-4-4H9a4 4 0 0 0-4 4v2"></path><circle cx="12" cy="7" r="4"></circle></symbol></defs></svg>
|
|
44
|
+
<svg class="IconSprite" hidden=""><defs><symbol id="IconSprite-close" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M18 6 6 18"></path><path d="m6 6 12 12"></path></symbol><symbol id="IconSprite-user" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M19 21v-2a4 4 0 0 0-4-4H9a4 4 0 0 0-4 4v2"></path><circle cx="12" cy="7" r="4"></circle></symbol></defs></svg>
|
|
45
45
|
HTML
|
|
46
46
|
end
|
|
47
47
|
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
<% props = Components::Callout.literal_properties %>
|
|
2
|
+
|
|
3
|
+
<table class="lookbook-table">
|
|
4
|
+
<thead>
|
|
5
|
+
<tr>
|
|
6
|
+
<th></th>
|
|
7
|
+
|
|
8
|
+
<% props[:type].type.each do |type| %>
|
|
9
|
+
<th><code><%= type %></code></th>
|
|
10
|
+
<% end %>
|
|
11
|
+
</tr>
|
|
12
|
+
</thead>
|
|
13
|
+
|
|
14
|
+
<tbody>
|
|
15
|
+
<% props[:variant].type.each do |variant| %>
|
|
16
|
+
<tr>
|
|
17
|
+
<th><code><%= variant %></code></th>
|
|
18
|
+
|
|
19
|
+
<% props[:type].type.each do |type| %>
|
|
20
|
+
<td>
|
|
21
|
+
<%= render Components::Callout.new(variant:, type:) { "Please upgrade to the new version" } %>
|
|
22
|
+
</td>
|
|
23
|
+
<% end %>
|
|
24
|
+
</tr>
|
|
25
|
+
<% end %>
|
|
26
|
+
</tbody>
|
|
27
|
+
</table>
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
class CalloutPreview < Lookbook::Preview
|
|
2
|
+
include Components
|
|
3
|
+
|
|
4
|
+
def overview; end
|
|
5
|
+
|
|
6
|
+
# @param type [Symbol] select { choices: [accent, error, warning, success] }
|
|
7
|
+
# @param variant [Symbol] select { choices: [soft, surface, outline] }
|
|
8
|
+
# @param label
|
|
9
|
+
def playground(type: :accent, variant: :soft, label: "Please upgrade to the new version.")
|
|
10
|
+
Callout(type:, variant:) { label }
|
|
11
|
+
end
|
|
12
|
+
end
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
<%
|
|
2
|
+
rows = [
|
|
3
|
+
Record.new("Hello world", "This is a data table"),
|
|
4
|
+
Record.new("Hello moon", "This is still a data table"),
|
|
5
|
+
Record.new("Hello mars", nil),
|
|
6
|
+
]
|
|
7
|
+
%>
|
|
8
|
+
<%= render Components::DataTable.new(rows:) do |table|
|
|
9
|
+
table.column(label: "Title", count: rows.size) do |record|
|
|
10
|
+
record.title.upcase
|
|
11
|
+
end
|
|
12
|
+
table.column(label: "Description", &:text)
|
|
13
|
+
end %>
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
<%
|
|
2
|
+
rows = {
|
|
3
|
+
1 => Record.new("Hello world", "This is a data table"),
|
|
4
|
+
2 => Record.new("Hello moon", "This is still a data table"),
|
|
5
|
+
3 => Record.new("Hello mars", nil),
|
|
6
|
+
}
|
|
7
|
+
%>
|
|
8
|
+
<%= render Components::DataTable.new(rows:) do |table|
|
|
9
|
+
table.column(label: "Title", count: rows.keys.size) do |id, record|
|
|
10
|
+
"#{id}. #{record.title.upcase}"
|
|
11
|
+
end
|
|
12
|
+
table.column(label: "Description") do |id, record|
|
|
13
|
+
record.text.presence || "No description"
|
|
14
|
+
end
|
|
15
|
+
end %>
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: backpack
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.4.
|
|
4
|
+
version: 0.4.6
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Lucas Heymès
|
|
@@ -129,6 +129,12 @@ files:
|
|
|
129
129
|
- lib/backpack/components/button.rb
|
|
130
130
|
- lib/backpack/components/button/button.css
|
|
131
131
|
- lib/backpack/components/button/button.js
|
|
132
|
+
- lib/backpack/components/callout.rb
|
|
133
|
+
- lib/backpack/components/callout/callout.css
|
|
134
|
+
- lib/backpack/components/callout/callout.js
|
|
135
|
+
- lib/backpack/components/data_table.rb
|
|
136
|
+
- lib/backpack/components/data_table/data_table.css
|
|
137
|
+
- lib/backpack/components/data_table/data_table.js
|
|
132
138
|
- lib/backpack/components/favicon.rb
|
|
133
139
|
- lib/backpack/components/heading.rb
|
|
134
140
|
- lib/backpack/components/heading/heading.css
|
|
@@ -167,6 +173,8 @@ files:
|
|
|
167
173
|
- spec/components/badge_spec.rb
|
|
168
174
|
- spec/components/breadcrumb_spec.rb
|
|
169
175
|
- spec/components/button_spec.rb
|
|
176
|
+
- spec/components/callout_spec.rb
|
|
177
|
+
- spec/components/data_table_spec.rb
|
|
170
178
|
- spec/components/favicon_spec.rb
|
|
171
179
|
- spec/components/heading_spec.rb
|
|
172
180
|
- spec/components/icon_button_spec.rb
|
|
@@ -177,6 +185,11 @@ files:
|
|
|
177
185
|
- spec/components/previews/breadcrumb_preview.rb
|
|
178
186
|
- spec/components/previews/button_preview.rb
|
|
179
187
|
- spec/components/previews/button_preview/overview.html.erb
|
|
188
|
+
- spec/components/previews/callout_preview.rb
|
|
189
|
+
- spec/components/previews/callout_preview/overview.html.erb
|
|
190
|
+
- spec/components/previews/data_table_preview.rb
|
|
191
|
+
- spec/components/previews/data_table_preview/array.html.erb
|
|
192
|
+
- spec/components/previews/data_table_preview/hash.html.erb
|
|
180
193
|
- spec/components/previews/heading_preview.rb
|
|
181
194
|
- spec/components/previews/icon_button_preview.rb
|
|
182
195
|
- spec/components/previews/icon_button_preview/overview.html.erb
|
|
@@ -227,6 +240,8 @@ test_files:
|
|
|
227
240
|
- spec/components/badge_spec.rb
|
|
228
241
|
- spec/components/breadcrumb_spec.rb
|
|
229
242
|
- spec/components/button_spec.rb
|
|
243
|
+
- spec/components/callout_spec.rb
|
|
244
|
+
- spec/components/data_table_spec.rb
|
|
230
245
|
- spec/components/favicon_spec.rb
|
|
231
246
|
- spec/components/heading_spec.rb
|
|
232
247
|
- spec/components/icon_button_spec.rb
|
|
@@ -237,6 +252,11 @@ test_files:
|
|
|
237
252
|
- spec/components/previews/breadcrumb_preview.rb
|
|
238
253
|
- spec/components/previews/button_preview.rb
|
|
239
254
|
- spec/components/previews/button_preview/overview.html.erb
|
|
255
|
+
- spec/components/previews/callout_preview.rb
|
|
256
|
+
- spec/components/previews/callout_preview/overview.html.erb
|
|
257
|
+
- spec/components/previews/data_table_preview.rb
|
|
258
|
+
- spec/components/previews/data_table_preview/array.html.erb
|
|
259
|
+
- spec/components/previews/data_table_preview/hash.html.erb
|
|
240
260
|
- spec/components/previews/heading_preview.rb
|
|
241
261
|
- spec/components/previews/icon_button_preview.rb
|
|
242
262
|
- spec/components/previews/icon_button_preview/overview.html.erb
|