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

Implements justifyContent space-evenly #678

Merged
merged 5 commits into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions examples/justify-content/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import './justify-content.js';
59 changes: 59 additions & 0 deletions examples/justify-content/justify-content.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import React from 'react';
import {render, Box, Text} from '../../src/index.js';

function JustifyContent() {
return (
<Box flexDirection="column">
<Box>
<Text>[</Text>
<Box justifyContent="flex-start" width={20} height={1}>
<Text>X</Text>
<Text>Y</Text>
</Box>
<Text>] flex-start</Text>
</Box>
<Box>
<Text>[</Text>
<Box justifyContent="flex-end" width={20} height={1}>
<Text>X</Text>
<Text>Y</Text>
</Box>
<Text>] flex-end</Text>
</Box>
<Box>
<Text>[</Text>
<Box justifyContent="center" width={20} height={1}>
<Text>X</Text>
<Text>Y</Text>
</Box>
<Text>] center</Text>
</Box>
<Box>
<Text>[</Text>
<Box justifyContent="space-around" width={20} height={1}>
<Text>X</Text>
<Text>Y</Text>
</Box>
<Text>] space-around</Text>
</Box>
<Box>
<Text>[</Text>
<Box justifyContent="space-between" width={20} height={1}>
<Text>X</Text>
<Text>Y</Text>
</Box>
<Text>] space-between</Text>
</Box>
<Box>
<Text>[</Text>
<Box justifyContent="space-evenly" width={20} height={1}>
<Text>X</Text>
<Text>Y</Text>
</Box>
<Text>] space-evenly</Text>
</Box>
</Box>
);
}

render(<JustifyContent />);
8 changes: 7 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -837,7 +837,7 @@ See [align-self](https://css-tricks.com/almanac/properties/a/align-self/).
##### justifyContent

Type: `string`\
Allowed values: `flex-start` `center` `flex-end` `space-between` `space-around`
Allowed values: `flex-start` `center` `flex-end` `space-between` `space-around` `space-evenly`

See [justify-content](https://css-tricks.com/almanac/properties/j/justify-content/).

Expand Down Expand Up @@ -868,6 +868,12 @@ See [justify-content](https://css-tricks.com/almanac/properties/j/justify-conten
<Text>Y</Text>
</Box>
// [ X Y ]

<Box justifyContent="space-evenly">
<Text>X</Text>
<Text>Y</Text>
</Box>
// [ X Y ]
```

#### Visibility
Expand Down
5 changes: 5 additions & 0 deletions src/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ export type Styles = {
| 'flex-end'
| 'space-between'
| 'space-around'
| 'space-evenly'
| 'center';

/**
Expand Down Expand Up @@ -483,6 +484,10 @@ const applyFlexStyles = (node: YogaNode, style: Styles): void => {
if (style.justifyContent === 'space-around') {
node.setJustifyContent(Yoga.JUSTIFY_SPACE_AROUND);
}

if (style.justifyContent === 'space-evenly') {
node.setJustifyContent(Yoga.JUSTIFY_SPACE_EVENLY);
}
}
};

Expand Down
11 changes: 11 additions & 0 deletions test/flex-justify-content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,17 @@ test('row - align two text nodes on the edges', t => {
t.is(output, 'A B');
});

test('row - space evenly two text nodes', t => {
const output = renderToString(
<Box justifyContent="space-evenly" width={10}>
<Text>A</Text>
<Text>B</Text>
</Box>,
);

t.is(output, ' A B');
});

// Yoga has a bug, where first child in a container with space-around doesn't have
// the correct X coordinate and measure function is used on that child node
test.failing('row - align two text nodes with equal space around them', t => {
Expand Down