Skip to content

Commit

Permalink
Doc::Thumbnail component (hashicorp-forge#75)
Browse files Browse the repository at this point in the history
* Start of Doc::Thumbnail

* Adjust folder appearance

* Design tweaks

* SVG tweaks

* Revised design

* Cleanup

* Add tests

* Obsolete product-badge tweak

* Adjust border radius

* Extend rather than replace shadows

* Tweak small thumbnail

* Post-merge style tweaks
  • Loading branch information
jeffdaley authored Mar 25, 2023
1 parent efa3dce commit 8b4aa7d
Show file tree
Hide file tree
Showing 17 changed files with 325 additions and 123 deletions.
35 changes: 35 additions & 0 deletions web/app/components/doc/folder-affordance.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<svg
data-test-doc-thumbnail-folder-affordance
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox={{if @isLarge "0 0 97 145" "0 0 43 63"}}
class="folder-affordance"
>
<path
fill="url(#doc-thumbnail-folder-gradient)"
stroke="currentColor"
fill-rule="evenodd"
d={{if
@isLarge
"M6 0a6 6 0 0 0-6 6v41.04a6 6 0 0 0 2.659 4.983l8.29 5.558v80.729a6 6 0 0 0 6 6H97V0H6Z"
"M3 0a3 3 0 0 0-3 3v18.407a3 3 0 0 0 .91 2.152l2.18 2.117v33.746a3 3 0 0 0 3 3H43V0H3Z"
}}
clip-rule="evenodd"
></path>
<defs>
<linearGradient
id="doc-thumbnail-folder-gradient"
x1={{if @isLarge "8.176" "4.746"}}
x2={{if @isLarge "8.176" "4.746"}}
y1="0"
y2={{if @isLarge "43.965" "19.018"}}
gradientUnits="userSpaceOnUse"
>
<stop stop-color="var(--token-color-palette-neutral-50)"></stop>
<stop
offset="1"
stop-color="var(--token-color-palette-neutral-100)"
></stop>
</linearGradient>
</defs>
</svg>
9 changes: 9 additions & 0 deletions web/app/components/doc/folder-affordance.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import Component from "@glimmer/component";

interface DocFolderAffordanceSignature {
Args: {
isLarge?: boolean;
};
}

export default class DocFolderAffordance extends Component<DocFolderAffordanceSignature> {}
33 changes: 1 addition & 32 deletions web/app/components/doc/inline.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -17,38 +17,7 @@
@model="{{@docID}}"
class="flex items-center space-x-3 py-2 px-3 hover:bg-[color:var(--token-color-palette-neutral-100)]"
>
<div
class="relative flex flex-shrink-0 items-center w-[40px] h-[56px] hds-surface-mid
{{if
(eq @status 'obsolete')
'hds-surface-faint opacity-75'
'hds-surface-primary'
}}
rounded overflow-hidden"
>
<img src="/images/document.png" class="w-full mix-blend-multiply" />
{{#if (eq @status "approved")}}
<FlightIcon
@name="check-circle"
@size="24"
class="absolute -right-2 top-1 fill-[var(--token-color-palette-green-200)] w-8 h-8 -rotate-12 mix-blend-multiply opacity-75"
/>
{{/if}}
{{#if (eq @status "obsolete")}}
<div
class="absolute top-0 left-0 right-1 bottom-0 flex items-center hds-surface-strong hds-surface-mid rounded overflow-hidden"
>
<FlightIcon
@name="archive"
@size="24"
class="absolute -left-2 top-1 fill-[var(--token-color-palette-neutral-200)] w-8 h-8 -rotate-12 mix-blend-multiply opacity-75"
/>
</div>
{{/if}}
<div class="{{if (eq @status 'obsolete') 'opacity-50'}}">
<Doc::Tag @name={{@productArea}} @isSmall="{true}" />
</div>
</div>
<Doc::Thumbnail @status={{@status}} @product={{@productArea}} />

<div class="flex flex-col space-y-1 overflow-hidden">
<h4
Expand Down
41 changes: 3 additions & 38 deletions web/app/components/doc/row.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -20,40 +20,9 @@
@route="authenticated.document"
@model="{{@docID}}"
@query={{hash draft=@isDraft}}
class="flex space-x-4"
class="flex space-x-4 items-start"
>
<div
class="relative flex flex-shrink-0 items-center w-[40px] h-[56px] hds-surface-mid
{{if
(eq @status 'obsolete')
'hds-surface-faint opacity-75'
'hds-surface-primary'
}}
rounded overflow-hidden"
>
<img src="/images/document.png" class="w-full mix-blend-multiply" />
{{#if (eq @status "approved")}}
<FlightIcon
@name="check-circle"
@size="24"
class="absolute -right-2 top-1 fill-[var(--token-color-palette-green-200)] w-8 h-8 -rotate-12 mix-blend-multiply opacity-75"
/>
{{/if}}
{{#if (eq @status "obsolete")}}
<div
class="absolute top-0 left-0 right-1 bottom-0 flex items-center hds-surface-strong hds-surface-mid rounded overflow-hidden"
>
<FlightIcon
@name="archive"
@size="24"
class="absolute -left-2 top-1 fill-[var(--token-color-palette-neutral-200)] w-8 h-8 -rotate-12 mix-blend-multiply opacity-75"
/>
</div>
{{/if}}
<div class="{{if (eq @status 'obsolete') 'opacity-50'}}">
<Doc::Tag @name={{@productArea}} @isSmall="{true}" />
</div>
</div>
<Doc::Thumbnail @status={{@status}} @product={{@productArea}} />
<div>
<h4
class="hds-typography-body-200 hds-font-weight-semibold hds-foreground-strong"
Expand All @@ -70,11 +39,7 @@
{{@docType}}
</Hds::Table::Td>
<Hds::Table::Td class="status">
<Doc::State
@state={{@status}}
@hideProgress={{true}}
class="whitespace-nowrap"
/></Hds::Table::Td>
<Doc::State @state={{@status}} @hideProgress={{true}} /></Hds::Table::Td>
<Hds::Table::Td class="product"><Hds::Badge
@text={{this.productAreaName}}
@icon={{this.productAreaIcon}}
Expand Down
4 changes: 2 additions & 2 deletions web/app/components/doc/state.hbs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{{#unless @hideProgress}}
<ol
class="state--{{this.dasherizedName}}
grid grid-cols-3 w-full items-center gap-0.5"
grid grid-cols-3 items-center list-none gap-0.5 w-28 whitespace-nowrap"
>
<Doc::StateProgressBar class={{this.state.barOneClass}} />
<Doc::StateProgressBar class={{this.state.barTwoClass}} />
Expand All @@ -12,5 +12,5 @@
<Hds::Badge
@text={{this.state.label}}
@color={{this.state.color}}
...attributes
class="whitespace-nowrap"
/>
36 changes: 36 additions & 0 deletions web/app/components/doc/thumbnail.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<div
data-test-doc-thumbnail
class="doc-thumbnail
{{if @isLarge 'large'}}
{{if this.isObsolete 'obsolete'}}
bg-color-palette-neutral-100 rounded"
...attributes
>
<img src="/images/document.png" class="w-full h-auto" />

<div class="w-full h-full absolute">
{{#if this.isObsolete}}
<Doc::FolderAffordance @isLarge={{@isLarge}} />
{{/if}}

{{#if (or this.isApproved this.isObsolete)}}
<div class="absolute w-full z-20">
<FlightIcon
data-test-doc-status-icon
@name={{if this.isApproved "check-circle" "archive"}}
@size="24"
class="status-icon {{this.status}}"
/>
</div>
{{/if}}

{{#if this.productShortName}}
<div
data-test-doc-thumbnail-product-badge
class="product-badge {{this.productShortName}}"
>
<FlightIcon @size="16" @name={{this.productShortName}} />
</div>
{{/if}}
</div>
</div>
38 changes: 38 additions & 0 deletions web/app/components/doc/thumbnail.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import Component from "@glimmer/component";
import { dasherize } from "@ember/string";
import getProductId from "hermes/utils/get-product-id";

interface DocThumbnailComponentSignature {
Element: HTMLDivElement;
Args: {
isLarge?: boolean;
status?: string;
product?: string;
};
}

export default class DocThumbnailComponent extends Component<DocThumbnailComponentSignature> {
protected get status(): string | null {
if (this.args.status) {
return dasherize(this.args.status);
} else {
return null;
}
}

protected get productShortName(): string | null {
if (this.args.product) {
return getProductId(this.args.product);
} else {
return null;
}
}

protected get isApproved(): boolean {
return this.status === "approved";
}

protected get isObsolete(): boolean {
return this.status === "obsolete";
}
}
45 changes: 2 additions & 43 deletions web/app/components/doc/tile.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -22,49 +22,8 @@
@query={{hash draft=@isDraft}}
class="flex flex-col items-start space-y-2 no-underline p-4 -m-4 rounded-md hover:bg-[color:var(--token-color-palette-neutral-50)] active:bg-[color:var(--token-color-palette-neutral-100)] overflow-hidden"
>
<div class="flex flex-col items-start w-[108px] space-y-3">
<div
class="relative flex items-center w-[108px] h-[148px] hds-surface-mid
{{if
(eq @status 'obsolete')
'hds-surface-faint opacity-75'
'hds-surface-primary'
}}
rounded overflow-hidden"
>
{{#if (is-empty @thumbnail)}}
<img src="/images/document.png" class="w-full mix-blend-multiply" />
{{else}}
<img
src="{{@thumbnail}}"
class="w-full mix-blend-multiply"
referrerpolicy="no-referrer"
/>
{{/if}}
{{#if (eq @status "approved")}}
<FlightIcon
@name="check-circle"
@size="24"
class="absolute -right-4 top-2 fill-[var(--token-color-palette-green-200)] w-20 h-20 -rotate-12 mix-blend-multiply opacity-75"
/>
{{/if}}
{{#if (eq @status "obsolete")}}
<div
class="absolute top-0 left-0 right-5 bottom-0 flex items-center hds-surface-strong hds-surface-mid rounded overflow-hidden"
>
<FlightIcon
@name="archive"
@size="24"
class="absolute -left-4 top-2 fill-[var(--token-color-palette-neutral-200)] w-20 h-20 -rotate-12 mix-blend-multiply opacity-75"
/>
</div>
{{/if}}
<div class="{{if (eq @status 'obsolete') 'opacity-50'}}">
<Doc::Tag @name={{@productArea}} />
</div>
</div>
<Doc::State @state="{{@status}}" />
</div>
<Doc::Thumbnail @status={{@status}} @product={{@productArea}} @isLarge={{true}} />
<Doc::State @state={{@status}} />

<div class="flex flex-col items-start space-y-1">
<h4 class="doc-tile-title">{{@title}}</h4>
Expand Down
6 changes: 1 addition & 5 deletions web/app/components/document/sidebar.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,7 @@
<small
class="hds-typography-body-100 hds-foreground-faint"
>Status</small>
<Doc::State
@state={{@document.status}}
@hideProgress={{true}}
class="whitespace-nowrap"
/>
<Doc::State @state={{@document.status}} @hideProgress={{true}} />
</div>

<div class="flex flex-col items-start space-y-2">
Expand Down
2 changes: 2 additions & 0 deletions web/app/styles/app.scss
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
@use "components/header/active-filter-list";
@use "components/header/active-filter-list-item";
@use "components/doc/tile-list";
@use "components/doc/thumbnail";
@use "components/doc/folder-affordance";
@use "components/doc/tile";
@use "components/preview-card";
@use "components/notification";
Expand Down
17 changes: 17 additions & 0 deletions web/app/styles/components/doc/folder-affordance.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
.doc-thumbnail {
.folder-affordance {
@apply w-auto absolute scale-x-[-1] -left-1;

// set border via currentColor
@apply text-color-border-primary;

// Allow strokes to show
@apply overflow-visible;

// Make it 100% tall plus 1px for each horizontal stroke
@apply h-[calc(100%+2px)];

// Offset it by 1px so the horizontal strokes aren't visible
@apply -top-[1px];
}
}
72 changes: 72 additions & 0 deletions web/app/styles/components/doc/thumbnail.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
.doc-thumbnail {
@apply relative w-12 shrink-0 flex overflow-hidden;

// Outer border / shadow
&::after {
content: "";
@apply absolute z-50 pointer-events-none;
// Make the element 1px smaller than its container
// so its shadow picks up colors from the elements below it.
@apply top-px right-px bottom-px left-px;
@apply shadow-surface-low rounded-sm;
}

.status-icon {
@apply absolute opacity-75 mix-blend-multiply;
@apply w-9 h-9;

&.approved {
@apply fill-color-palette-green-200 -rotate-6;
@apply -right-[7px] top-[5px];
}

&.obsolete {
@apply fill-color-palette-neutral-300 opacity-60;
@apply -left-[8px] top-[3px];
}
}

.product-badge {
@apply bottom-0 left-0;
@apply w-[19px] h-[17px] rounded-bl rounded-tr;

.flight-icon {
@apply scale-75;
}
}

&.obsolete {
.product-badge {
@apply bg-gradient-to-br from-color-palette-neutral-300 to-color-palette-neutral-400 text-color-palette-neutral-50;
}
}

&.large {
// Match the width of the progress bars
@apply w-28;

&::after {
@apply shadow-surface-mid rounded;
}

.product-badge {
@apply w-[36px] h-[32px] rounded-bl rounded-tr;

.flight-icon {
@apply scale-100;
}
}

.status-icon {
@apply w-[84px] h-[84px] top-[8px];

&.approved {
@apply -right-3.5;
}

&.obsolete {
@apply -left-5;
}
}
}
}
Loading

0 comments on commit 8b4aa7d

Please sign in to comment.