-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #322 from department-of-veterans-affairs/feature/2…
…57-roettger-SpacerComponent [Feature] Standalone Spacer component
- Loading branch information
Showing
7 changed files
with
156 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
packages/components/src/components/Spacer/Spacer.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import { Meta, StoryObj } from '@storybook/react' | ||
import { View, ViewStyle } from 'react-native' | ||
import React from 'react' | ||
|
||
import { Button, ButtonVariants } from '../Button/Button' | ||
import { Icon } from '../Icon/Icon' | ||
import { Link } from '../Link/Link' | ||
import { Spacer, SpacerProps } from './Spacer' | ||
|
||
const centerProps: ViewStyle = { | ||
flex: 1, | ||
justifyContent: 'center', | ||
alignItems: 'center', | ||
} | ||
|
||
const meta: Meta<SpacerProps> = { | ||
title: 'Spacer', | ||
component: Spacer, | ||
decorators: [ | ||
(Story) => ( | ||
<View style={centerProps}> | ||
<Story /> | ||
</View> | ||
), | ||
], | ||
} | ||
|
||
export default meta | ||
|
||
type Story = StoryObj<SpacerProps> | ||
|
||
export const Horizontal: Story = { | ||
name: 'Horizontal', | ||
args: { | ||
horizontal: true, | ||
}, | ||
decorators: [ | ||
(Story) => ( | ||
<View | ||
style={{ | ||
...centerProps, | ||
flexDirection: 'row', | ||
}}> | ||
<Icon name="Info" preventScaling /> | ||
<Story /> | ||
<Link | ||
text="Link text after Spacer" | ||
type="custom" | ||
onPress={() => { | ||
null | ||
}} | ||
/> | ||
</View> | ||
), | ||
], | ||
} | ||
|
||
export const Vertical: Story = { | ||
name: 'Vertical', | ||
decorators: [ | ||
(Story) => ( | ||
<View | ||
style={{ | ||
...centerProps, | ||
flexDirection: 'column', | ||
}}> | ||
<Button | ||
label="Button before Spacer" | ||
onPress={() => { | ||
null | ||
}} | ||
/> | ||
<Story /> | ||
<Button | ||
label="Button after Spacer" | ||
buttonType={ButtonVariants.Secondary} | ||
onPress={() => { | ||
null | ||
}} | ||
/> | ||
</View> | ||
), | ||
], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { Spacer } from './Spacer' | ||
import { render, screen } from '@testing-library/react-native' | ||
import React from 'react' | ||
|
||
describe('Spacer', () => { | ||
it('renders correctly at default size (10)', () => { | ||
render(<Spacer />) | ||
|
||
const spacer = screen.root | ||
|
||
expect(spacer.props.style.height).toBe(10) | ||
expect(spacer.props.style.width).toBe('auto') | ||
}) | ||
|
||
it('renders correctly at overridden size 20', () => { | ||
render(<Spacer size={20} />) | ||
|
||
const spacer = screen.root | ||
|
||
expect(spacer.props.style.height).toBe(20) | ||
expect(spacer.props.style.width).toBe('auto') | ||
}) | ||
|
||
it('renders horizontally at default size (10)', () => { | ||
render(<Spacer horizontal />) | ||
|
||
const spacer = screen.root | ||
|
||
expect(spacer.props.style.height).toBe('auto') | ||
expect(spacer.props.style.width).toBe(10) | ||
}) | ||
|
||
it('renders horizontally at overridden size 20', () => { | ||
render(<Spacer size={20} horizontal />) | ||
|
||
const spacer = screen.root | ||
|
||
expect(spacer.props.style.height).toBe('auto') | ||
expect(spacer.props.style.width).toBe(20) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { View } from 'react-native' | ||
import React, { FC } from 'react' | ||
|
||
export type SpacerProps = { | ||
/** Size of the spacer, default 10 */ | ||
size?: number | ||
/** True for horizontal spacing */ | ||
horizontal?: boolean | ||
} | ||
|
||
/** | ||
* Convenience component for handling spacing without managing margin/padding between elements | ||
* @param size - Size of the spacer, default 10 | ||
* @param horizontal - True for horizontal spacing | ||
* @returns A non-visible component sized to provide appropriate spacing | ||
*/ | ||
export const Spacer: FC<SpacerProps> = ({ size = 10, horizontal = false }) => { | ||
return ( | ||
<View | ||
style={{ | ||
width: horizontal ? size : 'auto', | ||
height: !horizontal ? size : 'auto', | ||
}} | ||
/> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters