-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
172 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import { Component, computed, input } from '@angular/core'; | ||
import type { PullRequestLabel } from '@app/core/modules/openapi'; | ||
import { HlmSkeletonModule } from '@spartan-ng/ui-skeleton-helm'; | ||
|
||
@Component({ | ||
selector: 'app-github-label', | ||
standalone: true, | ||
imports: [HlmSkeletonModule], | ||
styleUrls: ['./github-label.component.scss'], | ||
host: { | ||
'[style.--label-r]': 'colors().r', | ||
'[style.--label-g]': 'colors().g', | ||
'[style.--label-b]': 'colors().b', | ||
'[style.--label-h]': 'colors().h', | ||
'[style.--label-s]': 'colors().s', | ||
'[style.--label-l]': 'colors().l' | ||
}, | ||
template: ` | ||
@if (isLoading()) { | ||
<hlm-skeleton class="w-14 h-6" /> | ||
} @else { | ||
<span class="px-2 py-0.5 rounded-[2rem] text-xs font-medium dark:border gh-label"> | ||
{{ label().name }} | ||
</span> | ||
} | ||
` | ||
}) | ||
export class GithubLabelComponent { | ||
isLoading = input(false); | ||
label = input.required<PullRequestLabel>(); | ||
|
||
protected colors = computed(() => this.hexToRgb(this.label().color ?? 'FFFFFF')); | ||
|
||
hexToRgb(hex: string) { | ||
const bigint = parseInt(hex, 16); | ||
const r = (bigint >> 16) & 255; | ||
const g = (bigint >> 8) & 255; | ||
const b = bigint & 255; | ||
|
||
const hsl = this.rgbToHsl(r, g, b); | ||
|
||
return { | ||
r: r, | ||
g: g, | ||
b: b, | ||
...hsl | ||
}; | ||
} | ||
|
||
rgbToHsl(r: number, g: number, b: number) { | ||
r /= 255; | ||
g /= 255; | ||
b /= 255; | ||
|
||
const max = Math.max(r, g, b); | ||
const min = Math.min(r, g, b); | ||
let h = 0, | ||
s = 0, | ||
l = (max + min) / 2; | ||
|
||
if (max !== min) { | ||
const d = max - min; | ||
s = l > 0.5 ? d / (2 - max - min) : d / (max + min); | ||
switch (max) { | ||
case r: | ||
h = (g - b) / d + (g < b ? 6 : 0); | ||
break; | ||
case g: | ||
h = (b - r) / d + 2; | ||
break; | ||
case b: | ||
h = (r - g) / d + 4; | ||
break; | ||
} | ||
h /= 6; | ||
} | ||
|
||
h = Math.round(h * 360); | ||
s = Math.round(s * 100); | ||
l = Math.round(l * 100); | ||
|
||
return { h, s, l }; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import { argsToTemplate, Meta, StoryObj } from '@storybook/angular'; | ||
import { GithubLabelComponent } from './github-label.component'; | ||
|
||
type FlatArgs = { | ||
isLoading: boolean; | ||
name: string; | ||
color: string; | ||
}; | ||
|
||
function flatArgsToProps(args: FlatArgs) { | ||
return { | ||
isLoading: args.isLoading, | ||
label: { | ||
name: args.name, | ||
color: args.color | ||
} | ||
}; | ||
} | ||
|
||
const meta: Meta<FlatArgs> = { | ||
component: GithubLabelComponent, | ||
tags: ['autodocs'], | ||
args: { | ||
isLoading: false, | ||
name: 'bug', | ||
color: 'f00000' | ||
}, | ||
argTypes: { | ||
isLoading: { | ||
control: { | ||
type: 'boolean' | ||
} | ||
}, | ||
name: { | ||
control: { | ||
type: 'text' | ||
} | ||
}, | ||
color: { | ||
control: { | ||
type: 'text' | ||
} | ||
} | ||
} | ||
}; | ||
|
||
export default meta; | ||
|
||
type Story = StoryObj<GithubLabelComponent>; | ||
|
||
export const Default: Story = { | ||
render: (args) => ({ | ||
props: flatArgsToProps(args as unknown as FlatArgs), | ||
template: `<app-github-label ${argsToTemplate(flatArgsToProps(args as unknown as FlatArgs))} />` | ||
}) | ||
}; | ||
|
||
export const isLoading: Story = { | ||
args: { | ||
isLoading: true | ||
}, | ||
render: (args) => ({ | ||
props: flatArgsToProps(args as unknown as FlatArgs), | ||
template: `<app-github-label ${argsToTemplate(flatArgsToProps(args as unknown as FlatArgs))} />` | ||
}) | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters