-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: theme * test: add theme * chore: update readme
- Loading branch information
Showing
13 changed files
with
171 additions
and
29 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
type Theme = Record< | ||
string, | ||
{ | ||
color: string | ||
background: string | ||
} | ||
> | ||
|
||
export const THEME: Theme = { | ||
summer: { | ||
color: 'white', | ||
background: 'linear-gradient(to bottom right, #74dcc4, #4597e9)' | ||
}, | ||
blue_chill: { | ||
color: 'white', | ||
background: 'linear-gradient(to bottom right, #5580eb, #2aeeff)' | ||
}, | ||
rainbow: { | ||
color: 'white', | ||
background: | ||
'linear-gradient(to bottom, #CD001A 0%, #CD001A 14.72%, #F06400 14.72%, ' + | ||
'#F06400 28.56%, #F2CD00 28.56%, #F2CD00 42.84%, #79c300 42.84%, ' + | ||
'#79c300 57.12%, #1961ae 57.12%, #1961ae 71.4%, #31137c 71.4%, ' + | ||
'#31137c 85.24%, #61007d 85.24%, #61007d 100%)' | ||
}, | ||
monica: { | ||
color: 'white', | ||
background: 'linear-gradient(to bottom right, #0c7bb3, #f2bae8)' | ||
} | ||
} | ||
|
||
export function getThemeOptions(theme: string): { | ||
color?: string | ||
background?: string | ||
} { | ||
return THEME[theme] ?? {} | ||
} |
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,17 @@ | ||
export function filterNotEmpty<T extends Record<string, unknown>>(obj: T): FilteredObj<T> { | ||
const result = {} as T | ||
|
||
for (const key in obj) { | ||
const value = obj[key] | ||
if (value !== null && value !== undefined) { | ||
result[key] = value | ||
} | ||
} | ||
|
||
// TODO: type | ||
return result as FilteredObj<T> | ||
} | ||
|
||
export type FilteredObj<T> = { | ||
[K in keyof T as Exclude<T[K], undefined | null> extends never ? never : K]: Exclude<T[K], undefined | null> | ||
} |
Binary file added
BIN
+77.1 KB
...l-profile-test-theme-test-ts-theme-render-card-with-blue-chill-theme-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+114 KB
...pixel-profile-test-theme-test-ts-theme-render-card-with-monica-theme-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+19.6 KB
...ixel-profile-test-theme-test-ts-theme-render-card-with-rainbow-theme-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+72.7 KB
...pixel-profile-test-theme-test-ts-theme-render-card-with-summer-theme-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+16.2 KB
...me-test-ts-theme-render-card-with-summer-theme-and-custom-background-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+73 KB
...t-theme-test-ts-theme-render-card-with-summer-theme-and-custom-color-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,63 @@ | ||
import { renderStats } from '../src' | ||
// @ts-expect-error ... | ||
import { toMatchImageSnapshot } from 'jest-image-snapshot' | ||
import { describe, expect, it } from 'vitest' | ||
|
||
declare global { | ||
// eslint-disable-next-line @typescript-eslint/no-namespace | ||
namespace jest { | ||
interface Matchers<R> { | ||
toMatchImageSnapshot(): R | ||
} | ||
} | ||
} | ||
|
||
expect.extend({ toMatchImageSnapshot }) | ||
|
||
const stats = { | ||
name: 'User Name', | ||
username: 'username', | ||
totalStars: 999, | ||
totalCommits: 99999, | ||
totalIssues: 99, | ||
totalPRs: 9, | ||
contributedTo: 9999, | ||
avatarUrl: '', | ||
rank: { | ||
level: 'S', | ||
percentile: 0, | ||
score: 0 | ||
} | ||
} | ||
|
||
describe('Theme', () => { | ||
it('Render card with summer theme and custom color', async () => { | ||
const png = await renderStats(stats, { theme: 'summer', color: 'yellow' }) | ||
expect(png).toMatchImageSnapshot() | ||
}) | ||
|
||
it('Render card with summer theme and custom background', async () => { | ||
const png = await renderStats(stats, { theme: 'summer', background: 'black' }) | ||
expect(png).toMatchImageSnapshot() | ||
}) | ||
|
||
it('Render card with summer theme', async () => { | ||
const png = await renderStats(stats, { theme: 'summer' }) | ||
expect(png).toMatchImageSnapshot() | ||
}) | ||
|
||
it('Render card with blue_chill theme', async () => { | ||
const png = await renderStats(stats, { theme: 'blue_chill' }) | ||
expect(png).toMatchImageSnapshot() | ||
}) | ||
|
||
it('Render card with rainbow theme', async () => { | ||
const png = await renderStats(stats, { theme: 'rainbow' }) | ||
expect(png).toMatchImageSnapshot() | ||
}) | ||
|
||
it('Render card with monica theme', async () => { | ||
const png = await renderStats(stats, { theme: 'monica' }) | ||
expect(png).toMatchImageSnapshot() | ||
}) | ||
}) |