element_component 0.10.0 → 0.12.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/AGENTS.md +102 -10
- data/lib/element_component/aliases.rb +116 -0
- data/lib/element_component/components/alert/heading.rb +2 -1
- data/lib/element_component/components/alert/link.rb +2 -1
- data/lib/element_component/components/alert.rb +2 -1
- data/lib/element_component/components/badge.rb +2 -1
- data/lib/element_component/components/breadcrumb/item.rb +2 -1
- data/lib/element_component/components/breadcrumb.rb +2 -1
- data/lib/element_component/components/button.rb +2 -1
- data/lib/element_component/components/button_group.rb +2 -1
- data/lib/element_component/components/card/body.rb +2 -1
- data/lib/element_component/components/card/footer.rb +2 -1
- data/lib/element_component/components/card/header.rb +2 -1
- data/lib/element_component/components/card/text.rb +2 -1
- data/lib/element_component/components/card/title.rb +2 -1
- data/lib/element_component/components/card.rb +2 -1
- data/lib/element_component/components/carousel/caption.rb +2 -1
- data/lib/element_component/components/carousel/item.rb +2 -1
- data/lib/element_component/components/carousel.rb +2 -1
- data/lib/element_component/components/dropdown/header.rb +2 -1
- data/lib/element_component/components/dropdown/item.rb +2 -1
- data/lib/element_component/components/dropdown/menu.rb +2 -1
- data/lib/element_component/components/dropdown.rb +2 -1
- data/lib/element_component/components/list_group/item.rb +2 -1
- data/lib/element_component/components/list_group.rb +2 -1
- data/lib/element_component/components/modal/body.rb +2 -1
- data/lib/element_component/components/modal/content.rb +2 -1
- data/lib/element_component/components/modal/dialog.rb +2 -1
- data/lib/element_component/components/modal/footer.rb +2 -1
- data/lib/element_component/components/modal/header.rb +2 -1
- data/lib/element_component/components/modal/title.rb +2 -1
- data/lib/element_component/components/nav/item.rb +2 -1
- data/lib/element_component/components/nav/link.rb +2 -1
- data/lib/element_component/components/nav.rb +2 -1
- data/lib/element_component/components/navbar/brand.rb +2 -1
- data/lib/element_component/components/navbar/collapse.rb +2 -1
- data/lib/element_component/components/navbar/nav.rb +2 -1
- data/lib/element_component/components/navbar.rb +2 -1
- data/lib/element_component/components/pagination/item.rb +2 -1
- data/lib/element_component/components/pagination.rb +2 -1
- data/lib/element_component/components/progress/bar.rb +2 -1
- data/lib/element_component/components/progress.rb +2 -1
- data/lib/element_component/components/spinner.rb +2 -1
- data/lib/element_component/components/table.rb +2 -1
- data/lib/element_component/version.rb +1 -1
- data/lib/element_component.rb +1 -0
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: b327f66396580a4106a123f22a80cf6edb726a1d98b5b47dcea4f00d4df8649a
|
|
4
|
+
data.tar.gz: 2ba097718efa76c3418a62657eb9f2f897d67501a88f9942d8b002d7ac783acf
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 83f7331b27128641ca774e75f5fd4e8ee4681402630f0091c31f27afe2397523e530e529ffb8481504555196a94ea530de820dbb278e03e9773eaf7a2bf55aa9
|
|
7
|
+
data.tar.gz: 988bada7149ec432984c71638e3cf4a53f309910093d10cebaf6a30ee13ff524697ebf19c7118c96625ff94575068eb5660c71902d992847943fa786b692a943
|
data/AGENTS.md
CHANGED
|
@@ -12,6 +12,7 @@ lib/
|
|
|
12
12
|
version.rb # VERSION constant
|
|
13
13
|
element.rb # Core Element class
|
|
14
14
|
components.rb # Component index, requires all components
|
|
15
|
+
aliases.rb # Namespace aliases and shortcuts
|
|
15
16
|
components/
|
|
16
17
|
alert.rb # Alert component
|
|
17
18
|
alert/
|
|
@@ -76,6 +77,7 @@ spec/
|
|
|
76
77
|
element_component_spec.rb # Version check
|
|
77
78
|
lib/
|
|
78
79
|
element_spec.rb # Element unit tests
|
|
80
|
+
aliases_spec.rb # Namespace aliases tests
|
|
79
81
|
components/
|
|
80
82
|
alert_spec.rb # Alert component tests
|
|
81
83
|
badge_spec.rb # Badge component tests
|
|
@@ -99,18 +101,56 @@ examples/
|
|
|
99
101
|
alert_example.rb # Complete Alert usage examples
|
|
100
102
|
```
|
|
101
103
|
|
|
104
|
+
## Namespace Aliases
|
|
105
|
+
|
|
106
|
+
All components and the Element class can be accessed in multiple ways to reduce verbosity:
|
|
107
|
+
|
|
108
|
+
### 1. Direct aliases (recommended)
|
|
109
|
+
```ruby
|
|
110
|
+
ElementComponent::Card.new("content")
|
|
111
|
+
ElementComponent::Alert.new("message", variant: :success)
|
|
112
|
+
ElementComponent::E.new("div", "content")
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
### 2. Short module alias
|
|
116
|
+
```ruby
|
|
117
|
+
EC::Card.new("content")
|
|
118
|
+
EC::E.new("span", "text")
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
### 3. Helper method for generic elements
|
|
122
|
+
```ruby
|
|
123
|
+
ElementComponent.tag("div", "content", class: "container")
|
|
124
|
+
ElementComponent.tag("div") { |e| e.add_content("block") }
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
### 4. View shortcuts (include in views/helpers)
|
|
128
|
+
```ruby
|
|
129
|
+
class MyView
|
|
130
|
+
include ElementComponent::Shortcuts
|
|
131
|
+
|
|
132
|
+
def render
|
|
133
|
+
Card.new("content")
|
|
134
|
+
E.new("span", "text")
|
|
135
|
+
tag("div", "content")
|
|
136
|
+
end
|
|
137
|
+
end
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
**All 48 components are available** via all four access patterns above.
|
|
141
|
+
|
|
102
142
|
## Core Classes
|
|
103
143
|
|
|
104
|
-
### `ElementComponent::Element`
|
|
144
|
+
### `ElementComponent::Element` (alias: `ElementComponent::E`)
|
|
105
145
|
- **Attributes**: `element` (tag name), `attributes` (Hash), `contents` (Array), `html` (rendered output)
|
|
106
|
-
- **Constructor**: `Element.new(tag_name, closing_tag: true, **attributes)`
|
|
146
|
+
- **Constructor**: `Element.new(tag_name, content = nil, closing_tag: true, **attributes, &block)`
|
|
107
147
|
- **Content methods**: `add_content`, `add_content!`, `add_content(&block)` — `content` can be a single value or an Array of values
|
|
108
148
|
- **Attribute methods**: `add_attribute`, `add_attribute!`, `remove_attribute`, `remove_attribute_value`
|
|
109
149
|
- **Render**: `render` (with hooks: `before_render`, `after_render`, `around_render`)
|
|
110
150
|
|
|
111
151
|
### Pre-built Components
|
|
112
152
|
|
|
113
|
-
Components live under `ElementComponent::Components
|
|
153
|
+
Components live under `ElementComponent::Components` (alias: `EC`). Direct aliases are also available under `ElementComponent::`.
|
|
114
154
|
|
|
115
155
|
| Component | Class | Tag | Key Options |
|
|
116
156
|
|---|---|---|---|
|
|
@@ -132,7 +172,8 @@ Components live under `ElementComponent::Components`. Each component folder cont
|
|
|
132
172
|
| Spinner | `Spinner` | `<div>` | `type` (border/grow), `variant` |
|
|
133
173
|
| Table | `Table` | `<table>` | `striped`, `bordered`, `hover`, `small`, `variant` |
|
|
134
174
|
|
|
135
|
-
**Alert constructor**: `Alert.new(variant: :primary, dismissible: false, **attributes, &block)`
|
|
175
|
+
**Alert constructor**: `Alert.new(content = nil, variant: :primary, dismissible: false, **attributes, &block)`
|
|
176
|
+
- `content`: optional content string or array, added before block content
|
|
136
177
|
- `variant`: one of `:primary`, `:secondary`, `:success`, `:danger`, `:warning`, `:info`, `:light`, `:dark`
|
|
137
178
|
- `dismissible`: adds `.alert-dismissible` class and appends a `CloseButton`
|
|
138
179
|
- `&block`: block with element parameter for adding content inside the element
|
|
@@ -140,18 +181,61 @@ Components live under `ElementComponent::Components`. Each component folder cont
|
|
|
140
181
|
**Component guidelines**:
|
|
141
182
|
- Always use `add_attribute()` instead of manipulating the `attributes` hash directly
|
|
142
183
|
- Each class in its own file under a component-named folder
|
|
143
|
-
-
|
|
144
|
-
- `block
|
|
184
|
+
- **Constructor pattern**: `def initialize(content = nil, **keyword_args, **attributes, &block)`
|
|
185
|
+
- Call `super("tag_name", &block)` first, then chain `add_attribute` calls, then `add_content(content) if content`
|
|
186
|
+
- Content from the `content` argument is added **before** block content
|
|
145
187
|
- Pass user attributes last via `add_attribute(attributes)`
|
|
146
188
|
|
|
147
|
-
###
|
|
189
|
+
### Component constructor pattern:
|
|
148
190
|
|
|
149
191
|
```ruby
|
|
150
192
|
class AlertHeading < Element
|
|
151
|
-
def initialize(**attributes
|
|
152
|
-
super("h4"
|
|
193
|
+
def initialize(content = nil, **attributes)
|
|
194
|
+
super("h4")
|
|
153
195
|
add_attribute(class: "alert-heading")
|
|
154
|
-
add_attribute(attributes)
|
|
196
|
+
add_attribute(attributes) unless attributes.empty?
|
|
197
|
+
add_content(content) if content
|
|
198
|
+
end
|
|
199
|
+
end
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
### Components with internal content (e.g., Alert, ModalHeader):
|
|
203
|
+
|
|
204
|
+
```ruby
|
|
205
|
+
class Alert < Element
|
|
206
|
+
def initialize(content = nil, variant: :primary, dismissible: false, **attributes, &block)
|
|
207
|
+
super("div", &block)
|
|
208
|
+
|
|
209
|
+
add_attribute(class: "alert")
|
|
210
|
+
add_attribute(class: "alert-\#{variant}")
|
|
211
|
+
add_attribute(class: "alert-dismissible") if dismissible
|
|
212
|
+
add_attribute(role: "alert")
|
|
213
|
+
|
|
214
|
+
add_attribute(attributes) unless attributes.empty?
|
|
215
|
+
add_content(content) if content # user content first
|
|
216
|
+
add_content(AlertCloseButton.new) if dismissible # internal content after
|
|
217
|
+
end
|
|
218
|
+
end
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
### Components with conditional tag names (e.g., Button, ListGroupItem):
|
|
222
|
+
|
|
223
|
+
```ruby
|
|
224
|
+
class Button < Element
|
|
225
|
+
def initialize(content = nil, variant: :primary, outline: false, size: nil, href: nil, **attributes, &block)
|
|
226
|
+
if href
|
|
227
|
+
super("a", &block)
|
|
228
|
+
add_attribute(href: href)
|
|
229
|
+
else
|
|
230
|
+
super("button", &block)
|
|
231
|
+
add_attribute(type: "button")
|
|
232
|
+
end
|
|
233
|
+
|
|
234
|
+
add_attribute(class: "btn")
|
|
235
|
+
add_attribute(class: outline ? "btn-outline-\#{variant}" : "btn-\#{variant}")
|
|
236
|
+
add_attribute(class: "btn-\#{size}") if size
|
|
237
|
+
add_attribute(attributes) unless attributes.empty?
|
|
238
|
+
add_content(content) if content
|
|
155
239
|
end
|
|
156
240
|
end
|
|
157
241
|
```
|
|
@@ -184,6 +268,7 @@ ruby examples/alert_example.rb # Run Alert examples
|
|
|
184
268
|
- Test render output as raw HTML strings
|
|
185
269
|
- Test attribute hashes directly
|
|
186
270
|
- Follow existing describe/context/it structure
|
|
271
|
+
- Test new aliases in `spec/lib/aliases_spec.rb`
|
|
187
272
|
|
|
188
273
|
## Development Workflow
|
|
189
274
|
|
|
@@ -202,6 +287,13 @@ ruby examples/alert_example.rb # Run Alert examples
|
|
|
202
287
|
- Hooks (`before_render`, `after_render`, `around_render`) are optional, detected via `respond_to?`
|
|
203
288
|
- Self-closing tags controlled by `closing_tag:` parameter
|
|
204
289
|
- Component classes use `add_attribute()` instead of direct hash manipulation
|
|
290
|
+
- `content` as first positional argument in all constructors (optional, default `nil`)
|
|
291
|
+
- Content argument is added before block content when both are provided
|
|
292
|
+
- All 48 components are aliased directly under `ElementComponent::` for convenience
|
|
293
|
+
- `ElementComponent::E` is an alias for `ElementComponent::Element`
|
|
294
|
+
- `ElementComponent::EC` is an alias for `ElementComponent::Components`
|
|
295
|
+
- `ElementComponent.tag()` is a helper method for creating generic elements
|
|
296
|
+
- `ElementComponent::Shortcuts` module provides instance methods for use in views/helpers
|
|
205
297
|
|
|
206
298
|
## Roadmap Features (from README)
|
|
207
299
|
- Caching support
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module ElementComponent
|
|
4
|
+
E = Element
|
|
5
|
+
|
|
6
|
+
def self.tag(name, content = nil, **attributes, &)
|
|
7
|
+
Element.new(name, content, **attributes, &)
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
EC = Components
|
|
11
|
+
|
|
12
|
+
Alert = Components::Alert
|
|
13
|
+
Badge = Components::Badge
|
|
14
|
+
Breadcrumb = Components::Breadcrumb
|
|
15
|
+
Button = Components::Button
|
|
16
|
+
ButtonGroup = Components::ButtonGroup
|
|
17
|
+
Card = Components::Card
|
|
18
|
+
Carousel = Components::Carousel
|
|
19
|
+
CloseButton = Components::CloseButton
|
|
20
|
+
Dropdown = Components::Dropdown
|
|
21
|
+
ListGroup = Components::ListGroup
|
|
22
|
+
Modal = Components::Modal
|
|
23
|
+
Nav = Components::Nav
|
|
24
|
+
Navbar = Components::Navbar
|
|
25
|
+
Pagination = Components::Pagination
|
|
26
|
+
Progress = Components::Progress
|
|
27
|
+
Spinner = Components::Spinner
|
|
28
|
+
Table = Components::Table
|
|
29
|
+
|
|
30
|
+
AlertHeading = Components::AlertHeading
|
|
31
|
+
AlertLink = Components::AlertLink
|
|
32
|
+
AlertCloseButton = Components::AlertCloseButton
|
|
33
|
+
BreadcrumbItem = Components::BreadcrumbItem
|
|
34
|
+
CardHeader = Components::CardHeader
|
|
35
|
+
CardBody = Components::CardBody
|
|
36
|
+
CardFooter = Components::CardFooter
|
|
37
|
+
CardTitle = Components::CardTitle
|
|
38
|
+
CardText = Components::CardText
|
|
39
|
+
CardImage = Components::CardImage
|
|
40
|
+
CarouselItem = Components::CarouselItem
|
|
41
|
+
CarouselCaption = Components::CarouselCaption
|
|
42
|
+
DropdownMenu = Components::DropdownMenu
|
|
43
|
+
DropdownItem = Components::DropdownItem
|
|
44
|
+
DropdownDivider = Components::DropdownDivider
|
|
45
|
+
DropdownHeader = Components::DropdownHeader
|
|
46
|
+
ListGroupItem = Components::ListGroupItem
|
|
47
|
+
ModalDialog = Components::ModalDialog
|
|
48
|
+
ModalContent = Components::ModalContent
|
|
49
|
+
ModalHeader = Components::ModalHeader
|
|
50
|
+
ModalTitle = Components::ModalTitle
|
|
51
|
+
ModalBody = Components::ModalBody
|
|
52
|
+
ModalFooter = Components::ModalFooter
|
|
53
|
+
NavItem = Components::NavItem
|
|
54
|
+
NavLink = Components::NavLink
|
|
55
|
+
NavbarBrand = Components::NavbarBrand
|
|
56
|
+
NavbarToggler = Components::NavbarToggler
|
|
57
|
+
NavbarCollapse = Components::NavbarCollapse
|
|
58
|
+
NavbarNav = Components::NavbarNav
|
|
59
|
+
PageItem = Components::PageItem
|
|
60
|
+
ProgressBar = Components::ProgressBar
|
|
61
|
+
|
|
62
|
+
# rubocop:disable Naming/MethodName
|
|
63
|
+
module Shortcuts
|
|
64
|
+
def Card(...) = ElementComponent::Card.new(...)
|
|
65
|
+
def Alert(...) = ElementComponent::Alert.new(...)
|
|
66
|
+
def Badge(...) = ElementComponent::Badge.new(...)
|
|
67
|
+
def Button(...) = ElementComponent::Button.new(...)
|
|
68
|
+
def ButtonGroup(...) = ElementComponent::ButtonGroup.new(...)
|
|
69
|
+
def Breadcrumb(...) = ElementComponent::Breadcrumb.new(...)
|
|
70
|
+
def Carousel(...) = ElementComponent::Carousel.new(...)
|
|
71
|
+
def CloseButton(...) = ElementComponent::CloseButton.new(...)
|
|
72
|
+
def Dropdown(...) = ElementComponent::Dropdown.new(...)
|
|
73
|
+
def ListGroup(...) = ElementComponent::ListGroup.new(...)
|
|
74
|
+
def Modal(...) = ElementComponent::Modal.new(...)
|
|
75
|
+
def Nav(...) = ElementComponent::Nav.new(...)
|
|
76
|
+
def Navbar(...) = ElementComponent::Navbar.new(...)
|
|
77
|
+
def Pagination(...) = ElementComponent::Pagination.new(...)
|
|
78
|
+
def Progress(...) = ElementComponent::Progress.new(...)
|
|
79
|
+
def Spinner(...) = ElementComponent::Spinner.new(...)
|
|
80
|
+
def Table(...) = ElementComponent::Table.new(...)
|
|
81
|
+
def AlertHeading(...) = ElementComponent::AlertHeading.new(...)
|
|
82
|
+
def AlertLink(...) = ElementComponent::AlertLink.new(...)
|
|
83
|
+
def AlertCloseButton(...) = ElementComponent::AlertCloseButton.new(...)
|
|
84
|
+
def BreadcrumbItem(...) = ElementComponent::BreadcrumbItem.new(...)
|
|
85
|
+
def CardHeader(...) = ElementComponent::CardHeader.new(...)
|
|
86
|
+
def CardBody(...) = ElementComponent::CardBody.new(...)
|
|
87
|
+
def CardFooter(...) = ElementComponent::CardFooter.new(...)
|
|
88
|
+
def CardTitle(...) = ElementComponent::CardTitle.new(...)
|
|
89
|
+
def CardText(...) = ElementComponent::CardText.new(...)
|
|
90
|
+
def CardImage(...) = ElementComponent::CardImage.new(...)
|
|
91
|
+
def CarouselItem(...) = ElementComponent::CarouselItem.new(...)
|
|
92
|
+
def CarouselCaption(...) = ElementComponent::CarouselCaption.new(...)
|
|
93
|
+
def DropdownMenu(...) = ElementComponent::DropdownMenu.new(...)
|
|
94
|
+
def DropdownItem(...) = ElementComponent::DropdownItem.new(...)
|
|
95
|
+
def DropdownDivider(...) = ElementComponent::DropdownDivider.new(...)
|
|
96
|
+
def DropdownHeader(...) = ElementComponent::DropdownHeader.new(...)
|
|
97
|
+
def ListGroupItem(...) = ElementComponent::ListGroupItem.new(...)
|
|
98
|
+
def ModalDialog(...) = ElementComponent::ModalDialog.new(...)
|
|
99
|
+
def ModalContent(...) = ElementComponent::ModalContent.new(...)
|
|
100
|
+
def ModalHeader(...) = ElementComponent::ModalHeader.new(...)
|
|
101
|
+
def ModalTitle(...) = ElementComponent::ModalTitle.new(...)
|
|
102
|
+
def ModalBody(...) = ElementComponent::ModalBody.new(...)
|
|
103
|
+
def ModalFooter(...) = ElementComponent::ModalFooter.new(...)
|
|
104
|
+
def NavItem(...) = ElementComponent::NavItem.new(...)
|
|
105
|
+
def NavLink(...) = ElementComponent::NavLink.new(...)
|
|
106
|
+
def NavbarBrand(...) = ElementComponent::NavbarBrand.new(...)
|
|
107
|
+
def NavbarToggler(...) = ElementComponent::NavbarToggler.new(...)
|
|
108
|
+
def NavbarCollapse(...) = ElementComponent::NavbarCollapse.new(...)
|
|
109
|
+
def NavbarNav(...) = ElementComponent::NavbarNav.new(...)
|
|
110
|
+
def PageItem(...) = ElementComponent::PageItem.new(...)
|
|
111
|
+
def ProgressBar(...) = ElementComponent::ProgressBar.new(...)
|
|
112
|
+
def E(...) = ElementComponent::E.new(...)
|
|
113
|
+
def tag(...) = ElementComponent.tag(...)
|
|
114
|
+
end
|
|
115
|
+
# rubocop:enable Naming/MethodName
|
|
116
|
+
end
|
|
@@ -3,11 +3,12 @@
|
|
|
3
3
|
module ElementComponent
|
|
4
4
|
module Components
|
|
5
5
|
class AlertHeading < Element
|
|
6
|
-
def initialize(**attributes)
|
|
6
|
+
def initialize(content = nil, **attributes)
|
|
7
7
|
super("h4")
|
|
8
8
|
|
|
9
9
|
add_attribute(class: "alert-heading")
|
|
10
10
|
add_attribute(attributes) unless attributes.empty?
|
|
11
|
+
add_content(content) if content
|
|
11
12
|
end
|
|
12
13
|
end
|
|
13
14
|
end
|
|
@@ -3,12 +3,13 @@
|
|
|
3
3
|
module ElementComponent
|
|
4
4
|
module Components
|
|
5
5
|
class AlertLink < Element
|
|
6
|
-
def initialize(href: "#", **attributes)
|
|
6
|
+
def initialize(content = nil, href: "#", **attributes)
|
|
7
7
|
super("a")
|
|
8
8
|
|
|
9
9
|
add_attribute(class: "alert-link")
|
|
10
10
|
add_attribute(href: href)
|
|
11
11
|
add_attribute(attributes) unless attributes.empty?
|
|
12
|
+
add_content(content) if content
|
|
12
13
|
end
|
|
13
14
|
end
|
|
14
15
|
end
|
|
@@ -9,7 +9,7 @@ module ElementComponent
|
|
|
9
9
|
class Alert < Element
|
|
10
10
|
VALID_VARIANTS = %i[primary secondary success danger warning info light dark].freeze
|
|
11
11
|
|
|
12
|
-
def initialize(variant: :primary, dismissible: false, **attributes, &block)
|
|
12
|
+
def initialize(content = nil, variant: :primary, dismissible: false, **attributes, &block)
|
|
13
13
|
super("div", &block)
|
|
14
14
|
|
|
15
15
|
add_attribute(class: "alert")
|
|
@@ -18,6 +18,7 @@ module ElementComponent
|
|
|
18
18
|
add_attribute(role: "alert")
|
|
19
19
|
|
|
20
20
|
add_attribute(attributes) unless attributes.empty?
|
|
21
|
+
add_content(content) if content
|
|
21
22
|
add_content(AlertCloseButton.new) if dismissible
|
|
22
23
|
end
|
|
23
24
|
end
|
|
@@ -5,13 +5,14 @@ module ElementComponent
|
|
|
5
5
|
class Badge < Element
|
|
6
6
|
VALID_VARIANTS = %i[primary secondary success danger warning info light dark].freeze
|
|
7
7
|
|
|
8
|
-
def initialize(variant: :primary, pill: false, **attributes, &block)
|
|
8
|
+
def initialize(content = nil, variant: :primary, pill: false, **attributes, &block)
|
|
9
9
|
super("span", &block)
|
|
10
10
|
|
|
11
11
|
add_attribute(class: "badge")
|
|
12
12
|
add_attribute(class: "bg-#{variant}")
|
|
13
13
|
add_attribute(class: "rounded-pill") if pill
|
|
14
14
|
add_attribute(attributes) unless attributes.empty?
|
|
15
|
+
add_content(content) if content
|
|
15
16
|
end
|
|
16
17
|
end
|
|
17
18
|
end
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
module ElementComponent
|
|
4
4
|
module Components
|
|
5
5
|
class BreadcrumbItem < Element
|
|
6
|
-
def initialize(href: nil, active: false, **attributes, &block)
|
|
6
|
+
def initialize(content = nil, href: nil, active: false, **attributes, &block)
|
|
7
7
|
super("li", &block)
|
|
8
8
|
|
|
9
9
|
add_attribute(class: "breadcrumb-item")
|
|
@@ -12,6 +12,7 @@ module ElementComponent
|
|
|
12
12
|
add_attribute(attributes) unless attributes.empty?
|
|
13
13
|
|
|
14
14
|
@href = href
|
|
15
|
+
add_content(content) if content
|
|
15
16
|
end
|
|
16
17
|
|
|
17
18
|
private
|
|
@@ -5,11 +5,12 @@ require_relative "breadcrumb/item"
|
|
|
5
5
|
module ElementComponent
|
|
6
6
|
module Components
|
|
7
7
|
class Breadcrumb < Element
|
|
8
|
-
def initialize(**attributes, &)
|
|
8
|
+
def initialize(content = nil, **attributes, &)
|
|
9
9
|
super("nav", &)
|
|
10
10
|
|
|
11
11
|
add_attribute("aria-label": "breadcrumb")
|
|
12
12
|
add_attribute(attributes) unless attributes.empty?
|
|
13
|
+
add_content(content) if content
|
|
13
14
|
end
|
|
14
15
|
|
|
15
16
|
def build
|
|
@@ -6,7 +6,7 @@ module ElementComponent
|
|
|
6
6
|
VALID_VARIANTS = %i[primary secondary success danger warning info light dark link].freeze
|
|
7
7
|
VALID_SIZES = %i[sm lg].freeze
|
|
8
8
|
|
|
9
|
-
def initialize(variant: :primary, outline: false, size: nil, href: nil, **attributes, &block)
|
|
9
|
+
def initialize(content = nil, variant: :primary, outline: false, size: nil, href: nil, **attributes, &block)
|
|
10
10
|
if href
|
|
11
11
|
super("a", &block)
|
|
12
12
|
add_attribute(href: href)
|
|
@@ -19,6 +19,7 @@ module ElementComponent
|
|
|
19
19
|
add_attribute(class: outline ? "btn-outline-#{variant}" : "btn-#{variant}")
|
|
20
20
|
add_attribute(class: "btn-#{size}") if size
|
|
21
21
|
add_attribute(attributes) unless attributes.empty?
|
|
22
|
+
add_content(content) if content
|
|
22
23
|
end
|
|
23
24
|
end
|
|
24
25
|
end
|
|
@@ -5,13 +5,14 @@ module ElementComponent
|
|
|
5
5
|
class ButtonGroup < Element
|
|
6
6
|
VALID_SIZES = %i[sm lg].freeze
|
|
7
7
|
|
|
8
|
-
def initialize(size: nil, vertical: false, **attributes, &block)
|
|
8
|
+
def initialize(content = nil, size: nil, vertical: false, **attributes, &block)
|
|
9
9
|
super("div", &block)
|
|
10
10
|
|
|
11
11
|
add_attribute(class: vertical ? "btn-group-vertical" : "btn-group")
|
|
12
12
|
add_attribute(class: "btn-group-#{size}") if size
|
|
13
13
|
add_attribute(role: "group")
|
|
14
14
|
add_attribute(attributes) unless attributes.empty?
|
|
15
|
+
add_content(content) if content
|
|
15
16
|
end
|
|
16
17
|
end
|
|
17
18
|
end
|
|
@@ -3,11 +3,12 @@
|
|
|
3
3
|
module ElementComponent
|
|
4
4
|
module Components
|
|
5
5
|
class CardBody < Element
|
|
6
|
-
def initialize(**attributes, &)
|
|
6
|
+
def initialize(content = nil, **attributes, &)
|
|
7
7
|
super("div", &)
|
|
8
8
|
|
|
9
9
|
add_attribute(class: "card-body")
|
|
10
10
|
add_attribute(attributes) unless attributes.empty?
|
|
11
|
+
add_content(content) if content
|
|
11
12
|
end
|
|
12
13
|
end
|
|
13
14
|
end
|
|
@@ -3,11 +3,12 @@
|
|
|
3
3
|
module ElementComponent
|
|
4
4
|
module Components
|
|
5
5
|
class CardFooter < Element
|
|
6
|
-
def initialize(**attributes, &)
|
|
6
|
+
def initialize(content = nil, **attributes, &)
|
|
7
7
|
super("div", &)
|
|
8
8
|
|
|
9
9
|
add_attribute(class: "card-footer")
|
|
10
10
|
add_attribute(attributes) unless attributes.empty?
|
|
11
|
+
add_content(content) if content
|
|
11
12
|
end
|
|
12
13
|
end
|
|
13
14
|
end
|
|
@@ -3,11 +3,12 @@
|
|
|
3
3
|
module ElementComponent
|
|
4
4
|
module Components
|
|
5
5
|
class CardHeader < Element
|
|
6
|
-
def initialize(**attributes, &)
|
|
6
|
+
def initialize(content = nil, **attributes, &)
|
|
7
7
|
super("div", &)
|
|
8
8
|
|
|
9
9
|
add_attribute(class: "card-header")
|
|
10
10
|
add_attribute(attributes) unless attributes.empty?
|
|
11
|
+
add_content(content) if content
|
|
11
12
|
end
|
|
12
13
|
end
|
|
13
14
|
end
|
|
@@ -3,11 +3,12 @@
|
|
|
3
3
|
module ElementComponent
|
|
4
4
|
module Components
|
|
5
5
|
class CardText < Element
|
|
6
|
-
def initialize(**attributes, &)
|
|
6
|
+
def initialize(content = nil, **attributes, &)
|
|
7
7
|
super("p", &)
|
|
8
8
|
|
|
9
9
|
add_attribute(class: "card-text")
|
|
10
10
|
add_attribute(attributes) unless attributes.empty?
|
|
11
|
+
add_content(content) if content
|
|
11
12
|
end
|
|
12
13
|
end
|
|
13
14
|
end
|
|
@@ -3,11 +3,12 @@
|
|
|
3
3
|
module ElementComponent
|
|
4
4
|
module Components
|
|
5
5
|
class CardTitle < Element
|
|
6
|
-
def initialize(**attributes, &)
|
|
6
|
+
def initialize(content = nil, **attributes, &)
|
|
7
7
|
super("h5", &)
|
|
8
8
|
|
|
9
9
|
add_attribute(class: "card-title")
|
|
10
10
|
add_attribute(attributes) unless attributes.empty?
|
|
11
|
+
add_content(content) if content
|
|
11
12
|
end
|
|
12
13
|
end
|
|
13
14
|
end
|
|
@@ -10,11 +10,12 @@ require_relative "card/image"
|
|
|
10
10
|
module ElementComponent
|
|
11
11
|
module Components
|
|
12
12
|
class Card < Element
|
|
13
|
-
def initialize(**attributes, &)
|
|
13
|
+
def initialize(content = nil, **attributes, &)
|
|
14
14
|
super("div", &)
|
|
15
15
|
|
|
16
16
|
add_attribute(class: "card")
|
|
17
17
|
add_attribute(attributes) unless attributes.empty?
|
|
18
|
+
add_content(content) if content
|
|
18
19
|
end
|
|
19
20
|
end
|
|
20
21
|
end
|
|
@@ -3,11 +3,12 @@
|
|
|
3
3
|
module ElementComponent
|
|
4
4
|
module Components
|
|
5
5
|
class CarouselCaption < Element
|
|
6
|
-
def initialize(**attributes, &)
|
|
6
|
+
def initialize(content = nil, **attributes, &)
|
|
7
7
|
super("div", &)
|
|
8
8
|
|
|
9
9
|
add_attribute(class: "carousel-caption")
|
|
10
10
|
add_attribute(attributes) unless attributes.empty?
|
|
11
|
+
add_content(content) if content
|
|
11
12
|
end
|
|
12
13
|
end
|
|
13
14
|
end
|
|
@@ -3,13 +3,14 @@
|
|
|
3
3
|
module ElementComponent
|
|
4
4
|
module Components
|
|
5
5
|
class CarouselItem < Element
|
|
6
|
-
def initialize(active: false, interval: nil, **attributes, &block)
|
|
6
|
+
def initialize(content = nil, active: false, interval: nil, **attributes, &block)
|
|
7
7
|
super("div", &block)
|
|
8
8
|
|
|
9
9
|
add_attribute(class: "carousel-item")
|
|
10
10
|
add_attribute(class: "active") if active
|
|
11
11
|
add_attribute("data-bs-interval": interval.to_s) if interval
|
|
12
12
|
add_attribute(attributes) unless attributes.empty?
|
|
13
|
+
add_content(content) if content
|
|
13
14
|
end
|
|
14
15
|
end
|
|
15
16
|
end
|
|
@@ -6,7 +6,7 @@ require_relative "carousel/caption"
|
|
|
6
6
|
module ElementComponent
|
|
7
7
|
module Components
|
|
8
8
|
class Carousel < Element
|
|
9
|
-
def initialize(id: "carousel", fade: false, indicators: true, controls: true, **attributes, &block)
|
|
9
|
+
def initialize(content = nil, id: "carousel", fade: false, indicators: true, controls: true, **attributes, &block)
|
|
10
10
|
@carousel_id = id
|
|
11
11
|
@show_indicators = indicators
|
|
12
12
|
@show_controls = controls
|
|
@@ -17,6 +17,7 @@ module ElementComponent
|
|
|
17
17
|
add_attribute(class: "slide")
|
|
18
18
|
add_attribute(class: "carousel-fade") if fade
|
|
19
19
|
add_attribute(attributes) unless attributes.empty?
|
|
20
|
+
add_content(content) if content
|
|
20
21
|
end
|
|
21
22
|
|
|
22
23
|
private
|
|
@@ -3,11 +3,12 @@
|
|
|
3
3
|
module ElementComponent
|
|
4
4
|
module Components
|
|
5
5
|
class DropdownHeader < Element
|
|
6
|
-
def initialize(**attributes, &)
|
|
6
|
+
def initialize(content = nil, **attributes, &)
|
|
7
7
|
super("li", &)
|
|
8
8
|
|
|
9
9
|
inner = Element.new("h6", class: "dropdown-header", **attributes)
|
|
10
10
|
@inner_header = inner
|
|
11
|
+
add_content(content) if content
|
|
11
12
|
end
|
|
12
13
|
|
|
13
14
|
private
|
|
@@ -5,7 +5,7 @@ module ElementComponent
|
|
|
5
5
|
class DropdownItem < Element
|
|
6
6
|
VALID_TYPES = %i[button link].freeze
|
|
7
7
|
|
|
8
|
-
def initialize(type: :link, href: "#", active: false, disabled: false, **attributes, &block)
|
|
8
|
+
def initialize(content = nil, type: :link, href: "#", active: false, disabled: false, **attributes, &block)
|
|
9
9
|
tag = type == :button ? "button" : "a"
|
|
10
10
|
super("li", &block)
|
|
11
11
|
|
|
@@ -19,6 +19,7 @@ module ElementComponent
|
|
|
19
19
|
inner.add_content(&block) if block
|
|
20
20
|
|
|
21
21
|
@inner_item = inner
|
|
22
|
+
add_content(content) if content
|
|
22
23
|
end
|
|
23
24
|
|
|
24
25
|
private
|
|
@@ -3,12 +3,13 @@
|
|
|
3
3
|
module ElementComponent
|
|
4
4
|
module Components
|
|
5
5
|
class DropdownMenu < Element
|
|
6
|
-
def initialize(align: nil, **attributes, &block)
|
|
6
|
+
def initialize(content = nil, align: nil, **attributes, &block)
|
|
7
7
|
super("ul", &block)
|
|
8
8
|
|
|
9
9
|
add_attribute(class: "dropdown-menu")
|
|
10
10
|
add_attribute(class: "dropdown-menu-#{align}") if align
|
|
11
11
|
add_attribute(attributes) unless attributes.empty?
|
|
12
|
+
add_content(content) if content
|
|
12
13
|
end
|
|
13
14
|
end
|
|
14
15
|
end
|
|
@@ -10,12 +10,13 @@ module ElementComponent
|
|
|
10
10
|
class Dropdown < Element
|
|
11
11
|
VALID_DIRECTIONS = %i[dropup dropend dropstart].freeze
|
|
12
12
|
|
|
13
|
-
def initialize(direction: nil, **attributes, &block)
|
|
13
|
+
def initialize(content = nil, direction: nil, **attributes, &block)
|
|
14
14
|
super("div", &block)
|
|
15
15
|
|
|
16
16
|
add_attribute(class: "dropdown")
|
|
17
17
|
add_attribute(class: direction.to_s) if direction
|
|
18
18
|
add_attribute(attributes) unless attributes.empty?
|
|
19
|
+
add_content(content) if content
|
|
19
20
|
end
|
|
20
21
|
|
|
21
22
|
def toggle_button(label: "Dropdown", variant: :secondary, split: false, **btn_attributes, &block)
|
|
@@ -5,7 +5,7 @@ module ElementComponent
|
|
|
5
5
|
class ListGroupItem < Element
|
|
6
6
|
VALID_VARIANTS = %i[primary secondary success danger warning info light dark].freeze
|
|
7
7
|
|
|
8
|
-
def initialize(variant: nil, active: false, disabled: false, href: nil, **attributes, &block)
|
|
8
|
+
def initialize(content = nil, variant: nil, active: false, disabled: false, href: nil, **attributes, &block)
|
|
9
9
|
tag = href ? "a" : "li"
|
|
10
10
|
super(tag, &block)
|
|
11
11
|
|
|
@@ -17,6 +17,7 @@ module ElementComponent
|
|
|
17
17
|
add_attribute(href: href) if href
|
|
18
18
|
add_attribute("aria-current": "true") if active
|
|
19
19
|
add_attribute(attributes) unless attributes.empty?
|
|
20
|
+
add_content(content) if content
|
|
20
21
|
end
|
|
21
22
|
end
|
|
22
23
|
end
|
|
@@ -5,13 +5,14 @@ require_relative "list_group/item"
|
|
|
5
5
|
module ElementComponent
|
|
6
6
|
module Components
|
|
7
7
|
class ListGroup < Element
|
|
8
|
-
def initialize(flush: false, numbered: false, **attributes, &block)
|
|
8
|
+
def initialize(content = nil, flush: false, numbered: false, **attributes, &block)
|
|
9
9
|
super("ul", &block)
|
|
10
10
|
|
|
11
11
|
add_attribute(class: "list-group")
|
|
12
12
|
add_attribute(class: "list-group-flush") if flush
|
|
13
13
|
add_attribute(class: "list-group-numbered") if numbered
|
|
14
14
|
add_attribute(attributes) unless attributes.empty?
|
|
15
|
+
add_content(content) if content
|
|
15
16
|
end
|
|
16
17
|
end
|
|
17
18
|
end
|
|
@@ -3,11 +3,12 @@
|
|
|
3
3
|
module ElementComponent
|
|
4
4
|
module Components
|
|
5
5
|
class ModalBody < Element
|
|
6
|
-
def initialize(**attributes, &)
|
|
6
|
+
def initialize(content = nil, **attributes, &)
|
|
7
7
|
super("div", &)
|
|
8
8
|
|
|
9
9
|
add_attribute(class: "modal-body")
|
|
10
10
|
add_attribute(attributes) unless attributes.empty?
|
|
11
|
+
add_content(content) if content
|
|
11
12
|
end
|
|
12
13
|
end
|
|
13
14
|
end
|
|
@@ -3,11 +3,12 @@
|
|
|
3
3
|
module ElementComponent
|
|
4
4
|
module Components
|
|
5
5
|
class ModalContent < Element
|
|
6
|
-
def initialize(**attributes, &)
|
|
6
|
+
def initialize(content = nil, **attributes, &)
|
|
7
7
|
super("div", &)
|
|
8
8
|
|
|
9
9
|
add_attribute(class: "modal-content")
|
|
10
10
|
add_attribute(attributes) unless attributes.empty?
|
|
11
|
+
add_content(content) if content
|
|
11
12
|
end
|
|
12
13
|
end
|
|
13
14
|
end
|
|
@@ -6,7 +6,7 @@ module ElementComponent
|
|
|
6
6
|
VALID_SIZES = %i[sm lg xl].freeze
|
|
7
7
|
VALID_FULLSCREEN = %i[always sm md lg xl xxl].freeze
|
|
8
8
|
|
|
9
|
-
def initialize(scrollable: false, centered: false, size: nil, fullscreen: nil, **attributes, &block)
|
|
9
|
+
def initialize(content = nil, scrollable: false, centered: false, size: nil, fullscreen: nil, **attributes, &block)
|
|
10
10
|
super("div", &block)
|
|
11
11
|
|
|
12
12
|
add_attribute(class: "modal-dialog")
|
|
@@ -15,6 +15,7 @@ module ElementComponent
|
|
|
15
15
|
add_attribute(class: "modal-#{size}") if size
|
|
16
16
|
add_attribute(class: "modal-fullscreen#{"-#{fullscreen}-down" unless fullscreen == :always}") if fullscreen
|
|
17
17
|
add_attribute(attributes) unless attributes.empty?
|
|
18
|
+
add_content(content) if content
|
|
18
19
|
end
|
|
19
20
|
end
|
|
20
21
|
end
|
|
@@ -3,11 +3,12 @@
|
|
|
3
3
|
module ElementComponent
|
|
4
4
|
module Components
|
|
5
5
|
class ModalFooter < Element
|
|
6
|
-
def initialize(**attributes, &)
|
|
6
|
+
def initialize(content = nil, **attributes, &)
|
|
7
7
|
super("div", &)
|
|
8
8
|
|
|
9
9
|
add_attribute(class: "modal-footer")
|
|
10
10
|
add_attribute(attributes) unless attributes.empty?
|
|
11
|
+
add_content(content) if content
|
|
11
12
|
end
|
|
12
13
|
end
|
|
13
14
|
end
|
|
@@ -3,12 +3,13 @@
|
|
|
3
3
|
module ElementComponent
|
|
4
4
|
module Components
|
|
5
5
|
class ModalHeader < Element
|
|
6
|
-
def initialize(close_button: true, **attributes, &block)
|
|
6
|
+
def initialize(content = nil, close_button: true, **attributes, &block)
|
|
7
7
|
super("div", &block)
|
|
8
8
|
|
|
9
9
|
add_attribute(class: "modal-header")
|
|
10
10
|
add_attribute(attributes) unless attributes.empty?
|
|
11
11
|
|
|
12
|
+
add_content(content) if content
|
|
12
13
|
add_content(CloseButton.new) if close_button
|
|
13
14
|
end
|
|
14
15
|
end
|
|
@@ -3,11 +3,12 @@
|
|
|
3
3
|
module ElementComponent
|
|
4
4
|
module Components
|
|
5
5
|
class ModalTitle < Element
|
|
6
|
-
def initialize(**attributes, &)
|
|
6
|
+
def initialize(content = nil, **attributes, &)
|
|
7
7
|
super("h5", &)
|
|
8
8
|
|
|
9
9
|
add_attribute(class: "modal-title")
|
|
10
10
|
add_attribute(attributes) unless attributes.empty?
|
|
11
|
+
add_content(content) if content
|
|
11
12
|
end
|
|
12
13
|
end
|
|
13
14
|
end
|
|
@@ -3,11 +3,12 @@
|
|
|
3
3
|
module ElementComponent
|
|
4
4
|
module Components
|
|
5
5
|
class NavItem < Element
|
|
6
|
-
def initialize(**attributes, &)
|
|
6
|
+
def initialize(content = nil, **attributes, &)
|
|
7
7
|
super("li", &)
|
|
8
8
|
|
|
9
9
|
add_attribute(class: "nav-item")
|
|
10
10
|
add_attribute(attributes) unless attributes.empty?
|
|
11
|
+
add_content(content) if content
|
|
11
12
|
end
|
|
12
13
|
end
|
|
13
14
|
end
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
module ElementComponent
|
|
4
4
|
module Components
|
|
5
5
|
class NavLink < Element
|
|
6
|
-
def initialize(href: "#", active: false, disabled: false, **attributes, &block)
|
|
6
|
+
def initialize(content = nil, href: "#", active: false, disabled: false, **attributes, &block)
|
|
7
7
|
super("a", &block)
|
|
8
8
|
|
|
9
9
|
add_attribute(class: "nav-link")
|
|
@@ -12,6 +12,7 @@ module ElementComponent
|
|
|
12
12
|
add_attribute(href: href)
|
|
13
13
|
add_attribute("aria-current": "page") if active
|
|
14
14
|
add_attribute(attributes) unless attributes.empty?
|
|
15
|
+
add_content(content) if content
|
|
15
16
|
end
|
|
16
17
|
end
|
|
17
18
|
end
|
|
@@ -8,7 +8,7 @@ module ElementComponent
|
|
|
8
8
|
class Nav < Element
|
|
9
9
|
VALID_TYPES = %i[tabs pills underline].freeze
|
|
10
10
|
|
|
11
|
-
def initialize(type: nil, fill: false, justified: false, vertical: false, **attributes, &block)
|
|
11
|
+
def initialize(content = nil, type: nil, fill: false, justified: false, vertical: false, **attributes, &block)
|
|
12
12
|
super("ul", &block)
|
|
13
13
|
|
|
14
14
|
add_attribute(class: "nav")
|
|
@@ -17,6 +17,7 @@ module ElementComponent
|
|
|
17
17
|
add_attribute(class: "nav-justified") if justified
|
|
18
18
|
add_attribute(class: "flex-column") if vertical
|
|
19
19
|
add_attribute(attributes) unless attributes.empty?
|
|
20
|
+
add_content(content) if content
|
|
20
21
|
end
|
|
21
22
|
end
|
|
22
23
|
end
|
|
@@ -3,12 +3,13 @@
|
|
|
3
3
|
module ElementComponent
|
|
4
4
|
module Components
|
|
5
5
|
class NavbarBrand < Element
|
|
6
|
-
def initialize(href: "#", **attributes, &block)
|
|
6
|
+
def initialize(content = nil, href: "#", **attributes, &block)
|
|
7
7
|
super("a", &block)
|
|
8
8
|
|
|
9
9
|
add_attribute(class: "navbar-brand")
|
|
10
10
|
add_attribute(href: href)
|
|
11
11
|
add_attribute(attributes) unless attributes.empty?
|
|
12
|
+
add_content(content) if content
|
|
12
13
|
end
|
|
13
14
|
end
|
|
14
15
|
end
|
|
@@ -3,13 +3,14 @@
|
|
|
3
3
|
module ElementComponent
|
|
4
4
|
module Components
|
|
5
5
|
class NavbarCollapse < Element
|
|
6
|
-
def initialize(id: nil, **attributes, &block)
|
|
6
|
+
def initialize(content = nil, id: nil, **attributes, &block)
|
|
7
7
|
super("div", &block)
|
|
8
8
|
|
|
9
9
|
add_attribute(class: "collapse")
|
|
10
10
|
add_attribute(class: "navbar-collapse")
|
|
11
11
|
add_attribute(id: id) if id
|
|
12
12
|
add_attribute(attributes) unless attributes.empty?
|
|
13
|
+
add_content(content) if content
|
|
13
14
|
end
|
|
14
15
|
end
|
|
15
16
|
end
|
|
@@ -3,11 +3,12 @@
|
|
|
3
3
|
module ElementComponent
|
|
4
4
|
module Components
|
|
5
5
|
class NavbarNav < Element
|
|
6
|
-
def initialize(**attributes, &)
|
|
6
|
+
def initialize(content = nil, **attributes, &)
|
|
7
7
|
super("ul", &)
|
|
8
8
|
|
|
9
9
|
add_attribute(class: "navbar-nav")
|
|
10
10
|
add_attribute(attributes) unless attributes.empty?
|
|
11
|
+
add_content(content) if content
|
|
11
12
|
end
|
|
12
13
|
end
|
|
13
14
|
end
|
|
@@ -13,7 +13,7 @@ module ElementComponent
|
|
|
13
13
|
VALID_FIXED = %i[top bottom].freeze
|
|
14
14
|
VALID_STICKY = %i[top bottom].freeze
|
|
15
15
|
|
|
16
|
-
def initialize(expand: :lg, theme: :light, background: nil, fixed: nil, sticky: nil, container: true, **attributes,
|
|
16
|
+
def initialize(content = nil, expand: :lg, theme: :light, background: nil, fixed: nil, sticky: nil, container: true, **attributes,
|
|
17
17
|
&block)
|
|
18
18
|
super("nav", &block)
|
|
19
19
|
|
|
@@ -26,6 +26,7 @@ module ElementComponent
|
|
|
26
26
|
add_attribute(attributes) unless attributes.empty?
|
|
27
27
|
|
|
28
28
|
@use_container = container
|
|
29
|
+
add_content(content) if content
|
|
29
30
|
end
|
|
30
31
|
|
|
31
32
|
private
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
module ElementComponent
|
|
4
4
|
module Components
|
|
5
5
|
class PageItem < Element
|
|
6
|
-
def initialize(active: false, disabled: false, href: "#", **attributes, &block)
|
|
6
|
+
def initialize(content = nil, active: false, disabled: false, href: "#", **attributes, &block)
|
|
7
7
|
super("li", &block)
|
|
8
8
|
|
|
9
9
|
add_attribute(class: "page-item")
|
|
@@ -14,6 +14,7 @@ module ElementComponent
|
|
|
14
14
|
|
|
15
15
|
@page_href = href
|
|
16
16
|
@page_disabled = disabled
|
|
17
|
+
add_content(content) if content
|
|
17
18
|
end
|
|
18
19
|
|
|
19
20
|
private
|
|
@@ -7,12 +7,13 @@ module ElementComponent
|
|
|
7
7
|
class Pagination < Element
|
|
8
8
|
VALID_SIZES = %i[sm lg].freeze
|
|
9
9
|
|
|
10
|
-
def initialize(size: nil, **attributes, &block)
|
|
10
|
+
def initialize(content = nil, size: nil, **attributes, &block)
|
|
11
11
|
@pagination_size = size
|
|
12
12
|
super("nav", &block)
|
|
13
13
|
|
|
14
14
|
add_attribute("aria-label": "Pagination")
|
|
15
15
|
add_attribute(attributes) unless attributes.empty?
|
|
16
|
+
add_content(content) if content
|
|
16
17
|
end
|
|
17
18
|
|
|
18
19
|
private
|
|
@@ -5,7 +5,7 @@ module ElementComponent
|
|
|
5
5
|
class ProgressBar < Element
|
|
6
6
|
VALID_VARIANTS = %i[primary secondary success danger warning info light dark].freeze
|
|
7
7
|
|
|
8
|
-
def initialize(value: 0, variant: nil, striped: false, animated: false, **attributes, &block)
|
|
8
|
+
def initialize(content = nil, value: 0, variant: nil, striped: false, animated: false, **attributes, &block)
|
|
9
9
|
super("div", &block)
|
|
10
10
|
|
|
11
11
|
add_attribute(class: "progress-bar")
|
|
@@ -18,6 +18,7 @@ module ElementComponent
|
|
|
18
18
|
add_attribute("aria-valuemax": "100")
|
|
19
19
|
add_attribute(style: "width: #{value}%")
|
|
20
20
|
add_attribute(attributes) unless attributes.empty?
|
|
21
|
+
add_content(content) if content
|
|
21
22
|
end
|
|
22
23
|
end
|
|
23
24
|
end
|
|
@@ -5,12 +5,13 @@ require_relative "progress/bar"
|
|
|
5
5
|
module ElementComponent
|
|
6
6
|
module Components
|
|
7
7
|
class Progress < Element
|
|
8
|
-
def initialize(**attributes, &)
|
|
8
|
+
def initialize(content = nil, **attributes, &)
|
|
9
9
|
super("div", &)
|
|
10
10
|
|
|
11
11
|
add_attribute(class: "progress")
|
|
12
12
|
add_attribute(role: "progressbar")
|
|
13
13
|
add_attribute(attributes) unless attributes.empty?
|
|
14
|
+
add_content(content) if content
|
|
14
15
|
end
|
|
15
16
|
end
|
|
16
17
|
end
|
|
@@ -6,13 +6,14 @@ module ElementComponent
|
|
|
6
6
|
VALID_VARIANTS = %i[primary secondary success danger warning info light dark].freeze
|
|
7
7
|
VALID_TYPES = %i[border grow].freeze
|
|
8
8
|
|
|
9
|
-
def initialize(type: :border, variant: nil, **attributes, &block)
|
|
9
|
+
def initialize(content = nil, type: :border, variant: nil, **attributes, &block)
|
|
10
10
|
super("div", &block)
|
|
11
11
|
|
|
12
12
|
add_attribute(class: "spinner-#{type}")
|
|
13
13
|
add_attribute(class: "text-#{variant}") if variant
|
|
14
14
|
add_attribute(role: "status")
|
|
15
15
|
add_attribute(attributes) unless attributes.empty?
|
|
16
|
+
add_content(content) if content
|
|
16
17
|
end
|
|
17
18
|
end
|
|
18
19
|
end
|
|
@@ -5,7 +5,7 @@ module ElementComponent
|
|
|
5
5
|
class Table < Element
|
|
6
6
|
VALID_VARIANTS = %i[primary secondary success danger warning info light dark].freeze
|
|
7
7
|
|
|
8
|
-
def initialize(striped: false, bordered: false, hover: false, small: false, variant: nil, **attributes, &block)
|
|
8
|
+
def initialize(content = nil, striped: false, bordered: false, hover: false, small: false, variant: nil, **attributes, &block)
|
|
9
9
|
super("table", &block)
|
|
10
10
|
|
|
11
11
|
add_attribute(class: "table")
|
|
@@ -15,6 +15,7 @@ module ElementComponent
|
|
|
15
15
|
add_attribute(class: "table-sm") if small
|
|
16
16
|
add_attribute(class: "table-#{variant}") if variant
|
|
17
17
|
add_attribute(attributes) unless attributes.empty?
|
|
18
|
+
add_content(content) if content
|
|
18
19
|
end
|
|
19
20
|
end
|
|
20
21
|
end
|
data/lib/element_component.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: element_component
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.12.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- João Paulo Correia
|
|
@@ -40,6 +40,7 @@ files:
|
|
|
40
40
|
- examples/spinner_example.rb
|
|
41
41
|
- examples/table_example.rb
|
|
42
42
|
- lib/element_component.rb
|
|
43
|
+
- lib/element_component/aliases.rb
|
|
43
44
|
- lib/element_component/components.rb
|
|
44
45
|
- lib/element_component/components/alert.rb
|
|
45
46
|
- lib/element_component/components/alert/close_button.rb
|