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

feat: add borderCurve and pointerEvents style properties #228

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ and adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## Next

- Add support of borderCurve and pointerEvents style properties in [#228](https://github.com/Shopify/restyle/pull/228) by [mlecoq](https://github.com/mlecoq)

## 2.3.0 - 2023-01-30

- Renamed gap shorthands to be lowercase [#218](https://github.com/Shopify/restyle/pull/218) by [mlecoq](https://github.com/mlecoq)
Expand Down
3 changes: 2 additions & 1 deletion documentation/docs/fundamentals/restyle-functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@ The Restyle library comes with a number of predefined Restyle functions for your
| backgroundColor | backgroundColor [bg] | colors |
| color | color | colors |
| opacity | opacity | _none_ |
| pointerEvents | pointerEvents | _none_ |
| visible | display (maps `true` / `false` to `flex` / `none`) | _none_ |
| spacing | margin [m], marginTop [mt], marginRight [mr], marginBottom [mb], marginLeft [ml], marginStart [ms], marginEnd[me], marginHorizontal [mx], marginVertical [my], padding [p], paddingTop [pt], paddingRight [pr], paddingBottom [pb], paddingLeft [pl], paddingStart [ps], paddingEnd [pe], paddingHorizontal [px], paddingVertical [py], gap [g], rowGap [rG], columnGap [cG] | spacing |
| layout | width, height, minWidth, maxWidth, minHeight, maxHeight, overflow, aspectRatio, alignContent, alignItems, alignSelf, justifyContent, flex, flexBasis, flexDirection, flexGrow, flexShrink, flexWrap | _none_ |
| position | position, top, right, bottom, left, start, end | _none_ |
| position | zIndex | zIndices |
| border | borderBottomWidth, borderLeftWidth, borderRightWidth, borderStartWidth, borderEndWidth, borderStyle, borderTopWidth, borderWidth | _none_ |
| border | borderBottomWidth, borderLeftWidth, borderRightWidth, borderStartWidth, borderEndWidth, borderStyle, borderTopWidth, borderWidth, borderCurve | _none_ |
| border | borderColor, borderTopColor, borderRightColor, borderLeftColor, borderStartColor, borderEndColor, borderBottomColor | colors |
| border | borderRadius, borderBottomLeftRadius, borderBottomRightRadius, borderBottomStartRadius, borderBottomEndRadius, borderTopLeftRadius, borderTopRightRadius, borderTopStartRadius, borderTopEndRadius | borderRadii |
| shadow | shadowOpacity, shadowOffset, shadowRadius, elevation | _none_ |
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"@shopify/eslint-plugin": "^42.0.3",
"@types/jest": "^29.2.1",
"@types/react": "^18.0.24",
"@types/react-native": "^0.71.0",
"@types/react-native": "^0.71.2",
"@types/react-test-renderer": "^18.0.0",
"babel-jest": "^29.2.1",
"eslint": "^8.32.0",
Expand Down
4 changes: 4 additions & 0 deletions src/createBox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,14 @@ import {
SpacingShorthandProps,
BackgroundColorShorthandProps,
spacingShorthand,
PointEventProps,
pointerEvents,
} from './restyleFunctions';

type BaseBoxProps<Theme extends BaseTheme> = BackgroundColorProps<Theme> &
OpacityProps<Theme> &
VisibleProps<Theme> &
PointEventProps<Theme> &
LayoutProps<Theme> &
SpacingProps<Theme> &
BorderProps<Theme> &
Expand All @@ -49,6 +52,7 @@ export const boxRestyleFunctions = [
backgroundColorShorthand,
opacity,
visible,
pointerEvents,
layout,
spacing,
spacingShorthand,
Expand Down
11 changes: 11 additions & 0 deletions src/restyleFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ const borderProperties = {
borderStartWidth: true,
borderEndWidth: true,
borderWidth: true,
borderCurve: true,
};

const borderRadiusProperties = {
Expand Down Expand Up @@ -167,6 +168,10 @@ export const visible = createRestyleFunction({
transform: ({value}) => (value === false ? 'none' : 'flex'),
});

export const pointerEvents = createRestyleFunction({
property: 'pointerEvents',
});

export const spacing = getKeys(spacingProperties).map(property => {
return createRestyleFunction({
property,
Expand Down Expand Up @@ -278,6 +283,12 @@ export interface OpacityProps<Theme extends BaseTheme> {
opacity?: ResponsiveValue<number, Theme['breakpoints']>;
}

export interface PointEventProps<Theme extends BaseTheme> {
pointerEvents?: ResponsiveValue<
ViewStyle['pointerEvents'],
Theme['breakpoints']
>;
}
export interface VisibleProps<Theme extends BaseTheme> {
visible?: ResponsiveValue<boolean, Theme['breakpoints']>;
}
Expand Down
32 changes: 29 additions & 3 deletions src/test/createRestyleComponent.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ import {
spacingShorthand,
OpacityProps,
opacity,
border,
BorderProps,
pointerEvents,
} from '../restyleFunctions';
import {ThemeProvider} from '../context';
import createVariant, {VariantProps} from '../createVariant';
Expand Down Expand Up @@ -61,9 +64,10 @@ const Component = createRestyleComponent<
SpacingProps<Theme> &
SpacingShorthandProps<Theme> &
OpacityProps<Theme> &
BorderProps<Theme> &
ViewProps,
Theme
>([backgroundColor, spacing, spacingShorthand, opacity]);
>([backgroundColor, spacing, spacingShorthand, opacity, border, pointerEvents]);
const cardVariant = createVariant<ThemeWithVariant, 'cardVariants'>({
themeKey: 'cardVariants',
});
Expand Down Expand Up @@ -107,12 +111,12 @@ describe('createRestyleComponent', () => {
it('does not pass styling properties to the child', () => {
const {root} = render(
<ThemeProvider theme={theme}>
<Component opacity={0.5} pointerEvents="auto" />
<Component opacity={0.5} removeClippedSubviews />
Copy link
Contributor

Choose a reason for hiding this comment

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

Why was pointerEvents replaced by removeClippedSubviews?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because pointerEvents is now present in style since rn 0.71 so this test failed. I have used removeClippedSubview but I could choose another property (that is not a style one)

</ThemeProvider>,
);
expect(root.findByType(View).props).toStrictEqual({
style: [{opacity: 0.5}],
pointerEvents: 'auto',
removeClippedSubviews: true,
});
});

Expand Down Expand Up @@ -218,5 +222,27 @@ describe('createRestyleComponent', () => {
style: [{gap: 8, columnGap: 8, rowGap: 8}],
});
});

it('passes borderCurve', () => {
const {root} = render(
<ThemeProvider theme={theme}>
<Component borderCurve />
</ThemeProvider>,
);
expect(root.findByType(View).props).toStrictEqual({
style: [{borderCurve: true}],
});
});

it('passes pointerEvent', () => {
const {root} = render(
<ThemeProvider theme={theme}>
<Component pointerEvents="none" />
</ThemeProvider>,
);
expect(root.findByType(View).props).toStrictEqual({
style: [{pointerEvents: 'none'}],
});
});
});
});
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2129,10 +2129,10 @@
resolved "https://registry.yarnpkg.com/@types/prop-types/-/prop-types-15.7.2.tgz#0e58ae66773d7fd7c372a493aff740878ec9ceaa"
integrity sha512-f8JzJNWVhKtc9dg/dyDNfliTKNOJSLa7Oht/ElZdF/UbMUmAH3rLmAk3ODNjw0mZajDEgatA03tRjB4+Dp/tzA==

"@types/react-native@^0.71.0":
version "0.71.0"
resolved "https://registry.yarnpkg.com/@types/react-native/-/react-native-0.71.0.tgz#a6f4d2d6c3730e86ceef0870d3cf221a54ec94c2"
integrity sha512-4MAoseGM8zv5PKQyc2SvKldvOmCJX4mNqj+mDqh0J9yJMzWQnGenk2vQCi+jxMXa3xWYIgx+ewaCSw0XiiGGSw==
"@types/react-native@^0.71.2":
version "0.71.2"
resolved "https://registry.yarnpkg.com/@types/react-native/-/react-native-0.71.2.tgz#b8ba52c2fd07d3d64fa87ae5d9b4fbbd3b9cbffd"
integrity sha512-RJ0slxB/aVh6gDBZcGusDLIMW+ydsigzOVva9nODPfZApvIY4UgacV5PAlyk/CScJaN7Frh4sZaD9bD73uc9HQ==
dependencies:
"@types/react" "*"

Expand Down