Skip to content

Commit

Permalink
[revise]: revise animation & add code highlight
Browse files Browse the repository at this point in the history
  • Loading branch information
IMHOJEONG committed Dec 22, 2023
1 parent 1050e5b commit 9430e5b
Show file tree
Hide file tree
Showing 19 changed files with 217 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,16 @@ export const hooks: DataProps = {
- Hook을 사용하면 컴포넌트에서 다양한 React 기능을 사용 가능
- 자신만의 Hook을 생성 가능
1. State Hooks
- 상태를 통해 컴포넌트는 사용자 입력과 같은 정보를 "기억"할 수 있습니다.
- "useState" : 직접 업데이트할 수 있는 상태 변수를 선언
- "useReducer" : 리듀서 함수 내부의 업데이트 논리를 사용해 상태 변수를 선언
\`\`\`javascript
const div = 'test'
\`\`\`
1. State Hooks tt
- 상태를 통해 컴포넌트는 사용자 입력과 같은 정보를 "기억"할 수 있습니다.
- "useState" : 직접 업데이트할 수 있는 상태 변수를 선언
- "useReducer" : 리듀서 함수 내부의 업데이트 논리를 사용해 상태 변수를 선언
`,
};
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { IsNotEmpty, Length } from 'class-validator';
export class SearchArticleDto {
@ApiProperty({
description: '???',
example: 'TEst',
example: '내장',
})
@IsNotEmpty()
@Length(2, 255)
Expand Down
5 changes: 4 additions & 1 deletion apps/pwrcode-frontend/app/design/atoms/Form/Form.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ export const SkillForm: Story = {
placeholder: 'Skills',
appearance: 'none',
background: '#fff',
border: '1px solid #c2d1d9',
border: '3px solid #c2d1d9',
borderRadius: '10px',
color: 'black',
},
};
Expand All @@ -35,6 +36,7 @@ export const KeyWordForm: Story = {
placeholder: 'type keyword...',
appearance: 'none',
background: '#fff',
fontFamily: 'Ubuntu',
border: '1px solid #c2d1d9',
color: 'black',
},
Expand All @@ -46,6 +48,7 @@ export const SearchKeyWordForm: Story = {
appearance: 'none',
background: '#fff',
border: '1px solid #c2d1d9',
fontFamily: 'Ubuntu',
width: '10vmax',
color: 'black',
},
Expand Down
6 changes: 5 additions & 1 deletion apps/pwrcode-frontend/app/design/atoms/Form/Form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import { useAtom } from 'jotai';
export interface FormProps {
placeholder: string;
border?: string;
fontFamily?: string;
borderRadius?: string;
appearance?: string;
background?: string;
color?: string;
Expand All @@ -25,7 +27,7 @@ export function SearchForm(props: FormProps) {
{...props}
value={keyword.keyword}
onChange={(e) => {
setKeyword({ keyword: e.target.value });
setKeyword({ ...keyword, keyword: e.target.value });
}}
/>
);
Expand All @@ -37,6 +39,8 @@ const Component = styled.input<FormProps>`
background: ${(props) => props.background};
border: ${(props) => props.border};
color: ${(props) => props.color};
border-radius: ${(props) => props.borderRadius};
font-family: ${(props) => props.fontFamily};
padding: 10px 20px;
&::placeholder {
color: #c2d1d9;
Expand Down
11 changes: 6 additions & 5 deletions apps/pwrcode-frontend/app/design/atoms/TextArea/TextArea.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import Markdown from 'react-markdown';
import React from 'react';
import remarkMdx from 'remark-mdx';
import remarkBreaks from 'remark-breaks';
import Image from 'next/image';
import Editor from '@monaco-editor/react';

export interface TextAreaProps {
fontFamily: string;
Expand Down Expand Up @@ -55,10 +55,11 @@ export function TextArea(props: TextAreaProps) {
components={{
img(props) {
const { src, ...rest } = props;
return <img
src={src}
width={'100vw'}
{...rest} />;
return <img src={src} width={'100vw'} {...rest} />;
},
code(props) {
const { children, className, node, ...rest } = props;
return <Editor defaultValue={String(children)} />;
},
}}
remarkPlugins={[remarkMdx, remarkBreaks]}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ export const MainCard: Story = {
justifyContent: 'space-between',
alignItems: 'center',
width: '30vmax',
height: '50vmax',
height: '50vmin',
border: '10px solid rgba(176, 166, 149, 0.50)',
padding: '1.19rem 1.75rem 3.25rem 1.75rem',
animation: '15s linear 1s infinite running slideintest',
// padding: '1.19rem 1.75rem 3.25rem 1.75rem',
// animation: '15s linear 1s infinite running slideintest',
background: '#F2F5F7',
children: (
<>
Expand Down Expand Up @@ -75,8 +75,7 @@ export const SearchCardStory: Story = {
justifyContent: 'space-between',
alignItems: 'center',
width: '75vmax',
height: '50vmax',
gap: '10px',
height: '85vmin',
border: '10px solid rgba(176, 166, 149, 0.50)',
// padding: '1.19rem 0 3.25rem 0',
background: '#F2F5F7',
Expand Down
1 change: 0 additions & 1 deletion apps/pwrcode-frontend/app/design/molecules/Card/Card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ export interface CardProps extends PropsWithChildren {
}

export function Card(props: CardProps) {

return (
<Component
width={props.width}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ export const MainDropDown: Story = {
args: {
appearance: 'none',
background: '#fff',
border: '1px solid #c2d1d9',
border: '3px solid #c2d1d9',
borderRadius: '10px',
fontFamily: 'Ubuntu',
color: 'black',
data: [
{ value: 'React', name: 'React' },
Expand All @@ -46,9 +48,13 @@ export const SelectDropDown: Story = {
args: {
appearance: 'none',
background: '#fff',
border: '1px solid #c2d1d9',
border: '3px solid #c2d1d9',
borderRadius: '10px',
color: 'black',
width: '10vmax',
height: '10vmin',
fontFamily: 'Ubuntu',
fontSize: '1.2rem',
data: [
{ value: 'React', name: 'React' },
{ value: 'Vue', name: 'Vue' },
Expand Down
25 changes: 24 additions & 1 deletion apps/pwrcode-frontend/app/design/molecules/DropDown/DropDown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import { FunctionComponent, ReactElement, PropsWithChildren } from 'react';
import React from 'react';
import styled from '@emotion/styled';
import { useAtom } from 'jotai';
import { searchKeywordAtom } from '@/app/state';

interface DropDownDataObj {
value: string;
Expand All @@ -11,10 +13,14 @@ interface DropDownProps extends PropsWithChildren {
data?: DropDownDataObj[];
placeholder?: string;
width?: string;
height?: string;
border?: string;
borderRadius?: string;
appearance?: string;
background?: string;
fontFamily?: string;
color?: string;
fontSize?: string;
}

export function DropDown(props: DropDownProps) {
Expand All @@ -28,13 +34,26 @@ export function DropDown(props: DropDownProps) {
},
);

const [keyword, setKeyword] = useAtom(searchKeywordAtom);

return (
<Component
width={props.width}
height={props.height}
appearance={props.appearance}
background={props.background}
border={props.border}
borderRadius={props.borderRadius}
color={props.color}
fontSize={props.fontSize}
fontFamily={props.fontFamily}
value={keyword.skill}
onChange={(e) => {
setKeyword({
...keyword,
skill: e.target.value,
});
}}
>
{optionsList}
</Component>
Expand All @@ -43,13 +62,16 @@ export function DropDown(props: DropDownProps) {

const Component = styled.select<DropDownProps>`
width: ${(props) => props.width};
height: ${(props) => props.height};
& select {
appearance: ${(props) => props.appearance};
}
background: ${(props) => props.background};
border: ${(props) => props.border};
border-radius: ${(props) => props.borderRadius};
color: ${(props) => props.color};
font-size: ${(props) => props.fontSize};
font-family: ${(props) => props.fontFamily};
padding: 10px 20px;
&::placeholder {
color: #c2d1d9;
Expand All @@ -63,6 +85,7 @@ const Component = styled.select<DropDownProps>`
&:focus {
outline: 1px solid black;
}
cursor: pointer;
`;

const OptionComponent = styled.option``;
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ export const MainCardGroup: Story = {
// primary: true,
width: '35vmax',
padding: '1.17rem',
justifyContent: 'center',
alignItems: 'center',
children: (
<>
<CardGroupMainDataServerComponent />
Expand All @@ -51,6 +53,7 @@ export const SearchCardGroupStory: Story = {
width: '80vmax',
justifyContent: 'stretch',
alignItems: 'center',
gap: '10px',
padding: '6.03vmax 1.158vmax 10px 1.158vmax',
overflow: 'scroll',
children: <CardGroupSearchDataServerComponent />,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export interface CardGroupProps extends PropsWithChildren {
justifyContent?: string;
alignItems?: string;
data?: ResponseBodyProps;
gap?: string;
}

export function CardGroup(props: CardGroupProps) {
Expand All @@ -38,6 +39,7 @@ export function CardGroup(props: CardGroupProps) {
zIndex={props.zIndex}
justifyContent={props.justifyContent}
alignItems={props.alignItems}
gap={props.gap}
>
{props.children}
</Component>
Expand All @@ -49,9 +51,9 @@ const Component = styled.div<CardGroupProps>`
width: ${(props) => props.width};
height: ${(props) => props.height};
flex-direction: column;
gap: ${(props) => props.gap};
padding: ${(props) => props.padding};
animation: ${(props) => props.animation};
gap: 10px;
z-index: ${(props) => props.zIndex};
overflow: ${(props) => props.overflow};
justify-content: ${(props) => props.justifyContent};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use client';
import styled from '@emotion/styled';

import { PropsWithChildren } from 'react';
import { PropsWithChildren, useState } from 'react';
import { Text } from '../../atoms/Text/Text';
import { CustomLink } from '../../atoms/Link/Link';

Expand Down Expand Up @@ -32,7 +33,7 @@ import {
} from '@tanstack/react-query';
import { atomsWithQuery } from 'jotai-tanstack-query';

// import styled from '@emotion/styled';
import { motion } from 'framer-motion';

async function getCardData() {
const response = await fetch('http://localhost:4000/search', {
Expand Down Expand Up @@ -106,6 +107,31 @@ export function CardGroupDataServerComponent(
);
}

const StyledMainComponent = styled.div`
display: flex;
position: relative;
flex-direction: column;
align-items: center;
justify-content: center;
gap: 10px;
/* animation: 30s fadein 1s infinite running slideintest; */
/* &:hover {
animation-play-state: paused;
} */
& > div {
/* transform: translate(100vmin, 0px); */
/* animation: 5s ease-in infinite normal forwards slidein; */
position: absolute;
height: 75vmin;
}
`;

const variants = {
open: { x: 0, y: 0, zIndex: 3 },
closed: { x: '1vmax', y: '1vmax', zIndex: 2 },
boxed: { x: '0vw', y: '70vh', zIndex: 1 },
};

export function CardGroupMainDataServerComponent(
props: CardDataServerComponentProps,
) {
Expand All @@ -124,18 +150,38 @@ export function CardGroupMainDataServerComponent(
throw new Error('Failed to fetch');
}

const [cardsState, setCardsState] = useState([1, 0, -1]);

return (
<>
{data?.hits?.map((item) => {
<StyledMainComponent>
{data?.hits?.map((item, index) => {
return (
<Card {...MainCard.args} data={item}>
<Text {...ReactText.args} text={item.title} />
<TextArea {...SearchTextArea.args} text={item.content} />
<CustomLink {...MainLink.args} href={item.link} />
</Card>
<motion.div
variants={variants}
transition={{ type: 'spring', stiffness: 100 }}
onClick={() => {
const copyArr = new Array(3).fill(-1);
copyArr[index] = 1;
copyArr[(index + 1) % copyArr.length] = 0;
setCardsState(copyArr);
}}
animate={
cardsState[index] === 1
? 'open'
: cardsState[index] === 0
? 'closed'
: 'boxed'
}
>
<Card {...MainCard.args} data={item}>
<Text {...ReactText.args} text={item.title} />
<TextArea {...SearchTextArea.args} text={item.content} />
<CustomLink {...MainLink.args} href={item.link} />
</Card>
</motion.div>
);
})}
</>
</StyledMainComponent>
);
}

Expand Down
Loading

0 comments on commit 9430e5b

Please sign in to comment.