-
Notifications
You must be signed in to change notification settings - Fork 227
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(top-app-bar): add children components for composition
- Loading branch information
Showing
32 changed files
with
1,234 additions
and
254 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,54 @@ | ||
// The MIT License | ||
// | ||
// Copyright (c) 2019 Google, Inc. | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in | ||
// all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
// THE SOFTWARE. | ||
|
||
import * as React from 'react'; | ||
import * as classnames from 'classnames'; | ||
import {cssClasses} from './constants'; | ||
|
||
|
||
export interface IconProps<T> extends React.HTMLProps<T> { | ||
actionItem?: boolean; | ||
className?: string; | ||
children: React.ReactElement<any>; | ||
navIcon?: boolean; | ||
} | ||
|
||
|
||
const Icon: <T extends Element = HTMLElement>(props: IconProps<T> ) => | ||
React.ReactElement<HTMLElement> = ({ | ||
/* eslint-disable react/prop-types */ | ||
actionItem = false, | ||
navIcon = false, | ||
className, | ||
children, | ||
...otherProps | ||
/* eslint-enable react/prop-types */ | ||
}) => | ||
React.cloneElement(children, { | ||
...otherProps, | ||
className: classnames(className, children.props.className, { | ||
[cssClasses.ACTION_ITEM]: actionItem, | ||
[cssClasses.NAV_ICON]: navIcon, | ||
}), | ||
}); | ||
|
||
export default Icon; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// The MIT License | ||
// | ||
// Copyright (c) 2019 Google, Inc. | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in | ||
// all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
// THE SOFTWARE. | ||
|
||
import * as React from 'react'; | ||
import * as classnames from 'classnames'; | ||
import {cssClasses} from './constants'; | ||
|
||
export interface RowProps<T> extends React.HTMLProps<T> { | ||
className?: string; | ||
tag?: string; | ||
}; | ||
|
||
const Row: <T extends HTMLElement = HTMLDivElement>(props: RowProps<T>) => | ||
React.ReactElement<T> = ({ | ||
/* eslint-disable react/prop-types */ | ||
children, | ||
className, | ||
tag: Tag = 'div', | ||
...otherProps | ||
/* eslint-enable react/prop-types */ | ||
}) => ( | ||
// @ts-ignore https://github.com/Microsoft/TypeScript/issues/28892 | ||
<Tag className={classnames(className, cssClasses.ROW)} {...otherProps}> | ||
{children} | ||
</Tag> | ||
); | ||
|
||
export default Row; |
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,55 @@ | ||
// The MIT License | ||
// | ||
// Copyright (c) 2019 Google, Inc. | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in | ||
// all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
// THE SOFTWARE. | ||
|
||
import * as React from 'react'; | ||
import * as classnames from 'classnames'; | ||
import {cssClasses} from './constants'; | ||
|
||
export interface SectionProps<T> extends React.HTMLProps<T> { | ||
align?: 'start' | 'end'; | ||
className?: string; | ||
tag?: string; | ||
}; | ||
|
||
const Section: <T extends HTMLElement = HTMLElement>(props: SectionProps<T>) => | ||
React.ReactElement<T> = ({ | ||
/* eslint-disable react/prop-types */ | ||
align, | ||
className, | ||
children, | ||
tag: Tag = 'section', | ||
...otherProps | ||
/* eslint-enable react/prop-types */ | ||
}) => ( | ||
// @ts-ignore https://github.com/Microsoft/TypeScript/issues/28892 | ||
<Tag | ||
className={classnames(className, cssClasses.SECTION, { | ||
[cssClasses.SECTION_START]: align === 'start', | ||
[cssClasses.SECTION_END]: align === 'end', | ||
})} | ||
{...otherProps} | ||
> | ||
{children} | ||
</Tag> | ||
); | ||
|
||
export default Section; |
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,47 @@ | ||
// The MIT License | ||
// | ||
// Copyright (c) 2019 Google, Inc. | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in | ||
// all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
// THE SOFTWARE. | ||
|
||
import * as React from 'react'; | ||
import * as classnames from 'classnames'; | ||
import {cssClasses} from './constants'; | ||
|
||
export interface TitleProps<T> extends React.HTMLProps<T> { | ||
className?: string; | ||
tag?: string; | ||
}; | ||
|
||
const Title: <T extends HTMLElement = HTMLSpanElement>(props: TitleProps<T>) => | ||
React.ReactElement<T> = ({ | ||
/* eslint-disable react/prop-types */ | ||
children, | ||
className, | ||
tag: Tag = 'span', | ||
...otherProps | ||
/* eslint-enable react/prop-types */ | ||
}) => ( | ||
// @ts-ignore https://github.com/Microsoft/TypeScript/issues/28892 | ||
<Tag className={classnames(className, cssClasses.TITLE)} {...otherProps} > | ||
{children} | ||
</Tag> | ||
); | ||
|
||
export default Title; |
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 @@ | ||
// The MIT License | ||
// | ||
// Copyright (c) 2019 Google, Inc. | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in | ||
// all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
const BASE = 'mdc-top-app-bar'; | ||
const SECTION = `${BASE}__section`; | ||
const cssClasses = { | ||
BASE, | ||
ROW: `${BASE}__row`, | ||
SECTION, | ||
SECTION_START: `${SECTION}--align-start`, | ||
SECTION_END: `${SECTION}--align-end`, | ||
FIXED: `${BASE}--fixed`, | ||
SHORT: `${BASE}--short`, | ||
SHORT_COLLAPSED: `${BASE}--short-collapsed`, | ||
PROMINENT: `${BASE}--prominent`, | ||
DENSE: `${BASE}--dense`, | ||
TITLE: `${BASE}__title`, | ||
ACTION_ITEM: `${BASE}__action-item`, | ||
NAV_ICON: `${BASE}__navigation-icon`, | ||
}; | ||
|
||
export {cssClasses}; |
Oops, something went wrong.