Skip to content

Commit 09a9224

Browse files
Merge pull request #337 from codex-team/feat/implement-tree-shaking
feat: implement tree-shaking
2 parents 5cfa15a + 4b7b407 commit 09a9224

File tree

17 files changed

+413
-207
lines changed

17 files changed

+413
-207
lines changed

@codexteam/ui/.gitignore

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Dependencies
2+
node_modules/
3+
4+
# Build output
5+
dist/
6+
7+
# Logs
8+
*.log
9+
10+
# Test app (internal testing only)
11+
test-app/
12+
13+
# Editor
14+
.idea/
15+
.vscode/
16+
*.sw?
17+
18+
# OS
19+
.DS_Store
20+
21+
# Environment
22+
.env
23+
.env.local

@codexteam/ui/.npmignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
dev/
2+
test-app/
23
node_modules/
34
src/
45
*.log

@codexteam/ui/README.md

Lines changed: 117 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,50 +4,150 @@ The Design System forged in the fires of open-source development
44

55
Demo: https://cdx-ui.vercel.app/
66

7-
- [ ] Make tree-shaking work
7+
- [x] Make tree-shaking work
88
- [ ] Test Web/React/Native implementations
99
- [ ] Think about i18n
1010

11-
## Access Vue components
11+
## Installation
1212

13-
```ts
14-
import { Button, Input, Heading } from '@codexteam/ui/vue';
13+
```bash
14+
npm install @codexteam/ui
15+
# or
16+
yarn add @codexteam/ui
1517
```
1618

19+
## Quick Start
20+
21+
### 1. Import Base Styles (Required)
22+
23+
```typescript
24+
// main.ts
25+
import '@codexteam/ui/styles';
26+
```
27+
28+
### 2. Import Fonts (Optional)
29+
30+
Fonts are **optional** and are **not** loaded by default. If you want to use the bundled **Inter** and **JetBrains Mono** fonts, import them explicitly:
31+
32+
```typescript
33+
// main.ts
34+
import '@codexteam/ui/styles/fonts';
35+
```
36+
37+
If you don't import fonts, typography will fall back to system fonts.
38+
39+
### 3. Import Themes (Tree-shakeable)
40+
41+
Import only the themes you need - others will NOT be included in the bundle:
42+
43+
```typescript
44+
import '@codexteam/ui/styles/themes/pure';
45+
import '@codexteam/ui/styles/themes/grass';
46+
```
47+
48+
**Available themes:** `graphite`, `crimson`, `red`, `violet`, `grass`, `amber`, `pure`, `sky`
49+
50+
### 4. Import Components (Tree-shakeable)
51+
52+
```typescript
53+
import { Button, Avatar, Heading } from '@codexteam/ui/vue';
54+
```
55+
56+
### 5. Apply Theme in Template
57+
1758
```vue
18-
<Heading :level="2">
19-
CodeX UI showcase
20-
</Heading>
21-
<Button text="Button text" />
22-
<Input text="Input text" />
59+
<template>
60+
<div color-scheme="light" theme-accent="pure" theme-base="grass">
61+
<Button>Click me</Button>
62+
</div>
63+
</template>
64+
```
65+
66+
## Complete Example
67+
68+
**main.ts:**
69+
```typescript
70+
import { createApp } from 'vue';
71+
import App from './App.vue';
72+
73+
// Base styles (required)
74+
import '@codexteam/ui/styles';
75+
76+
// Fonts (optional)
77+
import '@codexteam/ui/styles/fonts';
78+
79+
// Themes (import only what you need)
80+
import '@codexteam/ui/styles/themes/pure';
81+
import '@codexteam/ui/styles/themes/grass';
82+
83+
createApp(App).mount('#app');
84+
```
85+
86+
**App.vue:**
87+
```vue
88+
<script setup lang="ts">
89+
import { Button, Heading, Input } from '@codexteam/ui/vue';
90+
</script>
91+
92+
<template>
93+
<div color-scheme="light" theme-accent="pure" theme-base="grass">
94+
<Heading :level="2">CodeX UI showcase</Heading>
95+
<Button>Button text</Button>
96+
<Input placeholder="Input text" />
97+
</div>
98+
</template>
2399
```
24100

25101
## Types for Vue Components
26102

27103
Add the following "path" to the "tsconfig.json"
28104

29-
```
105+
```json
30106
{
31107
"compilerOptions": {
32108
"paths": {
33-
"@codexteam/ui/vue": ["../@codexteam/ui/dist/types/vue/index.d.ts"],
109+
"@codexteam/ui/vue": ["../@codexteam/ui/dist/types/vue/index.d.ts"]
34110
}
35-
},
111+
}
36112
}
37-
38113
```
39114

