Skip to content

Commit

Permalink
fix: png format 기본 사용 & image config 수정 & 테스트 케이스 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
steven-yn committed Nov 8, 2023
1 parent 6afb1ef commit 0a124d9
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 13 deletions.
13 changes: 12 additions & 1 deletion next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,17 @@
const { createVanillaExtractPlugin } = require('@vanilla-extract/next-plugin');
const withVanillaExtract = createVanillaExtractPlugin();

const nextConfig = {};
const nextConfig = {
images: {
remotePatterns: [
{
protocol: 'https',
hostname: '**.brand-ing.me',
},
],
// loader: 'custom',
// loaderFile: './utils/image/cloudFlareLoader.ts',
},
};

module.exports = withVanillaExtract(nextConfig);
18 changes: 17 additions & 1 deletion src/components/storybook/IconBoard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,17 @@ const IconBoard = () => {

interface SocialProps {
company: CompanyIconToken;
format?: 'png' | 'svg';
}

const Social = ({ company }: SocialProps) => {
const Social = ({ company, format }: SocialProps) => {
return (
<>
<Icon
width={32}
height={32}
company={company}
format={format}
color="BRAND"
background="NONE"
state="DEFAULT"
Expand All @@ -47,6 +49,7 @@ const Social = ({ company }: SocialProps) => {
width={32}
height={32}
company={company}
format={format}
color="BRAND"
background="CIRCULAR"
state="DEFAULT"
Expand All @@ -55,6 +58,7 @@ const Social = ({ company }: SocialProps) => {
width={32}
height={32}
company={company}
format={format}
color="BRAND"
background="RECTANGLAR"
state="DEFAULT"
Expand All @@ -64,6 +68,7 @@ const Social = ({ company }: SocialProps) => {
width={32}
height={32}
company={company}
format={format}
color="GRAY"
background="NONE"
state="DEFAULT"
Expand All @@ -72,6 +77,7 @@ const Social = ({ company }: SocialProps) => {
width={32}
height={32}
company={company}
format={format}
color="GRAY"
background="CIRCULAR"
state="DEFAULT"
Expand All @@ -80,6 +86,7 @@ const Social = ({ company }: SocialProps) => {
width={32}
height={32}
company={company}
format={format}
color="GRAY"
background="RECTANGLAR"
state="DEFAULT"
Expand All @@ -89,6 +96,7 @@ const Social = ({ company }: SocialProps) => {
width={32}
height={32}
company={company}
format={format}
color="GRAY"
background="NONE"
state="HOVER"
Expand All @@ -97,6 +105,7 @@ const Social = ({ company }: SocialProps) => {
width={32}
height={32}
company={company}
format={format}
color="GRAY"
background="CIRCULAR"
state="HOVER"
Expand All @@ -105,6 +114,7 @@ const Social = ({ company }: SocialProps) => {
width={32}
height={32}
company={company}
format={format}
color="GRAY"
background="RECTANGLAR"
state="HOVER"
Expand All @@ -114,6 +124,7 @@ const Social = ({ company }: SocialProps) => {
width={32}
height={32}
company={company}
format={format}
color="WHITE"
background="NONE"
state="DEFAULT"
Expand All @@ -122,6 +133,7 @@ const Social = ({ company }: SocialProps) => {
width={32}
height={32}
company={company}
format={format}
color="WHITE"
background="CIRCULAR"
state="DEFAULT"
Expand All @@ -130,6 +142,7 @@ const Social = ({ company }: SocialProps) => {
width={32}
height={32}
company={company}
format={format}
color="WHITE"
background="RECTANGLAR"
state="DEFAULT"
Expand All @@ -139,6 +152,7 @@ const Social = ({ company }: SocialProps) => {
width={32}
height={32}
company={company}
format={format}
color="WHITE"
background="RECTANGLAR"
state="HOVER"
Expand All @@ -147,6 +161,7 @@ const Social = ({ company }: SocialProps) => {
width={32}
height={32}
company={company}
format={format}
color="WHITE"
background="RECTANGLAR"
state="HOVER"
Expand All @@ -155,6 +170,7 @@ const Social = ({ company }: SocialProps) => {
width={32}
height={32}
company={company}
format={format}
color="WHITE"
background="RECTANGLAR"
state="HOVER"
Expand Down
25 changes: 15 additions & 10 deletions src/composable/Icon/Icon.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
iconStateTokens,
} from '@/mock/iconTokens.mock';
import { randomIndex, randomBetweenNumber } from '@/utils/number/random';
import iconResourceSrcFormat from '@/utils/string/iconResourceSrcFormat';
import capitalizeFirstLetter from '@/utils/string/capitalizeFirstLetter';
import Icon from './Icon';

describe('Icon 컴포넌트', () => {
Expand Down Expand Up @@ -36,19 +36,24 @@ describe('Icon 컴포넌트', () => {
expect(image).toHaveAttribute('height', testProps.size.toString());
expect(image).toHaveAttribute('alt', testProps.company);

const resource = iconResourceSrcFormat({
company: testProps.company,
color: testProps.color,
background: testProps.background,
state: testProps.state,
});
expect(image).toHaveAttribute(
'src',
expect.stringContaining(`${capitalizeFirstLetter(testProps.company)}`),
);

expect(image).toHaveAttribute(
'src',
expect.stringContaining(`${capitalizeFirstLetter(testProps.color)}`),
);

const path = `${ASSET_ENDPOINT}/icons/${testProps.company.toLowerCase()}`;
const imageSrc = `${path}/${resource}`;
expect(image).toHaveAttribute(
'src',
expect.stringContaining(`${capitalizeFirstLetter(testProps.background)}`),
);

expect(image).toHaveAttribute(
'src',
expect.stringContaining(`${imageSrc}`),
expect.stringContaining(`${capitalizeFirstLetter(testProps.state)}`),
);
});
});
2 changes: 1 addition & 1 deletion src/composable/Icon/Icon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const Icon = ({
return (
<Image
{...props}
src={`${path}/${resource}.${format || 'svg'}`}
src={`${path}/${resource}.${format || 'png'}`}
alt={company}
/>
);
Expand Down
15 changes: 15 additions & 0 deletions src/utils/image/cloudFlareLoader.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { ASSET_ENDPOINT } from '@/const/endpoint';

// Docs: https://developers.cloudflare.com/images/url-format
export default function cloudflareLoader({
src,
width,
quality,
}: {
src: string;
width: number;
quality?: number;
}) {
const params = [`width=${width}`, `quality=${quality || 75}`, 'format=auto'];
return `${ASSET_ENDPOINT}/cdn-cgi/image/${params.join(',')}/${src}`;
}

0 comments on commit 0a124d9

Please sign in to comment.