forked from primer/view_components
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3b5b110
commit f7b0f7f
Showing
13 changed files
with
157 additions
and
2 deletions.
There are no files selected for viewing
12 changes: 12 additions & 0 deletions
12
app/components/primer/open_project/zen_mode_button.html.erb
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 @@ | ||
<%= render(Primer::BaseComponent.new(tag: "zen-mode-button", **@system_arguments)) do %> | ||
<%= render( | ||
Primer::Beta::IconButton.new( | ||
scheme: :default, | ||
id: 'zenModeButton', | ||
icon: 'screen-normal', | ||
aria: { label: 'zen mode' }, | ||
autofocus: true, | ||
data: { target: "zen-mode-button.button", action: "click:zen-mode-button#performAction" } | ||
) | ||
) %> | ||
<% 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,5 @@ | ||
/* CSS for ZenModeButton */ | ||
|
||
.zen-mode-button--active { | ||
box-shadow: 0 0 3px var(--color-border-default) inset; | ||
} |
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,23 @@ | ||
# 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 ZenModeButton < Primer::Component | ||
status :open_project | ||
|
||
# @param system_arguments [Hash] <%= link_to_system_arguments_docs %> | ||
def initialize(**system_arguments) | ||
@system_arguments = system_arguments | ||
@system_arguments[:tag] = "zen-mode-button" | ||
@system_arguments[:classes] = | ||
class_names( | ||
@system_arguments[:classes], | ||
"zen-mode-button" | ||
) | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import {attr, controller, target, targets} from '@github/catalyst' | ||
import screenfull from 'screenfull'; | ||
|
||
|
||
@controller | ||
class ZenModeButtonElement extends HTMLElement { | ||
@target button: HTMLElement | ||
inZenMode = false; | ||
@attr name = 'screen-full'; | ||
|
||
private deactivateZenMode():void { | ||
this.inZenMode = false; | ||
this.button.classList.remove('zen-mode-button--active'); | ||
this.querySelector('body')?.classList.remove('zen-mode'); | ||
if (screenfull.isEnabled && screenfull.isFullscreen) { | ||
screenfull.exit(); | ||
} | ||
} | ||
|
||
private activateZenMode() { | ||
this.inZenMode = true; | ||
document.querySelector('body')?.classList.add('zen-mode'); | ||
this.button.classList.add('zen-mode-button--active'); | ||
if (screenfull.isEnabled) { | ||
screenfull.request(); | ||
} | ||
} | ||
|
||
public performAction() { | ||
if (this.inZenMode) { | ||
this.deactivateZenMode(); | ||
} else { | ||
this.activateZenMode(); | ||
} | ||
} | ||
} | ||
|
||
declare global { | ||
interface Window { | ||
ZenModeButtonElement: typeof ZenModeButtonElement | ||
} | ||
} | ||
|
||
if (!window.customElements.get('zen-mode-button')) { | ||
window.ZenModeButtonElement = ZenModeButtonElement | ||
window.customElements.define('zen-mode-button', ZenModeButtonElement) | ||
} | ||
|
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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,19 @@ | ||
# 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 ZenModeButton | ||
class ZenModeButtonPreview < ViewComponent::Preview | ||
def playground() | ||
render(Primer::OpenProject::ZenModeButton.new()) | ||
end | ||
# @label Default | ||
def default() | ||
render(Primer::OpenProject::ZenModeButton.new()) | ||
end | ||
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
13 changes: 13 additions & 0 deletions
13
test/components/primer/open_project/zen_mode_button_test.rb
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,13 @@ | ||
# frozen_string_literal: true | ||
|
||
require "components/test_helper" | ||
|
||
class PrimerOpenProjectZenModeButtonTest < Minitest::Test | ||
include Primer::ComponentTestHelpers | ||
|
||
def test_renders | ||
render_inline(Primer::OpenProject::ZenModeButton.new) | ||
|
||
assert_selector(".zen-mode-button .octicon-screen-normal") | ||
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,11 @@ | ||
# frozen_string_literal: true | ||
|
||
require "system/test_case" | ||
|
||
class IntegrationOpenProjectZenModeButtonTest < System::TestCase | ||
def test_renders_component | ||
visit_preview(:default) | ||
|
||
assert_selector(".zen-mode-button") | ||
end | ||
end |