Last active
July 19, 2021 13:06
-
-
Save kosciolek/91dbdd855e9a6a475a98135f51c59942 to your computer and use it in GitHub Desktop.
Styled components variant and iif.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const iif = <PROPS extends unknown, PROP_NAME extends keyof PROPS>( | |
prop: PROP_NAME, | |
val?: PROPS[PROP_NAME] | |
) => (propsInner: PROPS) => { | |
if (val !== undefined) return propsInner[prop] === val ? "&" : "&.__NEVER"; | |
return propsInner[prop] ? "&" : "&.__NEVER"; | |
}; | |
export const variant = <PROPS extends unknown>( | |
prop: PROPS[keyof PROPS], | |
propName?: keyof PROPS | |
) => (propsInner: PROPS) => { | |
// @ts-ignore | |
return propsInner[propName || "variant"] === prop ? "&" : "&.__NEVER"; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment