Skip to content

Commit

Permalink
Merge pull request #1782 from Kajabi/feature/upload-card-update
Browse files Browse the repository at this point in the history
[DSS-328] Upload Card - Layout Update
  • Loading branch information
anechol authored Oct 16, 2023
2 parents ad75aaf + ad36f96 commit 83602ea
Show file tree
Hide file tree
Showing 7 changed files with 455 additions and 158 deletions.
111 changes: 89 additions & 22 deletions docs/app/views/examples/components/upload_card/_preview.html.erb
Original file line number Diff line number Diff line change
@@ -1,42 +1,109 @@
<h3 class="t-sage-heading-6">Initial State</h3>
<%
dropdown_menu_items = [
{
value: "Upload file",
}, {
value: "Select recent file",
}, {
style: "danger",
modifiers: ["border-before"],
value: "Remove image",
}
]
%>

<h3>Default State (no file selected)</h3>

<%= sage_component SageUploadCard, {
selection_label: "Select a file",
selection_subtext: "Recommended dimensions or file size requirements",
} %>
id: "upload-card-default",
selection_label: "Select file",
} do %>
<% content_for :sage_upload_card_instructions do %>
<p>Upload a JPEG</p>
<% end %>
<% end %>

<h3>Selected File State</h3>

<h3 class="t-sage-heading-6">Selected File State</h3>
<p>Restrict accepted file types using <code>accepted_file_types</code>.</p>

<%= sage_component SageUploadCard, {
accepted_files: [
{name: "contacts.csv"},
{name: "my-image-file.jpg"},
],
file_selected: true,
accepted_file_types: ["image/jpg"],
selection_preview: "https://placekitten.com/360",
selection_label: "Replace file",
selection_subtext: "Recommended dimensions or file size requirements",
} %>
id: "upload-card-selected",
} do %>
<% content_for :sage_upload_card_instructions do %>
<p>Upload a JPEG this is a test</p>
<% end %>
<% end %>

<h3 class="t-sage-heading-6">Error State</h3>

<h3>Vertical (stacked) layout</h3>
<p>The default layout will adjust from a vertical (stacked) orientation to horizontal depending on available space and/or screen size.</p>

<p>Setting <code>stack_layout</code> to <code>true</code> locks the component to the vertical orientation.</p>

<%= sage_component SageUploadCard, {
has_error: true,
selection_label: "Select a file",
selection_subtext: "Recommended dimensions or file size requirements",
errors: [
{text: "This is the error message."},
]
} %>
accepted_files: [
{name: "my-image-file.jpg"},
],
file_selected: true,
selection_preview: "https://placekitten.com/360",
stack_layout: true,
id: "upload-card-stack",
selection_label: "Edit file",
} do %>
<% content_for :sage_upload_card_instructions do %>
<p>Recommended dimensions or file size requirements</p>
<% end %>
<% end %>

<h3 class="t-sage-heading-6">Selected Error State</h3>
<h3>Custom content areas</h3>
<h4>Instructions area</h4>
<p>The <code>sage_upload_card_instructions</code> slot provides an area for extended instructions and custom markup.</p>

<h4>Actions area</h4>
<p>Use the <code>sage_upload_card_actions</code> slot to replace the default button and display custom components, such as dropdowns.</p>
<p><strong>NOTE:</strong> a file input field and label are <em>included by default in the base component</em>, as seen in the examples above. When applying a custom file input with `sage_upload_card_actions`, set <code>custom_file_input_field</code> to <code>true</code> to remove these defaults.</p>
<%= sage_component SageUploadCard, {
accepted_files: [
{name: "contacts.csv"},
{name: "fluffy-kitteh.jpg"},
],
custom_file_input_field: true,
file_selected: true,
selection_preview: "https://placekitten.com/360",
id: "upload-card-dropdown"
} do %>
<% content_for :sage_upload_card_actions do %>
<%= sage_component SageDropdown, { items: dropdown_menu_items } do %>
<% content_for :sage_dropdown_trigger, flush: true do %>
<%= sage_component SageButton, {
style: "secondary",
icon: { name: "caret-down", style: "right" },
value: "Edit file",
} %>
<% end %>
<% end %>
<% end %>
<% end %>


<h3>Error State</h3>

