Skip to content

Commit

Permalink
feat: add basic categories
Browse files Browse the repository at this point in the history
  • Loading branch information
remvze committed Oct 5, 2023
1 parent 5791346 commit 8d7e4d2
Show file tree
Hide file tree
Showing 13 changed files with 180 additions and 84 deletions.
3 changes: 1 addition & 2 deletions .lintstagedrc.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"*.{ts,tsx}": ["eslint --fix", "tsc-files --noEmit"],
"*.{js,jsx}": "eslint --fix",
"*.{ts,tsx,js,jsx}": "eslint --fix",
"*.{json,md}": "prettier --write",
"*.css": "stylelint --fix",
"*.astro": ["eslint --fix", "stylelint --fix"],
Expand Down
26 changes: 11 additions & 15 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
"@types/react-dom": "^18.2.10",
"astro": "^3.2.3",
"react": "^18.2.0",
"react-dom": "^18.2.0"
"react-dom": "^18.2.0",
"react-icons": "4.11.0"
},
"devDependencies": {
"@commitlint/cli": "17.7.2",
Expand Down Expand Up @@ -60,7 +61,6 @@
"stylelint-config-html": "1.1.0",
"stylelint-config-idiomatic-order": "9.0.0",
"stylelint-config-standard": "34.0.0",
"stylelint-prettier": "4.0.2",
"tsc-files": "1.1.4"
"stylelint-prettier": "4.0.2"
}
}
61 changes: 0 additions & 61 deletions src/components/Card.astro

This file was deleted.

64 changes: 64 additions & 0 deletions src/components/categories/categories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import { useMemo } from 'react';
import { BiSolidTree } from 'react-icons/bi';
import { FaCity } from 'react-icons/fa';

import { Container } from '@/components/container';
import { Category } from '@/components/category';

interface CategoriesProps {
sounds: {
[id: string]: {
title: string;
sounds: Array<{
label: string;
src: string;
}>;
};
};
}

export function Categories({ sounds }: CategoriesProps) {
const categories = useMemo(() => {
const idToColor: { [id: string]: string } = {
nature: 'green',
urban: 'indigo',
};

const idToIcon: { [id: string]: React.ReactNode } = {
nature: <BiSolidTree />,
urban: <FaCity />,
};

const ids = Object.keys(sounds);
const categories: Array<{
color: string;
icon: React.ReactNode;
title: string;
id: string;
sounds: Array<{ label: string; src: string }>;
}> = [];

ids.forEach(id => {
const category = sounds[id];

categories.push({
color: idToColor[id] || 'green',
icon: idToIcon[id] || '-',
id: id,
...category,
});
});

return categories;
}, [sounds]);

return (
<Container>
<div>
{categories.map(category => (
<Category {...category} key={category.id} />
))}
</div>
</Container>
);
}
1 change: 1 addition & 0 deletions src/components/categories/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { Categories } from './categories';
50 changes: 50 additions & 0 deletions src/components/category/category.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
.category {
& .iconContainer {
display: flex;
flex-direction: column;
align-items: center;
margin-bottom: 15px;

& .tail {
width: 1px;
height: 75px;
background: linear-gradient(transparent, var(--color-neutral-300));

&.green {
background: linear-gradient(transparent, #16a34a);
}

&.indigo {
background: linear-gradient(transparent, #4f46e5);
}
}

& .icon {
display: flex;
width: 45px;
height: 45px;
align-items: center;
justify-content: center;
border: 1px solid var(--color-neutral-300);
border-radius: 50%;
font-size: var(--font-md);

&.green {
border-color: #16a34a;
background-color: rgb(22 163 74 / 20%);
}

&.indigo {
border-color: #4f46e5;
background-color: rgb(79 70 229 / 20%);
}
}
}

& .title {
font-family: var(--font-display);
font-size: var(--font-lg);
font-weight: 600;
text-align: center;
}
}
35 changes: 35 additions & 0 deletions src/components/category/category.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { useMemo } from 'react';

import { cn } from '@/helpers/styles';

import styles from './category.module.css';

interface CategoryProps {
color: string;
icon: React.ReactNode;
title: string;
id: string;
sounds: Array<{ label: string; src: string }>;
}

export function Category({ color, icon, title }: CategoryProps) {
const colorStyle = useMemo(() => {
const colorToStyle: { [color: string]: string } = {
green: styles.green,
indigo: styles.indigo,
};

return colorToStyle[color];
}, [color]);

return (
<div className={styles.category}>
<div className={styles.iconContainer}>
<div className={cn(styles.tail, colorStyle)} />
<div className={cn(styles.icon, colorStyle)}>{icon}</div>
</div>

<h2 className={styles.title}>{title}</h2>
</div>
);
}
1 change: 1 addition & 0 deletions src/components/category/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { Category } from './category';
2 changes: 1 addition & 1 deletion src/components/hero/hero.module.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.hero {
padding: 100px 0;
padding: 100px 0 10px;
text-align: center;

& .logo {
Expand Down
4 changes: 2 additions & 2 deletions src/data/sounds.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"sounds": {
"nature": {
"label": "Nature",
"title": "Nature",
"sounds": [
{
"label": "Rain",
Expand Down Expand Up @@ -38,7 +38,7 @@
]
},
"urban": {
"label": "Urban",
"title": "Urban",
"sounds": [
{
"label": "Airport",
Expand Down
7 changes: 7 additions & 0 deletions src/helpers/styles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
type className = undefined | null | false | string;

export function cn(...classNames: Array<className>): string {
const className = classNames.filter(className => !!className).join(' ');

return className;
}
4 changes: 4 additions & 0 deletions src/pages/index.astro
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@ import Layout from '@/layouts/layout.astro';
import { Gradient } from '@/components/gradient';
import { Hero } from '@/components/hero';
import { Categories } from '@/components/categories';
import sounds from '@/data/sounds.json';
---

<Layout title="Welcome to Astro.">
<Gradient />
<Hero />
<Categories client:load sounds={sounds.sounds} />
</Layout>

0 comments on commit 8d7e4d2

Please sign in to comment.