Skip to content

Commit

Permalink
fix: Prefer null over undefined on BoxTransforms (#426)
Browse files Browse the repository at this point in the history
  • Loading branch information
tassoevan authored Apr 14, 2021
1 parent 2516d42 commit 9cba6b8
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import React, { useCallback, useEffect, useState } from 'react';

import { appendClassName } from '../../../helpers/appendClassName';
import { useStyle } from '../../../hooks/useStyle';
import { BoxTransforms, useComposedBoxTransform } from '../transforms';
import { BoxTransforms, useComposedBoxTransform } from '../BoxTransforms';

function AnimatedVisibility({
children,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { createContext, useContext, useMemo } from 'react';

export const BoxTransforms = createContext();
export const BoxTransforms = createContext<null | ((props: any) => any)>(null);

export const useBoxTransform = () => useContext(BoxTransforms);

export const useComposedBoxTransform = (fn) => {
export const useComposedBoxTransform = (fn: (props: any) => any) => {
const parentFn = useContext(BoxTransforms);

return useMemo(() => {
Expand All @@ -16,6 +16,6 @@ export const useComposedBoxTransform = (fn) => {
return parentFn;
}

return (...args) => fn(parentFn(...args));
return (props: any) => fn(parentFn(props));
}, [fn, parentFn]);
};
2 changes: 1 addition & 1 deletion packages/fuselage/src/components/Box/Flex/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import PropTypes from 'prop-types';
import React, { useCallback } from 'react';

import { BoxTransforms, useComposedBoxTransform } from '../transforms';
import { BoxTransforms, useComposedBoxTransform } from '../BoxTransforms';

function FlexContainer({
inline = false,
Expand Down
2 changes: 1 addition & 1 deletion packages/fuselage/src/components/Box/Scrollable/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import React, { useRef, useCallback } from 'react';

import { appendClassName } from '../../../helpers/appendClassName';
import { useStyle } from '../../../hooks/useStyle';
import { BoxTransforms, useComposedBoxTransform } from '../transforms';
import { BoxTransforms, useComposedBoxTransform } from '../BoxTransforms';

const getTouchingEdges = (element) => ({
top: !element.scrollTop,
Expand Down
4 changes: 2 additions & 2 deletions packages/fuselage/src/components/Box/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import { appendClassName } from '../../helpers/appendClassName';
import { prependClassName } from '../../helpers/prependClassName';
import { useStyle } from '../../hooks/useStyle';
import { useStyleSheet } from '../../hooks/useStyleSheet';
import { useBoxTransform, BoxTransforms } from './BoxTransforms';
import {
/* propTypes as stylingPropsPropTypes, */ useStylingProps,
} from './stylingProps';
import { useBoxTransform, BoxTransforms } from './transforms';

export const useArrayLikeClassNameProp = (props) => {
const classNames = [].concat(props.className);
Expand Down Expand Up @@ -98,7 +98,7 @@ export const Box = memo(
const element = createElement(is, props, children);

if (transformFn) {
return <BoxTransforms.Provider children={element} />;
return <BoxTransforms.Provider children={element} value={null} />;
}

return element;
Expand Down
2 changes: 1 addition & 1 deletion packages/fuselage/src/components/Margins/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { createPropType } from '../../helpers/createPropType';
import { patchChildren } from '../../helpers/patchChildren';
import { useStyle } from '../../hooks/useStyle';
import { margin } from '../../styleTokens';
import { BoxTransforms, useComposedBoxTransform } from '../Box/transforms';
import { BoxTransforms, useComposedBoxTransform } from '../Box/BoxTransforms';

function Margins(props) {
const {
Expand Down
38 changes: 19 additions & 19 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3962,13 +3962,13 @@ __metadata:
languageName: node
linkType: hard

"@rocket.chat/css-in-js@^0.22.0, @rocket.chat/css-in-js@workspace:packages/css-in-js":
"@rocket.chat/css-in-js@^0.23.0, @rocket.chat/css-in-js@workspace:packages/css-in-js":
version: 0.0.0-use.local
resolution: "@rocket.chat/css-in-js@workspace:packages/css-in-js"
dependencies:
"@emotion/hash": ^0.8.0
"@rocket.chat/eslint-config": ^0.4.0
"@rocket.chat/memo": ^0.22.0
"@rocket.chat/memo": ^0.23.0
"@rollup/plugin-commonjs": ^17.0.0
"@rollup/plugin-json": ^4.1.0
"@rollup/plugin-node-resolve": ^11.0.1
Expand Down Expand Up @@ -4038,14 +4038,14 @@ __metadata:
languageName: node
linkType: hard

"@rocket.chat/fuselage-hooks@^0.22.0, @rocket.chat/fuselage-hooks@workspace:packages/fuselage-hooks":
"@rocket.chat/fuselage-hooks@^0.23.0, @rocket.chat/fuselage-hooks@workspace:packages/fuselage-hooks":
version: 0.0.0-use.local
resolution: "@rocket.chat/fuselage-hooks@workspace:packages/fuselage-hooks"
dependencies:
"@microsoft/api-documenter": ^7.8.21
"@microsoft/api-extractor": ^7.9.2
"@rocket.chat/eslint-config": ^0.4.0
"@rocket.chat/fuselage-tokens": ^0.22.0
"@rocket.chat/fuselage-tokens": ^0.23.0
"@rollup/plugin-commonjs": ^15.1.0
"@rollup/plugin-json": ^4.1.0
"@rollup/plugin-node-resolve": ^9.0.0
Expand Down Expand Up @@ -4080,7 +4080,7 @@ __metadata:
languageName: unknown
linkType: soft

"@rocket.chat/fuselage-polyfills@^0.22.0, @rocket.chat/fuselage-polyfills@workspace:packages/fuselage-polyfills":
"@rocket.chat/fuselage-polyfills@^0.23.0, @rocket.chat/fuselage-polyfills@workspace:packages/fuselage-polyfills":
version: 0.0.0-use.local
resolution: "@rocket.chat/fuselage-polyfills@workspace:packages/fuselage-polyfills"
dependencies:
Expand All @@ -4093,7 +4093,7 @@ __metadata:
languageName: unknown
linkType: soft

"@rocket.chat/fuselage-tokens@^0.22.0, @rocket.chat/fuselage-tokens@workspace:packages/fuselage-tokens":
"@rocket.chat/fuselage-tokens@^0.23.0, @rocket.chat/fuselage-tokens@workspace:packages/fuselage-tokens":
version: 0.0.0-use.local
resolution: "@rocket.chat/fuselage-tokens@workspace:packages/fuselage-tokens"
dependencies:
Expand All @@ -4113,11 +4113,11 @@ __metadata:
"@babel/preset-react": ^7.10.4
"@rocket.chat/apps-engine": ^1.17.0
"@rocket.chat/eslint-config": ^0.4.0
"@rocket.chat/fuselage": ^0.22.0
"@rocket.chat/fuselage-hooks": ^0.22.0
"@rocket.chat/fuselage-polyfills": ^0.22.0
"@rocket.chat/icons": ^0.22.0
"@rocket.chat/ui-kit": ^0.22.0
"@rocket.chat/fuselage": ^0.23.0
"@rocket.chat/fuselage-hooks": ^0.23.0
"@rocket.chat/fuselage-polyfills": ^0.23.0
"@rocket.chat/icons": ^0.23.0
"@rocket.chat/ui-kit": ^0.23.0
"@storybook/addon-essentials": ^6.1.11
"@storybook/addons": ^6.1.11
"@storybook/react": ^6.1.11
Expand Down Expand Up @@ -4153,7 +4153,7 @@ __metadata:
languageName: unknown
linkType: soft

"@rocket.chat/fuselage@^0.22.0, @rocket.chat/fuselage@workspace:packages/fuselage":
"@rocket.chat/fuselage@^0.23.0, @rocket.chat/fuselage@workspace:packages/fuselage":
version: 0.0.0-use.local
resolution: "@rocket.chat/fuselage@workspace:packages/fuselage"
dependencies:
Expand All @@ -4163,11 +4163,11 @@ __metadata:
"@babel/plugin-transform-runtime": ^7.11.5
"@babel/preset-env": ^7.11.5
"@babel/preset-react": ^7.10.4
"@rocket.chat/css-in-js": ^0.22.0
"@rocket.chat/css-in-js": ^0.23.0
"@rocket.chat/eslint-config": ^0.4.0
"@rocket.chat/fuselage-hooks": ^0.22.0
"@rocket.chat/fuselage-polyfills": ^0.22.0
"@rocket.chat/fuselage-tokens": ^0.22.0
"@rocket.chat/fuselage-hooks": ^0.23.0
"@rocket.chat/fuselage-polyfills": ^0.23.0
"@rocket.chat/fuselage-tokens": ^0.23.0
"@rocket.chat/memo": ^0.6.3-dev.180
"@storybook/addon-essentials": ^6.1.11
"@storybook/addon-jest": ^6.1.11
Expand Down Expand Up @@ -4230,7 +4230,7 @@ __metadata:
languageName: unknown
linkType: soft

"@rocket.chat/icons@^0.22.0, @rocket.chat/icons@workspace:packages/icons":
"@rocket.chat/icons@^0.23.0, @rocket.chat/icons@workspace:packages/icons":
version: 0.0.0-use.local
resolution: "@rocket.chat/icons@workspace:packages/icons"
dependencies:
Expand All @@ -4255,7 +4255,7 @@ __metadata:
languageName: unknown
linkType: soft

"@rocket.chat/memo@^0.22.0, @rocket.chat/memo@workspace:packages/memo":
"@rocket.chat/memo@^0.23.0, @rocket.chat/memo@workspace:packages/memo":
version: 0.0.0-use.local
resolution: "@rocket.chat/memo@workspace:packages/memo"
dependencies:
Expand Down Expand Up @@ -4308,7 +4308,7 @@ __metadata:
languageName: unknown
linkType: soft

"@rocket.chat/ui-kit@^0.22.0, @rocket.chat/ui-kit@workspace:packages/ui-kit":
"@rocket.chat/ui-kit@^0.23.0, @rocket.chat/ui-kit@workspace:packages/ui-kit":
version: 0.0.0-use.local
resolution: "@rocket.chat/ui-kit@workspace:packages/ui-kit"
dependencies:
Expand Down

0 comments on commit 9cba6b8

Please sign in to comment.