-
Notifications
You must be signed in to change notification settings - Fork 371
Masthead #6170
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
Merged
Merged
Masthead #6170
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
131baba
masthead initial commit
kmcfaul 6eb35eb
change brand to anchor, add example
kmcfaul d58021e
add display, insets, bgColor
kmcfaul b934f26
remove non-composable alternative, add demos, add unit tests, add int…
kmcfaul d9aa5cb
add description to Masthead docs stating the common structure
kmcfaul 58b4824
flip to TS examples/demos
kmcfaul 67eea51
update link example to use icon
kmcfaul ea9e15f
className set to undefined
kmcfaul 2d1fba8
rebase and add modifiers to toolbar
kmcfaul 0045324
add beta tag
kmcfaul 1ddba53
use Brand, update kebab position
kmcfaul d2e7608
add tabindex
kmcfaul File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,54 @@ | ||
import * as React from 'react'; | ||
import styles from '@patternfly/react-styles/css/components/Masthead/masthead'; | ||
import { css } from '@patternfly/react-styles'; | ||
import { formatBreakpointMods } from '../../helpers/util'; | ||
export interface MastheadProps extends React.DetailedHTMLProps<React.HTMLProps<HTMLDivElement>, HTMLDivElement> { | ||
/** Content rendered inside of the masthead */ | ||
children?: React.ReactNode; | ||
/** Additional classes added to the masthead */ | ||
className?: string; | ||
/** Background theme color of the masthead */ | ||
backgroundColor?: 'dark' | 'light' | 'light200'; | ||
/** Display type at various breakpoints */ | ||
display?: { | ||
default?: 'inline' | 'stack'; | ||
sm?: 'inline' | 'stack'; | ||
md?: 'inline' | 'stack'; | ||
lg?: 'inline' | 'stack'; | ||
xl?: 'inline' | 'stack'; | ||
'2xl'?: 'inline' | 'stack'; | ||
}; | ||
/** Insets at various breakpoints */ | ||
inset?: { | ||
default?: 'insetNone' | 'insetXs' | 'insetSm' | 'insetMd' | 'insetLg' | 'insetXl' | 'inset2xl' | 'inset3xl'; | ||
sm?: 'insetNone' | 'insetXs' | 'insetSm' | 'insetMd' | 'insetLg' | 'insetXl' | 'inset2xl' | 'inset3xl'; | ||
md?: 'insetNone' | 'insetXs' | 'insetSm' | 'insetMd' | 'insetLg' | 'insetXl' | 'inset2xl' | 'inset3xl'; | ||
lg?: 'insetNone' | 'insetXs' | 'insetSm' | 'insetMd' | 'insetLg' | 'insetXl' | 'inset2xl' | 'inset3xl'; | ||
xl?: 'insetNone' | 'insetXs' | 'insetSm' | 'insetMd' | 'insetLg' | 'insetXl' | 'inset2xl' | 'inset3xl'; | ||
'2xl'?: 'insetNone' | 'insetXs' | 'insetSm' | 'insetMd' | 'insetLg' | 'insetXl' | 'inset2xl' | 'inset3xl'; | ||
}; | ||
} | ||
|
||
export const Masthead: React.FunctionComponent<MastheadProps> = ({ | ||
children, | ||
className, | ||
backgroundColor = 'dark', | ||
display, | ||
inset, | ||
...props | ||
}: MastheadProps) => ( | ||
<header | ||
className={css( | ||
styles.masthead, | ||
formatBreakpointMods(display, styles, 'display-'), | ||
formatBreakpointMods(inset, styles), | ||
backgroundColor === 'light' && styles.modifiers.light, | ||
backgroundColor === 'light200' && styles.modifiers.light_200, | ||
className | ||
)} | ||
{...props} | ||
> | ||
{children} | ||
</header> | ||
); | ||
Masthead.displayName = 'Masthead'; |
28 changes: 28 additions & 0 deletions
28
packages/react-core/src/components/Masthead/MastheadBrand.tsx
This file contains hidden or 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,28 @@ | ||
import * as React from 'react'; | ||
import styles from '@patternfly/react-styles/css/components/Masthead/masthead'; | ||
import { css } from '@patternfly/react-styles'; | ||
|
||
export interface MastheadBrandProps | ||
extends React.DetailedHTMLProps<React.HTMLProps<HTMLAnchorElement>, HTMLAnchorElement> { | ||
/** Content rendered inside of the masthead brand. */ | ||
children?: React.ReactNode; | ||
/** Additional classes added to the masthead brand. */ | ||
className?: string; | ||
/** Component type of the masthead brand. */ | ||
component?: React.ElementType<any> | React.ComponentType<any>; | ||
kmcfaul marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
export const MastheadBrand: React.FunctionComponent<MastheadBrandProps> = ({ | ||
children, | ||
className, | ||
component = 'a', | ||
...props | ||
}: MastheadBrandProps) => { | ||
const Component = component as any; | ||
return ( | ||
<Component className={css(styles.mastheadBrand, className)} tabIndex={0} {...props}> | ||
{children} | ||
</Component> | ||
); | ||
}; | ||
MastheadBrand.displayName = 'MastheadBrand'; |
21 changes: 21 additions & 0 deletions
21
packages/react-core/src/components/Masthead/MastheadContent.tsx
This file contains hidden or 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,21 @@ | ||
import * as React from 'react'; | ||
import styles from '@patternfly/react-styles/css/components/Masthead/masthead'; | ||
import { css } from '@patternfly/react-styles'; | ||
|
||
export interface MastheadContentProps extends React.DetailedHTMLProps<React.HTMLProps<HTMLDivElement>, HTMLDivElement> { | ||
/** Content rendered inside of the masthead content block. */ | ||
children?: React.ReactNode; | ||
/** Additional classes added to the masthead content. */ | ||
className?: string; | ||
} | ||
|
||
export const MastheadContent: React.FunctionComponent<MastheadContentProps> = ({ | ||
children, | ||
className, | ||
...props | ||
}: MastheadContentProps) => ( | ||
<div className={css(styles.mastheadContent, className)} {...props}> | ||
{children} | ||
</div> | ||
); | ||
MastheadContent.displayName = 'MastheadContent'; |
21 changes: 21 additions & 0 deletions
21
packages/react-core/src/components/Masthead/MastheadMain.tsx
This file contains hidden or 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,21 @@ | ||
import * as React from 'react'; | ||
import styles from '@patternfly/react-styles/css/components/Masthead/masthead'; | ||
import { css } from '@patternfly/react-styles'; | ||
|
||
export interface MastheadMainProps extends React.DetailedHTMLProps<React.HTMLProps<HTMLDivElement>, HTMLDivElement> { | ||
/** Content rendered inside of the masthead main block. */ | ||
children?: React.ReactNode; | ||
/** Additional classes added to the masthead main. */ | ||
className?: string; | ||
} | ||
|
||
export const MastheadMain: React.FunctionComponent<MastheadMainProps> = ({ | ||
children, | ||
className, | ||
...props | ||
}: MastheadMainProps) => ( | ||
<div className={css(styles.mastheadMain, className)} {...props}> | ||
{children} | ||
</div> | ||
); | ||
MastheadMain.displayName = 'MastheadMain'; |
21 changes: 21 additions & 0 deletions
21
packages/react-core/src/components/Masthead/MastheadToggle.tsx
This file contains hidden or 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,21 @@ | ||
import * as React from 'react'; | ||
import styles from '@patternfly/react-styles/css/components/Masthead/masthead'; | ||
import { css } from '@patternfly/react-styles'; | ||
|
||
export interface MastheadToggleProps extends React.DetailedHTMLProps<React.HTMLProps<HTMLDivElement>, HTMLDivElement> { | ||
/** Content rendered inside of the masthead toggle. */ | ||
children?: React.ReactNode; | ||
/** Additional classes added to the masthead toggle. */ | ||
className?: string; | ||
} | ||
|
||
export const MastheadToggle: React.FunctionComponent<MastheadToggleProps> = ({ | ||
children, | ||
className, | ||
...props | ||
}: MastheadToggleProps) => ( | ||
<div className={css(styles.mastheadToggle, className)} {...props}> | ||
kmcfaul marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{children} | ||
</div> | ||
); | ||
MastheadToggle.displayName = 'MastheadToggle'; |
135 changes: 135 additions & 0 deletions
135
packages/react-core/src/components/Masthead/__tests__/Masthead.test.tsx
This file contains hidden or 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,135 @@ | ||
import React from 'react'; | ||
import { shallow, mount } from 'enzyme'; | ||
import { Masthead, MastheadBrand, MastheadContent, MastheadMain, MastheadToggle } from '../index'; | ||
|
||
describe('Masthead', () => { | ||
test('verify basic', () => { | ||
const view = shallow(<Masthead>test</Masthead>); | ||
|
||
expect(view).toMatchSnapshot(); | ||
}); | ||
|
||
test('verify full structure', () => { | ||
const view = mount( | ||
<Masthead> | ||
<MastheadToggle>Toggle</MastheadToggle> | ||
<MastheadMain> | ||
<MastheadBrand>Logo</MastheadBrand> | ||
</MastheadMain> | ||
<MastheadContent> | ||
<span>Content</span> | ||
</MastheadContent> | ||
</Masthead> | ||
); | ||
|
||
expect(view).toMatchSnapshot(); | ||
}); | ||
|
||
test('verify custom class', () => { | ||
const view = mount(<Masthead className="custom-css">test</Masthead>); | ||
|
||
expect(view).toMatchSnapshot(); | ||
}); | ||
|
||
test('verify inline display breakpoints', () => { | ||
const view = mount( | ||
<Masthead | ||
display={{ default: 'inline', sm: 'inline', md: 'inline', lg: 'inline', xl: 'inline', '2xl': 'inline' }} | ||
> | ||
test | ||
</Masthead> | ||
); | ||
|
||
expect(view).toMatchSnapshot(); | ||
}); | ||
|
||
test('verify stack display breakpoints', () => { | ||
const view = mount( | ||
<Masthead display={{ default: 'stack', sm: 'stack', md: 'stack', lg: 'stack', xl: 'stack', '2xl': 'stack' }}> | ||
test | ||
</Masthead> | ||
); | ||
|
||
expect(view).toMatchSnapshot(); | ||
}); | ||
|
||
Object.values(['insetNone', 'insetXs', 'insetSm', 'insetMd', 'insetLg', 'insetXl', 'inset2xl', 'inset3xl'] as [ | ||
'insetNone', | ||
'insetXs', | ||
'insetSm', | ||
'insetMd', | ||
'insetLg', | ||
'insetXl', | ||
'inset2xl', | ||
'inset3xl' | ||
]).forEach(inset => { | ||
test(`verify ${inset} inset breakpoints`, () => { | ||
const view = mount( | ||
<Masthead inset={{ default: inset, sm: inset, md: inset, lg: inset, xl: inset, '2xl': inset }}>test</Masthead> | ||
); | ||
expect(view).toMatchSnapshot(); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('MastheadBrand', () => { | ||
test('verify basic', () => { | ||
const view = shallow(<MastheadBrand>test</MastheadBrand>); | ||
|
||
expect(view).toMatchSnapshot(); | ||
}); | ||
|
||
test('verify custom class', () => { | ||
const view = mount(<MastheadBrand className="custom-css">test</MastheadBrand>); | ||
|
||
expect(view).toMatchSnapshot(); | ||
}); | ||
|
||
test('verify custom component', () => { | ||
const view = mount(<MastheadBrand component="div">test</MastheadBrand>); | ||
|
||
expect(view).toMatchSnapshot(); | ||
}); | ||
}); | ||
|
||
describe('MastheadContent', () => { | ||
test('verify basic', () => { | ||
const view = shallow(<MastheadContent>test</MastheadContent>); | ||
|
||
expect(view).toMatchSnapshot(); | ||
}); | ||
|
||
test('verify custom class', () => { | ||
const view = mount(<MastheadContent className="custom-css">test</MastheadContent>); | ||
|
||
expect(view).toMatchSnapshot(); | ||
}); | ||
}); | ||
|
||
describe('MastheadMain', () => { | ||
test('verify basic', () => { | ||
const view = shallow(<MastheadMain>test</MastheadMain>); | ||
|
||
expect(view).toMatchSnapshot(); | ||
}); | ||
|
||
test('verify custom class', () => { | ||
const view = mount(<MastheadMain className="custom-css">test</MastheadMain>); | ||
|
||
expect(view).toMatchSnapshot(); | ||
}); | ||
}); | ||
|
||
describe('MastheadToggle', () => { | ||
test('verify basic', () => { | ||
const view = shallow(<MastheadToggle>test</MastheadToggle>); | ||
|
||
expect(view).toMatchSnapshot(); | ||
}); | ||
|
||
test('verify custom class', () => { | ||
const view = mount(<MastheadToggle className="custom-css">test</MastheadToggle>); | ||
|
||
expect(view).toMatchSnapshot(); | ||
}); | ||
}); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.