loco_motion-rails 0.0.8 → 0.4.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 -13
- data/app/components/daisy/data_input/checkbox_component.rb +92 -0
- data/app/components/daisy/data_input/file_input_component.rb +92 -0
- data/app/components/daisy/data_input/label_component.rb +84 -0
- data/app/components/daisy/data_input/radio_button_component.rb +87 -0
- data/app/components/daisy/data_input/range_component.rb +95 -0
- data/app/components/daisy/data_input/rating_component.html.haml +13 -0
- data/app/components/daisy/data_input/rating_component.rb +138 -0
- data/app/components/daisy/data_input/select_component.html.haml +15 -0
- data/app/components/daisy/data_input/select_component.rb +178 -0
- data/app/components/daisy/data_input/text_area_component.rb +124 -0
- data/app/components/daisy/data_input/text_input_component.html.haml +6 -0
- data/app/components/daisy/data_input/text_input_component.rb +140 -0
- data/app/components/daisy/data_input/toggle_component.rb +36 -0
- data/app/helpers/daisy/form_builder_helper.rb +159 -0
- data/lib/daisy.rb +5 -0
- data/lib/loco_motion/base_component.rb +9 -2
- data/lib/loco_motion/engine.rb +6 -0
- data/lib/loco_motion/helpers.rb +12 -0
- data/lib/loco_motion/version.rb +1 -1
- metadata +32 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 767e282b6b6bdd3838a976a9ee4b75e2b89d0e42282955076b00ffa9de3c092b
|
4
|
+
data.tar.gz: d87d11791dee9d2b92d1273d39f7eebbeffd9ff20b947ba208ae48692497d45d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 949e31fa02cbf137771872b6c35c3abfc1ccbaebe065ae74076693a2b19861bd274bb00c55688c7d688dd4e92f01ae72886e9945a7b95d1f634bde95d4b67f87
|
7
|
+
data.tar.gz: 2072ec0b0557723d23df2d1b41af5aaa48e786f81a95715e29833aa9b33cb3b78e90a4625568756f33ec5cfcbb3624e681518aa66a329f6c38003f91791741fb
|
data/README.md
CHANGED
@@ -6,19 +6,45 @@ ViewComponent, TailwindCSS, DaisyUI and more!
|
|
6
6
|
|
7
7
|
<img src="//loco-motion-docs.profoundry.us/images/loco-chats.png" width="500px" style="border: 1px solid #bbb; padding: 2px; border-radius: 10px;">
|
8
8
|
|
9
|
-
|
9
|
+
<!-- omit from toc -->
|
10
|
+
## DISCLAIMER / CURRENT STATUS
|
10
11
|
|
11
12
|
This project is in active development and many changes occur with every release!
|
12
|
-
|
13
|
-
|
14
|
-
to
|
13
|
+
|
14
|
+
We've added a very basic / untested version of all DaisyUI 4 components. While
|
15
|
+
we originally intended to take some time to flesh out and attempt to use these
|
16
|
+
components, with the recent release of Tailwind 4 and DaisyUI 5, we feel our
|
17
|
+
time is best spent updating all of the components and dependencies for these
|
18
|
+
new releases.
|
19
|
+
|
20
|
+
This means that we will **NOT** be making any bug fixes to the current branch
|
21
|
+
(0.4.0), and will instead include any bug fixes / improvements into the 0.5.0
|
22
|
+
branch which will also upgrade to Tailwind 4 and DaisyUI 5.
|
23
|
+
|
24
|
+
- Current Release **(0.4.0)** - Works with DaisyUI 4 and Tailwind 3
|
25
|
+
- Next Release **(0.5.0)** - Will work with DaisyUI 5 and Tailwind 4
|
26
|
+
|
27
|
+
<!-- omit from toc -->
|
28
|
+
## Additional Notes
|
29
|
+
|
30
|
+
### DataInput Components
|
31
|
+
|
32
|
+
Many of the DataInput elements (file input, text input, select dropdown, etc)
|
33
|
+
were built rather hastily so that we would have a base version to start from.
|
34
|
+
|
35
|
+
However, the new DaisyUI 5 components are implemented in a much cleaner way and
|
36
|
+
we didn't want to invest too much time building these out and making them more
|
37
|
+
ideal since we're about to change them.
|
38
|
+
|
39
|
+
### Hosting / Sites
|
15
40
|
|
16
41
|
We expect to settle on and purchase a real domain name in the near future, but
|
17
42
|
for the time being, the latest documentation is available at the links below.
|
18
43
|
|
19
|
-
- [
|
20
|
-
- [
|
21
|
-
|
44
|
+
- [Latest Release][1]
|
45
|
+
- [Main / Staging][3]
|
46
|
+
|
47
|
+
### Getting Help
|
22
48
|
|
23
49
|
Please reach out by opening an
|
24
50
|
[Issue](https://github.com/profoundry-us/loco_motion/issues) if you've found a
|
@@ -47,6 +73,8 @@ your solution is aligned with our goals.
|
|
47
73
|
- [Install](#install)
|
48
74
|
- [Using Components](#using-components)
|
49
75
|
- [Developing](#developing)
|
76
|
+
- [Contributing](#contributing)
|
77
|
+
- [Releasing](#releasing)
|
50
78
|
- [Tooling](#tooling)
|
51
79
|
- [TODO / Next Steps](#todo--next-steps)
|
52
80
|
|
@@ -856,6 +884,20 @@ See the `Makefile` for all available commands.
|
|
856
884
|
> make demo-restart
|
857
885
|
> ```
|
858
886
|
|
887
|
+
### Contributing
|
888
|
+
|
889
|
+
If you're interested in contributing to LocoMotion, please check out our
|
890
|
+
[CONTRIBUTING guide](docs/dev_guides/CONTRIBUTING.md) which provides detailed
|
891
|
+
information about the contribution process, code standards, documentation
|
892
|
+
requirements, and testing procedures.
|
893
|
+
|
894
|
+
### Releasing
|
895
|
+
|
896
|
+
For core team members who need to release new versions of LocoMotion, please
|
897
|
+
refer to our [RELEASING guide](docs/dev_guides/RELEASING.md) for step-by-step
|
898
|
+
instructions on version updates, building, testing, and publishing both the Ruby
|
899
|
+
gem and NPM package.
|
900
|
+
|
859
901
|
### Tooling
|
860
902
|
|
861
903
|
For VSCode, you may want to add the following to your settings to get
|
@@ -919,9 +961,9 @@ the GitHub Discussions feature and let us know!
|
|
919
961
|
- [x] Basic versions of DaisyUI Data Display
|
920
962
|
- [x] Basic versions of DaisyUI Navigation
|
921
963
|
- [x] Basic versions of DaisyUI Feedback
|
922
|
-
- [
|
923
|
-
- [
|
924
|
-
- [
|
964
|
+
- [x] Basic versions of DaisyUI Data Input
|
965
|
+
- [x] Basic versions of DaisyUI Layout
|
966
|
+
- [x] Basic versions of DaisyUI Mockup
|
925
967
|
- [x] ~~Get YARD docs rendering with (better) Markdown~~ _**Working for now**_
|
926
968
|
- [x] Extract relevant pieces into a yard-loco_motion plugin
|
927
969
|
- [x] Publish Gem
|
@@ -932,9 +974,9 @@ the GitHub Discussions feature and let us know!
|
|
932
974
|
- [ ] Choose, recommend, and document a pagination gem
|
933
975
|
- [ ] Discuss caching techniques / setup
|
934
976
|
- [x] Create / publish a staging version of the demo site ([Demo Staging][2])
|
935
|
-
- [
|
936
|
-
- [
|
937
|
-
- [
|
977
|
+
- [x] Create / publish a staging version of the docs site
|
978
|
+
- [x] Create / publish a production version of the demo site
|
979
|
+
- [x] Create / publish a production version of the docs site
|
938
980
|
- [x] Update demo site to allow for a different docs site using ENV var
|
939
981
|
- [x] Update README to suggest Playwright
|
940
982
|
- [ ] Build some have docs / guides / examples for using playwright-ruby-client
|
@@ -946,6 +988,7 @@ the GitHub Discussions feature and let us know!
|
|
946
988
|
- [ ] See if we can update the Join component to auto-add the `join-item` CSS
|
947
989
|
under certain conditions
|
948
990
|
- [ ] Add title and description content_for blocks to all examples for SEO purposes
|
991
|
+
- [ ] Update to Tailwind 4 and DaisyUI 5
|
949
992
|
|
950
993
|
[1]: https://loco-motion.profoundry.us/
|
951
994
|
[2]: https://loco-motion-demo-staging.profoundry.us/
|
@@ -0,0 +1,92 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
#
|
4
|
+
# The Checkbox component renders a DaisyUI styled checkbox input.
|
5
|
+
# It can be used standalone or with a form builder, and supports various styling
|
6
|
+
# options including toggle mode for switch-like appearance.
|
7
|
+
#
|
8
|
+
# @loco_example Basic Usage
|
9
|
+
# = daisy_checkbox(name: "accept", id: "accept")
|
10
|
+
#
|
11
|
+
# @loco_example Checked Checkbox
|
12
|
+
# = daisy_checkbox(name: "accept", id: "accept", checked: true)
|
13
|
+
#
|
14
|
+
# @loco_example Toggle Checkbox
|
15
|
+
# = daisy_checkbox(name: "accept", id: "accept", toggle: true)
|
16
|
+
#
|
17
|
+
# @loco_example Disabled Checkbox
|
18
|
+
# = daisy_checkbox(name: "accept", id: "accept", disabled: true)
|
19
|
+
#
|
20
|
+
class Daisy::DataInput::CheckboxComponent < LocoMotion::BaseComponent
|
21
|
+
attr_reader :name, :id, :value, :checked, :toggle, :disabled, :required
|
22
|
+
|
23
|
+
#
|
24
|
+
# Instantiate a new Checkbox component.
|
25
|
+
#
|
26
|
+
# @param kws [Hash] The keyword arguments for the component.
|
27
|
+
#
|
28
|
+
# @option kws name [String] The name attribute for the checkbox input.
|
29
|
+
#
|
30
|
+
# @option kws id [String] The ID attribute for the checkbox input.
|
31
|
+
#
|
32
|
+
# @option kws value [String] The value attribute for the checkbox input.
|
33
|
+
# Defaults to "1".
|
34
|
+
#
|
35
|
+
# @option kws checked [Boolean] Whether the checkbox is checked. Defaults to
|
36
|
+
# false.
|
37
|
+
#
|
38
|
+
# @option kws toggle [Boolean] Whether the checkbox should be styled as a
|
39
|
+
# toggle switch. Defaults to false.
|
40
|
+
#
|
41
|
+
# @option kws disabled [Boolean] Whether the checkbox is disabled. Defaults to
|
42
|
+
# false.
|
43
|
+
#
|
44
|
+
# @option kws required [Boolean] Whether the checkbox is required for form
|
45
|
+
# validation. Defaults to false.
|
46
|
+
#
|
47
|
+
def initialize(**kws)
|
48
|
+
super
|
49
|
+
|
50
|
+
@name = config_option(:name)
|
51
|
+
@id = config_option(:id)
|
52
|
+
@value = config_option(:value, "1")
|
53
|
+
@checked = config_option(:checked, false)
|
54
|
+
@toggle = config_option(:toggle, false)
|
55
|
+
@disabled = config_option(:disabled, false)
|
56
|
+
@required = config_option(:required, false)
|
57
|
+
end
|
58
|
+
|
59
|
+
#
|
60
|
+
# Calls the {setup_component} method before rendering the component.
|
61
|
+
#
|
62
|
+
def before_render
|
63
|
+
setup_component
|
64
|
+
end
|
65
|
+
|
66
|
+
#
|
67
|
+
# Sets up the component by configuring the tag name, CSS classes, and HTML
|
68
|
+
# attributes.
|
69
|
+
#
|
70
|
+
def setup_component
|
71
|
+
set_tag_name(:component, :input)
|
72
|
+
|
73
|
+
add_css(:component, @toggle ? "toggle" : "checkbox")
|
74
|
+
|
75
|
+
add_html(:component, {
|
76
|
+
type: "checkbox",
|
77
|
+
name: @name,
|
78
|
+
id: @id,
|
79
|
+
value: @value,
|
80
|
+
checked: @checked,
|
81
|
+
disabled: @disabled,
|
82
|
+
required: @required
|
83
|
+
})
|
84
|
+
end
|
85
|
+
|
86
|
+
#
|
87
|
+
# Renders the component inline with no additional whitespace.
|
88
|
+
#
|
89
|
+
def call
|
90
|
+
part(:component)
|
91
|
+
end
|
92
|
+
end
|
@@ -0,0 +1,92 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
#
|
4
|
+
# The FileInput component renders a DaisyUI styled file input.
|
5
|
+
# It can be used standalone or with a form builder, and supports
|
6
|
+
# various styling options including different sizes and variants.
|
7
|
+
#
|
8
|
+
# @loco_example Basic Usage
|
9
|
+
# = daisy_file_input(name: "document", id: "document")
|
10
|
+
#
|
11
|
+
# @loco_example With Accept Attribute
|
12
|
+
# = daisy_file_input(name: "image", id: "image", accept: "image/*")
|
13
|
+
#
|
14
|
+
# @loco_example With Multiple Files
|
15
|
+
# = daisy_file_input(name: "documents[]", id: "documents", multiple: true)
|
16
|
+
#
|
17
|
+
# @loco_example Disabled File Input
|
18
|
+
# = daisy_file_input(name: "document", id: "document", disabled: true)
|
19
|
+
#
|
20
|
+
class Daisy::DataInput::FileInputComponent < LocoMotion::BaseComponent
|
21
|
+
attr_reader :name, :id, :accept, :multiple, :disabled, :required
|
22
|
+
|
23
|
+
#
|
24
|
+
# Instantiate a new FileInput component.
|
25
|
+
#
|
26
|
+
# @param kws [Hash] The keyword arguments for the component.
|
27
|
+
#
|
28
|
+
# @option kws name [String] The name attribute for the file input.
|
29
|
+
#
|
30
|
+
# @option kws id [String] The ID attribute for the file input.
|
31
|
+
#
|
32
|
+
# @option kws accept [String] The accept attribute for the file input,
|
33
|
+
# specifying allowed file types.
|
34
|
+
#
|
35
|
+
# @option kws multiple [Boolean] Whether the file input allows multiple file
|
36
|
+
# selection. Defaults to false.
|
37
|
+
#
|
38
|
+
# @option kws disabled [Boolean] Whether the file input is disabled. Defaults to
|
39
|
+
# false.
|
40
|
+
#
|
41
|
+
# @option kws required [Boolean] Whether the file input is required for form
|
42
|
+
# validation. Defaults to false.
|
43
|
+
#
|
44
|
+
def initialize(**kws)
|
45
|
+
super
|
46
|
+
|
47
|
+
@name = config_option(:name)
|
48
|
+
@id = config_option(:id)
|
49
|
+
@accept = config_option(:accept, nil)
|
50
|
+
@multiple = config_option(:multiple, false)
|
51
|
+
@disabled = config_option(:disabled, false)
|
52
|
+
@required = config_option(:required, false)
|
53
|
+
end
|
54
|
+
|
55
|
+
#
|
56
|
+
# Calls the {setup_component} method before rendering the component.
|
57
|
+
#
|
58
|
+
def before_render
|
59
|
+
setup_component
|
60
|
+
end
|
61
|
+
|
62
|
+
#
|
63
|
+
# Sets up the component by configuring the tag name, CSS classes, and HTML
|
64
|
+
# attributes. Sets the tag to input with type 'file' and adds the 'file-input'
|
65
|
+
# CSS class.
|
66
|
+
#
|
67
|
+
# This configures the name, id, accept attribute, multiple state, disabled state,
|
68
|
+
# and required state of the file input.
|
69
|
+
#
|
70
|
+
def setup_component
|
71
|
+
set_tag_name(:component, :input)
|
72
|
+
|
73
|
+
add_css(:component, "file-input")
|
74
|
+
|
75
|
+
add_html(:component, {
|
76
|
+
type: "file",
|
77
|
+
name: @name,
|
78
|
+
id: @id,
|
79
|
+
accept: @accept,
|
80
|
+
multiple: @multiple,
|
81
|
+
disabled: @disabled,
|
82
|
+
required: @required
|
83
|
+
})
|
84
|
+
end
|
85
|
+
|
86
|
+
#
|
87
|
+
# Renders the component inline with no additional whitespace.
|
88
|
+
#
|
89
|
+
def call
|
90
|
+
part(:component)
|
91
|
+
end
|
92
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
#
|
4
|
+
# The Label component renders a DaisyUI styled label for form inputs.
|
5
|
+
# It can be used with any form input component and provides visual styling
|
6
|
+
# consistent with other Daisy UI elements.
|
7
|
+
#
|
8
|
+
# @loco_example Basic Usage
|
9
|
+
# = daisy_label(for: "input_id") do
|
10
|
+
# My Label
|
11
|
+
#
|
12
|
+
# @loco_example With Label Title
|
13
|
+
# = daisy_label(for: "input_id", title: "My Label")
|
14
|
+
#
|
15
|
+
# @loco_example Required Label
|
16
|
+
# = daisy_label(for: "input_id", required: true) do
|
17
|
+
# My Required Label
|
18
|
+
#
|
19
|
+
class Daisy::DataInput::LabelComponent < LocoMotion::BaseComponent
|
20
|
+
attr_reader :for, :title, :required
|
21
|
+
|
22
|
+
#
|
23
|
+
# Instantiate a new Label component.
|
24
|
+
#
|
25
|
+
# @param kws [Hash] The keyword arguments for the component.
|
26
|
+
#
|
27
|
+
# @option kws for [String] The ID of the input element this label is for.
|
28
|
+
# This connects the label to its associated form control for accessibility.
|
29
|
+
#
|
30
|
+
# @option kws title [String] The text content of the label. If not provided,
|
31
|
+
# the content block will be used. If a content block is provided, it will
|
32
|
+
# take precedence over the title option.
|
33
|
+
#
|
34
|
+
# @option kws required [Boolean] Whether the label is for a required input.
|
35
|
+
# Defaults to false.
|
36
|
+
#
|
37
|
+
def initialize(**kws)
|
38
|
+
super
|
39
|
+
|
40
|
+
@for = config_option(:for)
|
41
|
+
@title = config_option(:title)
|
42
|
+
@required = config_option(:required, false)
|
43
|
+
end
|
44
|
+
|
45
|
+
#
|
46
|
+
# Calls the {setup_component} method before rendering the component.
|
47
|
+
#
|
48
|
+
def before_render
|
49
|
+
setup_component
|
50
|
+
end
|
51
|
+
|
52
|
+
#
|
53
|
+
# Sets up the component by configuring the tag name, CSS classes, and HTML
|
54
|
+
# attributes. Sets the tag to 'label' and adds the 'label' CSS class.
|
55
|
+
#
|
56
|
+
# This configures the 'for' attribute to connect the label to its input and
|
57
|
+
# adds appropriate styling for required inputs when needed.
|
58
|
+
#
|
59
|
+
def setup_component
|
60
|
+
set_tag_name(:component, :label)
|
61
|
+
|
62
|
+
add_css(:component, "label")
|
63
|
+
|
64
|
+
add_html(:component, {
|
65
|
+
for: @for
|
66
|
+
})
|
67
|
+
end
|
68
|
+
|
69
|
+
#
|
70
|
+
# Renders the component with its content.
|
71
|
+
#
|
72
|
+
def call
|
73
|
+
part(:component) do
|
74
|
+
if content?
|
75
|
+
content
|
76
|
+
elsif @title
|
77
|
+
content_tag(:span, @title, class: "label-text")
|
78
|
+
else
|
79
|
+
# Fallback to empty content
|
80
|
+
""
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
#
|
4
|
+
# The Radio Button component renders a DaisyUI styled radio button input.
|
5
|
+
# It can be used standalone or with a form builder, and is ideal for creating
|
6
|
+
# option groups where users must select exactly one choice.
|
7
|
+
#
|
8
|
+
# @loco_example Basic Usage
|
9
|
+
# = daisy_radio(name: "option", id: "option1", value: "1")
|
10
|
+
#
|
11
|
+
# @loco_example Checked Radio Button
|
12
|
+
# = daisy_radio(name: "option", id: "option2", value: "2", checked: true)
|
13
|
+
#
|
14
|
+
# @loco_example Disabled Radio Button
|
15
|
+
# = daisy_radio(name: "option", id: "option3", value: "3", disabled: true)
|
16
|
+
#
|
17
|
+
class Daisy::DataInput::RadioButtonComponent < LocoMotion::BaseComponent
|
18
|
+
attr_reader :name, :id, :value, :checked, :disabled, :required
|
19
|
+
|
20
|
+
#
|
21
|
+
# Instantiate a new Radio Button component.
|
22
|
+
#
|
23
|
+
# @param kws [Hash] The keyword arguments for the component.
|
24
|
+
#
|
25
|
+
# @option kws name [String] The name attribute for the radio button input.
|
26
|
+
#
|
27
|
+
# @option kws id [String] The ID attribute for the radio button input.
|
28
|
+
#
|
29
|
+
# @option kws value [String] The value attribute for the radio button input.
|
30
|
+
#
|
31
|
+
# @option kws checked [Boolean] Whether the radio button is checked. Defaults to
|
32
|
+
# false.
|
33
|
+
#
|
34
|
+
# @option kws disabled [Boolean] Whether the radio button is disabled. Defaults to
|
35
|
+
# false.
|
36
|
+
#
|
37
|
+
# @option kws required [Boolean] Whether the radio button is required for form
|
38
|
+
# validation. Defaults to false.
|
39
|
+
#
|
40
|
+
def initialize(**kws)
|
41
|
+
super
|
42
|
+
|
43
|
+
@name = config_option(:name)
|
44
|
+
@id = config_option(:id)
|
45
|
+
@value = config_option(:value)
|
46
|
+
@checked = config_option(:checked, false)
|
47
|
+
@disabled = config_option(:disabled, false)
|
48
|
+
@required = config_option(:required, false)
|
49
|
+
end
|
50
|
+
|
51
|
+
#
|
52
|
+
# Calls the {setup_component} method before rendering the component.
|
53
|
+
#
|
54
|
+
def before_render
|
55
|
+
setup_component
|
56
|
+
end
|
57
|
+
|
58
|
+
#
|
59
|
+
# Sets up the component by configuring the tag name, CSS classes, and HTML
|
60
|
+
# attributes. Sets the tag to input with type 'radio' and adds the 'radio' CSS class.
|
61
|
+
#
|
62
|
+
# This configures the name, id, value, disabled state, required state, and
|
63
|
+
# checked state of the radio button.
|
64
|
+
#
|
65
|
+
def setup_component
|
66
|
+
set_tag_name(:component, :input)
|
67
|
+
|
68
|
+
add_css(:component, "radio")
|
69
|
+
|
70
|
+
add_html(:component, {
|
71
|
+
type: "radio",
|
72
|
+
name: @name,
|
73
|
+
id: @id,
|
74
|
+
value: @value,
|
75
|
+
checked: @checked,
|
76
|
+
disabled: @disabled,
|
77
|
+
required: @required
|
78
|
+
})
|
79
|
+
end
|
80
|
+
|
81
|
+
#
|
82
|
+
# Renders the component inline with no additional whitespace.
|
83
|
+
#
|
84
|
+
def call
|
85
|
+
part(:component)
|
86
|
+
end
|
87
|
+
end
|
@@ -0,0 +1,95 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
#
|
4
|
+
# The Range component renders a DaisyUI styled range input slider.
|
5
|
+
# It can be used standalone or with a form builder, and supports customization
|
6
|
+
# of min/max values, step increments, and color variants.
|
7
|
+
#
|
8
|
+
# @loco_example Basic Usage
|
9
|
+
# = daisy_range(name: "volume", id: "volume", min: 0, max: 100, value: 50)
|
10
|
+
#
|
11
|
+
# @loco_example Range with Steps
|
12
|
+
# = daisy_range(name: "step_range", id: "step_range", min: 0, max: 100, step: 25)
|
13
|
+
#
|
14
|
+
# @loco_example Range with Different Colors
|
15
|
+
# = daisy_range(name: "primary_range", id: "primary_range", css: "range-primary")
|
16
|
+
# = daisy_range(name: "error_range", id: "error_range", css: "range-error")
|
17
|
+
#
|
18
|
+
class Daisy::DataInput::RangeComponent < LocoMotion::BaseComponent
|
19
|
+
attr_reader :name, :id, :min, :max, :step, :value, :disabled, :required
|
20
|
+
|
21
|
+
#
|
22
|
+
# Instantiate a new Range component.
|
23
|
+
#
|
24
|
+
# @param kws [Hash] The keyword arguments for the component.
|
25
|
+
#
|
26
|
+
# @option kws name [String] The name attribute for the range input.
|
27
|
+
#
|
28
|
+
# @option kws id [String] The ID attribute for the range input.
|
29
|
+
#
|
30
|
+
# @option kws min [Integer] The minimum value (default: 0).
|
31
|
+
#
|
32
|
+
# @option kws max [Integer] The maximum value (default: 100).
|
33
|
+
#
|
34
|
+
# @option kws step [Integer] The step increment (default: 1).
|
35
|
+
#
|
36
|
+
# @option kws value [Integer] The current value (default: min).
|
37
|
+
#
|
38
|
+
# @option kws disabled [Boolean] Whether the range input is disabled. Defaults to
|
39
|
+
# false.
|
40
|
+
#
|
41
|
+
# @option kws required [Boolean] Whether the range input is required for form
|
42
|
+
# validation. Defaults to false.
|
43
|
+
#
|
44
|
+
def initialize(**kws)
|
45
|
+
super
|
46
|
+
|
47
|
+
@name = config_option(:name)
|
48
|
+
@id = config_option(:id)
|
49
|
+
@min = config_option(:min, 0)
|
50
|
+
@max = config_option(:max, 100)
|
51
|
+
@step = config_option(:step, 1)
|
52
|
+
@value = config_option(:value, @min)
|
53
|
+
@disabled = config_option(:disabled, false)
|
54
|
+
@required = config_option(:required, false)
|
55
|
+
end
|
56
|
+
|
57
|
+
#
|
58
|
+
# Calls the {setup_component} method before rendering the component.
|
59
|
+
#
|
60
|
+
def before_render
|
61
|
+
setup_component
|
62
|
+
end
|
63
|
+
|
64
|
+
#
|
65
|
+
# Sets up the component by configuring the tag name, CSS classes, and HTML
|
66
|
+
# attributes. Sets the tag to input with type 'range' and adds the 'range' CSS class.
|
67
|
+
#
|
68
|
+
# This configures the min, max, step values along with name, id, value, disabled state,
|
69
|
+
# and required state of the range input.
|
70
|
+
#
|
71
|
+
def setup_component
|
72
|
+
set_tag_name(:component, :input)
|
73
|
+
|
74
|
+
add_css(:component, "range")
|
75
|
+
|
76
|
+
add_html(:component, {
|
77
|
+
type: "range",
|
78
|
+
name: @name,
|
79
|
+
id: @id,
|
80
|
+
min: @min,
|
81
|
+
max: @max,
|
82
|
+
step: @step,
|
83
|
+
value: @value,
|
84
|
+
disabled: @disabled,
|
85
|
+
required: @required
|
86
|
+
})
|
87
|
+
end
|
88
|
+
|
89
|
+
#
|
90
|
+
# Renders the component inline with no additional whitespace.
|
91
|
+
#
|
92
|
+
def call
|
93
|
+
part(:component)
|
94
|
+
end
|
95
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
= part(:component) do
|
2
|
+
= part(:hidden_input)
|
3
|
+
|
4
|
+
- if items?
|
5
|
+
- items.each do |item|
|
6
|
+
- item.set_loco_parent(component_ref)
|
7
|
+
= item
|
8
|
+
- elsif content?
|
9
|
+
= content
|
10
|
+
- elsif star_items.present?
|
11
|
+
- star_items.each do |item|
|
12
|
+
- item.set_loco_parent(component_ref)
|
13
|
+
= render(item)
|