Skip to content

Commit c0b51a6

Browse files
committed
works
1 parent 18a7923 commit c0b51a6

File tree

5 files changed

+35
-9
lines changed

5 files changed

+35
-9
lines changed

packages/storybook/.storybook/main.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,5 @@ export default defineMain({
3333
},
3434
} satisfies UserConfig);
3535
},
36-
staticDirs: ["../public"],
36+
staticDirs: ["../public", "../../ui-webc/dist/ui-webc/assets"],
3737
});

packages/storybook/src/stories/avatar.stories.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ export default meta;
1414
export const BasicExample = meta.story({
1515
args: {},
1616
render: (args) => (
17-
<ScoutAvatar {...args} />
17+
<div style={{ width: "200px"}}>
18+
<ScoutAvatar {...args} />
19+
</div>
1820
),
1921
});
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
:host {
2-
2+
display: flex;
3+
aspect-ratio: 1 / 1;
4+
}
5+
img {
6+
border-radius: 50%;
37
}

packages/ui-webc/src/components/avatar/avatar.tsx

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1-
import { Component, type ComponentInterface, h, Prop } from "@stencil/core";
2-
import { getAssetPath } from '@stencil/core';
1+
import { Component, type ComponentInterface, getAssetPath, h, Prop } from "@stencil/core";
32

3+
/**
4+
* The avatar component is used to display the user's profile picture.
5+
* Wrap it with a container, to determine its size, since it scales to fit container.
6+
*/
47
@Component({
58
tag: "scout-avatar",
69
styleUrl: "avatar.css",
@@ -9,6 +12,10 @@ import { getAssetPath } from '@stencil/core';
912
},
1013
assetsDirs: ['assets'],
1114
})
15+
16+
/**
17+
*
18+
*/
1219
export class ScoutAvatar implements ComponentInterface {
1320

1421
/**
@@ -22,12 +29,20 @@ export class ScoutAvatar implements ComponentInterface {
2229
@Prop() alt = '';
2330

2431
render() {
25-
26-
const fallback = getAssetPath('fallbackImage.png');
27-
console.log('Fallback asset path:', fallback);
32+
const getImagePath = () => {
33+
if (this.imageSrc) {
34+
return this.imageSrc;
35+
}
36+
try {
37+
return getAssetPath('assets/fallbackImage.png');
38+
} catch (error) {
39+
console.info("In storybook, rendering from storybook asset");
40+
return 'fallbackImage.png';
41+
}
42+
};
2843

2944
return (
30-
<img src={getAssetPath('./assets/fallbackImage.png')} alt={this.alt} />
45+
<img src={getImagePath()} alt={this.alt} />
3146
);
3247
}
3348
}

packages/ui-webc/src/components/avatar/readme.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
<!-- Auto Generated Below -->
44

55

6+
## Overview
7+
8+
The avatar component is used to display the user's profile picture.
9+
Wrap it with a container, to determine its size, since it scales to fit container.
10+
611
## Properties
712

813
| Property | Attribute | Description | Type | Default |

0 commit comments

Comments
 (0)