Skip to content

Commit

Permalink
completed styling updates and added new component and helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
roncodes committed Feb 1, 2024
1 parent 4e735b7 commit 0a83e5e
Show file tree
Hide file tree
Showing 12 changed files with 235 additions and 27 deletions.
2 changes: 1 addition & 1 deletion addon/components/dropdown-button.hbs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<BasicDropdown class={{@wrapperClass}} @renderInPlace={{@renderInPlace}} @registerAPI={{@registerAPI}} @horizontalPosition={{@horizontalPosition}} @verticalPosition={{@verticalPosition}} @calculatePosition={{@calculatePosition}} @defaultClass={{@defaultClass}} @matchTriggerWidth={{@matchTriggerWidth}} @onOpen={{@onOpen}} @onClose={{@onClose}} {{did-insert this.onInsert}} as |dd|>
<BasicDropdown id={{@dropdownId}} class={{@wrapperClass}} @renderInPlace={{@renderInPlace}} @registerAPI={{@registerAPI}} @horizontalPosition={{@horizontalPosition}} @verticalPosition={{@verticalPosition}} @calculatePosition={{@calculatePosition}} @defaultClass={{@defaultClass}} @matchTriggerWidth={{@matchTriggerWidth}} @onOpen={{@onOpen}} @onClose={{@onClose}} {{did-insert this.onInsert}} as |dd|>
<dd.Trigger class={{@triggerClass}}>
{{#if @buttonComponent}}
{{component @buttonComponent buttonComponentArgs=this.buttonComponentArgs text=@text class=(concat @buttonClass (if dd.isOpen ' dd-is-open')) wrapperClass=@buttonWrapperClass type=this.type active=@active size=this.buttonSize isLoading=@isLoading disabled=@disabled textClass=@textClass helpText=@helpText tooltipPlacement=@tooltipPlacement img=@img imgClass=@imgClass alt=@alt}}
Expand Down
10 changes: 6 additions & 4 deletions addon/components/file-icon.hbs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<div class="file-icon file-icon-{{this.extension}}">
<div class="file-icon file-icon-{{this.extension}}" ...attributes>
<FaIcon @icon={{this.icon}} class={{@iconClass}} @size={{@iconSize}} />
<span class="file-extension truncate">
{{this.extension}}
</span>
{{#unless @hideExtension}}
<span class="file-extension truncate {{@fileExtensionClass}}">
{{this.extension}}
</span>
{{/unless}}
<div>
{{yield}}
</div>
Expand Down
26 changes: 8 additions & 18 deletions addon/components/file-icon.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,14 @@ export default class FileIconComponent extends Component {
}

getExtension(file) {
return getWithDefault(
{
'application/vnd.ms-excel': 'xls',
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet': 'xls',
'vnd.openxmlformats-officedocument.spreadsheetml.sheet': 'xls',
'vnd.ms-excel': 'xls',
'text/csv': 'csv',
'text/tsv': 'tsv',
xlsx: 'xls',
xls: 'xls',
xlsb: 'xls',
xlsm: 'xls',
docx: 'doc',
docm: 'doc',
},
getWithDefault(file, 'extension', 'xls'),
'xls'
);
if (!file || (!file.original_filename && !file.url && !file.path)) {
return null;
}

// Prefer to use the original filename if available, then URL, then path
const filename = file.original_filename || file.url || file.path;
const extensionMatch = filename.match(/\.(.+)$/);
return extensionMatch ? extensionMatch[1] : null;
}

getIcon(file) {
Expand Down
41 changes: 41 additions & 0 deletions addon/components/file.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<div class="x-fleetbase-file" ...attributes>
<div class="x-fleetbase-file-wrapper">
<div class="x-fleetbase-file-actions">
<DropdownButton @dropdownId="x-fleetbase-file-actions-dropdown" @icon="ellipsis" @iconSize="xs" @iconPrefix={{@dropdownButtonIconPrefix}} @text={{@dropdownButtonText}} @size="xs" @horizontalPosition="left" @calculatePosition={{@dropdownButtonCalculatePosition}} @renderInPlace={{or @dropdownButtonRenderInPlace true}} @wrapperClass={{concat @dropdownButtonWrapperClass " " "next-nav-item-dropdown-button"}} @triggerClass={{@dropdownButtonTriggerClass}} @registerAPI={{@registerAPI}} @onInsert={{this.onDropdownButtonInsert}} as |dd|>
<div class="next-dd-menu mt-0i" role="menu" aria-orientation="vertical" aria-labelledby="user-menu">
<div class="px-1">
<div class="text-sm flex flex-row items-center px-3 py-1 rounded-md my-1 text-gray-800 dark:text-gray-300">
{{t "component.file.dropdown-label"}}
</div>
</div>
<div class="next-dd-menu-seperator"></div>
<div role="group" class="px-1">
{{!-- template-lint-disable no-nested-interactive --}}
<a href="javascript:;" role="menuitem" class="next-dd-item text-danger" {{on "click" (fn this.onDropdownItemClick "onDelete" dd)}}>
<span class="mr-1">
<FaIcon @icon="trash" @prefix={{@dropdownButtonIconPrefix}} />
</span>
{{t "common.delete"}}
</a>
</div>
</div>
</DropdownButton>
</div>
<div class="flex flex-1 flex-col justify-between items-center">
<div class="flex-1">
{{#if this.isImage}}
<Image src={{@file.url}} alt={{@file.original_filename}} class="x-fleetbase-file-preview rounded-md shadow-sm" />
{{else}}
<div class="x-fleetbase-file-preview">
<FileIcon @file={{@file}} @hideExtension={{true}} @iconSize="2xl" />
</div>
{{/if}}
</div>
<div class="flex-1 overflow-hidden flex flex-col items-center justify-end">
<div class="x-fleetbase-file-name">
{{truncate-filename @file.original_filename}}
</div>
</div>
</div>
</div>
</div>
43 changes: 43 additions & 0 deletions addon/components/file.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import Component from '@glimmer/component';
import { tracked } from '@glimmer/tracking';
import { action } from '@ember/object';

export default class FileComponent extends Component {
@tracked file;
@tracked isImage = false;

constructor(owner, { file }) {
super(...arguments);

this.file = file;
this.isImage = this.isImageFile(file);
}

@action onDropdownItemClick(action, dd) {
if (typeof dd.actions === 'object' && typeof dd.actions.close === 'function') {
dd.actions.close();
}

if (typeof this.args[action] === 'function') {
this.args[action](this.file);
}
}

isImageFile(file) {
if (!file || (!file.original_filename && !file.url && !file.path)) {
return false;
}

const filename = file.original_filename || file.url || file.path;
const extensionMatch = filename.match(/\.(.+)$/);

if (!extensionMatch) {
return false;
}

const extension = extensionMatch[1].toLowerCase();
const imageExtensions = ['jpg', 'jpeg', 'png', 'gif', 'bmp', 'tiff', 'webp'];

return imageExtensions.includes(extension);
}
}
20 changes: 20 additions & 0 deletions addon/helpers/truncate-filename.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { helper } from '@ember/component/helper';

export default helper(function truncateFilename([filename, maxLength = 20]) {
if (!filename || typeof filename !== 'string' || filename.length <= maxLength) {
return filename;
}

const extensionMatch = filename.match(/\.(.+)$/);
const extension = extensionMatch ? extensionMatch[0] : '';
const baseName = filename.slice(0, -extension.length);

if (maxLength <= extension.length) {
// If the maximum length is less than or equal to the extension's length, return only the extension
return `...${extension}`;
}

const truncated = baseName.slice(0, maxLength - extension.length - 3) + '...';

return truncated + extension;
});
2 changes: 1 addition & 1 deletion addon/styles/layout/legacy.css
Original file line number Diff line number Diff line change
Expand Up @@ -737,7 +737,7 @@ body[data-theme='dark'] .ui-combo-box .options-list a.combo-box-option:hover {

.file-dropzone {
@apply w-full rounded-lg px-4 py-8 bg-gray-50 text-gray-800 text-center flex flex-col items-center justify-center border-2 border-dashed border-gray-200;
min-height: 14rem;
min-height: 10rem;
}

body[data-theme='dark'] .file-dropzone {
Expand Down
73 changes: 70 additions & 3 deletions addon/styles/layout/next.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
body {
height: 100%;
min-height: 100%;
max-height: 100%;
}

body, html, button, a, * {
cursor: default;
}
Expand Down Expand Up @@ -70,8 +76,9 @@ body[data-theme='dark'] .next-mobile-navbar .next-mobile-navbar-tabs > .next-mob
@apply text-gray-800 flex flex-col bg-white border-t-0;
overflow: hidden;
width: 100%;
height: 100%;
min-height: 100%;
height: 100%;
min-height: 100%;
max-height: 100%;
align-items: stretch;
border-top: none;
}
Expand Down Expand Up @@ -997,7 +1004,7 @@ body[data-theme='dark'] .next-content-panel-wrapper .next-content-panel-containe
height: 57px;
flex-shrink: 0;
min-width: 100vw;
max-width: 100vw;
max-width: 100%;
-moz-user-select: none;
user-select: none;
-webkit-user-select: none;
Expand Down Expand Up @@ -1873,4 +1880,64 @@ input.order-list-overlay-search:focus {

.thread-comment-conent-paragraph-wrapper {
min-height: 1.75rem;
}

.x-fleetbase-file > .x-fleetbase-file-wrapper {
position: relative;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
padding: .65rem;
max-width: 96px;
height: 135px;
max-height: 160px;
border: 1px #d1d5db solid;
border-radius: .5rem;
}

body[data-theme="dark"] .x-fleetbase-file > .x-fleetbase-file-wrapper {
border: 1px #374151 solid;
}

.x-fleetbase-file > .x-fleetbase-file-wrapper:hover {
border: 1px #3b82f6 solid;
}

.x-fleetbase-file > .x-fleetbase-file-wrapper .x-fleetbase-file-name {
background-color: #3b82f6;
padding: .15rem;
border-radius: .15rem;
text-align: center;
font-size: 0.75rem;
line-height: 1rem;
color: #fff;
}

.x-fleetbase-file > .x-fleetbase-file-wrapper .x-fleetbase-file-preview {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
width: 4rem;
height: 4rem;
margin-bottom: .5rem;
}

.x-fleetbase-file > .x-fleetbase-file-wrapper .x-fleetbase-file-actions {
display: flex;
flex-direction: row;
align-items: center;
justify-content: end;
}

.x-fleetbase-file > .x-fleetbase-file-wrapper .x-fleetbase-file-actions #x-fleetbase-file-actions-dropdown {
position: absolute;
right: 0;
top: 0;
margin: 0.25rem;
}

.x-fleetbase-file > .x-fleetbase-file-wrapper .x-fleetbase-file-actions #x-fleetbase-file-actions-dropdown .ember-basic-dropdown-trigger button.btn {
padding: 0.15rem 0.65rem;
}
1 change: 1 addition & 0 deletions app/components/file.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from '@fleetbase/ember-ui/components/file';
1 change: 1 addition & 0 deletions app/helpers/truncate-filename.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from '@fleetbase/ember-ui/helpers/truncate-filename';
26 changes: 26 additions & 0 deletions tests/integration/components/file-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { module, test } from 'qunit';
import { setupRenderingTest } from 'dummy/tests/helpers';
import { render } from '@ember/test-helpers';
import { hbs } from 'ember-cli-htmlbars';

module('Integration | Component | file', function (hooks) {
setupRenderingTest(hooks);

test('it renders', async function (assert) {
// Set any properties with this.set('myProperty', 'value');
// Handle any actions with this.set('myAction', function(val) { ... });

await render(hbs`<File />`);

assert.dom().hasText('');

// Template block usage:
await render(hbs`
<File>
template block text
</File>
`);

assert.dom().hasText('template block text');
});
});
17 changes: 17 additions & 0 deletions tests/integration/helpers/truncate-filename-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { module, test } from 'qunit';
import { setupRenderingTest } from 'dummy/tests/helpers';
import { render } from '@ember/test-helpers';
import { hbs } from 'ember-cli-htmlbars';

module('Integration | Helper | truncate-filename', function (hooks) {
setupRenderingTest(hooks);

// TODO: Replace this with your real tests.
test('it renders', async function (assert) {
this.set('inputValue', '1234');

await render(hbs`{{truncate-filename this.inputValue}}`);

assert.dom().hasText('1234');
});
});

0 comments on commit 0a83e5e

Please sign in to comment.