Skip to content

Commit 43b17e8

Browse files
ks-ci-botdonniean
andauthored
[master] chore: sync codes (#4416)
chore: sync codes Signed-off-by: donniean <donniean1@gmail.com> Co-authored-by: donniean <donniean1@gmail.com>
1 parent 21a5eb7 commit 43b17e8

File tree

8 files changed

+105
-19
lines changed

8 files changed

+105
-19
lines changed

packages/core/src/containers/Extensions/Management/components/ResetDefaultConfigTip/ResetDefaultConfigConfirmModal.tsx

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,12 @@
44
*/
55

66
import React from 'react';
7-
import type { ModalProps } from '@kubed/components';
8-
import { Question } from '@kubed/icons';
97

10-
import { StyledModal, Header, Title, Description } from './ResetDefaultConfigConfirmModal.styles';
8+
import type { ConfirmModalProps } from '@ks-console/shared';
9+
import { ConfirmModal } from '@ks-console/shared';
1110

1211
type ResetDefaultConfigConfirmModalProps = Pick<
13-
ModalProps,
12+
ConfirmModalProps,
1413
'visible' | 'confirmLoading' | 'onCancel' | 'onOk'
1514
>;
1615

@@ -21,19 +20,14 @@ export function ResetDefaultConfigConfirmModal({
2120
onOk,
2221
}: ResetDefaultConfigConfirmModalProps) {
2322
return (
24-
<StyledModal
23+
<ConfirmModal
2524
visible={visible}
26-
header={null}
27-
closable={false}
25+
titleIconProps={{ type: 'info' }}
26+
title={t('RESET_DEFAULT_CONFIGURATION_TITLE')}
27+
description={t('RESET_DEFAULT_CONFIGURATION_CONFIRM_DESCRIPTION')}
2828
confirmLoading={confirmLoading}
2929
onCancel={onCancel}
3030
onOk={onOk}
31-
>
32-
<Header>
33-
<Question size={20} />
34-
<Title>{t('RESET_DEFAULT_CONFIGURATION_TITLE')}</Title>
35-
</Header>
36-
<Description>{t('RESET_DEFAULT_CONFIGURATION_CONFIRM_DESCRIPTION')}</Description>
37-
</StyledModal>
31+
/>
3832
);
3933
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { Question, Exclamation, Failure } from '@kubed/icons';
2+
3+
export const DEFAULT_TITLE_ICON_PROPS = {
4+
size: 20,
5+
color: '#fff',
6+
} as const;
7+
8+
export const TITLE_ICON_TYPE_MAP = {
9+
info: {
10+
icon: Question,
11+
fillColorName: 'blue',
12+
},
13+
warning: {
14+
icon: Exclamation,
15+
fillColorName: 'yellow',
16+
},
17+
error: {
18+
icon: Failure,
19+
fillColorName: 'red',
20+
},
21+
} as const;
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import React from 'react';
2+
import { merge } from 'lodash';
3+
import { useTheme } from '@kubed/components';
4+
5+
import type { TitleIconProps, ConfirmModalProps } from './ConfirmModal.types';
6+
import { DEFAULT_TITLE_ICON_PROPS, TITLE_ICON_TYPE_MAP } from './ConfirmModal.constants';
7+
8+
interface TitleIconOptions {
9+
titleIconProps?: TitleIconProps;
10+
titleIcon?: ConfirmModalProps['titleIcon'];
11+
}
12+
13+
export function renderTitleIcon({ titleIconProps, titleIcon }: TitleIconOptions) {
14+
const { palette } = useTheme();
15+
16+
if (titleIcon) {
17+
return titleIcon;
18+
}
19+
20+
if (!titleIconProps) {
21+
return null;
22+
}
23+
24+
const { icon: Icon, fillColorName } = TITLE_ICON_TYPE_MAP[titleIconProps.type];
25+
const defaultProps: Omit<TitleIconProps, 'type'> = {
26+
...DEFAULT_TITLE_ICON_PROPS,
27+
fill: palette.colors[fillColorName]?.[2],
28+
};
29+
const finalProps = merge({}, defaultProps, titleIconProps);
30+
31+
return <Icon {...finalProps} />;
32+
}
Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,6 @@ export const Header = styled.div`
2525
display: flex;
2626
align-items: center;
2727
column-gap: 4px;
28-
29-
svg.kubed-icon {
30-
color: rgba(255, 255, 255, 0.9);
31-
fill: ${({ theme }) => theme.palette.colors.blue[2]};
32-
}
3328
`;
3429

3530
export const Title = styled.h5`
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import React from 'react';
2+
3+
import type { ConfirmModalProps } from './ConfirmModal.types';
4+
import { renderTitleIcon } from './ConfirmModal.helpers';
5+
import { StyledModal, Header, Title, Description } from './ConfirmModal.styles';
6+
7+
export function ConfirmModal({
8+
titleIconProps,
9+
titleIcon,
10+
title,
11+
description,
12+
...rest
13+
}: ConfirmModalProps) {
14+
const hasHeader = title || titleIcon || titleIconProps;
15+
16+
return (
17+
<StyledModal header={null} closable={false} {...rest}>
18+
{hasHeader && (
19+
<Header>
20+
{renderTitleIcon({ titleIconProps, titleIcon })}
21+
{title && <Title>{title}</Title>}
22+
</Header>
23+
)}
24+
{description && <Description>{description}</Description>}
25+
</StyledModal>
26+
);
27+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import type { ReactNode } from 'react';
2+
import type { ModalProps } from '@kubed/components';
3+
import type { Props } from '@kubed/icons';
4+
5+
export interface TitleIconProps extends Props {
6+
type: 'warning' | 'info' | 'error';
7+
}
8+
9+
export interface ConfirmModalProps extends Omit<ModalProps, 'title' | 'titleIcon'> {
10+
titleIconProps?: TitleIconProps;
11+
titleIcon?: ReactNode;
12+
title?: ReactNode;
13+
description?: ReactNode;
14+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export type { ConfirmModalProps } from './ConfirmModal.types';
2+
export * from './ConfirmModal';

packages/shared/src/components/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export { default as Pagination } from './Pagination';
2323
export { default as Avatar } from './Avatar';
2424
export { default as StatusReason } from './StatusReason';
2525

26+
export * from './Modals/Confirm';
2627
export * from './Modals/EnterLicense';
2728
export * from './Modals/FullScreenModal';
2829
export * from './Modals/KubeCtl';

0 commit comments

Comments
 (0)