Skip to content

Commit

Permalink
Add DragHandlerComponent
Browse files Browse the repository at this point in the history
  • Loading branch information
HDinger committed Sep 18, 2023
1 parent 20b9b93 commit 9a138c8
Show file tree
Hide file tree
Showing 10 changed files with 105 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .changeset/unlucky-buses-knock.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@openproject/primer-view-components': minor
---

Add DragHandler component

<!-- Changed components: Primer::OpenProject::DragHandler -->
6 changes: 6 additions & 0 deletions app/components/primer/open_project/drag_handler.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<%= render Primer::BaseComponent.new(**@system_arguments) do %>
<%= render(Primer::Beta::Octicon.new(
icon: :grabber,
size: @size
)) %>
<% end %>
6 changes: 6 additions & 0 deletions app/components/primer/open_project/drag_handler.pcss
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/* CSS for DragHandler */

.DragHandler {
cursor: move;
color: var(--fgColor-muted);
}
28 changes: 28 additions & 0 deletions app/components/primer/open_project/drag_handler.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# frozen_string_literal: true

module Primer
module OpenProject
# Add a general description of component here
# Add additional usage considerations or best practices that may aid the user to use the component correctly.
# @accessibility Add any accessibility considerations
class DragHandler < Primer::Component
status :open_project

DEFAULT_SIZE = Primer::Beta::Octicon::SIZE_DEFAULT
SIZE_OPTIONS = Primer::Beta::Octicon::SIZE_OPTIONS

# @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
def initialize(size: Primer::OpenProject::DragHandler::DEFAULT_SIZE, **system_arguments)
@system_arguments = system_arguments
@system_arguments[:tag] = "div"
@system_arguments[:classes] =
class_names(
@system_arguments[:classes],
"DragHandler"
)

@size = fetch_or_fallback(Primer::OpenProject::DragHandler::SIZE_OPTIONS, size, Primer::OpenProject::DragHandler::DEFAULT_SIZE)
end
end
end
end
1 change: 1 addition & 0 deletions app/components/primer/primer.pcss
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,4 @@

/* OP specifics */
@import "./open_project/page_header.pcss";
@import "./open_project/drag_handler.pcss";
23 changes: 23 additions & 0 deletions previews/primer/open_project/drag_handler_preview.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# frozen_string_literal: true

# Setup Playground to use all available component props
# Setup Features to use individual component props and combinations

module Primer
module OpenProject
# @label DragHandler
class DragHandlerPreview < ViewComponent::Preview
# @label Default
# @snapshot
def default(size: :small)
render(Primer::OpenProject::DragHandler.new(size: size))
end

# @label Playground
# @param size [Symbol] select [xsmall, small, medium]
def playground(size: :small)
render(Primer::OpenProject::DragHandler.new(size: size))
end
end
end
end
3 changes: 3 additions & 0 deletions static/classes.json
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,9 @@
"Counter--secondary": [
"Primer::Beta::Counter"
],
"DragHandler": [
"Primer::OpenProject::DragHandler"
],
"FormControl": [
"Primer::Alpha::TextField"
],
Expand Down
1 change: 1 addition & 0 deletions test/components/component_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class PrimerComponentTest < Minitest::Test

# Components with any arguments necessary to make them render
COMPONENTS_WITH_ARGS = [
[Primer::OpenProject::DragHandler, {}],
[Primer::OpenProject::PageHeader, {}, proc { |component|
component.with_title { "Foo" }
}],
Expand Down
19 changes: 19 additions & 0 deletions test/components/primer/open_project/drag_handler_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# frozen_string_literal: true

require "components/test_helper"

class PrimerOpenProjectDragHandlerTest < Minitest::Test
include Primer::ComponentTestHelpers

def test_renders
render_inline(Primer::OpenProject::DragHandler.new)

assert_selector(".DragHandler .octicon")
end

def test_renders_larger_icon
render_inline(Primer::OpenProject::DragHandler.new(size: :medium))

assert_selector(".DragHandler .octicon[width='24']")
end
end
11 changes: 11 additions & 0 deletions test/system/open_project/drag_handler_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# frozen_string_literal: true

require "system/test_case"

class IntegrationOpenProjectDragHandlerTest < System::TestCase
def test_renders_component
visit_preview(:default)

assert_selector(".DragHandler")
end
end

0 comments on commit 9a138c8

Please sign in to comment.