Skip to content

Commit

Permalink
size property
Browse files Browse the repository at this point in the history
  • Loading branch information
oofdere committed Aug 5, 2024
1 parent e5e0876 commit cf7c9fc
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 11 deletions.
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@ I also really like semantic values, and Tailwind gives you sensible semantic val

## roadmap
- [x] `tw` units
- [ ] `@screen <breakpoint>` queries
- [ ] `@dark` and `@light` queries
- [x] `@screen <breakpoint>` queries
- [x] `@dark` and `@light` queries
- [x] `size` property that sets width and height
- [ ] `aspect-ratio: square` and `aspect-ratio: video`
- [ ] semantic `perspective`s
- [ ] translations as properties
- [ ] preflight
- [ ] typography
- [ ] inline variables
- [ ] `dark-light()`, `@light`, and `@dark` polyfilled for the multiple strategies in tailwind
- [ ] (maybe) daisyui and/or shadcn port
- [ ] (maybe) container queries
- [ ] respect tailwind config (prob only if there's financial demand lmao)
Expand Down
5 changes: 3 additions & 2 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import { composePlugins, type Plugin } from './src/plugin';
import { screens } from './src/screens';
import { spacing } from './src/spacing';
import { colorScheme } from './src/colorScheme';
import { size } from './src/size';

export const crosswind = composePlugins([screens, spacing, colorScheme])
export const crosswind = composePlugins([screens, spacing, colorScheme, size])

export { composePlugins, type Plugin, screens, spacing, colorScheme }
export { composePlugins, type Plugin, screens, spacing, colorScheme, size }
4 changes: 2 additions & 2 deletions playground.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import { composePlugins, spacing, screens, colorScheme, crosswind } from ".";
let { code, map } = transform({
filename: 'test.css',
minify: true,
code: new TextEncoder().encode('.foo{color: red;@light {color: green;}; @dark {color:yellow;}}'),
...crosswind
code: new TextEncoder().encode('.foo{size: 4em}'),
...composePlugins([crosswind])
});

console.log(code.toString())
27 changes: 27 additions & 0 deletions src/size.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import type { CustomAtRules, Visitor } from "lightningcss";

export const size: Visitor<CustomAtRules> = {
Declaration: {
custom: {
size: (prop) => {
return [{
property: "unparsed",
value: {
propertyId: {
property: "width"
},
value: prop.value
}
}, {
property: "unparsed",
value: {
propertyId: {
property: "height"
},
value: prop.value
}
}]
}
}
}
} as const;
14 changes: 14 additions & 0 deletions tests/size.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { expect, test } from "bun:test";
import { testHelper } from "./test";
import { size } from "../index";


test("size", () => {
expect(testHelper([size], '.foo {size: 1em}'))
.toBe('.foo{width:1em;height:1em}')
})

test("size auto", () => {
expect(testHelper([size], '.foo {size: auto}'))
.toBe('.foo{width:auto;height:auto}')
})
8 changes: 4 additions & 4 deletions tests/spacing.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import { spacing } from "../index";


test("tw units", () => {
expect(testHelper([spacing], '.foo {size: 1tw}'))
.toBe('.foo{size:.25rem}')
expect(testHelper([spacing], '.foo {width: 1tw}'))
.toBe('.foo{width:.25rem}')
})

test("calc w/ tw", () => {
expect(testHelper([spacing], '.foo {size: calc(var(--size) * 1tw)}'))
.toBe('.foo{size:calc(var(--size)*.25rem)}')
expect(testHelper([spacing], '.foo {width: calc(var(--size) * 1tw)}'))
.toBe('.foo{width:calc(var(--size)*.25rem)}')
})

0 comments on commit cf7c9fc

Please sign in to comment.