Skip to content

Commit

Permalink
seperate thumbnail and icon block for clearer readability (#1979)
Browse files Browse the repository at this point in the history
* seperte thumbnail and icon block for clearer readability

* split entity-display to two seperate component
  • Loading branch information
lucaslyl authored Dec 27, 2024
1 parent 0e48dfe commit 71f2711
Show file tree
Hide file tree
Showing 13 changed files with 323 additions and 180 deletions.
13 changes: 5 additions & 8 deletions packages/experiments-realm/address.gts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
import StringField from 'https://cardstack.com/base/string';
import { CountryField } from './country';
import MapPinIcon from '@cardstack/boxel-icons/map-pin';
import { EntityDisplay } from './components/entity-display';
import EntityDisplayWithIcon from './components/entity-icon-display';

function getAddressRows(
addressLine1: string | undefined,
Expand Down Expand Up @@ -39,14 +39,11 @@ class Atom extends Component<typeof Address> {
);
}
<template>
<EntityDisplay>
<:title>
{{this.label}}
</:title>
<:thumbnail>
<EntityDisplayWithIcon @title={{this.label}}>
<:icon>
<MapPinIcon />
</:thumbnail>
</EntityDisplay>
</:icon>
</EntityDisplayWithIcon>
</template>
}

Expand Down
6 changes: 3 additions & 3 deletions packages/experiments-realm/components/activity-card.gts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import GlimmerComponent from '@glimmer/component';
import { EntityDisplay } from './entity-display';
import EntityDisplayWithThumbnail from './entity-thumbnail-display';

interface ActivityCardArgs {
Blocks: {
Expand All @@ -17,7 +17,7 @@ export default class ActivityCard extends GlimmerComponent<ActivityCardArgs> {
<article class='activity-card' ...attributes>
<header class='activity-card-header'>
<div class='activity-card-title-desc-group'>
<EntityDisplay>
<EntityDisplayWithThumbnail>
<:title>
<span class='activity-card-title'>
{{yield to='title'}}
Expand All @@ -28,7 +28,7 @@ export default class ActivityCard extends GlimmerComponent<ActivityCardArgs> {
{{yield to='thumbnail'}}
</span>
</:thumbnail>
</EntityDisplay>
</EntityDisplayWithThumbnail>

{{#if (has-block 'description')}}
<p class='activity-card-description'>
Expand Down
9 changes: 3 additions & 6 deletions packages/experiments-realm/components/contact-row.gts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Avatar, Pill } from '@cardstack/boxel-ui/components';
import { EntityDisplay } from './entity-display';
import EntityDisplayWithThumbnail from './entity-thumbnail-display';
import GlimmerComponent from '@glimmer/component';

interface ContactRowArgs {
Expand All @@ -15,10 +15,7 @@ interface ContactRowArgs {

export class ContactRow extends GlimmerComponent<ContactRowArgs> {
<template>
<EntityDisplay>
<:title>
{{@name}}
</:title>
<EntityDisplayWithThumbnail @title={{@name}}>
<:thumbnail>
<Avatar
@userID={{@userID}}
Expand All @@ -35,7 +32,7 @@ export class ContactRow extends GlimmerComponent<ContactRowArgs> {
</Pill>
{{/if}}
</:tag>
</EntityDisplay>
</EntityDisplayWithThumbnail>
<style scoped>
.avatar {
--profile-avatar-icon-size: 20px;
Expand Down
93 changes: 0 additions & 93 deletions packages/experiments-realm/components/entity-display.gts

This file was deleted.

126 changes: 126 additions & 0 deletions packages/experiments-realm/components/entity-icon-display.gts
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
import GlimmerComponent from '@glimmer/component';
import { concat } from '@ember/helper';

interface EntityDisplayWithIconArgs {
Args: {
title?: string; //prefer using args.title if the title is just a string
center?: boolean;
underline?: boolean;
};
Blocks: {
title?: []; //we can choose use this to pass instead of using args.title if the title block HTML is complex
icon?: [];
tag?: [];
content?: [];
};
Element: HTMLElement;
}

export default class EntityDisplayWithIcon extends GlimmerComponent<EntityDisplayWithIconArgs> {
get shouldAlignCenter() {
return this.args.center;
}

get shouldUnderlineText() {
return this.args.underline;
}

<template>
<div
class={{concat
'entity-icon-display'
(if this.shouldAlignCenter ' center')
}}
...attributes
>
{{#if (has-block 'icon')}}
<aside class='entity-icon'>
{{yield to='icon'}}
</aside>
{{/if}}

<div class='entity-info'>
{{! Title and tag }}
<div class='entity-title-tag-container'>
{{! this guard clause is already priotize yield to 'title' instead of using args.title if both are provided}}
{{#if (has-block 'title')}}
{{yield to='title'}}
{{else if @title}}
<span
class={{concat
'entity-title'
(if this.shouldUnderlineText ' underline')
}}
>
{{@title}}
</span>
{{/if}}

{{#if (has-block 'tag')}}
{{yield to='tag'}}
{{/if}}
</div>

{{! Extra Content }}
{{#if (has-block 'content')}}
<div class='entity-content'>
{{yield to='content'}}
</div>
{{/if}}
</div>

</div>
<style scoped>
.entity-icon-display {
--icon-size: var(--entity-display-icon-size, var(--boxel-icon-sm));
--title-font-size: var(
--entity-display-title-font-size,
var(--boxel-font-size-sm)
);
--content-font-size: var(
--entity-display-content-font-size,
var(--boxel-font-size-xs)
);
--content-color: var(--entity-display-content-color, var(--boxel-400));
--content-gap: var(--entity-display-content-gap, var(--boxel-sp-xxxs));
display: flex;
align-items: flex-start;
gap: var(--content-gap);
}
.entity-icon-display.center {
align-items: center;
}
.entity-icon {
display: inline-flex;
align-items: center;
justify-content: center;
flex-shrink: 0;
width: var(--icon-size);
height: var(--icon-size);
}
.entity-info {
display: flex;
flex-direction: column;
gap: var(--content-gap);
}
.entity-title-tag-container {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: var(--content-gap);
}
.entity-title {
word-break: break-word;
font-size: var(--title-font-size);
}
.entity-title.underline {
text-decoration: underline;
}
.entity-content {
margin: 0;
font-size: var(--content-font-size);
color: var(--content-color);
}
</style>
</template>
}
Loading

0 comments on commit 71f2711

Please sign in to comment.