Skip to content

Add react router links to Breadcrumbs #59

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .storybook/preview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ const preview: Preview = {
backgrounds: { disable: true },
layout: "fullscreen",
},
argTypes: {
linkComponent: {
control: false,
},
},
};

export default preview;
6 changes: 3 additions & 3 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@ SciReactUI Changelog
====================


[v0.1.1] - 2025-?-?
[v0.2.0] - 2025-?-?
--------------------

### Added
-
-

### Fixed
- Styles added to Navbar and Footer incorrectly remove built in styles.

### Changed
-
- Breadcrumbs component takes optional linkComponent prop for page routing.

[v0.1.0] - 2025-04-10
---------------------
Expand Down
2 changes: 2 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export default [
"babel.config.js",
"eslint.config.js",
"jest.config.js",
"jest.setup.js",
"rollup.config.mjs",
]},
js.configs.recommended,
Expand All @@ -40,6 +41,7 @@ export default [
},
rules: {
"react/react-in-jsx-scope": "off",
"react/prop-types": "off",
"no-console": "off",
"prettier/prettier": "error",
"@typescript-eslint/no-unused-vars": [
Expand Down
19 changes: 11 additions & 8 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
/** @type {import('jest').Config} */
const config = { testEnvironment: "jsdom",
moduleNameMapper: {
"^.+.(svg)$": "jest-transform-stub",
},
transform: {
"^.+\\.tsx?$": "babel-jest"
}};
const config = {
testEnvironment: "jsdom",
moduleNameMapper: {
"^.+.(svg)$": "jest-transform-stub",
},
transform: {
"^.+\\.tsx?$": "babel-jest",
},
setupFilesAfterEnv: ['./jest.setup.js'],
};

export default config;
export default config;
4 changes: 4 additions & 0 deletions jest.setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
const { TextEncoder, TextDecoder } = require('util');

global.TextEncoder = TextEncoder;
global.TextDecoder = TextDecoder;
29 changes: 15 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@diamondlightsource/sci-react-ui",
"version": "0.1.1alpha",
"version": "0.2",
"description": "A theme and component library to make websites at scientific institutions simple to create.",
"author": "Diamond Light Source",
"license": "ISC",
Expand Down Expand Up @@ -29,17 +29,17 @@
"peerDependencies": {
"@emotion/react": "^11.13.3",
"@emotion/styled": "^11.13.0",
"@mui/material": "^6.1.7",
"@mui/icons-material": "^6.1.7",
"react": "^18.3.1",
"react-dom": "^18.3.1"
"@mui/material": "^6.1.7",
"react": "^18.3.1"
},
"devDependencies": {
"@babel/core": "^7.26.0",
"@babel/preset-env": "^7.26.0",
"@babel/preset-react": "^7.25.9",
"@babel/preset-typescript": "^7.26.0",
"@chromatic-com/storybook": "^3.2.2",
"@eslint/eslintrc": "^3.2.0",
"@rollup/plugin-commonjs": "^28.0.1",
"@rollup/plugin-image": "^3.0.3",
"@rollup/plugin-json": "^6.1.0",
Expand All @@ -63,11 +63,21 @@
"@types/node": "^20.17.6",
"@types/react": "^18.3.12",
"@types/react-dom": "^18.3.1",
"@typescript-eslint/eslint-plugin": "^8.18.1",
"@typescript-eslint/parser": "^8.18.1",
"babel-jest": "^29.7.0",
"eslint": "^9.17.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-prettier": "^5.2.1",
"eslint-plugin-react": "^7.37.2",
"eslint-plugin-react-hooks": "^5.1.0",
"file-loader": "^6.2.0",
"gh-pages": "^6.2.0",
"jest": "^29.7.0",
"jest-environment-jsdom": "^29.7.0",
"jest-transform-stub": "^2.0.0",
"react-dom": "^18.3.1",
"react-router-dom": "^7.5.3",
"rollup": "^4.27.3",
"rollup-plugin-dts": "^6.1.1",
"rollup-plugin-peer-deps-external": "^2.2.4",
Expand All @@ -76,16 +86,7 @@
"storybook-dark-mode": "^4.0.2",
"tslib": "^2.8.1",
"typescript": "^5.6.3",
"typescript-eslint": "^8.15.0",
"eslint": "^9.17.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-prettier": "^5.2.1",
"eslint-plugin-react": "^7.37.2",
"eslint-plugin-react-hooks": "^5.1.0",
"jest-transform-stub": "^2.0.0",
"@typescript-eslint/eslint-plugin": "^8.18.1",
"@typescript-eslint/parser": "^8.18.1",
"@eslint/eslintrc": "^3.2.0"
"typescript-eslint": "^8.15.0"
},
"packageManager": "pnpm@9.12.3+sha256.24235772cc4ac82a62627cd47f834c72667a2ce87799a846ec4e8e555e2d4b8b"
}
57 changes: 54 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

86 changes: 65 additions & 21 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ A theme and component library to make websites at scientific installations simpl

Using
-----

### Installing

Install as usual:
Expand All @@ -22,42 +21,87 @@ npm i @diamondlightsource/sci-react-ui
First use the ThemeProvider and supply a theme.

```js
import { ThemeProvider, DiamondTheme } from "@diamondlightsource/sci-react-ui";

root.render(
<ThemeProvider theme={DiamondTheme}>
<App />
</ThemeProvider>,
);
```

There are currently two themes, `GenericTheme` or `DiamondTheme`, but you can - and should - adapt your own.

The Breadcrumbs supports either static links or the use of a routing library.
To use static links, omit the linkComponent prop and Breadcrumbs will use a Link component with standard href attributes.

```js
import { Breadcrumbs } from "@diamondlightsource/sci-react-ui";

function App() {
return <Breadcrumbs path={window.location.pathname} />;
}
export default App;
```

To use the Breadcrumbs component with your routing library, use a route provider from your preferred library. For example, to use react-router's BrowserRouter, install react-router-dom:

```sh
npm i react-router-dom
```

Next, use the BrowserRouter which can be used at the top level:

```js
import { BrowserRouter } from "react-router-dom";
import {
ThemeProvider,
DiamondTheme
} from "@diamondlightsource/sci-react-ui";

root.render(
<ThemeProvider theme={DiamondTheme}>
<App />
<BrowserRouter>
<App />
<BrowserRouter>
</ThemeProvider>
)
```

There are currently two themes, `GenericTheme` or `DiamondTheme`, but you can - and should - adapt your own.
Then pass your library's corresponding Link component to Breadcrumbs in the linkComponent prop, for example:

There are various components, here's an example of how to use the NavBar:
```js
import { Link } from "react-router-dom";
import { Breadcrumbs } from "@diamondlightsource/sci-react-ui";

function App() {
return <Breadcrumbs path={window.location.pathname} linkComponent={Link} />;
}
export default App;
```

There are various other components, here's an example of how to use the NavBar:

```js
import {Container, Typography} from "@mui/material";
import {
Navbar,
NavLink,
NavLinks
} from "@diamondlightsource/sci-react-ui";
import { Container, Typography } from "@mui/material";
import { Navbar, NavLink, NavLinks } from "@diamondlightsource/sci-react-ui";

function App() {
return <>
<Navbar>
<NavLinks key="links">
<NavLink href="#" key="first">A link</NavLink>
</NavLinks>
</Navbar>
<Container>
<Typography variant="h2">Scientific UI Collection</Typography>
<Typography>A collection of science based React components.</Typography>
</Container>
</>
return (
<>
<Navbar>
<NavLinks key="links">
<NavLink href="#" key="first">
A link
</NavLink>
</NavLinks>
</Navbar>
<Container>
<Typography variant="h2">Scientific UI Collection</Typography>
<Typography>A collection of science based React components.</Typography>
</Container>
</>
);
}
export default App;
```
Expand Down
Loading