-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(global-header): add spacer component (#412)
Signed-off-by: Christoph Jerolimov <[email protected]>
- Loading branch information
1 parent
2f73462
commit 8a0b57f
Showing
10 changed files
with
156 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@red-hat-developer-hub/backstage-plugin-global-header': patch | ||
--- | ||
|
||
Add new Spacer component |
File renamed without changes.
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 |
---|---|---|
|
@@ -5,3 +5,4 @@ plugins: | |
|
||
nav: | ||
- About: index.md | ||
- Configuration: configuration.md |
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
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
58 changes: 58 additions & 0 deletions
58
workspaces/global-header/plugins/global-header/src/components/Spacer/Spacer.test.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,58 @@ | ||
/* | ||
* Copyright Red Hat, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import React from 'react'; | ||
|
||
import { render } from '@testing-library/react'; | ||
|
||
import { Spacer } from './Spacer'; | ||
|
||
describe('Spacer', () => { | ||
it('render some default styles', () => { | ||
const { container } = render(<Spacer />); | ||
expect(container.firstElementChild?.getAttribute('style')).toEqual( | ||
'flex-grow: 1; min-width: 8px;', | ||
); | ||
}); | ||
|
||
it('accepts another grow factor', () => { | ||
const { container } = render(<Spacer growFactor={2} />); | ||
expect(container.firstElementChild?.getAttribute('style')).toEqual( | ||
'flex-grow: 2; min-width: 8px;', | ||
); | ||
}); | ||
|
||
it('accepts number min width', () => { | ||
const { container } = render(<Spacer minWidth={2} />); | ||
expect(container.firstElementChild?.getAttribute('style')).toEqual( | ||
'flex-grow: 1; min-width: 16px;', | ||
); | ||
}); | ||
|
||
it('accepts string min width', () => { | ||
const { container } = render(<Spacer minWidth="24px" />); | ||
expect(container.firstElementChild?.getAttribute('style')).toEqual( | ||
'flex-grow: 1; min-width: 24px;', | ||
); | ||
}); | ||
|
||
it('accepts both', () => { | ||
const { container } = render(<Spacer growFactor={2} minWidth={2} />); | ||
expect(container.firstElementChild?.getAttribute('style')).toEqual( | ||
'flex-grow: 2; min-width: 16px;', | ||
); | ||
}); | ||
}); |
39 changes: 39 additions & 0 deletions
39
workspaces/global-header/plugins/global-header/src/components/Spacer/Spacer.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,39 @@ | ||
/* | ||
* Copyright Red Hat, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import React from 'react'; | ||
|
||
/** | ||
* @public | ||
*/ | ||
export interface SpacerProps { | ||
growFactor?: number; | ||
minWidth?: number | string; | ||
} | ||
|
||
/** | ||
* @public | ||
*/ | ||
export const Spacer = ({ growFactor = 1, minWidth = 1 }: SpacerProps) => { | ||
return ( | ||
<div | ||
style={{ | ||
flexGrow: growFactor, | ||
minWidth: typeof minWidth === 'number' ? minWidth * 8 : minWidth, | ||
}} | ||
/> | ||
); | ||
}; |
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