-
Notifications
You must be signed in to change notification settings - Fork 0
feat: Avatar component #104
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
base: main
Are you sure you want to change the base?
Changes from 3 commits
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 |
|---|---|---|
| @@ -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} /> | ||
daBack marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| </div> | ||
| ), | ||
| }); | ||
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,7 @@ | ||||||||||||
| :host { | ||||||||||||
| display: flex; | ||||||||||||
| aspect-ratio: 1 / 1; | ||||||||||||
| } | ||||||||||||
| img { | ||||||||||||
|
||||||||||||
| img { | |
| img { | |
| width: 100%; | |
| height: 100%; | |
| object-fit: cover; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| import { | ||
| Component, | ||
| type ComponentInterface, | ||
| getAssetPath, | ||
| h, | ||
| Prop, | ||
|
Comment on lines
+4
to
+6
|
||
| } 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"], | ||
| }) | ||
|
|
||
| /** | ||
| * | ||
| */ | ||
daBack marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| export class ScoutAvatar implements ComponentInterface { | ||
| /** | ||
| * The source URL of the user image. | ||
| */ | ||
| @Prop() imageSrc = ""; | ||
daBack marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| /** | ||
| * 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} />; | ||
daBack marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
| 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/)* |
Uh oh!
There was an error while loading. Please reload this page.