[MM-57725] Convert ./components/common/chip/chip.tsx from Class Component to Function Component (#26729)
* [MM-57725] Convert `./components/common/chip/chip.tsx` from Class Component to Function Component * :refactor: improve code structure
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
4ee5763e9d
Коммит
9b227aaa28
@@ -1,7 +1,7 @@
|
|||||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||||
// See LICENSE.txt for license information.
|
// See LICENSE.txt for license information.
|
||||||
|
|
||||||
import React from 'react';
|
import React, {useCallback} from 'react';
|
||||||
import {FormattedMessage} from 'react-intl';
|
import {FormattedMessage} from 'react-intl';
|
||||||
import styled from 'styled-components';
|
import styled from 'styled-components';
|
||||||
|
|
||||||
@@ -52,34 +52,45 @@ const StyledChip = styled.button<{ otherOption?: boolean }>`
|
|||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
export default class Chip extends React.PureComponent<Props> {
|
const emojiStyles = {marginRight: '11px'};
|
||||||
onClick = (e: React.MouseEvent) => {
|
|
||||||
e.preventDefault();
|
|
||||||
this.props.onClick?.();
|
|
||||||
};
|
|
||||||
|
|
||||||
render() {
|
const Chip = ({
|
||||||
return (
|
onClick,
|
||||||
<StyledChip
|
otherOption,
|
||||||
onClick={this.onClick}
|
className,
|
||||||
otherOption={this.props.otherOption}
|
leadingIcon,
|
||||||
className={this.props.className || ''}
|
id,
|
||||||
>
|
defaultMessage,
|
||||||
{this.props.leadingIcon && (
|
values,
|
||||||
<RenderEmoji
|
additionalMarkup,
|
||||||
emojiName={this.props.leadingIcon}
|
}: Props) => {
|
||||||
emojiStyle={{marginRight: '11px'}}
|
const handleClick = useCallback((e: React.MouseEvent) => {
|
||||||
/>
|
e.preventDefault();
|
||||||
)}
|
onClick?.();
|
||||||
{(this.props.id && this.props.defaultMessage && this.props.values) && (
|
}, [onClick]);
|
||||||
<FormattedMessage
|
|
||||||
id={this.props.id}
|
return (
|
||||||
defaultMessage={this.props.defaultMessage}
|
<StyledChip
|
||||||
values={this.props.values}
|
onClick={handleClick}
|
||||||
/>
|
otherOption={otherOption}
|
||||||
)}
|
className={className || ''}
|
||||||
{this.props.additionalMarkup}
|
>
|
||||||
</StyledChip>
|
{leadingIcon && (
|
||||||
);
|
<RenderEmoji
|
||||||
}
|
emojiName={leadingIcon}
|
||||||
}
|
emojiStyle={emojiStyles}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
{(id && defaultMessage && values) && (
|
||||||
|
<FormattedMessage
|
||||||
|
id={id}
|
||||||
|
defaultMessage={defaultMessage}
|
||||||
|
values={values}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
{additionalMarkup}
|
||||||
|
</StyledChip>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default Chip;
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user