-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add DatePicker component and dsl for single_date_picker and range_dat…
…e_picker form fields
- Loading branch information
Showing
12 changed files
with
249 additions
and
19 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
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 @@ | ||
<%= render(FormControl.new(input: @input, tag: :"primer-datepicker-field")) do %> | ||
<%= content_tag(:div, **@field_wrap_arguments) do %> | ||
<%# leading spinner implies a leading visual %> | ||
<% if @input.leading_visual || @input.leading_spinner? %> | ||
<span class="FormControl-input-leadingVisualWrap"> | ||
<%= render(Primer::Beta::Octicon.new(**@input.leading_visual, data: { target: "primer-text-field.leadingVisual" })) %> | ||
<% if @input.leading_spinner? %> | ||
<%= render(Primer::Beta::Spinner.new(size: :small, hidden: true, data: { target: "primer-text-field.leadingSpinner" })) %> | ||
<% end %> | ||
</span> | ||
<% end %> | ||
<%= render Primer::ConditionalWrapper.new(condition: @input.auto_check_src, tag: "auto-check", csrf: auto_check_authenticity_token, src: @input.auto_check_src) do %> | ||
<%= angular_component_tag @datepicker_options.fetch(:component), | ||
inputs: @datepicker_options.merge( | ||
id: @datepicker_options.fetch(:id) { builder.field_id(@input.name) }, | ||
name: @datepicker_options.fetch(:name) { builder.field_name(@input.name) }, | ||
value: @datepicker_options.fetch(:value) { @input.input_arguments[:value] }, | ||
inputClassNames: @datepicker_options.fetch(:class) { @input.input_arguments[:class] } | ||
) | ||
%> | ||
<% 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,17 @@ | ||
# frozen_string_literal: true | ||
|
||
module Primer | ||
module OpenProject | ||
module Forms | ||
# :nodoc: | ||
class DatePicker < Primer::Forms::TextField | ||
include AngularHelper | ||
|
||
def initialize(input:, datepicker_options:) | ||
super(input:) | ||
@datepicker_options = datepicker_options | ||
end | ||
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
21 changes: 21 additions & 0 deletions
21
lib/primer/open_project/forms/dsl/range_date_picker_input.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,21 @@ | ||
# frozen_string_literal: true | ||
|
||
module Primer | ||
module OpenProject | ||
module Forms | ||
module Dsl | ||
class RangeDatePickerInput < SingleDatePickerInput | ||
def derive_datepicker_options(options) | ||
options.reverse_merge( | ||
component: "opce-range-date-picker" | ||
) | ||
end | ||
|
||
def type | ||
:range_date_picker | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
33 changes: 33 additions & 0 deletions
33
lib/primer/open_project/forms/dsl/single_date_picker_input.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,33 @@ | ||
# frozen_string_literal: true | ||
|
||
module Primer | ||
module OpenProject | ||
module Forms | ||
module Dsl | ||
class SingleDatePickerInput < Primer::Forms::Dsl::TextFieldInput | ||
attr_reader :datepicker_options | ||
|
||
def initialize(name:, label:, datepicker_options:, **system_arguments) | ||
@datepicker_options = derive_datepicker_options(datepicker_options) | ||
|
||
super(name:, label:, **system_arguments) | ||
end | ||
|
||
def derive_datepicker_options(options) | ||
options.reverse_merge( | ||
component: "opce-single-date-picker" | ||
) | ||
end | ||
|
||
def to_component | ||
DatePicker.new(input: self, datepicker_options:) | ||
end | ||
|
||
def type | ||
:single_date_picker | ||
end | ||
end | ||
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
59 changes: 58 additions & 1 deletion
59
lookbook/previews/open_project/common/datepicker_preview/range.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 |
---|---|---|
@@ -1 +1,58 @@ | ||
<%= tag :'opce-range-date-picker', value: %> | ||
<% | ||
the_form = Class.new(ApplicationForm) do | ||
form do |query_form| | ||
query_form.range_date_picker( | ||
name: :date, | ||
label: 'Date', | ||
leading_visual: { icon: }, | ||
value: value, | ||
datepicker_options: { inDialog: in_dialog } | ||
) | ||
|
||
query_form.range_date_picker( | ||
name: :date, | ||
label: 'Date', | ||
leading_visual: { icon: }, | ||
value: value, | ||
datepicker_options: { inDialog: in_dialog } | ||
) | ||
|
||
query_form.range_date_picker( | ||
name: :date, | ||
label: 'Date', | ||
leading_visual: { icon: }, | ||
value: value, | ||
datepicker_options: { inDialog: in_dialog } | ||
) | ||
end | ||
end | ||
%> | ||
|
||
<% if in_dialog %> | ||
<%= render(Primer::Alpha::Dialog.new(title: "Dialog Title", | ||
size: :large, | ||
open: true, | ||
id: "my-dialog")) do |d| %> | ||
<% d.with_show_button { "Show dialog" } %> | ||
<% d.with_header(variant: :medium) %> | ||
|
||
<%= render(Primer::Alpha::Dialog::Body.new) do | ||
primer_form_with( | ||
url: '/abc', | ||
id: "my-form") do |f| | ||
render(the_form.new(f)) | ||
end | ||
end %> | ||
|
||
<%= d.with_footer do %> | ||
<%= render(Primer::Beta::Button.new(data: { "close-dialog-id": "my-dialog" })) { I18n.t(:button_cancel) } %> | ||
<%= render(Primer::Beta::Button.new(scheme: :primary, type: :submit, form: "my-form")) { I18n.t(:button_apply) } %> | ||
<% end %> | ||
<% end %> | ||
<% else %> | ||
<%= primer_form_with( | ||
url: '/abc', | ||
id: "my-form") do |f| | ||
render(the_form.new(f)) | ||
end %> | ||
<% end %> |
59 changes: 58 additions & 1 deletion
59
lookbook/previews/open_project/common/datepicker_preview/single.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 |
---|---|---|
@@ -1 +1,58 @@ | ||
<%= tag :'opce-single-date-picker', value: %> | ||
<% | ||
the_form = Class.new(ApplicationForm) do | ||
form do |query_form| | ||
query_form.single_date_picker( | ||
name: :date, | ||
label: 'Date', | ||
leading_visual: { icon: }, | ||
value: value.iso8601, | ||
datepicker_options: { inDialog: in_dialog } | ||
) | ||
|
||
query_form.single_date_picker( | ||
name: :date, | ||
label: 'Date', | ||
leading_visual: { icon: }, | ||
value: value.iso8601, | ||
datepicker_options: { inDialog: in_dialog } | ||
) | ||
|
||
query_form.single_date_picker( | ||
name: :date, | ||
label: 'Date', | ||
leading_visual: { icon: }, | ||
value: value.iso8601, | ||
datepicker_options: { inDialog: in_dialog } | ||
) | ||
end | ||
end | ||
%> | ||
|
||
<% if in_dialog %> | ||
<%= render(Primer::Alpha::Dialog.new(title: "Dialog Title", | ||
size: :large, | ||
open: true, | ||
id: "my-dialog")) do |d| %> | ||
<% d.with_show_button { "Show dialog" } %> | ||
<% d.with_header(variant: :medium) %> | ||
|
||
<%= render(Primer::Alpha::Dialog::Body.new) do | ||
primer_form_with( | ||
url: '/abc', | ||
id: "my-form") do |f| | ||
render(the_form.new(f)) | ||
end | ||
end %> | ||
|
||
<%= d.with_footer do %> | ||
<%= render(Primer::Beta::Button.new(data: { "close-dialog-id": "my-dialog" })) { I18n.t(:button_cancel) } %> | ||
<%= render(Primer::Beta::Button.new(scheme: :primary, type: :submit, form: "my-form")) { I18n.t(:button_apply) } %> | ||
<% end %> | ||
<% end %> | ||
<% else %> | ||
<%= primer_form_with( | ||
url: '/abc', | ||
id: "my-form") do |f| | ||
render(the_form.new(f)) | ||
end %> | ||
<% end %> |