Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

feat: Revamp library using new Safe Theme #216

Merged
merged 60 commits into from
Feb 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
734e5e6
Added first approach of mui5 safe theme
DaniSomoza Apr 29, 2022
baffe6e
Added snapshots
DaniSomoza Apr 29, 2022
2e69f64
updated snapshots
DaniSomoza Apr 29, 2022
cf94462
Configure build for SSR rendering
yagopv May 3, 2022
44ad8b7
yarn.lock
yagopv May 3, 2022
4b74c21
style: Adjust typography variants (#199)
usame-algan May 29, 2022
4269b15
chore: Bump version to 2.0.1
usame-algan May 29, 2022
4cbe12d
fix: Remove auto responsive font sizes
usame-algan May 29, 2022
0bdaa51
Merge branch 'main' into revamp-safe-react-components
dasanra Aug 12, 2022
8ae712c
Enable storybook build and set correct peer dependencies
dasanra Aug 12, 2022
f52cca4
Add new theming
dasanra Dec 26, 2022
b146d64
Remove unnecessary components
yagopv Jan 19, 2023
85b9fd7
Merge branch 'main' into revamp-safe-react-components
dasanra Jan 19, 2023
53f4497
fix linting issue
dasanra Jan 19, 2023
dd64f44
Remove GnosisTheme
yagopv Jan 20, 2023
b7c73bc
Update theme
yagopv Jan 20, 2023
1c2fad5
Merge branch 'revamp-safe-react-components' of https://github.com/gno…
yagopv Jan 20, 2023
22bd8b7
EthHashInfo start
yagopv Jan 20, 2023
26a30ef
Add global theme mode change
yagopv Jan 20, 2023
1dd38d1
Reuse darktheme between stories
yagopv Jan 20, 2023
a3b832c
Remove old material
yagopv Jan 23, 2023
05d68b0
Update webpack
yagopv Jan 23, 2023
45d06ab
Add fonts
yagopv Jan 23, 2023
9c98330
EthHashInfo refactor
yagopv Jan 23, 2023
f68012f
ExplorerButton
yagopv Jan 24, 2023
134a967
Load svg
yagopv Jan 24, 2023
be7b5c0
Remove unused storyshots
yagopv Jan 24, 2023
092334a
Remove svg
yagopv Jan 24, 2023
fe6d493
Improve some things
yagopv Jan 25, 2023
319111c
Use path imports
yagopv Jan 25, 2023
d084e11
Fix components
yagopv Jan 25, 2023
f164b3c
Minor fixes
yagopv Jan 25, 2023
7f63577
Clean deps
yagopv Jan 26, 2023
c41fb42
use local palette because exported compionents are not picking the ri…
yagopv Jan 26, 2023
a2debea
Update shots
yagopv Jan 26, 2023
ae19a39
2.0.0-beta.0
yagopv Jan 26, 2023
b1450c0
Add private false flag
yagopv Jan 26, 2023
478071e
Remove the private tag
dasanra Jan 26, 2023
b51140b
Use concrete isAddress module
yagopv Jan 27, 2023
088fad7
Merge branch 'revamp-safe-react-components' of https://github.com/gno…
yagopv Jan 27, 2023
b3065da
Cleanup
yagopv Jan 27, 2023
48ee81f
Fix typography problems
yagopv Jan 27, 2023
07d7512
Refactor Icons
yagopv Jan 27, 2023
395b96b
Remove styled-components dependency
dasanra Jan 27, 2023
f57ab80
Remove unnecessary peers
yagopv Jan 27, 2023
e8132d1
Merge branch 'revamp-safe-react-components' of https://github.com/gno…
yagopv Jan 27, 2023
f0d71c7
Remove unnecessary libs
yagopv Jan 27, 2023
3655f3f
Update README to align with current version
dasanra Jan 27, 2023
ebbab59
Remove unsed imports
yagopv Jan 27, 2023
21a2d81
Export SafeThemeProvider for theming library components
yagopv Jan 27, 2023
c798a82
use themes from sx as now it works
yagopv Jan 27, 2023
a905195
Refactor theme provider
yagopv Jan 27, 2023
f321d8b
Update readme
yagopv Jan 27, 2023
4645eb1
add comment
yagopv Jan 30, 2023
3980080
Set v2.0.0-beta.1
dasanra Jan 30, 2023
4f24f7f
README
yagopv Jan 30, 2023
7b8929d
Storyshots
yagopv Jan 31, 2023
83cbb98
Fix lint check action
dasanra Jan 31, 2023
ef78a7f
Update eslint to latest version
dasanra Jan 31, 2023
56a31ac
Set v2.0.0
dasanra Feb 2, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
12 changes: 11 additions & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,14 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: gnosis/safe-react-eslint-plus-action@v4.0.1

- uses: actions/setup-node@v3
with:
node-version: 18
cache: yarn

- name: Install Dependencies
run: yarn install --frozen-lockfile

- name: Run eslint
run: yarn lint:check
3 changes: 3 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
name: Unit tests
on:
pull_request:
push:
branches:
- main

jobs:
test:
Expand Down
35 changes: 0 additions & 35 deletions .storybook/gnosisTheme.js

This file was deleted.

4 changes: 4 additions & 0 deletions .storybook/main.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
module.exports = {
core: {
builder: 'webpack5',
},
stories: ['../src/**/*.stories.tsx'],
addons: [
'@storybook/addon-actions',
Expand All @@ -7,4 +10,5 @@ module.exports = {
'@storybook/addon-links',
'storybook-addon-react-docgen',
],
staticDirs: ['../src/assets/fonts'],
};
10 changes: 7 additions & 3 deletions .storybook/manager.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import { create } from '@storybook/theming/create';
import { addons } from '@storybook/addons';
import gnosisTheme from './gnosisTheme';


addons.setConfig({
disableTelemetry: true,
enableShortcuts: false,
showNav: true,
showPanel: false,
theme: gnosisTheme,
theme: storyBookTheme,
});

const storyBookTheme = create({
base: 'light',
});
1 change: 1 addition & 0 deletions .storybook/preview-head.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<link rel="stylesheet" href="/fonts.css" />
52 changes: 45 additions & 7 deletions .storybook/preview.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,53 @@
import React from 'react';
import { addDecorator } from '@storybook/react';
import { addParameters } from '@storybook/react';
import { ThemeProvider } from 'styled-components';

import theme from '../src/theme';
import {
Stack,
Typography,
IconButton,
Card,
CardContent,
CssBaseline,
ThemeProvider,
} from '@mui/material';
import Brightness4Icon from '@mui/icons-material/Brightness4';
import Brightness7Icon from '@mui/icons-material/Brightness7';

addDecorator((storyFn) => (
<>
<ThemeProvider theme={theme}>{storyFn()}</ThemeProvider>
</>
));
import createSafeTheme from '../src/theme/safeTheme.tsx';
import useThemeMode from '../src/hooks/useThemeMode';
import SafeThemeProvider from '../src/theme/SafeThemeProvider';

addDecorator((storyFn) => {
const { switchThemeMode, themeMode } = useThemeMode();

return (
<SafeThemeProvider mode={themeMode}>
{(safeTheme) => (
<ThemeProvider theme={safeTheme}>
<CssBaseline />
<Card>
<CardContent>
<Stack direction="row" alignItems="center" sx={{ mb: 2 }}>
<IconButton
onClick={switchThemeMode}
color="inherit"
sx={{ p: 0 }}>
{themeMode === 'light' ? (
<Brightness4Icon />
) : (
<Brightness7Icon />
)}
</IconButton>
</Stack>
{storyFn()}
</CardContent>
</Card>
</ThemeProvider>
)}
</SafeThemeProvider>
);
});

addParameters({
options: {
Expand Down
58 changes: 31 additions & 27 deletions .storybook/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,43 +2,47 @@ module.exports = ({ config }) => {
config.module.rules.push({
test: /\.(ts|js)x?$/,
exclude: [/node_modules/],
use: [
{
loader: require.resolve('ts-loader'),
},
]
use: {
loader: 'ts-loader',
},
});

// There was a problem with the fonts not being loaded
// I took the fix from here: https://github.com/storybookjs/storybook/issues/5936#issuecomment-532902187
config.module.rules = config.module.rules.map(rule => {
if (rule.test && rule.test.toString().includes('woff')) {
config.module.rules.push({
test: /\.css$/i,
use: ['style-loader', 'css-loader'],
});

// remove svg from existing rule
config.module.rules = config.module.rules.map((rule) => {
if (
String(rule.test) ===
String(
/\.(svg|ico|jpg|jpeg|png|gif|eot|otf|webp|ttf|woff|woff2|cur|ani)(\?.*)?$/
)
) {
return {
...rule,
test: /\.(svg|ico|jpg|jpeg|png|gif|webp|cur|ani|pdf)(\?.*)?$/
}
test: /\.(ico|jpg|jpeg|png|gif|eot|otf|webp|ttf|woff|woff2|cur|ani)(\?.*)?$/,
};
}
return rule
})

return rule;
});

config.module.rules.push({
test: /\.(svg|png|jpg)$/i,
use: [
{
loader: 'url-loader',
query: {
name: '[name].[ext]'
}
}
]
test: /\.(woff(2)?|ttf|eot)(\?v=\d+\.\d+\.\d+)?$/,
type: 'asset/resource',
generator: {
filename: '[name][ext][query]',
},
});

config.resolve.extensions.push('.ts', '.tsx', 'woff2');
config.module.rules.push({
test: /\.(png|jpg)$/i,
type: 'asset/inline',
});

config.node = {
fs: 'empty',
child_process: 'empty'
};
config.resolve.extensions.push('.ts', '.tsx', 'woff2');

return config;
};
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2018-2022 Safe Ecosystem Foundation
Copyright (c) 2018-2023 Safe Ecosystem Foundation

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

Expand Down
69 changes: 45 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,75 +1,95 @@
# safe-react-components

[![Storybook](https://raw.githubusercontent.com/storybooks/brand/master/badge/badge-storybook.svg)](https://components.gnosis-safe.io/)
[![npm](https://img.shields.io/npm/v/@gnosis.pm/safe-react-components)](https://www.npmjs.com/package/@gnosis.pm/safe-react-components)
![license](https://img.shields.io/github/license/safe-global/safe-react-components)
![tests](https://img.shields.io/github/actions/workflow/status/safe-global/safe-react-components/test.yml?branch=main)

This repository contains a set of React components written in TypeScript.
This repository contains a [@mui/material](https://material-ui.com/) theming and a set of useful React components written in TypeScript.

These components are being used to build the [Gnosis Safe](https://github.com/gnosis/safe-react) web and desktop app.
These components and theming are being used to build the [Safe](https://github.com/safe-global/web-core) web and desktop app.

As Gnosis Safe allows to integrate third party applications ("Safe Apps"), these components can also be used to build Safe Apps with the following benefits:
As Safe allows to integrate third party applications ("Safe Apps"), these components can also be used to build Safe Apps with the following benefits:

- **Native feel:** Build your Safe Apps with a similar style as the one used by Gnosis Safe. This makes your Safe Apps feel almost like a native feature of the Gnosis Safe.
- **Responsive:** Most of the components will are optimized to render properly in different resolutions.
- **Native feel:** Build your Safe Apps with a similar style as the one used by the Safe. This makes your Safe Apps feel almost like a native feature of the Safe.
- **Blockchain-focused:** Some components solve common blockchain-related problems like inputs for ETH addresses and bigNumbers, identicon images, and more.
- **Save time:** No need to build all components from scratch.

## How to install

```bash
yarn add @gnosis.pm/safe-react-components
### Yarn

npm install @gnosis.pm/safe-react-components
```bash
yarn add @safe-global/safe-react-components
```

## Integration
### npm

This library makes use of [material-ui - 4.X.X](https://material-ui.com/) and [styled-components - 5.X.X](https://styled-components.com/) as `peer dependencies`, this means you must install it in your Safe App. Make sure to provide the same version as the one being used by the current version of this library.
```bash
npm install @safe-global/safe-react-components
```

## Integration

Once everything is installed, you have to instantiate a [ThemeProvider](https://styled-components.com/docs/api#themeprovider) from [styled-components](https://styled-components.com/).
This library makes use of [@mui/material - 5.x.x](https://material-ui.com/) as `peer dependency`, this means you must install it in your Safe App. Make sure to provide a compatible version as defined by peer dependencies.

This example uses the theme exported by safe-react-components. Here, you can extend this theme to customize it to your needs.
Once everything is installed, you have to instantiate the SafeThemeProvider with the desired theme mode (light/dark) and with the generated safe theme return a [ThemeProvider](https://mui.com/material-ui/customization/theming/#theme-provider) for the application.

```js
import { ThemeProvider } from 'styled-components';
import { theme } from '@gnosis.pm/safe-react-components';
import { ThemeProvider } from '@mui/material/styles';
import { SafeThemeProvider } from '@safe-global/safe-react-components';

import App from './App';

export default () => (
<ThemeProvider theme={theme}>
<App />
</ThemeProvider>
<SafeThemeProvider mode="light">
{(safeTheme: Theme) => (
<ThemeProvider theme={safeTheme}>
<App />
</ThemeProvider>
)}
</SafeThemeProvider>
);
```

## Using the components

You can import every component exported from `@gnosis.pm/safe-react-components` in the same way.
You can import every component exported from `@safe-global/safe-react-components` in the same way.

```js
import { Text } from '@gnosis.pm/safe-react-components';
import { EthHashInfo } from '@safe-global/safe-react-components';

const App = () => {
return <Text size="lg">some text</Text>;
const App = (account) => {
return <EthHashInfo address={account} showCopyButton />;
};

export default App;
```

## Adding the fonts

The fonts will be bundled on `build` and a `fonts.css` file will be provided as well for adding the corresponding `font-face` declarations

```
// from js/ts files
import '@safe-global/safe-react-components/dist/fonts.css'

// from css files
@import url(<path-to-node_modules>/@safe-global/safe-react-components/dist/fonts.css)
```

## Storybook

You can find documentation and examples of all our components in this [storybook](https://components.gnosis-safe.io/).

## Local development

To develop on your local machine, install the dependencies (including the peer dependencies):

```
yarn
```

Launch the Storybook:

```
yarn storybook
```
Expand All @@ -79,6 +99,7 @@ yarn storybook
Snapshot tests are generated automatically from the Storybook stories using the [StoryShots addon](https://github.com/storybookjs/storybook/tree/master/addons/storyshots/storyshots-core).

To run the tests locally:

```
yarn test
```
Expand All @@ -91,4 +112,4 @@ If you want to add a new Jest test, make sure to put a file with the `.test.tsx`

## Examples

At Gnosis we have developed some example Safe Apps. Here is the [repository](https://github.com/gnosis/safe-react-apps).
At Safe we have developed some example Safe Apps. Here is the [repository](https://github.com/safe-global/safe-react-apps).
Loading