Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DSS-328] Upload Card - Layout Update #1782

Merged
merged 20 commits into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
c04f9c2
fix(upload card): align specs, refactor template logic
teenwolfblitzer Apr 12, 2023
fef2c66
refactor(upload card): restructure card
teenwolfblitzer Apr 21, 2023
56b9279
chore(upload card): remove container assignment
teenwolfblitzer Apr 21, 2023
f2536ca
feat(upload card): force stack layout option
teenwolfblitzer Apr 22, 2023
28078c4
fix(upload card): examples, file types and a11y fixes
teenwolfblitzer Apr 22, 2023
760215d
chore(upload card): remove container experiment
teenwolfblitzer Apr 26, 2023
23efd64
fix(upload card): remove input and label with custom actions
teenwolfblitzer Apr 27, 2023
91c7fa8
feat(upload card): adjust content areas
teenwolfblitzer Apr 28, 2023
fde0ba7
fix(upload card): style adjustments
teenwolfblitzer Apr 28, 2023
fdaff51
docs(upload card): update rails examples
teenwolfblitzer Apr 28, 2023
8dbdb8b
fix(upload card): fixes issue with content for content is replicated …
anechol Aug 2, 2023
598e4d0
style(upload card): updates instructions font style and stack spacing
anechol Aug 3, 2023
92270c7
refactor(upload card): refactors logic for React to match Rails version
anechol Aug 10, 2023
4ccb1ca
feat(upload card): adds stacked layout and id props
anechol Aug 11, 2023
4d0e099
docs(upload card): adds stack example to storybook
anechol Aug 14, 2023
b534bfc
test(upload card): adds tests for upload card
anechol Aug 15, 2023
df6c048
docs(upload card): adds descriptions to stories and fixes preview ima…
anechol Aug 15, 2023
59c1515
docs(upload card): adds missing button to Rails preview
anechol Aug 15, 2023
77de1bf
docs: updates variable name for consistency
anechol Aug 16, 2023
ad36f96
refactor(upload card): refactors label and button logic
anechol Aug 18, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🐈

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>

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: extra space between 'for extended'

<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, {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the sage_upload_card_actions be wrapped in <code> to match the others?

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
Loading