-
Notifications
You must be signed in to change notification settings - Fork 456
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: sync codes Signed-off-by: donniean <[email protected]> Co-authored-by: donniean <[email protected]>
- Loading branch information
Showing
8 changed files
with
105 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
packages/shared/src/components/Modals/Confirm/ConfirmModal.constants.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { Question, Exclamation, Failure } from '@kubed/icons'; | ||
|
||
export const DEFAULT_TITLE_ICON_PROPS = { | ||
size: 20, | ||
color: '#fff', | ||
} as const; | ||
|
||
export const TITLE_ICON_TYPE_MAP = { | ||
info: { | ||
icon: Question, | ||
fillColorName: 'blue', | ||
}, | ||
warning: { | ||
icon: Exclamation, | ||
fillColorName: 'yellow', | ||
}, | ||
error: { | ||
icon: Failure, | ||
fillColorName: 'red', | ||
}, | ||
} as const; |
32 changes: 32 additions & 0 deletions
32
packages/shared/src/components/Modals/Confirm/ConfirmModal.helpers.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import React from 'react'; | ||
import { merge } from 'lodash'; | ||
import { useTheme } from '@kubed/components'; | ||
|
||
import type { TitleIconProps, ConfirmModalProps } from './ConfirmModal.types'; | ||
import { DEFAULT_TITLE_ICON_PROPS, TITLE_ICON_TYPE_MAP } from './ConfirmModal.constants'; | ||
|
||
interface TitleIconOptions { | ||
titleIconProps?: TitleIconProps; | ||
titleIcon?: ConfirmModalProps['titleIcon']; | ||
} | ||
|
||
export function renderTitleIcon({ titleIconProps, titleIcon }: TitleIconOptions) { | ||
const { palette } = useTheme(); | ||
|
||
if (titleIcon) { | ||
return titleIcon; | ||
} | ||
|
||
if (!titleIconProps) { | ||
return null; | ||
} | ||
|
||
const { icon: Icon, fillColorName } = TITLE_ICON_TYPE_MAP[titleIconProps.type]; | ||
const defaultProps: Omit<TitleIconProps, 'type'> = { | ||
...DEFAULT_TITLE_ICON_PROPS, | ||
fill: palette.colors[fillColorName]?.[2], | ||
}; | ||
const finalProps = merge({}, defaultProps, titleIconProps); | ||
|
||
return <Icon {...finalProps} />; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
packages/shared/src/components/Modals/Confirm/ConfirmModal.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import React from 'react'; | ||
|
||
import type { ConfirmModalProps } from './ConfirmModal.types'; | ||
import { renderTitleIcon } from './ConfirmModal.helpers'; | ||
import { StyledModal, Header, Title, Description } from './ConfirmModal.styles'; | ||
|
||
export function ConfirmModal({ | ||
titleIconProps, | ||
titleIcon, | ||
title, | ||
description, | ||
...rest | ||
}: ConfirmModalProps) { | ||
const hasHeader = title || titleIcon || titleIconProps; | ||
|
||
return ( | ||
<StyledModal header={null} closable={false} {...rest}> | ||
{hasHeader && ( | ||
<Header> | ||
{renderTitleIcon({ titleIconProps, titleIcon })} | ||
{title && <Title>{title}</Title>} | ||
</Header> | ||
)} | ||
{description && <Description>{description}</Description>} | ||
</StyledModal> | ||
); | ||
} |
14 changes: 14 additions & 0 deletions
14
packages/shared/src/components/Modals/Confirm/ConfirmModal.types.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import type { ReactNode } from 'react'; | ||
import type { ModalProps } from '@kubed/components'; | ||
import type { Props } from '@kubed/icons'; | ||
|
||
export interface TitleIconProps extends Props { | ||
type: 'warning' | 'info' | 'error'; | ||
} | ||
|
||
export interface ConfirmModalProps extends Omit<ModalProps, 'title' | 'titleIcon'> { | ||
titleIconProps?: TitleIconProps; | ||
titleIcon?: ReactNode; | ||
title?: ReactNode; | ||
description?: ReactNode; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export type { ConfirmModalProps } from './ConfirmModal.types'; | ||
export * from './ConfirmModal'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters