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

sync: master to alpha #2707

Merged
merged 1 commit into from
Oct 10, 2023
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
19 changes: 19 additions & 0 deletions src/Stack/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,22 @@ Stacks are vertical by default and stacked items are full-width by default. Watc
<div className="border p-2">third block</div>
</Stack>
```

## Reversed props

- **Vertical** with `reversed` prop
```jsx live
<Stack gap={3} reversed>
<Button>first button</Button>
<Button>second button</Button>
<Button>third button</Button>
</Stack>
```
- **Horizontal** with `reversed` prop
```jsx live
<Stack direction="horizontal" gap={3} reversed>
<div className="border p-2">first block</div>
<div className="border p-2">second block</div>
<div className="border p-2">third block</div>
</Stack>
```
13 changes: 12 additions & 1 deletion src/Stack/Stack.test.jsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,28 @@
import React from 'react';
import { render } from '@testing-library/react';
import { mount } from 'enzyme';
import renderer from 'react-test-renderer';

import Stack from './index';

const stackList = ['First', 'Second'];

describe('<Stack />', () => {
describe('correct rendering', () => {
it('renders without props', () => {
const tree = renderer.create((
<Stack>content</Stack>
<Stack>{stackList.map((el) => <div>{el}</div>)}</Stack>
)).toJSON();
expect(tree).toMatchSnapshot();
});
it('renders with the reversed prop', () => {
const { container } = render(
<Stack reversed>
{stackList.reverse().map((el) => <div>{el}</div>)}
</Stack>,
);
expect(container).toMatchSnapshot();
});
it('renders with the vertical direction', () => {
const wrapper = mount(<Stack>Content</Stack>);
expect(wrapper.find('.pgn__vstack').length).toBeGreaterThan(0);
Expand Down
22 changes: 21 additions & 1 deletion src/Stack/__snapshots__/Stack.test.jsx.snap
Original file line number Diff line number Diff line change
@@ -1,9 +1,29 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`<Stack /> correct rendering renders with the reversed prop 1`] = `
<div>
<div
class="pgn__vstack pgn__stack-reversed"
>
<div>
Second
</div>
<div>
First
</div>
</div>
</div>
`;

exports[`<Stack /> correct rendering renders without props 1`] = `
<div
className="pgn__vstack"
>
content
<div>
First
</div>
<div>
Second
</div>
</div>
`;
5 changes: 5 additions & 0 deletions src/Stack/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const DIRECTION_VARIANTS = [
const Stack = forwardRef(({
direction,
gap,
reversed,
children,
className,
...rest
Expand All @@ -19,6 +20,7 @@ const Stack = forwardRef(({
className={classNames(
direction === 'horizontal' ? 'pgn__hstack' : 'pgn__vstack',
gap ? `pgn__stack-gap--${gap}` : '',
reversed ? 'pgn__stack-reversed' : '',
className,
)}
{...rest}
Expand All @@ -39,6 +41,8 @@ Stack.propTypes = {
* `0, 0.5, ... 6`.
*/
gap: PropTypes.number,
/** Specifies the order of the children. */
reversed: PropTypes.bool,
/** Specifies an additional `className` to add to the base element. */
className: PropTypes.string,
};
Expand All @@ -47,6 +51,7 @@ Stack.defaultProps = {
direction: 'vertical',
gap: 0,
className: undefined,
reversed: false,
};

export default Stack;
9 changes: 9 additions & 0 deletions src/Stack/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,18 @@
.pgn__vstack {
flex: 1 1 auto;
flex-direction: column;

&.pgn__stack-reversed {
flex-direction: column-reverse;
}
}

.pgn__hstack {
flex-direction: row;
align-items: center;

&.pgn__stack-reversed {
flex-direction: row-reverse;
justify-content: flex-end;
}
}
Loading