Skip to content

Multiple arguments in utils functions #1070

Answered by sandgraham
nob3110 asked this question in Help
Discussion options

You must be logged in to vote

I've been using an array or object to wrap the arguments into a single argument.

createStitches({
  utils: {
    paddingVH: ([v, h]: [number, number]) => ({
      paddingTop: v,
      paddingBottom: v,
      paddingLeft: h,
      paddingRight: h,
    }),
  },
});

css({ paddingVH: [2, 3] });

Can also use Stitches.PropertyValue to keep the types theme aware:

type Size = Stitches.PropertyValue<'sizes'>;
createStitches({
  utils: {
    paddingVH: ([v, h]: [Size, Size]) => ({
      paddingTop: v,
      paddingBottom: v,
      paddingLeft: h,
      paddingRight: h,
    }),
  },
});

css({ paddingVH: ["$2", "$3"] });

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@nob3110
Comment options

Answer selected by nob3110
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
2 participants