Skip to content

Commit 12fabc3

Browse files
committed
Add CSSX theme assets
1 parent 445c540 commit 12fabc3

10 files changed

Lines changed: 705 additions & 1 deletion

File tree

packages/css-to-rn/src/transform/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -559,6 +559,10 @@ function transformTransform (
559559
property: string,
560560
value: string
561561
): PropertyTransformResult {
562+
if (value.trim().toLowerCase() === 'none') {
563+
return { style: { transform: [] } }
564+
}
565+
562566
const parts = parseFunctionSequence(value)
563567
const transforms: TransformStyleValue[] = []
564568

packages/css-to-rn/test/engine/transform.test.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,17 @@ describe('@cssxjs/css-to-rn declaration transformer', () => {
8888
})
8989
})
9090

91+
it('transforms none into an empty transform list', () => {
92+
const result = transform([
93+
['transform', 'none'],
94+
])
95+
96+
assert.deepEqual(result.diagnostics, [])
97+
assert.deepEqual(result.style, {
98+
transform: [],
99+
})
100+
})
101+
91102
it('passes through box-shadow and filter strings', () => {
92103
const result = transform([
93104
['box-shadow', '0 2px 8px rgba(0,0,0,.2), 0 1px 2px #333'],

packages/cssxjs/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@
2727
"./runtime/web": "./runtime/web.js",
2828
"./runtime/react-native": "./runtime/react-native.js",
2929
"./runtime/web-teamplay": "./runtime/web-teamplay.js",
30-
"./runtime/react-native-teamplay": "./runtime/react-native-teamplay.js"
30+
"./runtime/react-native-teamplay": "./runtime/react-native-teamplay.js",
31+
"./themes/tailwind": "./themes/tailwind.js",
32+
"./themes/shadcn": "./themes/shadcn.js"
3133
},
3234
"publishConfig": {
3335
"access": "public"

packages/cssxjs/test/smoke.mjs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
import assert from 'node:assert/strict'
2+
import { readFileSync } from 'node:fs'
3+
import { dirname, join } from 'node:path'
4+
import { fileURLToPath } from 'node:url'
5+
import { compileCss } from '@cssxjs/css-to-rn'
26
import {
37
CssxProvider,
48
cssx,
@@ -41,3 +45,19 @@ assert.deepEqual(
4145
iconStyle: [[{ color: 'blue' }], { marginLeft: 8 }]
4246
}
4347
)
48+
49+
const packageDir = dirname(dirname(fileURLToPath(import.meta.url)))
50+
51+
for (const name of ['tailwind', 'shadcn']) {
52+
const source = readFileSync(join(packageDir, 'themes', `${name}.cssx.css`), 'utf8')
53+
assert.equal(source.includes('@theme'), false, `${name} theme must not use Tailwind @theme syntax`)
54+
55+
const sheet = compileCss(source, { mode: 'build', sourceId: `cssxjs/themes/${name}` })
56+
assert.equal(sheet.error, undefined, `${name} theme should compile without fatal errors`)
57+
assert.deepEqual(
58+
sheet.diagnostics.filter(diagnostic => diagnostic.level === 'error'),
59+
[],
60+
`${name} theme should compile without errors`
61+
)
62+
assert.equal(sheet.metadata.hasVars, true, `${name} theme should expose CSS variables`)
63+
}
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
/*
2+
* shadcn/ui theme variables adapted for CSSX.
3+
* Source: https://ui.shadcn.com/docs/theming
4+
*
5+
* The default theme is represented by :root. The dark variant is represented
6+
* by :root.dark so CssxProvider theme='auto' can select it on dark systems.
7+
*/
8+
9+
:root {
10+
--radius: 0.625rem;
11+
12+
--background: oklch(1 0 0);
13+
--foreground: oklch(0.145 0 0);
14+
--card: oklch(1 0 0);
15+
--card-foreground: oklch(0.145 0 0);
16+
--popover: oklch(1 0 0);
17+
--popover-foreground: oklch(0.145 0 0);
18+
--primary: oklch(0.205 0 0);
19+
--primary-foreground: oklch(0.985 0 0);
20+
--secondary: oklch(0.97 0 0);
21+
--secondary-foreground: oklch(0.205 0 0);
22+
--muted: oklch(0.97 0 0);
23+
--muted-foreground: oklch(0.556 0 0);
24+
--accent: oklch(0.97 0 0);
25+
--accent-foreground: oklch(0.205 0 0);
26+
--destructive: oklch(0.577 0.245 27.325);
27+
--destructive-foreground: oklch(0.985 0 0);
28+
--success: oklch(0.723 0.219 149.579);
29+
--success-foreground: oklch(0.985 0 0);
30+
--warning: oklch(0.769 0.188 70.08);
31+
--warning-foreground: oklch(0.205 0 0);
32+
--border: oklch(0.922 0 0);
33+
--input: oklch(0.922 0 0);
34+
--ring: oklch(0.708 0 0);
35+
--chart-1: oklch(0.646 0.222 41.116);
36+
--chart-2: oklch(0.6 0.118 184.704);
37+
--chart-3: oklch(0.398 0.07 227.392);
38+
--chart-4: oklch(0.828 0.189 84.429);
39+
--chart-5: oklch(0.769 0.188 70.08);
40+
--sidebar: oklch(0.985 0 0);
41+
--sidebar-foreground: oklch(0.145 0 0);
42+
--sidebar-primary: oklch(0.205 0 0);
43+
--sidebar-primary-foreground: oklch(0.985 0 0);
44+
--sidebar-accent: oklch(0.97 0 0);
45+
--sidebar-accent-foreground: oklch(0.205 0 0);
46+
--sidebar-border: oklch(0.922 0 0);
47+
--sidebar-ring: oklch(0.708 0 0);
48+
49+
--color-background: var(--background);
50+
--color-foreground: var(--foreground);
51+
--color-card: var(--card);
52+
--color-card-foreground: var(--card-foreground);
53+
--color-popover: var(--popover);
54+
--color-popover-foreground: var(--popover-foreground);
55+
--color-primary: var(--primary);
56+
--color-primary-foreground: var(--primary-foreground);
57+
--color-secondary: var(--secondary);
58+
--color-secondary-foreground: var(--secondary-foreground);
59+
--color-muted: var(--muted);
60+
--color-muted-foreground: var(--muted-foreground);
61+
--color-accent: var(--accent);
62+
--color-accent-foreground: var(--accent-foreground);
63+
--color-destructive: var(--destructive);
64+
--color-destructive-foreground: var(--destructive-foreground);
65+
--color-success: var(--success);
66+
--color-success-foreground: var(--success-foreground);
67+
--color-warning: var(--warning);
68+
--color-warning-foreground: var(--warning-foreground);
69+
--color-border: var(--border);
70+
--color-input: var(--input);
71+
--color-ring: var(--ring);
72+
--color-chart-1: var(--chart-1);
73+
--color-chart-2: var(--chart-2);
74+
--color-chart-3: var(--chart-3);
75+
--color-chart-4: var(--chart-4);
76+
--color-chart-5: var(--chart-5);
77+
--color-sidebar: var(--sidebar);
78+
--color-sidebar-foreground: var(--sidebar-foreground);
79+
--color-sidebar-primary: var(--sidebar-primary);
80+
--color-sidebar-primary-foreground: var(--sidebar-primary-foreground);
81+
--color-sidebar-accent: var(--sidebar-accent);
82+
--color-sidebar-accent-foreground: var(--sidebar-accent-foreground);
83+
--color-sidebar-border: var(--sidebar-border);
84+
--color-sidebar-ring: var(--sidebar-ring);
85+
86+
--radius-sm: calc(var(--radius) - 4px);
87+
--radius-md: calc(var(--radius) - 2px);
88+
--radius-lg: var(--radius);
89+
--radius-xl: calc(var(--radius) + 4px);
90+
}
91+
92+
:root.dark {
93+
--background: oklch(0.145 0 0);
94+
--foreground: oklch(0.985 0 0);
95+
--card: oklch(0.205 0 0);
96+
--card-foreground: oklch(0.985 0 0);
97+
--popover: oklch(0.205 0 0);
98+
--popover-foreground: oklch(0.985 0 0);
99+
--primary: oklch(0.922 0 0);
100+
--primary-foreground: oklch(0.205 0 0);
101+
--secondary: oklch(0.269 0 0);
102+
--secondary-foreground: oklch(0.985 0 0);
103+
--muted: oklch(0.269 0 0);
104+
--muted-foreground: oklch(0.708 0 0);
105+
--accent: oklch(0.269 0 0);
106+
--accent-foreground: oklch(0.985 0 0);
107+
--destructive: oklch(0.704 0.191 22.216);
108+
--destructive-foreground: oklch(0.985 0 0);
109+
--success: oklch(0.696 0.17 162.48);
110+
--success-foreground: oklch(0.145 0 0);
111+
--warning: oklch(0.769 0.188 70.08);
112+
--warning-foreground: oklch(0.145 0 0);
113+
--border: oklch(1 0 0 / 10%);
114+
--input: oklch(1 0 0 / 15%);
115+
--ring: oklch(0.556 0 0);
116+
--chart-1: oklch(0.488 0.243 264.376);
117+
--chart-2: oklch(0.696 0.17 162.48);
118+
--chart-3: oklch(0.769 0.188 70.08);
119+
--chart-4: oklch(0.627 0.265 303.9);
120+
--chart-5: oklch(0.645 0.246 16.439);
121+
--sidebar: oklch(0.205 0 0);
122+
--sidebar-foreground: oklch(0.985 0 0);
123+
--sidebar-primary: oklch(0.488 0.243 264.376);
124+
--sidebar-primary-foreground: oklch(0.985 0 0);
125+
--sidebar-accent: oklch(0.269 0 0);
126+
--sidebar-accent-foreground: oklch(0.985 0 0);
127+
--sidebar-border: oklch(1 0 0 / 10%);
128+
--sidebar-ring: oklch(0.556 0 0);
129+
}
130+

packages/cssxjs/themes/shadcn.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import type { CompiledCssSheet } from '@cssxjs/css-to-rn'
2+
3+
declare const theme: CompiledCssSheet
4+
export default theme

packages/cssxjs/themes/shadcn.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { default } from './shadcn.cssx.css'

0 commit comments

Comments
 (0)