Skip to content

Commit 90aa20f

Browse files
Tahuljohnsoncodehkantfu
authored
feat(css()): move towards css-in-js (#19)
Co-authored-by: johnsoncodehk <[email protected]> Co-authored-by: Anthony Fu <[email protected]>
1 parent 0b2742f commit 90aa20f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+1629
-976
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# @nuxtjs/design-tokens
1+
# @nuxtjs/style
22

33
Use [Design Tokens](https://amzn.github.io/style-dictionary/#/tokens) in your Nuxt project.
44

build.config.ts

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,17 @@ export default defineBuildConfig({
77
input: './src/index.ts',
88
builder: 'rollup',
99
name: 'index'
10-
},
11-
{
12-
input: './src/formats.ts',
13-
builder: 'rollup',
14-
name: 'formats'
15-
},
16-
{
17-
input: './src/generate.ts',
18-
builder: 'rollup',
19-
name: 'generate'
2010
}
2111
],
2212
externals: [
2313
// ??
2414
'formats.mjs',
2515
'generate.mjs',
2616
// ??
17+
'@vue/compiler-sfc',
18+
'magic-string',
19+
'json5',
20+
'recast',
2721
'scule',
2822
'unplugin',
2923
'#design-tokens',

docs/content/0.index.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: "Design System made easy"
3-
description: "ully-typed design tokens integration for making and maintaining a design system."
3+
description: "Fully-typed design tokens integration for making and maintaining a design system."
44
navigation: false
55
layout: fluid
66
---
@@ -20,7 +20,7 @@ snippet: npm install @nuxtjs/design-tokens --save-dev
2020
:ellipsis
2121

2222
#title
23-
Nuxt :highlight[DesignTokens]
23+
Nuxt :highlight[Style Tokens]
2424

2525
#description
2626
Fully-typed design tokens integration for making and maintaining a design system.

docs/content/1.guide/2.get-started.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export default defineNuxtConfig({
3232

3333
👩‍🎨. [**Define your design tokens.**]{.text-xl}
3434

35-
```ts [tokens.config.ts]
35+
```ts [style.config.ts]
3636
import { defineTokens } from '@nuxtjs/design-tokens'
3737

3838
export default defineTokens({

docs/content/1.guide/3.API.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ description: Discover how to create and use your tokens with @nuxtjs/design-toke
55

66
`tokens` are a [Design Tokens format](https://design-tokens.github.io/community-group/format/) compatible object definition that gets processed by [Style Dictionary](https://amzn.github.io/style-dictionary).
77

8-
This allows the options defined by the theme author in his `designTokens.tokens` key to be type-safe for the theme user that will configure his theme via the same key or a `tokens.config` file.
8+
This allows the options defined by the theme author in his `style.tokens` key to be type-safe for the theme user that will configure his theme via the same key or a `tokens.config` file.
99

1010
### Defining theme tokens
1111

1212
There is two ways to define theme tokens:
1313

14-
- Via the `designTokens.tokens` key in the `nuxt.config` file.
15-
- Via the `tokens.config.{js|ts}` file at the root of your project.
14+
- Via the `style.tokens` key in the `nuxt.config` file.
15+
- Via the `style.config.{js|ts}` file at the root of your project.
1616

1717
Both of these options will be merged in the end.
1818

@@ -21,7 +21,7 @@ These two ways will both work for theme authors and theme users as they will get
2121
::code-group
2222

2323
```ts [tokens.config.ts]
24-
import { defineTokens } from '@nuxtjs/design-tokens'
24+
import { defineTokens } from '@nuxtjs/style'
2525

2626
export default defineTokens({
2727
colors: {
@@ -39,7 +39,7 @@ export default defineTokens({
3939
import { defineNuxtConfig } from 'nuxt'
4040

4141
export default defineNuxtConfig({
42-
designTokens: {
42+
style: {
4343
tokens: {
4444
colors: {
4545
primary: {
@@ -66,7 +66,7 @@ Theme tokens gets processed by [Style Dictionary](https://amzn.github.io/style-d
6666
- `tokens.json` if you want to import it from a JSON context.
6767
- `index.ts` to import it from runtime or from any TypeScript context.
6868
- `index.js` to import it from runtime or from any JavaScript context.
69-
- `types.d.ts` for global type inference (`$dt()`, `$tokens()`, `useTokens()`, `defineTokens`, `nuxt.config.designTokens.tokens`).
69+
- `types.d.ts` for global type inference (`$dt()`, `$tokens()`, `useTokens()`, `defineTokens`, `nuxt.config.style.tokens`).
7070

7171
- **Composable usage**
7272
```ts

docs/theme.config.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
export default {
2-
title: 'Nuxt Design Tokens',
3-
description: 'Fully-typed design tokens integration for making and maintaining a design system.',
2+
title: '@nuxtjs/style',
3+
description: 'Vue-native zero-runtime CSS-in-JS solution.',
44
url: 'https://design-tokens.nuxtjs.org',
55
socials: {
66
twitter: '@yaeeelglx',
@@ -16,7 +16,7 @@ export default {
1616
},
1717
cover: {
1818
src: '/cover.jpg',
19-
alt: 'Nuxt Design Tokens'
19+
alt: '@nuxtjs/style'
2020
},
2121
footer: {
2222
credits: {

package.json

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@nuxtjs/design-tokens",
33
"version": "0.0.1",
4-
"description": "Use Design Tokens in your Nuxt app.",
4+
"description": "'Vue-native zero-runtime CSS-in-JS solution.",
55
"keywords": [
66
"nuxt",
77
"theme",
@@ -44,15 +44,18 @@
4444
},
4545
"dependencies": {
4646
"@nuxt/kit": "^3.0.0-rc.8",
47+
"@stitches/stringify": "^1.2.8",
4748
"browser-style-dictionary": "^3.1.1-browser.1",
4849
"chroma-js": "^2.4.2",
4950
"csstype": "^3.1.0",
51+
"json5": "^2.2.1",
5052
"paneer": "^0.0.1",
5153
"postcss-custom-properties": "^12.1.8",
5254
"postcss-easing-gradients": "^3.0.1",
5355
"postcss-nested": "^5.0.6",
5456
"to-ast": "^1.0.0",
55-
"untyped": "^0.4.5"
57+
"unplugin-ast": "^0.5.5",
58+
"untyped": "^0.4.7"
5659
},
5760
"devDependencies": {
5861
"@nuxt-themes/docus": "npm:@nuxt-themes/docus-edge@latest",
@@ -61,9 +64,10 @@
6164
"@nuxt/test-utils": "npm:@nuxt/test-utils-edge@latest",
6265
"@nuxtjs/eslint-config-typescript": "latest",
6366
"@nuxtjs/tailwindcss": "^5.3.2",
67+
"@volar/vue-language-core": "^0.40.4",
6468
"browser-style-dictionary": "^3.1.1-browser.1",
6569
"c8": "^7.12.0",
66-
"eslint": "^8.22.0",
70+
"eslint": "^8.23.0",
6771
"globby": "^13.1.2",
6872
"husky": "^8.0.1",
6973
"jiti": "^1.14.0",

playground/components/Block.vue

Lines changed: 57 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,63 @@
1-
<template>
2-
<button :class="['block', ...variants]">
3-
{{ variants[0] }}
4-
</button>
5-
</template>
6-
71
<script setup lang="ts">
82
defineProps({
9-
...$variantProps('block')
3+
...$variantsProps('button')
104
})
115
</script>
126

13-
<style scoped lang="postcss">
14-
.block {
15-
@component('block');
16-
}
7+
<template>
8+
<button :class="{ ...$props }">
9+
<template v-for="[key, value] in Object.entries($props)">
10+
<p v-if="value" :key="key">
11+
{{ value ? key : '' }}
12+
</p>
13+
</template>
14+
</button>
15+
</template>
16+
17+
<style lang="ts" scoped>
18+
css({
19+
button: {
20+
display: 'flex',
21+
alignItems: 'center',
22+
justifyContent: 'center',
23+
borderRadius: '16px',
24+
width: '320px',
25+
height: '320px',
26+
border: '16px solid {colors.grape}',
27+
position: 'relative',
28+
'&:hover': {
29+
border: '8px solid blue',
30+
},
31+
'& > p': {
32+
fontSize: '16px',
33+
textDecoration: 'underline',
34+
},
35+
variants: {
36+
primary: {
37+
backgroundColor: '{colors.primary.500}',
38+
},
39+
black: {
40+
backgroundColor: '{colors.black}',
41+
},
42+
lavender: {
43+
backgroundColor: '{colors.lavender}'
44+
},
45+
lila: {
46+
backgroundColor: '{colors.lila}'
47+
},
48+
velvet: {
49+
backgroundColor: '{colors.velvet}'
50+
},
51+
grape: {
52+
backgroundColor: '{colors.grape}'
53+
},
54+
rounded: {
55+
borderRadius: '50%'
56+
},
57+
padded: {
58+
padding: '4rem'
59+
},
60+
}
61+
}
62+
})
1763
</style>

playground/nuxt.config.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,14 @@ const resolveThemeDir = (path: string) => resolve(themeDir, path)
77

88
export default defineNuxtConfig({
99
alias: {
10-
'@nuxtjs/design-tokens': resolveThemeDir('../src/module.ts')
10+
'@nuxtjs/design-tokens': resolveThemeDir('../src/index.ts')
1111
},
1212

13-
extends: [resolveThemeDir('./theme')]
13+
extends: [resolveThemeDir('./theme')],
1414

15-
// modules: ['@nuxtjs/tailwindcss']
15+
nitro: {
16+
externals: {
17+
inline: ['recast', 'ast-types']
18+
}
19+
}
1620
})

playground/pages/index.vue

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@
99
</header>
1010

1111
<section>
12-
<Block :variants="variants" @click="makeRounded" />
13-
<Block :variants="['black']" />
14-
<Block :variants="['grape']" />
15-
<Block :variants="['lila']" />
16-
<Block :variants="['velvet']" />
12+
<Block primary />
13+
<Block black />
14+
<Block lila />
15+
<Block lavender />
16+
<Block velvet />
17+
<Block grape />
1718
</section>
1819

1920
<footer>
@@ -26,17 +27,9 @@
2627
</div>
2728
</template>
2829

29-
<script setup lang="ts">
30-
const variants = ref(['primary'])
31-
32-
const makeRounded = () => {
33-
variants.value.push('rounded')
34-
}
35-
</script>
36-
37-
<style>
30+
<style lang="postcss">
3831
html {
39-
font-family: Inter, sans-serif;
32+
font-family: $dt('fonts.primary');
4033
}
4134
</style>
4235

@@ -48,7 +41,7 @@ html {
4841
align-items: center;
4942
flex-direction: column;
5043
overflow-y: auto;
51-
background-color: $dt('colors.primary.100');
44+
background-color: $dt('colors.primary.500');
5245
color: white;
5346
5447
@dark {
@@ -66,7 +59,7 @@ html {
6659
position: sticky;
6760
top: 0;
6861
width: 100%;
69-
background-color: $dt('colors.black');
62+
background-color: $dt('colors.primary.500');
7063
z-index: 50;
7164
7265
span {
@@ -87,7 +80,7 @@ html {
8780
}
8881
8982
footer {
90-
background-color: $dt('colors.black');
83+
background-color: $dt('colors.grape');
9184
display: flex;
9285
align-items: center;
9386
justify-content: space-between;

0 commit comments

Comments
 (0)