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 398eeaf
Show file tree
Hide file tree
Showing 10 changed files with 106 additions and 1 deletion.
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 DragHandle component

<!-- Changed components: Primer::OpenProject::DragHandle -->
6 changes: 6 additions & 0 deletions app/components/primer/open_project/drag_handle.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_handle.pcss
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/* CSS for DragHandle */

.DragHandle {
cursor: move;
color: var(--fgColor-muted);
}
28 changes: 28 additions & 0 deletions app/components/primer/open_project/drag_handle.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 DragHandle < 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::DragHandle::DEFAULT_SIZE, **system_arguments)
@system_arguments = system_arguments
@system_arguments[:tag] = "div"
@system_arguments[:classes] =
class_names(
@system_arguments[:classes],
"DragHandle"
)

@size = fetch_or_fallback(Primer::OpenProject::DragHandle::SIZE_OPTIONS, size, Primer::OpenProject::DragHandle::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_handle.pcss";
23 changes: 23 additions & 0 deletions previews/primer/open_project/drag_handle_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 DragHandle
class DragHandlePreview < ViewComponent::Preview
# @label Default
# @snapshot
def default(size: :small)
render(Primer::OpenProject::DragHandle.new(size: size))
end

# @label Playground
# @param size [Symbol] select [xsmall, small, medium]
def playground(size: :small)
render(Primer::OpenProject::DragHandle.new(size: size))
end
end
end
end
5 changes: 4 additions & 1 deletion static/classes.json
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,9 @@
"Counter--secondary": [
"Primer::Beta::Counter"
],
"DragHandle": [
"Primer::OpenProject::DragHandle"
],
"FormControl": [
"Primer::Alpha::TextField"
],
Expand Down Expand Up @@ -618,4 +621,4 @@
"UnderlineNav-octicon": [
"Primer::Alpha::UnderlineNav"
]
}
}
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::DragHandle, {}],
[Primer::OpenProject::PageHeader, {}, proc { |component|
component.with_title { "Foo" }
}],
Expand Down
19 changes: 19 additions & 0 deletions test/components/primer/open_project/drag_handle_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 PrimerOpenProjectDragHandleTest < Minitest::Test
include Primer::ComponentTestHelpers

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

assert_selector(".DragHandle .octicon")
end

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

assert_selector(".DragHandle .octicon[width='24']")
end
end
11 changes: 11 additions & 0 deletions test/system/open_project/drag_handle_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 IntegrationOpenProjectDragHandleTest < System::TestCase
def test_renders_component
visit_preview(:default)

assert_selector(".DragHandle")
end
end

0 comments on commit 398eeaf

Please sign in to comment.