40115
## Build Design System
41116
Build the design system to be able to use the @codexteam/ui/styles import
42117

43-
```
118+
```bash
44119
yarn build
45120
```
46121

47-
## Access CSS variables
122+
## Custom Theming
123+
124+
If you don't want to use built-in themes, define your own CSS variables:
125+
126+
```css
127+
:root {
128+
/* Base colors */
129+
--base--bg-primary: #ffffff;
130+
--base--bg-secondary: #f5f5f5;
131+
--base--bg-secondary-hover: #eeeeee;
132+
--base--border: #e0e0e0;
133+
--base--text: #333333;
134+
--base--text-secondary: #666666;
135+
--base--solid: #000000;
136+
--base--text-solid-foreground: #ffffff;
137+
138+
/* Accent colors */
139+
--accent--solid: #2196f3;
140+
--accent--solid-hover: #1976d2;
141+
--accent--bg-secondary: #e3f2fd;
142+
--accent--text-solid-foreground: #ffffff;
143+
}
144+
```
145+
146+
## Access CSS Variables
48147

49-
1. Import `@codexteam/ui/styles` somewhere in App
50-
2. Use variable in CSS, e.g `var(--ui-color)`
148+
1. Import `@codexteam/ui/styles` in your app
149+
2. Import themes you need (e.g., `@codexteam/ui/styles/themes/pure`)
150+
3. Use variables in CSS: `var(--base--text)`, `var(--accent--solid)`
51151

52152
## Using Typography
53153

@codexteam/ui/dev/index.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
<script type="module">
1111
import { createApp } from 'vue';
1212
import { createRouter, createWebHashHistory } from 'vue-router';
13+
import "../src/styles/fonts.pcss";
1314
import "../src/styles/index.pcss";
15+
import "../src/styles/themes/index.pcss";
1416

1517
import Playground from './Playground.vue';
1618
import routes from './routes';

@codexteam/ui/package.json

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
{
22
"name": "@codexteam/ui",
3-
"version": "0.1.1",
3+
"version": "0.2.0-rc.3",
44
"type": "module",
5+
"sideEffects": [
6+
"*.css",
7+
"*.pcss"
8+
],
59
"scripts": {
610
"dev": "vite",
711
"build": "yarn build-src && yarn build-types",
@@ -17,12 +21,38 @@
1721
],
1822
"exports": {
1923
"./vue": {
20-
"import": {
21-
"default": "./dist/vue.js"
22-
}
24+
"types": "./dist/types/vue/index.d.ts",
25+
"import": "./dist/vue.js"
2326
},
2427
"./styles": {
25-
"import": "./dist/styles.css"
28+
"import": "./dist/style.css"
29+
},
30+
"./styles/fonts": {
31+
"import": "./dist/styles/fonts.css"
32+
},
33+
"./styles/themes/graphite": {
34+
"import": "./dist/styles/themes/graphite.css"
35+
},
36+
"./styles/themes/crimson": {
37+
"import": "./dist/styles/themes/crimson.css"
38+
},
39+
"./styles/themes/red": {
40+
"import": "./dist/styles/themes/red.css"
41+
},
42+
"./styles/themes/violet": {
43+
"import": "./dist/styles/themes/violet.css"
44+
},
45+
"./styles/themes/grass": {
46+
"import": "./dist/styles/themes/grass.css"
47+
},
48+
"./styles/themes/amber": {
49+
"import": "./dist/styles/themes/amber.css"
50+
},
51+
"./styles/themes/pure": {
52+
"import": "./dist/styles/themes/pure.css"
53+
},
54+
"./styles/themes/sky": {
55+
"import": "./dist/styles/themes/sky.css"
2656
}
2757
},
2858
"devDependencies": {
@@ -48,7 +78,11 @@
4878
"vue-tsc": "latest"
4979
},
5080
"dependencies": {
81+
"@codexteam/icons": "^0.3.3",
5182
"@editorjs/editorjs": "2.30.2",
83+
"@vueuse/core": "^10.3.0"
84+
},
85+
"peerDependencies": {
5286
"vue": "^3.4.16"
5387
}
5488
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
@import url('../fonts/Inter/inter.css');
2+
@import url('../fonts/JetBrainsMono/JetBrainsMono.css');

@codexteam/ui/src/styles/index.pcss

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
@import './themes/index.pcss';
21
@import './dimensions.pcss';
32
@import './typography.pcss';
43
@import './mixins.pcss';

@codexteam/ui/src/styles/typography.pcss

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
@import url('../fonts/Inter/inter.css');
2-
@import url('../fonts/JetBrainsMono/JetBrainsMono.css');
31

42
/**
53
* Fonts setup

0 commit comments

Comments
 (0)