<%= sage_component SageUploadCard, {
has_error: true,
selection_label: "Replace file",
selection_subtext: "Recommended dimensions or file size requirements",
id: "upload-card-error",
selection_label: "Select a file",
errors: [
{text: "This is the error message."},
{text: "This is an error message."},
]
} %>
} do %>
<% content_for :sage_upload_card_instructions do %>
<p>Recommended dimensions or file size requirements</p>
<% end %>
<% end %>
10 changes: 9 additions & 1 deletion docs/lib/sage_rails/app/sage_components/sage_upload_card.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,20 @@ class SageUploadCard < SageComponent
name: [:optional, NilClass, String],
size: [:optional, NilClass, String],
]]],
accepted_file_types: [:optional, NilClass, Array],
custom_file_input_field: [:optional, NilClass, TrueClass],
errors: [:optional, NilClass, [[
text: [:optional, NilClass, String],
]]],
file_selected: [:optional, NilClass, TrueClass],
has_error: [:optional, NilClass, TrueClass],
id: String,
name: [:optional, NilClass, String],
selection_preview: [:optional, NilClass, String],
selection_label: [:optional, NilClass, String],
selection_subtext: [:optional, NilClass, String],
stack_layout:[:optional, NilClass, TrueClass],
})
def sections
%w(upload_card_instructions upload_card_preview upload_card_actions)
end
end
Original file line number Diff line number Diff line change
@@ -1,42 +1,56 @@
<div
class="
sage-upload-card
<% if component.file_selected.present? %> sage-upload-card--selected<% end %>
<% if component.has_error.present? %> sage-upload-card--error<% end %>
<%= component.generated_css_classes %>
"
<%= component.generated_html_attributes.html_safe %>
>
<%
upload_card_classes = ['sage-upload-card']
upload_card_classes << 'sage-upload-card--stack-only' if component.stack_layout == true
upload_card_classes << 'sage-upload-card--selected' if component.file_selected.present?
upload_card_classes << 'sage-upload-card--error' if component.has_error.present?
upload_card_classes << component.generated_css_classes
upload_card_input_label = component.selection_label.present? ? component.selection_label : "Select a file"
upload_card_image_types = component.accepted_file_types.present? ? component.accepted_file_types.join(",") : "image/*"

upload_card_preview_image_options = {
class: "sage-upload-card__preview",
alt: ""
}
%>
<div class="<%= upload_card_classes.join(" ") %>" <%= component.generated_html_attributes.html_safe %>>
<div class="sage-upload-card__dropzone">
<input class="sage-upload-card__input" accept=".csv" multiple="multiple" type="file" autocomplete="off" />
<% if component.file_selected.present? %>
<% unless component.custom_file_input_field %>
<input class="sage-upload-card__input" accept="<%= upload_card_image_types %>" multiple="multiple" type="file" autocomplete="off" name="<%= component.name.present? ? component.name : component.id %>" id="<%= component.id %>" />
<% end %>
<% if component.selection_preview.present? %>
<%= image_tag(component.selection_preview, upload_card_preview_image_options) %>
<% elsif content_for? :sage_upload_card_preview %>
<%= content_for :sage_upload_card_preview %>
<% else %>
<%= sage_component SageIconCard, {
color: "draft",
css_classes: "sage-upload-card__preview",
icon: "image",
label: "Upload graphic",
size: "2xl",
} %>
<div class="sage-upload-card__body">
<p class="sage-upload-card__text"><%= component.accepted_files[0][:name] %></p>
<%= sage_component SageButton, {
style: "primary",
subtle: true,
value: component.selection_label
} %>
<p class="sage-upload-card__subtext"><%= component.selection_subtext %></p>
</div>
<% else %>
<div class="sage-upload-card__body">
<i class="sage-upload-card__icon sage-icon-image-2xl" aria-label="Upload graphic"></i>
<%= sage_component SageButton, {
style: "primary",
subtle: true,
value: component.selection_label
} %>
<p class="sage-upload-card__subtext"><%= component.selection_subtext %></p>
</div>
<% end %>
<div class="sage-upload-card__body">
<div class="sage-upload-card__description">
<% if component.file_selected.present? || component.selection_preview.present? %>
<p class="sage-upload-card__filename">
<%= component.accepted_files[0][:name] %>
</p>
<% end %>
<% if content_for? :sage_upload_card_instructions %>
<div class="sage-upload-card__instructions">
<%= content_for :sage_upload_card_instructions %>
</div>
<% end %>
</div>
<% if component.selection_label.present? && !component.custom_file_input_field %>
<label for="<%= component.id %>" class="sage-upload-card__input-label sage-btn sage-btn--secondary"><%= upload_card_input_label %></label>
<% elsif content_for? :sage_upload_card_actions %>
<% if !component.custom_file_input_field %>
<label for="<%= component.id %>" class="visually-hidden"><%= upload_card_input_label %></label>
<% end %>
<%= content_for :sage_upload_card_actions %>
<% end %>
</div>
</div>
<% if component.errors.present? %>
<div class="sage-upload-card__errors">
Expand Down
Loading

0 comments on commit 83602ea

Please sign in to comment.