Skip to content

Instantly share code, notes, and snippets.

@joe-bell
Last active October 5, 2021 12:15
Show Gist options
  • Save joe-bell/a81649f9d839aee975f8cbf6599bdb8c to your computer and use it in GitHub Desktop.
Save joe-bell/a81649f9d839aee975f8cbf6599bdb8c to your computer and use it in GitHub Desktop.
Stitches: Themed Variants
import type * as Stitches from '@stitches/react';
import { css, config } from "./stitches.config";
type TCSS = Stitches.CSS<typeof config>;
const { space } = config.theme;
type TSpaceKey = keyof typeof space;
const gap = (Object.keys(space) as Array<TSpaceKey>).reduce<
Record<TSpaceKey, TCSS>
>(
(acc, cv) => ({
...acc,
[cv]: { $$stackGap: `$space$${cv}` },
}),
{} as any
);
/**
* Stack
*/
export const stack = css({
display: "flex",
listStyleType: "none",
paddingLeft: 0,
"> * + *": {
marginTop: "$$stackGap",
},
variants: {
gap,
},
defaultVariants: {
gap: 4,
},
});
@ashtonlance
Copy link

What is TCSS?

@joe-bell
Copy link
Author

joe-bell commented Oct 5, 2021

What is TCSS?

Just updated to make this gist a little more self-contained – hope it helps

@ashtonlance
Copy link

Ah ha! That's what I kinda figured that type was. I appreciate the clarification.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment