Skip to content

Commit

Permalink
feat: adicionado componente de imagem
Browse files Browse the repository at this point in the history
  • Loading branch information
erikfig committed Sep 3, 2024
1 parent 767f4aa commit a220018
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/components/card/card-background.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { HTMLAttributes, ReactNode } from 'react'
import { Img } from '../img'

export type CardBackgroundProps = {
children?: ReactNode,
Expand All @@ -9,7 +10,7 @@ export const CardBackground = ({ children, src, className, ...props }: CardBackg
return (
<>
<div className="absolute w-full h-full top-0 left-0 z-0 overflow-hidden">
<img className='w-full h-full object-cover' src={src} />
<Img className='w-full h-full object-cover' src={src} />
</div>
{children && <div className={`relative -m-8 p-6 ${className}`} {...props}>{children}</div>}
</>
Expand Down
13 changes: 13 additions & 0 deletions src/components/img/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { ImgHTMLAttributes, useEffect, useState } from 'react'

type ImgProps = ImgHTMLAttributes<HTMLImageElement>

export const Img = ({ src, ...props }: ImgProps) => {
const [localSrc, setLocalSrc] = useState<string>('')

useEffect(() => {
setLocalSrc(`${import.meta.env.VITE_BASE_APP ? import.meta.env.VITE_BASE_APP : '/'}${src}`)
}, [src])

return <img src={localSrc} {...props} />
}
3 changes: 2 additions & 1 deletion src/layouts/default/default.layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { Typography } from '../../components/Typography'
import { Toggle } from '../../components/form/toggle'
import { Outlet, useNavigate } from 'react-router-dom'
import { RoutesConfig } from '@config/routes'
import { Img } from '../../components/img'

type DefaultLayoutProps = {
title?: string
Expand Down Expand Up @@ -47,7 +48,7 @@ export const DefaultLayout = ({ title }: DefaultLayoutProps) => {
<div className='m-6'>

<a href="" className="flex items-center gap-3">
<Rounded><img src="/logo.png" width={50} height={50} /></Rounded>
<Rounded><Img src="/logo.png" width={50} height={50} /></Rounded>
{' '}
<span>Erik <span className='text-primary'>Dashboard</span></span>
</a>
Expand Down

0 comments on commit a220018

Please sign in to comment.