-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #276 from SaekKkanDa/develop
v1.0.0 배포
- Loading branch information
Showing
98 changed files
with
3,176 additions
and
1,297 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
interface ErrorResponse { | ||
code: number; | ||
message: string; | ||
} |
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,12 @@ | ||
import styled from 'styled-components'; | ||
|
||
export const Backdrop = styled.div` | ||
position: fixed; | ||
top: 0; | ||
left: 0; | ||
width: 100%; | ||
height: 100%; | ||
background-color: ${({ theme }) => theme.gray[900]}; | ||
opacity: 0.6; | ||
z-index: 10; | ||
`; |
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 |
---|---|---|
@@ -1,33 +1,33 @@ | ||
import { CSSProperties, ReactNode } from 'react'; | ||
import styled from 'styled-components'; | ||
|
||
export interface HiddenProps { | ||
isHidden: boolean; | ||
isUseVisibility?: boolean; | ||
style?: CSSProperties; | ||
children?: ReactNode; | ||
} | ||
export function Hidden({ | ||
isHidden, | ||
isUseVisibility = false, | ||
style, | ||
children, | ||
}: HiddenProps) { | ||
return ( | ||
<HiddenContainer | ||
isHidden={isHidden} | ||
isUseVisibility={isUseVisibility} | ||
style={style} | ||
> | ||
{children} | ||
</HiddenContainer> | ||
); | ||
} | ||
|
||
const HiddenContainer = styled.div<{ | ||
isHidden: boolean; | ||
isUseVisibility: boolean; | ||
}>` | ||
${({ isUseVisibility, isHidden }) => | ||
isHidden && (isUseVisibility ? 'visiblity : hidden' : 'display : none')} | ||
`; | ||
import { CSSProperties, ReactNode } from 'react'; | ||
import styled from 'styled-components'; | ||
|
||
export interface HiddenProps { | ||
isHidden: boolean; | ||
isUseVisibility?: boolean; | ||
style?: CSSProperties; | ||
children?: ReactNode; | ||
} | ||
export function Hidden({ | ||
isHidden, | ||
isUseVisibility = false, | ||
style, | ||
children, | ||
}: HiddenProps) { | ||
return ( | ||
<HiddenContainer | ||
isHidden={isHidden} | ||
isUseVisibility={isUseVisibility} | ||
style={style} | ||
> | ||
{children} | ||
</HiddenContainer> | ||
); | ||
} | ||
|
||
const HiddenContainer = styled.div<{ | ||
isHidden: boolean; | ||
isUseVisibility: boolean; | ||
}>` | ||
${({ isUseVisibility, isHidden }) => | ||
isHidden && (isUseVisibility ? 'visiblity : hidden' : 'display : none')} | ||
`; |
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,15 @@ | ||
import { useEffect, useState } from 'react'; | ||
import { createPortal } from 'react-dom'; | ||
|
||
// next js client component should be rendered after window object is created | ||
// https://stackoverflow.com/questions/75408148/referenceerror-document-is-not-defined-inside-next-js-client-component | ||
export default function useCreatePortal() { | ||
const [isMounted, setIsMounted] = useState(false); | ||
useEffect(() => { | ||
setIsMounted(true); | ||
}, []); | ||
|
||
if (!isMounted) return null; | ||
|
||
return createPortal; | ||
} |
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,31 @@ | ||
import { useCallback, useEffect, useRef } from 'react'; | ||
|
||
export const useIntersectionObserver = ( | ||
onIntersect: ( | ||
entry: IntersectionObserverEntry, | ||
observer: IntersectionObserver | ||
) => void, | ||
options?: IntersectionObserverInit | ||
) => { | ||
const ref = useRef<HTMLDivElement>(null); | ||
|
||
const callback = useCallback( | ||
(entries: IntersectionObserverEntry[], observer: IntersectionObserver) => { | ||
entries.forEach((entry) => { | ||
if (entry.isIntersecting) onIntersect(entry, observer); | ||
}); | ||
}, | ||
[onIntersect] | ||
); | ||
|
||
useEffect(() => { | ||
if (!ref.current) return; | ||
|
||
const observer = new IntersectionObserver(callback, options); | ||
observer.observe(ref.current); | ||
|
||
return () => observer.disconnect(); | ||
}, [ref, options, callback]); | ||
|
||
return { ref }; | ||
}; |
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,24 @@ | ||
import { useEffect, useRef, useState } from 'react'; | ||
|
||
export interface UseLazyUpateProps<T> { | ||
state: T; | ||
time?: number; | ||
} | ||
|
||
export default function useLazyUpdate<T>({ | ||
state, | ||
time = 500, | ||
}: UseLazyUpateProps<T>) { | ||
const timeRef = useRef(time); | ||
const [localState, setLocalState] = useState(state); | ||
|
||
useEffect(() => { | ||
const timoutId = setTimeout(() => setLocalState(state), timeRef.current); | ||
|
||
return () => { | ||
clearTimeout(timoutId); | ||
}; | ||
}, [state]); | ||
|
||
return localState; | ||
} |
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 |
---|---|---|
@@ -1,31 +1,31 @@ | ||
import { useCallback, useEffect, useState } from 'react'; | ||
import { useCallback, useEffect, useRef } from 'react'; | ||
|
||
import { isFalse } from '@Base/utils/check'; | ||
import { isNil } from '@Base/utils/check'; | ||
|
||
export interface UseTriggerProps { | ||
triggerFn?: () => boolean; | ||
onTrigger?: (reset: () => void) => void; | ||
} | ||
|
||
export function useTrigger({ triggerFn, onTrigger }: UseTriggerProps) { | ||
const [isTriggered, setIsTriggered] = useState(false); | ||
const isTrigredRef = useRef(false); | ||
|
||
const reset = useCallback(() => { | ||
setIsTriggered(false); | ||
isTrigredRef.current = false; | ||
}, []); | ||
|
||
const trigger = useCallback(() => { | ||
setIsTriggered(true); | ||
isTrigredRef.current = true; | ||
}, []); | ||
|
||
useEffect(() => { | ||
if (isFalse(triggerFn)) return; | ||
if (isNil(triggerFn)) return; | ||
|
||
if (triggerFn()) { | ||
setIsTriggered(true); | ||
if (!isTrigredRef.current && triggerFn()) { | ||
isTrigredRef.current = true; | ||
onTrigger?.(reset); | ||
} | ||
}, [onTrigger, reset, triggerFn]); | ||
|
||
return { isTriggered, reset, trigger }; | ||
return { isTriggered: isTrigredRef.current, reset, trigger }; | ||
} |
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 |
---|---|---|
@@ -1,22 +1,22 @@ | ||
/** | ||
* checking object if is null + undefined or not | ||
* if object is 0, this functions consider as true | ||
*/ | ||
export function isFalse<T>(obj: T | undefined | null): obj is undefined | null { | ||
if (obj === undefined || obj === null) return true; | ||
|
||
return false; | ||
} | ||
|
||
/** | ||
* checking object if is null + undefined or not | ||
* if object is 0, this functions consider as true | ||
*/ | ||
export function isTrue<T>(obj: T | undefined | null): obj is T { | ||
return !isFalse(obj); | ||
} | ||
|
||
export function isEmpty<T extends string | Array<unknown>>(obj: T) { | ||
if (obj.length === 0) return true; | ||
return false; | ||
} | ||
/** | ||
* checking object if is null + undefined or not | ||
* if object is 0, this functions consider as true | ||
*/ | ||
export function isNil<T>(obj: T | undefined | null): obj is undefined | null { | ||
if (obj === undefined || obj === null) return true; | ||
|
||
return false; | ||
} | ||
|
||
/** | ||
* checking object if is null + undefined or not | ||
* if object is 0, this functions consider as true | ||
*/ | ||
export function isNotNil<T>(obj: T | undefined | null): obj is T { | ||
return !isNil(obj); | ||
} | ||
|
||
export function isEmpty<T extends string | Array<unknown>>(obj: T) { | ||
if (obj.length === 0) return true; | ||
return false; | ||
} |
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,11 @@ | ||
import { isNil } from '@Base/utils/check'; | ||
|
||
export function getRandomId() { | ||
return Math.random().toString(16).slice(2); | ||
} | ||
|
||
export function withDefault<T>(obj: T | null | undefined, defaultValue: T): T { | ||
if (isNil(obj)) return defaultValue; | ||
|
||
return obj; | ||
} |
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,12 @@ | ||
export async function loadImg(src: string) { | ||
return new Promise<HTMLImageElement>((resolve, reject) => { | ||
const img = new Image(); | ||
img.onload = () => { | ||
resolve(img); | ||
}; | ||
img.onerror = (err) => { | ||
reject(err); | ||
}; | ||
img.src = src; | ||
}); | ||
} |
Oops, something went wrong.