Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(Typography): add types and removed unnecessary code #265

Merged
merged 1 commit into from
Mar 7, 2024

Conversation

RodrigoTomeES
Copy link
Contributor

@RodrigoTomeES RodrigoTomeES commented Mar 6, 2024

Descripción

The component now need less code to do the same and props are typed.

variant and color overwrite types is needed because a bug of Astro that type Astro.props as any instead as T Issue 10347

Problema solucionado

Props no tienen tipos

Cambios propuestos

Se han corregido los tipos y eliminado codigo innecesario

Capturas de pantalla (si corresponde)

---
import type { HTMLTag, Polymorphic } from "astro/types"

type Props<Tag extends HTMLTag> = Polymorphic<{
	as: Tag
	variant: keyof typeof variantClasses
	color: keyof typeof colorClasses
}>

const { as: Tag, class: className, variant, color, ...props } = Astro.props

const variantClasses = {
	h2: "text-lg font-medium uppercase lg:text-2xl",
	h3: "text-2xl font-semibold uppercase",
	body: "text-xl",
	medium: "text-md",
}

const colorClasses = {
	white: "text-white",
	black: "text-black",
	primary: "text-accent",
	neutral: "text-neutral-300",
}

const classes = [
	variantClasses[variant as keyof typeof variantClasses],
	colorClasses[color as keyof typeof colorClasses],
	className,
]
---

<Tag class:list={classes} {...props}>
	<slot />
</Tag>

Comprobación de cambios

  • He revisado localmente los cambios para asegurarme de que no haya errores ni problemas.
  • He probado estos cambios en múltiples dispositivos y navegadores para asegurarme de que la landing page se vea y funcione correctamente.
  • He actualizado la documentación, si corresponde.

The component now need less code to do the same and props are typed.

variant and color overwrite types is needed because a bug of Astro that type Astro.props as any instead as T
Copy link

vercel bot commented Mar 6, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
la-velada-web-oficial ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 6, 2024 7:02pm

@midudev midudev merged commit 9ae254f into midudev:main Mar 7, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants