-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add view component and create a basic button with daisyui * replace all buttons * add badge component * adjust color * adjust card sizes
- Loading branch information
1 parent
d0f3d02
commit 83055a8
Showing
23 changed files
with
425 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# frozen_string_literal: true | ||
|
||
class ApplicationComponent < ViewComponent::Base | ||
extend Dry::Initializer | ||
attr_accessor :attributes | ||
option :display, default: proc { true } | ||
|
||
def initialize(*args, **options) | ||
super(*args, **options) | ||
defined_option_keys = self.class.dry_initializer.options.map(&:source) | ||
self.attributes = options.except(*defined_option_keys) | ||
end | ||
|
||
def render? | ||
display | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# frozen_string_literal: true | ||
|
||
class Ui::BadgeComponent < ApplicationComponent | ||
KIND_MAPPING = { | ||
neutral: "badge-neutral", | ||
primary: "badge-primary", | ||
secondary: "badge-secondary", | ||
accent: "badge-accent", | ||
info: "badge-info", | ||
success: "badge-success", | ||
warning: "badge-warning", | ||
error: "badge-error", | ||
ghost: "badge-ghost" | ||
} | ||
|
||
SIZE_MAPPING = { | ||
xs: "badge-xs", | ||
sm: "badge-sm", | ||
md: "badge-md", | ||
lg: "badge-lg" | ||
} | ||
|
||
param :text, optional: true | ||
option :kind, type: Dry::Types["coercible.symbol"].enum(*KIND_MAPPING.keys), default: proc { :primary } | ||
option :size, type: Dry::Types["coercible.symbol"].enum(*SIZE_MAPPING.keys), default: proc { :md } | ||
option :outline, type: Dry::Types["strict.bool"], default: proc { false } | ||
|
||
def call | ||
content_tag(:span, class: classes, **attributes.except(:class)) do | ||
concat content | ||
end | ||
end | ||
|
||
private | ||
|
||
def classes | ||
[component_classes, attributes[:class]].join(" ") | ||
end | ||
|
||
def component_classes | ||
class_names( | ||
"badge", | ||
KIND_MAPPING[kind], | ||
SIZE_MAPPING[size], | ||
"badge-outline": outline | ||
) | ||
end | ||
|
||
def content | ||
text.presence || super | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
# frozen_string_literal: true | ||
|
||
class Ui::ButtonComponent < ApplicationComponent | ||
KIND_MAPPING = { | ||
neutral: "btn-neutral", | ||
primary: "btn-primary", | ||
secondary: "btn-secondary", | ||
accent: "btn-accent", | ||
info: "btn-info", | ||
success: "btn-success", | ||
warning: "btn-warning", | ||
error: "btn-error", | ||
ghost: "btn-ghost", | ||
link: "btn-link" | ||
} | ||
|
||
SIZE_MAPPING = { | ||
sm: "btn-sm", | ||
md: "", | ||
lg: "btn-lg" | ||
} | ||
|
||
param :text, default: proc {} | ||
option :url, Dry::Types["coercible.string"], optional: true | ||
option :method, Dry::Types["coercible.symbol"].enum(:get, :post, :patch, :put, :delete), optional: true | ||
option :kind, type: Dry::Types["coercible.symbol"].enum(*KIND_MAPPING.keys), default: proc { :primary } | ||
option :size, type: Dry::Types["coercible.symbol"].enum(*SIZE_MAPPING.keys), default: proc { :md } | ||
option :type, type: Dry::Types["coercible.symbol"].enum(:button, :submit, :input), default: proc { :button } | ||
option :disabled, type: Dry::Types["strict.bool"], default: proc { false } | ||
option :outline, type: Dry::Types["strict.bool"], default: proc { false } | ||
option :animation, type: Dry::Types["strict.bool"], default: proc { false } | ||
|
||
def call | ||
case button_kind | ||
when :link | ||
link_to(url, disabled: disabled, class: classes, **attributes.except(:class, :type)) { content } | ||
when :button_to | ||
button_to(url, disabled: disabled, method: method, class: classes, **attributes.except(:class, :type)) { content } | ||
when :button | ||
tag.button(type: type, disabled: disabled, class: classes, **attributes.except(:class, :type)) { content } | ||
end | ||
end | ||
|
||
private | ||
|
||
def classes | ||
[component_classes, attributes[:class]].join(" ") | ||
end | ||
|
||
def component_classes | ||
class_names( | ||
"btn", | ||
KIND_MAPPING[kind], | ||
SIZE_MAPPING[size], | ||
"btn-outline": outline, | ||
"btn-disabled": disabled, | ||
"no-animation": !animation # animation is disabled by default, I don't really like the effect when you enter the page | ||
) | ||
end | ||
|
||
def content | ||
text.presence || super | ||
end | ||
|
||
def button_kind | ||
return :link if url.present? && default_method? | ||
return :button_to if url.present? && !default_method? | ||
|
||
:button | ||
end | ||
|
||
def default_method? | ||
method.blank? || method == :get | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
module ViewComponentHelper | ||
UI_HELPERS = { | ||
badge: "Ui::BadgeComponent", | ||
button: "Ui::ButtonComponent" | ||
}.freeze | ||
|
||
UI_HELPERS.each do |name, component| | ||
define_method "ui_#{name}" do |*args, **kwargs, &block| | ||
render component.constantize.new(*args, **kwargs), &block | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,7 @@ | |
}, | ||
"packageManager": "[email protected]", | ||
"devDependencies": { | ||
"daisyui": "^3.9.4", | ||
"postcss-import": "^15.1.0", | ||
"postcss-nested": "^6.0.1", | ||
"prettier": "^2.8.8", | ||
|
Oops, something went wrong.