Skip to content

Commit a56c4e9

Browse files
adding multi-themes-example
1 parent 089d4ea commit a56c4e9

File tree

10 files changed

+203
-0
lines changed

10 files changed

+203
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
1. Create a project with create-react-app and install all dependencies in package.json
2+
3+
2. Install sass and react-dyn-tabs
4+
5+
```js
6+
$ npm install react-dyn-tabs
7+
$ npm install sass --save-dev
8+
```
9+
10+
3. Copy all files from example/multi-themes-example/src to your own src folder.
11+
12+
4. Run project
13+
14+
```js
15+
$ npm start
16+
```
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
body {
2+
position: relative;
3+
left: 0px;
4+
top: 0px;
5+
margin: 0px;
6+
padding: 0px;
7+
background-color: lavender;
8+
overflow-y: scroll;
9+
overflow-x: hidden;
10+
}
11+
12+
select,
13+
button,
14+
input {
15+
outline: none;
16+
}
17+
18+
#root {
19+
position: absolute;
20+
left: 0px;
21+
right: 0px;
22+
top: 0px;
23+
bottom: 0px;
24+
}
25+
26+
#header {
27+
position: relative;
28+
margin: 15px;
29+
display: flex;
30+
align-items: center;
31+
justify-content: center;
32+
}
33+
34+
#header a {
35+
text-decoration: none;
36+
z-index: 2;
37+
}
38+
39+
#header h1 {
40+
text-align: center;
41+
color: #ab0000;
42+
margin: 0px;
43+
}
44+
45+
#actions > div {
46+
margin-right: 150px;
47+
}
48+
49+
@media only screen and (max-width: 580px) {
50+
#header {
51+
display: table;
52+
margin: auto;
53+
}
54+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import React from 'react';
2+
import './App.css';
3+
import Tabs from './components/simple-tabs/simple-tabs.js';
4+
import useSelectTheme from './components/useSelectTheme/useSelectTheme.js';
5+
function App() {
6+
const [ThemeSelectorComponent, scopeSelector] = useSelectTheme();
7+
return (
8+
<>
9+
<div id="header">
10+
<a href="https://github.com/dev-javascript/react-dyn-tabs" target="_blank">
11+
<h1>react-dyn-tabs</h1>
12+
</a>
13+
<ThemeSelectorComponent></ThemeSelectorComponent>
14+
</div>
15+
<div className={scopeSelector}>
16+
<Tabs />
17+
</div>
18+
</>
19+
);
20+
}
21+
22+
export default App;
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import React from 'react';
2+
import 'react-dyn-tabs/style/react-dyn-tabs.css';
3+
import '../../scoped-themes/scss/card.scss';
4+
import '../../scoped-themes/scss/classic.scss';
5+
import '../../scoped-themes/scss/basic.scss';
6+
import '../../scoped-themes/scss/bootstrap.scss';
7+
import useDynTabs from 'react-dyn-tabs';
8+
export default function () {
9+
const allComponents = {
10+
Panel1: (props) => <p>tab content 1</p>,
11+
Panel2: <p>tab content 2</p>,
12+
Panel3: <p>tab content 3</p>,
13+
Panel4: (props) => <p>tab content 4</p>,
14+
};
15+
const options = {
16+
tabs: [
17+
{id: '1', title: 'tab 1', panelComponent: allComponents.Panel1},
18+
{id: '2', title: 'tab 2', panelComponent: allComponents.Panel2},
19+
{id: '3', title: 'tab 3', panelComponent: allComponents.Panel3},
20+
{id: '4', title: 'tab 4', panelComponent: allComponents.Panel4},
21+
],
22+
selectedTabID: '1',
23+
};
24+
const [Tablist, Panellist, ready] = useDynTabs(options);
25+
return (
26+
<div
27+
style={{
28+
margin: '10px',
29+
background: 'white',
30+
padding: '10px',
31+
borderRadius: '7px',
32+
}}>
33+
<div style={{width: '100%', display: 'block'}}>
34+
<Tablist></Tablist>
35+
<Panellist></Panellist>
36+
</div>
37+
</div>
38+
);
39+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#theme-container {
2+
position: absolute;
3+
left: 0px;
4+
top: 50%;
5+
transform: translate(0px, -50%);
6+
margin-top: 5px;
7+
color: #6767a3;
8+
}
9+
@media only screen and (max-width: 580px) {
10+
#theme-container {
11+
position: relative;
12+
margin-top: 20px;
13+
text-align: center;
14+
}
15+
}
16+
#theme-container #theme-selector {
17+
padding: 2px 8px;
18+
border: 1px solid #c5c5e9;
19+
color: #6767a3;
20+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import React, {useState, useCallback} from 'react';
2+
import './themeSelector.css';
3+
const useSelectTheme = (props) => {
4+
const [scopeSelector, setScopeSelector] = useState('card');
5+
const onChangeTheme = (e) => {
6+
setScopeSelector(e.target.value);
7+
};
8+
const ThemeSelector = useCallback(
9+
(props) => (
10+
<div id="theme-container">
11+
<label htmlFor="theme-selector">Theme : </label>
12+
<select id="theme-selector" onChange={onChangeTheme} value={scopeSelector}>
13+
<option key="2" value="card">
14+
card
15+
</option>
16+
<option key="1" value="bootstrap">
17+
bootstrap
18+
</option>
19+
<option key="3" value="basic">
20+
basic
21+
</option>
22+
<option key="4" value="classic">
23+
classic
24+
</option>
25+
</select>
26+
</div>
27+
),
28+
[scopeSelector],
29+
);
30+
return [ThemeSelector, scopeSelector];
31+
};
32+
export default useSelectTheme;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
@use '../../../node_modules/react-dyn-tabs/themes/scss/modules/react-dyn-tabs-basic'as m;
2+
3+
.basic {
4+
@include m.main;
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
@use '../../../node_modules/react-dyn-tabs/themes/scss/modules/react-dyn-tabs-bootstrap'as m;
2+
3+
.bootstrap {
4+
@include m.main;
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
@use '../../../node_modules/react-dyn-tabs/themes/scss/modules/react-dyn-tabs-card'as m;
2+
3+
.card {
4+
@include m.main;
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
@use '../../../node_modules/react-dyn-tabs/themes/scss/modules/react-dyn-tabs-classic'as m;
2+
3+
.classic {
4+
@include m.main;
5+
}

0 commit comments

Comments
 (0)