Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/perky-teeth-cover.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@scouterna/ui-webc": major
---

New component Avatar
2 changes: 1 addition & 1 deletion packages/storybook/.storybook/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,5 @@ export default defineMain({
},
} satisfies UserConfig);
},
staticDirs: ["../public"],
staticDirs: ["../public", "../../ui-webc/dist/ui-webc/assets"],
Comment thread
daBack marked this conversation as resolved.
});
21 changes: 21 additions & 0 deletions packages/storybook/src/stories/avatar.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { ScoutAvatar } from "@scouterna/ui-react";
import preview from "#.storybook/preview";

const meta = preview.meta({
title: "Basics/Avatar",
component: ScoutAvatar,
parameters: {
layout: "centered",
},
});

export default meta;

export const BasicExample = meta.story({
args: {},
render: (args) => (
<div style={{ width: "200px" }}>
<ScoutAvatar {...args} />
Comment thread
daBack marked this conversation as resolved.
</div>
),
});
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions packages/ui-webc/src/components/avatar/avatar.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
:host {
display: flex;
aspect-ratio: 1 / 1;
}
img {
Comment thread
scriptcoded marked this conversation as resolved.
border-radius: 50%;
}
47 changes: 47 additions & 0 deletions packages/ui-webc/src/components/avatar/avatar.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import {
Component,
type ComponentInterface,
getAssetPath,
h,
Prop,
Comment thread
scriptcoded marked this conversation as resolved.
} from "@stencil/core";

/**
* The avatar component is used to display the user's profile picture.
* Wrap it with a container, to determine its size, since it scales to fit container.
*/
@Component({
tag: "scout-avatar",
styleUrl: "avatar.css",
shadow: {
delegatesFocus: true,
},
assetsDirs: ["assets"],
})
export class ScoutAvatar implements ComponentInterface {
/**
* The source URL of the user image.
*/
@Prop() imageSrc = "";

/**
* The name of the user.
*/
@Prop() alt = "";

render() {
const getImagePath = () => {
if (this.imageSrc) {
return this.imageSrc;
}
try {
return getAssetPath("assets/fallbackImage.png");
} catch (_e) {
console.info("In storybook, rendering from storybook asset");
return "fallbackImage.png";
}
};

return <img src={getImagePath()} alt={this.alt} />;
Comment thread
daBack marked this conversation as resolved.
}
}
21 changes: 21 additions & 0 deletions packages/ui-webc/src/components/avatar/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# scout-avatar

<!-- Auto Generated Below -->


## Overview

The avatar component is used to display the user's profile picture.
Wrap it with a container, to determine its size, since it scales to fit container.

## Properties

| Property | Attribute | Description | Type | Default |
| ---------- | ----------- | --------------------------------- | -------- | ------- |
| `alt` | `alt` | The name of the user. | `string` | `""` |
| `imageSrc` | `image-src` | The source URL of the user image. | `string` | `""` |


----------------------------------------------

*Built with [StencilJS](https://stenciljs.com/)*