mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
[MM-54816] Convert ./components/admin_console/color_setting.tsx from Class Component to Function Component (#24963)
* Convert class component to function component * Apply changes from suggestions * Lint check * Update schema_admin_settings.test.jsx.snap --------- Co-authored-by: Mattermost Build <build@mattermost.com>
This commit is contained in:
@@ -595,7 +595,7 @@ exports[`components/admin_console/SchemaAdminSettings should match snapshot with
|
||||
}
|
||||
value={true}
|
||||
/>
|
||||
<ColorSetting
|
||||
<Memo(ColorSetting)
|
||||
disabled={false}
|
||||
helpText={
|
||||
<SchemaText
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
import React from 'react';
|
||||
import React, {useCallback} from 'react';
|
||||
|
||||
import ColorInput from 'components/color_input';
|
||||
|
||||
@@ -16,27 +16,27 @@ type Props = {
|
||||
disabled?: boolean;
|
||||
}
|
||||
|
||||
export default class ColorSetting extends React.PureComponent<Props> {
|
||||
private handleChange = (color: string) => {
|
||||
if (this.props.onChange) {
|
||||
this.props.onChange(this.props.id, color);
|
||||
const ColorSetting = (props: Props) => {
|
||||
const handleChange = useCallback((color: string) => {
|
||||
if (props.onChange) {
|
||||
props.onChange(props.id, color);
|
||||
}
|
||||
};
|
||||
}, [props.id, props.onChange]);
|
||||
|
||||
public render() {
|
||||
return (
|
||||
<Setting
|
||||
label={this.props.label}
|
||||
helpText={this.props.helpText}
|
||||
inputId={this.props.id}
|
||||
>
|
||||
<ColorInput
|
||||
id={this.props.id}
|
||||
value={this.props.value}
|
||||
onChange={this.handleChange}
|
||||
isDisabled={this.props.disabled}
|
||||
/>
|
||||
</Setting>
|
||||
);
|
||||
}
|
||||
}
|
||||
return (
|
||||
<Setting
|
||||
label={props.label}
|
||||
helpText={props.helpText}
|
||||
inputId={props.id}
|
||||
>
|
||||
<ColorInput
|
||||
id={props.id}
|
||||
value={props.value}
|
||||
onChange={handleChange}
|
||||
isDisabled={props.disabled}
|
||||
/>
|
||||
</Setting>
|
||||
);
|
||||
};
|
||||
|
||||
export default React.memo(ColorSetting);
|
||||
|
||||
Reference in New Issue
Block a user