Skip to content
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

Refactor dynamic interpolations to use a util #423

Merged
merged 13 commits into from
Dec 23, 2020
Merged

Conversation

itsdouges
Copy link
Collaborator

@itsdouges itsdouges commented Dec 21, 2020

Closes #346
Closes #333

This PR introduces an ix function which handles CSS custom property values, with an optional suffix/prefix.

Currently only the suffix and prefix handling is done for template literal CSS, so for example:

styled.div`
  content: "${props => props.content}";
`;

Would result in this ix call:

ix(props.content, '"', '"');

If we did this for object CSS instead you would need to handle this yourself:

styled.div({
  content: props => ('"' + props.content + '"'),
});

Which ends up with the ix call:

ix('"' + props.content + '"'); // no suffix or prefix argument

@itsdouges itsdouges added the wip 🚧 Work in progress - don't judge too harshly. label Dec 21, 2020
@itsdouges itsdouges changed the title feat: adds interpolation util Refactor dynamic interpolations to use a util Dec 22, 2020
@itsdouges itsdouges force-pushed the interpolation-func branch 2 times, most recently from f4aa4bc to 266928b Compare December 22, 2020 05:48
@itsdouges itsdouges marked this pull request as ready for review December 22, 2020 05:58
@itsdouges itsdouges removed the wip 🚧 Work in progress - don't judge too harshly. label Dec 22, 2020
* @param suffix
* @param prefix
*/
export default function cssCustomPropertyValue(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to do some perf testing here since we introduce this during runtime?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nevermind. It won't be that slow..hehe. Few if checks only.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😄

@pgmanutd
Copy link
Contributor

Can we add bundlesize check for ix?

* @param prefix
*/
export default function cssCustomPropertyValue(
value: string | number | number,
Copy link
Contributor

@pgmanutd pgmanutd Dec 22, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
value: string | number | number,
value: string | number | undefined | null,

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -31,15 +31,15 @@ export type Interpolations<TProps extends Record<string, unknown>> = (
* props from `StyledProps`.
*/
export interface StyledFunctionFromTag<TTag extends keyof JSX.IntrinsicElements> {
<TProps extends Record<string, unknown>>(
<TProps extends unknown>(
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixing types that i introduced a regression to in the TS change before, oops

Copy link
Contributor

@pgmanutd pgmanutd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@itsdouges itsdouges merged commit 3e04974 into master Dec 23, 2020
@itsdouges itsdouges deleted the interpolation-func branch December 23, 2020 04:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants