Skip to content

Commit

Permalink
feature: Create Card and Player components
Browse files Browse the repository at this point in the history
  • Loading branch information
bartoszputek committed Sep 22, 2024
1 parent 367bc77 commit aa308f8
Show file tree
Hide file tree
Showing 8 changed files with 113 additions and 6 deletions.
9 changes: 9 additions & 0 deletions svelte/package-lock.json

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

7 changes: 5 additions & 2 deletions svelte/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,8 @@
"typescript-eslint": "^8.0.0",
"vite": "^5.0.3"
},
"type": "module"
}
"type": "module",
"dependencies": {
"@fontsource/roboto": "^5.1.0"
}
}
42 changes: 42 additions & 0 deletions svelte/src/lib/components/Card.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<script lang="ts">
const CARD_REVERSE = '2B';
export let value: string = CARD_REVERSE;
export let width: number = 70;
const height: number = width * 1.4;
let isSelected: boolean = false;
</script>

<button
aria-label={value}
style="width:{width}px; height:{height}px;"
class:isSelected
on:click={() => (isSelected = !isSelected)}
>
<img alt="" src={`/images/cards/${value.toUpperCase()}.svg`} />
</button>

<style>
button {
display: inline-block;
padding: 0;
margin: 2px;
cursor: pointer;
border: solid;
border-width: 0px;
border-radius: 4px;
}
button:hover {
outline: 3px solid #9ecaed;
box-shadow: 0 0 10px 1px #9ecaed;
}
img {
display: block;
width: 100%;
height: 100%;
}
</style>
5 changes: 1 addition & 4 deletions svelte/src/lib/components/CardIcon.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@
aria-label={value}
style="width:{width}px; height:{height}px;"
class:isSelected
on:click={() => {
isSelected = !isSelected;
console.log(isSelected);
}}
on:click={() => (isSelected = !isSelected)}
>
<img alt="" src={`/images/cards/${value.toUpperCase()}.svg`} />
</button>
Expand Down
30 changes: 30 additions & 0 deletions svelte/src/lib/components/Player.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<script lang="ts">
import Card from './Card.svelte';
export let playerName: string = 'Player 1';
export let firstCard: string | undefined;
export let secondCard: string | undefined;
</script>

<section>
<div>
<Card value={firstCard} />
<Card value={secondCard} />
</div>
<h4>{playerName}</h4>
</section>

<style>
section {
display: flex;
flex-direction: column;
align-items: center;
width: 200px;
}
h4 {
margin: 0;
}
</style>
8 changes: 8 additions & 0 deletions svelte/src/routes/+layout.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<script>
import '@fontsource/roboto';
import './../styles.css';
</script>

<main>
<slot />
</main>
6 changes: 6 additions & 0 deletions svelte/src/routes/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<script lang="ts">
import CardIcon from '$lib/components/CardIcon.svelte';
import Card from '../lib/components/Card.svelte';
import Player from '../lib/components/Player.svelte';
export const CARD_SUITS: string[] = ['s', 'd', 'h', 'c'];
export const CARD_RANKS: string[] = [
Expand All @@ -25,5 +27,9 @@
{/each}
{/each}

<br />

<Player />

<h1>Welcome to SvelteKit</h1>
<p>Visit <a href="https://kit.svelte.dev">kit.svelte.dev</a> to read the documentation</p>
12 changes: 12 additions & 0 deletions svelte/src/styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
html {
font-size: 62.5%;
}

body {
font-family: 'Roboto', sans-serif;
font-size: 1.6rem;
}

h4 {
font-size: 2.1rem;
}

0 comments on commit aa308f8

Please sign in to comment.