diff --git a/README.md b/README.md index 13ee6f6..e32f684 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,7 @@ [hanspoon](https://github.com/TeamCooks/hanspoon) 프로젝트의 페이지 개선을 목표로 하는 프로젝트입니다. 원본 페이지: https://spoonacular.com/ +hanspoon 페이지: https://hanspoon-31cd9.web.app/ ## 🛠 사용기술 diff --git a/public/index.html b/public/index.html index 13efb63..7740000 100644 --- a/public/index.html +++ b/public/index.html @@ -27,5 +27,9 @@

The service is not available normally.

+ +
+
+
diff --git a/src/components/CookingInfo/CookingInfo.styled.tsx b/src/components/CookingInfo/CookingInfo.styled.tsx index 345eafa..42613c2 100644 --- a/src/components/CookingInfo/CookingInfo.styled.tsx +++ b/src/components/CookingInfo/CookingInfo.styled.tsx @@ -7,7 +7,7 @@ export const StyledDL = styled.dl` color: #cbcbcb; font-size: ${pxToRem(24)}; padding: ${pxToRem(10)} 0; - max-width: ${pxToRem(400)}; + width: 100%; `; export const StyledDiv = styled.div` diff --git a/src/components/Loading/Loading.stories.tsx b/src/components/Loading/Loading.stories.tsx new file mode 100644 index 0000000..21a3373 --- /dev/null +++ b/src/components/Loading/Loading.stories.tsx @@ -0,0 +1,14 @@ +import { ComponentMeta, ComponentStory } from '@storybook/react'; +import { Loading } from './Loading'; + +export default { + title: 'Loading', + component: Loading, + args: { + message: 'Loading..', + }, +} as ComponentMeta; + +const Template: ComponentStory = (args) => ; + +export const Default = Template.bind({}); diff --git a/src/components/Loading/Loading.styled.tsx b/src/components/Loading/Loading.styled.tsx new file mode 100644 index 0000000..282761e --- /dev/null +++ b/src/components/Loading/Loading.styled.tsx @@ -0,0 +1,10 @@ +import LoadingIcons from 'react-loading-icons'; +import styled from 'styled-components'; + +export const StyledLoadingThreeDots = styled(LoadingIcons.ThreeDots)` + z-index: 400; + position: fixed; + top: 50vh; + left: 50vw; + transform: translate(-50%, -50%); +`; diff --git a/src/components/Loading/Loading.tsx b/src/components/Loading/Loading.tsx new file mode 100644 index 0000000..1e101b2 --- /dev/null +++ b/src/components/Loading/Loading.tsx @@ -0,0 +1,45 @@ +import { useEffect } from 'react'; +import { $ } from 'utils'; +import { StyledLoadingThreeDots } from './Loading.styled'; +import { LoadingProps } from './Loading.types'; + +const loadingStartNode = $('loading-start'); +const loadingEndNode = $('loading-end'); + +export const Loading = ({ message, showBackground }: LoadingProps) => { + useEffect(() => { + loadingStartNode.setAttribute('role', 'alert'); + loadingStartNode.insertAdjacentHTML('beforeend', `${message}`); + + return () => { + loadingStartNode.removeAttribute('role'); + loadingStartNode.innerHTML = ''; + + loadingEndNode.insertAdjacentHTML('beforeend', `Finished Loading.`); + setTimeout(() => { + loadingEndNode.innerHTML = ''; + }, 800); + }; + }, [message]); + + return ( + <> + {showBackground ? ( +
+ ) : null} + ; + + ); +}; diff --git a/src/components/Loading/Loading.types.ts b/src/components/Loading/Loading.types.ts new file mode 100644 index 0000000..68e29f9 --- /dev/null +++ b/src/components/Loading/Loading.types.ts @@ -0,0 +1,4 @@ +export interface LoadingProps { + message: string; + showBackground: boolean; +} diff --git a/src/components/index.ts b/src/components/index.ts index 5929d65..dc91dd7 100644 --- a/src/components/index.ts +++ b/src/components/index.ts @@ -1,2 +1,3 @@ export * from './App/App'; export * from './CookingInfo/CookingInfo'; +export * from './Loading/Loading'; diff --git a/src/styles/GlobalStyle.ts b/src/styles/GlobalStyle.ts index c05f905..bb09b19 100644 --- a/src/styles/GlobalStyle.ts +++ b/src/styles/GlobalStyle.ts @@ -122,4 +122,15 @@ export const GlobalStyle = createGlobalStyle` figure { margin: 0; } + + /* 접근성 관련 css */ + .a11yHidden { + overflow: hidden; + position: absolute !important; + clip: rect(0, 0, 0, 0); + clip-path: inset(50%); + width: 1px; + height: 1px; + margin: -1px; + } `; diff --git a/src/utils/dom.ts b/src/utils/dom.ts new file mode 100644 index 0000000..97ac82b --- /dev/null +++ b/src/utils/dom.ts @@ -0,0 +1,4 @@ +export const $ = (selector: string) => { + const element = document.querySelector(selector); + return element as T; +}; diff --git a/src/utils/index.ts b/src/utils/index.ts index 54fcd80..42bc1cc 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -1 +1,2 @@ export * from './style'; +export * from './dom';