|
1 | | -import { version } from "../../package.json" |
| 1 | +import packageJson from "../../package.json" |
2 | 2 | import { Meta } from "@storybook/blocks"; |
3 | 3 |
|
4 | 4 | <Meta title="Introduction" /> |
5 | 5 |
|
6 | 6 | <div className="sb-container"> |
7 | 7 | <div className='sb-section-title'> |
8 | | - # Scientific React UI v{version} |
| 8 | + # Scientific React UI v{packageJson.version} |
9 | 9 |
|
10 | 10 | ## Introduction |
11 | 11 |
|
12 | 12 | SciReactUI is a collection of useful scientific focused components, utilizing Material UI, to make your React based websites look great. |
13 | 13 |
|
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>. |
15 | 15 | </div> |
16 | 16 | </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 | + |
17 | 72 | <div className="sb-container"> |
18 | 73 | <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. |
65 | 107 |
|
66 | 108 | </div> |
67 | 109 | </div> |
0 commit comments