Skip to content

Commit

Permalink
chore: Reducing number of sizes and cleaning up previews
Browse files Browse the repository at this point in the history
  • Loading branch information
joshsadam committed Oct 23, 2024
1 parent 1aea921 commit 7c81e8a
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 78 deletions.
6 changes: 4 additions & 2 deletions embedded_gems/flowbite/app/components/flowbite/button.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@ class Button < Flowbite::Component
include Flowbite::ButtonSizes

# rubocop:disable Metrics/ParameterLists
def initialize(base_button_class: Flowbite::BaseButton, scheme: DEFAULT_SCHEME, size: DEFAULT_SIZE,
def initialize(base_button_class: Flowbite::BaseButton, scheme: DEFAULT_SCHEME, size: DEFAULT_SIZE, block: false,
disabled: false, label_wrap: false, **system_arguments)
@base_button_class = base_button_class
@scheme = scheme
@label_wrap = label_wrap
@size = size
@block = block

@system_arguments = system_arguments
@system_arguments[:disabled] = disabled
Expand All @@ -28,7 +29,8 @@ def initialize(base_button_class: Flowbite::BaseButton, scheme: DEFAULT_SCHEME,
system_arguments[:classes],
SCHEME_MAPPINGS[fetch_or_fallback(SCHEME_OPTIONS, scheme, DEFAULT_SCHEME)],
SIZE_MAPPINGS[fetch_or_fallback(SIZE_OPTIONS, size, DEFAULT_SIZE)],
'rounded-lg font-medium focus:outline-none focus:ring-4 disabled:opacity-50 disabled:cursor-not-allowed'
'rounded-lg font-medium focus:outline-none focus:ring-4 disabled:opacity-50 disabled:cursor-not-allowed',
'block w-full' => block
)
end

Expand Down
3 changes: 2 additions & 1 deletion embedded_gems/flowbite/app/lib/flowbite/button_schemes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module Flowbite
# This module contains methods for generating and managing button schemes.
module ButtonSchemes
# Default color scheme for buttons
DEFAULT_SCHEME = :light
DEFAULT_SCHEME = :default

# Generates a CSS class string for a button scheme
#
Expand Down Expand Up @@ -45,6 +45,7 @@ def self.generate_scheme_mappings
alternative: generate_scheme('gray', 'gray-900', 'white', '100', '800', border: true),
dark: generate_scheme('slate', 'white', '700', '300', '700'),
light: generate_scheme('slate', 'slate-900', 'white', '100', '800', border: true),
default: generate_scheme('slate', 'slate-900', 'white', '100', '800', border: true),
green: generate_scheme('green', 'white', '600', '300', '500'),
red: generate_scheme('red', 'white', '600', '300', '500'),
yellow: generate_scheme('yellow', 'slate-900', '300', '300', '300'),
Expand Down
9 changes: 3 additions & 6 deletions embedded_gems/flowbite/app/lib/flowbite/button_sizes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,12 @@ module Flowbite
# This module contains methods for generating and managing button sizes.
module ButtonSizes
# Default size for buttons
DEFAULT_SIZE = :default
DEFAULT_SIZE = :medium

# A hash of predefined button size mappings
SIZE_MAPPINGS = {
extra_small: 'px-3 py-2 text-xs',
small: 'px-3 py-2 text-sm',
default: 'px-5 py-2.5 text-sm',
large: 'px-5 py-3 text-base',
extra_large: 'px-6 py-3.5 text-base'
small: 'px-3 py-2 text-xs',
medium: 'px-3 py-2 text-sm'
}.freeze
SIZE_OPTIONS = SIZE_MAPPINGS.keys
end
Expand Down
5 changes: 1 addition & 4 deletions embedded_gems/flowbite/app/lib/flowbite/button_visuals.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,8 @@ module Flowbite
module ButtonVisuals
# A hash of predefined icon size mappings
ICON_SIZE_MAPPINGS = {
extra_small: 'w-3 h-3',
small: 'w-3 h-3',
default: 'w-3.5 h-3.5',
large: 'w-4 h-4',
extra_large: 'w-4 h-4'
medium: 'w-3 h-3'
}.freeze

def self.included(base)
Expand Down
4 changes: 2 additions & 2 deletions embedded_gems/flowbite/lib/flowbite/classify.rb
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ def validated_class_names(classes)
# TODO: This needs to be reworked for our purposes
if invalid_class_names.any?
raise ArgumentError, 'Use System Arguments (https://primer.style/view-components/system-arguments) ' \
"instead of Primer CSS class #{'name'.pluralize(invalid_class_names.length)} #{invalid_class_names.to_sentence}. " \
'This warning will not be raised in production. Set PRIMER_WARNINGS_DISABLED=1 to disable this warning.'
"instead of Flowbite CSS class #{'name'.pluralize(invalid_class_names.length)} #{invalid_class_names.to_sentence}. " \

Check warning on line 123 in embedded_gems/flowbite/lib/flowbite/classify.rb

View workflow job for this annotation

GitHub Actions / runner / rubocop

[rubocop] reported by reviewdog 🐶 Line is too long. [151/120] Raw Output: embedded_gems/flowbite/lib/flowbite/classify.rb:123:121: C: Layout/LineLength: Line is too long. [151/120]
'This warning will not be raised in production. Set FLOWBITE_WARNINGS_DISABLED=1 to disable this warning.'

Check warning on line 124 in embedded_gems/flowbite/lib/flowbite/classify.rb

View workflow job for this annotation

GitHub Actions / runner / rubocop

[rubocop] reported by reviewdog 🐶 Line is too long. [139/120] Raw Output: embedded_gems/flowbite/lib/flowbite/classify.rb:124:121: C: Layout/LineLength: Line is too long. [139/120]
end
end

Expand Down
18 changes: 17 additions & 1 deletion test/components/previews/flowbite_button_preview.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,23 @@
# frozen_string_literal: true

class FlowbiteButtonPreview < ViewComponent::Preview
def default_button; end
# @param scheme select { choices: [default,primary, blue, alternative, dark, light, green, red, purple, yellow] } "The color scheme of the button."
# @param size select { choices: [small, medium] } "The size of the button."
# @param disabled toggle "The Boolean disabled attribute, when present, makes the element not mutable, focusable, or even submitted with the form. The user can neither edit nor focus on the control, nor its form control descendants."
# @param block toggle "If true, the button will take up the full width of its container."
def playground(scheme: :default, size: :medium, disabled: false, block: false)
render Flowbite::Button.new(scheme:, size:, disabled:, block:) do
'Button'
end
end

# @param disabled toggle "The Boolean disabled attribute, when present, makes the element not mutable, focusable, or even submitted with the form. The user can neither edit nor focus on the control, nor its form control descendants."
def default(disabled: false)
render Flowbite::Button.new(disabled:) do
'Button'
end
end

def button_sizes; end
def button_sizes_with_icon; end
def buttons_with_icons; end
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<%= render Flowbite::Button.new(disabled:) do %>
Button
<% end %>

This file was deleted.

0 comments on commit 7c81e8a

Please sign in to comment.