-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
93 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
{ | ||
"editor.codeActionsOnSave": { | ||
"source.fixAll.eslint": "explicit" | ||
}, | ||
"editor.formatOnSave": true, | ||
"editor.tabSize": 2, | ||
} | ||
"editor.codeActionsOnSave": { | ||
"source.fixAll.eslint": "explicit" | ||
}, | ||
"editor.formatOnSave": true, | ||
"editor.tabSize": 2 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,22 @@ | ||
# sv | ||
## Ejemplo Twitter en Svelte | ||
|
||
Everything you need to build a Svelte project, powered by [`sv`](https://github.com/sveltejs/cli). | ||
El ejemplo muestra cómo podría funcionar una página de Twitter. | ||
|
||
## Creating a project | ||
- Queremos replicar el comportamiento de twitter | ||
- Escribimos en un texto, nos dice cuántos caracteres escribimos | ||
- BONUS: que nos diga cuántos caracteres nos quedan | ||
- BONUS 2: mostrarlo con colores distintos. verde si podemos escribir tranquilo, amarillo cuando falten menos de 5 y rojo cuando ya nos pasamos. | ||
|
||
If you're seeing this, you've probably already done this step. Congrats! | ||
Ejercicio extraído de la [guía de binding](https://algo3.uqbar-project.org/gua-prctica-de-ejercicios/ejercicios-binding). | ||
|
||
```bash | ||
# create a new project in the current directory | ||
npx sv create | ||
TODO: demo | ||
|
||
# create a new project in my-app | ||
npx sv create my-app | ||
``` | ||
## Implementación | ||
|
||
## Developing | ||
La URL es `http://localhost:5173` | ||
|
||
Once you've created a project and installed dependencies with `npm install` (or `pnpm install` or `yarn`), start a development server: | ||
En la variante con template tenemos | ||
|
||
```bash | ||
npm run dev | ||
|
||
# or start the server and open the app in a new browser tab | ||
npm run dev -- --open | ||
``` | ||
|
||
## Building | ||
|
||
To create a production version of your app: | ||
|
||
```bash | ||
npm run build | ||
``` | ||
|
||
You can preview the production build with `npm run preview`. | ||
|
||
> To deploy your app, you may need to install an [adapter](https://svelte.dev/docs/kit/adapters) for your target environment. | ||
- un estado mutable: el **tweet**, un string | ||
- un valor calculable o `$derived`, la **cantidad de caracteres restantes** | ||
- otro valor calculable a partir de los caracteres restantes, **qué clase le corresponde**. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,4 +10,4 @@ declare global { | |
} | ||
} | ||
|
||
export { } | ||
export {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,9 +4,12 @@ | |
<meta charset="utf-8" /> | ||
<link rel="icon" href="%sveltekit.assets%/favicon.ico" /> | ||
|
||
<link rel="preconnect" href="https://fonts.googleapis.com"> | ||
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin> | ||
<link href="https://fonts.googleapis.com/css2?family=Geist+Mono:[email protected]&display=swap" rel="stylesheet"> | ||
<link rel="preconnect" href="https://fonts.googleapis.com" /> | ||
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin /> | ||
<link | ||
href="https://fonts.googleapis.com/css2?family=Geist+Mono:[email protected]&display=swap" | ||
rel="stylesheet" | ||
/> | ||
|
||
<meta name="viewport" content="width=device-width, initial-scale=1" /> | ||
%sveltekit.head% | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,32 @@ | ||
<script lang='ts'> | ||
import './styles.css'; | ||
<script lang="ts"> | ||
import './styles.css' | ||
const LONGITUD_MAXIMA = 140 | ||
const LONGITUD_MAXIMA = 140 | ||
const claseEspacioRestante = (restantes: number): string => | ||
restantes > 10 ? 'ok' : (restantes > 5 ? 'limite' : 'pasado') | ||
const claseEspacioRestante = (restantes: number): string => | ||
restantes > 10 ? 'ok' : restantes > 5 ? 'limite' : 'pasado' | ||
let tweet = $state('') | ||
let restantes = $derived(LONGITUD_MAXIMA - tweet.length) | ||
let espacioRestanteClass = $derived(claseEspacioRestante(restantes)) | ||
let tweet = $state('') | ||
let restantes = $derived(LONGITUD_MAXIMA - tweet.length) | ||
let espacioRestanteClass = $derived(claseEspacioRestante(restantes)) | ||
</script> | ||
|
||
<article class="container"> | ||
<h1>Twitter - Svelte</h1> | ||
<form name="form" class="form"> | ||
<div> | ||
<textarea id="texto" name="texto" data-testid="texto" placeholder="¿Qué estás pensando?" bind:value={tweet}></textarea> | ||
</div> | ||
<div> | ||
<span data-testid="restantes" class="badge {espacioRestanteClass}"> | ||
{restantes} | ||
</span> | ||
</div> | ||
</form> | ||
</article> | ||
<h1>Twitter - Svelte</h1> | ||
<form name="form" class="form"> | ||
<div> | ||
<textarea | ||
id="texto" | ||
name="texto" | ||
data-testid="texto" | ||
placeholder="¿Qué estás pensando?" | ||
bind:value={tweet} | ||
></textarea> | ||
</div> | ||
<div> | ||
<span data-testid="restantes" class="badge {espacioRestanteClass}"> | ||
{restantes} | ||
</span> | ||
</div> | ||
</form> | ||
</article> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,44 @@ | ||
* { | ||
font-family: "Geist Mono", sans-serif; | ||
box-sizing: border-box; | ||
font-family: 'Geist Mono', sans-serif; | ||
box-sizing: border-box; | ||
} | ||
|
||
form { | ||
display: flex; | ||
flex-direction: column; | ||
font-size: 1.5rem; | ||
display: flex; | ||
flex-direction: column; | ||
font-size: 1.5rem; | ||
} | ||
|
||
h1 { | ||
font-size: 1.7rem; | ||
font-size: 1.7rem; | ||
} | ||
|
||
input, | ||
textarea { | ||
width: 100%; | ||
height: 10em; | ||
font-size: 1em; | ||
margin-bottom: 2em; | ||
padding: 0.8em; | ||
border: 1px solid darkslategray; | ||
width: 100%; | ||
height: 10em; | ||
font-size: 1em; | ||
margin-bottom: 2em; | ||
padding: 0.8em; | ||
border: 1px solid darkslategray; | ||
} | ||
|
||
.badge { | ||
font-size: 1.2em; | ||
padding: 1em; | ||
border-radius: 35%; | ||
font-size: 1.2em; | ||
padding: 1em; | ||
border-radius: 35%; | ||
} | ||
|
||
.pasado { | ||
color: white; | ||
background-color: rgb(201, 72, 72); | ||
color: white; | ||
background-color: rgb(201, 72, 72); | ||
} | ||
|
||
.limite { | ||
background-color: rgb(203, 203, 31); | ||
background-color: rgb(203, 203, 31); | ||
} | ||
|
||
.ok { | ||
color: white; | ||
background-color: green; | ||
} | ||
color: white; | ||
background-color: green; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,18 @@ | ||
import adapter from '@sveltejs/adapter-auto'; | ||
import { vitePreprocess } from '@sveltejs/vite-plugin-svelte'; | ||
import adapter from '@sveltejs/adapter-auto' | ||
import { vitePreprocess } from '@sveltejs/vite-plugin-svelte' | ||
|
||
/** @type {import('@sveltejs/kit').Config} */ | ||
const config = { | ||
// Consult https://svelte.dev/docs/kit/integrations | ||
// for more information about preprocessors | ||
preprocess: vitePreprocess(), | ||
preprocess: vitePreprocess({ script: true }), | ||
|
||
kit: { | ||
// adapter-auto only supports some environments, see https://svelte.dev/docs/kit/adapter-auto for a list. | ||
// If your environment is not supported, or you settled on a specific environment, switch out the adapter. | ||
// See https://svelte.dev/docs/kit/adapters for more information about adapters. | ||
adapter: adapter() | ||
} | ||
}; | ||
} | ||
|
||
export default config; | ||
export default config |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
import { defineConfig } from 'vitest/config'; | ||
import { sveltekit } from '@sveltejs/kit/vite'; | ||
import { defineConfig } from 'vitest/config' | ||
import { sveltekit } from '@sveltejs/kit/vite' | ||
|
||
export default defineConfig({ | ||
plugins: [sveltekit()], | ||
|
||
test: { | ||
include: ['src/**/*.{test,spec}.{js,ts}'] | ||
} | ||
}); | ||
}) |