-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(TopBar): initial implementation (unstable) (#692)
- Loading branch information
1 parent
44ff745
commit 4ef15bc
Showing
6 changed files
with
145 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { render } from '@testing-library/react'; | ||
import TopBar_unstable from './TopBar_unstable'; | ||
|
||
describe('TopBar_unstable', () => { | ||
it('Can render without ThemeProvider', () => { | ||
const { baseElement } = render(<TopBar_unstable />); | ||
|
||
expect(baseElement).toBeTruthy(); | ||
}); | ||
}); |
38 changes: 38 additions & 0 deletions
38
libs/spark/src/TopBar_unstable/TopBar_unstable.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,38 @@ | ||
import React from 'react'; | ||
import type { Meta, Story as DefaultStory } from '@storybook/react/types-6-0'; | ||
import { TopBar_unstable, TopBarProps_unstable } from '..'; | ||
|
||
export const _retyped = TopBar_unstable as typeof TopBar_unstable; | ||
|
||
export default { | ||
title: '@ps/TopBar', | ||
component: _retyped, | ||
excludeStories: ['_retyped'], | ||
} as Meta; | ||
|
||
const Template = (args) => <TopBar_unstable {...args} />; | ||
|
||
type Story = DefaultStory<TopBarProps_unstable>; | ||
|
||
export const Default: Story = Template.bind({}); | ||
Default.storyName = '(default)'; | ||
|
||
export const ColorStandard: Story = Template.bind({}); | ||
ColorStandard.args = { color: 'standard' }; | ||
ColorStandard.storyName = 'color=standard'; | ||
|
||
export const ColorBrand: Story = Template.bind({}); | ||
ColorBrand.args = { color: 'brand' }; | ||
ColorBrand.storyName = 'color=brand'; | ||
|
||
export const ColorInverse: Story = Template.bind({}); | ||
ColorInverse.args = { color: 'inverse' }; | ||
ColorInverse.storyName = 'color=inverse'; | ||
|
||
export const ColorAlternative: Story = Template.bind({}); | ||
ColorAlternative.args = { color: 'alternative' }; | ||
ColorAlternative.storyName = 'color=alternative'; | ||
|
||
export const ColorTransparent: Story = Template.bind({}); | ||
ColorTransparent.args = { color: 'transparent' }; | ||
ColorTransparent.storyName = 'color=transparent'; |
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,90 @@ | ||
import { | ||
default as MuiAppBar, | ||
AppBarProps as MuiAppBarProps, | ||
} from '@material-ui/core/AppBar'; | ||
import clsx from 'clsx'; | ||
import React, { forwardRef } from 'react'; | ||
import { StandardProps } from '../utils'; | ||
import withStyles, { Styles } from '../withStyles'; | ||
|
||
export interface TopBarProps_unstable | ||
extends StandardProps< | ||
MuiAppBarProps, | ||
TopBarClassKey_unstable, | ||
'classes' | 'color' | 'elevation' | 'square' | 'variant' | ||
> { | ||
/** | ||
* The color of the component. | ||
*/ | ||
color?: 'standard' | 'inverse' | 'brand' | 'transparent' | 'alternative'; | ||
} | ||
|
||
export type TopBarClassKey_unstable = 'root'; | ||
|
||
type PrivateClassKey = | ||
| 'private-root-color-alternative' | ||
| 'private-root-color-inverse' | ||
| 'private-root-color-brand' | ||
| 'private-root-color-standard' | ||
| 'private-root-color-transparent'; | ||
|
||
const styles: Styles<TopBarClassKey_unstable | PrivateClassKey> = (theme) => ({ | ||
/* Styles applied to the root element. */ | ||
root: { | ||
borderBottom: theme.unstable_borders.standard, | ||
borderColor: theme.unstable_palette.neutral[80], | ||
minHeight: 64, | ||
[theme.breakpoints.down('sm')]: { | ||
minHeight: 48, | ||
}, | ||
}, | ||
/* Private */ | ||
'private-root-color-alternative': { | ||
backgroundColor: theme.unstable_palette.background.alternative, | ||
}, | ||
'private-root-color-brand': { | ||
backgroundColor: theme.unstable_palette.background.brand, | ||
borderColor: theme.unstable_palette.neutral[600], | ||
}, | ||
'private-root-color-inverse': { | ||
backgroundColor: theme.unstable_palette.background.inverse, | ||
borderColor: theme.unstable_palette.neutral[0], | ||
}, | ||
'private-root-color-standard': { | ||
backgroundColor: theme.unstable_palette.background.default, | ||
}, | ||
'private-root-color-transparent': { | ||
backgroundColor: 'transparent', | ||
}, | ||
}); | ||
|
||
const UnstyledTopBar = forwardRef<HTMLDivElement, TopBarProps_unstable>( | ||
function TopBar(props, ref) { | ||
const { classes, color = 'standard', ...other } = props; | ||
|
||
return ( | ||
<MuiAppBar | ||
classes={{ | ||
root: clsx(classes.root, { | ||
[classes['private-root-color-alternative']]: | ||
color === 'alternative', | ||
[classes['private-root-color-brand']]: color === 'brand', | ||
[classes['private-root-color-inverse']]: color === 'inverse', | ||
[classes['private-root-color-standard']]: color === 'standard', | ||
[classes['private-root-color-transparent']]: | ||
color === 'transparent', | ||
}), | ||
}} | ||
elevation={0} | ||
ref={ref} | ||
{...other} | ||
/> | ||
); | ||
} | ||
); | ||
|
||
const TopBar_unstable = withStyles(styles, { | ||
name: 'MuiSparkTopBar_unstable', | ||
})(UnstyledTopBar) as typeof UnstyledTopBar; | ||
|
||
export default TopBar_unstable; |
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,2 @@ | ||
export { default } from './TopBar_unstable'; | ||
export * from './TopBar_unstable'; |
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