Skip to content

Commit 42b7368

Browse files
committed
feat: add app-bar
1 parent fcbdffe commit 42b7368

File tree

6 files changed

+135
-36
lines changed

6 files changed

+135
-36
lines changed

package-lock.json

Lines changed: 107 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
"homepage": "https://github.com/AutoScheduleJS/react-elements#readme",
3030
"peerDependencies": {
3131
"emotion": "^10.0.5",
32-
"emotion-theming": "^10.0.5",
3332
"react": "^16.7.0"
3433
},
3534
"devDependencies": {
@@ -49,10 +48,11 @@
4948
"@types/storybook__react": "^4.0.1",
5049
"awesome-typescript-loader": "^5.2.1",
5150
"emotion": "^10.0.9",
52-
"emotion-theming": "^10.0.10",
5351
"jest": "^24.0.0",
5452
"react": "^16.8.6",
5553
"ts-jest": "^24.0.0",
54+
"tslint": "^5.15.0",
55+
"tslint-config-prettier": "^1.18.0",
5656
"tslint-react": "^4.0.0",
5757
"typescript": "^3.3.4000"
5858
}

src/app-bar/app-bar.tsx

Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
11
import { css } from 'emotion';
2-
import { withTheme } from 'emotion-theming';
32
import * as React from 'react';
43
import { ElevationProps } from '../elevation/elevation';
54
import { merge, mergeProps } from '../util/hoc.util';
5+
import { ThemeContext } from '../util/theme';
66

7-
interface CustomableProps extends React.HTMLAttributes<HTMLDivElement> {
8-
theme?: any;
9-
}
10-
11-
interface AppBarProps extends CustomableProps {}
7+
interface AppBarProps extends React.HTMLAttributes<HTMLDivElement> {}
128

139
interface AppBarTheme {
1410
appBar: {
@@ -22,7 +18,7 @@ const defaultTheme = (theme: any): AppBarTheme =>
2218
{
2319
appBar: {
2420
elevation: 4,
25-
totalHeight: '58px'
21+
totalHeight: '58px',
2622
},
2723
},
2824
theme
@@ -37,21 +33,13 @@ const AppBarRootStyles = (theme: AppBarTheme) => ({
3733
/**
3834
* AppBar container. Not responsible for hiding/reveal upon scroll (should be another component -> when tabs & app-bar are unified, this behavior should be)
3935
*/
40-
class AppBarImpl extends React.PureComponent<AppBarProps> {
41-
render() {
42-
const {
43-
children,
44-
theme: incomingTheme,
45-
...defaultHostProps
46-
} = this.props;
47-
const theme = defaultTheme(incomingTheme);
48-
const hostProps = mergeProps(
49-
ElevationProps(theme.appBar.elevation, theme),
50-
AppBarRootStyles(theme),
51-
defaultHostProps
52-
);
53-
return <div {...hostProps}>{children}</div>;
54-
}
55-
}
56-
57-
export const AppBar = withTheme(AppBarImpl);
36+
export const AppBar: React.FunctionComponent<AppBarProps> = props => {
37+
const { children, ...defaultHostProps } = props;
38+
const theme = defaultTheme(React.useContext(ThemeContext));
39+
const hostProps = mergeProps(
40+
ElevationProps(theme.appBar.elevation, theme),
41+
AppBarRootStyles(theme),
42+
defaultHostProps
43+
);
44+
return <div {...hostProps}>{children}</div>;
45+
};

src/util/theme.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { createContext} from 'react';
2+
3+
export const ThemeContext = createContext({});

stories/app-bar.stories.tsx

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
import * as React from 'react';
21
import { storiesOf } from '@storybook/react';
32
import { css } from 'emotion';
4-
3+
import * as React from 'react';
54
import { AppBar } from '../src/app-bar/app-bar';
6-
import { ThemeProvider } from 'emotion-theming';
5+
import { ThemeContext } from '../src/util/theme';
76

87
const classFlex = css`
98
display: flex;
@@ -13,14 +12,14 @@ storiesOf('Component/Material/AppBar', module)
1312
.addDecorator(story => <div className={classFlex}>{story()}</div>)
1413
.add('default', () => <AppBar>Subarashi AppBar</AppBar>)
1514
.add('with custom theme', () => (
16-
<ThemeProvider
17-
theme={{
15+
<ThemeContext.Provider
16+
value={{
1817
appBar: {
1918
elevation: 12,
2019
totalHeight: '100px',
2120
},
2221
}}
2322
>
2423
<AppBar>Subarashi AppBar</AppBar>
25-
</ThemeProvider>
24+
</ThemeContext.Provider>
2625
));

tslint.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@
22
"defaultSeverity": "error",
33
"extends": [
44
"tslint:latest",
5-
"tslint-react"
5+
"tslint-react",
6+
"tslint-config-prettier"
67
],
78
"jsRules": {},
8-
"rules": {},
9+
"rules": {
10+
"interface-name": false
11+
},
912
"rulesDirectory": []
1013
}

0 commit comments

Comments
 (0)