Make all props used in components listed explicitly

This commit is contained in:
Konrad Szwarc 2022-10-22 13:04:36 +02:00
parent e46a29e314
commit f258bc6cb4
11 changed files with 43 additions and 53 deletions

View file

@ -3,7 +3,7 @@ export interface Props {
href: string; href: string;
} }
const { props } = Astro; const { href } = Astro.props;
const classes = { const classes = {
main: 'inline-flex items-center px-4 h-10 text-base font-medium rounded-md shadow-sm text-white bg-primary-600 select-none cursor-pointer', main: 'inline-flex items-center px-4 h-10 text-base font-medium rounded-md shadow-sm text-white bg-primary-600 select-none cursor-pointer',
@ -13,4 +13,4 @@ const classes = {
}; };
--- ---
<a href={props.href} class:list={[classes.main, classes.hover, classes.active, classes.focus]}><slot /></a> <a href={href} class:list={[classes.main, classes.hover, classes.active, classes.focus]}><slot /></a>

View file

@ -1,11 +1,14 @@
--- ---
import type { IconName } from '@/types/icon';
import Icon from './icon'; import Icon from './icon';
type IconButtonSize = 'small' | 'large'; type IconButtonSize = 'small' | 'large';
export interface Props extends astroHTML.JSX.AnchorHTMLAttributes { export interface Props {
icon: string; icon: IconName;
name: string; target?: astroHTML.JSX.AnchorHTMLAttributes['target'];
href: string;
size: IconButtonSize; size: IconButtonSize;
} }
@ -14,11 +17,12 @@ const sizeMap: Record<IconButtonSize, string> = {
large: 'w-9 h-9', large: 'w-9 h-9',
}; };
const { icon, name, size, ...props } = Astro.props; const { icon, href, target, size } = Astro.props;
--- ---
<a <a
{...props} href={href}
target={target}
class:list={[ class:list={[
'flex', 'flex',
'items-center', 'items-center',
@ -29,12 +33,10 @@ const { icon, name, size, ...props } = Astro.props;
'active:translate-y-px', 'active:translate-y-px',
'focus:outline-none', 'focus:outline-none',
'focus:ring-2', 'focus:ring-2',
'focus:ring-offset-2',
'focus:ring-primary-500',
sizeMap[size], sizeMap[size],
props.class,
]} ]}
tabindex="-1"
> >
<button class:list={['flex', 'items-center', 'justify-center', 'w-full', 'h-full']}> <Icon client:load name={icon} size={16} />
<Icon client:load name={icon} size={16} />
</button>
</a> </a>

View file

@ -1,13 +1,13 @@
--- ---
export interface Props extends astroHTML.JSX.HTMLAttributes { export interface Props {
label: string; label: string;
value: string; value: string;
} }
const { label, value, ...props } = Astro.props; const { label, value } = Astro.props;
--- ---
<div {...props} class:list={['text-base', props.class]}> <div class="text-base">
<span class="font-medium text-gray-700">{label}:</span> <span class="font-medium text-gray-700">{label}:</span>
<span class="font-normal text-gray-500">{value}</span> <span class="font-normal text-gray-500">{value}</span>
</div> </div>

View file

@ -1,7 +1 @@
--- <div class="p-8 bg-white rounded-2xl shadow-md"><slot /></div>
export interface Props extends astroHTML.JSX.HTMLAttributes {}
const { props } = Astro;
---
<div {...props} class:list={['p-8 bg-white rounded-2xl shadow-md', props.class]}><slot /></div>

View file

@ -1,24 +1,23 @@
--- ---
import type { Icon as IconName } from '@/types/icon'; import type { IconName } from '@/types/icon';
import Icon from './icon'; import Icon from './icon';
export interface Props extends astroHTML.JSX.ButtonHTMLAttributes { export interface Props {
icon: IconName; icon: IconName;
active?: boolean; active?: boolean;
} }
const { props } = Astro; const { icon, active } = Astro.props;
--- ---
<button <button
type="button" type="button"
class:list={[ class:list={[
`inline-flex justify-center items-center h-10 w-10 rounded-lg transition hover:bg-primary-600`, `inline-flex justify-center items-center h-10 w-10 rounded-lg transition hover:bg-primary-600`,
props.active && 'bg-primary-600', active && 'bg-primary-600',
props.class,
]} ]}
> >
<Icon client:load name={props.icon} size={20} color={props.active ? 'white' : 'gray'} /> <Icon client:load name={icon} size={20} color={active ? 'white' : 'gray'} />
<slot /> <slot />
</button> </button>

View file

@ -1,9 +1,11 @@
--- ---
export interface Props extends astroHTML.JSX.HTMLAttributes { export interface Props {
skillLevel: number; skillLevel: number;
tileLevel: number; tileLevel: number;
} }
const { skillLevel, tileLevel } = Astro.props; const { skillLevel, tileLevel } = Astro.props;
const isFilled = skillLevel >= tileLevel; const isFilled = skillLevel >= tileLevel;
--- ---

View file

@ -1,9 +1,3 @@
--- <nav class="flex flex-col w-max p-2 rounded-lg gap-2 bg-white shadow-md">
export interface Props extends astroHTML.JSX.HTMLAttributes {}
const { props } = Astro;
---
<nav class:list={['flex flex-col w-max p-2 rounded-lg gap-2 bg-white shadow-md', props.class]}>
<slot /> <slot />
</nav> </nav>

View file

@ -1,14 +1,15 @@
--- ---
import SkillLevelTile from '@/atoms/skill-level-tile.astro'; import SkillLevelTile from '@/atoms/skill-level-tile.astro';
export interface Props extends astroHTML.JSX.HTMLAttributes { export interface Props {
skillLevel: number; skillLevel: number;
} }
const { skillLevel } = Astro.props; const { skillLevel } = Astro.props;
const LEVELS = [1, 2, 3, 4, 5]; const levels = [1, 2, 3, 4, 5];
--- ---
<div class:list={['flex', 'gap-1']}> <div class:list={['flex', 'gap-1']}>
{LEVELS.map((tileLevel) => <SkillLevelTile tileLevel={tileLevel} skillLevel={skillLevel} />)} {levels.map((tileLevel) => <SkillLevelTile tileLevel={tileLevel} skillLevel={skillLevel} />)}
</div> </div>

View file

@ -5,19 +5,17 @@ import type { LevelledSkill } from '@/types/skills-section';
import SkillLevel from './skill-level.astro'; import SkillLevel from './skill-level.astro';
export interface Props extends astroHTML.JSX.HTMLAttributes { export interface Props extends LevelledSkill {}
levelledSkill: LevelledSkill;
}
const { levelledSkill, ...props } = Astro.props; const { url, icon, iconColor, name, level } = Astro.props;
--- ---
<div class:list={['flex', 'flex-col', 'gap-2']} {...props}> <div class:list={['flex', 'flex-col', 'gap-2']}>
<div class:list={['flex', 'gap-2', 'h-5']}> <div class:list={['flex', 'gap-2', 'h-5']}>
<a href={levelledSkill.url} target="_blank" rel="noopener noreferrer"> <a href={url} target="_blank" rel="noopener noreferrer">
<Icon client:load name={levelledSkill.icon} color={levelledSkill.iconColor} size={20} /> <Icon client:load name={icon} color={iconColor} size={20} />
</a> </a>
<Typography variant="tile-subtitle" class="text-gray-700">{levelledSkill.name}</Typography> <Typography variant="tile-subtitle" class="text-gray-700">{name}</Typography>
</div> </div>
<SkillLevel skillLevel={levelledSkill.level} /> <SkillLevel skillLevel={level} />
</div> </div>

View file

@ -3,8 +3,8 @@ import IconButton from '@/atoms/icon-button.astro';
--- ---
<div class:list={['p-5', 'flex', 'flex-col', 'gap-2']}> <div class:list={['p-5', 'flex', 'flex-col', 'gap-2']}>
<IconButton icon="fa6-brands:facebook-f" name="Facebook" size="small" href="https://facebook.com/" target="_blank" /> <IconButton icon="fa6-brands:facebook-f" size="small" href="#" />
<IconButton icon="fa6-brands:github" name="GitHub" size="small" href="https://github.com/" target="_blank" /> <IconButton icon="fa6-brands:github" size="small" href="#" />
<IconButton icon="fa6-brands:linkedin-in" name="LinkedIn" size="large" href="https://linkedin.com/" target="_blank" /> <IconButton icon="fa6-brands:linkedin-in" size="large" href="#" />
<IconButton icon="fa6-brands:twitter" name="Twitter" size="large" href="https://twitter.com/" target="_blank" /> <IconButton icon="fa6-brands:twitter" size="large" href="#" />
</div> </div>

View file

@ -11,4 +11,4 @@ const levelledSkill: LevelledSkill = {
}; };
--- ---
<Skill levelledSkill={levelledSkill} /> <Skill {...levelledSkill} />