Skip to content

Commit 5e76d8a

Browse files
authored
Add new section for theme creation. (#91)
Fix import.
1 parent 9df0760 commit 5e76d8a

File tree

3 files changed

+93
-50
lines changed

3 files changed

+93
-50
lines changed

src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export * from "./themes/BaseTheme";
1717
export * from "./themes/DiamondTheme";
1818
export * from "./themes/GenericTheme";
1919
export * from "./themes/ThemeProvider";
20+
export * from "./themes/ThemeManager";
2021

2122
// utils
2223
export * from "./utils/diamond";

src/storybook/Introduction.mdx

Lines changed: 91 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,109 @@
1-
import { version } from "../../package.json"
1+
import packageJson from "../../package.json"
22
import { Meta } from "@storybook/blocks";
33

44
<Meta title="Introduction" />
55

66
<div className="sb-container">
77
<div className='sb-section-title'>
8-
# Scientific React UI v{version}
8+
# Scientific React UI v{packageJson.version}
99

1010
## Introduction
1111

1212
SciReactUI is a collection of useful scientific focused components, utilizing Material UI, to make your React based websites look great.
1313

14-
This storybook displays the components for version <strong>{version}</strong>.
14+
This storybook displays the components in @diamondlightsource/sci-react-ui:<strong>{packageJson.version}</strong>.
1515
</div>
1616
</div>
17+
18+
<div className="sb-container">
19+
<div className='sb-section-title'>
20+
## Usage
21+
22+
### Add Theme
23+
24+
First select a theme: `GenericTheme` or `DiamondTheme` are available to use
25+
(you can also create your own, see following section):
26+
27+
```tsx filename="main.tsx"
28+
import {
29+
ThemeProvider,
30+
DiamondTheme
31+
} from "@diamondlightsource/sci-react-ui";
32+
33+
root.render(
34+
<ThemeProvider theme={DiamondTheme}>
35+
<App />
36+
</ThemeProvider>
37+
)
38+
```
39+
40+
### Create an App
41+
42+
Then create something, for instance, you may want a Navigation Bar at the top of your website:
43+
44+
```tsx filename="App.tsx"
45+
import {Container, Typography} from "@mui/material";
46+
import {
47+
Navbar,
48+
NavLink,
49+
NavLinks
50+
} from "@diamondlightsource/sci-react-ui";
51+
52+
function App() {
53+
return <>
54+
<Navbar>
55+
<NavLinks key="links">
56+
<NavLink href="#" key="first">A link</NavLink>
57+
</NavLinks>
58+
</Navbar>
59+
<Container>
60+
<Typography variant="h2">Scientific UI Collection</Typography>
61+
<Typography>A collection of science based React components.</Typography>
62+
</Container>
63+
</>
64+
}
65+
export default App;
66+
```
67+
68+
</div>
69+
</div>
70+
71+
1772
<div className="sb-container">
1873
<div className='sb-section-title'>
19-
# Usage
20-
21-
## Add Theme
22-
23-
First select a theme: GenericTheme or DiamondTheme (or create your own):
24-
25-
```js
26-
import {
27-
ThemeProvider,
28-
DiamondTheme
29-
} from "@diamondlightsource/sci-react-ui";
30-
31-
root.render(
32-
<ThemeProvider theme={DiamondTheme}>
33-
<App />
34-
</ThemeProvider>
35-
)
36-
```
37-
38-
## Create App
39-
40-
Then create something, e.g.
41-
42-
```js
43-
import {Container, Typography} from "@mui/material";
44-
import {
45-
Navbar,
46-
NavLink,
47-
NavLinks
48-
} from "@diamondlightsource/sci-react-ui";
49-
50-
function App() {
51-
return <>
52-
<Navbar>
53-
<NavLinks key="links">
54-
<NavLink href="#" key="first">A link</NavLink>
55-
</NavLinks>
56-
</Navbar>
57-
<Container>
58-
<Typography variant="h2">Scientific UI Collection</Typography>
59-
<Typography>A collection of science based React components.</Typography>
60-
</Container>
61-
</>
62-
}
63-
export default App;
64-
```
74+
## Create new Theme
75+
76+
The 'GenericTheme.ts' shows you a simple example of creating a new theme.
77+
Use `mergeThemeOptions` to create a new one from an existing one.
78+
79+
To inherit from the DiamondTheme by overriding the light palette, use something like this:
80+
81+
```tsx
82+
import { createTheme, Theme } from "@mui/material/styles";
83+
import { DiamondThemeOptions, mergeThemeOptions } from '@diamondlightsource/sci-react-ui'
84+
85+
const MyThemeOptions = mergeThemeOptions({
86+
colorSchemes: {
87+
light: {
88+
palette: {
89+
primary: {
90+
main: "#f00",
91+
light: "#f55",
92+
dark: "#a00",
93+
contrastText: "#fff",
94+
},
95+
},
96+
},
97+
}
98+
}, DiamondThemeOptions);
99+
100+
const MyTheme: Theme = createTheme(MyThemeOptions);
101+
export { MyTheme };
102+
```
103+
104+
The theme options are documented in MUI. For the examples used in DiamondTheme
105+
see [DiamondTheme.tsx](https://github.com/DiamondLightSource/sci-react-ui/blob/main/src/themes/DiamondTheme.ts)
106+
on GitHub.
65107

66108
</div>
67109
</div>

src/themes/GenericTheme.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,5 @@ const GenericThemeOptions = mergeThemeOptions({
2323
});
2424

2525
const GenericTheme: Theme = createTheme(GenericThemeOptions);
26-
console.log(GenericTheme);
26+
2727
export { GenericTheme, GenericThemeOptions };

0 commit comments

Comments
 (0)