Skip to content

Commit

Permalink
adds inactive button state
Browse files Browse the repository at this point in the history
  • Loading branch information
mperrotti committed Oct 12, 2023
1 parent 47d4c23 commit a37d8a0
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 4 deletions.
4 changes: 4 additions & 0 deletions app/components/primer/beta/base_button.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@ class BaseButton < Primer::Component
# @param type [Symbol] <%= one_of(Primer::Beta::BaseButton::TYPE_OPTIONS) %>
# @param block [Boolean] Whether button is full-width with `display: block`.
# @param disabled [Boolean] Whether or not the button is disabled. If true, this option forces `tag:` to `:button`.
# @param inactive [Boolean] Whether the button looks visually disabled, but can still accept all the same interactions as an enabled button.
# @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
def initialize(
tag: DEFAULT_TAG,
type: DEFAULT_TYPE,
block: false,
disabled: false,
inactive: false,
**system_arguments
)
@system_arguments = system_arguments
Expand All @@ -37,6 +39,8 @@ def initialize(
"btn-block" => block
)

@system_arguments[:"aria-disabled"] = true if inactive

@disabled = disabled
return unless @disabled

Expand Down
8 changes: 6 additions & 2 deletions app/components/primer/beta/button.pcss
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,15 @@
transition: none;
}

&:disabled,
&[aria-disabled='true'] {
&:disabled {
cursor: not-allowed;
box-shadow: none;
}

&[aria-disabled='true'] {
cursor: default;
box-shadow: none;
}
}

.Button-withTooltip {
Expand Down
3 changes: 3 additions & 0 deletions app/components/primer/beta/button.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,20 +100,23 @@ class Button < Primer::Component
# @param tag [Symbol] (Primer::Beta::BaseButton::DEFAULT_TAG) <%= one_of(Primer::Beta::BaseButton::TAG_OPTIONS) %>
# @param type [Symbol] (Primer::Beta::BaseButton::DEFAULT_TYPE) <%= one_of(Primer::Beta::BaseButton::TYPE_OPTIONS) %>
# @param disabled [Boolean] Whether or not the button is disabled. If true, this option forces `tag:` to `:button`.
# @param inactive [Boolean] Whether the button looks visually disabled, but can still accept all the same interactions as an enabled button.
# @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
def initialize(
scheme: DEFAULT_SCHEME,
size: DEFAULT_SIZE,
block: false,
align_content: DEFAULT_ALIGN_CONTENT,
disabled: false,
inactive: false,
**system_arguments
)
@scheme = scheme
@block = block

@system_arguments = system_arguments
@system_arguments[:disabled] = disabled
@system_arguments[:inactive] = inactive

@id = @system_arguments[:id]

Expand Down
7 changes: 5 additions & 2 deletions previews/primer/beta/button_preview.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class ButtonPreview < ViewComponent::Preview
# @param size select [small, medium, large]
# @param block toggle
# @param disabled toggle
# @param inactive toggle
# @param align_content select [center, start]
# @param tag select [a, summary, button]
def playground(
Expand All @@ -27,7 +28,8 @@ def playground(
id: "button-preview",
align_content: :center,
tag: :button,
disabled: false
disabled: false,
inactive: false
)
render(Primer::Beta::Button.new(
scheme: scheme,
Expand All @@ -36,7 +38,8 @@ def playground(
id: id,
align_content: align_content,
tag: tag,
disabled: disabled
disabled: disabled,
inactive: inactive
)) do |_c|
"Button"
end
Expand Down

0 comments on commit a37d8a0

Please sign in to comment.