Skip to content

Commit c1febfe

Browse files
authored
Merge pull request #99 from chenz24/fix/improve
Some improves
2 parents bc530f4 + c619355 commit c1febfe

File tree

8 files changed

+59
-25
lines changed

8 files changed

+59
-25
lines changed

.changeset/fair-fireants-brush.md

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
'@kubed/components': patch
3+
---
4+
5+
1. Divider support height and color.
6+
2. Fix modal cannot hide header and footer.
7+
3. Fix react key warning when open imperative modal.
8+
4. Popover support set width and contentClassName.

packages/components/src/Divider/Divider.story.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export const Label = () => (
2828
export const Vertical = () => (
2929
<Group>
3030
<Button>1</Button>
31-
<Divider direction="vertical" margins="sm" />
31+
<Divider direction="vertical" height={20} margins="sm" />
3232
<Button>2</Button>
3333
<Divider direction="vertical" margins="sm" />
3434
<Button>3</Button>

packages/components/src/Divider/Divider.styles.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,16 @@ export const DividerWrapper = styled('div')<React.ComponentPropsWithoutRef<any>>
2020
2121
&.horizontal {
2222
border-top-style: ${({ variant }) => variant};
23-
border-top-width: ${({ size }) => getSizeValue(size, sizes)};
24-
border-top-color: ${({ theme }) => theme.palette.border};
23+
border-top-width: ${({ $size }) => getSizeValue($size, sizes)};
24+
border-top-color: ${({ theme, $color }) => $color || theme.palette.border};
2525
margin: ${({ $margins, theme }) => getSizeValue($margins, theme.layout.spacing)} 0;
2626
}
2727
2828
&.vertical {
29-
align-self: stretch;
29+
${({ $height }) => ($height ? `height: ${$height}px;` : 'align-self: stretch;')};
3030
border-left-style: ${({ variant }) => variant};
31-
border-left-color: ${({ theme }) => theme.palette.border};
32-
border-left-width: ${({ size }) => getSizeValue(size, sizes)};
31+
border-left-color: ${({ theme, $color }) => $color || theme.palette.border};
32+
border-left-width: ${({ $size }) => getSizeValue($size, sizes)};
3333
margin-left: ${({ $margins, theme }) => getSizeValue($margins, theme.layout.spacing)};
3434
margin-right: ${({ $margins, theme }) => getSizeValue($margins, theme.layout.spacing)};
3535
}

packages/components/src/Divider/Divider.tsx

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from 'react';
2-
import cx from 'clsx';
2+
import cx from 'classnames';
33
import forwardRef from '../utils/forwardRef';
44
import { DefaultProps, KubedNumberSize } from '../theme';
55
import { DividerWrapper, Label } from './Divider.styles';
@@ -28,6 +28,9 @@ export interface DividerProps extends DefaultProps {
2828

2929
/** Top and bottom margins for horizontal variant, left and right for vertical, xs, sm, md, lg, xl for value from theme.spacing, number for margins in px */
3030
margins?: KubedNumberSize;
31+
32+
/** Divider height, only available if direction is vertical */
33+
height?: number;
3134
}
3235

3336
export const Divider = forwardRef<DividerProps, 'hr'>(
@@ -43,6 +46,7 @@ export const Divider = forwardRef<DividerProps, 'hr'>(
4346
themeOverride,
4447
variant = 'solid',
4548
margins = 0,
49+
height,
4650
...rest
4751
},
4852
ref
@@ -58,7 +62,9 @@ export const Divider = forwardRef<DividerProps, 'hr'>(
5862
direction={direction}
5963
variant={variant}
6064
$margins={margins}
61-
size={size}
65+
$size={size}
66+
$height={height}
67+
$color={color}
6268
{...rest}
6369
>
6470
{!!label && horizontal && (

packages/components/src/Modal/Modal.tsx

+14-12
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React, { RefObject, useEffect, useImperativeHandle, useState } from 'react';
22
import cx from 'classnames';
3+
import { isNull } from 'lodash';
34
import { Close } from '@kubed/icons';
45
import { StyledDialog } from './Modal.styles';
56
import { ButtonProps, Button } from '../Button/Button';
@@ -101,8 +102,7 @@ interface ModalRef {
101102

102103
export type ModalType = 'info' | 'success' | 'error' | 'warn' | 'warning' | 'confirm' | 'open';
103104

104-
export interface ModalFuncProps
105-
extends Omit<ModalProps, 'footer' | 'forceRender' | 'destroyOnClose'> {
105+
export interface ModalFuncProps extends Omit<ModalProps, 'forceRender' | 'destroyOnClose'> {
106106
content?: React.ReactNode;
107107
icon?: React.ReactNode;
108108
type?: ModalType;
@@ -126,8 +126,17 @@ const Modal = forwardRef<ModalProps, any>((props, ref) => {
126126
onOk?.(e);
127127
};
128128

129+
const renderHeader = () => {
130+
const { header, title, description, titleIcon } = props;
131+
if (header || isNull(header)) return header;
132+
133+
return <Field value={title} label={description} avatar={titleIcon} />;
134+
};
135+
129136
const renderFooter = () => {
130-
const { okText, cancelText, confirmLoading, cancelButtonProps, okButtonProps } = props;
137+
const { footer, okText, cancelText, confirmLoading, cancelButtonProps, okButtonProps } = props;
138+
if (footer || isNull(footer)) return footer;
139+
131140
return (
132141
<>
133142
<Button onClick={handleCancel} radius="xl" {...cancelButtonProps}>
@@ -148,18 +157,13 @@ const Modal = forwardRef<ModalProps, any>((props, ref) => {
148157
};
149158

150159
const {
151-
footer,
152160
visible,
153161
centered = true,
154162
getContainer,
155163
closeIcon,
156164
focusTriggerAfterClose = true,
157165
width = 600,
158166
wrapClassName,
159-
header,
160-
title,
161-
description,
162-
titleIcon,
163167
...restProps
164168
} = props;
165169
const [internalVisible, setInternalVisible] = useState(visible);
@@ -178,8 +182,6 @@ const Modal = forwardRef<ModalProps, any>((props, ref) => {
178182

179183
const renderCloseIcon = <>{closeIcon || <Close size={24} />}</>;
180184

181-
const renderHeader = header || <Field value={title} label={description} avatar={titleIcon} />;
182-
183185
return (
184186
<StyledDialog
185187
{...restProps}
@@ -190,8 +192,8 @@ const Modal = forwardRef<ModalProps, any>((props, ref) => {
190192
width={width}
191193
closeIcon={renderCloseIcon}
192194
onClose={handleCancel}
193-
title={renderHeader}
194-
footer={footer || renderFooter()}
195+
title={renderHeader()}
196+
footer={renderFooter()}
195197
transitionName={getTransitionName('kubed', 'zoom', props.transitionName)}
196198
maskTransitionName={getTransitionName('kubed', 'fade', props.maskTransitionName)}
197199
/>

packages/components/src/Modal/ModalProvider/ModalProvider.tsx

+6-2
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,13 @@ export function ModalProvider({ children }: PropsWithChildren<Props>) {
5252
{children}
5353
{modalState.map((modal) => {
5454
if (!modal.type) {
55-
return <Modal {...modal}>{modal.content}</Modal>;
55+
return (
56+
<Modal {...modal} key={modal.id}>
57+
{modal.content}
58+
</Modal>
59+
);
5660
}
57-
return <ConfirmDialog {...modal} />;
61+
return <ConfirmDialog {...modal} key={modal.id} />;
5862
})}
5963
</ModalContext.Provider>
6064
);

packages/components/src/Popover/Popover.story.tsx

+6-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,12 @@ export default {
88

99
export const Basic = () => (
1010
<div style={{ marginTop: '70px', marginLeft: '100px' }}>
11-
<Popover title="popover title" content="Display additional, floating content on click">
11+
<Popover
12+
title="popover title"
13+
content="Display additional, floating content on click"
14+
width={240}
15+
contentClassName="test-classname"
16+
>
1217
<Button radius="xl">KubeSphere</Button>
1318
</Popover>
1419
</div>

packages/components/src/Popover/Popover.tsx

+11-2
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,14 @@ import styled from 'styled-components';
33
import { Tooltip, TooltipProps } from '../Tooltip/Tooltip';
44
import { addColorAlpha } from '../utils/color';
55

6-
const PopoverWrapper = styled.div`
6+
interface WrapperProps {
7+
$width?: number;
8+
}
9+
10+
const PopoverWrapper = styled('div')<WrapperProps>`
711
display: flex;
812
flex-direction: column;
13+
${({ $width }) => ($width ? `width: ${$width}px` : null)};
914
`;
1015

1116
const PopoverTitle = styled.div`
@@ -19,18 +24,22 @@ const PopoverContent = styled.div`
1924

2025
export interface PopoverProps extends TooltipProps {
2126
title?: string;
27+
width?: number;
28+
contentClassName?: string;
2229
}
2330

2431
export function Popover({
2532
title,
2633
children,
2734
maxWidth = '264px',
35+
width,
2836
interactive = true,
2937
content,
38+
contentClassName,
3039
...rest
3140
}: PopoverProps) {
3241
const popContent = (
33-
<PopoverWrapper>
42+
<PopoverWrapper $width={width} className={contentClassName}>
3443
{title && <PopoverTitle>{title}</PopoverTitle>}
3544
<PopoverContent>{content}</PopoverContent>
3645
</PopoverWrapper>

0 commit comments

Comments
 (0)