-
-
Notifications
You must be signed in to change notification settings - Fork 120
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Experimental getSchema
#333
base: main
Are you sure you want to change the base?
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
@joe-bell Just a heads up, if it helps - my fork already has some tests for Overall the code in both the actual code as well as the tests are very similar to the current state of |
Thanks @bengry! I think my preference here would be for us to instead do something kinda like: const getSchema: GetSchema = (comp) => {
// CVA function would spit the `variants` out from the specified `config`– untouched – into a hidden `_cva` metadata object. Which we'd use to create the schema
return comp._cva?.variants
? Object.fromEntries(
Object.entries(comp._cva?.variants).map(([key, value]) => [
key,
Object.keys(value).map((propertyKey) =>
normalizeVariantKey(propertyKey),
),
]),
)
: {};
};
// Demo
const button = cva({
variants: {
size: {
sm: "p-2",
},
},
});
const schema = getSchema(button); // { size: readonly "sm"[]; } I'd largely consider getting the Biggest challenge is going to be typing these damn types – it's had me pretty stumped today |
Making good progress, but gotta whole lotta types nonsense to figure out here |
@@ -35,7 +35,7 @@ | |||
"build:cjs": "swc ./src/index.ts --config-file ./.config/.swcrc -o dist/index.js -C module.type=commonjs", | |||
"build:esm": "swc ./src/index.ts --config-file ./.config/.swcrc -o dist/index.mjs -C module.type=es6 ", | |||
"build:tsc": "tsc --project .config/tsconfig.build.json", | |||
"bundlesize": "pnpm build && bundlesize -f 'dist/*.js' -s 1.6KB", | |||
"bundlesize": "pnpm build && bundlesize -f 'dist/*.js' -s 2KB", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Temporary bump. Might consider moving getSchema
into a separate cva/utils
entry point to keep bundlesize lower
@joe-bell I didn't look at your implementation too much, but here's a very quick POC I made for what you suggested. It split the ~2kB bundle size into two parts, and using ESM further reduces the bundle size a bit:
I also replaced Basic types work as expected, but I didn't implement the private variants, or the same for |
Oh nice, thanks for the heads up @bengry, I'll take a look! Feel pretty happy with the progress on my solution so far – mostly type issues |
Warning
Extremely WIP
Description
Surfaces a
getSchema
function to extract acva
component's variant schema for documentation purposesInspired by @bengry's wonderful proposal
Additional context
What is the purpose of this pull request?
Before submitting the PR, please make sure you do the following
fixes #123
).