flowbite-components 0.1.4 → 0.2.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/CHANGELOG.md +14 -4
- data/README.md +23 -4
- data/app/components/flowbite/breadcrumb/home_icon.rb +28 -0
- data/app/components/flowbite/breadcrumb/item/current.rb +35 -0
- data/app/components/flowbite/breadcrumb/item/first.rb +37 -0
- data/app/components/flowbite/breadcrumb/item.rb +50 -0
- data/app/components/flowbite/breadcrumb/separator_icon.rb +34 -0
- data/app/components/flowbite/breadcrumb.rb +54 -0
- data/app/components/flowbite/button.rb +6 -5
- data/app/components/flowbite/card.rb +15 -1
- data/app/components/flowbite/input/checkbox.rb +2 -2
- data/app/components/flowbite/input/date.rb +2 -2
- data/app/components/flowbite/input/date_time.rb +11 -0
- data/app/components/flowbite/input/email.rb +2 -2
- data/app/components/flowbite/input/file.rb +2 -2
- data/app/components/flowbite/input/hint.rb +6 -1
- data/app/components/flowbite/input/label.rb +1 -1
- data/app/components/flowbite/input/number.rb +2 -2
- data/app/components/flowbite/input/password.rb +2 -2
- data/app/components/flowbite/input/phone.rb +2 -2
- data/app/components/flowbite/input/radio_button.rb +2 -2
- data/app/components/flowbite/input/select.rb +2 -2
- data/app/components/flowbite/input/textarea.rb +2 -2
- data/app/components/flowbite/input/url.rb +2 -2
- data/app/components/flowbite/input/validation_error.rb +1 -1
- data/app/components/flowbite/input.rb +155 -0
- data/app/components/flowbite/input_field/date_time.rb +13 -0
- data/app/components/flowbite/input_field/input_field.html.erb +2 -2
- data/app/components/flowbite/input_field/radio_button.rb +9 -15
- data/app/components/flowbite/input_field.rb +91 -47
- data/app/components/flowbite/link.rb +2 -0
- data/app/components/flowbite/toast/icon.html.erb +5 -0
- data/app/components/flowbite/toast/icon.rb +57 -0
- data/app/components/flowbite/toast/toast.html.erb +40 -0
- data/app/components/flowbite/toast.rb +37 -0
- data/lib/flowbite/components/version.rb +1 -1
- data/lib/yard/flowbite_viewcomponent.rb +24 -0
- metadata +33 -5
- data/app/components/flowbite/input/field.rb +0 -126
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Flowbite
|
|
4
|
-
module Input
|
|
5
|
-
# The indivdual input component for use in forms without labels or error
|
|
6
|
-
# messages.
|
|
7
|
-
#
|
|
8
|
-
# Use this when you want to render an input field on its own without any
|
|
9
|
-
# surrounding elements, ie as a building block in more complex input
|
|
10
|
-
# components.
|
|
11
|
-
#
|
|
12
|
-
# To render a complete input field with labels and error messages, use
|
|
13
|
-
# `Flowbite::InputField` instead.
|
|
14
|
-
class Field < ViewComponent::Base
|
|
15
|
-
SIZES = {
|
|
16
|
-
sm: ["px-2.5", "py-2", "text-sm"],
|
|
17
|
-
default: ["px-3", "py-2.5", "text-sm"],
|
|
18
|
-
lg: ["px-3.5", "py-3", "text-base"]
|
|
19
|
-
}.freeze
|
|
20
|
-
|
|
21
|
-
STATES = [
|
|
22
|
-
DEFAULT = :default,
|
|
23
|
-
DISABLED = :disabled,
|
|
24
|
-
ERROR = :error
|
|
25
|
-
].freeze
|
|
26
|
-
|
|
27
|
-
attr_reader :options, :size, :style
|
|
28
|
-
|
|
29
|
-
class << self
|
|
30
|
-
def classes(size: :default, state: :default, style: :default)
|
|
31
|
-
style = styles.fetch(style)
|
|
32
|
-
state_classes = style.fetch(state)
|
|
33
|
-
state_classes + sizes.fetch(size)
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
# Returns the sizes this Field supports.
|
|
37
|
-
#
|
|
38
|
-
# This is effectively the SIZES constant, but provided as a method to
|
|
39
|
-
# return the constant from the current class, not the superclass.
|
|
40
|
-
#
|
|
41
|
-
# @return [Hash] A hash mapping size names to their corresponding CSS
|
|
42
|
-
# classes.
|
|
43
|
-
def sizes
|
|
44
|
-
const_get(:SIZES)
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
# rubocop:disable Layout/LineLength
|
|
48
|
-
def styles
|
|
49
|
-
Flowbite::Styles.from_hash(
|
|
50
|
-
{
|
|
51
|
-
default: {
|
|
52
|
-
default: ["bg-neutral-secondary-medium", "border", "border-default-medium", "text-heading", "rounded-base", "focus:ring-brand", "focus:border-brand", "block", "w-full", "shadow-xs", "placeholder:text-body"],
|
|
53
|
-
disabled: ["bg-neutral-secondary-medium", "border", "border-default-medium", "text-fg-disabled", "rounded-base", "focus:ring-brand", "focus:border-brand", "block", "w-full", "shadow-xs", "cursor-not-allowed", "placeholder:text-fg-disabled"],
|
|
54
|
-
error: ["bg-danger-soft", "border", "border-danger-subtle", "text-fg-danger-strong", "rounded-base", "focus:ring-danger", "focus:border-danger", "block", "w-full", "shadow-xs", "placeholder:text-fg-danger-strong"]
|
|
55
|
-
}
|
|
56
|
-
}.freeze
|
|
57
|
-
)
|
|
58
|
-
end
|
|
59
|
-
# rubocop:enable Layout/LineLength
|
|
60
|
-
end
|
|
61
|
-
|
|
62
|
-
def initialize(attribute:, form:, class: nil, disabled: false, options: {}, size: :default)
|
|
63
|
-
@attribute = attribute
|
|
64
|
-
@class = Array.wrap(binding.local_variable_get(:class))
|
|
65
|
-
@disabled = disabled
|
|
66
|
-
@form = form
|
|
67
|
-
@options = options || {}
|
|
68
|
-
@object = form.object
|
|
69
|
-
@size = size
|
|
70
|
-
end
|
|
71
|
-
|
|
72
|
-
# Returns the HTML to use for the actual input field element.
|
|
73
|
-
def call
|
|
74
|
-
@form.send(
|
|
75
|
-
input_field_type,
|
|
76
|
-
@attribute,
|
|
77
|
-
**input_options
|
|
78
|
-
)
|
|
79
|
-
end
|
|
80
|
-
|
|
81
|
-
# Returns the CSS classes to apply to the input field
|
|
82
|
-
def classes
|
|
83
|
-
self.class.classes(size: size, state: state) + @class
|
|
84
|
-
end
|
|
85
|
-
|
|
86
|
-
# Returns the name of the method used to generate HTML for the input field
|
|
87
|
-
def input_field_type
|
|
88
|
-
:text_field
|
|
89
|
-
end
|
|
90
|
-
|
|
91
|
-
protected
|
|
92
|
-
|
|
93
|
-
# Returns true if the field is disabled
|
|
94
|
-
def disabled?
|
|
95
|
-
!!@disabled
|
|
96
|
-
end
|
|
97
|
-
|
|
98
|
-
# Returns true if the object has errors. Returns false if there is no
|
|
99
|
-
# object.
|
|
100
|
-
#
|
|
101
|
-
# @return [Boolean] true if there are errors, false otherwise.
|
|
102
|
-
def errors?
|
|
103
|
-
return false unless @object
|
|
104
|
-
|
|
105
|
-
@object.errors.include?(@attribute.intern)
|
|
106
|
-
end
|
|
107
|
-
|
|
108
|
-
private
|
|
109
|
-
|
|
110
|
-
# Returns the options argument for the input field
|
|
111
|
-
def input_options
|
|
112
|
-
{
|
|
113
|
-
class: classes,
|
|
114
|
-
disabled: disabled?
|
|
115
|
-
}.merge(options)
|
|
116
|
-
end
|
|
117
|
-
|
|
118
|
-
def state
|
|
119
|
-
return DISABLED if disabled?
|
|
120
|
-
return ERROR if errors?
|
|
121
|
-
|
|
122
|
-
DEFAULT
|
|
123
|
-
end
|
|
124
|
-
end
|
|
125
|
-
end
|
|
126
|
-
end
|