Skip to content

Commit 1588397

Browse files
authored
Support space-evenly value for justifyContent attribute (#678)
1 parent 2090ad9 commit 1588397

File tree

5 files changed

+83
-1
lines changed

5 files changed

+83
-1
lines changed

examples/justify-content/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import './justify-content.js';
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import React from 'react';
2+
import {render, Box, Text} from '../../src/index.js';
3+
4+
function JustifyContent() {
5+
return (
6+
<Box flexDirection="column">
7+
<Box>
8+
<Text>[</Text>
9+
<Box justifyContent="flex-start" width={20} height={1}>
10+
<Text>X</Text>
11+
<Text>Y</Text>
12+
</Box>
13+
<Text>] flex-start</Text>
14+
</Box>
15+
<Box>
16+
<Text>[</Text>
17+
<Box justifyContent="flex-end" width={20} height={1}>
18+
<Text>X</Text>
19+
<Text>Y</Text>
20+
</Box>
21+
<Text>] flex-end</Text>
22+
</Box>
23+
<Box>
24+
<Text>[</Text>
25+
<Box justifyContent="center" width={20} height={1}>
26+
<Text>X</Text>
27+
<Text>Y</Text>
28+
</Box>
29+
<Text>] center</Text>
30+
</Box>
31+
<Box>
32+
<Text>[</Text>
33+
<Box justifyContent="space-around" width={20} height={1}>
34+
<Text>X</Text>
35+
<Text>Y</Text>
36+
</Box>
37+
<Text>] space-around</Text>
38+
</Box>
39+
<Box>
40+
<Text>[</Text>
41+
<Box justifyContent="space-between" width={20} height={1}>
42+
<Text>X</Text>
43+
<Text>Y</Text>
44+
</Box>
45+
<Text>] space-between</Text>
46+
</Box>
47+
<Box>
48+
<Text>[</Text>
49+
<Box justifyContent="space-evenly" width={20} height={1}>
50+
<Text>X</Text>
51+
<Text>Y</Text>
52+
</Box>
53+
<Text>] space-evenly</Text>
54+
</Box>
55+
</Box>
56+
);
57+
}
58+
59+
render(<JustifyContent />);

readme.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -837,7 +837,7 @@ See [align-self](https://css-tricks.com/almanac/properties/a/align-self/).
837837
##### justifyContent
838838

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

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

@@ -868,6 +868,12 @@ See [justify-content](https://css-tricks.com/almanac/properties/j/justify-conten
868868
<Text>Y</Text>
869869
</Box>
870870
// [ X Y ]
871+
872+
<Box justifyContent="space-evenly">
873+
<Text>X</Text>
874+
<Text>Y</Text>
875+
</Box>
876+
// [ X Y ]
871877
```
872878

873879
#### Visibility

src/styles.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ export type Styles = {
152152
| 'flex-end'
153153
| 'space-between'
154154
| 'space-around'
155+
| 'space-evenly'
155156
| 'center';
156157

157158
/**
@@ -483,6 +484,10 @@ const applyFlexStyles = (node: YogaNode, style: Styles): void => {
483484
if (style.justifyContent === 'space-around') {
484485
node.setJustifyContent(Yoga.JUSTIFY_SPACE_AROUND);
485486
}
487+
488+
if (style.justifyContent === 'space-evenly') {
489+
node.setJustifyContent(Yoga.JUSTIFY_SPACE_EVENLY);
490+
}
486491
}
487492
};
488493

test/flex-justify-content.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,17 @@ test('row - align two text nodes on the edges', t => {
5757
t.is(output, 'A B');
5858
});
5959

60+
test('row - space evenly two text nodes', t => {
61+
const output = renderToString(
62+
<Box justifyContent="space-evenly" width={10}>
63+
<Text>A</Text>
64+
<Text>B</Text>
65+
</Box>,
66+
);
67+
68+
t.is(output, ' A B');
69+
});
70+
6071
// Yoga has a bug, where first child in a container with space-around doesn't have
6172
// the correct X coordinate and measure function is used on that child node
6273
test.failing('row - align two text nodes with equal space around them', t => {

0 commit comments

Comments
 (0)