chore: optimize useBreakpoint hook
This commit is contained in:
parent
c029423bf9
commit
513960b6a2
7 changed files with 25 additions and 21 deletions
|
@ -28,7 +28,7 @@ const MessageItem: FC<MessageItemProps> = ({ data }) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="grid grid-cols-[auto_1fr] gap-x-2">
|
<div className="grid grid-cols-[auto_1fr] gap-x-2 px-4 first:pt-4 last:pb-4">
|
||||||
<Avatar>
|
<Avatar>
|
||||||
<AvatarImage src={formatData.avatar} />
|
<AvatarImage src={formatData.avatar} />
|
||||||
<AvatarFallback>{formatData.username}</AvatarFallback>
|
<AvatarFallback>{formatData.username}</AvatarFallback>
|
||||||
|
|
|
@ -1,12 +1,15 @@
|
||||||
import { type ReactElement, type FC } from 'react'
|
import { type ReactElement, type FC } from 'react'
|
||||||
|
|
||||||
import { type MessageItemProps } from './MessageItem'
|
import { type MessageItemProps } from './MessageItem'
|
||||||
|
import { ScrollArea } from '@/components/ui/ScrollArea'
|
||||||
|
|
||||||
export interface MessageListProps {
|
export interface MessageListProps {
|
||||||
children?: Array<ReactElement<MessageItemProps>>
|
children?: Array<ReactElement<MessageItemProps>>
|
||||||
}
|
}
|
||||||
const MessageList: FC<MessageListProps> = ({ children }) => {
|
const MessageList: FC<MessageListProps> = ({ children }) => {
|
||||||
return <div className="grid content-start overflow-y-auto p-4">{children}</div>
|
return <ScrollArea>{children}</ScrollArea>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MessageList.displayName = 'MessageList'
|
||||||
|
|
||||||
export default MessageList
|
export default MessageList
|
||||||
|
|
|
@ -8,7 +8,9 @@ const ScrollArea = React.forwardRef<
|
||||||
React.ComponentPropsWithoutRef<typeof ScrollAreaPrimitive.Root>
|
React.ComponentPropsWithoutRef<typeof ScrollAreaPrimitive.Root>
|
||||||
>(({ className, children, ...props }, ref) => (
|
>(({ className, children, ...props }, ref) => (
|
||||||
<ScrollAreaPrimitive.Root ref={ref} className={cn('relative overflow-hidden', className)} {...props}>
|
<ScrollAreaPrimitive.Root ref={ref} className={cn('relative overflow-hidden', className)} {...props}>
|
||||||
<ScrollAreaPrimitive.Viewport className="h-full w-full rounded-[inherit]">{children}</ScrollAreaPrimitive.Viewport>
|
<ScrollAreaPrimitive.Viewport className="h-full w-full overscroll-none rounded-[inherit]">
|
||||||
|
{children}
|
||||||
|
</ScrollAreaPrimitive.Viewport>
|
||||||
<ScrollBar />
|
<ScrollBar />
|
||||||
<ScrollAreaPrimitive.Corner />
|
<ScrollAreaPrimitive.Corner />
|
||||||
</ScrollAreaPrimitive.Root>
|
</ScrollAreaPrimitive.Root>
|
||||||
|
|
|
@ -1,18 +1,18 @@
|
||||||
// https://night-tailwindcss.vercel.app/docs/breakpoints
|
// https://night-tailwindcss.vercel.app/docs/breakpoints
|
||||||
export const BREAKPOINTS = {
|
export const BREAKPOINTS = {
|
||||||
sm: '640px',
|
sm: 640,
|
||||||
// => @media (min-width: 640px) { ... }
|
// => @media (min-width: 640px) { ... }
|
||||||
|
|
||||||
md: '768px',
|
md: 768,
|
||||||
// => @media (min-width: 768px) { ... }
|
// => @media (min-width: 768px) { ... }
|
||||||
|
|
||||||
lg: '1024px',
|
lg: 1024,
|
||||||
// => @media (min-width: 1024px) { ... }
|
// => @media (min-width: 1024px) { ... }
|
||||||
|
|
||||||
xl: '1280px',
|
xl: 1280,
|
||||||
// => @media (min-width: 1280px) { ... }
|
// => @media (min-width: 1280px) { ... }
|
||||||
|
|
||||||
'2xl': '1536px'
|
'2xl': 1536
|
||||||
// => @media (min-width: 1536px) { ... }
|
// => @media (min-width: 1536px) { ... }
|
||||||
} as const
|
} as const
|
||||||
|
|
||||||
|
|
|
@ -1,18 +1,17 @@
|
||||||
import { useMedia } from 'react-use'
|
import { createBreakpoint } from 'react-use'
|
||||||
import { BREAKPOINTS } from '@/constants'
|
import { BREAKPOINTS } from '@/constants'
|
||||||
|
|
||||||
|
const _useBreakpoint = createBreakpoint(BREAKPOINTS)
|
||||||
|
|
||||||
const useBreakpoint = () => {
|
const useBreakpoint = () => {
|
||||||
const isSM = useMedia(`(min-width: ${BREAKPOINTS.sm})`)
|
const breakpoint = _useBreakpoint() as keyof typeof BREAKPOINTS
|
||||||
const isMD = useMedia(`(min-width: ${BREAKPOINTS.md})`)
|
|
||||||
const isLG = useMedia(`(min-width: ${BREAKPOINTS.lg})`)
|
|
||||||
const isXL = useMedia(`(min-width: ${BREAKPOINTS.xl})`)
|
|
||||||
const is2XL = useMedia(`(min-width: ${BREAKPOINTS['2xl']})`)
|
|
||||||
return {
|
return {
|
||||||
isSM,
|
isSM: breakpoint === 'sm',
|
||||||
isMD,
|
isMD: breakpoint === 'md',
|
||||||
isLG,
|
isLG: breakpoint === 'lg',
|
||||||
isXL,
|
isXL: breakpoint === 'xl',
|
||||||
is2XL
|
is2XL: breakpoint === '2xl'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -36,7 +36,7 @@ const Footer: FC = () => {
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="grid gap-y-2 p-4">
|
<div className="grid gap-y-2 px-4 pb-4">
|
||||||
<MessageInput
|
<MessageInput
|
||||||
value={text}
|
value={text}
|
||||||
preview={isPreview}
|
preview={isPreview}
|
||||||
|
|
|
@ -7,7 +7,7 @@ const Header: FC = () => {
|
||||||
const websiteInfo = getWebSiteInfo()
|
const websiteInfo = getWebSiteInfo()
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="shadow-xs grid h-12 grid-cols-[auto_1fr_auto] items-center bg-white px-4 backdrop-blur-lg 2xl:h-14">
|
<div className="shadow-xs z-10 grid h-12 grid-cols-[auto_1fr_auto] items-center bg-white px-4 backdrop-blur-lg 2xl:h-14">
|
||||||
<img className="h-8 w-8 overflow-hidden rounded-full" src={websiteInfo.icon} />
|
<img className="h-8 w-8 overflow-hidden rounded-full" src={websiteInfo.icon} />
|
||||||
<HoverCard>
|
<HoverCard>
|
||||||
<HoverCardTrigger asChild>
|
<HoverCardTrigger asChild>
|
||||||
|
|
Loading…
Reference in a new issue