Skip to content

Commit

Permalink
Add layout props to createText function
Browse files Browse the repository at this point in the history
The RN `Text` component supports layout styles like `flex` and `maxWidth` these are commonly used, especially flex={1} for layouting and therefore useful to be exposed as props.
  • Loading branch information
robrechtme committed Feb 23, 2024
1 parent 5c4b17c commit 39f19d9
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ and adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
## Next

- Fixed: clean up the project configuration for RN0.71, aligning some packages to the right version [#271](https://github.com/Shopify/restyle/pull/271) by [kelset](https://github.com/kelset) & [tido64](https://github.com/tido64)
- Added: Add layout props to createText function [#262](https://github.com/Shopify/restyle/pull/262) by [robrechtme](https://github.com/robrechtme)

## 2.4.2 - 2023-03-30

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const Text = createText<Theme>();
export default Text;
```

The Text component comes with the following [Restyle functions](/fundamentals/restyle-functions#predefined-restyle-functions): `color`, `textDecorationColor`, `opacity`, `visible`, `typography`, `textShadow`, `spacing`. It also includes a [variant](/fundamentals/variants) that picks up styles under the `textVariants` key in your theme:
The Text component comes with the following [Restyle functions](/fundamentals/restyle-functions#predefined-restyle-functions): `color`, `textDecorationColor`, `opacity`, `visible`, `typography`, `textShadow`, `spacing`, `layout`. It also includes a [variant](/fundamentals/variants) that picks up styles under the `textVariants` key in your theme:

```tsx
// In your theme
Expand Down
4 changes: 4 additions & 0 deletions src/createText.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import {
VisibleProps,
spacingShorthand,
SpacingShorthandProps,
layout,
LayoutProps,
} from './restyleFunctions';
import createVariant, {VariantProps} from './createVariant';

Expand All @@ -26,6 +28,7 @@ type BaseTextProps<Theme extends BaseTheme> = ColorProps<Theme> &
VisibleProps<Theme> &
TypographyProps<Theme> &
SpacingProps<Theme> &
LayoutProps<Theme> &
TextShadowProps<Theme> &
VariantProps<Theme, 'textVariants'>;

Expand All @@ -44,6 +47,7 @@ export const textRestyleFunctions = [
spacing,
spacingShorthand,
textShadow,
layout,
createVariant({themeKey: 'textVariants'}),
];

Expand Down
4 changes: 4 additions & 0 deletions src/test/createText.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ describe('createText', () => {
textTransform="capitalize"
verticalAlign="top"
writingDirection="rtl"
flex={1}
maxWidth={250}
>
Some text
</Text>
Expand Down Expand Up @@ -148,6 +150,8 @@ describe('createText', () => {
textTransform: 'capitalize',
verticalAlign: 'top',
writingDirection: 'rtl',
flex: 1,
maxWidth: 250,
},
]);
});
Expand Down

0 comments on commit 39f19d9

Please sign in to comment.