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

Adds deprecation warning on "down" behavior usage #168

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 14 additions & 10 deletions src/utils/styles/applyStyles/applyStyles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,36 +17,40 @@ const createStyleString = (

const breakpointOptions = Layout.getBreakpoint(breakpoint.name)

/**
* Wrap CSS rule in a media query only if its prop includes
* a breakpoint and behavior different than the default ones.
*/
const shouldWrapInMediaQuery =
// Wrap CSS rule in a media query only if its prop includes
// a breakpoint and behavior different than the default ones.
const isConditionalStyle =
breakpointOptions &&
!(breakpoint.isDefault && behavior === Layout.defaultBehavior)

return shouldWrapInMediaQuery
return isConditionalStyle
? `@media ${createMediaQuery(breakpointOptions, behavior)} {${styleProps}}`
: styleProps
}

export default function applyStyles(pristineProps: Props): string {
return (
Object.keys(pristineProps)
/* Parse each prop to include "breakpoint" and "behavior" */
// Parse each prop to include "breakpoint" and "behavior"
.map(parsePropName)
/* Filter out props that are not included in prop aliases */
// Filter out props that are not included in prop aliases
.filter(({ purePropName }) => propAliases.hasOwnProperty(purePropName))
/* Filter out props with "undefined" or "null" as value */
// Filter out props with "undefined" or "null" as value
.filter(({ originPropName }) => isset(pristineProps[originPropName]))
/* Map each prop to a CSS string */
// Map each prop to a CSS string
.map(({ purePropName, originPropName, breakpoint, behavior }) => {
const { props, transformValue } = propAliases[purePropName]
const propValue = pristineProps[originPropName]
const transformedPropValue = transformValue
? transformValue(propValue)
: propValue

if (behavior === 'down') {
console.warn(
`Deprecated usage of "down" behavior for prop "${originPropName}". Please replace this behavior with "up" or "only" behavior type instead.`,
)
}

return createStyleString(
props,
transformedPropValue,
Expand Down