protos 0.2.2 → 0.3.0
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 +56 -60
- data/examples/list.rb +1 -1
- data/examples/navbar.rb +1 -1
- data/lib/protos/accordion/item.rb +4 -2
- data/lib/protos/accordion.rb +5 -4
- data/lib/protos/alert/actions.rb +1 -1
- data/lib/protos/alert/icon.rb +1 -1
- data/lib/protos/alert.rb +1 -1
- data/lib/protos/avatar.rb +1 -1
- data/lib/protos/breadcrumbs/crumb.rb +1 -1
- data/lib/protos/breadcrumbs.rb +1 -1
- data/lib/protos/card/actions.rb +1 -1
- data/lib/protos/card/body.rb +1 -1
- data/lib/protos/card/image.rb +1 -1
- data/lib/protos/card/title.rb +1 -1
- data/lib/protos/card.rb +1 -1
- data/lib/protos/carousel/actions.rb +1 -1
- data/lib/protos/carousel/item.rb +1 -1
- data/lib/protos/carousel.rb +1 -1
- data/lib/protos/chat_bubble/content.rb +1 -1
- data/lib/protos/chat_bubble/footer.rb +1 -1
- data/lib/protos/chat_bubble/header.rb +1 -1
- data/lib/protos/chat_bubble/image.rb +1 -1
- data/lib/protos/chat_bubble.rb +1 -1
- data/lib/protos/collapse/content.rb +1 -1
- data/lib/protos/collapse/title.rb +10 -2
- data/lib/protos/collapse.rb +12 -4
- data/lib/protos/command/dialog.rb +1 -1
- data/lib/protos/command/empty.rb +1 -1
- data/lib/protos/command/group.rb +1 -1
- data/lib/protos/command/input.rb +3 -2
- data/lib/protos/command/item.rb +1 -1
- data/lib/protos/command/list.rb +1 -1
- data/lib/protos/command/title.rb +1 -1
- data/lib/protos/command/trigger.rb +1 -1
- data/lib/protos/command.rb +1 -1
- data/lib/protos/drawer/content.rb +1 -1
- data/lib/protos/drawer/side.rb +1 -1
- data/lib/protos/drawer/trigger.rb +1 -1
- data/lib/protos/drawer.rb +2 -2
- data/lib/protos/dropdown/item.rb +1 -1
- data/lib/protos/dropdown/menu.rb +1 -1
- data/lib/protos/hero/content.rb +1 -1
- data/lib/protos/hero/overlay.rb +1 -1
- data/lib/protos/hero.rb +1 -1
- data/lib/protos/list/item.rb +1 -1
- data/lib/protos/list.rb +1 -1
- data/lib/protos/modal/close_button.rb +1 -1
- data/lib/protos/modal/dialog.rb +1 -1
- data/lib/protos/modal/trigger.rb +1 -1
- data/lib/protos/modal.rb +1 -1
- data/lib/protos/popover/content.rb +1 -1
- data/lib/protos/popover/trigger.rb +1 -1
- data/lib/protos/popover.rb +1 -1
- data/lib/protos/stats/actions.rb +1 -1
- data/lib/protos/stats/description.rb +1 -1
- data/lib/protos/stats/figure.rb +1 -1
- data/lib/protos/stats/stat.rb +1 -1
- data/lib/protos/stats/title.rb +1 -1
- data/lib/protos/stats/value.rb +1 -1
- data/lib/protos/stats.rb +1 -1
- data/lib/protos/swap/off.rb +1 -1
- data/lib/protos/swap/on.rb +1 -1
- data/lib/protos/swap.rb +3 -4
- data/lib/protos/table/body.rb +1 -1
- data/lib/protos/table/caption.rb +1 -1
- data/lib/protos/table/cell.rb +1 -1
- data/lib/protos/table/footer.rb +1 -1
- data/lib/protos/table/head.rb +1 -1
- data/lib/protos/table/header.rb +1 -1
- data/lib/protos/table/row.rb +1 -1
- data/lib/protos/table.rb +1 -1
- data/lib/protos/tabs/tab.rb +3 -2
- data/lib/protos/tabs.rb +1 -1
- data/lib/protos/theme.rb +10 -1
- data/lib/protos/timeline/center.rb +1 -1
- data/lib/protos/timeline/item.rb +1 -1
- data/lib/protos/timeline/left.rb +1 -1
- data/lib/protos/timeline/right.rb +1 -1
- data/lib/protos/timeline.rb +1 -1
- data/lib/protos/toast/close_button.rb +1 -1
- data/lib/protos/toast.rb +1 -1
- data/lib/protos/token_list.rb +1 -17
- data/lib/protos/typography/heading.rb +1 -1
- data/lib/protos/typography/inline_link.rb +1 -1
- data/lib/protos/typography/paragraph.rb +1 -1
- data/lib/protos/version.rb +1 -1
- data/protos.gemspec +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5fe048d407665dc19039444171da359495565d7b94d1787c444c4e8e8c5fe191
|
4
|
+
data.tar.gz: fda1eea822602572a8a28be104b8e60b533d429745d4ef616be8c7f14bf9e53e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e4859a4076a79386043b18ad71735b9b372c9120a0f3a8a816d1020174152b19ed2a030172ef01e7240ec26d28dce73070ce478ed440e15526eabde03f500067
|
7
|
+
data.tar.gz: 2ac30388a8534552f10cb32bc68b9f7786bd14caf1eab69d8f15c6a310a08d92b27eeb1a97896a60df18cd6e489c30f179706fd72ac0eca7072f435d05ebad9e
|
data/README.md
CHANGED
@@ -25,11 +25,11 @@ Other Phlex based UI libraries worth checking out:
|
|
25
25
|
A protos component follows some conventions that make them easy to work with as
|
26
26
|
components in your app.
|
27
27
|
|
28
|
-
Every UI component library will have a tension between being too general
|
29
|
-
narrow to be useful. Making components that look good out of
|
30
|
-
them hard to customize.
|
28
|
+
Every UI component library will have a tension between being too general to fit
|
29
|
+
in your app or too narrow to be useful. Making components that look good out of
|
30
|
+
the box can make them hard to customize.
|
31
31
|
|
32
|
-
We try and resolve this
|
32
|
+
We try and resolve this tension by making these components have a minimal style
|
33
33
|
that can be easily overridden using some ergonomic conventions.
|
34
34
|
|
35
35
|
There are 3 core conventions:
|
@@ -40,7 +40,12 @@ There are 3 core conventions:
|
|
40
40
|
### Slots and themes
|
41
41
|
|
42
42
|
Components are styled with `css` slots that are filled with values from
|
43
|
-
a `theme
|
43
|
+
a `theme`.
|
44
|
+
|
45
|
+
You define a theme for your component by defining a `#theme` method that returns
|
46
|
+
a hash. This hash will be merged with any theme provided when rendering your
|
47
|
+
component. This allows you to easily override styles for your components
|
48
|
+
depending on their context.
|
44
49
|
|
45
50
|
```ruby
|
46
51
|
class List < Protos::Component
|
@@ -53,31 +58,8 @@ class List < Protos::Component
|
|
53
58
|
|
54
59
|
def theme
|
55
60
|
{
|
56
|
-
list: tokens("space-y-4"),
|
57
|
-
item:
|
58
|
-
}
|
59
|
-
end
|
60
|
-
end
|
61
|
-
```
|
62
|
-
|
63
|
-
Here we are using conditional `tokens` from Phlex but you can also use
|
64
|
-
simple strings.
|
65
|
-
|
66
|
-
If you want to change the method we define our default theme you can override the
|
67
|
-
`theme_method` on the class:
|
68
|
-
|
69
|
-
```ruby
|
70
|
-
class List < Protos::Component
|
71
|
-
theme_method :custom_theme
|
72
|
-
|
73
|
-
# ...
|
74
|
-
|
75
|
-
private
|
76
|
-
|
77
|
-
def custom_theme
|
78
|
-
{
|
79
|
-
list: tokens("space-y-4"),
|
80
|
-
item: tokens("font-bold", "text-2xl")
|
61
|
+
list: tokens("space-y-4"), # We can use `#tokens` from phlex (recommended)
|
62
|
+
item: "font-bold text-2xl" # Or just plain old strings
|
81
63
|
}
|
82
64
|
end
|
83
65
|
end
|
@@ -137,14 +119,36 @@ The new `css[:item]` slot would be:
|
|
137
119
|
<li class="font-bold">Item 1</li>
|
138
120
|
```
|
139
121
|
|
122
|
+
If you want to change the method we define our default theme you can override the
|
123
|
+
`theme_method` on the class:
|
124
|
+
|
125
|
+
```ruby
|
126
|
+
class List < Protos::Component
|
127
|
+
theme_method :custom_theme
|
128
|
+
|
129
|
+
# ...
|
130
|
+
|
131
|
+
private
|
132
|
+
|
133
|
+
def custom_theme
|
134
|
+
{
|
135
|
+
list: tokens("space-y-4"),
|
136
|
+
item: tokens("font-bold", "text-2xl")
|
137
|
+
}
|
138
|
+
end
|
139
|
+
end
|
140
|
+
```
|
141
|
+
|
140
142
|
### Attrs and default attrs
|
141
143
|
|
142
144
|
By convention, all components spread in an `attrs` hash on their outermost
|
143
145
|
element of the component.
|
144
146
|
|
145
147
|
By doing this we enable 2 main conveniences:
|
146
|
-
1. We can pass `class` when initializing the component
|
147
|
-
|
148
|
+
1. We can pass a `class` keyword when initializing the component which will be
|
149
|
+
merged safely into the `css[:container]` slot
|
150
|
+
2. We can add default attributes that are safely merged with any provided to the
|
151
|
+
component when its being initialized
|
148
152
|
|
149
153
|
```ruby
|
150
154
|
class List < Protos::Component
|
@@ -158,9 +162,7 @@ class List < Protos::Component
|
|
158
162
|
|
159
163
|
def default_attrs
|
160
164
|
{
|
161
|
-
|
162
|
-
controller: "list"
|
163
|
-
}
|
165
|
+
data: { controller: "list" }
|
164
166
|
}
|
165
167
|
end
|
166
168
|
|
@@ -173,9 +175,24 @@ class List < Protos::Component
|
|
173
175
|
end
|
174
176
|
```
|
175
177
|
|
176
|
-
|
177
|
-
|
178
|
-
|
178
|
+
`#attrs` will by default merge the `class` keyword into the `css[:container]`
|
179
|
+
slot which we define in our theme.
|
180
|
+
|
181
|
+
Special html options will be safely merged. For examples, the component above
|
182
|
+
defines a list controller. If we passed our own controller into data when we
|
183
|
+
initialize, the component's data-controller attribute would be appended to:
|
184
|
+
|
185
|
+
```ruby
|
186
|
+
render List.new(
|
187
|
+
data: { controller: "tooltip" }
|
188
|
+
)
|
189
|
+
```
|
190
|
+
|
191
|
+
That would output both controllers to the DOM element:
|
192
|
+
|
193
|
+
```html
|
194
|
+
<ul data-controller="list tooltip">
|
195
|
+
```
|
179
196
|
|
180
197
|
If we wanted to, just like for our theme we can change the method from
|
181
198
|
`default_attrs` by defining the `default_attrs_method` on the class:
|
@@ -184,37 +201,16 @@ If we wanted to, just like for our theme we can change the method from
|
|
184
201
|
class List < Protos::Component
|
185
202
|
default_attrs_method :custom_attrs
|
186
203
|
|
187
|
-
# ...
|
188
|
-
|
189
204
|
private
|
190
205
|
|
191
206
|
def custom_attrs
|
192
207
|
{
|
193
|
-
data: {
|
194
|
-
controller: "list"
|
195
|
-
}
|
208
|
+
data: { controller: "list" }
|
196
209
|
}
|
197
210
|
end
|
198
|
-
|
199
|
-
# ...
|
200
211
|
end
|
201
212
|
```
|
202
213
|
|
203
|
-
Now we get some additional convenience:
|
204
|
-
|
205
|
-
```ruby
|
206
|
-
render List.new(
|
207
|
-
class: "my-lg",
|
208
|
-
data: { controller: "confetti" }
|
209
|
-
)
|
210
|
-
```
|
211
|
-
|
212
|
-
This would merge our `data` and `class` safely into the attributes:
|
213
|
-
|
214
|
-
```html
|
215
|
-
<ul data-controller="list confetti" class="space-y-4 my-lg">
|
216
|
-
```
|
217
|
-
|
218
214
|
### Params and options
|
219
215
|
|
220
216
|
Components extend
|
data/examples/list.rb
CHANGED
data/examples/navbar.rb
CHANGED
@@ -7,10 +7,12 @@ module Protos
|
|
7
7
|
|
8
8
|
option :id, type: Types::Coercible::String
|
9
9
|
|
10
|
-
def
|
10
|
+
def view_template(&block)
|
11
11
|
li(**attrs) do
|
12
12
|
render collapse_component do
|
13
|
-
|
13
|
+
# form: "" prevents the radio button from being submitted if its
|
14
|
+
# within a form
|
15
|
+
input(type: :radio, name: id, form: "", autocomplete: :off)
|
14
16
|
yield if block
|
15
17
|
end
|
16
18
|
end
|
data/lib/protos/accordion.rb
CHANGED
@@ -7,9 +7,10 @@ module Protos
|
|
7
7
|
# to be open at the same time, use the collapse component.
|
8
8
|
# https://daisyui.com/components/accordion/
|
9
9
|
|
10
|
-
option :id,
|
10
|
+
option :id,
|
11
|
+
default: -> { "collapse-#{SecureRandom.hex(4)}" }
|
11
12
|
|
12
|
-
def
|
13
|
+
def view_template(&block)
|
13
14
|
ul(**attrs, &block)
|
14
15
|
end
|
15
16
|
|
@@ -17,8 +18,8 @@ module Protos
|
|
17
18
|
Item.new(id:, **kwargs)
|
18
19
|
end
|
19
20
|
|
20
|
-
def title(
|
21
|
-
Collapse::Title.new(
|
21
|
+
def title(*args, **kwargs, &block)
|
22
|
+
Collapse::Title.new(*args, id:, **kwargs, &block)
|
22
23
|
end
|
23
24
|
|
24
25
|
def content(...)
|
data/lib/protos/alert/actions.rb
CHANGED
data/lib/protos/alert/icon.rb
CHANGED
data/lib/protos/alert.rb
CHANGED
data/lib/protos/avatar.rb
CHANGED
data/lib/protos/breadcrumbs.rb
CHANGED
data/lib/protos/card/actions.rb
CHANGED
data/lib/protos/card/body.rb
CHANGED
data/lib/protos/card/image.rb
CHANGED
data/lib/protos/card/title.rb
CHANGED
data/lib/protos/card.rb
CHANGED
data/lib/protos/carousel/item.rb
CHANGED
data/lib/protos/carousel.rb
CHANGED
data/lib/protos/chat_bubble.rb
CHANGED
@@ -5,9 +5,17 @@ module Protos
|
|
5
5
|
class Title < Component
|
6
6
|
# DOCS: The title of a collapse. This is the content that is always
|
7
7
|
# visible and is used to toggle the collapse.
|
8
|
+
option :id,
|
9
|
+
type: Types::Coercible::String,
|
10
|
+
reader: false,
|
11
|
+
default: -> { "" }
|
8
12
|
|
9
|
-
def
|
10
|
-
|
13
|
+
def view_template(&block)
|
14
|
+
if @id.size.positive?
|
15
|
+
label(for: @id, **attrs, &block)
|
16
|
+
else
|
17
|
+
div(**attrs, &block)
|
18
|
+
end
|
11
19
|
end
|
12
20
|
|
13
21
|
private
|
data/lib/protos/collapse.rb
CHANGED
@@ -6,12 +6,20 @@ module Protos
|
|
6
6
|
# is visible at all times, and the content is only visible when expanded.
|
7
7
|
# https://daisyui.com/components/collapse/
|
8
8
|
|
9
|
-
|
10
|
-
|
9
|
+
option :checkbox, default: -> { false }, type: Types::Bool, reader: false
|
10
|
+
option :id,
|
11
|
+
default: -> { "collapse-#{SecureRandom.hex(4)}" },
|
12
|
+
type: Types::String
|
13
|
+
|
14
|
+
def view_template
|
15
|
+
div(**attrs) do
|
16
|
+
input(type: "checkbox", id:, autocomplete: :off) if @checkbox
|
17
|
+
yield if block_given?
|
18
|
+
end
|
11
19
|
end
|
12
20
|
|
13
|
-
def title(
|
14
|
-
Title.new(
|
21
|
+
def title(*args, **kwargs, &block)
|
22
|
+
Title.new(*args, id:, **kwargs, &block)
|
15
23
|
end
|
16
24
|
|
17
25
|
def content(...)
|
@@ -6,7 +6,7 @@ module Protos
|
|
6
6
|
# DOCS: The dialog for a command wraps the command content and provides a
|
7
7
|
# modal backdrop for the command when it is opened.
|
8
8
|
|
9
|
-
def
|
9
|
+
def view_template(&block)
|
10
10
|
dialog(**attrs) do
|
11
11
|
div(class: css[:modal], &block)
|
12
12
|
form(method: :dialog, class: css[:form]) do
|
data/lib/protos/command/empty.rb
CHANGED
data/lib/protos/command/group.rb
CHANGED
data/lib/protos/command/input.rb
CHANGED
@@ -11,7 +11,7 @@ module Protos
|
|
11
11
|
},
|
12
12
|
reader: :private
|
13
13
|
|
14
|
-
def
|
14
|
+
def view_template(&block)
|
15
15
|
div(**attrs) do
|
16
16
|
label(class: css[:label]) do
|
17
17
|
div(class: css[:icon], &block) if block
|
@@ -19,7 +19,8 @@ module Protos
|
|
19
19
|
type: :text,
|
20
20
|
data: { action: "protos--command#filter" },
|
21
21
|
class: css[:input],
|
22
|
-
placeholder
|
22
|
+
placeholder:,
|
23
|
+
autocomplete: :off
|
23
24
|
)
|
24
25
|
end
|
25
26
|
end
|
data/lib/protos/command/item.rb
CHANGED
data/lib/protos/command/list.rb
CHANGED
data/lib/protos/command/title.rb
CHANGED
data/lib/protos/command.rb
CHANGED
data/lib/protos/drawer/side.rb
CHANGED
data/lib/protos/drawer.rb
CHANGED
@@ -9,9 +9,9 @@ module Protos
|
|
9
9
|
|
10
10
|
option :id, type: Types::Coercible::String
|
11
11
|
|
12
|
-
def
|
12
|
+
def view_template
|
13
13
|
div(**attrs) do
|
14
|
-
input(id:, type: :checkbox, class: css[:toggle])
|
14
|
+
input(id:, type: :checkbox, class: css[:toggle], autocomplete: :off)
|
15
15
|
yield if block_given?
|
16
16
|
end
|
17
17
|
end
|