Skip to content

Commit

Permalink
Added icon for button in adapter-react-v5 (#2812)
Browse files Browse the repository at this point in the history
  • Loading branch information
GermanBluefox authored Nov 17, 2024
1 parent 07ab9e8 commit 968daac
Show file tree
Hide file tree
Showing 39 changed files with 9,864 additions and 1,090 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,5 @@ lerna-debug.log
packages/admin/build-backend
/packages/admin/admin/custom/
packages/admin/README.md
/packages/jsonConfig/test/testSchema.js
/packages/jsonConfig/test/testSchema.js.map
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ The icons may not be reused in other projects without the proper flaticon licens
<!--
### **WORK IN PROGRESS**
-->
### **WORK IN PROGRESS**

- (@GermanBluefox) Added new JsonConfig control: staticInfo

### 7.3.2 (2024-11-15)

- (@GermanBluefox) Some GUI packages were updated.
Expand Down
1,815 changes: 850 additions & 965 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"@alcalzone/release-script-plugin-iobroker": "^3.7.2",
"@alcalzone/release-script-plugin-license": "^3.7.0",
"@alcalzone/release-script-plugin-lerna": "^3.7.0",
"lerna": "^8.1.8"
"lerna": "^8.1.9"
},
"scripts": {
"build": "npm run clean && lerna run build",
Expand Down
76 changes: 76 additions & 0 deletions packages/adapter-react-v5/MIGRATION_4_5.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# Migration from adapter-react to adapter-react-v5

## In src/package.json => dependencies

- `"@iobroker/adapter-react": "^2.0.22",` => `"@iobroker/adapter-react-v5": "^3.1.34",`
- `"@material-ui/core": "^4.12.3",` => `"@mui/material": "^5.10.9",`
- `"@material-ui/icons": "^4.11.2",` => `"@mui/icons-material": "^5.10.9",`
- Add `"@mui/styles": "^5.10.9",`
- Add `"babel-eslint": "^10.1.0",`

## In Source files

- All `@iobroker/adapter-react/...` => `@iobroker/adapter-react-v5/...`
- All `@material-ui/icons/...` => `@mui/icons-material/...`
- Change `import { withStyles } from '@material-ui/core/styles';` => `import { withStyles } from '@mui/styles';`
- Change `import { makeStyles } from '@mui/material/styles';` => `import { makeStyles } from '@mui/styles';`
- Change `import withWidth from '@material-ui/core/withWidth';` => `import { withWidth } from '@iobroker/adapter-react-v5';`
- All `@material-ui/core...` => `@mui/material...`
- Change `import { MuiThemeProvider } from '@material-ui/core/styles';` => `import { ThemeProvider, StyledEngineProvider } from '@mui/material/styles';`
- Change all `<MuiThemeProvider theme={this.state.theme}>` to `<StyledEngineProvider injectFirst><ThemeProvider theme={this.state.theme}>`
- Rename in styles `theme.palette.type` => `theme.palette.mode`
- Add to all `TextField`, `Select`, `FormControl` the property `variant="standard"`
- Add to all `Button` that do not have `color` property: `color="grey"`
- Replace by `TextField` the `readOnly` attribute (if exists) with `InputProps={{readOnly: true}}`
- Remove px by all `theme.spacing`: `calc(100% - ${theme.spacing(4)}px)` => `calc(100% - ${theme.spacing(4)})`
- Replace `this.selectTab(e.target.parentNode.dataset.name, index)` => `this.selectTab(e.target.dataset.name, index)`

If you still have questions, try to find an answer [here](https://mui.com/guides/migration-v4/).

# Migration from [email protected] to [email protected]

- Look for getObjectView socket requests and replace `socket.getObjectView('startKey', 'endKey', 'instance')` to `socket.getObjectViewSystem('instance', 'startKey', 'endKey')`
- Look for calls of custom like

```jsx
this.props.socket._socket.emit('getObjectView', 'system', 'custom', { startKey: '', endKey: '\u9999' }, (err, objs) => {
(objs?.rows || []).forEach(item => console.log(item.id, item.value));
});
```
to
```jsx
socket.getObjectViewCustom('custom', 'state', 'startKey', 'endKey').then(objects => {
Object.keys(objects).forEach(obj => console.log(obj._id));
});
```
- Replace all `socket.log.error('text')` to `socket.log('text', 'error')`
- Add to App.js `import { AdminConnection } from '@iobroker/adapter-react-v5';` and `super(props, { Connection: AdminConnection });` if run in admin
# Migration from [email protected] to [email protected]
- `Theme` is renamed to IobTheme. It is an object with classes inside. `Theme` is still inside and it same as mui `createTheme`.
- adapter-react-v5 has all types exported. So you can use `import { type IobTheme, Theme } from '@iobroker/adapter-react-v5';` and `const theme: IobTheme = Theme('light');`
- Json-Config is now an external package and must be included as dependency separately.
- Use type `Translate` for `t(word: string, ...args: any[]) => string`
- All components for admin JsonConfig must be changed:
Before `adapter-react-v5@5.x`:
```jsx
import { ConfigGeneric, I18n } from '@iobroker/adapter-react-v5';
class JsonComponent extends ConfigGeneric {
// ...
}
```
With `adapter-react-v5@5.x`:
```jsx
import { I18n } from '@iobroker/adapter-react-v5';
import { ConfigGeneric } from '@iobroker/json-config';
class JsonComponent extends ConfigGeneric {
// ...
}
```
90 changes: 90 additions & 0 deletions packages/adapter-react-v5/MIGRATION_5_6.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
# Migration from v5 to v6

The main change is that the `withStyles` was removed. So you have to replace all `withStyles` with `sx` or `style` properties.

You can read more about sx [here](https://mui.com/system/getting-started/the-sx-prop/).

- Remove at start of the file `import { withStyles } from '@mui/styles';`
- Replace it at the very end of the file `export default withStyles(styles)(MyComponent);` with `export default MyComponent;`
- Modify `const styles`:
Before:

```typescript jsx
const styles: Record<string, any> = (theme: IobTheme) => ({
dialog: {
height: `calc(100% - ${theme.mixins.toolbar.minHeight}px)`,
padding: theme.spacing(1),
margin: theme.spacing(2),
gap: 5,
borderRadius: 5,
marginLeft: 10, // marginTop, marginRight, marginBottom
paddingLeft: 10, // paddingTop, paddingRight, paddingBottom
},
...
});
```

After:

```typescript jsx
const styles: Record<string, any> = {
dialog: (theme: IobTheme) => ({
height: `calc(100% - ${theme => theme.mixins.toolbar.minHeight}px)`,
p: 1, // or 8px, padding is OK too
m: '16px', // or 2, margin is OK too
gap: '5px',
borderRadius: '5px',
ml: '10px', // mt, mr, mb, but marginLeft, marginRight, marginBottom is OK too
pl: '10px', // pt, pr, pb, but paddingTop, paddingRight, paddingBottom is OK too
}),
};
```

- Modify `className`:
Before: `<div className={this.props.classes.box}>`

After: `<Box sx={styles.box}>`

Before: `<span className={Utils.clsx(this.props.classes.box1, condition && this.props.classes.box2)}>`

After: `<Box component="span" sx={Utils.getStyle(this.props.theme, this.props.classes.box1, condition && this.props.classes.box2)}>`
Or if no one style is a function: `<Box component="div" sx={{ ...this.props.classes.box1, ...(condition ? this.props.classes.box2 : undefined) }}>`

Do not use `sx` if the style is not dynamic (not a function). Use `style` instead.

Be aware, that all paddings and margins are now in `theme.spacing(1)` format.
So you have to replace all `padding: 8` with `padding: 1` or with `padding: '8px'`.

The best practice is to replace `padding` with `p` and `margin` with `m`, so you will see immediately that it is a padding or margin for `sx` property.

- Modify `classes`:
Before: `<Dialog classes={{ scrollPaper: this.props.classes.dialog, paper: this.props.classes.paper }}>`
After: `<Dialog sx={{ '&.MuiDialog-scrollPaper': styles.dialog, '& .MuiDialog-paper': styles.paper }}>`,

Before: `<Dialog classes={{ scrollPaper: this.props.classes.dialog, paper: this.props.classes.paper }}>`
After: `<Dialog sx={{ '&.MuiDialog-scrollPaper': styles.dialog, '& .MuiDialog-paper': styles.paper }}>`

Before: `<ListItem classes={{ root: this.props.classes.listItem }} >`,
After: `<ListItem sx={{ '&.MuiListItem-root': styles.listItem }} >`

Before: `<Typography component="h2" variant="h6" classes={{ root: this.props.classes.typography }}>`,
After: `<Typography component="h2" variant="h6" sx={{ '&.MuiTypography-root': styles.typography }}>`

Before: `<Badge classes={{ 'badge': this.props.classes.expertBadge }}>`,
After: `<Badge sx={{ '& .MuiBadge-badge': styles.expertBadge }}>`

Before: `<Tab classes={{ selected: this.props.classes..selected }} />`,
After: `<Tab sx={{ '&.Mui-selected': styles.selected }} />`

Before: `<Tabs classes={{ indicator: this.props.classes.indicator }} />`,
After: `<Tabs sx={{ '& .MuiTabs-indicator': styles.indicator }} />`

Before: `<Tooltip title={this.props.t('ra_Refresh tree')} classes={{ popper: this.props.classes.tooltip }}>`,
After: `<Tooltip title={this.props.t('ra_Refresh tree')} componentsProps={{ popper: { sx: { pointerEvents: 'none' } } }}>`,
Or: `<Tooltip title={this.props.t('ra_Refresh tree')} componentsProps={{ popper: { sx: styles.tooltip } }}>`

Before. `<AccordionSummary classes={{ root: this.props.classes.rootStyle, content: this.props.classes.content }}>`,
After. `<AccordionSummary sx={{ '&.MuiAccordionSummary-root': styles.rootStyle, '& .MuiAccordionSummary-content': styles.content }}>`

Before. `<Drawer classes={{ paper: this.props.classes.paperStyle }}>`,
After. `<Drawer sx={{ '& .MuiDrawer-paper': styles.paperStyle }}>`
56 changes: 56 additions & 0 deletions packages/adapter-react-v5/MIGRATION_6_7.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Migration from [email protected] to [email protected]

Only MUI library was updated from v5 to v6.

## No `withStyles` at all

`withStyles` was removed completely. So you have to replace all `withStyles` with `sx` or `style` properties.

## slotProps

`inputProps` and `InputProps` are now in `slotProps`

Examples:
Before:

```jsx
<TextField
inputProps={{ readOnly: true }}
InputProps={{ endAdornment: <IconButton /> }}
/>
```

```jsx
<TextField
slotProps={{
htmlInput: {
readOnly: true,
},
input: {
endAdornment: <IconButton />,
},
}}
/>
```

## SelectID dialog

`SelectID` dialog now requires `theme` property. Without this property, the dialog will crash.

## Grid => Grid2

Replace all `Grid` with `Grid2` component and remove `item` property as it not needed anymore.

Attributes xs, sm, md, lg, xl are now in `size` property.

Before:

```jsx
<Grid item xs={6} sm={4} md={3}>
<Grid/>
```

```jsx
<Grid2 size={{ xs: 6, sm: 4, md: 3 }}>
<Grid2/>
```
8 changes: 6 additions & 2 deletions packages/adapter-react-v5/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ If you want to create the configuration page with ReactJS:
- Change `name` from `src` to `ADAPTERNAME-admin` (Of course replace `ADAPTERNAME` with yours)
- Add to devDependencies:
```json
"@iobroker/adapter-react-v5": "^7.3.1",
"@iobroker/adapter-react-v5": "^7.3.2",
```
Versions can be higher.
So your `src/package.json` should look like:
Expand All @@ -24,7 +24,7 @@ If you want to create the configuration page with ReactJS:
"version": "0.1.0",
"private": true,
"dependencies": {
"@iobroker/adapter-react-v5": "^7.3.1",
"@iobroker/adapter-react-v5": "^7.3.2",
"@iobroker/build-tools": "^1.0.0",
"babel-eslint": "^10.1.0",
"react-scripts": "^5.0.1"
Expand Down Expand Up @@ -689,6 +689,10 @@ You can find the migration instructions:
-->

## Changelog
### **WORK IN PROGRESS**

- (@GermanBluefox) Added new component: IconDeviceType

### 7.2.3 (2024-10-05)

- (@GermanBluefox) Corrected error in the simple CRON dialog
Expand Down
2 changes: 2 additions & 0 deletions packages/adapter-react-v5/modulefederation.admin.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ function makeShared(pkgs) {
// Admin shares these modules for all components
module.exports = {
shared: makeShared([
'@emotion/react',
'@emotion/styled',
'@iobroker/adapter-react-v5',
'@iobroker/json-config',
'@iobroker/dm-gui-components',
Expand Down
30 changes: 15 additions & 15 deletions packages/adapter-react-v5/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"3-patchReadme": "node tasks --3-patchReadme",
"npm": "npm i -f",
"lint": "eslint -c eslint.config.mjs src",
"test": "ts-node test/testSchema.ts"
"test": "ts-node ../jsonConfig/test/testSchema.ts"
},
"repository": {
"type": "git",
Expand Down Expand Up @@ -56,26 +56,26 @@
"@iobroker/js-controller-common-db": "^6.0.11",
"@iobroker/socket-client": "^3.1.2",
"@iobroker/types": "^6.0.11",
"@mui/icons-material": "^6.1.5",
"@mui/material": "^6.1.5",
"@sentry/browser": "^8.35.0",
"cronstrue": "^2.50.0",
"@mui/icons-material": "^6.1.7",
"@mui/material": "^6.1.7",
"@sentry/browser": "^8.38.0",
"cronstrue": "^2.51.0",
"react-color": "^2.19.3",
"react-colorful": "^5.6.1",
"react-cropper": "^2.3.3",
"react-dropzone": "^14.2.10",
"react-inlinesvg": "^4.1.4"
"react-dropzone": "^14.3.5",
"react-inlinesvg": "^4.1.5"
},
"devDependencies": {
"@babel/core": "^7.25.7",
"@babel/core": "^7.26.0",
"@babel/plugin-proposal-class-properties": "^7.18.6",
"@babel/plugin-transform-runtime": "^7.25.7",
"@babel/preset-env": "^7.25.7",
"@babel/preset-flow": "^7.25.7",
"@babel/preset-react": "^7.25.7",
"@iobroker/eslint-config": "^0.1.6",
"@types/node": "^22.7.5",
"@types/react": "^18.3.11",
"@babel/plugin-transform-runtime": "^7.25.9",
"@babel/preset-env": "^7.26.0",
"@babel/preset-flow": "^7.25.9",
"@babel/preset-react": "^7.25.9",
"@iobroker/eslint-config": "^0.1.7",
"@types/node": "^22.9.0",
"@types/react": "^18.3.12",
"@types/react-color": "^3.0.12",
"ajv": "^8.17.1",
"ts-node": "^10.9.2",
Expand Down
12 changes: 6 additions & 6 deletions packages/adapter-react-v5/src/Components/Icon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export function getSelectIdIcon(obj: ioBroker.Object | null, imagePrefix?: strin
return src || null;
}

interface IconProps {
export interface IconProps {
/** URL, UTF-8 character, or svg code (data:image/svg...) */
src: string | React.JSX.Element | null | undefined;
/** Class name */
Expand Down Expand Up @@ -165,7 +165,7 @@ export function Icon(props: IconProps): React.JSX.Element | null {
className={Utils.clsx(props.className, 'iconOwn')}
width={props.style?.width || 28}
height={props.style?.height || props.style?.width || 28}
style={props.style || {}}
style={props.style || undefined}
/>
);
}
Expand All @@ -183,7 +183,7 @@ export function Icon(props: IconProps): React.JSX.Element | null {
component="img"
sx={props.sx}
title={props.title || undefined}
style={props.style || {}}
style={props.style || undefined}
className={Utils.clsx(props.className, 'iconOwn')}
src={`https://remote-files.iobroker.in${src}`}
alt={props.alt || undefined}
Expand All @@ -195,7 +195,7 @@ export function Icon(props: IconProps): React.JSX.Element | null {
return (
<img
title={props.title || undefined}
style={props.style || {}}
style={props.style || undefined}
className={Utils.clsx(props.className, 'iconOwn')}
src={`https://remote-files.iobroker.in${src}`}
alt={props.alt || undefined}
Expand All @@ -210,7 +210,7 @@ export function Icon(props: IconProps): React.JSX.Element | null {
component="img"
sx={props.sx}
title={props.title || undefined}
style={props.style || {}}
style={props.style || undefined}
className={Utils.clsx(props.className, 'iconOwn')}
src={props.src}
alt={props.alt || undefined}
Expand All @@ -222,7 +222,7 @@ export function Icon(props: IconProps): React.JSX.Element | null {
return (
<img
title={props.title || undefined}
style={props.style || {}}
style={props.style || undefined}
className={Utils.clsx(props.className, 'iconOwn')}
src={props.src}
alt={props.alt || undefined}
Expand Down
Loading

0 comments on commit 968daac

Please sign in to comment.