Skip to content

Commit f73c6c1

Browse files
chore(buttons): wrapped disalbed color generation in useMemo
1 parent 3966bd7 commit f73c6c1

File tree

5 files changed

+20
-14
lines changed

5 files changed

+20
-14
lines changed

src/buttons/common-buttons/elevated-button/ElevatedButton.component.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@ export const ElevatedButton: React.FC<CommonButtonProps> = ({titleStyle, style,
1717
),
1818
[props.disabled]
1919
);
20-
console.log(colorStyles.container);
20+
2121
return <CommonButton style={[colorStyles.container, styles.container, style]} titleStyle={[colorStyles.title, titleStyle]} {...props} />;
2222
};

src/buttons/icon-buttons/filled-icon-button/FilledIconButton.component.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React from 'react';
1+
import React, {useMemo} from 'react';
22

33
import {useTheme} from '../../../theme/useTheme.hook';
44
import {type IconButtonProps} from '../icon-button.types';
@@ -9,8 +9,10 @@ import {BaseIconButton} from '../base-icon-button/BaseIconButton.component';
99
export const FilledIconButton: React.FC<IconButtonProps> = ({selected, Icon, selectedIcon, style, ...props}) => {
1010
const {primary, surface, surfaceContainer} = useTheme();
1111

12-
const disabledIconColor = convertToRGBA(surface.text as ColorValue, 0.38);
13-
const disabledContainerColor = convertToRGBA(surface.text as ColorValue, 0.12);
12+
const [disabledIconColor, disabledContainerColor] = useMemo(
13+
() => [convertToRGBA(surface.text as ColorValue, 0.38), convertToRGBA(surface.text as ColorValue, 0.12)],
14+
[surface.text]
15+
);
1416

1517
const [activeContainerColor, activeIconColor, IconComponent] = selected
1618
? [primary.background, primary.text, selectedIcon ?? Icon]

src/buttons/icon-buttons/outlined-icon-button/OutlinedIconButton.component.tsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
1-
import React from 'react';
1+
import React, {useMemo} from 'react';
22

33
import {useTheme} from '../../../theme/useTheme.hook';
4-
import {type ColorValue} from 'src/theme/theme.types';
54
import {type IconButtonProps} from '../icon-button.types';
5+
import {type ColorValue} from '../../../theme/theme.types';
66
import {convertToRGBA} from '../../../utils/convert-to-rgba';
77
import {BaseIconButton} from '../base-icon-button/BaseIconButton.component';
88

99
export const OutlinedIconButton: React.FC<IconButtonProps> = ({selected, Icon, selectedIcon, style, ...props}) => {
1010
const {surface, outline} = useTheme();
1111

12-
const disabledIconColor = convertToRGBA(surface.text as ColorValue, 0.38);
13-
const disabledContainerColor = convertToRGBA(surface.text as ColorValue, 0.12);
14-
const appliedDisabledContainerColor = selected ? convertToRGBA(surface.text as ColorValue, 0.12) : 'transparent';
12+
const [disabledIconColor, disabledContainerColor] = useMemo(
13+
() => [convertToRGBA(surface.text as ColorValue, 0.38), convertToRGBA(surface.text as ColorValue, 0.12)],
14+
[surface.text]
15+
);
1516

17+
const appliedDisabledContainerColor = selected ? disabledContainerColor : 'transparent';
1618
const [activeContainerColor, activeIconColor, activeBorderColor, IconComponent] = selected
1719
? [surface.backgroundInverse, surface.textInverse, surface.backgroundInverse, selectedIcon ?? Icon]
1820
: ['transparent', surface.textVariant, outline, Icon];

src/buttons/icon-buttons/standart-icon-button/StandardIconButton.component.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React from 'react';
1+
import React, {useMemo} from 'react';
22

33
import {useTheme} from '../../../theme/useTheme.hook';
44
import {type IconButtonProps} from '../icon-button.types';
@@ -9,7 +9,7 @@ import {BaseIconButton} from '../base-icon-button/BaseIconButton.component';
99
export const StandartIconButton: React.FC<IconButtonProps> = ({selected, Icon, selectedIcon, ...props}) => {
1010
const {primary, surface} = useTheme();
1111

12-
const disabledIconColor = convertToRGBA(surface.text as ColorValue, 0.38);
12+
const disabledIconColor = useMemo(() => convertToRGBA(surface.text as ColorValue, 0.38), [surface.text]);
1313

1414
const [iconColor, IconComponent] = selected ? [primary.background, selectedIcon ?? Icon] : [surface.textVariant, Icon];
1515

src/buttons/icon-buttons/tonal-icon-button/TonalIconButton.component.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React from 'react';
1+
import React, {useMemo} from 'react';
22

33
import {useTheme} from '../../../theme/useTheme.hook';
44
import {type IconButtonProps} from '../icon-button.types';
@@ -9,8 +9,10 @@ import {BaseIconButton} from '../base-icon-button/BaseIconButton.component';
99
export const TonalIconButton: React.FC<IconButtonProps> = ({selected, Icon, selectedIcon, style, ...props}) => {
1010
const {surfaceContainer, surface, secondaryContainer} = useTheme();
1111

12-
const disabledIconColor = convertToRGBA(surface.text as ColorValue, 0.38);
13-
const disabledContainerColor = convertToRGBA(surface.text as ColorValue, 0.12);
12+
const [disabledIconColor, disabledContainerColor] = useMemo(
13+
() => [convertToRGBA(surface.text as ColorValue, 0.38), convertToRGBA(surface.text as ColorValue, 0.12)],
14+
[surface.text]
15+
);
1416

1517
const [activeContainerColor, activeIconColor, IconComponent] = selected
1618
? [secondaryContainer.background, secondaryContainer.text, selectedIcon ?? Icon]

0 commit comments

Comments
 (0)