turbo_material 0.3.3 → 0.3.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +55 -14
- data/Rakefile +5 -2
- data/app/assets/javascripts/turbo_material/drawer_button_controller.js +2 -1
- data/app/assets/javascripts/turbo_material/material_checkbox_controller.js +5 -3
- data/app/assets/javascripts/turbo_material/material_chips_input_controller.js +26 -16
- data/app/assets/javascripts/turbo_material/material_chips_select_controller.js +35 -21
- data/app/assets/javascripts/turbo_material/material_data_table_controller.js +1 -3
- data/app/assets/javascripts/turbo_material/material_dialog_controller.js +4 -1
- data/app/assets/javascripts/turbo_material/material_drawer_controller.js +2 -11
- data/app/assets/javascripts/turbo_material/material_input_controller.js +2 -1
- data/app/assets/javascripts/turbo_material/material_list_controller.js +2 -1
- data/app/assets/javascripts/turbo_material/material_live_form_controller.js +81 -0
- data/app/assets/javascripts/turbo_material/material_menu_button_controller.js +14 -2
- data/app/assets/javascripts/turbo_material/material_menu_surface_controller.js +2 -1
- data/app/assets/javascripts/turbo_material/material_radio_controller.js +2 -1
- data/app/assets/javascripts/turbo_material/material_ripple_controller.js +1 -0
- data/app/assets/javascripts/turbo_material/material_select_controller.js +6 -4
- data/app/assets/javascripts/turbo_material/material_switch_controller.js +4 -3
- data/app/assets/javascripts/turbo_material/material_tooltip_controller.js +2 -1
- data/app/helpers/turbo_material/application_helper.rb +1 -1
- data/app/helpers/turbo_material/tooltip_helper.rb +2 -2
- data/app/views/common/_menu_contents.html.erb +1 -1
- data/app/views/components/_chip_set.html.erb +1 -1
- data/app/views/components/_chips_input.html.erb +9 -8
- data/app/views/components/_data_table.html.erb +5 -5
- data/app/views/components/_input.html.erb +3 -4
- data/app/views/components/_menu_button.html.erb +5 -4
- data/app/views/components/_modal.html.erb +10 -9
- data/app/views/components/_radio.html.erb +16 -20
- data/app/views/components/_select.html.erb +2 -3
- data/app/views/components/_switch.html.erb +2 -2
- data/app/views/components/_textarea.html.erb +4 -4
- data/app/views/layouts/turbo_material/lookbook.html.erb +2 -2
- data/app/views/lookbook/_data_table_headers.html.erb +1 -0
- data/app/views/lookbook/_data_table_rows.html.erb +6 -0
- data/app/views/lookbook/_drawer.html.erb +16 -0
- data/app/views/lookbook/_tooltip.html.erb +7 -0
- data/config/importmap.rb +1 -1
- data/config/routes.rb +1 -0
- data/lib/generators/turbo_material/install_generator.rb +5 -7
- data/lib/lookbook/chip_set_preview.rb +7 -0
- data/lib/lookbook/chips_input_preview.rb +2 -3
- data/lib/lookbook/data_table_preview.rb +20 -0
- data/lib/lookbook/drawer_preview.rb +9 -0
- data/lib/lookbook/menu_button_preview.rb +2 -1
- data/lib/lookbook/modal_preview.rb +2 -1
- data/lib/lookbook/tooltip_preview.rb +8 -0
- data/lib/turbo_material/engine.rb +7 -25
- data/lib/turbo_material/version.rb +6 -1
- data/lib/turbo_material.rb +0 -15
- metadata +14 -6
- data/lib/turbo_material/configuration.rb +0 -7
- data/lib/turbo_material/post_install.rb +0 -10
|
@@ -2,9 +2,9 @@ import { Controller } from "@hotwired/stimulus";
|
|
|
2
2
|
|
|
3
3
|
export default class extends Controller {
|
|
4
4
|
connect() {
|
|
5
|
-
|
|
6
|
-
select.listen("MDCSelect:change", () => {
|
|
7
|
-
select.root.dispatchEvent(
|
|
5
|
+
this.select = mdc.select.MDCSelect.attachTo(this.element);
|
|
6
|
+
this.select.listen("MDCSelect:change", () => {
|
|
7
|
+
this.select.root.dispatchEvent(
|
|
8
8
|
new CustomEvent("submit-now", {
|
|
9
9
|
bubbles: true,
|
|
10
10
|
cancelable: true,
|
|
@@ -13,5 +13,7 @@ export default class extends Controller {
|
|
|
13
13
|
});
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
disconnect() {
|
|
16
|
+
disconnect() {
|
|
17
|
+
this.select?.destroy();
|
|
18
|
+
}
|
|
17
19
|
}
|
|
@@ -2,13 +2,14 @@ import { Controller } from "@hotwired/stimulus";
|
|
|
2
2
|
|
|
3
3
|
export default class extends Controller {
|
|
4
4
|
connect() {
|
|
5
|
-
|
|
5
|
+
this.switchControl = mdc.switchControl.MDCSwitch.attachTo(this.element.querySelector('.mdc-switch'));
|
|
6
6
|
const hidden = this.element.querySelector('input[type=hidden]');
|
|
7
|
-
switchControl.listen('click', () => {
|
|
8
|
-
hidden.value = switchControl.selected;
|
|
7
|
+
this.switchControl.listen('click', () => {
|
|
8
|
+
hidden.value = this.switchControl.selected;
|
|
9
9
|
});
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
disconnect() {
|
|
13
|
+
this.switchControl?.destroy();
|
|
13
14
|
}
|
|
14
15
|
}
|
|
@@ -2,9 +2,10 @@ import { Controller } from "@hotwired/stimulus";
|
|
|
2
2
|
|
|
3
3
|
export default class extends Controller {
|
|
4
4
|
connect() {
|
|
5
|
-
mdc.tooltip.MDCTooltip.attachTo(this.element);
|
|
5
|
+
this.tooltip = mdc.tooltip.MDCTooltip.attachTo(this.element);
|
|
6
6
|
}
|
|
7
7
|
|
|
8
8
|
disconnect() {
|
|
9
|
+
this.tooltip?.destroy();
|
|
9
10
|
}
|
|
10
11
|
}
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
module TurboMaterial
|
|
4
4
|
module TooltipHelper
|
|
5
|
-
def material_tooltip(kwargs = {}, &
|
|
6
|
-
content = block_given? ? capture(&
|
|
5
|
+
def material_tooltip(kwargs = {}, &)
|
|
6
|
+
content = block_given? ? capture(&) : nil
|
|
7
7
|
render 'components/tooltip', **kwargs, content: content
|
|
8
8
|
end
|
|
9
9
|
end
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
<ul class="mdc-deprecated-list mdc-deprecated-list--icon-list" role="menu" aria-
|
|
1
|
+
<ul class="mdc-deprecated-list mdc-deprecated-list--icon-list" role="menu" aria-orientation="vertical" tabindex="-1">
|
|
2
2
|
<li class="mdc-deprecated-list-item" role="menuitem">
|
|
3
3
|
<span class="mdc-deprecated-list-item__ripple"></span>
|
|
4
4
|
<span class="mdc-deprecated-list-item__icon material-icons">person</span>
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<%# locals: (chips: []) %>
|
|
2
|
-
<span class="mdc-chip-set" role="grid"
|
|
2
|
+
<span class="mdc-chip-set" role="grid">
|
|
3
3
|
<span class="mdc-chip-set__chips" role="presentation">
|
|
4
4
|
<%- chips.each do |chip| -%>
|
|
5
5
|
<%= material_chip label: chip[:label] %>
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
<%# locals: (form:, disabled: false, required: false, name:, label: nil, id:, frame: nil, suffix: nil, type: 'text', url: nil, selected: [], options: [], value: nil, fixed: false, prefetch: false, additional_query_params: {}) %>
|
|
1
|
+
<%# locals: (form:, disabled: false, required: false, name:, label: nil, id:, frame: nil, suffix: nil, type: 'text', url: nil, selected: [], options: [], value: nil, fixed: false, prefetch: false, additional_query_params: {}, autocomplete: 'off') %>
|
|
2
2
|
<%- id = [name, suffix].compact_blank.join('-') -%>
|
|
3
3
|
<div data-controller="material-chips-input"
|
|
4
4
|
data-material-chips-input-url-value="<%= url %>"
|
|
@@ -7,25 +7,26 @@
|
|
|
7
7
|
data-material-chips-input-prefetch-value="<%= prefetch.to_s %>"
|
|
8
8
|
data-material-chips-input-additional-query-params-value="<%= additional_query_params.to_json %>"
|
|
9
9
|
<% if suffix.present? %>data-material-chips-input-suffix-value="<%= suffix %>"<% end %>
|
|
10
|
-
data-action="keydown.esc->material-chips-input#close keydown.enter->prevent
|
|
10
|
+
data-action="keydown.esc->material-chips-input#close keydown.enter->material-chips-input#confirmSelection:prevent material-list:action->material-chips-input#confirmSelection"
|
|
11
11
|
>
|
|
12
12
|
<label class="mdc-text-field mdc-text-field--filled w-full h-max! h-full!">
|
|
13
13
|
<span class="mdc-text-field__ripple"></span>
|
|
14
|
-
<span class="mdc-floating-label top-6!"><%= label %></span>
|
|
14
|
+
<span id="<%= id %>-label" class="mdc-floating-label top-6!"><%= label %></span>
|
|
15
15
|
<div class="mdc-chip-set mdc-chip-set--input pt-8! w-full" role="grid">
|
|
16
16
|
<%- selected.each do |chip| -%>
|
|
17
|
-
<div class="mdc-chip">
|
|
17
|
+
<div class="mdc-chip" data-value="<%= chip[:id] %>">
|
|
18
18
|
<div class="mdc-chip__text"><%= chip[:label] %></div>
|
|
19
|
-
|
|
19
|
+
<i class="material-icons mdc-chip__icon mdc-chip__icon--trailing" tabindex="0" role="button"
|
|
20
|
+
data-action="click->material-chips-input#removeChip" data-value="<%= chip[:id] %>">cancel</i>
|
|
20
21
|
</div>
|
|
21
22
|
<%- end -%>
|
|
22
|
-
<%= form.hidden_field name.to_sym, value: value, data: { 'material-chips-input-target': 'hidden' } %>
|
|
23
|
+
<%= form.hidden_field name.to_sym, value: value || selected.map { |chip| chip[:id] }.join(','), data: { 'material-chips-input-target': 'hidden' } %>
|
|
23
24
|
<%= form.text_field "#{name}_".to_sym,
|
|
24
|
-
class: 'mdc-text-field__input', value:
|
|
25
|
+
class: 'mdc-text-field__input', value: nil,
|
|
25
26
|
id: id, 'aria-labelledby' => id + '-label',
|
|
26
27
|
required: required,
|
|
27
28
|
disabled: disabled,
|
|
28
|
-
type: type, autocomplete:
|
|
29
|
+
type: type, autocomplete: autocomplete,
|
|
29
30
|
data: { 'material-chips-input-target': 'input',
|
|
30
31
|
action: 'input->material-chips-input#search mousedown->material-chips-input#toggle keydown.down->material-chips-input#focusNext keydown.up->material-chips-input#focusPrevious keydown.enter->material-chips-input#confirmSelection keydown->material-chips-input#open' }
|
|
31
32
|
%>
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
<%# locals: (name:, table_body:, url:, table_params:, records:, selected_records:, pagy:, table_headers_partial:, table_contents_partial:) %>
|
|
1
|
+
<%# locals: (name:, table_body:, url:, table_params:, records:, selected_records:, pagy:, table_headers_partial:, table_contents_partial:, per_page_options: [10, 25, 50, 100].map { |n| { value: n, label: n.to_s } }) %>
|
|
2
2
|
<div class="mdc-data-table w-full" data-controller="material-data-table"
|
|
3
3
|
data-material-data-table-body-value="<%= table_body %>"
|
|
4
4
|
data-material-data-table-url-value="<%= url %>"
|
|
5
5
|
data-material-data-table-query-string-value="<%= table_params.to_query %>">
|
|
6
6
|
<div class="mdc-data-table__table-container">
|
|
7
|
-
<table class="mdc-data-table__table
|
|
7
|
+
<table class="mdc-data-table__table" aria-label="<%= name %>">
|
|
8
8
|
<thead>
|
|
9
9
|
<tr class="mdc-data-table__header-row">
|
|
10
10
|
<th class="mdc-data-table__header-cell mdc-data-table__header-cell--checkbox" role="columnheader" scope="col">
|
|
11
|
-
<div class="mdc-checkbox mdc-data-table__header-row-checkbox
|
|
11
|
+
<div class="mdc-checkbox mdc-data-table__header-row-checkbox">
|
|
12
12
|
<input type="checkbox" class="mdc-checkbox__native-control" aria-label="Toggle all rows"/>
|
|
13
13
|
<div class="mdc-checkbox__background">
|
|
14
14
|
<svg class="mdc-checkbox__checkmark" viewBox="0 0 24 24">
|
|
@@ -37,8 +37,8 @@
|
|
|
37
37
|
<%= form_with(url: url, method: :get, data: {
|
|
38
38
|
turbo_frame: table_body,
|
|
39
39
|
turbo_action: 'advance',
|
|
40
|
-
controller: 'live-form',
|
|
41
|
-
action: 'input->live-form#submit submit-now->live-form#submitNow' }, autocomplete: 'off') do |form| %>
|
|
40
|
+
controller: 'material-live-form',
|
|
41
|
+
action: 'input->material-live-form#submit submit-now->material-live-form#submitNow' }, autocomplete: 'off') do |form| %>
|
|
42
42
|
<% params.keys.select { |k| k.starts_with?('ransack') }.each do |key| -%>
|
|
43
43
|
<%= form.hidden_field key, value: params[key] %>
|
|
44
44
|
<%- end -%>
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
<%# locals: (form:, custom_controller: nil, custom_css: nil, disabled: false, required: false, name:, label: nil, id:, frame: nil, provide_hidden: false, value: nil, type: 'text', data: {}, min: nil, max: nil, helper: nil, parent: nil, style: 'filled', leading_icon: nil, trailing_icon: nil, leading_icon_data: {}, trailing_icon_data: {}) %>
|
|
1
|
+
<%# locals: (form:, custom_controller: nil, custom_css: nil, disabled: false, required: false, name:, label: nil, id:, frame: nil, provide_hidden: false, value: nil, type: 'text', data: {}, min: nil, max: nil, helper: nil, parent: nil, style: 'filled', leading_icon: nil, trailing_icon: nil, leading_icon_data: {}, trailing_icon_data: {}, autocomplete: nil) %>
|
|
2
2
|
<label class="mdc-text-field rounded-none <%= style == 'filled' ? 'mdc-text-field--filled' : 'mdc-text-field--outlined' %> <%= (value || form&.object&.[](name.to_sym)).present? ? 'mdc-text-field--label-floating' : '' %> w-full <%= leading_icon ? 'mdc-text-field--with-leading-icon' : '' %> <%= trailing_icon ? 'mdc-text-field--with-trailing-icon' : '' %> <%= custom_css %>"
|
|
3
3
|
data-controller="<%= custom_controller || 'material-input' %>" <% if frame %>data-frame="<%= frame %>"<% end %>>
|
|
4
4
|
<%- if style == 'filled' -%>
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
class: 'mdc-text-field__input', value: value || form&.object&.[](name.to_sym),
|
|
25
25
|
id: id, 'aria-labelledby' => id + '-label',
|
|
26
26
|
required: required, disabled: disabled,
|
|
27
|
-
type: type, autocomplete:
|
|
27
|
+
type: type, autocomplete: autocomplete, data: { frame: frame, **(data) }.compact,
|
|
28
28
|
min: min, max: max
|
|
29
29
|
%>
|
|
30
30
|
<%- if trailing_icon -%>
|
|
@@ -40,8 +40,7 @@
|
|
|
40
40
|
<div class="mdc-text-field-helper-text--validation-msg text-sm text-red-500 hidden jserror">
|
|
41
41
|
</div>
|
|
42
42
|
<%- parent&.errors&.[](name.to_sym)&.each do |msg| -%>
|
|
43
|
-
<div class="mdc-text-field-helper-text--validation-msg text-sm text-red-500"
|
|
44
|
-
aria-hidden="true">
|
|
43
|
+
<div class="mdc-text-field-helper-text--validation-msg text-sm text-red-500" role="alert">
|
|
45
44
|
<%= msg %>
|
|
46
45
|
</div>
|
|
47
46
|
<%- end -%>
|
|
@@ -11,10 +11,11 @@
|
|
|
11
11
|
</span>
|
|
12
12
|
</button>
|
|
13
13
|
<div class="mdc-menu mdc-menu-surface <%= custom_surface_css %>">
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
<%- else -%>
|
|
14
|
+
<%# block_given? is always true in a partial, so branch on the local %>
|
|
15
|
+
<%- if menu_contents_partial -%>
|
|
17
16
|
<%= render partial: menu_contents_partial %>
|
|
18
|
-
|
|
17
|
+
<%- else -%>
|
|
18
|
+
<%= yield %>
|
|
19
|
+
<%- end -%>
|
|
19
20
|
</div>
|
|
20
21
|
</div>
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
<%# locals: (title:, contents_partial: nil, cancel_button_text: 'Cancel', ok_button_text: 'OK', opened: true, dialog_surface_custom_css: '!min-w-[36rem] !min-h-[14rem]', close_action_url: nil, form: nil) %>
|
|
1
|
+
<%# locals: (title:, contents_partial: nil, cancel_button_text: 'Cancel', ok_button_text: 'OK', opened: true, dialog_surface_custom_css: '!min-w-[36rem] !min-h-[14rem]', close_action_url: nil, form: nil, id: "material-dialog-#{SecureRandom.hex(4)}", title_css: 'bg-secondary') %>
|
|
2
2
|
<div class="mdc-dialog" data-controller="material-dialog" data-material-dialog-opened-value="<%= opened %>"
|
|
3
3
|
data-material-dialog-close-action-url-value="<%= close_action_url %>">
|
|
4
4
|
<div class="mdc-dialog__container">
|
|
5
5
|
<div class="mdc-dialog__surface <%= dialog_surface_custom_css %>"
|
|
6
6
|
role="alertdialog"
|
|
7
7
|
aria-modal="true"
|
|
8
|
-
aria-labelledby="
|
|
9
|
-
aria-describedby="
|
|
10
|
-
<h2 class="mdc-dialog__title
|
|
8
|
+
aria-labelledby="<%= id %>-title"
|
|
9
|
+
aria-describedby="<%= id %>-content">
|
|
10
|
+
<h2 id="<%= id %>-title" class="mdc-dialog__title <%= title_css %>">
|
|
11
11
|
<div class="text-white! flex items-center justify-between">
|
|
12
12
|
<span><%= title %></span>
|
|
13
13
|
<button type="button" class="mdc-icon-button mdc-dialog__close" data-mdc-ripple-is-unbounded data-action="click->material-dialog#close">
|
|
@@ -17,12 +17,13 @@
|
|
|
17
17
|
</button>
|
|
18
18
|
</div>
|
|
19
19
|
</h2>
|
|
20
|
-
<div class="mdc-dialog__content">
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
<%- else -%>
|
|
20
|
+
<div id="<%= id %>-content" class="mdc-dialog__content">
|
|
21
|
+
<%# block_given? is always true in a partial, so branch on the local %>
|
|
22
|
+
<%- if contents_partial -%>
|
|
24
23
|
<%= render partial: contents_partial, locals: { form: form } %>
|
|
25
|
-
|
|
24
|
+
<%- else -%>
|
|
25
|
+
<%= yield %>
|
|
26
|
+
<%- end -%>
|
|
26
27
|
</div>
|
|
27
28
|
<div class="mdc-dialog__actions">
|
|
28
29
|
<button type="button" class="mdc-button mdc-dialog__button mdc-dialog__close" data-action="click->material-dialog#close">
|
|
@@ -1,28 +1,24 @@
|
|
|
1
|
-
<%# locals: (form:, disabled: false, required: false, name:, label: nil, id:, checked: false, value: nil, parent: nil) %>
|
|
1
|
+
<%# locals: (form:, disabled: false, required: false, name:, label: nil, id:, checked: false, value: nil, parent: nil, options: [{ value: 'true', label: 'Yes' }, { value: 'false', label: 'No' }]) %>
|
|
2
|
+
<%# ponytail: nil value selects 'false' so the default Yes/No keeps treating a blank boolean as No %>
|
|
3
|
+
<%- current = value.nil? ? 'false' : value.to_s -%>
|
|
2
4
|
<div class="mdc-form-field flex flex-col">
|
|
3
5
|
<label>
|
|
4
6
|
<%= label || name.capitalize %>
|
|
5
7
|
</label>
|
|
6
8
|
<div class="flex flex-row items-center w-full">
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
<div class="mdc-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
<%- options.each_with_index do |option, idx| -%>
|
|
10
|
+
<%- option_id = "#{id}-#{idx + 1}" -%>
|
|
11
|
+
<div class="mdc-radio <%= disabled ? 'mdc-radio--disabled' : '' %>" data-controller="material-radio">
|
|
12
|
+
<%= form.radio_button name.to_sym, option[:value], class: 'mdc-radio__native-control', id: option_id,
|
|
13
|
+
checked: option[:value].to_s == current, disabled: disabled, required: required %>
|
|
14
|
+
<div class="mdc-radio__background">
|
|
15
|
+
<div class="mdc-radio__outer-circle"></div>
|
|
16
|
+
<div class="mdc-radio__inner-circle"></div>
|
|
17
|
+
</div>
|
|
18
|
+
<div class="mdc-radio__ripple"></div>
|
|
19
|
+
<div class="mdc-radio__focus-ring"></div>
|
|
12
20
|
</div>
|
|
13
|
-
<
|
|
14
|
-
|
|
15
|
-
</div>
|
|
16
|
-
<label for="<%= id %>-1">Yes</label>
|
|
17
|
-
<div class="mdc-radio <%= disabled ? 'mdc-radio--disabled' : '' %>">
|
|
18
|
-
<%= form.radio_button name.to_sym, 'false', class: 'mdc-radio__native-control', id: id + '-2', checked: !value, disabled: disabled %>
|
|
19
|
-
<div class="mdc-radio__background">
|
|
20
|
-
<div class="mdc-radio__outer-circle"></div>
|
|
21
|
-
<div class="mdc-radio__inner-circle"></div>
|
|
22
|
-
</div>
|
|
23
|
-
<div class="mdc-radio__ripple"></div>
|
|
24
|
-
<div class="mdc-radio__focus-ring"></div>
|
|
25
|
-
</div>
|
|
26
|
-
<label for="<%= id %>-2">No</label>
|
|
21
|
+
<label for="<%= option_id %>"><%= option[:label] %></label>
|
|
22
|
+
<%- end -%>
|
|
27
23
|
</div>
|
|
28
24
|
</div>
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
<span class="mdc-notched-outline">
|
|
18
18
|
<span class="mdc-notched-outline__leading"></span>
|
|
19
19
|
<span class="mdc-notched-outline__notch">
|
|
20
|
-
<%- if label -%><span id="
|
|
20
|
+
<%- if label -%><span id="<%= id %>-label" class="mdc-floating-label"><%= label || name.capitalize %></span><%- end -%>
|
|
21
21
|
</span>
|
|
22
22
|
<span class="mdc-notched-outline__trailing"></span>
|
|
23
23
|
</span>
|
|
@@ -51,8 +51,7 @@
|
|
|
51
51
|
<div class="mdc-text-field-helper-text" aria-hidden="true"><%= helper %></div>
|
|
52
52
|
<%- end -%>
|
|
53
53
|
<%- parent&.errors&.[](name.to_sym)&.each do |msg| -%>
|
|
54
|
-
<div class="mdc-text-field-helper-text--validation-msg text-sm text-red-500"
|
|
55
|
-
aria-hidden="true">
|
|
54
|
+
<div class="mdc-text-field-helper-text--validation-msg text-sm text-red-500" role="alert">
|
|
56
55
|
<%= msg %>
|
|
57
56
|
</div>
|
|
58
57
|
<%- end -%>
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<%# locals: (form:, disabled: false, name:, label: nil, id:, value: nil, true_label: nil, false_label: nil, frame: nil) %>
|
|
2
2
|
<div data-controller="material-switch" <% if frame %> data-frame="<%= frame %>"<% end %>>
|
|
3
|
-
<button id="
|
|
3
|
+
<button id="<%= id %>"class="mdc-switch <%= cast_boolean(value) ? 'mdc-switch--selected' : '' %>"
|
|
4
4
|
type="button" role="switch" aria-checked="<%= cast_boolean(value) ? 'true' : 'false' %>" <% if disabled %>disabled<% end %>>
|
|
5
5
|
<div class="mdc-switch__track"></div>
|
|
6
6
|
<div class="mdc-switch__handle-track">
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
<div class="mdc-switch__focus-ring"></div>
|
|
24
24
|
</span>
|
|
25
25
|
</button>
|
|
26
|
-
<label for="
|
|
26
|
+
<label for="<%= id %>">
|
|
27
27
|
<% if cast_boolean(value) %>
|
|
28
28
|
<%= true_label || label %>
|
|
29
29
|
<% else %>
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
<%# locals: (form:, custom_controller: nil, custom_css: nil, disabled: false, required: false, name:, label: nil, id:, frame: nil, provide_hidden: false, value: nil, type: 'text', data: {}, rows: 8, cols: 40, maxlength: 140, helper: nil, parent: nil) %>
|
|
1
|
+
<%# locals: (form:, custom_controller: nil, custom_css: nil, disabled: false, required: false, name:, label: nil, id:, frame: nil, provide_hidden: false, value: nil, type: 'text', data: {}, rows: 8, cols: 40, maxlength: 140, helper: nil, parent: nil, autocomplete: nil) %>
|
|
2
2
|
<label class="mdc-text-field mdc-text-field--filled mdc-text-field--textarea mdc-text-field--no-label w-full! p-2"
|
|
3
3
|
data-controller="<%= custom_controller || 'material-input' %>" <% if frame %>data-frame="<%= frame %>"<% end %>>
|
|
4
4
|
<span class="mdc-notched-outline">
|
|
@@ -8,8 +8,8 @@
|
|
|
8
8
|
|
|
9
9
|
<%= form.text_area provide_hidden ? "#{name}_".to_sym : name.to_sym,
|
|
10
10
|
class: 'mdc-text-field__input', value: value || form&.object&.[](name.to_sym),
|
|
11
|
-
id: id, 'aria-
|
|
12
|
-
autocomplete:
|
|
11
|
+
id: id, 'aria-label' => label || name.capitalize, required: required, disabled: disabled,
|
|
12
|
+
autocomplete: autocomplete, data: { frame: frame }.compact, rows: rows, cols: cols, maxlength: maxlength
|
|
13
13
|
%>
|
|
14
14
|
<span class="mdc-text-field-character-counter">0 / <%= maxlength %></span>
|
|
15
15
|
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
<div class="mdc-text-field-helper-text" aria-hidden="true"><%= helper %></div>
|
|
23
23
|
<%- end -%>
|
|
24
24
|
<%- parent&.errors&.[](name.to_sym)&.each do |msg| -%>
|
|
25
|
-
<div class="mdc-text-field-helper-text--validation-msg text-sm text-red-500"
|
|
25
|
+
<div class="mdc-text-field-helper-text--validation-msg text-sm text-red-500" role="alert">
|
|
26
26
|
<%= msg %>
|
|
27
27
|
</div>
|
|
28
28
|
<%- end -%>
|
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
<title>Turbo material</title>
|
|
5
5
|
<%= csrf_meta_tags %>
|
|
6
6
|
<%= csp_meta_tag %>
|
|
7
|
-
<link href="//cdn.jsdelivr.net/npm/material-components-web
|
|
8
|
-
<script src="//cdn.jsdelivr.net/npm/material-components-web
|
|
7
|
+
<link href="//cdn.jsdelivr.net/npm/material-components-web@<%= TurboMaterial::MDC_VERSION %>/dist/material-components-web.min.css" rel="stylesheet">
|
|
8
|
+
<script src="//cdn.jsdelivr.net/npm/material-components-web@<%= TurboMaterial::MDC_VERSION %>/dist/material-components-web.min.js"></script>
|
|
9
9
|
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
|
|
10
10
|
<%= stylesheet_link_tag "turbo_material/tailwind", "data-turbo-track": "reload" %>
|
|
11
11
|
<%= javascript_importmap_tags %>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<%= material_data_table_sortable_header label: 'Name', column_id: 'name', sort_value: aria_sort('name', default: true) %>
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
<%- records.each do |record| -%>
|
|
2
|
+
<tr class="mdc-data-table__row" data-row-id="<%= record[:id] %>">
|
|
3
|
+
<%= material_data_table_row_checkbox id: "row-#{record[:id]}", checked: selected_records.include?(record[:id]) %>
|
|
4
|
+
<td class="mdc-data-table__cell" id="row-<%= record[:id] %>"><%= record[:name] %></td>
|
|
5
|
+
</tr>
|
|
6
|
+
<%- end -%>
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
<%# locals: (opened:) %>
|
|
2
|
+
<div class="flex">
|
|
3
|
+
<div class="grow p-4">
|
|
4
|
+
<button class="mdc-icon-button material-icons" id="drawer-toggle"
|
|
5
|
+
data-controller="drawer-button" data-drawer-button-material-drawer-outlet="#drawer"
|
|
6
|
+
data-action="click->drawer-button#click">menu</button>
|
|
7
|
+
</div>
|
|
8
|
+
<aside id="drawer" class="mdc-drawer mdc-drawer--dismissible mdc-drawer--right"
|
|
9
|
+
data-controller="material-drawer"
|
|
10
|
+
data-material-drawer-opened-value="<%= opened %>"
|
|
11
|
+
data-material-drawer-name-value="preview"
|
|
12
|
+
data-material-drawer-open-url-value="/drawer/open"
|
|
13
|
+
data-material-drawer-close-url-value="/drawer/close">
|
|
14
|
+
<div class="mdc-drawer__content p-4">Drawer content</div>
|
|
15
|
+
</aside>
|
|
16
|
+
</div>
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
<%# locals: (text:) %>
|
|
2
|
+
<div class="p-6">
|
|
3
|
+
<button class="mdc-button" id="tooltip-anchor" aria-describedby="preview-tooltip" data-tooltip-id="preview-tooltip">
|
|
4
|
+
<span class="mdc-button__label">Hover me</span>
|
|
5
|
+
</button>
|
|
6
|
+
<%= material_tooltip(id: 'preview-tooltip') { text } %>
|
|
7
|
+
</div>
|
data/config/importmap.rb
CHANGED
|
@@ -3,4 +3,4 @@
|
|
|
3
3
|
pin_all_from File.expand_path('../app/assets/javascripts', __dir__)
|
|
4
4
|
pin '@rails/request.js', to: 'https://ga.jspm.io/npm:@rails/request.js@0.0.9/src/index.js'
|
|
5
5
|
pin 'stimulus-use', to: 'https://ga.jspm.io/npm:stimulus-use@0.51.3/dist/index.js'
|
|
6
|
-
pin 'hotkeys-js', to: 'https://ga.jspm.io/npm:hotkeys-js@3.10.2/dist/hotkeys.esm.js'
|
|
6
|
+
pin 'hotkeys-js', to: 'https://ga.jspm.io/npm:hotkeys-js@3.10.2/dist/hotkeys.esm.js' # imported by stimulus-use
|
data/config/routes.rb
CHANGED
|
@@ -7,20 +7,18 @@ module TurboMaterial
|
|
|
7
7
|
HEAD_LINKS = <<-HTML.rstrip.freeze
|
|
8
8
|
|
|
9
9
|
|
|
10
|
-
<link href="
|
|
11
|
-
<script src="
|
|
10
|
+
<link href="https://cdn.jsdelivr.net/npm/material-components-web@#{MDC_VERSION}/dist/material-components-web.min.css" rel="stylesheet" integrity="#{MDC_CSS_SRI}" crossorigin="anonymous">
|
|
11
|
+
<script src="https://cdn.jsdelivr.net/npm/material-components-web@#{MDC_VERSION}/dist/material-components-web.min.js" integrity="#{MDC_JS_SRI}" crossorigin="anonymous"></script>
|
|
12
12
|
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">#{' '}
|
|
13
13
|
HTML
|
|
14
14
|
|
|
15
|
-
IMPORT = '@import "../builds/tailwind/turbo_material.css";'
|
|
15
|
+
IMPORT = '@import "../builds/tailwind/turbo_material.css";'
|
|
16
16
|
|
|
17
17
|
def add_turbo_material_tailwind
|
|
18
18
|
return if options[:update_tailwind_only]
|
|
19
19
|
|
|
20
20
|
tailwind_path = Rails.root.join('app/assets/tailwind/application.css')
|
|
21
|
-
unless tailwind_path.exist?
|
|
22
|
-
raise '`app/assets/tailwind/application.css` does not exist'
|
|
23
|
-
end
|
|
21
|
+
raise '`app/assets/tailwind/application.css` does not exist' unless tailwind_path.exist?
|
|
24
22
|
|
|
25
23
|
if tailwind_path.read.include?(IMPORT)
|
|
26
24
|
puts "`app/assets/tailwind/application.css` already contains `#{IMPORT}`"
|
|
@@ -56,7 +54,7 @@ module TurboMaterial
|
|
|
56
54
|
raise '`app/views/layouts/application.html.erb` does not exist or does not contain `<%= csp_meta_tag %>`'
|
|
57
55
|
end
|
|
58
56
|
|
|
59
|
-
if layout_path.read.include?('
|
|
57
|
+
if layout_path.read.include?('//cdn.jsdelivr.net/npm/material-components-web@')
|
|
60
58
|
puts '`app/views/layouts/application.html.erb` head already contains material components web links'
|
|
61
59
|
else
|
|
62
60
|
insert_into_file layout_path, after: '<%= csp_meta_tag %>' do
|
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
class ChipsInputPreview < Lookbook::Preview
|
|
4
|
-
|
|
5
4
|
# @param label text
|
|
6
5
|
# @param disabled toggle
|
|
7
6
|
# @param required toggle
|
|
8
7
|
def default(label: 'Chips Input', disabled: false, required: false)
|
|
9
8
|
render 'common/form', helper_name: 'material_chips_input',
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
url: '/countries', name: 'countries', label:, id: 'Input', disabled:, required:,
|
|
10
|
+
options: Carmen::Country.all.map { |c| { id: c.alpha_3_code, label: c.name } }
|
|
12
11
|
end
|
|
13
12
|
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
class DataTablePreview < Lookbook::Preview
|
|
4
|
+
Pagy = Data.define(:page, :limit, :count) do
|
|
5
|
+
def last = (count.to_f / limit).ceil
|
|
6
|
+
def from = ((page - 1) * limit) + 1
|
|
7
|
+
def to = [page * limit, count].min
|
|
8
|
+
def prev = page > 1 ? page - 1 : nil
|
|
9
|
+
def next = page < last ? page + 1 : nil
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def default
|
|
13
|
+
records = [{ id: 1, name: 'Alpha' }, { id: 2, name: 'Beta' }, { id: 3, name: 'Gamma' }]
|
|
14
|
+
render 'common/standalone', helper_name: 'material_data_table',
|
|
15
|
+
name: 'Items', table_body: 'items', url: '/items', table_params: {},
|
|
16
|
+
records:, selected_records: [2], pagy: Pagy.new(page: 1, limit: 10, count: 3),
|
|
17
|
+
table_headers_partial: 'lookbook/data_table_headers',
|
|
18
|
+
table_contents_partial: 'lookbook/data_table_rows'
|
|
19
|
+
end
|
|
20
|
+
end
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
class MenuButtonPreview < Lookbook::Preview
|
|
3
4
|
# @param button_text text
|
|
4
5
|
def default(button_text: 'Menu')
|
|
5
6
|
render 'common/standalone', helper_name: 'material_menu_button', button_text:, menu_contents_partial: 'common/menu_contents'
|
|
@@ -7,32 +7,18 @@ module TurboMaterial
|
|
|
7
7
|
isolate_namespace TurboMaterial
|
|
8
8
|
|
|
9
9
|
initializer 'local_helper.action_controller' do
|
|
10
|
+
helper_paths = Dir[root.join('app/helpers/turbo_material/*_helper.rb')]
|
|
10
11
|
ActiveSupport.on_load :action_controller do
|
|
11
|
-
helper TurboMaterial
|
|
12
|
-
helper TurboMaterial::InputHelper
|
|
13
|
-
helper TurboMaterial::CheckboxHelper
|
|
14
|
-
helper TurboMaterial::ChipSetHelper
|
|
15
|
-
helper TurboMaterial::ChipsInputHelper
|
|
16
|
-
helper TurboMaterial::ChipsInputOptionsHelper
|
|
17
|
-
helper TurboMaterial::ChipsSelectHelper
|
|
18
|
-
helper TurboMaterial::DataTableHelper
|
|
19
|
-
helper TurboMaterial::MenuButtonHelper
|
|
20
|
-
helper TurboMaterial::ModalHelper
|
|
21
|
-
helper TurboMaterial::RadioHelper
|
|
22
|
-
helper TurboMaterial::SelectHelper
|
|
23
|
-
helper TurboMaterial::SwitchHelper
|
|
24
|
-
helper TurboMaterial::TextareaHelper
|
|
25
|
-
helper TurboMaterial::TooltipHelper
|
|
12
|
+
helper_paths.each { |path| helper "TurboMaterial::#{File.basename(path, '.rb').camelize}".constantize }
|
|
26
13
|
end
|
|
27
14
|
end
|
|
28
15
|
|
|
29
|
-
initializer 'turbo_material.tailwindcss' do
|
|
16
|
+
initializer 'turbo_material.tailwindcss' do
|
|
30
17
|
ActiveSupport.on_load(:tailwindcss_rails) do
|
|
31
18
|
config.tailwindcss_rails.engines << TurboMaterial::Engine.engine_name
|
|
32
19
|
end
|
|
33
20
|
end
|
|
34
21
|
|
|
35
|
-
|
|
36
22
|
initializer 'turbo_material.importmap', before: 'importmap' do |app|
|
|
37
23
|
# NOTE: this will add pins from this engine to the main app
|
|
38
24
|
# https://github.com/rails/importmap-rails#composing-import-maps
|
|
@@ -43,16 +29,12 @@ module TurboMaterial
|
|
|
43
29
|
app.config.importmap.cache_sweepers << root.join('app/assets/javascripts')
|
|
44
30
|
end
|
|
45
31
|
|
|
46
|
-
#
|
|
32
|
+
# The manifest links every engine JS and CSS file for production precompile.
|
|
47
33
|
initializer 'turbo_material.assets' do |app|
|
|
48
|
-
app.config.assets
|
|
49
|
-
end
|
|
34
|
+
next unless app.config.respond_to?(:assets) # no asset pipeline in the host
|
|
50
35
|
|
|
51
|
-
|
|
52
|
-
app.config.assets.
|
|
53
|
-
app.config.assets.precompile << 'turbo_material/application.js'
|
|
54
|
-
app.config.assets.paths << root.join('app/assets/dist')
|
|
55
|
-
app.config.assets.precompile << 'turbo_material/tailwind.css'
|
|
36
|
+
app.config.assets.paths << root.join('app/assets/javascripts') << root.join('app/assets/dist')
|
|
37
|
+
app.config.assets.precompile += %w[turbo_material_manifest] if app.config.assets.precompile # Sprockets only
|
|
56
38
|
end
|
|
57
39
|
end
|
|
58
40
|
end
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
module TurboMaterial
|
|
4
|
-
VERSION = '0.3.
|
|
4
|
+
VERSION = '0.3.5'
|
|
5
|
+
MDC_VERSION = '14.0.0'
|
|
6
|
+
# SRI for MDC_VERSION's dist/*.min.{css,js}: "hash" (base64 SHA-256) from
|
|
7
|
+
# https://data.jsdelivr.com/v1/packages/npm/material-components-web@<version>. Update with MDC_VERSION.
|
|
8
|
+
MDC_CSS_SRI = 'sha256-YPguGDqg55HB8+tbrJBbWuiF9J+XCK7sjscaiwFMTxI='
|
|
9
|
+
MDC_JS_SRI = 'sha256-8DHMt+TYs1kVcO+R+oZYTrHYIYwHUOChiQsqKb2BT3g='
|
|
5
10
|
end
|