-
Notifications
You must be signed in to change notification settings - Fork 97
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
Make ProductArea badges interactive #272
Changes from 6 commits
573795e
6a55e8a
92854a5
0b26f4a
d3ee17a
fb11c5e
6c519c8
05ef3a4
2ee8cec
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,56 @@ | ||
<LinkTo | ||
@route="authenticated.document" | ||
@model={{@docID}} | ||
@query={{hash draft=@isDraft}} | ||
class="flex flex-col items-start space-y-2 p-4 -m-4 rounded-md hover:bg-color-palette-neutral-50 active:bg-color-palette-neutral-100 overflow-hidden" | ||
> | ||
<div class="space-y-2"> | ||
<Doc::Thumbnail | ||
@status={{@status}} | ||
@product={{@productArea}} | ||
@isLarge={{true}} | ||
/> | ||
<Doc::State @state={{@status}} /> | ||
</div> | ||
<div class="relative group"> | ||
<LinkTo | ||
@route="authenticated.document" | ||
@model={{@docID}} | ||
@query={{hash draft=@isDraft}} | ||
class="pb-2 block" | ||
> | ||
{{! | ||
We create a click area that extends beyond the edges of its relative container. | ||
This makes the parent div clickable without having to wrap itself in a link, | ||
and lets us nest interactive elements (e.g., ProductBadgeLink) in a way that improves the mouse experience without sacrificing accessibility. | ||
}} | ||
<div | ||
aria-hidden="true" | ||
class="absolute rounded-md group-hover:bg-color-surface-faint -top-4 -left-4 -right-4 -bottom-6" | ||
></div> | ||
|
||
<div class="flex flex-col items-start space-y-1"> | ||
<h4 class="doc-tile-title"> | ||
{{@title}} | ||
</h4> | ||
{{#if (not (is-empty @docNumber))}} | ||
<small class="text-body-100 text-color-foreground-faint"> | ||
{{@docNumber}} | ||
</small> | ||
{{/if}} | ||
</div> | ||
<div class="relative"> | ||
<div class="space-y-2.5 inline-block"> | ||
<Doc::Thumbnail | ||
@status={{@status}} | ||
@product={{@productArea}} | ||
@isLarge={{true}} | ||
/> | ||
<Doc::State @state={{@status}} /> | ||
</div> | ||
<div class="mt-2 space-y-1"> | ||
<h4 class="doc-tile-title"> | ||
{{@title}} | ||
</h4> | ||
{{#if @docNumber}} | ||
<small class="text-body-100 text-color-foreground-faint"> | ||
{{@docNumber}} | ||
</small> | ||
{{/if}} | ||
</div> | ||
<div class="space-y-1 mt-2 max-w-full"> | ||
<Person | ||
@ignoreUnknown={{true}} | ||
@imgURL={{@avatar}} | ||
@email="{{@owner}}" | ||
/> | ||
Comment on lines
+38
to
+42
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can make this clickable in another PR. |
||
{{#if @modifiedAgo}} | ||
<p class="text-body-100 text-color-foreground-faint"> | ||
{{@modifiedAgo}} | ||
</p> | ||
{{/if}} | ||
</div> | ||
{{#if (and @isResult @snippet)}} | ||
<Doc::Snippet @snippet={{@snippet}} class="mt-2" /> | ||
{{/if}} | ||
</div> | ||
</LinkTo> | ||
|
||
<div class="flex flex-col items-start space-y-1 pb-1 max-w-full"> | ||
<Person @ignoreUnknown={{true}} @imgURL={{@avatar}} @email={{@owner}} /> | ||
{{#if (not (is-empty @modifiedAgo))}} | ||
<p class="text-body-100 text-color-foreground-faint"> | ||
{{@modifiedAgo}} | ||
</p> | ||
{{/if}} | ||
</div> | ||
|
||
<Hds::Badge | ||
@text={{this.productAreaName}} | ||
@icon={{or (get-product-id this.this.args.productArea) "folder"}} | ||
/> | ||
|
||
{{#if (and @isResult @snippet)}} | ||
<Doc::Snippet @snippet={{@snippet}} class="pt-2" /> | ||
{{/if}} | ||
</LinkTo> | ||
<ProductBadgeLink @productArea={{@productArea}} class="relative" /> | ||
</div> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<LinkTo | ||
@route={{this.route}} | ||
@query={{this.query}} | ||
class="product-badge-link" | ||
...attributes | ||
> | ||
<Hds::Badge | ||
@icon={{or (get-product-id this.this.args.productArea) "folder"}} | ||
@text={{this.productAreaName}} | ||
title={{this.productAreaName}} | ||
/> | ||
</LinkTo> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import RouterService from "@ember/routing/router-service"; | ||
import { inject as service } from "@ember/service"; | ||
import Component from "@glimmer/component"; | ||
|
||
interface ProductBadgeLinkComponentSignature { | ||
Element: HTMLAnchorElement; | ||
Args: { | ||
productArea?: string; | ||
}; | ||
Blocks: { | ||
default: []; | ||
}; | ||
} | ||
|
||
export default class ProductBadgeLinkComponent extends Component<ProductBadgeLinkComponentSignature> { | ||
@service declare router: RouterService; | ||
|
||
protected get productAreaName(): string { | ||
switch (this.args.productArea) { | ||
case "Cloud Platform": | ||
return "HCP"; | ||
default: | ||
return this.args.productArea || "Unknown"; | ||
} | ||
} | ||
|
||
protected get query() { | ||
if (this.args.productArea) { | ||
return { | ||
product: [this.args.productArea], | ||
}; | ||
} else { | ||
return {}; | ||
} | ||
} | ||
|
||
protected get route() { | ||
const { currentRouteName } = this.router; | ||
|
||
if (!currentRouteName) { | ||
return "authenticated.all"; | ||
} | ||
|
||
if (currentRouteName.includes("drafts")) { | ||
return "authenticated.drafts"; | ||
} | ||
|
||
if (currentRouteName.includes("my")) { | ||
return "authenticated.my"; | ||
} | ||
|
||
return "authenticated.all"; | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I couldn't immediately tell why we needed this logic - maybe a comment would help? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah I probably overcomplicated it anyway 😅 Updated |
||
|
||
declare module "@glint/environment-ember-loose/registry" { | ||
export default interface Registry { | ||
ProductBadgeLink: typeof ProductBadgeLinkComponent; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
.product-badge-link { | ||
&:hover .hds-badge--color-neutral { | ||
@apply bg-color-palette-neutral-200; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❤️