-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Docs and demos for breadcrumbs and UJS
- Loading branch information
Showing
27 changed files
with
765 additions
and
52 deletions.
There are no files selected for viewing
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
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,54 @@ | ||
/** | ||
* Base class for custom elements, providing support for event delegation, and idempotent | ||
* customElement registration. | ||
* | ||
* The `handleEvent` method is called any time an event defined in `delegatedEvents` is triggered. | ||
* It's a central handler to handle events for this custom element. | ||
* | ||
* @example | ||
* class MyComponent extends CustomElement { | ||
* static componentName = 'my-component' | ||
* static delegatedEvents = ['click'] | ||
* | ||
* handleEvent(event) { | ||
* console.log('Hello, world!') | ||
* } | ||
* } | ||
* MyComponent.register() | ||
*/ | ||
export default class CustomElement extends HTMLElement { | ||
/** | ||
* Register the component as a custom element, inferring the component name from the kebab-cased | ||
* class name. You can override the component name by setting a static `componentName` property. | ||
* | ||
* This method is idempotent. | ||
*/ | ||
static register() { | ||
if (this.componentName === undefined) { | ||
this.componentName = this.name | ||
.replaceAll(/(.)([A-Z])/g, "$1-$2") | ||
.toLowerCase(); | ||
} | ||
|
||
if (!customElements.get(this.componentName)) { | ||
customElements.define(this.componentName, this); | ||
} | ||
} | ||
|
||
/** | ||
* A list of event types to be delegated for the lifetime of the custom element. | ||
* | ||
* @type {Array} | ||
*/ | ||
static delegatedEvents = []; | ||
|
||
constructor() { | ||
super(); | ||
|
||
if (typeof this.handleEvent !== "undefined") { | ||
this.constructor.delegatedEvents?.forEach((event) => { | ||
this.addEventListener(event, this); | ||
}); | ||
} | ||
} | ||
} |
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
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,15 @@ | ||
.base { | ||
margin: 10px 20px; | ||
|
||
legend { | ||
background-color: blanchedalmond; | ||
padding: 5px 10px; | ||
font-size: 0.7em; | ||
color: dimgray; | ||
width: fit-content; | ||
} | ||
|
||
pre { | ||
margin: 0; | ||
} | ||
} |
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,35 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'phlex/testing/view_helper' | ||
|
||
class CodeBlockComponent < ApplicationComponent | ||
FORMATTER = Rouge::Formatters::HTML.new | ||
|
||
attribute :syntax, _Nilable(_Union(String, Symbol)), positional: true | ||
|
||
def template(&block) | ||
@code = capture(&block) | ||
@code = HtmlBeautifier.beautify(@code) if @syntax == :html | ||
|
||
div class: :@base do | ||
legend { @syntax } | ||
pre class: :highlight, data: data do | ||
@syntax ? unsafe_raw(FORMATTER.format(lexer.lex(@code))) : @code | ||
end | ||
end | ||
end | ||
|
||
private | ||
|
||
def data | ||
{ language: @syntax, lines: lines } | ||
end | ||
|
||
def lines | ||
@code.scan("\n").count + 1 | ||
end | ||
|
||
def lexer | ||
Rouge::Lexer.find(@syntax) | ||
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,9 @@ | ||
.base { | ||
margin: 20px; | ||
|
||
> div { | ||
border: 1px ridge; | ||
background-color: snow; | ||
padding: 30px; | ||
} | ||
} |
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,9 @@ | ||
# frozen_string_literal: true | ||
|
||
class CodeStageComponent < ApplicationComponent | ||
def template(&block) | ||
div class: :@base do | ||
div(&block) | ||
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 |
---|---|---|
@@ -1,5 +1,6 @@ | ||
# frozen_string_literal: true | ||
|
||
class ApplicationController < ActionController::Base | ||
include Phlexible::Rails::ActionController::ImplicitRender | ||
layout false | ||
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 |
---|---|---|
@@ -1,13 +1,12 @@ | ||
# frozen_string_literal: true | ||
|
||
class UI::BreadcrumbsController < UIController | ||
include Proscenium::UI::Breadcrumbs::Control | ||
|
||
def index | ||
add_breadcrumb 'Proscenium UI', :ui | ||
add_breadcrumb 'Components', :ui | ||
module UI | ||
class BreadcrumbsController < UIController | ||
include Proscenium::UI::Breadcrumbs::Control | ||
add_breadcrumb 'Breadcrumbs' | ||
|
||
render UI::Breadcrumbs::IndexView.new | ||
def index | ||
render Breadcrumbs::IndexView.new | ||
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,19 @@ | ||
# frozen_string_literal: true | ||
|
||
module UI | ||
class UJSController < UIController | ||
add_breadcrumb 'UJS', :ui_ujs | ||
|
||
def index | ||
render UJS::IndexView.new | ||
end | ||
|
||
def confirm | ||
add_breadcrumb 'confirm' | ||
end | ||
|
||
def disable_with | ||
add_breadcrumb 'disable_with' | ||
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
Oops, something went wrong.