Skip to content
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

feat(pin): add stream animation #34

Merged
merged 2 commits into from
May 21, 2024
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
143 changes: 103 additions & 40 deletions projects/kit/documentation.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion projects/kit/src/components/avatar/avatar.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ export const Text: Story = {
</div> `,
}),
};
export const WithBadge: Story = OnElement;
export const WithBadge = OnElement;
2 changes: 1 addition & 1 deletion projects/kit/src/components/badge/badge.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,4 @@ export const Attribute: Story = {
}),
};

export const Avatar: Story = OnElement;
export const Avatar = OnElement;
28 changes: 25 additions & 3 deletions projects/kit/src/components/pin/pin.component.scss
Original file line number Diff line number Diff line change
@@ -1,7 +1,29 @@
zen-pin {
zen-pin,
zen-pin.stream::before {
display: block;
height: 10px;
width: 10px;
height: 8px;
width: 8px;
border-radius: 50%;
background-color: #6b7280;
}

zen-pin {
position: relative;

&.stream::before {
content: '';
position: absolute;
top: 50%;
left: 50%;
translate: -50% -50%;
animation: stream 1s ease-in-out infinite;
}
}

@keyframes stream {
75%,
100% {
transform: scale(2);
opacity: 0;
}
}
19 changes: 18 additions & 1 deletion projects/kit/src/components/pin/pin.component.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import {
booleanAttribute,
ChangeDetectionStrategy,
Component,
HostBinding,
input,
ViewEncapsulation,
} from '@angular/core';

import type { BooleanAttribute } from '../../types';

/**
* The ZenPinComponent represents a simple visual pin with a circular shape.
*
Expand All @@ -24,4 +29,16 @@ import {
encapsulation: ViewEncapsulation.None,
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class ZenPinComponent {}
export class ZenPinComponent {
/**
* Displays waving stream animation
*/
readonly stream = input<boolean, BooleanAttribute>(false, {
transform: booleanAttribute,
});

@HostBinding('class.stream')
get classStream() {
return this.stream();
}
}
50 changes: 39 additions & 11 deletions projects/kit/src/components/pin/pin.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,16 @@ export default {
title: 'Components/Pin',
component: ZenPinComponent,
tags: ['autodocs'],
render: args => ({ props: { ...args }, template: `<zen-pin />` }),
argTypes: {
stream: { control: 'boolean' },
},
args: {
stream: false,
},
render: args => ({
props: { ...args },
template: `<zen-pin ${args.stream ? 'stream' : ''}/>`,
}),
} satisfies Meta<ZenPinComponent>;

type Story = StoryObj<ZenPinComponent>;
Expand All @@ -23,17 +32,36 @@ export const OnElement: Story = {
],
render: () => ({
template: `
<div style="display: flex; gap: 1rem; --zen-badge-offset: -4px">
<zen-badge>
<zen-pin topRight style="background-color: #2a912a; border: 2px solid white"/>
<zen-avatar src="https://picsum.photos/32" />
</zen-badge>
<div style="display: flex; gap: 1rem; --zen-badge-offset: -4px">
<zen-badge>
<zen-pin topRight style="background-color: #2a912a; border: 2px solid white"/>
<zen-avatar src="https://picsum.photos/32" />
</zen-badge>

<zen-badge>
<zen-pin bottomRight style="background-color: #c42929; border: 2px solid white"/>
<zen-avatar style="color:white">AB</zen-avatar>
</zen-badge>
</div>
`,
}),
};

<zen-badge>
<zen-pin bottomRight style="background-color: #c42929; border: 2px solid white"/>
<zen-avatar style="color:white">AB</zen-avatar>
</zen-badge>
</div>
export const StreamAttribute: Story = {
decorators: [
moduleMetadata({
imports: [ZenPinComponent, ZenAvatarComponent, ZenBadgeComponent],
}),
],
args: {
stream: true,
},
render: args => ({
template: `
<zen-badge style="--zen-badge-offset: -4px">
<zen-pin ${args.stream ? 'stream' : ''} topRight style="border: 2px solid white"/>
<zen-avatar src="https://github.com/Kordrad.png" />
</zen-badge>
`,
}),
};
11 changes: 11 additions & 0 deletions projects/kit/src/types/booleanAttribute.type.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/**
* Use it when you use `booleanAttribute` for transform in angular input
* @example
* ```typescript
* input<boolean, BooleanAttribute>(false, {
* transform: booleanAttribute
* });
* ```
*/

export type BooleanAttribute = boolean | 'true' | 'false' | '';
1 change: 1 addition & 0 deletions projects/kit/src/types/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './booleanAttribute.type';
Loading