Skip to content

Commit

Permalink
Tailwind config and readme
Browse files Browse the repository at this point in the history
  • Loading branch information
martinwenisch committed Aug 31, 2024
1 parent 6bc7f42 commit 1633728
Show file tree
Hide file tree
Showing 14 changed files with 84 additions and 71 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,7 @@ The _one_ voting advice application used by millions of voters in four countries
- 🇸🇰 **[Volebná kalkulačka](https://www.volebnakalkulacka.sk)** in Slovakia
- 🇭🇺 **[Voksmonitor](https://www.voksmonitor.hu)** in Hungary
- 🇦🇹 **[Wahlrechner](https://www.wahlrechner.at)** in Austria

# Design System package

[Desing System config and Theming](packages/design-system/README.md)
1 change: 1 addition & 0 deletions apps/design-system/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ module.exports = {
parserOptions: {
project: true,
},
ignorePatterns: ["build/**"],
};
4 changes: 2 additions & 2 deletions apps/design-system/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"extends": "@repo/typescript-config/react-library.json",
"include": ["**/*.mdx", "**/*.ts", "**/*.tsx"],
"exclude": ["dist", "node_modules", "public"],
"exclude": ["node_modules", "public", "build"],
"compilerOptions": {
"jsx": "react-jsx",
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"moduleResolution": "node"
"moduleResolution": "NodeNext"
}
}
3 changes: 0 additions & 3 deletions apps/design-system/vercel.json

This file was deleted.

18 changes: 4 additions & 14 deletions apps/web/tailwind.config.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,10 @@
import globalConfig from "@repo/tailwind-config";
import globalConfig from "@repo/design-system/tailwind";
import type { Config } from "tailwindcss";
import defaultTheme from "tailwindcss/defaultTheme";

const fonts = {
theme: {
extend: {
fontFamily: {
sans: ['"Radio Canada"', ...defaultTheme.fontFamily.sans],
},
},
},
};

const config: Pick<Config, "content" | "presets"> = {
const config: Pick<Config, "content" | "presets" | "prefix"> = {
presets: [globalConfig],
content: ["./app/**/*.tsx"],
presets: [globalConfig, fonts],
prefix: "", // design-system has k1- prefix. We might or might not use it in other projects. But it's better to not conflict with it.
};

export default config;
26 changes: 26 additions & 0 deletions packages/design-system/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Design system

This package contains design system for all Kalkulacka One projects.

## Exports

- `./tailwind` exports `tailwind.config.js` file as default export
- `./styles` exports compiled css file (compiled Tailwind CSS)
- `./themes/*` export all theme css files (inlcuding default theme)
- `/fonts` export public directory with all fonts used in the design system

Components should be exported per-category using a barrel index file from each directory in `/src`.

## Tailwind configuration

- We define all config in `tailwind.config.js` file. Which is a base configuration for all projects using Tailwind CSS in their implementation. Each project is required to override `content` for their own tailwind files and `prefix` to avoid conflict with the design-system classes.
- We use specific theme configuration in `/config` directory. e.g. `colors`, `typography`. To add new theme overrides, add a new file, properly type it using `Pick<Partial<ThemeConfig>, "XYZ">` and import in `tailwind.config.js` file.

## Theming

We use css variables as a theming solution. Currently they are in `/src/themes` directory, but this is a subject to change.

- We have a default file `theme-default.css` which is a base theme for all projects.
- For each theme we can have an override file, e.g. `theme-idnes.css` that can re-define some of the variables or add their own custom css.

For each project, we need to import the default theme and then import the specific theme, if one is selected.
19 changes: 19 additions & 0 deletions packages/design-system/config/colors.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { ThemeConfig } from "tailwindcss/types/config";

const colors: Pick<Partial<ThemeConfig>, "colors"> = {
colors: {
primary: {
100: "var(--primary-100)",
50: "var(--primary-50)",
},
secondary: {
50: "var(--secondary-50)",
},
neutral: {
100: "var(--neutral-100)",
50: "var(--neutral-50)",
},
},
};

export default colors;
13 changes: 13 additions & 0 deletions packages/design-system/config/typography.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import defaultTheme from "tailwindcss/defaultTheme";
import { ThemeConfig } from "tailwindcss/types/config";

const typography: Pick<
Partial<ThemeConfig>,
"fontFamily" | "fontSize" | "fontWeight" | "lineHeight" | "letterSpacing"
> = {
fontFamily: {
sans: ['"Radio Canada"', ...defaultTheme.fontFamily.sans],
},
};

export default typography;
3 changes: 2 additions & 1 deletion packages/design-system/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"./themes/*": "./src/themes/*.css",
"./styles": "./dist/index.css",
"./fonts": "./dist/fonts",
"./heading": "./src/heading.tsx"
"./heading": "./src/heading.tsx",
"./tailwind": "./tailwind.config.ts"
},
"scripts": {
"build": "npm run fonts && npm run tailwind",
Expand Down
2 changes: 1 addition & 1 deletion packages/design-system/src/heading.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ type Props = {
};

const Heading = ({ children }: Props): JSX.Element => {
return <h1 className="text-primary-50">{children}</h1>;
return <h1 className="k1-text-primary-50">{children}</h1>;
};

export { Heading };
16 changes: 12 additions & 4 deletions packages/design-system/tailwind.config.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
import type { Config } from "tailwindcss";
import colors from "./config/colors";
import typography from "./config/typography";

import globalConfig from "@repo/tailwind-config";

const config: Pick<Config, "content" | "prefix" | "presets"> = {
// Each package is responsible for its own content
const config: Config = {
content: ["./src/**/*.tsx"],
presets: [globalConfig],
prefix: "k1-",
theme: {
extend: {
...colors,
...typography,
},
},
plugins: [],
};

export default config;
12 changes: 0 additions & 12 deletions packages/tailwind-config/package.json

This file was deleted.

29 changes: 0 additions & 29 deletions packages/tailwind-config/tailwind.config.ts

This file was deleted.

5 changes: 0 additions & 5 deletions packages/tailwind-config/tsconfig.json

This file was deleted.

0 comments on commit 1633728

Please sign in to comment.