Skip to content

Commit ebd5677

Browse files
committed
refactor children props destructuring
Signed-off-by: Leonardo Rossi <[email protected]>
1 parent 562ef9d commit ebd5677

10 files changed

+76
-52
lines changed

src/components/BorderedBox.jsx

+17-14
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,23 @@ import PropTypes from 'prop-types'
33
import styles from './BorderedBox.module.css'
44
import commonStyles from './Common.module.css'
55
import { COLORS_BORDERED_BOX, DARK_BLUE, TRANSPARENT, OPACITIES, OPACITY_100 } from './constants'
6-
function BorderedBox ({
7-
classes = '',
8-
color = TRANSPARENT,
9-
children,
10-
backgroundColor = DARK_BLUE,
11-
backgroundColorOpacity = OPACITY_100,
12-
borderColorOpacity = OPACITY_100,
13-
clickable = false,
14-
onClick = () => {},
15-
internalOverHandling = false,
16-
backgroundColorOver = null,
17-
backgroundColorOpacityOver = null,
18-
borderColorOpacityOver = null
19-
}) {
6+
7+
function BorderedBox (props) {
8+
const {
9+
classes = '',
10+
color = TRANSPARENT,
11+
children,
12+
backgroundColor = DARK_BLUE,
13+
backgroundColorOpacity = OPACITY_100,
14+
borderColorOpacity = OPACITY_100,
15+
clickable = false,
16+
onClick = () => {},
17+
internalOverHandling = false,
18+
backgroundColorOver = null,
19+
backgroundColorOpacityOver = null,
20+
borderColorOpacityOver = null
21+
} = props
22+
2023
const [over, setOver] = useState(false)
2124
const [className, setClassName] = useState(normalClassName())
2225

src/components/Box.jsx

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import styles from './Box.module.css'
22
import React from 'react'
3-
export default function Box ({ justifyCentered, children }) {
3+
4+
export default function Box (props) {
5+
const { justifyCentered, children } = props
46
let className = `${styles.box}`
57
if (justifyCentered) className += ` ${styles.justifyCentered}`
68

src/components/InfoBox.jsx

+9-7
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@ import Button from './Button'
55
import PlatformaticIcon from './PlatformaticIcon'
66
import { COLORS_BUTTON, COLORS_ICON, HOVER_EFFECTS_BUTTONS, MAIN_GREEN } from './constants'
77

8-
function InfoBox ({
9-
children,
10-
iconName = '',
11-
iconColor = MAIN_GREEN,
12-
helpText = '',
13-
buttonProps = null
14-
}) {
8+
function InfoBox (props) {
9+
const {
10+
children,
11+
iconName = '',
12+
iconColor = MAIN_GREEN,
13+
helpText = '',
14+
buttonProps = null
15+
} = props
16+
1517
return (
1618
<div className={styles.container}>
1719
<PlatformaticIcon size='extra-large' iconName={iconName} color={iconColor} />

src/components/List.jsx

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
import React from 'react'
22
import styles from './List.module.css'
33

4-
export default function List ({ title, ...props }) {
4+
export default function List (props) {
5+
const { title, children, ...rest } = props
56
return (
67
<div className={styles.container}>
78
{title &&
89
<div
910
className={styles.title}
1011
data-testid='list-title'
11-
{...props}
12+
{...rest}
1213
>
1314
{title}
1415
</div>}
1516
<div className={styles.elements}>
16-
{props.children}
17+
{children}
1718
</div>
1819
</div>
1920
)

src/components/SimpleMetric.jsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ import MetricValue from './MetricValue'
55
import ButtonFullRounded from './ButtonFullRounded'
66
import { DULLS_BACKGROUND_COLOR, MEDIUM, WHITE } from './constants'
77

8-
export default function SimpleMetric ({ title, pre, color, unit, value, tooltip, children }) {
8+
export default function SimpleMetric (props) {
9+
const { title, pre, color, unit, value, tooltip, children } = props
910
const withoutChildrenSingleMetric = !children ? styles.centerMetric : ''
1011
return (
1112
<BorderedBox>

src/components/SplashScreen.jsx

+14-13
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,18 @@ import styles from './SplashScreen.module.css'
33
import { ERROR_RED, MAIN_GREEN, RICH_BLACK, WHITE } from './constants'
44
import Icons from './icons'
55
import Button from './Button'
6-
export default function SplashScreen ({
7-
success = true,
8-
timeout = 5000,
9-
message = '',
10-
title = 'Operation completed',
11-
blur = false,
12-
children,
13-
onDestroyed = () => {}
14-
}) {
6+
7+
export default function SplashScreen (props) {
8+
const {
9+
success = true,
10+
timeout = 5000,
11+
message = '',
12+
title = 'Operation completed',
13+
blur = false,
14+
children,
15+
onDestroyed = () => {}
16+
} = props
17+
1518
const [destroyed, setDestroyed] = useState(false)
1619
useEffect(() => {
1720
if (destroyed) {
@@ -52,13 +55,11 @@ export default function SplashScreen ({
5255
backgroundColor={WHITE}
5356
onClick={() => setDestroyed(true)}
5457
label='Dismiss'
55-
paddingClass='px-2 py-1'
56-
textClass='text-[13px]'
58+
paddingClass={styles.buttonPadding}
59+
textClass={styles.buttonText}
5760
/>
5861
</div>
59-
6062
</div>
61-
6263
</div>
6364
)
6465
}

src/components/SplashScreen.module.css

+9-1
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,12 @@
3232

3333
.button {
3434
@apply flex items-center justify-center;
35-
}
35+
}
36+
37+
.buttonPadding {
38+
@apply px-2 py-1;
39+
}
40+
41+
.buttonText {
42+
@apply text-[14px];
43+
}

src/components/TextWithLabel.jsx

+10-7
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,16 @@ import PropTypes from 'prop-types'
33
import { FONT_BASE, FONT_XS, MAIN_DARK_BLUE, WHITE } from './constants'
44
import commonStyles from './Common.module.css'
55
import styles from './TextWithLabel.module.css'
6-
function TextWithLabel ({
7-
label = '',
8-
text = '',
9-
children,
10-
color = WHITE,
11-
fontSize = FONT_BASE
12-
}) {
6+
7+
function TextWithLabel (props) {
8+
const {
9+
label = '',
10+
text = '',
11+
children,
12+
color = WHITE,
13+
fontSize = FONT_BASE
14+
} = props
15+
1316
const className = commonStyles[`text--${color}`] + ' ' + commonStyles[`text--${fontSize}`]
1417
return (
1518
<div className={className}>

src/components/layouts/Layout.jsx

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import React from 'react'
22
import PropTypes from 'prop-types'
33

4-
function Layout ({
5-
className = 'container mx-auto px-5 my-5 flex flex-col gap-10 h-screen',
6-
children = null
7-
}) {
4+
function Layout (props) {
5+
const {
6+
className = 'container mx-auto px-5 my-5 flex flex-col gap-10 h-screen',
7+
children = null
8+
} = props
9+
810
return (
911
<div className={className}>
1012
{children}

src/components/layouts/TwoColumnsLayout.jsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import React from 'react'
22
import styles from './TwoColumnsLayout.module.css'
33

4-
export default function TwoColumnsLayout ({ children, gridTemplate = 'columns' }) {
4+
export default function TwoColumnsLayout (props) {
5+
const { children, gridTemplate = 'columns' } = props
56
const className = styles[`${gridTemplate}`]
67
return (
78
<div className={className}>

0 commit comments

Comments
 (0)