Skip to content

Commit

Permalink
feat(app): new App component
Browse files Browse the repository at this point in the history
  • Loading branch information
nolimits4web committed Aug 27, 2021
1 parent 8b566d9 commit de882b5
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 18 deletions.
35 changes: 17 additions & 18 deletions kitchen-sink/react/components/App.jsx
Original file line number Diff line number Diff line change
@@ -1,31 +1,30 @@
import React, { useState } from 'react';
import { HashRouter as Router, Switch, Route } from 'react-router-dom';
import { TailwindMobileProvider } from 'tailwind-mobile/react';
import { App as TailwindMobileApp } from 'tailwind-mobile/react';

import routes from '../routes.js';
import HomePage from '../pages/Home.jsx';

function App() {
const [theme, setTheme] = useState('ios');
return (
<TailwindMobileProvider theme={theme}>
<div
className={`absolute left-0 top-0 w-full h-full min-h-screen twm-${theme}`}
>
<Router>
<Switch>
{routes.map((route) => (
<Route key={route.path} path={route.path}>
<route.component />
</Route>
))}
<Route path="/">
<HomePage theme={theme} setTheme={setTheme} />
<TailwindMobileApp
theme={theme}
className="absolute left-0 top-0 w-full h-full min-h-screen"
>
<Router>
<Switch>
{routes.map((route) => (
<Route key={route.path} path={route.path}>
<route.component />
</Route>
</Switch>
</Router>
</div>
</TailwindMobileProvider>
))}
<Route path="/">
<HomePage theme={theme} setTheme={setTheme} />
</Route>
</Switch>
</Router>
</TailwindMobileApp>
);
}

Expand Down
34 changes: 34 additions & 0 deletions src/react/components/App.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import React from 'react';
import { cls } from '../shared/cls.js';
import { TailwindMobileProvider } from '../shared/TailwindMobileProvider.jsx';

const App = (props) => {
const {
component = 'div',
className,

theme = 'material',

// Children
children,

// Rest
...rest
} = props;

const Component = component;

const attrs = {
...rest,
};

return (
<TailwindMobileProvider theme={theme}>
<Component className={cls(`twm-${theme}`, className)} {...attrs}>
{children}
</Component>
</TailwindMobileProvider>
);
};

export default App;
2 changes: 2 additions & 0 deletions src/react/tailwind-mobile-react.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import App from './components/App.jsx';
import Badge from './components/Badge.jsx';
import Block from './components/Block.jsx';
import BlockFooter from './components/BlockFooter.jsx';
Expand Down Expand Up @@ -46,6 +47,7 @@ export {
useTheme,
useThemeClasses,
// components
App,
Badge,
Block,
BlockFooter,
Expand Down

0 comments on commit de882b5

Please sign in to comment.