3. semester
En React-udvikler
Løsning
(næsten)
Utility-framework
har truffet mange valg på forhånd, så du slipper for at konfigurere alting selv
The hardest thing about programming is naming stuff!
<section>
<svg>...</svg>
<h2>Constraint-based</h2>
<p>An API for your design system.</p>
<p>Utility classes help you work within the constraints...</p>
...
<section>
<svg>...</svg>
<h2>Constraint-based</h2>
<p>An API for your design system.</p>
<p>Utility classes help you work within the constraints...</p>
...
"kicker"
<section>
<svg>...</svg>
<h2>Constraint-based</h2>
<p class="text-4xl font-extrabold">An API for your design system.</p>
<p>Utility classes help you work within the constraints...</p>
...
"kicker"
Opgave
Oversæt CSS til Tailwind, så et tilsvarende HTML-element får samme styling. Og omvendt.
øvelse
Genskab følgende design med TailwindCSS. Det skal ikke være 100 % én til én, men så tæt på, som muligt.
bg-slate-900
bg-blue-500
text-blue-200
Lad den forblive åben...
øvelse
Byg videre på øvelsen. Brug dark-præfiksen,
så kortet har en "dark mode"-variant. Du vælger selv, hvordan den skal se ud.
...fortsat...
øvelse
Genskab følgende design med TailwindCSS. Det skal ikke være 100 % én til én, men så tæt på, som muligt.
Genskab flow-space mm.
<section class="space-y-[1.3rem] bg-[#bada55]">
<h2 class="text-[3rem] text-(color:--my-var)">Constraint-based</h2>
<p class="text-(length:--my-var)">An API for your design system.</p>
</section>
/** @type {import('tailwindcss').Config} */
export default {
content: ["./index.html", "./src/**/*.{js,ts,jsx,tsx}"],
theme: {
extend: {},
plugins: [],
};
/** @type {import('tailwindcss').Config} */
export default {
content: ["./index.html", "./src/**/*.{js,ts,jsx,tsx}"],
theme: {
extend: {},
plugins: [],
};
/** @type {import('tailwindcss').Config} */
export default {
content: ["./index.html", "./src/**/*.{js,ts,jsx,tsx}"],
theme: {
extend: {},
plugins: [],
};
Følg med på https://play.tailwindcss.com/
@import "tailwindcss";
@theme {
/* ... */
}
@import "tailwindcss";
@theme {
--color-custom: #5000ca;
}
Fjerner alle farver
@import "tailwindcss";
@theme {
--color-*: initial;
--color-custom: #5000ca;
}
Tokens
@import "tailwindcss";
@theme {
--color-*: initial;
--color-primary-dark: #173f5f;
--color-primary-light: #20639b;
--color-secondary: #3caea3;
--color-tertiary: #f6d55c;
--color-accent: #ed553b;
}
100
200
300
400
500
600
700
800
100
200
300
400
500
600
700
800
100
200
300
400
500
600
700
800
@import "tailwindcss";
@theme {
--color-*: initial;
--color-primary-100: #cffafe;
--color-primary-200: #a5f3fc;
--color-primary-300: #67e8f9;
--color-primary-400: #22d3ee;
--color-primary-500: #06b6d4;
--color-primary-600: #0891b2;
--color-primary-700: #0e7490;
--color-primary-800: #155e75;
--color-primary-900: #164e63;
--color-primary: var(--color-primary-500);
}
100
200
300
400
500
600
700
800
100
200
300
400
500
600
700
800
100
200
300
400
500
600
700
800
200
500
800
/** @type {import('tailwindcss').Config} */
export default {
content: ["./index.html", "./src/**/*.{js,ts,jsx,tsx}"],
theme: {
colors: {
// ...
primary: {
light: '#67e8f9',
DEFAULT: '#06b6d4',
dark: '#0e7490',
},
// ...
},
extend: {},
plugins: [],
};
@import "tailwindcss";
@theme {
--color-*: initial;
--color-primary-light: #67e8f9;
--color-primary: #06b6d4;
--color-primary-dark: #0e7490;
}
@import "tailwindcss";
@theme {
--color-*: initial;
--color-primary-light: oklch(from var(--color-primary) calc(l * 1.2) c h);
--color-primary: #06b6d4;
--color-primary-dark: oklch(from var(--color-primary) calc(l * .8) c h);
}
@import "tailwindcss";
@theme {
--color-surface-1: var(--color-stone-50);
--color-heading: var(--color-stone-950);
--color-body: var(--color-stone-600);
--color-accent: var(--color-lime-400);
}
<button class="bg-accent">Hello</button>
<div class="bg-surface-1">
<h2 class="text-heading">Hello</h2>
<p class="text-body">Lorem ipsum dolor sit amet.</p>
</div>
@import "tailwindcss";
@theme {
--color-surface-1: var(--color-stone-50);
--color-heading: var(--color-stone-950);
--color-body: var(--color-stone-600);
--color-accent: var(--color-lime-400);
}
<button class="bg-accent">Hello</button>
<div class="bg-surface-1">
<h2 class="text-heading">Hello</h2>
<p class="text-body">Lorem ipsum dolor sit amet.</p>
</div>
@import "tailwindcss";
@theme {
--color-surface-1: var(--surface-1);
--color-heading: var(--ink-2);
--color-body: var(--ink-1);
--color-accent: var(--color-lime-400);
}
:root {
color-scheme: light dark;
--ink-1: light-dark(var(--color-stone-600), var(--color-stone-200));
--ink-2: light-dark(var(--color-stone-950), var(--color-stone-50));
--surface-1: light-dark(var(--color-stone-50), var(--color-stone-800));
}
@custom-variant dark (&:where([data-theme=dark], [data-theme=dark] *));
øvelse
Genskab følgende design med TailwindCSS. Det skal ikke være 100 % én til én, men så tæt på, som muligt. Lav også en mørk variant som kan toggles via knappen.